WP to Twitter - Version 3.2.0

Version Description

  • Bug fix: if user without permissions to edit WP to Twitter meta updated profiles, Twitter profile data was deleted.
  • Bug fix: PHP notices (2) in Twitter search widget
  • Bug fix: no notice to update settings when setting new URL shortener.
  • Bug fix: permissions tabs non functional if custom role name had a space
  • Bug fix: remove notice thrown when rate limiting is run on a Tweet not associated with a post
  • Bug fix: remove notice thrown when no error defined by custom shortener.
  • Design update in metabox panel
  • Misc. design & text updates
  • Ability to add new URL shorteners via filters ('wpt_shorten_link', 'wpt_shortener_settings', 'wpt_choose_shortener')
  • Remove ability to set YOURLS as a local resource in new installs
  • Added filter to disable storing URLs in post meta
  • Deprecate more old jd_ prefixed functions
  • Change admin page URL to match Pro version.
  • Remove dependency on is_plugin_active()
  • Added opt-in usage tracking via Freemius.com
Download this release

Release Info

Developer joedolson
Plugin Icon 128x128 WP to Twitter
Version 3.2.0
Comparing to
See all releases

Code changes from version 3.1.9 to 3.2.0

Files changed (98) hide show
  1. css/post-styles.css +64 -31
  2. css/styles.css +26 -11
  3. freemius/.gitignore +3 -0
  4. freemius/LICENSE.txt +340 -0
  5. freemius/README.md +245 -0
  6. freemius/assets/css/admin/account.css +1 -0
  7. freemius/assets/css/admin/add-ons.css +2 -0
  8. freemius/assets/css/admin/common.css +1 -0
  9. freemius/assets/css/admin/connect.css +1 -0
  10. freemius/assets/css/admin/deactivation-feedback.css +1 -0
  11. freemius/assets/css/common.css +1 -0
  12. freemius/assets/img/plugin-icon.png +0 -0
  13. freemius/assets/js/jquery.ba-postmessage.js +222 -0
  14. freemius/assets/js/jquery.ba-postmessage.min.js +9 -0
  15. freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  16. freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  17. freemius/assets/js/postmessage.js +110 -0
  18. freemius/assets/scss/_colors.scss +58 -0
  19. freemius/assets/scss/_functions.scss +0 -0
  20. freemius/assets/scss/_load.scss +4 -0
  21. freemius/assets/scss/_mixins.scss +224 -0
  22. freemius/assets/scss/_start.scss +4 -0
  23. freemius/assets/scss/_vars.scss +5 -0
  24. freemius/assets/scss/admin/account.scss +138 -0
  25. freemius/assets/scss/admin/add-ons.scss +319 -0
  26. freemius/assets/scss/admin/common.scss +134 -0
  27. freemius/assets/scss/admin/connect.scss +421 -0
  28. freemius/assets/scss/admin/deactivation-feedback.scss +120 -0
  29. freemius/composer.json +10 -0
  30. freemius/config.php +171 -0
  31. freemius/includes/class-freemius-abstract.php +404 -0
  32. freemius/includes/class-freemius.php +7845 -0
  33. freemius/includes/class-fs-api.php +454 -0
  34. freemius/includes/class-fs-logger.php +168 -0
  35. freemius/includes/class-fs-plugin-updater.php +314 -0
  36. freemius/includes/class-fs-security.php +61 -0
  37. freemius/includes/entities/class-fs-entity.php +149 -0
  38. freemius/includes/entities/class-fs-plugin-info.php +34 -0
  39. freemius/includes/entities/class-fs-plugin-license.php +160 -0
  40. freemius/includes/entities/class-fs-plugin-plan.php +71 -0
  41. freemius/includes/entities/class-fs-plugin-tag.php +24 -0
  42. freemius/includes/entities/class-fs-plugin.php +90 -0
  43. freemius/includes/entities/class-fs-scope-entity.php +29 -0
  44. freemius/includes/entities/class-fs-site.php +119 -0
  45. freemius/includes/entities/class-fs-subscription.php +117 -0
  46. freemius/includes/entities/class-fs-user.php +62 -0
  47. freemius/includes/fs-core-functions.php +343 -0
  48. freemius/includes/fs-essential-functions.php +403 -0
  49. freemius/includes/fs-plugin-functions.php +413 -0
  50. freemius/includes/i18n.php +299 -0
  51. freemius/includes/managers/class-fs-admin-menu-manager.php +549 -0
  52. freemius/includes/managers/class-fs-admin-notice-manager.php +303 -0
  53. freemius/includes/managers/class-fs-cache-manager.php +211 -0
  54. freemius/includes/managers/class-fs-key-value-storage.php +291 -0
  55. freemius/includes/managers/class-fs-license-manager.php +101 -0
  56. freemius/includes/managers/class-fs-option-manager.php +297 -0
  57. freemius/includes/managers/class-fs-plan-manager.php +147 -0
  58. freemius/includes/managers/class-fs-plugin-manager.php +154 -0
  59. freemius/includes/sdk/Exceptions/ArgumentNotExistException.php +6 -0
  60. freemius/includes/sdk/Exceptions/EmptyArgumentException.php +6 -0
  61. freemius/includes/sdk/Exceptions/Exception.php +75 -0
  62. freemius/includes/sdk/Exceptions/InvalidArgumentException.php +6 -0
  63. freemius/includes/sdk/Exceptions/OAuthException.php +12 -0
  64. freemius/includes/sdk/Freemius.php +533 -0
  65. freemius/includes/sdk/FreemiusBase.php +178 -0
  66. freemius/includes/sdk/LICENSE.txt +340 -0
  67. freemius/includes/supplements/fs-essential-functions-1.1.7.1.php +45 -0
  68. freemius/start.php +332 -0
  69. freemius/templates/account.php +455 -0
  70. freemius/templates/add-ons.php +117 -0
  71. freemius/templates/admin-notice.php +42 -0
  72. freemius/templates/all-admin-notice.php +35 -0
  73. freemius/templates/checkout.php +246 -0
  74. freemius/templates/connect.php +242 -0
  75. freemius/templates/contact.php +77 -0
  76. freemius/templates/deactivation-feedback-modal.php +201 -0
  77. freemius/templates/debug.php +213 -0
  78. freemius/templates/email.php +46 -0
  79. freemius/templates/firewall-issues-js.php +53 -0
  80. freemius/templates/plugin-icon.php +76 -0
  81. freemius/templates/plugin-info/description.php +75 -0
  82. freemius/templates/plugin-info/features.php +97 -0
  83. freemius/templates/plugin-info/screenshots.php +33 -0
  84. freemius/templates/powered-by.php +41 -0
  85. freemius/templates/pricing.php +100 -0
  86. freemius/templates/sticky-admin-notice-js.php +40 -0
  87. images/icon.png +0 -0
  88. js/base.js +14 -0
  89. readme.txt +21 -3
  90. wp-to-twitter-manager.php +47 -51
  91. wp-to-twitter-oauth.php +11 -4
  92. wp-to-twitter-shorteners.php +369 -389
  93. wp-to-twitter.php +136 -75
  94. wpt-feed.php +1 -1
  95. wpt-functions.php +19 -11
  96. wpt-rate-limiting.php +16 -11
  97. wpt-widget.php +5 -3
  98. wpt_twitter_oauth.php +2 -2
css/post-styles.css CHANGED
@@ -36,11 +36,12 @@
36
  }
37
 
38
  #wp2t p.disabled {
39
- font-weight: 700;
40
- background: #ffc;
41
- padding: 5px 12px;
42
- font-size: 1.2em;
43
- margin: -10px -12px .5em;
 
44
  }
45
 
46
  #wp2t .wpt-options .disabled {
@@ -76,6 +77,27 @@
76
  max-height: 120px;
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  .wpt-options {
80
  -moz-column-count: 3;
81
  -webkit-column-count: 3;
@@ -163,7 +185,7 @@ button.time div {
163
 
164
  .wpt-options .tabs a {
165
  display: inline-block;
166
- padding: 4px;
167
  border-radius: 4px 4px 0 0;
168
  border: 1px solid #ccc;
169
  background: #f3f3f3;
@@ -172,6 +194,9 @@ button.time div {
172
  .wpt-options .tabs a.active {
173
  border-bottom: 1px solid #fefefe;
174
  background: #fefefe;
 
 
 
175
  }
176
 
177
  .wpt_log, #jts {
@@ -189,54 +214,62 @@ button.time div {
189
  background: #f6f6f6;
190
  }
191
 
 
 
 
 
192
  .toggle-btn-group {
193
  margin: .25em auto .5em;
 
 
 
 
 
 
 
 
194
  content: "";
195
  display: table;
196
- clear: both;
197
  }
198
 
199
  .toggle-btn-group label {
200
- padding: .25em;
201
  float: left;
202
  text-align: center;
203
  cursor: pointer;
204
  background-color: #f3f3f3;
205
- border: #aaa 1px solid;
 
 
 
206
  }
207
 
208
  .toggle-btn-group label:first-of-type {
209
- border-radius: 0 .5em .5em 0;
210
  }
211
 
212
  .toggle-btn-group input[type="radio"]:checked + label {
213
- background-color: #ddd;
214
- border: #666 1px solid;
215
- text-decoration: underline;
216
  cursor: text;
 
 
 
 
 
 
 
 
 
 
217
  }
218
 
219
  .toggle-btn-group label:hover,
220
  .toggle-btn-group label:focus {
221
  background-color: #ddd;
222
- border: #000 1px solid;
223
- }
224
-
225
- .toggle-btn-group label:first-of-type {
226
- border-radius: .5em 0 0 .5em;
227
- }
228
-
229
- .toggle-btn-group label:last-of-type {
230
- border-top-right-radius: .5em;
231
- border-bottom-right-radius: .5em;
232
- }
233
-
234
- .toggle-btn-group label:first-of-type {
235
- border-right: 0px solid;
236
- }
237
-
238
- .toggle-btn-group label:last-of-type {
239
- border-left: 0px solid;
240
  }
241
 
242
  .toggle-btn-group input {
36
  }
37
 
38
  #wp2t p.disabled {
39
+ font-weight: 400;
40
+ font-style: italic;
41
+ background: #ffd;
42
+ padding: 4px 12px;
43
+ font-size: 1.1em;
44
+ margin: .5em -12px -12px;
45
  }
46
 
47
  #wp2t .wpt-options .disabled {
77
  max-height: 120px;
78
  }
79
 
80
+ .panel-toggle a {
81
+ display: block;
82
+ padding: 2px;
83
+ background: rgba( 240,240,240, .9 );
84
+ border: 1px solid rgba( 240,240,240, .9 );
85
+ text-decoration: none;
86
+ }
87
+
88
+ .panel-toggle a:hover, .panel-toggle a:focus {
89
+ border: 1px solid rgba( 220,220,220, 1 );
90
+ }
91
+
92
+ .wp-to-twitter .dashicons {
93
+ font-size: inherit;
94
+ line-height: inherit;
95
+ }
96
+
97
+ .wp-to-twitter .dashicons-clock {
98
+ font-size: 20px;
99
+ }
100
+
101
  .wpt-options {
102
  -moz-column-count: 3;
103
  -webkit-column-count: 3;
185
 
186
  .wpt-options .tabs a {
187
  display: inline-block;
188
+ padding: 4px 6px;
189
  border-radius: 4px 4px 0 0;
190
  border: 1px solid #ccc;
191
  background: #f3f3f3;
194
  .wpt-options .tabs a.active {
195
  border-bottom: 1px solid #fefefe;
196
  background: #fefefe;
197
+ text-decoration: none;
198
+ color: #444;
199
+ font-weight: 700;
200
  }
201
 
202
  .wpt_log, #jts {
214
  background: #f6f6f6;
215
  }
216
 
217
+ .wp-to-twitter .template {
218
+ margin: 0;
219
+ }
220
+
221
  .toggle-btn-group {
222
  margin: .25em auto .5em;
223
+ width: auto;
224
+ }
225
+
226
+ .wptab .toggle-btn-group {
227
+ margin: .25em -5px .25em;
228
+ }
229
+
230
+ .toggle-btn-group:after {
231
  content: "";
232
  display: table;
233
+ clear: both;
234
  }
235
 
236
  .toggle-btn-group label {
237
+ padding: .25em 0;
238
  float: left;
239
  text-align: center;
240
  cursor: pointer;
241
  background-color: #f3f3f3;
242
+ display: inline-block;
243
+ width: 50%;
244
+ text-decoration: underline;
245
+ color: #6e6e6e;
246
  }
247
 
248
  .toggle-btn-group label:first-of-type {
249
+ border-radius: 0;
250
  }
251
 
252
  .toggle-btn-group input[type="radio"]:checked + label {
253
+ background-color: #0073aa;
254
+ outline: 1px solid #00a0d2;
255
+ text-decoration: none;
256
  cursor: text;
257
+ font-weight: 700;
258
+ color: #fff;
259
+ }
260
+
261
+ .toggle-btn-group input[type="radio"]:checked + label:before {
262
+ font-family: dashicons;
263
+ content: "\f147";
264
+ color: #fff;
265
+ margin-right: 2px;
266
+ vertical-align: bottom;
267
  }
268
 
269
  .toggle-btn-group label:hover,
270
  .toggle-btn-group label:focus {
271
  background-color: #ddd;
272
+ outline: #aaa 1px solid;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  }
274
 
275
  .toggle-btn-group input {
css/styles.css CHANGED
@@ -7,11 +7,10 @@
7
  border: none;
8
  }
9
 
10
- #wp-to-twitter legend, #wpt-settings_page legend {
11
- padding: 6px;
12
- background: #f3f3f3;
13
- width: 100%;
14
- border-radius: 3px 0 0 3px;
15
  color: #000;
16
  margin-top: 4px;
17
  }
@@ -50,17 +49,22 @@
50
 
51
  #wp-to-twitter .wpt-terms p {
52
  text-align: right;
53
- padding-bottom: 5px;
54
- border-bottom: 1px solid #ddd;
 
 
55
  }
56
 
57
  #wp-to-twitter .wpt-terms ul {
 
 
58
  -moz-column-count: 3;
59
  -moz-column-gap: 20px;
60
  -webkit-column-count: 3;
61
  -webkit-column-gap: 20px;
62
  margin: 0 0 20px;
63
- padding: 0;
 
64
  }
65
 
66
  #wp-to-twitter .wpt-terms li {
@@ -87,7 +91,7 @@
87
  }
88
 
89
  #wp-to-twitter .wpt-template, #wp-to-twitter .support-request {
90
- width: 95%;
91
  }
92
 
93
  .wpt_image {
@@ -122,7 +126,7 @@ label[for="wpt_license_key"] {
122
  }
123
 
124
  #wpt_settings_page .tabs {
125
- margin: 0 !important;
126
  padding: 0 4px;
127
  position: relative;
128
  top: 1px;
@@ -180,8 +184,9 @@ label[for="wpt_license_key"] {
180
  min-height: 160px !important;
181
  }
182
 
183
- .wpt-permissions legend {
184
  background: none;
 
185
  }
186
 
187
  .wpt-terms li {
@@ -293,6 +298,10 @@ label[for='wpt_prepend_rt'], label[for='wpt_prepend_rt2'], label[for='wpt_prepen
293
  text-decoration: none;
294
  }
295
 
 
 
 
 
296
  @media (max-width: 782px) {
297
  .jcd-narrow {
298
  width: 100%;
@@ -301,4 +310,10 @@ label[for='wpt_prepend_rt'], label[for='wpt_prepend_rt2'], label[for='wpt_prepen
301
  .jcd-wide {
302
  width: 100%;
303
  }
 
 
 
 
 
 
304
  }
7
  border: none;
8
  }
9
 
10
+ #wp-to-twitter legend, #wpt_settings_page legend {
11
+ padding: 6px 1%;
12
+ background: #f3f4f5;
13
+ width: 98%;
 
14
  color: #000;
15
  margin-top: 4px;
16
  }
49
 
50
  #wp-to-twitter .wpt-terms p {
51
  text-align: right;
52
+ border-bottom: 1px solid #ccc;
53
+ background: #f3f4f5;
54
+ padding: 4px;
55
+ margin: -30px 0 0;
56
  }
57
 
58
  #wp-to-twitter .wpt-terms ul {
59
+ column-count: 3;
60
+ column-gap: 20px;
61
  -moz-column-count: 3;
62
  -moz-column-gap: 20px;
63
  -webkit-column-count: 3;
64
  -webkit-column-gap: 20px;
65
  margin: 0 0 20px;
66
+ padding: 6px 2%;
67
+ width: 96%;
68
  }
69
 
70
  #wp-to-twitter .wpt-terms li {
91
  }
92
 
93
  #wp-to-twitter .wpt-template, #wp-to-twitter .support-request {
94
+ width: 100%;
95
  }
96
 
97
  .wpt_image {
126
  }
127
 
128
  #wpt_settings_page .tabs {
129
+ margin: .5em 0 0;
130
  padding: 0 4px;
131
  position: relative;
132
  top: 1px;
184
  min-height: 160px !important;
185
  }
186
 
187
+ #wpt_settings_page .wpt-permissions .wptab legend {
188
  background: none;
189
+ padding: 0;
190
  }
191
 
192
  .wpt-terms li {
298
  text-decoration: none;
299
  }
300
 
301
+ .toplevel_page_wp-tweets-pro #fs_connect .fs-terms a {
302
+ color: #555;
303
+ }
304
+
305
  @media (max-width: 782px) {
306
  .jcd-narrow {
307
  width: 100%;
310
  .jcd-wide {
311
  width: 100%;
312
  }
313
+
314
+ #wp-to-twitter .wpt-terms p {
315
+ margin: 0;
316
+ }
317
+
318
+
319
  }
freemius/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ output/
2
+ assets/img/icon.*
3
+
freemius/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
freemius/README.md ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Freemius WordPress SDK
2
+ ======================
3
+
4
+ Freemius is an [analytics](https://freemius.com/wordpress/insights/) & [monetization](https://freemius.com/wordpress/) platform for plugin developers. Freemius empower developers with advanced real-time analytics and helps turning any plugin into a commercial product in less than 10 min.
5
+
6
+ The platform is fully functional and running in production. Having said that, the monetization platform is still in closed beta.
7
+ If you are a WordPress plugin developer and you are interested to monetize with Freemius [apply to our closed beta here](http://bit.ly/freemius-beta):
8
+
9
+ http://bit.ly/freemius-beta
10
+
11
+ **Below you'll find the integration instructions for our WordPress SDK.**
12
+
13
+ ## Initializing the SDK
14
+
15
+ Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
16
+
17
+ ```php
18
+ <?php
19
+ // Create a helper function for easy SDK access.
20
+ function my_prefix_fs() {
21
+ global $my_prefix_fs;
22
+ if ( ! isset( $my_prefix_fs ) ) {
23
+ // Include Freemius SDK.
24
+ require_once dirname(__FILE__) . '/freemius/start.php';
25
+
26
+ $my_prefix_fs = fs_dynamic_init( array(
27
+ 'id' => '1234',
28
+ 'slug' => 'my-plugin-slug',
29
+ 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
30
+ 'public_key' => 'pk_MY_PUBLIC_KEY',
31
+ 'is_live' => true,
32
+ 'is_premium' => true,
33
+ 'has_addons' => false,
34
+ 'has_paid_plans' => false,
35
+ // Set the SDK to work in a sandbox mode (for development & testing).
36
+ // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
37
+ 'secret_key' => 'sk_MY_SECRET_KEY',
38
+ ) );
39
+ }
40
+
41
+ return $my_prefix_fs;
42
+ }
43
+
44
+ // Init Freemius.
45
+ my_prefix_fs();
46
+ ?>
47
+ ```
48
+
49
+ - **1234** - Replace with your plugin's ID.
50
+ - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
51
+ - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
52
+ - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
53
+ - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
54
+
55
+
56
+ ## Usage example
57
+
58
+ You can call the SDK by using the shortcode function:
59
+
60
+ ```php
61
+ <?php my_prefix_fs()->get_upgrade_url(); ?>
62
+ ```
63
+
64
+ Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
65
+
66
+ ```php
67
+ <?php
68
+ global $my_prefix_fs;
69
+ $my_prefix_fs->get_account_url();
70
+ ?>
71
+ ```
72
+
73
+ ## Adding license based logic examples
74
+
75
+ Add marketing content to encourage your users to upgrade for your paid version:
76
+
77
+ ```php
78
+ <?php
79
+ if ( my_prefix_fs()->is_not_paying() ) {
80
+ echo '<section><h1>' . __('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
81
+ echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
82
+ __('Upgrade Now!', 'my-plugin-slug') .
83
+ '</a>';
84
+ echo '</section>';
85
+ }
86
+ ?>
87
+ ```
88
+
89
+ Add logic which will only be available in your premium plugin version:
90
+
91
+ ```php
92
+ <?php
93
+ // This "if" block will be auto removed from the Free version.
94
+ if ( my_prefix_fs()->is__premium_only() ) {
95
+
96
+ // ... premium only logic ...
97
+
98
+ }
99
+ ?>
100
+ ```
101
+
102
+ To add a function which will only be available in your premium plugin version, simply add __premium_only as the suffix of the function name. Just make sure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:
103
+
104
+ ```php
105
+ <?php
106
+ class My_Plugin {
107
+ function init() {
108
+ ...
109
+
110
+ // This "if" block will be auto removed from the free version.
111
+ if ( my_prefix_fs()->is__premium_only() ) {
112
+ // Init premium version.
113
+ $this->admin_init__premium_only();
114
+
115
+ add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
116
+ }
117
+
118
+ ...
119
+ }
120
+
121
+ // This method will be only included in the premium version.
122
+ function admin_init__premium_only() {
123
+ ...
124
+ }
125
+
126
+ // This method will be only included in the premium version.
127
+ function admin_init_hook__premium_only() {
128
+ ...
129
+ }
130
+ }
131
+ ?>
132
+ ```
133
+
134
+ Add logic which will only be executed for customers in your 'professional' plan:
135
+
136
+ ```php
137
+ <?php
138
+ if ( my_prefix_fs()->is_plan('professional', true) ) {
139
+ // .. logic related to Professional plan only ...
140
+ }
141
+ ?>
142
+ ```
143
+
144
+ Add logic which will only be executed for customers in your 'professional' plan or higher plans:
145
+
146
+ ```php
147
+ <?php
148
+ if ( my_prefix_fs()->is_plan('professional') ) {
149
+ // ... logic related to Professional plan and higher plans ...
150
+ }
151
+ ?>
152
+ ```
153
+
154
+ Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):
155
+
156
+ ```php
157
+ <?php
158
+ // This "if" block will be auto removed from the Free version.
159
+ if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
160
+ // ... logic related to Professional plan and higher plans ...
161
+ }
162
+ ?>
163
+ ```
164
+
165
+ Add logic only for users in trial:
166
+
167
+ ```php
168
+ <?php
169
+ if ( my_prefix_fs()->is_trial() ) {
170
+ // ... logic for users in trial ...
171
+ }
172
+ ?>
173
+ ```
174
+
175
+ Add logic for specified paid plan:
176
+
177
+ ```php
178
+ <?php
179
+ // This "if" block will be auto removed from the Free version.
180
+ if ( my_prefix_fs()->is__premium_only() ) {
181
+ if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
182
+
183
+ // ... logic related to Professional plan only ...
184
+
185
+ } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
186
+
187
+ // ... logic related to Business plan and higher plans ...
188
+
189
+ }
190
+ }
191
+ ?>
192
+ ```
193
+
194
+ ## Excluding files and folders from the free plugin version
195
+ There are two ways to exclude files from your free version.
196
+
197
+ 1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included in the premium plugin version. This works for all type of files, not only PHP.
198
+ 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
199
+ ```php
200
+ <?php
201
+ /**
202
+ * Plugin Name: My Very Awesome Plugin
203
+ * Plugin URI: http://my-awesome-plugin.com
204
+ * Description: Create and manage Awesomeness right in WordPress.
205
+ * Version: 1.0.0
206
+ * Author: Awesomattic
207
+ * Author URI: http://my-awesome-plugin.com/me/
208
+ * License: GPLv2
209
+ * Text Domain: myplugin
210
+ * Domain Path: /langs
211
+ *
212
+ * @fs_premium_only /lib/functions.php, /premium-files/
213
+ */
214
+
215
+ if ( ! defined( 'ABSPATH' ) ) {
216
+ exit;
217
+ }
218
+
219
+ // ... my code ...
220
+ ?>
221
+ ```
222
+ The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
223
+
224
+ # WordPress.org Compliance
225
+ Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
226
+ > All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers.
227
+
228
+ Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with `if ( my_prefix_fs()->{{ method }}__premium_only() )` or the other methods provided to exclude premium features & files from the free version.
229
+
230
+ ## Deployment
231
+ Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
232
+ The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
233
+
234
+ 1. **Premium version**: Identical to your uploaded version, including all code (except your `secret_key`). Will be enabled for download ONLY for your paying or in trial customers.
235
+ 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
236
+
237
+ The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org complaint and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo.
238
+
239
+ ## Reporting Bugs
240
+ Email dev [at] freemius [dot] com
241
+
242
+ ## FAQ
243
+
244
+ ## Copyright
245
+ Freemius, Inc.
freemius/assets/css/admin/account.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_account .postbox,#fs_account .widefat{max-width:700px}#fs_account h3{font-size:1.3em;padding:12px 12px 12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:0.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table td label{background:orange;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table var,.fs-key-value-table code{color:#0073AA;font-size:16px;background:none}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}
freemius/assets/css/admin/add-ons.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ #fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner ul{-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:0.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}
2
+ #TB_window,#TB_window iframe{width:772px !important}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin-left:30px}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{background:#FFFEEC;margin:-16px;padding:20px 20px 50px 20px;border-bottom:1px solid #DDD}#plugin-information .plugin-information-pricing h3{margin-top:0}#plugin-information .plugin-information-pricing .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing label{white-space:nowrap}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
freemius/assets/css/admin/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;bottom:-22px;top:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;box-shadow:0px 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}
freemius/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}#fs_connect .fs-actions .button{padding:0 10px 1px;line-height:35px;height:37px;font-size:16px;margin-bottom:0}#fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}#fs_connect .fs-actions .button.button-primary{padding-right:15px;padding-left:15px}#fs_connect .fs-actions .button.button-primary:after{content:' \279C'}#fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}#fs_connect .fs-actions .button.button-secondary{float:right}#fs_connect.fs-anonymous-disabled .fs-actions .button.button-primary{width:100%}#fs_connect .fs-permissions{padding:10px 20px;background:#FEFEFE;-moz-transition:background 0.5s ease;-o-transition:background 0.5s ease;-ms-transition:background 0.5s ease;-webkit-transition:background 0.5s ease;transition:background 0.5s ease}#fs_connect .fs-permissions .fs-trigger{font-size:0.9em;text-decoration:none;text-align:center;display:block}#fs_connect .fs-permissions ul{height:0;overflow:hidden;margin:0}#fs_connect .fs-permissions ul li{margin-bottom:12px}#fs_connect .fs-permissions ul li:last-child{margin-bottom:0}#fs_connect .fs-permissions ul li i.dashicons{float:left;font-size:40px;width:40px;height:40px}#fs_connect .fs-permissions ul li div{margin-left:55px}#fs_connect .fs-permissions ul li div span{font-weight:bold;text-transform:uppercase;color:#23282d}#fs_connect .fs-permissions ul li div p{margin:2px 0 0 0}#fs_connect .fs-permissions.fs-open{background:#fff}#fs_connect .fs-permissions.fs-open ul{height:auto;margin:20px 20px 10px 20px}@media screen and (max-width: 479px){#fs_connect .fs-permissions{background:#fff}#fs_connect .fs-permissions .fs-trigger{display:none}#fs_connect .fs-permissions ul{height:auto;margin:20px}}#fs_connect .fs-visual{padding:12px;line-height:0;background:#fafafa;height:80px;position:relative}#fs_connect .fs-visual .fs-site-icon{position:absolute;left:20px;top:10px}#fs_connect .fs-visual .fs-connect-logo{position:absolute;right:20px;top:10px}#fs_connect .fs-visual .fs-plugin-icon{position:absolute;top:10px;left:50%;margin-left:-40px}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-site-icon,#fs_connect .fs-visual img,#fs_connect .fs-visual object{width:80px;height:80px}#fs_connect .fs-visual .dashicons-wordpress{font-size:64px;background:#01749a;color:#fff;width:64px;height:64px;padding:8px}#fs_connect .fs-visual .dashicons-plus{position:absolute;top:50%;font-size:30px;margin-top:-10px;color:#bbb}#fs_connect .fs-visual .dashicons-plus.fs-first{left:28%}#fs_connect .fs-visual .dashicons-plus.fs-second{left:65%}#fs_connect .fs-visual .fs-plugin-icon,#fs_connect .fs-visual .fs-connect-logo,#fs_connect .fs-visual .fs-site-icon{border:1px solid #ccc;padding:1px;background:#fff}#fs_connect .fs-terms{text-align:center;font-size:0.85em;padding:5px;background:rgba(0,0,0,0.05)}#fs_connect .fs-terms,#fs_connect .fs-terms a{color:#999}#fs_connect .fs-terms a{text-decoration:none}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li div{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
freemius/assets/css/admin/deactivation-feedback.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input{margin-left:29px}.fs-modal .fs-modal-dialog li.reason label{display:table}.fs-modal .fs-modal-dialog li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}.fs-modal .reason-input{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea{width:100%}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
freemius/assets/css/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice.success{color:green;font-weight:700}
freemius/assets/img/plugin-icon.png ADDED
Binary file
freemius/assets/js/jquery.ba-postmessage.js ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ */
9
+
10
+ // Script: jQuery postMessage: Cross-domain scripting goodness
11
+ //
12
+ // *Version: 0.5, Last updated: 9/11/2009*
13
+ //
14
+ // Project Home - http://benalman.com/projects/jquery-postmessage-plugin/
15
+ // GitHub - http://github.com/cowboy/jquery-postmessage/
16
+ // Source - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.js
17
+ // (Minified) - http://github.com/cowboy/jquery-postmessage/raw/master/jquery.ba-postmessage.min.js (0.9kb)
18
+ //
19
+ // About: License
20
+ //
21
+ // Copyright (c) 2009 "Cowboy" Ben Alman,
22
+ // Dual licensed under the MIT and GPL licenses.
23
+ // http://benalman.com/about/license/
24
+ //
25
+ // About: Examples
26
+ //
27
+ // This working example, complete with fully commented code, illustrates one
28
+ // way in which this plugin can be used.
29
+ //
30
+ // Iframe resizing - http://benalman.com/code/projects/jquery-postmessage/examples/iframe/
31
+ //
32
+ // About: Support and Testing
33
+ //
34
+ // Information about what version or versions of jQuery this plugin has been
35
+ // tested with and what browsers it has been tested in.
36
+ //
37
+ // jQuery Versions - 1.3.2
38
+ // Browsers Tested - Internet Explorer 6-8, Firefox 3, Safari 3-4, Chrome, Opera 9.
39
+ //
40
+ // About: Release History
41
+ //
42
+ // 0.5 - (9/11/2009) Improved cache-busting
43
+ // 0.4 - (8/25/2009) Initial release
44
+
45
+ (function($){
46
+ '$:nomunge'; // Used by YUI compressor.
47
+
48
+ // A few vars used in non-awesome browsers.
49
+ var interval_id,
50
+ last_hash,
51
+ cache_bust = 1,
52
+
53
+ // A var used in awesome browsers.
54
+ rm_callback,
55
+
56
+ // A few convenient shortcuts.
57
+ window = this,
58
+ FALSE = !1,
59
+
60
+ // Reused internal strings.
61
+ postMessage = 'postMessage',
62
+ addEventListener = 'addEventListener',
63
+
64
+ p_receiveMessage,
65
+
66
+ // I couldn't get window.postMessage to actually work in Opera 9.64!
67
+ has_postMessage = window[postMessage] && !$.browser.opera;
68
+
69
+ // Method: jQuery.postMessage
70
+ //
71
+ // This method will call window.postMessage if available, setting the
72
+ // targetOrigin parameter to the base of the target_url parameter for maximum
73
+ // security in browsers that support it. If window.postMessage is not available,
74
+ // the target window's location.hash will be used to pass the message. If an
75
+ // object is passed as the message param, it will be serialized into a string
76
+ // using the jQuery.param method.
77
+ //
78
+ // Usage:
79
+ //
80
+ // > jQuery.postMessage( message, target_url [, target ] );
81
+ //
82
+ // Arguments:
83
+ //
84
+ // message - (String) A message to be passed to the other frame.
85
+ // message - (Object) An object to be serialized into a params string, using
86
+ // the jQuery.param method.
87
+ // target_url - (String) The URL of the other frame this window is
88
+ // attempting to communicate with. This must be the exact URL (including
89
+ // any query string) of the other window for this script to work in
90
+ // browsers that don't support window.postMessage.
91
+ // target - (Object) A reference to the other frame this window is
92
+ // attempting to communicate with. If omitted, defaults to `parent`.
93
+ //
94
+ // Returns:
95
+ //
96
+ // Nothing.
97
+
98
+ $[postMessage] = function( message, target_url, target ) {
99
+ if ( !target_url ) { return; }
100
+
101
+ // Serialize the message if not a string. Note that this is the only real
102
+ // jQuery dependency for this script. If removed, this script could be
103
+ // written as very basic JavaScript.
104
+ message = typeof message === 'string' ? message : $.param( message );
105
+
106
+ // Default to parent if unspecified.
107
+ target = target || parent;
108
+
109
+ if ( has_postMessage ) {
110
+ // The browser supports window.postMessage, so call it with a targetOrigin
111
+ // set appropriately, based on the target_url parameter.
112
+ target[postMessage]( message, target_url.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
113
+
114
+ } else if ( target_url ) {
115
+ // The browser does not support window.postMessage, so set the location
116
+ // of the target to target_url#message. A bit ugly, but it works! A cache
117
+ // bust parameter is added to ensure that repeat messages trigger the
118
+ // callback.
119
+ target.location = target_url.replace( /#.*$/, '' ) + '#' + (+new Date) + (cache_bust++) + '&' + message;
120
+ }
121
+ };
122
+
123
+ // Method: jQuery.receiveMessage
124
+ //
125
+ // Register a single callback for either a window.postMessage call, if
126
+ // supported, or if unsupported, for any change in the current window
127
+ // location.hash. If window.postMessage is supported and source_origin is
128
+ // specified, the source window will be checked against this for maximum
129
+ // security. If window.postMessage is unsupported, a polling loop will be
130
+ // started to watch for changes to the location.hash.
131
+ //
132
+ // Note that for simplicity's sake, only a single callback can be registered
133
+ // at one time. Passing no params will unbind this event (or stop the polling
134
+ // loop), and calling this method a second time with another callback will
135
+ // unbind the event (or stop the polling loop) first, before binding the new
136
+ // callback.
137
+ //
138
+ // Also note that if window.postMessage is available, the optional
139
+ // source_origin param will be used to test the event.origin property. From
140
+ // the MDC window.postMessage docs: This string is the concatenation of the
141
+ // protocol and "://", the host name if one exists, and ":" followed by a port
142
+ // number if a port is present and differs from the default port for the given
143
+ // protocol. Examples of typical origins are https://example.org (implying
144
+ // port 443), http://example.net (implying port 80), and http://example.com:8080.
145
+ //
146
+ // Usage:
147
+ //
148
+ // > jQuery.receiveMessage( callback [, source_origin ] [, delay ] );
149
+ //
150
+ // Arguments:
151
+ //
152
+ // callback - (Function) This callback will execute whenever a <jQuery.postMessage>
153
+ // message is received, provided the source_origin matches. If callback is
154
+ // omitted, any existing receiveMessage event bind or polling loop will be
155
+ // canceled.
156
+ // source_origin - (String) If window.postMessage is available and this value
157
+ // is not equal to the event.origin property, the callback will not be
158
+ // called.
159
+ // source_origin - (Function) If window.postMessage is available and this
160
+ // function returns false when passed the event.origin property, the
161
+ // callback will not be called.
162
+ // delay - (Number) An optional zero-or-greater delay in milliseconds at
163
+ // which the polling loop will execute (for browser that don't support
164
+ // window.postMessage). If omitted, defaults to 100.
165
+ //
166
+ // Returns:
167
+ //
168
+ // Nothing!
169
+
170
+ $.receiveMessage = p_receiveMessage = function( callback, source_origin, delay ) {
171
+ if ( has_postMessage ) {
172
+ // Since the browser supports window.postMessage, the callback will be
173
+ // bound to the actual event associated with window.postMessage.
174
+
175
+ if ( callback ) {
176
+ // Unbind an existing callback if it exists.
177
+ rm_callback && p_receiveMessage();
178
+
179
+ // Bind the callback. A reference to the callback is stored for ease of
180
+ // unbinding.
181
+ rm_callback = function(e) {
182
+ if ( ( typeof source_origin === 'string' && e.origin !== source_origin )
183
+ || ( $.isFunction( source_origin ) && source_origin( e.origin ) === FALSE ) ) {
184
+ return FALSE;
185
+ }
186
+ callback( e );
187
+ };
188
+ }
189
+
190
+ if ( window[addEventListener] ) {
191
+ window[ callback ? addEventListener : 'removeEventListener' ]( 'message', rm_callback, FALSE );
192
+ } else {
193
+ window[ callback ? 'attachEvent' : 'detachEvent' ]( 'onmessage', rm_callback );
194
+ }
195
+
196
+ } else {
197
+ // Since the browser sucks, a polling loop will be started, and the
198
+ // callback will be called whenever the location.hash changes.
199
+
200
+ interval_id && clearInterval( interval_id );
201
+ interval_id = null;
202
+
203
+ if ( callback ) {
204
+ delay = typeof source_origin === 'number'
205
+ ? source_origin
206
+ : typeof delay === 'number'
207
+ ? delay
208
+ : 100;
209
+
210
+ interval_id = setInterval(function(){
211
+ var hash = document.location.hash,
212
+ re = /^#?\d+&/;
213
+ if ( hash !== last_hash && re.test( hash ) ) {
214
+ last_hash = hash;
215
+ callback({ data: hash.replace( re, '' ) });
216
+ }
217
+ }, delay );
218
+ }
219
+ }
220
+ };
221
+
222
+ })(jQuery);
freemius/assets/js/jquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ */
9
+ (function($){var g,d,j=1,a,b=this,f=!1,h="postMessage",e="addEventListener",c,i=b[h]&&!$.browser.opera;$[h]=function(k,l,m){if(!l){return}k=typeof k==="string"?k:$.param(k);m=m||parent;if(i){m[h](k,l.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))}else{if(l){m.location=l.replace(/#.*$/,"")+"#"+(+new Date)+(j++)+"&"+k}}};$.receiveMessage=c=function(l,m,k){if(i){if(l){a&&c();a=function(n){if((typeof m==="string"&&n.origin!==m)||($.isFunction(m)&&m(n.origin)===f)){return f}l(n)}}if(b[e]){b[l?e:"removeEventListener"]("message",a,f)}else{b[l?"attachEvent":"detachEvent"]("onmessage",a)}}else{g&&clearInterval(g);g=null;if(l){k=typeof m==="number"?m:typeof k==="number"?k:100;g=setInterval(function(){var o=document.location.hash,n=/^#?\d+&/;if(o!==d&&n.test(o)){d=o;l({data:o.replace(n,"")})}},k)}}}})(jQuery);
freemius/assets/js/nojquery.ba-postmessage.js ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ *
9
+ * Non-jQuery fork by Jeff Lee
10
+ *
11
+ * This fork consists of the following changes:
12
+ * 1. Basic code cleanup and restructuring, for legibility.
13
+ * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
+ * in terms of both function names and object scope. Scope is specified by
15
+ * the the "this" context of NoJQueryPostMessageMixin();
16
+ * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
+ * at least three different GitHub users requesting the removal of this
18
+ * "Opera sniff" on the original project's Issues page, so I figured this
19
+ * would be a relatively safe change.
20
+ * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
+ * strings. I actually prefer this structure anyway. `receiveMessage` does
22
+ * not implement a corresponding deserialization step, and as such it seems
23
+ * cleaner and more symmetric to leave both data serialization and
24
+ * deserialization to the client.
25
+ * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
+ * 6. The `$:nomunge` YUI option is no longer necessary.
27
+ */
28
+
29
+ function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
+
31
+ var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
+ intervalId, lastHash, cacheBust = 1;
33
+
34
+ if (window.postMessage) {
35
+
36
+ if (window.addEventListener) {
37
+ setMessageCallback = function(callback) {
38
+ window.addEventListener('message', callback, false);
39
+ }
40
+
41
+ unsetMessageCallback = function(callback) {
42
+ window.removeEventListener('message', callback, false);
43
+ }
44
+ } else {
45
+ setMessageCallback = function(callback) {
46
+ window.attachEvent('onmessage', callback);
47
+ }
48
+
49
+ unsetMessageCallback = function(callback) {
50
+ window.detachEvent('onmessage', callback);
51
+ }
52
+ }
53
+
54
+ this[postBinding] = function(message, targetUrl, target) {
55
+ if (!targetUrl) {
56
+ return;
57
+ }
58
+
59
+ // The browser supports window.postMessage, so call it with a targetOrigin
60
+ // set appropriately, based on the targetUrl parameter.
61
+ target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
+ }
63
+
64
+ // Since the browser supports window.postMessage, the callback will be
65
+ // bound to the actual event associated with window.postMessage.
66
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
+ // Unbind an existing callback if it exists.
68
+ if (currentMsgCallback) {
69
+ unsetMessageCallback(currentMsgCallback);
70
+ currentMsgCallback = null;
71
+ }
72
+
73
+ if (!callback) {
74
+ return false;
75
+ }
76
+
77
+ // Bind the callback. A reference to the callback is stored for ease of
78
+ // unbinding.
79
+ currentMsgCallback = setMessageCallback(function(e) {
80
+ switch(Object.prototype.toString.call(sourceOrigin)) {
81
+ case '[object String]':
82
+ if (sourceOrigin !== e.origin) {
83
+ return false;
84
+ }
85
+ break;
86
+ case '[object Function]':
87
+ if (sourceOrigin(e.origin)) {
88
+ return false;
89
+ }
90
+ break;
91
+ }
92
+
93
+ callback(e);
94
+ });
95
+ };
96
+
97
+ } else {
98
+
99
+ this[postBinding] = function(message, targetUrl, target) {
100
+ if (!targetUrl) {
101
+ return;
102
+ }
103
+
104
+ // The browser does not support window.postMessage, so set the location
105
+ // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
+ // bust parameter is added to ensure that repeat messages trigger the
107
+ // callback.
108
+ target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
+ }
110
+
111
+ // Since the browser sucks, a polling loop will be started, and the
112
+ // callback will be called whenever the location.hash changes.
113
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
+ if (intervalId) {
115
+ clearInterval(intervalId);
116
+ intervalId = null;
117
+ }
118
+
119
+ if (callback) {
120
+ delay = typeof sourceOrigin === 'number'
121
+ ? sourceOrigin
122
+ : typeof delay === 'number'
123
+ ? delay
124
+ : 100;
125
+
126
+ intervalId = setInterval(function(){
127
+ var hash = document.location.hash,
128
+ re = /^#?\d+&/;
129
+ if ( hash !== lastHash && re.test( hash ) ) {
130
+ lastHash = hash;
131
+ callback({ data: hash.replace( re, '' ) });
132
+ }
133
+ }, delay );
134
+ }
135
+ };
136
+
137
+ }
138
+
139
+ return this;
140
+ }
freemius/assets/js/nojquery.ba-postmessage.min.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * nojquery-postmessage by Jeff Lee
3
+ * a non-jQuery fork of:
4
+ *
5
+ * jQuery postMessage - v0.5 - 9/11/2009
6
+ * http://benalman.com/projects/jquery-postmessage-plugin/
7
+ *
8
+ * Copyright (c) 2009 "Cowboy" Ben Alman
9
+ * Dual licensed under the MIT and GPL licenses.
10
+ * http://benalman.com/about/license/
11
+ */
12
+ function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
freemius/assets/js/postmessage.js ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($, undef) {
2
+ var global = this;
3
+
4
+ // Namespace.
5
+ global.FS = global.FS || {};
6
+
7
+ global.FS.PostMessage = function ()
8
+ {
9
+ var
10
+ _is_child = false,
11
+ _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
+ _callbacks = {},
13
+ _base_url,
14
+ _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
+ _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
+ _init = function () {
17
+ _postman.receiveMessage(function (e) {
18
+ var data = JSON.parse(e.data);
19
+
20
+ if (_callbacks[data.type]) {
21
+ for (var i = 0; i < _callbacks[data.type].length; i++) {
22
+ // Execute type callbacks.
23
+ _callbacks[data.type][i](data.data);
24
+ }
25
+ }
26
+ }, _base_url);
27
+ };
28
+
29
+ return {
30
+ init : function (url)
31
+ {
32
+ _base_url = url;
33
+ _init();
34
+
35
+ // Automatically receive forward messages.
36
+ FS.PostMessage.receiveOnce('forward', function (data){
37
+ window.location = data.url;
38
+ });
39
+ },
40
+ init_child : function ()
41
+ {
42
+ this.init(_parent_subdomain);
43
+
44
+ _is_child = true;
45
+
46
+ // Post height of a child right after window is loaded.
47
+ $(window).bind('load', function () {
48
+ FS.PostMessage.postHeight();
49
+ });
50
+
51
+ },
52
+ postHeight : function (diff, wrapper) {
53
+ diff = diff || 0;
54
+ wrapper = wrapper || '#wrap_section';
55
+ this.post('height', {
56
+ height: diff + $(wrapper).outerHeight(true)
57
+ });
58
+ },
59
+ post : function (type, data, iframe)
60
+ {
61
+ console.debug('PostMessage.post', type);
62
+
63
+ if (iframe)
64
+ {
65
+ // Post to iframe.
66
+ _postman.postMessage(JSON.stringify({
67
+ type: type,
68
+ data: data
69
+ }), iframe.src, iframe.contentWindow);
70
+ }
71
+ else {
72
+ // Post to parent.
73
+ _postman.postMessage(JSON.stringify({
74
+ type: type,
75
+ data: data
76
+ }), _parent_url, window.parent);
77
+ }
78
+ },
79
+ receive: function (type, callback)
80
+ {
81
+ console.debug('PostMessage.receive', type);
82
+
83
+ if (undef === _callbacks[type])
84
+ _callbacks[type] = [];
85
+
86
+ _callbacks[type].push(callback);
87
+ },
88
+ receiveOnce: function (type, callback)
89
+ {
90
+ if (this.is_set(type))
91
+ return;
92
+
93
+ this.receive(type, callback);
94
+ },
95
+ // Check if any callbacks assigned to a specified message type.
96
+ is_set: function (type)
97
+ {
98
+ return (undef != _callbacks[type]);
99
+ },
100
+ parent_url: function ()
101
+ {
102
+ return _parent_url;
103
+ },
104
+ parent_subdomain: function ()
105
+ {
106
+ return _parent_subdomain;
107
+ }
108
+ };
109
+ }();
110
+ })(jQuery);
freemius/assets/scss/_colors.scss ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $menu-hover-color: #333;
2
+ $darkest-color: #000;
3
+ $fms-live-color: #71ae00;
4
+ $fms-test-color: #f7941d;
5
+ $fms-link-color: #29abe1;
6
+ $fms-link-hover-color: darken(#29abe1, 10%);
7
+ $body-bkg: #111;
8
+ $special-color: #d3135a;
9
+ $body-color: #f1f1f1;
10
+ $fms-white: #f1f1f1;
11
+ $container-bkg: #222;
12
+ $container-bkg-odd: #262626;
13
+ $container-border-color: #333;
14
+ $table-head-bkg: #333;
15
+ $table-head-color: #999;
16
+ $info-color: #999;
17
+ $error-color: #ff0000;
18
+
19
+ $fs-logo-blue-color: #29abe1;
20
+ $fs-logo-green-color: #71ae00;
21
+ $fs-logo-magenta-color: #d3135a;
22
+
23
+ $fs-notice-promotion-border-color: #00a0d2;
24
+ $fs-notice-promotion-bkg: #f2fcff;
25
+
26
+ // WordPress colors.
27
+ $page-header-bkg: #333;
28
+ $page-header-color: $fms-white;
29
+ $text-dark-color: #333;
30
+ $text-light-color: #666;
31
+ $text-lightest-color: #999;
32
+
33
+ // WP Buttons.
34
+ $button-primary-bkg: #6bc406;
35
+ $button-primary-color: $fms-white;
36
+ $button-secondary-bkg: #333;
37
+ $button-secondary-color: $fms-white;
38
+ $featured-color: #6bc406;
39
+ $wp-selected-color: #0074a3;
40
+
41
+ $wordpress_color: #01749A;
42
+ $blogger_color: #ff8100;
43
+ $wix_color: #fac102;
44
+ $shopify_color: #80d100;
45
+ $addthis_color: #fe6d4e;
46
+ $tumblr_color: #34506b;
47
+ $zepo_color: #00baf2;
48
+ $jquery_color: #000919;
49
+ $javascript_color: #00baf2;
50
+ $squarespace_color: #000;
51
+
52
+ $blog_color: #ff6600;
53
+ $facebook_color: #3b5998;
54
+ $twitter_color: #4099ff;
55
+ $linkedin_color: #4875b4;
56
+ $youtube_color: #ff3333;
57
+ $gplus_color: #c63d2d;
58
+
freemius/assets/scss/_functions.scss ADDED
File without changes
freemius/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
freemius/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---- CSS3 SASS MIXINS ----
2
+ // https://github.com/madr/css3-sass-mixins
3
+ //
4
+ // Copyright (C) 2011 by Anders Ytterström
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ // THE SOFTWARE.
23
+ //
24
+
25
+ // ---- LEGACY IE SUPPORT USING FILTERS ----
26
+ // Should IE filters be used or not?
27
+ // PROS: gradients, drop shadows etc will be handled by css.
28
+ // CONS: will harm the site performance badly,
29
+ // especially on sites with heavy rendering and scripting.
30
+ $useIEFilters: 0;
31
+ // might be 0 or 1. disabled by default.
32
+ // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
+
34
+
35
+ @mixin background-size ($value) {
36
+ -webkit-background-size: $value;
37
+ background-size: $value;
38
+ }
39
+
40
+ @mixin border-image ($path, $offsets, $repeats) {
41
+ -moz-border-image: $path $offsets $repeats;
42
+ -o-border-image: $path $offsets $repeats;
43
+ -webkit-border-image: $path $offsets $repeats;
44
+ border-image: $path $offsets $repeats;
45
+ }
46
+
47
+ @mixin border-radius ($values...) {
48
+ -moz-border-radius: $values;
49
+ -webkit-border-radius: $values;
50
+ border-radius: $values;
51
+ /*-moz-background-clip: padding;
52
+ -webkit-background-clip: padding-box;
53
+ background-clip: padding-box;*/
54
+ }
55
+
56
+ @mixin box-shadow ($values...) {
57
+ -moz-box-shadow: $values;
58
+ -webkit-box-shadow: $values;
59
+ box-shadow: $values;
60
+ }
61
+
62
+ //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
+ // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
+ // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
+ // box-shadow: $x $y $offset $spread $hex $inset;
66
+ //
67
+ // @if $ie == 1 {
68
+ // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
+ // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
+ // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
+ // }
72
+ //}
73
+
74
+ @mixin box-sizing($value) {
75
+ -moz-box-sizing: $value;
76
+ -webkit-box-sizing: $value;
77
+ box-sizing: $value;
78
+ }
79
+
80
+ // requires sass 3.2
81
+ //@mixin keyframes {
82
+ // @-moz-keyframes { @content; }
83
+ // @-ms-keyframes { @content; }
84
+ // @-o-keyframes { @content; }
85
+ // @-webkit-keyframes { @content; }
86
+ // @keyframes { @content; }
87
+ //}
88
+
89
+ @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
+ @if $ie != 1 { background-color: $to; }
91
+
92
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
+ background-image: -webkit-linear-gradient(top, $from, $to);
94
+ background-image: -moz-linear-gradient(top, $from, $to);
95
+ background-image: -ms-linear-gradient(top, $from, $to);
96
+ background-image: -o-linear-gradient(top, $from, $to);
97
+ background-image: linear-gradient(top, bottom, $from, $to);
98
+
99
+ @if $ie == 1 {
100
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
+ }
102
+ }
103
+
104
+ @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
+ @if $ie != 1 { background-color: $endColor; }
106
+
107
+ background-color: $endColor;
108
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
+ background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
+ background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
+ background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
+ background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
+ background-repeat: repeat-x;
114
+ @if $ie == 1 {
115
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
+ }
117
+ }
118
+
119
+ @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
+ @if $ie != 1 { background-color: $to; }
121
+
122
+ background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
+ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
+ background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
+ background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
+ background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
+ background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
+ background-color: $from;
129
+
130
+ @if $ie == 1 {
131
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
+ }
133
+ }
134
+
135
+ /*@mixin rgba-bg ($hex, $alpha, $ie: $useIEFilters) {
136
+ @if $ie == 1 {
137
+ background-color: none;
138
+ $hexopac: ie-hex-str(rgba($hex, $alpha));
139
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}}');
140
+ -ms-filter: quote(progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}'));
141
+ }
142
+ @else {
143
+ background-color: $hex;
144
+ background-color: rgba($hex, $alpha);
145
+ }
146
+ }*/
147
+
148
+ @mixin perspective($perspective) {
149
+ -moz-perspective: $perspective;
150
+ -ms-perspective: $perspective;
151
+ -webkit-perspective: $perspective;
152
+ perspective: $perspective;
153
+ -moz-transform-style: preserve-3d;
154
+ -ms-transform-style: preserve-3d;
155
+ -webkit-transform-style: preserve-3d;
156
+ transform-style: preserve-3d;
157
+ }
158
+
159
+ @mixin transform ($transforms) {
160
+ -moz-transform: $transforms;
161
+ -o-transform: $transforms;
162
+ -ms-transform: $transforms;
163
+ -webkit-transform: $transforms;
164
+ transform: $transforms;
165
+ }
166
+
167
+ @mixin matrix ($a, $b, $c, $d, $e, $f) {
168
+ -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
169
+ -o-transform: matrix($a, $b, $c, $d, $e, $f);
170
+ -ms-transform: matrix($a, $b, $c, $d, $e, $f);
171
+ -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
172
+ transform: matrix($a, $b, $c, $d, $e, $f);
173
+ }
174
+
175
+ @mixin rotate ($deg) {
176
+ @include transform(rotate(#{$deg}deg));
177
+ }
178
+
179
+ @mixin scale ($size) {
180
+ @include transform(scale(#{$size}));
181
+ }
182
+
183
+ @mixin translate ($x, $y) {
184
+ @include transform(translate($x, $y));
185
+ }
186
+
187
+ @mixin transition ($value...) {
188
+ -moz-transition: $value;
189
+ -o-transition: $value;
190
+ -ms-transition: $value;
191
+ -webkit-transition: $value;
192
+ transition: $value;
193
+ }
194
+
195
+ // ==== /CSS3 SASS MIXINS ====
196
+
197
+ @mixin opacity($opacity) {
198
+ opacity: $opacity;
199
+ $opacity-ie: $opacity * 100;
200
+ filter: alpha(opacity=$opacity-ie); //IE8
201
+ }
202
+
203
+ @mixin sprite($img, $width, $height: $width, $display: block)
204
+ {
205
+ display: $display;
206
+ background-image: url('#{$img}');
207
+
208
+ @include size($width, $height);
209
+ }
210
+
211
+ @mixin size($width, $height: $width)
212
+ {
213
+ width: $width;
214
+ height: $height;
215
+ }
216
+
217
+ @mixin clearfix
218
+ {
219
+ &:after {
220
+ content: "";
221
+ display: table;
222
+ clear: both;
223
+ }
224
+ }
freemius/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
freemius/assets/scss/_vars.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
freemius/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #fs_account
2
+ {
3
+ .postbox,
4
+ .widefat
5
+ {
6
+ max-width: 700px;
7
+ }
8
+
9
+ h3
10
+ {
11
+ font-size: 1.3em;
12
+ padding: 12px 12px 12px 15px;
13
+ margin: 0 0 12px 0;
14
+ line-height: 1.4;
15
+ border-bottom: 1px solid #F1F1F1;
16
+ }
17
+
18
+ i.dashicons
19
+ {
20
+ font-size: 1.2em;
21
+ height: 1.2em;
22
+ width: 1.2em;
23
+ }
24
+
25
+ .fs-header-actions
26
+ {
27
+ position: absolute;
28
+ top: 17px;
29
+ right: 15px;
30
+ font-size: 0.9em;
31
+
32
+ ul
33
+ {
34
+ margin: 0;
35
+ }
36
+
37
+ li
38
+ {
39
+ form
40
+ {
41
+ display: inline-block;
42
+ }
43
+
44
+ float: left;
45
+ a
46
+ {
47
+ text-decoration: none;
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ .rtl #fs_account .fs-header-actions
54
+ {
55
+ left: 15px;
56
+ right: auto;
57
+ }
58
+
59
+ .fs-key-value-table
60
+ {
61
+ width: 100%;
62
+
63
+ form
64
+ {
65
+ display: inline-block;
66
+ }
67
+
68
+ td label
69
+ {
70
+ background: orange;
71
+ color: #fff;
72
+ display: inline-block;
73
+ border-radius: 3px;
74
+ padding: 5px;
75
+ font-size: 11px;
76
+ line-height: 11px;
77
+ vertical-align: baseline;
78
+ }
79
+
80
+ tr
81
+ {
82
+ td:first-child
83
+ {
84
+ nobr
85
+ {
86
+ font-weight: bold;
87
+ }
88
+
89
+ text-align: right;
90
+
91
+ form
92
+ {
93
+ display: block;
94
+ }
95
+ }
96
+
97
+ td.fs-right
98
+ {
99
+ text-align: right;
100
+ }
101
+
102
+ &.fs-odd
103
+ {
104
+ background: #ebebeb;
105
+ }
106
+ }
107
+
108
+ td, th
109
+ {
110
+ padding: 10px;
111
+ }
112
+
113
+ var, code
114
+ {
115
+ color: #0073AA;
116
+ font-size: 16px;
117
+ background: none;
118
+ }
119
+ }
120
+
121
+ #fs_addons
122
+ {
123
+ td:first-child,
124
+ th:first-child
125
+ {
126
+ text-align: left;
127
+ font-weight: bold;
128
+ }
129
+ td:last-child,
130
+ th:last-child
131
+ {
132
+ text-align: right;
133
+ }
134
+ th
135
+ {
136
+ font-weight: bold;
137
+ }
138
+ }
freemius/assets/scss/admin/add-ons.scss ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_addons
4
+ {
5
+ .fs-cards-list
6
+ {
7
+ list-style: none;
8
+
9
+ .fs-card
10
+ {
11
+ float: left;
12
+ // height: 185px; // With reviews/ratings
13
+ height: 152px;
14
+ width: 310px;
15
+ padding: 0;
16
+ margin: 0 0 30px 30px;
17
+ font-size: 14px;
18
+ list-style: none;
19
+ border: 1px solid #ddd;
20
+ cursor: pointer;
21
+ position: relative;
22
+
23
+ .fs-overlay
24
+ {
25
+ position: absolute;
26
+ left: 0;
27
+ right: 0;
28
+ bottom: 0;
29
+ top: 0;
30
+ z-index: 9;
31
+ }
32
+
33
+ .fs-inner
34
+ {
35
+ background-color: #fff;
36
+ overflow: hidden;
37
+ height: 100%;
38
+ position: relative;
39
+
40
+ ul
41
+ {
42
+ @include transition(all, 0.15s);
43
+ left: 0;
44
+ right: 0;
45
+ top: 0;
46
+ position: absolute;
47
+
48
+ }
49
+
50
+ li
51
+ {
52
+ list-style: none;
53
+ line-height: 18px;
54
+ padding: 0 15px;
55
+ width: 100%;
56
+ display: block;
57
+ @include box-sizing(border-box);
58
+ }
59
+
60
+ .fs-card-banner
61
+ {
62
+ padding: 0;
63
+ margin: 0;
64
+ line-height: 0;
65
+ display: block;
66
+ height: 100px;
67
+ background-repeat: repeat-x;
68
+ background-size: 100% 100%;
69
+ @include transition(all, 0.15s);
70
+ }
71
+
72
+ .fs-title
73
+ {
74
+ margin: 10px 0 0 0;
75
+ height: 18px;
76
+ overflow: hidden;
77
+ color: #000;
78
+ white-space: nowrap;
79
+ text-overflow: ellipsis;
80
+ font-weight: bold;
81
+ }
82
+
83
+ .fs-offer
84
+ {
85
+ font-size: 0.9em;
86
+ }
87
+
88
+ .fs-description
89
+ {
90
+ background-color: #f9f9f9;
91
+ padding: 10px 15px 100px 15px;
92
+ border-top: 1px solid #eee;
93
+ margin: 0 0 10px 0;
94
+ color: #777;
95
+ }
96
+ }
97
+
98
+ @media screen and (min-width: 960px) {
99
+ &:hover
100
+ {
101
+ .fs-overlay
102
+ {
103
+ border: 2px solid $fms-link-color;
104
+ margin-left: -1px;
105
+ margin-top: -1px;
106
+ }
107
+
108
+ .fs-inner
109
+ {
110
+ ul
111
+ {
112
+ top: -100px;
113
+ }
114
+
115
+ .fs-card-banner
116
+ {
117
+ // background-position: 50% -100px;
118
+ }
119
+
120
+ .fs-title,
121
+ .fs-offer
122
+ {
123
+ color: $fms-link-color;
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ #TB_window
133
+ {
134
+ &, iframe
135
+ {
136
+ width: 772px !important;
137
+ }
138
+ }
139
+
140
+ #plugin-information
141
+ {
142
+ #section-description
143
+ {
144
+ h2, h3, p, b, i, blockquote, li, ul, ol
145
+ {
146
+ clear: none;
147
+ }
148
+
149
+ .fs-selling-points
150
+ {
151
+ padding-bottom: 10px;
152
+ border-bottom: 1px solid #ddd;
153
+
154
+ ul
155
+ {
156
+ margin: 0;
157
+
158
+ li
159
+ {
160
+ padding: 0;
161
+ list-style: none outside none;
162
+
163
+ i.dashicons
164
+ {
165
+ color: $fs-logo-green-color;
166
+ font-size: 3em;
167
+ vertical-align: middle;
168
+ line-height: 30px;
169
+ float: left;
170
+ margin: 0 0 0 -15px;
171
+ }
172
+
173
+ h3
174
+ {
175
+ margin-left: 30px;
176
+ }
177
+ }
178
+ }
179
+ }
180
+
181
+ .fs-screenshots
182
+ {
183
+ @include clearfix();
184
+ ul
185
+ {
186
+ list-style: none;
187
+ margin: 0;
188
+
189
+ li
190
+ {
191
+ width: 225px;
192
+ height: 225px;
193
+ float: left;
194
+ margin-bottom: 20px;
195
+ @include box-sizing(content-box);
196
+
197
+ a
198
+ {
199
+ display: block;
200
+ width: 100%;
201
+ height: 100%;
202
+ border: 1px solid;
203
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.2));
204
+ background-size: cover;
205
+ }
206
+
207
+ &.odd
208
+ {
209
+ margin-right: 20px;
210
+ }
211
+ }
212
+ }
213
+ }
214
+ }
215
+
216
+ .plugin-information-pricing
217
+ {
218
+ background: #FFFEEC;
219
+ margin: -16px;
220
+ padding: 20px 20px 50px 20px;
221
+ border-bottom: 1px solid #DDD;
222
+
223
+ h3
224
+ {
225
+ margin-top: 0;
226
+ }
227
+
228
+ .button
229
+ {
230
+ width: 100%;
231
+ text-align: center;
232
+ font-weight: bold;
233
+ text-transform: uppercase;
234
+ font-size: 1.1em;
235
+ }
236
+
237
+ label
238
+ {
239
+ white-space: nowrap;
240
+ }
241
+ }
242
+
243
+ #section-features
244
+ {
245
+ .fs-features
246
+ {
247
+ margin: -20px -26px;
248
+ }
249
+
250
+ table {
251
+ width: 100%;
252
+ border-spacing: 0;
253
+ border-collapse: separate;
254
+
255
+ thead {
256
+ th
257
+ {
258
+ padding: 10px 0;
259
+ }
260
+
261
+ .fs-price
262
+ {
263
+ color: $fs-logo-green-color;
264
+ font-weight: normal;
265
+ display: block;
266
+ text-align: center;
267
+ }
268
+ }
269
+
270
+ tbody
271
+ {
272
+ td
273
+ {
274
+ border-top: 1px solid #ccc;
275
+ padding: 10px 0;
276
+ text-align: center;
277
+ width: 100px;
278
+ color: $fs-logo-green-color;
279
+
280
+ &:first-child
281
+ {
282
+ text-align: left;
283
+ width: auto;
284
+ color: inherit;
285
+ padding-left: 26px;
286
+ }
287
+ }
288
+ tr.fs-odd
289
+ {
290
+ td
291
+ {
292
+ background: #fefefe;
293
+ }
294
+ }
295
+ }
296
+ }
297
+
298
+ .dashicons-yes
299
+ {
300
+ width: 30px;
301
+ height: 30px;
302
+ font-size: 30px;
303
+ }
304
+ }
305
+ }
306
+
307
+ @media screen and (max-width: 961px)
308
+ {
309
+ #fs_addons
310
+ {
311
+ .fs-cards-list
312
+ {
313
+ .fs-card
314
+ {
315
+ height: 265px;
316
+ }
317
+ }
318
+ }
319
+ }
freemius/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .fs-notice
4
+ {
5
+ position: relative;
6
+
7
+ &.fs-has-title
8
+ {
9
+ margin-bottom: 30px !important;
10
+ }
11
+
12
+ &.success
13
+ {
14
+ color: green;
15
+ // font-weight: normal;
16
+ }
17
+
18
+ &.promotion
19
+ {
20
+ border-color: $fs-notice-promotion-border-color !important;
21
+ background-color: $fs-notice-promotion-bkg !important;
22
+ }
23
+
24
+ .fs-notice-body
25
+ {
26
+ margin: .5em 0;
27
+ padding: 2px;
28
+ }
29
+
30
+ .fs-close
31
+ {
32
+ // position: absolute;
33
+ // top: 2px;
34
+ // bottom: 2px;
35
+ // right: 2px;
36
+ // min-width: 100px;
37
+ // text-align: center;
38
+ // padding-right: 2px;
39
+ cursor: pointer;
40
+ color: #aaa;
41
+ float: right;
42
+
43
+ &:hover
44
+ {
45
+ color: #666;
46
+ // background: #A9A9A9;
47
+ }
48
+
49
+ > *
50
+ {
51
+ margin-top: 7px;
52
+ display: inline-block;
53
+ }
54
+ }
55
+
56
+ label.fs-plugin-title
57
+ {
58
+ background: rgba(0, 0, 0, 0.3);
59
+ color: #fff;
60
+ padding: 2px 10px;
61
+ position: absolute;
62
+ bottom: -22px;
63
+ top: auto;
64
+ right: auto;
65
+ @include border-radius(0 0 3px 3px);
66
+ left: 10px;
67
+ font-size: 12px;
68
+ font-weight: bold;
69
+ cursor: auto;
70
+ }
71
+ }
72
+
73
+ .rtl .fs-notice
74
+ {
75
+ .fs-close
76
+ {
77
+ // left: 2px;
78
+ // right: auto;
79
+ // padding-right: 0;
80
+ // padding-left: 2px;
81
+ float: left;
82
+ }
83
+ }
84
+
85
+ .fs-secure-notice
86
+ {
87
+ position: fixed;
88
+ top: 32px;
89
+ left: 160px;
90
+ right: 0;
91
+ background: rgb(235, 253, 235);
92
+ padding: 10px 20px;
93
+ color: green;
94
+ z-index: 9999;
95
+ box-shadow: 0px 2px 2px rgba(6, 113, 6, 0.3);
96
+ @include opacity(0.95);
97
+
98
+ &:hover
99
+ {
100
+ @include opacity(1);
101
+ }
102
+ }
103
+
104
+ @media screen and (max-width: 960px) {
105
+ .fs-secure-notice
106
+ {
107
+ left: 36px;
108
+ }
109
+ }
110
+
111
+ @media screen and (max-width: 782px) {
112
+ .fs-secure-notice
113
+ {
114
+ left: 0;
115
+ top: 46px;
116
+ text-align: center;
117
+ }
118
+ }
119
+
120
+ span.fs-submenu-item.fs-sub:before
121
+ {
122
+ // Add small arrow.
123
+ content: '\21B3';
124
+ padding: 0 5px;
125
+ }
126
+
127
+ .rtl
128
+ {
129
+ span.fs-submenu-item.fs-sub:before
130
+ {
131
+ // Add small RTL arrow.
132
+ content: '\21B2';
133
+ }
134
+ }
freemius/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ $form_width: 480px;
4
+
5
+ #fs_connect
6
+ {
7
+ width: $form_width;
8
+ @include box-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));
9
+ margin: 20px 0;
10
+
11
+ @media screen and (max-width: ($form_width - 1)) {
12
+ @include box-shadow(none);
13
+ width: auto;
14
+ margin: 0 0 0 -10px;
15
+ }
16
+
17
+ .fs-content
18
+ {
19
+ background: #fff;
20
+ padding: 15px 20px;
21
+
22
+ p
23
+ {
24
+ margin: 0;
25
+ padding: 0;
26
+ font-size: 1.2em;
27
+ }
28
+ }
29
+
30
+ .fs-actions
31
+ {
32
+ padding: 10px 20px;
33
+ background: #C0C7CA;
34
+
35
+ .button
36
+ {
37
+ padding: 0 10px 1px;
38
+ line-height: 35px;
39
+ height: 37px;
40
+ font-size: 16px;
41
+ margin-bottom: 0;
42
+
43
+ .dashicons
44
+ {
45
+ font-size: 37px;
46
+ margin-left: -8px;
47
+ margin-right: 12px;
48
+ }
49
+
50
+ &.button-primary
51
+ {
52
+ padding-right: 15px;
53
+ padding-left: 15px;
54
+
55
+ &:after
56
+ {
57
+ content: ' \279C';
58
+ }
59
+
60
+ &.fs-loading
61
+ {
62
+ &:after
63
+ {
64
+ content: '';
65
+ }
66
+ }
67
+ }
68
+
69
+ &.button-secondary
70
+ {
71
+ float: right;
72
+ }
73
+ }
74
+
75
+ // .fs-skip
76
+ // {
77
+ // line-height: 38px;
78
+ // vertical-align: middle;
79
+ // text-decoration: none;
80
+ // margin-left: 10px;
81
+ // }
82
+ }
83
+
84
+ &.fs-anonymous-disabled
85
+ {
86
+ .fs-actions
87
+ {
88
+ .button.button-primary
89
+ {
90
+ width: 100%;
91
+ }
92
+ }
93
+ }
94
+
95
+ .fs-permissions
96
+ {
97
+ padding: 10px 20px;
98
+ background: #FEFEFE;
99
+ // background: #F1F1F1;
100
+ @include transition(background 0.5s ease);
101
+
102
+ .fs-trigger
103
+ {
104
+ font-size: 0.9em;
105
+ text-decoration: none;
106
+ text-align: center;
107
+ display: block;
108
+ }
109
+
110
+ ul
111
+ {
112
+ height: 0;
113
+ overflow: hidden;
114
+ margin: 0;
115
+
116
+ li
117
+ {
118
+ margin-bottom: 12px;
119
+
120
+ &:last-child
121
+ {
122
+ margin-bottom: 0;
123
+ }
124
+
125
+ i.dashicons
126
+ {
127
+ float: left;
128
+ font-size: 40px;
129
+ width: 40px;
130
+ height: 40px;
131
+ }
132
+
133
+ div
134
+ {
135
+ margin-left: 55px;
136
+
137
+ span
138
+ {
139
+ font-weight: bold;
140
+ text-transform: uppercase;
141
+ color: #23282d;
142
+ }
143
+
144
+ p
145
+ {
146
+ margin: 2px 0 0 0;
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ &.fs-open
153
+ {
154
+ background: #fff;
155
+
156
+ ul
157
+ {
158
+ height: auto;
159
+ margin: 20px 20px 10px 20px;
160
+ }
161
+ }
162
+
163
+ @media screen and (max-width: ($form_width - 1)) {
164
+ background: #fff;
165
+
166
+ .fs-trigger
167
+ {
168
+ display: none;
169
+ }
170
+
171
+ ul
172
+ {
173
+ height: auto;
174
+ margin: 20px;
175
+ }
176
+ }
177
+ }
178
+
179
+ $icon_size: 80px;
180
+ $wp_logo_padding: $icon_size / 10;
181
+ $icons_top: 10px;
182
+
183
+ .fs-visual
184
+ {
185
+ padding: 12px;
186
+ line-height: 0;
187
+ background: #fafafa;
188
+ height: $icon_size;
189
+ position: relative;
190
+
191
+ .fs-site-icon
192
+ {
193
+ position: absolute;
194
+ left: 20px;
195
+ top: $icons_top;
196
+ }
197
+
198
+ .fs-connect-logo
199
+ {
200
+ position: absolute;
201
+ right: 20px;
202
+ top: $icons_top;
203
+ }
204
+
205
+ .fs-plugin-icon
206
+ {
207
+ position: absolute;
208
+ top: $icons_top;
209
+ left: 50%;
210
+ margin-left: - ($icon_size / 2);
211
+ }
212
+
213
+ .fs-plugin-icon,
214
+ .fs-site-icon,
215
+ img,
216
+ object
217
+ {
218
+ width: $icon_size;
219
+ height: $icon_size;
220
+ }
221
+
222
+ .dashicons-wordpress
223
+ {
224
+ font-size: $icon_size - ($wp_logo_padding * 2);
225
+ background: $wordpress_color;
226
+ color: #fff;
227
+ width: $icon_size - ($wp_logo_padding * 2);
228
+ height: $icon_size - ($wp_logo_padding * 2);
229
+ padding: $wp_logo_padding;
230
+ }
231
+
232
+ .dashicons-plus
233
+ {
234
+ position: absolute;
235
+ top: 50%;
236
+ font-size: 30px;
237
+ margin-top: -10px;
238
+ color: #bbb;
239
+
240
+ &.fs-first
241
+ {
242
+ left: 28%;
243
+ }
244
+ &.fs-second
245
+ {
246
+ left: 65%;
247
+ }
248
+ }
249
+
250
+ .fs-plugin-icon,
251
+ .fs-connect-logo,
252
+ .fs-site-icon
253
+ {
254
+ border: 1px solid #ccc;
255
+ padding: 1px;
256
+ background: #fff;
257
+ }
258
+ }
259
+
260
+ .fs-terms
261
+ {
262
+ text-align: center;
263
+ font-size: 0.85em;
264
+ padding: 5px;
265
+ background: rgba(0, 0, 0, 0.05);
266
+
267
+ &, a
268
+ {
269
+ color: #999;
270
+ }
271
+
272
+ a
273
+ {
274
+ text-decoration: none;
275
+ }
276
+ }
277
+ }
278
+
279
+ .rtl
280
+ {
281
+ #fs_connect
282
+ {
283
+ .fs-actions
284
+ {
285
+ padding: 10px 20px;
286
+ background: #C0C7CA;
287
+
288
+ .button
289
+ {
290
+ .dashicons
291
+ {
292
+ font-size: 37px;
293
+ margin-left: -8px;
294
+ margin-right: 12px;
295
+ }
296
+
297
+ &.button-primary
298
+ {
299
+ &:after
300
+ {
301
+ content: ' \000bb';
302
+ }
303
+
304
+ &.fs-loading
305
+ {
306
+ &:after
307
+ {
308
+ content: '';
309
+ }
310
+ }
311
+ }
312
+
313
+ &.button-secondary
314
+ {
315
+ float: left;
316
+ }
317
+ }
318
+ }
319
+
320
+ .fs-permissions
321
+ {
322
+ ul
323
+ {
324
+ li
325
+ {
326
+ div
327
+ {
328
+ margin-right: 55px;
329
+ margin-left: 0;
330
+ }
331
+
332
+ i.dashicons
333
+ {
334
+ float: right;
335
+ }
336
+
337
+ }
338
+ }
339
+ }
340
+
341
+ .fs-visual
342
+ {
343
+ .fs-site-icon
344
+ {
345
+ right: 20px;
346
+ left: auto;
347
+ }
348
+
349
+ .fs-connect-logo
350
+ {
351
+ right: auto;
352
+ left: 20px;
353
+ }
354
+ }
355
+ }
356
+ }
357
+
358
+ .wp-pointer-content
359
+ {
360
+ #fs_connect
361
+ {
362
+ margin: 0;
363
+ @include box-shadow(none);
364
+ }
365
+ }
366
+
367
+ .fs-opt-in-pointer
368
+ {
369
+ .wp-pointer-content
370
+ {
371
+ padding: 0;
372
+ }
373
+
374
+ &.wp-pointer-top
375
+ {
376
+ .wp-pointer-arrow
377
+ {
378
+ border-bottom-color: #dfdfdf;
379
+ }
380
+ .wp-pointer-arrow-inner
381
+ {
382
+ border-bottom-color: #fafafa;
383
+ }
384
+ }
385
+
386
+ &.wp-pointer-bottom
387
+ {
388
+ .wp-pointer-arrow
389
+ {
390
+ border-top-color: #dfdfdf;
391
+ }
392
+ .wp-pointer-arrow-inner
393
+ {
394
+ border-top-color: #fafafa;
395
+ }
396
+ }
397
+
398
+ &.wp-pointer-left
399
+ {
400
+ .wp-pointer-arrow
401
+ {
402
+ border-right-color: #dfdfdf;
403
+ }
404
+ .wp-pointer-arrow-inner
405
+ {
406
+ border-right-color: #fafafa;
407
+ }
408
+ }
409
+
410
+ &.wp-pointer-right
411
+ {
412
+ .wp-pointer-arrow
413
+ {
414
+ border-left-color: #dfdfdf;
415
+ }
416
+ .wp-pointer-arrow-inner
417
+ {
418
+ border-left-color: #fafafa;
419
+ }
420
+ }
421
+ }
freemius/assets/scss/admin/deactivation-feedback.scss ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal {
2
+ position: fixed;
3
+ overflow: auto;
4
+ height: 100%;
5
+ width: 100%;
6
+ top: 0;
7
+ z-index: 100000;
8
+ display: none;
9
+ background: rgba(0, 0, 0, 0.6);
10
+
11
+ .fs-modal-dialog {
12
+ background: transparent;
13
+ position: absolute;
14
+ left: 50%;
15
+ margin-left: -298px;
16
+ padding-bottom: 30px;
17
+ top: -100%;
18
+ z-index: 100001;
19
+ width: 596px;
20
+
21
+ @media (max-width: 650px) {
22
+ margin-left: -50%;
23
+ box-sizing: border-box;
24
+ padding-left: 10px;
25
+ padding-right: 10px;
26
+ width: 100%;
27
+
28
+ .fs-modal-panel > h3 > strong {
29
+ font-size: 1.3em;
30
+ }
31
+
32
+ li.reason {
33
+ margin-bottom: 10px;
34
+
35
+ .reason-input {
36
+ margin-left: 29px;
37
+ }
38
+
39
+ label {
40
+ display: table;
41
+
42
+ > span {
43
+ display: table-cell;
44
+ font-size: 1.3em;
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ &.active {
52
+ display: block;
53
+
54
+ &:before {
55
+ display: block;
56
+ }
57
+
58
+ .fs-modal-dialog {
59
+ top: 10%;
60
+ }
61
+ }
62
+
63
+ .fs-modal-body,
64
+ .fs-modal-footer {
65
+ border: 0;
66
+ background: #fefefe;
67
+ padding: 20px;
68
+ }
69
+
70
+ .fs-modal-body {
71
+ border-bottom: 0;
72
+
73
+ h2 {
74
+ font-size: 20px;
75
+ }
76
+
77
+ > div {
78
+ margin-top: 10px;
79
+
80
+ h2 {
81
+ font-weight: bold;
82
+ font-size: 20px;
83
+ margin-top: 0;
84
+ }
85
+ }
86
+ }
87
+
88
+ .fs-modal-footer {
89
+ border-top: #eeeeee solid 1px;
90
+ text-align: right;
91
+
92
+ > .button {
93
+ margin: 0 7px;
94
+
95
+ &:first-child {
96
+ margin: 0;
97
+ }
98
+ }
99
+ }
100
+
101
+ .fs-modal-panel:not(.active) {
102
+ display: none;
103
+ }
104
+
105
+ .reason-input {
106
+ margin: 3px 0 3px 22px;
107
+
108
+ input, textarea {
109
+ width: 100%;
110
+ }
111
+ }
112
+ }
113
+
114
+ body.has-fs-modal {
115
+ overflow: hidden;
116
+ }
117
+
118
+ #the-list .deactivate > .fs-slug {
119
+ display: none;
120
+ }
freemius/composer.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "freemius/wordpress-sdk",
3
+ "description": "Freemius WordPress SDK",
4
+ "keywords": ["freemius", "wordpress", "plugin", "sdk"],
5
+ "homepage": "https://freemius.com",
6
+ "license": "GPL-2.0+",
7
+ "require": {
8
+ "php": ">=5.2"
9
+ }
10
+ }
freemius/config.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SLUG', 'freemius' );
14
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
15
+ define( 'WP_FS__DEV_MODE', false );
16
+ }
17
+
18
+ /**
19
+ * API Connectivity Simulation
20
+ */
21
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false && WP_FS__DEV_MODE );
22
+ define( 'WP_FS__SIMULATE_NO_CURL', false && WP_FS__DEV_MODE );
23
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false && WP_FS__DEV_MODE );
24
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false && WP_FS__DEV_MODE );
25
+ if ( WP_FS__SIMULATE_NO_CURL ) {
26
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
27
+ }
28
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
29
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
30
+ }
31
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
32
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
33
+ }
34
+
35
+ /**
36
+ * If your dev environment supports custom public network IP setup
37
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
38
+ * and uncomment it during dev.
39
+ */
40
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
41
+ // VVV default public network IP.
42
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
43
+
44
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
45
+ }
46
+
47
+ /**
48
+ * If true and running with secret key, the opt-in process
49
+ * will skip the email activation process which is invoked
50
+ * when the email of the context user already exist in Freemius
51
+ * database (as a security precaution, to prevent sharing user
52
+ * secret with unauthorized entity).
53
+ *
54
+ * IMPORTANT:
55
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
56
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
57
+ * CLOCK IS SYNCED.
58
+ */
59
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
60
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
61
+ }
62
+
63
+ /**
64
+ * Directories
65
+ */
66
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
67
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
68
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
69
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
70
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
71
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
72
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
73
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
74
+
75
+
76
+ /**
77
+ * Domain / URL / Address
78
+ */
79
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp:8080' );
80
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
81
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
82
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
83
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
84
+
85
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
86
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
87
+
88
+ define( 'WP_FS__IS_PRODUCTION_MODE', ! defined( 'WP_FS__DEV_MODE' ) || ! WP_FS__DEV_MODE || ( WP_FS__TESTING_DOMAIN !== $_SERVER['HTTP_HOST'] ) );
89
+
90
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
91
+
92
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
93
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
94
+ } else {
95
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
96
+ is_string( WP_FS__REMOTE_ADDR ) &&
97
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) == '127.' ||
98
+ WP_FS__REMOTE_ADDR == '::1' )
99
+ );
100
+ }
101
+
102
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
103
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
104
+
105
+ // Set API address for local testing.
106
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
107
+ define( 'FS_API__ADDRESS', 'http://api.freemius:8080' );
108
+ define( 'FS_API__SANDBOX_ADDRESS', 'http://sandbox-api.freemius:8080' );
109
+ }
110
+
111
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
112
+
113
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
114
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
115
+ }
116
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
117
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
118
+ }
119
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
120
+
121
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
122
+ // Checks if CloudFlare's HTTPS (Flexible SSL support)
123
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ||
124
+ // Check if HTTPS request.
125
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
126
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
127
+ );
128
+
129
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
130
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
131
+
132
+ /**
133
+ * Billing Frequencies
134
+ */
135
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
136
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
137
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
138
+
139
+ /**
140
+ * Plans
141
+ */
142
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
143
+ define( 'WP_FS__PLAN_FREE', 'free' );
144
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
145
+
146
+ /**
147
+ * Times in seconds
148
+ */
149
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
150
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
151
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
152
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
153
+
154
+ /**
155
+ * Debugging
156
+ */
157
+ define( 'WP_FS__DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg'] ) );
158
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
159
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-n-d H:i:s' );
160
+
161
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
162
+ error_reporting( E_ALL );
163
+ ini_set( 'error_reporting', E_ALL );
164
+ ini_set( 'display_errors', true );
165
+ ini_set( 'html_errors', true );
166
+ }
167
+
168
+
169
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
170
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
171
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
freemius/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,404 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+
13
+ /**
14
+ * - Each instance of Freemius class represents a single plugin
15
+ * install by a single user (the installer of the plugin).
16
+ *
17
+ * - Each website can only have one install of the same plugin.
18
+ *
19
+ * - Install entity is only created after a user connects his account with Freemius.
20
+ *
21
+ * Class Freemius_Abstract
22
+ */
23
+ abstract class Freemius_Abstract {
24
+
25
+ #region Identity ------------------------------------------------------------------
26
+
27
+ /**
28
+ * Check if user registered with Freemius by connecting his account.
29
+ *
30
+ * @since 1.0.1
31
+ * @return bool
32
+ */
33
+ abstract function is_registered();
34
+
35
+ /**
36
+ * Check if the user skipped connecting the account with Freemius.
37
+ *
38
+ * @since 1.0.7
39
+ *
40
+ * @return bool
41
+ */
42
+ abstract function is_anonymous();
43
+
44
+ /**
45
+ * Check if the user currently in activation mode.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_activation_mode();
52
+
53
+ #endregion Identity ------------------------------------------------------------------
54
+
55
+ #region Permissions ------------------------------------------------------------------
56
+
57
+ /**
58
+ * Check if plugin must be WordPress.org compliant.
59
+ *
60
+ * @since 1.0.7
61
+ *
62
+ * @return bool
63
+ */
64
+ abstract function is_org_repo_compliant();
65
+
66
+ /**
67
+ * Check if plugin is allowed to install executable files.
68
+ *
69
+ * @author Vova Feldman (@svovaf)
70
+ * @since 1.0.5
71
+ *
72
+ * @return bool
73
+ */
74
+ function is_allowed_to_install() {
75
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
76
+ }
77
+
78
+ #endregion Permissions ------------------------------------------------------------------
79
+
80
+ /**
81
+ * Check if user in trial or in free plan (not paying).
82
+ *
83
+ * @author Vova Feldman (@svovaf)
84
+ * @since 1.0.4
85
+ *
86
+ * @return bool
87
+ */
88
+ function is_not_paying() {
89
+ return ( $this->is_trial() || $this->is_free_plan() );
90
+ }
91
+
92
+ /**
93
+ * Check if the user has an activated and valid paid license on current plugin's install.
94
+ *
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ abstract function is_paying();
100
+
101
+ /**
102
+ * Check if the user is paying or in trial.
103
+ *
104
+ * @since 1.0.9
105
+ *
106
+ * @return bool
107
+ */
108
+ function is_paying_or_trial() {
109
+ return ( $this->is_paying() || $this->is_trial() );
110
+ }
111
+
112
+ #region Premium Only ------------------------------------------------------------------
113
+
114
+ /**
115
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
116
+ * included in the premium code.
117
+ *
118
+ * Example:
119
+ * if ( freemius()->is__premium_only() ) {
120
+ * ...
121
+ * }
122
+ */
123
+
124
+ /**
125
+ * Returns true when running premium plugin code.
126
+ *
127
+ * @since 1.0.9
128
+ *
129
+ * @return bool
130
+ */
131
+ function is__premium_only() {
132
+ return $this->is_premium();
133
+ }
134
+
135
+ /**
136
+ * Check if the user has an activated and valid paid license on current plugin's install.
137
+ *
138
+ * @since 1.0.9
139
+ *
140
+ * @return bool
141
+ *
142
+ */
143
+ function is_paying__premium_only() {
144
+ return ( $this->is__premium_only() && $this->is_paying() );
145
+ }
146
+
147
+ /**
148
+ * All code wrapped in this statement will be only included in the premium code.
149
+ *
150
+ * @since 1.0.9
151
+ *
152
+ * @param string $plan Plan name
153
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
154
+ *
155
+ * @return bool
156
+ */
157
+ function is_plan__premium_only( $plan, $exact = false ) {
158
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
159
+ }
160
+
161
+ /**
162
+ * Check if plan matches active license' plan or active trial license' plan.
163
+ *
164
+ * All code wrapped in this statement will be only included in the premium code.
165
+ *
166
+ * @since 1.0.9
167
+ *
168
+ * @param string $plan Plan name
169
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
170
+ *
171
+ * @return bool
172
+ */
173
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
174
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
175
+ }
176
+
177
+ /**
178
+ * Check if the user is paying or in trial.
179
+ *
180
+ * All code wrapped in this statement will be only included in the premium code.
181
+ *
182
+ * @since 1.0.9
183
+ *
184
+ * @return bool
185
+ */
186
+ function is_paying_or_trial__premium_only() {
187
+ return $this->is_premium() && $this->is_paying_or_trial();
188
+ }
189
+
190
+ /**
191
+ * Check if the user has an activated and valid paid license on current plugin's install.
192
+ *
193
+ * @since 1.0.4
194
+ *
195
+ * @return bool
196
+ *
197
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
198
+ * @using Alias to is_paying__premium_only()
199
+ */
200
+ function is_paying__fs__() {
201
+ return $this->is_paying__premium_only();
202
+ }
203
+
204
+ #endregion Premium Only ------------------------------------------------------------------
205
+
206
+ #region Trial ------------------------------------------------------------------
207
+
208
+ /**
209
+ * Check if the user in a trial.
210
+ *
211
+ * @since 1.0.3
212
+ *
213
+ * @return bool
214
+ */
215
+ abstract function is_trial();
216
+
217
+ /**
218
+ * Check if trial already utilized.
219
+ *
220
+ * @since 1.0.9
221
+ *
222
+ * @return bool
223
+ */
224
+ abstract function is_trial_utilized();
225
+
226
+ #endregion Trial ------------------------------------------------------------------
227
+
228
+ #region Plans ------------------------------------------------------------------
229
+
230
+ /**
231
+ * Check if plugin using the free plan.
232
+ *
233
+ * @since 1.0.4
234
+ *
235
+ * @return bool
236
+ */
237
+ abstract function is_free_plan();
238
+
239
+ /**
240
+ * @since 1.0.2
241
+ *
242
+ * @param string $plan Plan name
243
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
244
+ *
245
+ * @return bool
246
+ */
247
+ abstract function is_plan( $plan, $exact = false );
248
+
249
+ /**
250
+ * Check if plan based on trial. If not in trial mode, should return false.
251
+ *
252
+ * @since 1.0.9
253
+ *
254
+ * @param string $plan Plan name
255
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
256
+ *
257
+ * @return bool
258
+ */
259
+ abstract function is_trial_plan( $plan, $exact = false );
260
+
261
+ /**
262
+ * Check if plan matches active license' plan or active trial license' plan.
263
+ *
264
+ * @since 1.0.9
265
+ *
266
+ * @param string $plan Plan name
267
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
268
+ *
269
+ * @return bool
270
+ */
271
+ function is_plan_or_trial( $plan, $exact = false ) {
272
+ return $this->is_plan( $plan, $exact ) ||
273
+ $this->is_trial_plan( $plan, $exact );
274
+ }
275
+
276
+ /**
277
+ * Check if plugin has any paid plans.
278
+ *
279
+ * @author Vova Feldman (@svovaf)
280
+ * @since 1.0.7
281
+ *
282
+ * @return bool
283
+ */
284
+ abstract function has_paid_plan();
285
+
286
+ /**
287
+ * Check if plugin has any free plan, or is it premium only.
288
+ *
289
+ * Note: If no plans configured, assume plugin is free.
290
+ *
291
+ * @author Vova Feldman (@svovaf)
292
+ * @since 1.0.7
293
+ *
294
+ * @return bool
295
+ */
296
+ abstract function has_free_plan();
297
+
298
+ #endregion Plans ------------------------------------------------------------------
299
+
300
+ /**
301
+ * Check if running payments in sandbox mode.
302
+ *
303
+ * @since 1.0.4
304
+ *
305
+ * @return bool
306
+ */
307
+ abstract function is_payments_sandbox();
308
+
309
+ /**
310
+ * Check if running test vs. live plugin.
311
+ *
312
+ * @since 1.0.5
313
+ *
314
+ * @return bool
315
+ */
316
+ abstract function is_live();
317
+
318
+ /**
319
+ * Check if running premium plugin code.
320
+ *
321
+ * @since 1.0.5
322
+ *
323
+ * @return bool
324
+ */
325
+ abstract function is_premium();
326
+
327
+ /**
328
+ * Get upgrade URL.
329
+ *
330
+ * @author Vova Feldman (@svovaf)
331
+ * @since 1.0.2
332
+ *
333
+ * @param string $period Billing cycle
334
+ *
335
+ * @return string
336
+ */
337
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
338
+
339
+ /**
340
+ * Check if Freemius was first added in a plugin update.
341
+ *
342
+ * @author Vova Feldman (@svovaf)
343
+ * @since 1.1.5
344
+ *
345
+ * @return bool
346
+ */
347
+ function is_plugin_update() {
348
+ return ! $this->is_plugin_new_install();
349
+ }
350
+
351
+ /**
352
+ * Check if Freemius was part of the plugin when the user installed it first.
353
+ *
354
+ * @author Vova Feldman (@svovaf)
355
+ * @since 1.1.5
356
+ *
357
+ * @return bool
358
+ */
359
+ abstract function is_plugin_new_install();
360
+
361
+ #region Marketing ------------------------------------------------------------------
362
+
363
+ /**
364
+ * Check if current user purchased any other plugins before.
365
+ *
366
+ * @author Vova Feldman (@svovaf)
367
+ * @since 1.0.9
368
+ *
369
+ * @return bool
370
+ */
371
+ abstract function has_purchased_before();
372
+
373
+ /**
374
+ * Check if current user classified as an agency.
375
+ *
376
+ * @author Vova Feldman (@svovaf)
377
+ * @since 1.0.9
378
+ *
379
+ * @return bool
380
+ */
381
+ abstract function is_agency();
382
+
383
+ /**
384
+ * Check if current user classified as a developer.
385
+ *
386
+ * @author Vova Feldman (@svovaf)
387
+ * @since 1.0.9
388
+ *
389
+ * @return bool
390
+ */
391
+ abstract function is_developer();
392
+
393
+ /**
394
+ * Check if current user classified as a business.
395
+ *
396
+ * @author Vova Feldman (@svovaf)
397
+ * @since 1.0.9
398
+ *
399
+ * @return bool
400
+ */
401
+ abstract function is_business();
402
+
403
+ #endregion ------------------------------------------------------------------
404
+ }
freemius/includes/class-freemius.php ADDED
@@ -0,0 +1,7845 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // "final class"
13
+ class Freemius extends Freemius_Abstract {
14
+ /**
15
+ * SDK Version
16
+ *
17
+ * @var string
18
+ */
19
+ public $version = WP_FS__SDK_VERSION;
20
+
21
+ #region Plugin Info
22
+
23
+ /**
24
+ * @since 1.0.1
25
+ *
26
+ * @var string
27
+ */
28
+ private $_slug;
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ private $_plugin_basename;
36
+ /**
37
+ * @since 1.0.0
38
+ *
39
+ * @var string
40
+ */
41
+ private $_free_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_plugin_dir_path;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_name;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_main_file_path;
60
+ /**
61
+ * @var string[]
62
+ */
63
+ private $_plugin_data;
64
+ /**
65
+ * @since 1.0.9
66
+ *
67
+ * @var string
68
+ */
69
+ private $_plugin_name;
70
+
71
+ #endregion Plugin Info
72
+
73
+ /**
74
+ * @since 1.0.9
75
+ *
76
+ * @var bool If false, don't turn Freemius on.
77
+ */
78
+ private $_is_on;
79
+
80
+ /**
81
+ * @since 1.1.3
82
+ *
83
+ * @var bool If false, don't turn Freemius on.
84
+ */
85
+ private $_is_anonymous;
86
+
87
+ /**
88
+ * @since 1.0.9
89
+ * @var bool If false, issues with connectivity to Freemius API.
90
+ */
91
+ private $_has_api_connection;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
96
+ */
97
+ private $_enable_anonymous;
98
+
99
+ /**
100
+ * @since 1.0.8
101
+ * @var bool Hints the SDK if the plugin has any paid plans.
102
+ */
103
+ private $_has_paid_plans;
104
+
105
+ /**
106
+ * @since 1.0.7
107
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
108
+ */
109
+ private $_is_org_compliant;
110
+
111
+ /**
112
+ * @since 1.0.7
113
+ * @var bool Hints the SDK if the plugin is has add-ons.
114
+ */
115
+ private $_has_addons;
116
+
117
+ /**
118
+ * @since 1.1.6
119
+ * @var string[]bool.
120
+ */
121
+ private $_permissions;
122
+
123
+ /**
124
+ * @var FS_Key_Value_Storage
125
+ */
126
+ private $_storage;
127
+
128
+ /**
129
+ * @since 1.0.0
130
+ *
131
+ * @var FS_Logger
132
+ */
133
+ private $_logger;
134
+ /**
135
+ * @since 1.0.4
136
+ *
137
+ * @var FS_Plugin
138
+ */
139
+ private $_plugin = false;
140
+ /**
141
+ * @since 1.0.4
142
+ *
143
+ * @var FS_Plugin
144
+ */
145
+ private $_parent_plugin = false;
146
+ /**
147
+ * @since 1.1.1
148
+ *
149
+ * @var Freemius
150
+ */
151
+ private $_parent = false;
152
+ /**
153
+ * @since 1.0.1
154
+ *
155
+ * @var FS_User
156
+ */
157
+ private $_user = false;
158
+ /**
159
+ * @since 1.0.1
160
+ *
161
+ * @var FS_Site
162
+ */
163
+ private $_site = false;
164
+ /**
165
+ * @since 1.0.1
166
+ *
167
+ * @var FS_Plugin_License
168
+ */
169
+ private $_license;
170
+ /**
171
+ * @since 1.0.2
172
+ *
173
+ * @var FS_Plugin_Plan[]
174
+ */
175
+ private $_plans = false;
176
+ /**
177
+ * @var FS_Plugin_License[]
178
+ * @since 1.0.5
179
+ */
180
+ private $_licenses = false;
181
+
182
+ /**
183
+ * @since 1.0.1
184
+ *
185
+ * @var FS_Admin_Menu_Manager
186
+ */
187
+ private $_menu;
188
+
189
+ /**
190
+ * @var FS_Admin_Notice_Manager
191
+ */
192
+ private $_admin_notices;
193
+
194
+ /**
195
+ * @since 1.1.6
196
+ *
197
+ * @var FS_Admin_Notice_Manager
198
+ */
199
+ private static $_global_admin_notices;
200
+
201
+ /**
202
+ * @var FS_Logger
203
+ * @since 1.0.0
204
+ */
205
+ private static $_static_logger;
206
+
207
+ /**
208
+ * @var FS_Option_Manager
209
+ * @since 1.0.2
210
+ */
211
+ private static $_accounts;
212
+
213
+ /**
214
+ * @var Freemius[]
215
+ */
216
+ private static $_instances = array();
217
+
218
+
219
+ /* Ctor
220
+ ------------------------------------------------------------------------------------------------------------------*/
221
+
222
+ private function __construct( $slug ) {
223
+ $this->_slug = $slug;
224
+
225
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
226
+
227
+ $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
228
+
229
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file();
230
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
231
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
232
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
233
+
234
+ $base_name_split = explode( '/', $this->_plugin_basename );
235
+ $this->_plugin_dir_name = $base_name_split[0];
236
+
237
+ if ( $this->_logger->is_on() ) {
238
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
239
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
240
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
241
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
242
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
243
+ }
244
+
245
+ // Remember link between file to slug.
246
+ $this->store_file_slug_map();
247
+
248
+ // Store plugin's initial install timestamp.
249
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
250
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
251
+ }
252
+
253
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
254
+
255
+ $this->_admin_notices = FS_Admin_Notice_Manager::instance(
256
+ $slug,
257
+ is_object( $this->_plugin ) ? $this->_plugin->title : ''
258
+ );
259
+
260
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ) {
261
+ FS_Api::clear_cache();
262
+ }
263
+
264
+ $this->_register_hooks();
265
+
266
+ $this->_load_account();
267
+
268
+ $this->_version_updates_handler();
269
+ }
270
+
271
+ /**
272
+ * @author Vova Feldman (@svovaf)
273
+ * @since 1.0.9
274
+ */
275
+ private function _version_updates_handler() {
276
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
277
+ // Freemius version upgrade mode.
278
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
279
+ $this->_storage->sdk_version = $this->version;
280
+
281
+ if ( empty( $this->_storage->sdk_last_version ) ||
282
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
283
+ ) {
284
+ $this->_storage->sdk_upgrade_mode = true;
285
+ $this->_storage->sdk_downgrade_mode = false;
286
+ } else {
287
+ $this->_storage->sdk_downgrade_mode = true;
288
+ $this->_storage->sdk_upgrade_mode = false;
289
+
290
+ }
291
+
292
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
293
+ }
294
+
295
+ $plugin_version = $this->get_plugin_version();
296
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
297
+ // Plugin version upgrade mode.
298
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
299
+ $this->_storage->plugin_version = $plugin_version;
300
+
301
+ if ( empty( $this->_storage->plugin_last_version ) ||
302
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
303
+ ) {
304
+ $this->_storage->plugin_upgrade_mode = true;
305
+ $this->_storage->plugin_downgrade_mode = false;
306
+ } else {
307
+ $this->_storage->plugin_downgrade_mode = true;
308
+ $this->_storage->plugin_upgrade_mode = false;
309
+ }
310
+
311
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
312
+ // Different version of the plugin was installed before, therefore it's an update.
313
+ $this->_storage->is_plugin_new_install = false;
314
+ }
315
+
316
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
317
+ }
318
+ }
319
+
320
+ /**
321
+ * @author Vova Feldman (@svovaf)
322
+ * @since 1.1.5
323
+ *
324
+ * @param string $sdk_prev_version
325
+ * @param string $sdk_version
326
+ */
327
+ function _data_migration( $sdk_prev_version, $sdk_version ) {
328
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
329
+ version_compare( $sdk_version, '1.1.5', '>=' )
330
+ ) {
331
+ // On version 1.1.5 merged connectivity and is_on data.
332
+ if ( isset( $this->_storage->connectivity_test ) ) {
333
+ if ( ! isset( $this->_storage->is_on ) ) {
334
+ unset( $this->_storage->connectivity_test );
335
+ } else {
336
+ $connectivity_data = $this->_storage->connectivity_test;
337
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
338
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
339
+
340
+ // Override.
341
+ $this->_storage->connectivity_test = $connectivity_data;
342
+
343
+ // Remove previous structure.
344
+ unset( $this->_storage->is_on );
345
+ }
346
+
347
+ }
348
+ }
349
+ }
350
+
351
+ /**
352
+ * @author Vova Feldman (@svovaf)
353
+ * @since 1.0.9
354
+ */
355
+ private function _register_hooks() {
356
+ if ( is_admin() ) {
357
+ // Hook to plugin activation
358
+ register_activation_hook( $this->_plugin_main_file_path, array(
359
+ &$this,
360
+ '_activate_plugin_event_hook'
361
+ ) );
362
+
363
+ // Hook to plugin uninstall.
364
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
365
+
366
+ if ( ! $this->is_ajax() ) {
367
+ if ( ! $this->is_addon() ) {
368
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
369
+ add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
370
+ }
371
+ }
372
+ }
373
+
374
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
375
+
376
+ add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
377
+
378
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
379
+
380
+ $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
381
+ }
382
+
383
+ /**
384
+ * @author Vova Feldman (@svovaf)
385
+ * @since 1.0.9
386
+ */
387
+ private function _register_account_hooks() {
388
+ if ( is_admin() ) {
389
+ if ( ! $this->is_ajax() ) {
390
+ if ( $this->has_trial_plan() ) {
391
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
392
+ if ( ! $this->_site->is_trial_utilized() &&
393
+ (
394
+ // Show promotion if never shown it yet and 24 hours after initial activation.
395
+ ( false === $last_time_trial_promotion_shown && $this->_storage->activation_timestamp < ( time() - WP_FS__TIME_24_HOURS_IN_SEC ) ) ||
396
+ // Show promotion in every 30 days.
397
+ ( is_numeric( $last_time_trial_promotion_shown ) && 30 * WP_FS__TIME_24_HOURS_IN_SEC < time() - $last_time_trial_promotion_shown ) )
398
+ ) {
399
+ $this->add_action( 'after_init_plugin_registered', array( &$this, '_add_trial_notice' ) );
400
+ }
401
+ }
402
+ }
403
+
404
+ // If user is paying or in trial and have the free version installed,
405
+ // assume that the deactivation is for the upgrade process.
406
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
407
+ add_action( 'wp_ajax_submit-uninstall-reason', array( &$this, '_submit_uninstall_reason_action' ) );
408
+
409
+ global $pagenow;
410
+ if ( 'plugins.php' === $pagenow ) {
411
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
412
+ }
413
+ }
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
419
+ * page.
420
+ *
421
+ * @author Vova Feldman (@svovaf)
422
+ * @author Leo Fajardo (@leorw)
423
+ * @since 1.1.2
424
+ */
425
+ function _add_deactivation_feedback_dialog_box() {
426
+ fs_enqueue_local_style( 'fs_deactivation_feedback', '/admin/deactivation-feedback.css' );
427
+
428
+ /* Check the type of user:
429
+ * 1. Long-term (long-term)
430
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
431
+ * 3. Short-term (short-term)
432
+ */
433
+ $is_long_term_user = true;
434
+
435
+ // Check if the site is at least 2 days old.
436
+ $time_installed = $this->_storage->install_timestamp;
437
+
438
+ // Difference in seconds.
439
+ $date_diff = time() - $time_installed;
440
+
441
+ // Convert seconds to days.
442
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
443
+
444
+ if ( $date_diff_days < 2 ) {
445
+ $is_long_term_user = false;
446
+ }
447
+
448
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
449
+
450
+ if ( $is_long_term_user ) {
451
+ $user_type = 'long-term';
452
+ } else {
453
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
454
+ $user_type = 'non-registered-and-non-anonymous-short-term';
455
+ } else {
456
+ $user_type = 'short-term';
457
+ }
458
+ }
459
+
460
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
461
+
462
+ // Load the HTML template for the deactivation feedback dialog box.
463
+ $vars = array(
464
+ 'reasons' => $uninstall_reasons,
465
+ 'slug' => $this->_slug
466
+ );
467
+
468
+ /**
469
+ * @todo Deactivation form core functions should be loaded only once! Otherwise, when there are multiple Freemius powered plugins the same code is loaded multiple times. The only thing that should be loaded differently is the various deactivation reasons object based on the state of the plugin.
470
+ */
471
+ fs_require_template( 'deactivation-feedback-modal.php', $vars );
472
+ }
473
+
474
+ /**
475
+ * @author Leo Fajardo (leorw)
476
+ * @since 1.1.2
477
+ *
478
+ * @param string $user_type
479
+ *
480
+ * @return array The uninstall reasons for the specified user type.
481
+ */
482
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
483
+ $reason_found_better_plugin = array(
484
+ 'id' => 2,
485
+ 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
486
+ 'input_type' => 'textfield',
487
+ 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
488
+ );
489
+
490
+ $reason_other = array(
491
+ 'id' => 7,
492
+ 'text' => __fs( 'reason-other', $this->_slug ),
493
+ 'input_type' => 'textfield',
494
+ 'input_placeholder' => ''
495
+ );
496
+
497
+ $long_term_user_reasons = array(
498
+ array(
499
+ 'id' => 1,
500
+ 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
501
+ 'input_type' => '',
502
+ 'input_placeholder' => ''
503
+ ),
504
+ $reason_found_better_plugin,
505
+ array(
506
+ 'id' => 3,
507
+ 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
508
+ 'input_type' => '',
509
+ 'input_placeholder' => ''
510
+ ),
511
+ array(
512
+ 'id' => 4,
513
+ 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
514
+ 'input_type' => '',
515
+ 'input_placeholder' => ''
516
+ ),
517
+ array(
518
+ 'id' => 5,
519
+ 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
520
+ 'input_type' => '',
521
+ 'input_placeholder' => ''
522
+ )
523
+ );
524
+
525
+ if ( $this->is_paying() ) {
526
+ $long_term_user_reasons[] = array(
527
+ 'id' => 6,
528
+ 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
529
+ 'input_type' => 'textfield',
530
+ 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
531
+ );
532
+ }
533
+
534
+ $long_term_user_reasons[] = $reason_other;
535
+
536
+ $uninstall_reasons = array(
537
+ 'long-term' => $long_term_user_reasons,
538
+ 'non-registered-and-non-anonymous-short-term' => array(
539
+ array(
540
+ 'id' => 8,
541
+ 'text' => __fs( 'reason-didnt-work', $this->_slug ),
542
+ 'input_type' => '',
543
+ 'input_placeholder' => ''
544
+ ),
545
+ array(
546
+ 'id' => 9,
547
+ 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
548
+ 'input_type' => '',
549
+ 'input_placeholder' => ''
550
+ ),
551
+ $reason_found_better_plugin,
552
+ $reason_other
553
+ ),
554
+ 'short-term' => array(
555
+ array(
556
+ 'id' => 10,
557
+ 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
558
+ 'input_type' => '',
559
+ 'input_placeholder' => ''
560
+ ),
561
+ $reason_found_better_plugin,
562
+ array(
563
+ 'id' => 11,
564
+ 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
565
+ 'input_type' => 'textarea',
566
+ 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
567
+ ),
568
+ array(
569
+ 'id' => 12,
570
+ 'text' => __fs( 'reason-not-working', $this->_slug ),
571
+ 'input_type' => 'textarea',
572
+ 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
573
+ ),
574
+ array(
575
+ 'id' => 13,
576
+ 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
577
+ 'input_type' => 'textarea',
578
+ 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
579
+ ),
580
+ array(
581
+ 'id' => 14,
582
+ 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
583
+ 'input_type' => 'textarea',
584
+ 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
585
+ ),
586
+ $reason_other
587
+ )
588
+ );
589
+
590
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
591
+
592
+ return $uninstall_reasons[ $user_type ];
593
+ }
594
+
595
+ /**
596
+ * Called after the user has submitted his reason for deactivating the plugin.
597
+ *
598
+ * @author Leo Fajardo (@leorw)
599
+ * @since 1.1.2
600
+ */
601
+ function _submit_uninstall_reason_action() {
602
+ if ( ! isset( $_POST['reason_id'] ) ) {
603
+ exit;
604
+ }
605
+
606
+ $reason_info = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
607
+
608
+ $reason = (object) array(
609
+ 'id' => $_POST['reason_id'],
610
+ 'info' => substr( $reason_info, 0, 128 )
611
+ );
612
+
613
+ $this->_storage->store( 'uninstall_reason', $reason );
614
+
615
+ // Print '1' for successful operation.
616
+ echo 1;
617
+ exit;
618
+ }
619
+
620
+ /**
621
+ * Leverage backtrace to find caller plugin file path.
622
+ *
623
+ * @author Vova Feldman (@svovaf)
624
+ * @since 1.0.6
625
+ *
626
+ * @return string
627
+ *
628
+ * @uses fs_find_caller_plugin_file
629
+ */
630
+ private function _find_caller_plugin_file() {
631
+ // Try to load the cached value of the file path.
632
+ if ( isset( $this->_storage->plugin_main_file ) ) {
633
+ if ( file_exists( $this->_storage->plugin_main_file->path ) ) {
634
+ return $this->_storage->plugin_main_file->path;
635
+ }
636
+ }
637
+
638
+ $plugin_file = fs_find_caller_plugin_file();
639
+
640
+ $this->_storage->plugin_main_file = (object) array(
641
+ 'path' => fs_normalize_path( $plugin_file ),
642
+ );
643
+
644
+ return $plugin_file;
645
+ }
646
+
647
+ #region Instance ------------------------------------------------------------------
648
+
649
+ /**
650
+ * Main singleton instance.
651
+ *
652
+ * @author Vova Feldman (@svovaf)
653
+ * @since 1.0.0
654
+ *
655
+ * @param $slug
656
+ *
657
+ * @return Freemius
658
+ */
659
+ static function instance( $slug ) {
660
+ $slug = strtolower( $slug );
661
+
662
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
663
+ if ( 0 === count( self::$_instances ) ) {
664
+ self::_load_required_static();
665
+ }
666
+
667
+ self::$_instances[ $slug ] = new Freemius( $slug );
668
+ }
669
+
670
+ return self::$_instances[ $slug ];
671
+ }
672
+
673
+ /**
674
+ * @author Vova Feldman (@svovaf)
675
+ * @since 1.0.6
676
+ *
677
+ * @param string|number $slug_or_id
678
+ *
679
+ * @return bool
680
+ */
681
+ private static function has_instance( $slug_or_id ) {
682
+ return ! is_numeric( $slug_or_id ) ?
683
+ isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
684
+ ( false !== self::get_instance_by_id( $slug_or_id ) );
685
+ }
686
+
687
+ /**
688
+ * @author Vova Feldman (@svovaf)
689
+ * @since 1.0.6
690
+ *
691
+ * @param $id
692
+ *
693
+ * @return false|Freemius
694
+ */
695
+ static function get_instance_by_id( $id ) {
696
+ foreach ( self::$_instances as $slug => $instance ) {
697
+ if ( $id == $instance->get_id() ) {
698
+ return $instance;
699
+ }
700
+ }
701
+
702
+ return false;
703
+ }
704
+
705
+ /**
706
+ *
707
+ * @author Vova Feldman (@svovaf)
708
+ * @since 1.0.1
709
+ *
710
+ * @param $plugin_file
711
+ *
712
+ * @return false|Freemius
713
+ */
714
+ static function get_instance_by_file( $plugin_file ) {
715
+ $slug = self::find_slug_by_basename( $plugin_file );
716
+
717
+ return ( false !== $slug ) ?
718
+ self::instance( $slug ) :
719
+ false;
720
+ }
721
+
722
+ /**
723
+ * @author Vova Feldman (@svovaf)
724
+ * @since 1.0.6
725
+ *
726
+ * @return false|Freemius
727
+ */
728
+ function get_parent_instance() {
729
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
730
+ }
731
+
732
+ /**
733
+ * @author Vova Feldman (@svovaf)
734
+ * @since 1.0.6
735
+ *
736
+ * @param $slug_or_id
737
+ *
738
+ * @return bool|Freemius
739
+ */
740
+ function get_addon_instance( $slug_or_id ) {
741
+ return ! is_numeric( $slug_or_id ) ?
742
+ self::instance( strtolower( $slug_or_id ) ) :
743
+ self::get_instance_by_id( $slug_or_id );
744
+ }
745
+
746
+ #endregion ------------------------------------------------------------------
747
+
748
+ /**
749
+ * @author Vova Feldman (@svovaf)
750
+ * @since 1.0.6
751
+ *
752
+ * @return bool
753
+ */
754
+ function is_parent_plugin_installed() {
755
+ return self::has_instance( $this->_plugin->parent_plugin_id );
756
+ }
757
+
758
+ /**
759
+ * Check if add-on parent plugin in activation mode.
760
+ *
761
+ * @author Vova Feldman (@svovaf)
762
+ * @since 1.0.7
763
+ *
764
+ * @return bool
765
+ */
766
+ function is_parent_in_activation() {
767
+ $parent_fs = $this->get_parent_instance();
768
+ if ( ! is_object( $parent_fs ) ) {
769
+ return false;
770
+ }
771
+
772
+ return ( $parent_fs->is_activation_mode() );
773
+ }
774
+
775
+ /**
776
+ * Is plugin in activation mode.
777
+ *
778
+ * @author Vova Feldman (@svovaf)
779
+ * @since 1.0.7
780
+ *
781
+ * @return bool
782
+ */
783
+ function is_activation_mode() {
784
+ return (
785
+ ! $this->is_registered() &&
786
+ ( ! $this->enable_anonymous() ||
787
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
788
+ );
789
+ }
790
+
791
+ private static $_statics_loaded = false;
792
+
793
+ /**
794
+ * Load static resources.
795
+ *
796
+ * @author Vova Feldman (@svovaf)
797
+ * @since 1.0.1
798
+ */
799
+ private static function _load_required_static() {
800
+ if ( self::$_statics_loaded ) {
801
+ return;
802
+ }
803
+
804
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
805
+
806
+ self::$_static_logger->entrance();
807
+
808
+ self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
809
+
810
+ self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
811
+
812
+ // Configure which Freemius powered plugins should be auto updated.
813
+ // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
814
+
815
+ add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
816
+
817
+ self::$_statics_loaded = true;
818
+ }
819
+
820
+ #region Debugging ------------------------------------------------------------------
821
+
822
+ /**
823
+ * @author Vova Feldman (@svovaf)
824
+ * @since 1.0.8
825
+ */
826
+ static function add_debug_page() {
827
+ if ( ! current_user_can( 'activate_plugins' ) ) {
828
+ return;
829
+ }
830
+
831
+ self::$_static_logger->entrance();
832
+
833
+ $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
834
+
835
+ if ( WP_FS__DEV_MODE ) {
836
+ // Add top-level debug menu item.
837
+ $hook = add_object_page(
838
+ $title,
839
+ $title,
840
+ 'manage_options',
841
+ 'freemius',
842
+ array( 'Freemius', '_debug_page_render' )
843
+ );
844
+ } else {
845
+ // Add hidden debug page.
846
+ $hook = add_submenu_page(
847
+ null,
848
+ $title,
849
+ $title,
850
+ 'manage_options',
851
+ 'freemius',
852
+ array( 'Freemius', '_debug_page_render' )
853
+ );
854
+ }
855
+
856
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
857
+ }
858
+
859
+ /**
860
+ * @author Vova Feldman (@svovaf)
861
+ * @since 1.0.8
862
+ */
863
+ static function _debug_page_actions() {
864
+ self::_clean_admin_content_section();
865
+
866
+ if ( fs_request_is_action( 'delete_all_accounts' ) ) {
867
+ check_admin_referer( 'delete_all_accounts' );
868
+
869
+ self::$_accounts->clear( true );
870
+
871
+ return;
872
+ }
873
+ }
874
+
875
+ /**
876
+ * @author Vova Feldman (@svovaf)
877
+ * @since 1.0.8
878
+ */
879
+ static function _debug_page_render() {
880
+ self::$_static_logger->entrance();
881
+
882
+ $sites = self::get_all_sites();
883
+ $users = self::get_all_users();
884
+ $addons = self::get_all_addons();
885
+ $account_addons = self::get_all_account_addons();
886
+
887
+ // $plans = self::get_all_plans();
888
+ // $licenses = self::get_all_licenses();
889
+
890
+ $vars = array(
891
+ 'sites' => $sites,
892
+ 'users' => $users,
893
+ 'addons' => $addons,
894
+ 'account_addons' => $account_addons,
895
+ );
896
+ fs_require_once_template( 'debug.php', $vars );
897
+ }
898
+
899
+ #endregion ------------------------------------------------------------------
900
+
901
+ #region Connectivity Issues ------------------------------------------------------------------
902
+
903
+ /**
904
+ * Check if Freemius should be turned on for the current plugin install.
905
+ *
906
+ * Note:
907
+ * $this->_is_on is updated in has_api_connectivity()
908
+ *
909
+ * @author Vova Feldman (@svovaf)
910
+ * @since 1.0.9
911
+ *
912
+ * @return bool
913
+ */
914
+ function is_on() {
915
+ self::$_static_logger->entrance();
916
+
917
+ if ( isset( $this->_is_on ) ) {
918
+ return $this->_is_on;
919
+ }
920
+
921
+ // If already installed or pending then sure it's on :)
922
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
923
+ $this->_is_on = true;
924
+
925
+ return true;
926
+ }
927
+
928
+ return false;
929
+ }
930
+
931
+ /**
932
+ * Check if there's any connectivity issue to Freemius API.
933
+ *
934
+ * @author Vova Feldman (@svovaf)
935
+ * @since 1.0.9
936
+ *
937
+ * @param bool $flush
938
+ *
939
+ * @return bool
940
+ */
941
+ function has_api_connectivity( $flush = false ) {
942
+ if ( ! $flush && isset( $this->_has_api_connection ) ) {
943
+ return $this->_has_api_connection;
944
+ }
945
+
946
+ $version = $this->get_plugin_version();
947
+
948
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
949
+ isset( $this->_storage->connectivity_test ) &&
950
+ true === $this->_storage->connectivity_test['is_connected']
951
+ ) {
952
+ unset( $this->_storage->connectivity_test );
953
+ }
954
+
955
+ if ( isset( $this->_storage->connectivity_test ) ) {
956
+ if ( ! WP_FS__IS_HTTP_REQUEST ||
957
+ ( $_SERVER['HTTP_HOST'] == $this->_storage->connectivity_test['host'] &&
958
+ WP_FS__REMOTE_ADDR == $this->_storage->connectivity_test['server_ip'] )
959
+ ) {
960
+ if ( ( $this->_storage->connectivity_test['is_connected'] &&
961
+ $this->_storage->connectivity_test['is_active'] ) ||
962
+ ( ! $flush &&
963
+ $version == $this->_storage->connectivity_test['version'] )
964
+ ) {
965
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
966
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] || ( WP_FS__DEV_MODE && $this->_has_api_connection );
967
+
968
+ return $this->_has_api_connection;
969
+ }
970
+ }
971
+ }
972
+
973
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
974
+
975
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
976
+ $is_connected = false;
977
+ } else {
978
+ $pong = $this->get_api_plugin_scope()->ping( $this->get_anonymous_id(), $is_update );
979
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
980
+ }
981
+
982
+ if ( ! $is_connected ) {
983
+ // 2nd try of connectivity.
984
+ $pong = $this->get_api_plugin_scope()->ping( $this->get_anonymous_id(), $is_update );
985
+
986
+ if ( $this->get_api_plugin_scope()->is_valid_ping( $pong ) ) {
987
+ $is_connected = true;
988
+ } else {
989
+ // Another API failure.
990
+ $this->_add_connectivity_issue_message( $pong );
991
+ }
992
+ }
993
+
994
+ $is_active = ( ! $is_connected ) ?
995
+ false :
996
+ ( isset( $pong->is_active ) && true == $pong->is_active );
997
+
998
+ $this->_storage->connectivity_test = array(
999
+ 'is_connected' => $is_connected,
1000
+ 'host' => $_SERVER['HTTP_HOST'],
1001
+ 'server_ip' => WP_FS__REMOTE_ADDR,
1002
+ 'is_active' => $is_active,
1003
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
1004
+ // Last version with connectivity attempt.
1005
+ 'version' => $version,
1006
+ );
1007
+
1008
+ $this->_has_api_connection = $is_connected;
1009
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected );
1010
+
1011
+ return $this->_has_api_connection;
1012
+ }
1013
+
1014
+ /**
1015
+ * Anonymous and unique site identifier (Hash).
1016
+ *
1017
+ * @author Vova Feldman (@svovaf)
1018
+ * @since 1.1.0
1019
+ *
1020
+ * @return string
1021
+ */
1022
+ function get_anonymous_id() {
1023
+ if ( ! self::$_accounts->has_option( 'unique_id' ) ) {
1024
+ $key = get_site_url();
1025
+
1026
+ // If localhost, assign microtime instead of domain.
1027
+ if ( WP_FS__IS_LOCALHOST || false !== strpos( $key, 'localhost' ) ) {
1028
+ $key = microtime();
1029
+ }
1030
+
1031
+ self::$_accounts->set_option( 'unique_id', md5( $key ), true );
1032
+ }
1033
+
1034
+ return self::$_accounts->get_option( 'unique_id' );
1035
+ }
1036
+
1037
+ /**
1038
+ * Generate API connectivity issue message.
1039
+ *
1040
+ * @author Vova Feldman (@svovaf)
1041
+ * @since 1.0.9
1042
+ *
1043
+ * @param mixed $api_result
1044
+ */
1045
+ function _add_connectivity_issue_message( $api_result ) {
1046
+ if ( $this->_enable_anonymous ) {
1047
+ // Don't add message if can run anonymously.
1048
+ return;
1049
+ }
1050
+
1051
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
1052
+ require_once( ABSPATH . 'wp-includes/functions.php' );
1053
+ }
1054
+
1055
+ self::require_pluggable_essentials();
1056
+
1057
+ $current_user = wp_get_current_user();
1058
+ // $admin_email = get_option( 'admin_email' );
1059
+ $admin_email = $current_user->user_email;
1060
+
1061
+ $message = false;
1062
+ if ( is_object( $api_result ) &&
1063
+ isset( $api_result->error )
1064
+ ) {
1065
+ switch ( $api_result->error->code ) {
1066
+ case 'curl_missing':
1067
+ $message = sprintf(
1068
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1069
+ __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1070
+ ' %s',
1071
+ '<b>' . $this->get_plugin_name() . '</b>',
1072
+ sprintf(
1073
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1074
+ sprintf(
1075
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1076
+ __fs( 'curl-missing-no-clue-title', $this->_slug ),
1077
+ ' - ' . sprintf(
1078
+ __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1079
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1080
+ )
1081
+ ),
1082
+ sprintf(
1083
+ '<b>%s</b> - %s',
1084
+ __fs( 'sysadmin-title', $this->_slug ),
1085
+ __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1086
+ ),
1087
+ sprintf(
1088
+ '<a href="%s"><b>%s</b></a>%s',
1089
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
1090
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1091
+ ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1092
+ )
1093
+ )
1094
+ );
1095
+ break;
1096
+ case 'cloudflare_ddos_protection':
1097
+ $message = sprintf(
1098
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1099
+ __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1100
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1101
+ ' %s',
1102
+ '<b>' . $this->get_plugin_name() . '</b>',
1103
+ sprintf(
1104
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1105
+ sprintf(
1106
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1107
+ __fs( 'fix-issue-title', $this->_slug ),
1108
+ ' - ' . sprintf(
1109
+ __fs( 'fix-issue-desc', $this->_slug ),
1110
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1111
+ )
1112
+ ),
1113
+ sprintf(
1114
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1115
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1116
+ __fs( 'install-previous-title', $this->_slug ),
1117
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1118
+ ),
1119
+ sprintf(
1120
+ '<a href="%s"><b>%s</b></a>%s',
1121
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
1122
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1123
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1124
+ )
1125
+ )
1126
+ );
1127
+ break;
1128
+ case 'squid_cache_block':
1129
+ $message = sprintf(
1130
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1131
+ __fs( 'squid-blocks-connection-message', $this->_slug ) .
1132
+ ' %s',
1133
+ '<b>' . $this->get_plugin_name() . '</b>',
1134
+ sprintf(
1135
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1136
+ sprintf(
1137
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1138
+ __fs( 'squid-no-clue-title', $this->_slug ),
1139
+ ' - ' . sprintf(
1140
+ __fs( 'squid-no-clue-desc', $this->_slug ),
1141
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1142
+ )
1143
+ ),
1144
+ sprintf(
1145
+ '<b>%s</b> - %s',
1146
+ __fs( 'sysadmin-title', $this->_slug ),
1147
+ sprintf(
1148
+ __fs( 'squid-sysadmin-desc', $this->_slug ),
1149
+ // We use a filter since the plugin might require additional API connectivity.
1150
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1151
+ ),
1152
+ sprintf(
1153
+ '<a href="%s"><b>%s</b></a>%s',
1154
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
1155
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1156
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1157
+ )
1158
+ )
1159
+ );
1160
+ break;
1161
+ default:
1162
+ $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1163
+ break;
1164
+ }
1165
+ }
1166
+
1167
+ if ( false === $message ) {
1168
+ $message = sprintf(
1169
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1170
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1171
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1172
+ ' %s',
1173
+ '<b>' . $this->get_plugin_name() . '</b>',
1174
+ sprintf(
1175
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1176
+ sprintf(
1177
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1178
+ __fs( 'fix-issue-title', $this->_slug ),
1179
+ ' - ' . sprintf(
1180
+ __fs( 'fix-issue-desc', $this->_slug ),
1181
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1182
+ )
1183
+ ),
1184
+ sprintf(
1185
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1186
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1187
+ __fs( 'install-previous-title', $this->_slug ),
1188
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1189
+ ),
1190
+ sprintf(
1191
+ '<a href="%s"><b>%s</b></a>%s',
1192
+ wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $this->_plugin_basename . '&amp;plugin_status=' . 'all' . '&amp;paged=' . '1' . '&amp;s=' . '', 'deactivate-plugin_' . $this->_plugin_basename ),
1193
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1194
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1195
+ )
1196
+ )
1197
+ );
1198
+ }
1199
+
1200
+ $this->_admin_notices->add_sticky(
1201
+ $message,
1202
+ 'failed_connect_api',
1203
+ __fs( 'oops', $this->_slug ) . '...',
1204
+ 'error'
1205
+ );
1206
+ }
1207
+
1208
+ /**
1209
+ * Get collection of all active plugins.
1210
+ *
1211
+ * @author Vova Feldman (@svovaf)
1212
+ * @since 1.0.9
1213
+ *
1214
+ * @return array[string]array
1215
+ */
1216
+ private function get_active_plugins() {
1217
+ self::require_plugin_essentials();
1218
+
1219
+ $active_plugin = array();
1220
+ $all_plugins = get_plugins();
1221
+ $active_plugins_basenames = get_option( 'active_plugins' );
1222
+
1223
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
1224
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
1225
+ }
1226
+
1227
+ return $active_plugin;
1228
+ }
1229
+
1230
+ /**
1231
+ * Handle user request to resolve connectivity issue.
1232
+ * This method will send an email to Freemius API technical staff for resolution.
1233
+ * The email will contain server's info and installed plugins (might be caching issue).
1234
+ *
1235
+ * @author Vova Feldman (@svovaf)
1236
+ * @since 1.0.9
1237
+ */
1238
+ function _email_about_firewall_issue() {
1239
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1240
+
1241
+ self::require_pluggable_essentials();
1242
+
1243
+ $current_user = wp_get_current_user();
1244
+ $admin_email = $current_user->user_email;
1245
+
1246
+ $ping = $this->get_api_plugin_scope()->ping();
1247
+
1248
+ $error_type = fs_request_get( 'error_type', 'general' );
1249
+
1250
+ switch ( $error_type ) {
1251
+ case 'squid':
1252
+ $title = 'Squid ACL Blocking Issue';
1253
+ break;
1254
+ case 'cloudflare':
1255
+ $title = 'CloudFlare Blocking Issue';
1256
+ break;
1257
+ default:
1258
+ $title = 'API Connectivity Issue';
1259
+ break;
1260
+ }
1261
+
1262
+ $custom_email_sections = array();
1263
+
1264
+ if ( 'squid' === $error_type ) {
1265
+ // Override the 'Site' email section.
1266
+ $custom_email_sections['site'] = array(
1267
+ 'rows' => array(
1268
+ 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1269
+ )
1270
+ );
1271
+ }
1272
+
1273
+ // Add 'API Error' custom email section.
1274
+ $custom_email_sections['api_error'] = array(
1275
+ 'title' => 'API Error',
1276
+ 'rows' => array(
1277
+ 'ping' => array( is_string( $ping ) ? htmlentities( $ping ) : json_encode( $ping ) )
1278
+ )
1279
+ );
1280
+
1281
+ // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1282
+ $this->send_email(
1283
+ 'api@freemius.com', // recipient
1284
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
1285
+ $custom_email_sections,
1286
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
1287
+ );
1288
+
1289
+ $this->_admin_notices->add_sticky(
1290
+ sprintf(
1291
+ __fs( 'fix-request-sent-message', $this->_slug ),
1292
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1293
+ ),
1294
+ 'server_details_sent'
1295
+ );
1296
+
1297
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
1298
+
1299
+ echo "1";
1300
+ exit;
1301
+ }
1302
+
1303
+ static function _add_firewall_issues_javascript() {
1304
+ $params = array();
1305
+ fs_require_once_template( 'firewall-issues-js.php', $params );
1306
+ }
1307
+
1308
+ #endregion Connectivity Issues ------------------------------------------------------------------
1309
+
1310
+ #region Email ------------------------------------------------------------------
1311
+
1312
+ /**
1313
+ * Generates and sends an HTML email with customizable sections.
1314
+ *
1315
+ * @author Leo Fajardo (@leorw)
1316
+ * @since 1.1.2
1317
+ *
1318
+ * @param string $to_address
1319
+ * @param string $subject
1320
+ * @param array $sections
1321
+ * @param array $headers
1322
+ *
1323
+ * @return bool Whether the email contents were sent successfully.
1324
+ */
1325
+ private function send_email(
1326
+ $to_address,
1327
+ $subject,
1328
+ $sections = array(),
1329
+ $headers = array()
1330
+ ) {
1331
+ $default_sections = $this->get_email_sections();
1332
+
1333
+ // Insert new sections or replace the default email sections.
1334
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
1335
+ foreach ( $sections as $section_id => $custom_section ) {
1336
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
1337
+ // If the section does not exist, add it.
1338
+ $default_sections[ $section_id ] = $custom_section;
1339
+ } else {
1340
+ // If the section already exists, override it.
1341
+ $current_section = $default_sections[ $section_id ];
1342
+
1343
+ // Replace the current section's title if a custom section title exists.
1344
+ if ( isset( $custom_section['title'] ) ) {
1345
+ $current_section['title'] = $custom_section['title'];
1346
+ }
1347
+
1348
+ // Insert new rows under the current section or replace the default rows.
1349
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1350
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
1351
+ $current_section['rows'][ $row_id ] = $row;
1352
+ }
1353
+ }
1354
+
1355
+ $default_sections[ $section_id ] = $current_section;
1356
+ }
1357
+ }
1358
+ }
1359
+
1360
+ $vars = array( 'sections' => $default_sections );
1361
+ $message = fs_get_template( 'email.php', $vars );
1362
+
1363
+ // Set the type of email to HTML.
1364
+ $headers[] = 'Content-type: text/html';
1365
+
1366
+ $header_string = implode( "\r\n", $headers );
1367
+
1368
+ return wp_mail(
1369
+ $to_address,
1370
+ $subject,
1371
+ $message,
1372
+ $header_string
1373
+ );
1374
+ }
1375
+
1376
+ /**
1377
+ * Generates the data for the sections of the email content.
1378
+ *
1379
+ * @author Leo Fajardo (@leorw)
1380
+ * @since 1.1.2
1381
+ *
1382
+ * @return array
1383
+ */
1384
+ private function get_email_sections() {
1385
+ self::require_pluggable_essentials();
1386
+
1387
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
1388
+ $current_user = wp_get_current_user();
1389
+
1390
+ // Retrieve the cURL version information so that we can get the version number below.
1391
+ $curl_version_information = curl_version();
1392
+
1393
+ $active_plugin = $this->get_active_plugins();
1394
+
1395
+ // Generate the list of active plugins separated by new line.
1396
+ $active_plugin_string = '';
1397
+ foreach ( $active_plugin as $plugin ) {
1398
+ $active_plugin_string .= sprintf(
1399
+ '<a href="%s">%s</a> [v%s]<br>',
1400
+ $plugin['PluginURI'],
1401
+ $plugin['Name'],
1402
+ $plugin['Version']
1403
+ );
1404
+ }
1405
+
1406
+ $server_ip = WP_FS__REMOTE_ADDR;
1407
+
1408
+ // Generate the default email sections.
1409
+ $sections = array(
1410
+ 'sdk' => array(
1411
+ 'title' => 'SDK',
1412
+ 'rows' => array(
1413
+ 'fs_version' => array( 'FS Version', $this->version ),
1414
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
1415
+ )
1416
+ ),
1417
+ 'plugin' => array(
1418
+ 'title' => 'Plugin',
1419
+ 'rows' => array(
1420
+ 'name' => array( 'Name', $this->get_plugin_name() ),
1421
+ 'version' => array( 'Version', $this->get_plugin_version() )
1422
+ )
1423
+ ),
1424
+ 'site' => array(
1425
+ 'title' => 'Site',
1426
+ 'rows' => array(
1427
+ 'address' => array( 'Address', site_url() ),
1428
+ 'host' => array(
1429
+ 'HTTP_HOST',
1430
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
1431
+ ),
1432
+ 'server_addr' => array(
1433
+ 'SERVER_ADDR',
1434
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
1435
+ )
1436
+ )
1437
+ ),
1438
+ 'user' => array(
1439
+ 'title' => 'User',
1440
+ 'rows' => array(
1441
+ 'email' => array( 'Email', $current_user->user_email ),
1442
+ 'first' => array( 'First', $current_user->user_firstname ),
1443
+ 'last' => array( 'Last', $current_user->user_lastname )
1444
+ )
1445
+ ),
1446
+ 'plugins' => array(
1447
+ 'title' => 'Plugins',
1448
+ 'rows' => array(
1449
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
1450
+ )
1451
+ ),
1452
+ );
1453
+
1454
+ // Allow the sections to be modified by other code.
1455
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
1456
+
1457
+ return $sections;
1458
+ }
1459
+
1460
+ #endregion Email ------------------------------------------------------------------
1461
+
1462
+ #region Initialization ------------------------------------------------------------------
1463
+
1464
+ /**
1465
+ * Init plugin's Freemius instance.
1466
+ *
1467
+ * @author Vova Feldman (@svovaf)
1468
+ * @since 1.0.1
1469
+ *
1470
+ * @param number $id
1471
+ * @param string $public_key
1472
+ * @param bool $is_live
1473
+ * @param bool $is_premium
1474
+ */
1475
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
1476
+ $this->_logger->entrance();
1477
+
1478
+ $this->dynamic_init( array(
1479
+ 'id' => $id,
1480
+ 'public_key' => $public_key,
1481
+ 'is_live' => $is_live,
1482
+ 'is_premium' => $is_premium,
1483
+ ) );
1484
+ }
1485
+
1486
+ /**
1487
+ * @param string[] $options
1488
+ * @param string $key
1489
+ * @param mixed $default
1490
+ *
1491
+ * @return bool
1492
+ */
1493
+ private function _get_option( &$options, $key, $default = false ) {
1494
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
1495
+ }
1496
+
1497
+ private function _get_bool_option( &$options, $key, $default = false ) {
1498
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
1499
+ }
1500
+
1501
+ private function _get_numeric_option( &$options, $key, $default = false ) {
1502
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
1503
+ }
1504
+
1505
+ /**
1506
+ * Dynamic initiator, originally created to support initiation
1507
+ * with parent_id for add-ons.
1508
+ *
1509
+ * @author Vova Feldman (@svovaf)
1510
+ * @since 1.0.6
1511
+ *
1512
+ * @param array $plugin_info
1513
+ *
1514
+ * @throws Freemius_Exception
1515
+ */
1516
+ function dynamic_init( array $plugin_info ) {
1517
+ $this->_logger->entrance();
1518
+
1519
+ $id = $this->_get_numeric_option( $plugin_info, 'id', false );
1520
+ $public_key = $this->_get_option( $plugin_info, 'public_key', false );
1521
+ $secret_key = $this->_get_option( $plugin_info, 'secret_key', null );
1522
+ $parent_id = $this->_get_numeric_option( $plugin_info, 'parent_id', null );
1523
+ $parent_name = $this->_get_option( $plugin_info, 'parent_name', null );
1524
+
1525
+ if ( isset( $plugin_info['parent'] ) ) {
1526
+ $parent_id = $this->_get_numeric_option( $plugin_info['parent'], 'id', null );
1527
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
1528
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
1529
+ $parent_name = $this->_get_option( $plugin_info['parent'], 'name', null );
1530
+ }
1531
+
1532
+ if ( false === $id ) {
1533
+ throw new Freemius_Exception( 'Plugin id parameter is not set.' );
1534
+ }
1535
+ if ( false === $public_key ) {
1536
+ throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
1537
+ }
1538
+
1539
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
1540
+ $this->_plugin :
1541
+ new FS_Plugin();
1542
+
1543
+ $plugin->update( array(
1544
+ 'id' => $id,
1545
+ 'public_key' => $public_key,
1546
+ 'slug' => $this->_slug,
1547
+ 'parent_plugin_id' => $parent_id,
1548
+ 'version' => $this->get_plugin_version(),
1549
+ 'title' => $this->get_plugin_name(),
1550
+ 'file' => $this->_free_plugin_basename,
1551
+ 'is_premium' => $this->_get_bool_option( $plugin_info, 'is_premium', true ),
1552
+ 'is_live' => $this->_get_bool_option( $plugin_info, 'is_live', true ),
1553
+ // 'secret_key' => $secret_key,
1554
+ ) );
1555
+
1556
+ if ( $plugin->is_updated() ) {
1557
+ // Update plugin details.
1558
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
1559
+ }
1560
+ $this->_plugin->secret_key = $secret_key;
1561
+
1562
+ if ( ! isset( $plugin_info['menu'] ) ) {
1563
+ // Back compatibility to 1.1.2
1564
+ $plugin_info['menu'] = array(
1565
+ 'slug' => isset( $plugin_info['menu_slug'] ) ?
1566
+ $plugin_info['menu_slug'] :
1567
+ $this->_slug
1568
+ );
1569
+ }
1570
+
1571
+ $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
1572
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
1573
+
1574
+ $this->_has_addons = $this->_get_bool_option( $plugin_info, 'has_addons', false );
1575
+ $this->_has_paid_plans = $this->_get_bool_option( $plugin_info, 'has_paid_plans', true );
1576
+ $this->_is_org_compliant = $this->_get_bool_option( $plugin_info, 'is_org_compliant', true );
1577
+ $this->_enable_anonymous = $this->_get_bool_option( $plugin_info, 'enable_anonymous', true );
1578
+ $this->_permissions = $this->_get_option( $plugin_info, 'permissions', array() );
1579
+
1580
+ if ( ! $this->is_registered() ) {
1581
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
1582
+ /**
1583
+ * If not registered and executed without HTTP context (e.g. CLI, Cronjob),
1584
+ * then don't start Freemius.
1585
+ *
1586
+ * @author Vova Feldman (@svovaf)
1587
+ * @since 1.1.6.3
1588
+ *
1589
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
1590
+ */
1591
+ return;
1592
+ }
1593
+
1594
+ if ( ! $this->has_api_connectivity() ) {
1595
+ if ( is_admin() && $this->_admin_notices->has_sticky( 'failed_connect_api' ) ) {
1596
+ if ( ! $this->_enable_anonymous ) {
1597
+ // If anonymous mode is disabled, add firewall admin-notice message.
1598
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
1599
+
1600
+ add_action( "wp_ajax_{$this->_slug}_resolve_firewall_issues", array(
1601
+ &$this,
1602
+ '_email_about_firewall_issue'
1603
+ ) );
1604
+ }
1605
+ }
1606
+
1607
+ return;
1608
+ }
1609
+
1610
+ // Check if Freemius is on for the current plugin.
1611
+ // This MUST be executed after all the plugin variables has been loaded.
1612
+ if ( ! $this->is_on() ) {
1613
+ return;
1614
+ }
1615
+ }
1616
+
1617
+ if ( false === $this->_background_sync() ) {
1618
+ // If background sync wasn't executed,
1619
+ // and if the plugin declared it has add-ons but
1620
+ // no add-ons found in the local data, then try to sync add-ons.
1621
+ if ( $this->_has_addons &&
1622
+ ! $this->is_addon() &&
1623
+ ( false === $this->get_addons() )
1624
+ ) {
1625
+ $this->_sync_addons();
1626
+ }
1627
+ }
1628
+
1629
+ if ( $this->is_addon() ) {
1630
+ if ( $this->is_parent_plugin_installed() ) {
1631
+ // Link to parent FS.
1632
+ $this->_parent = self::get_instance_by_id( $parent_id );
1633
+
1634
+ // Get parent plugin reference.
1635
+ $this->_parent_plugin = $this->_parent->get_plugin();
1636
+ }
1637
+ }
1638
+
1639
+ if ( is_admin() ) {
1640
+ global $pagenow;
1641
+ if ( 'plugins.php' === $pagenow ) {
1642
+ $this->hook_plugin_action_links();
1643
+ }
1644
+
1645
+ if ( $this->is_addon() ) {
1646
+ if ( ! $this->is_parent_plugin_installed() ) {
1647
+ $this->_admin_notices->add(
1648
+ ( is_string( $parent_name ) ?
1649
+ sprintf( __fs( 'addon-cannot-run-without-x', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
1650
+ sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
1651
+ ),
1652
+ __fs( 'oops', $this->_slug ) . '...',
1653
+ 'error'
1654
+ );
1655
+
1656
+ return;
1657
+ } else {
1658
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
1659
+ // If parent plugin activated, automatically install add-on for the user.
1660
+ $this->_activate_addon_account( $this->_parent );
1661
+ }
1662
+
1663
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
1664
+ if ( $this->is_premium() ) {
1665
+ // Remove add-on download admin-notice.
1666
+ $this->_parent->_admin_notices->remove_sticky( 'addon_plan_upgraded_' . $this->_slug );
1667
+ }
1668
+ }
1669
+ } else {
1670
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
1671
+
1672
+ if ( $this->_has_addons() &&
1673
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
1674
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
1675
+ ) {
1676
+ // Remove default plugin information action.
1677
+ remove_all_actions( 'install_plugins_pre_plugin-information' );
1678
+
1679
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-functions.php';
1680
+
1681
+ // Override action with custom plugins function for add-ons.
1682
+ add_action( 'install_plugins_pre_plugin-information', 'fs_install_plugin_information' );
1683
+
1684
+ // Override request for plugin information for Add-ons.
1685
+ add_filter( 'fs_plugins_api', array(
1686
+ &$this,
1687
+ '_get_addon_info_filter'
1688
+ ), WP_FS__DEFAULT_PRIORITY, 3 );
1689
+ }
1690
+ }
1691
+
1692
+ if ( $this->is_premium() ) {
1693
+ new FS_Plugin_Updater( $this );
1694
+ }
1695
+
1696
+ // if ( $this->is_registered() ||
1697
+ // $this->is_anonymous() ||
1698
+ // $this->is_pending_activation()
1699
+ // ) {
1700
+ // $this->_init_admin();
1701
+ // }
1702
+ }
1703
+
1704
+ $this->do_action( 'initiated' );
1705
+
1706
+ if ( ! $this->is_addon() ) {
1707
+ if ( $this->is_registered() ) {
1708
+ // Fix for upgrade from versions < 1.0.9.
1709
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
1710
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
1711
+ }
1712
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
1713
+ if ( isset( $this->_storage->prev_is_premium ) ) {
1714
+ add_action( is_admin() ? 'admin_init' : 'init', array(
1715
+ &$this,
1716
+ '_plugin_code_type_changed'
1717
+ ) );
1718
+ } else {
1719
+ // Set for code type for the first time.
1720
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
1721
+ }
1722
+ }
1723
+
1724
+ $this->do_action( 'after_init_plugin_registered' );
1725
+ } else if ( $this->is_anonymous() ) {
1726
+ $this->do_action( 'after_init_plugin_anonymous' );
1727
+ } else if ( $this->is_pending_activation() ) {
1728
+ $this->do_action( 'after_init_plugin_pending_activations' );
1729
+ }
1730
+ } else {
1731
+ if ( $this->is_registered() ) {
1732
+ $this->do_action( 'after_init_addon_registered' );
1733
+ } else if ( $this->is_anonymous() ) {
1734
+ $this->do_action( 'after_init_addon_anonymous' );
1735
+ } else if ( $this->is_pending_activation() ) {
1736
+ $this->do_action( 'after_init_addon_pending_activations' );
1737
+ }
1738
+ }
1739
+ }
1740
+
1741
+ /**
1742
+ * Handles plugin's code type change (free <--> premium).
1743
+ *
1744
+ * @author Vova Feldman (@svovaf)
1745
+ * @since 1.0.9
1746
+ */
1747
+ function _plugin_code_type_changed() {
1748
+ // Send code type changes event.
1749
+ $this->sync_install();
1750
+
1751
+ if ( $this->is_premium() ) {
1752
+ // Activated premium code.
1753
+ $this->do_action( 'after_premium_version_activation' );
1754
+
1755
+ // Remove all sticky messages related to download of the premium version.
1756
+ $this->_admin_notices->remove_sticky( array(
1757
+ 'trial_started',
1758
+ 'plan_upgraded',
1759
+ 'plan_changed',
1760
+ ) );
1761
+
1762
+ $this->_admin_notices->add_sticky(
1763
+ __fs( 'premium-activated-message', $this->_slug ),
1764
+ 'premium_activated',
1765
+ __fs( 'woot', $this->_slug ) . '!'
1766
+ );
1767
+ } else {
1768
+ // Activated free code (after had the premium before).
1769
+ $this->do_action( 'after_free_version_reactivation' );
1770
+
1771
+ if ( $this->is_paying() && ! $this->is_premium() ) {
1772
+ $this->_admin_notices->add_sticky(
1773
+ sprintf(
1774
+ __fs( 'you-have-x-license', $this->_slug ),
1775
+ $this->_site->plan->title
1776
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
1777
+ __fs( 'download-x-version-now', $this->_slug ),
1778
+ $this->_site->plan->title
1779
+ ) ),
1780
+ 'plan_upgraded',
1781
+ __fs( 'yee-haw', $this->_slug ) . '!'
1782
+ );
1783
+ }
1784
+ }
1785
+
1786
+ // Update is_premium of latest version.
1787
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
1788
+ }
1789
+
1790
+ #endregion Initialization ------------------------------------------------------------------
1791
+
1792
+ #region Add-ons -------------------------------------------------------------------------
1793
+
1794
+ /**
1795
+ * Generate add-on plugin information.
1796
+ *
1797
+ * @author Vova Feldman (@svovaf)
1798
+ * @since 1.0.6
1799
+ *
1800
+ * @param array $data
1801
+ * @param string $action
1802
+ * @param object|null $args
1803
+ *
1804
+ * @return array|null
1805
+ */
1806
+ function _get_addon_info_filter( $data, $action = '', $args = null ) {
1807
+ $this->_logger->entrance();
1808
+
1809
+ $parent_plugin_id = fs_request_get( 'parent_plugin_id', false );
1810
+
1811
+ if ( $this->get_id() != $parent_plugin_id ||
1812
+ ( 'plugin_information' !== $action ) ||
1813
+ ! isset( $args->slug )
1814
+ ) {
1815
+ return $data;
1816
+ }
1817
+
1818
+ // Find add-on by slug.
1819
+ $addons = $this->get_addons();
1820
+ $selected_addon = false;
1821
+ foreach ( $addons as $addon ) {
1822
+ if ( $addon->slug == $args->slug ) {
1823
+ $selected_addon = $addon;
1824
+ break;
1825
+ }
1826
+ }
1827
+
1828
+ if ( false === $selected_addon ) {
1829
+ return $data;
1830
+ }
1831
+
1832
+ if ( ! isset( $selected_addon->info ) ) {
1833
+ // Setup some default info.
1834
+ $selected_addon->info = new stdClass();
1835
+ $selected_addon->info->selling_point_0 = 'Selling Point 1';
1836
+ $selected_addon->info->selling_point_1 = 'Selling Point 2';
1837
+ $selected_addon->info->selling_point_2 = 'Selling Point 3';
1838
+ $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
1839
+ }
1840
+
1841
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
1842
+
1843
+ $data = $args;
1844
+
1845
+ // Fetch as much as possible info from local files.
1846
+ $plugin_local_data = $this->get_plugin_data();
1847
+ $data->name = $selected_addon->title;
1848
+ $data->author = $plugin_local_data['Author'];
1849
+ $view_vars = array( 'plugin' => $selected_addon );
1850
+ $data->sections = array(
1851
+ 'description' => fs_get_template( '/plugin-info/description.php', $view_vars ),
1852
+ );
1853
+
1854
+ if ( ! empty( $selected_addon->info->banner_url ) ) {
1855
+ $data->banners = array(
1856
+ 'low' => $selected_addon->info->banner_url,
1857
+ );
1858
+ }
1859
+
1860
+ if ( ! empty( $selected_addon->info->screenshots ) ) {
1861
+ $view_vars = array(
1862
+ 'screenshots' => $selected_addon->info->screenshots,
1863
+ 'plugin' => $selected_addon,
1864
+ );
1865
+ $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
1866
+ }
1867
+
1868
+ // Load add-on pricing.
1869
+ $has_pricing = false;
1870
+ $has_features = false;
1871
+ $plans = false;
1872
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans.json" );
1873
+ if ( ! isset( $plans_result->error ) ) {
1874
+ $plans = $plans_result->plans;
1875
+ if ( is_array( $plans ) ) {
1876
+ foreach ( $plans as &$plan ) {
1877
+ $pricing_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/pricing.json" );
1878
+ if ( ! isset( $pricing_result->error ) ) {
1879
+ // Update plan's pricing.
1880
+ $plan->pricing = $pricing_result->pricing;
1881
+
1882
+ $has_pricing = true;
1883
+ }
1884
+
1885
+ $features_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/features.json" );
1886
+ if ( ! isset( $features_result->error ) &&
1887
+ is_array( $features_result->features ) &&
1888
+ 0 < count( $features_result->features )
1889
+ ) {
1890
+ // Update plan's pricing.
1891
+ $plan->features = $features_result->features;
1892
+
1893
+ $has_features = true;
1894
+ }
1895
+ }
1896
+ }
1897
+ }
1898
+
1899
+ // Get latest add-on version.
1900
+ $latest = $this->_fetch_latest_version( $selected_addon->id );
1901
+
1902
+ if ( is_object( $latest ) ) {
1903
+ $data->version = $latest->version;
1904
+ $data->last_updated = ! is_null( $latest->updated ) ? $latest->updated : $latest->created;
1905
+ $data->requires = $latest->requires_platform_version;
1906
+ $data->tested = $latest->tested_up_to_version;
1907
+ } else {
1908
+ // Add dummy version.
1909
+ $data->version = '1.0.0';
1910
+
1911
+ // Add message to developer to deploy the plugin through Freemius.
1912
+ }
1913
+
1914
+ $data->checkout_link = $this->checkout_url();
1915
+ $data->download_link = 'https://dummy.com';
1916
+
1917
+ if ( $has_pricing ) {
1918
+ // Add plans to data.
1919
+ $data->plans = $plans;
1920
+
1921
+ if ( $has_features ) {
1922
+ $view_vars = array(
1923
+ 'plans' => $plans,
1924
+ 'plugin' => $selected_addon,
1925
+ );
1926
+ $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
1927
+ }
1928
+ }
1929
+
1930
+ return $data;
1931
+ }
1932
+
1933
+ /**
1934
+ * Check if add-on installed and activated on site.
1935
+ *
1936
+ * @author Vova Feldman (@svovaf)
1937
+ * @since 1.0.6
1938
+ *
1939
+ * @param string|number $slug_or_id
1940
+ *
1941
+ * @return bool
1942
+ */
1943
+ function is_addon_activated( $slug_or_id ) {
1944
+ return self::has_instance( $slug_or_id );
1945
+ }
1946
+
1947
+ /**
1948
+ * Determines if add-on installed.
1949
+ *
1950
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
1951
+ *
1952
+ * @author Vova Feldman (@svovaf)
1953
+ * @since 1.0.6
1954
+ *
1955
+ * @param string $slug
1956
+ *
1957
+ * @return bool
1958
+ */
1959
+ function is_addon_installed( $slug ) {
1960
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
1961
+ }
1962
+
1963
+ /**
1964
+ * Get add-on basename.
1965
+ *
1966
+ * @author Vova Feldman (@svovaf)
1967
+ * @since 1.0.6
1968
+ *
1969
+ * @param string $slug
1970
+ *
1971
+ * @return string
1972
+ */
1973
+ function get_addon_basename( $slug ) {
1974
+ if ( $this->is_addon_activated( $slug ) ) {
1975
+ self::instance( $slug )->get_plugin_basename();
1976
+ }
1977
+
1978
+ return $slug . '/' . $slug . '.php';
1979
+ }
1980
+
1981
+ /**
1982
+ * Get installed add-ons instances.
1983
+ *
1984
+ * @author Vova Feldman (@svovaf)
1985
+ * @since 1.0.6
1986
+ *
1987
+ * @return Freemius[]
1988
+ */
1989
+ function get_installed_addons() {
1990
+ $installed_addons = array();
1991
+ foreach ( self::$_instances as $slug => $instance ) {
1992
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
1993
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
1994
+ $installed_addons[] = $instance;
1995
+ }
1996
+ }
1997
+ }
1998
+
1999
+ return $installed_addons;
2000
+ }
2001
+
2002
+ /**
2003
+ * Check if any add-ons of the plugin are installed.
2004
+ *
2005
+ * @author Leo Fajardo (@leorw)
2006
+ * @since 1.1.1
2007
+ *
2008
+ * @return bool
2009
+ */
2010
+ function has_installed_addons() {
2011
+ if ( ! $this->_has_addons() ) {
2012
+ return false;
2013
+ }
2014
+
2015
+ foreach ( self::$_instances as $slug => $instance ) {
2016
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2017
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2018
+ return true;
2019
+ }
2020
+ }
2021
+ }
2022
+
2023
+ return false;
2024
+ }
2025
+
2026
+ /**
2027
+ * Tell Freemius that the current plugin is an add-on.
2028
+ *
2029
+ * @author Vova Feldman (@svovaf)
2030
+ * @since 1.0.6
2031
+ *
2032
+ * @param number $parent_plugin_id The parent plugin ID
2033
+ */
2034
+ function init_addon( $parent_plugin_id ) {
2035
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
2036
+ }
2037
+
2038
+ /**
2039
+ * @author Vova Feldman (@svovaf)
2040
+ * @since 1.0.6
2041
+ *
2042
+ * @return bool
2043
+ */
2044
+ function is_addon() {
2045
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2046
+ }
2047
+
2048
+ #endregion ------------------------------------------------------------------
2049
+
2050
+ #region Sandbox ------------------------------------------------------------------
2051
+
2052
+ /**
2053
+ * Set Freemius into sandbox mode for debugging.
2054
+ *
2055
+ * @author Vova Feldman (@svovaf)
2056
+ * @since 1.0.4
2057
+ *
2058
+ * @param string $secret_key
2059
+ */
2060
+ function init_sandbox( $secret_key ) {
2061
+ $this->_plugin->secret_key = $secret_key;
2062
+
2063
+ // Update plugin details.
2064
+ FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
2065
+ }
2066
+
2067
+ /**
2068
+ * Check if running payments in sandbox mode.
2069
+ *
2070
+ * @author Vova Feldman (@svovaf)
2071
+ * @since 1.0.4
2072
+ *
2073
+ * @return bool
2074
+ */
2075
+ function is_payments_sandbox() {
2076
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
2077
+ }
2078
+
2079
+ #endregion Sandbox ------------------------------------------------------------------
2080
+
2081
+ /**
2082
+ * Check if running test vs. live plugin.
2083
+ *
2084
+ * @author Vova Feldman (@svovaf)
2085
+ * @since 1.0.5
2086
+ *
2087
+ * @return bool
2088
+ */
2089
+ function is_live() {
2090
+ return $this->_plugin->is_live;
2091
+ }
2092
+
2093
+ /**
2094
+ * Check if the user skipped connecting the account with Freemius.
2095
+ *
2096
+ * @author Vova Feldman (@svovaf)
2097
+ * @since 1.0.7
2098
+ *
2099
+ * @return bool
2100
+ */
2101
+ function is_anonymous() {
2102
+ if ( ! isset( $this->_is_anonymous ) ) {
2103
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
2104
+ // Not skipped.
2105
+ $this->_is_anonymous = false;
2106
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
2107
+ // For back compatibility, since the variable was boolean before.
2108
+ $this->_is_anonymous = $this->_storage->is_anonymous;
2109
+
2110
+ // Upgrade stored data format to 1.1.3 format.
2111
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
2112
+ } else {
2113
+ // Version 1.1.3 and higher.
2114
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
2115
+ }
2116
+ }
2117
+
2118
+ return $this->_is_anonymous;
2119
+ }
2120
+
2121
+ /**
2122
+ * Check if user connected his account and install pending email activation.
2123
+ *
2124
+ * @author Vova Feldman (@svovaf)
2125
+ * @since 1.0.7
2126
+ *
2127
+ * @return bool
2128
+ */
2129
+ function is_pending_activation() {
2130
+ return $this->_storage->get( 'is_pending_activation', false );
2131
+ }
2132
+
2133
+ /**
2134
+ * Check if plugin must be WordPress.org compliant.
2135
+ *
2136
+ * @since 1.0.7
2137
+ *
2138
+ * @return bool
2139
+ */
2140
+ function is_org_repo_compliant() {
2141
+ return $this->_is_org_compliant;
2142
+ }
2143
+
2144
+ /**
2145
+ * Background sync every 24 hours.
2146
+ *
2147
+ * @author Vova Feldman (@svovaf)
2148
+ * @since 1.0.4
2149
+ *
2150
+ * @return bool If function actually executed the sync in this iteration.
2151
+ */
2152
+ private function _background_sync() {
2153
+ $this->_logger->entrance();
2154
+
2155
+ // Don't sync license on AJAX calls.
2156
+ if ( $this->is_ajax() ) {
2157
+ return false;
2158
+ }
2159
+
2160
+ // Asked to sync explicitly, no need for background sync.
2161
+ if ( fs_request_is_action( $this->_slug . '_sync_license' ) ) {
2162
+ return false;
2163
+ }
2164
+
2165
+ // Check if API is not down.
2166
+ if ( FS_Api::is_temporary_down() ) {
2167
+ return false;
2168
+ }
2169
+
2170
+ $sync_timestamp = $this->_storage->get( 'sync_timestamp' );
2171
+
2172
+ if ( ! is_numeric( $sync_timestamp ) || $sync_timestamp >= time() ) {
2173
+ // If updated not set or happens to be in the future, set as if was 24 hours earlier.
2174
+ $sync_timestamp = time() - WP_FS__TIME_24_HOURS_IN_SEC;
2175
+ $this->_storage->sync_timestamp = $sync_timestamp;
2176
+ }
2177
+
2178
+ if ( ( defined( 'WP_FS__DEV_MODE' ) && WP_FS__DEV_MODE && fs_request_has( 'background_sync' ) ) ||
2179
+ ( $sync_timestamp <= time() - WP_FS__TIME_24_HOURS_IN_SEC )
2180
+ ) {
2181
+
2182
+ if ( $this->is_registered() ) {
2183
+ // Initiate background plan sync.
2184
+ $this->_sync_license( true );
2185
+
2186
+ if ( $this->is_paying() ) {
2187
+ // Check for plugin updates.
2188
+ $this->_check_updates( true );
2189
+ }
2190
+ }
2191
+
2192
+ if ( ! $this->is_addon() ) {
2193
+ if ( $this->is_registered() || $this->_has_addons ) {
2194
+ // Try to fetch add-ons if registered or if plugin
2195
+ // declared that it has add-ons.
2196
+ $this->_sync_addons();
2197
+ }
2198
+ }
2199
+
2200
+ // Update last sync timestamp.
2201
+ $this->_storage->sync_timestamp = time();
2202
+
2203
+ return true;
2204
+ }
2205
+
2206
+ return false;
2207
+ }
2208
+
2209
+ /**
2210
+ * Show a notice that activation is currently pending.
2211
+ *
2212
+ * @author Vova Feldman (@svovaf)
2213
+ * @since 1.0.7
2214
+ *
2215
+ * @param bool|string $email
2216
+ */
2217
+ function _add_pending_activation_notice( $email = false ) {
2218
+ if ( ! is_string( $email ) ) {
2219
+ $current_user = wp_get_current_user();
2220
+ $email = $current_user->user_email;
2221
+ }
2222
+
2223
+ $this->_admin_notices->add_sticky(
2224
+ sprintf(
2225
+ __fs( 'pending-activation-message', $this->_slug ),
2226
+ '<b>' . $this->get_plugin_name() . '</b>',
2227
+ '<b>' . $email . '</b>'
2228
+ ),
2229
+ 'activation_pending',
2230
+ 'Thanks!'
2231
+ );
2232
+ }
2233
+
2234
+ /**
2235
+ * Check if currently in plugin activation.
2236
+ *
2237
+ * @author Vova Feldman (@svovaf)
2238
+ * @since 1.1.4
2239
+ *
2240
+ * @return bool
2241
+ */
2242
+ function is_plugin_activation() {
2243
+ return get_option( "fs_{$this->_slug}_activated", false );
2244
+ }
2245
+
2246
+ /**
2247
+ *
2248
+ * NOTE: admin_menu action executed before admin_init.
2249
+ *
2250
+ * @author Vova Feldman (@svovaf)
2251
+ * @since 1.0.7
2252
+ */
2253
+ function _admin_init_action() {
2254
+ /**
2255
+ * Automatically redirect to connect/activation page after plugin activation.
2256
+ *
2257
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
2258
+ */
2259
+ if ( $this->is_plugin_activation() ) {
2260
+ delete_option( "fs_{$this->_slug}_activated" );
2261
+
2262
+ if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
2263
+ $this->_redirect_on_activation_hook();
2264
+
2265
+ return;
2266
+ }
2267
+ }
2268
+
2269
+ if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
2270
+ check_admin_referer( $this->_slug . '_skip_activation' );
2271
+
2272
+ $this->skip_connection();
2273
+
2274
+ if ( fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) ) ) {
2275
+ exit();
2276
+ }
2277
+ }
2278
+
2279
+ if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
2280
+ if ( ! $this->is_pending_activation() ) {
2281
+ if ( ! $this->_menu->is_activation_page() ) {
2282
+ if ( $this->is_plugin_new_install() ) {
2283
+ // Show notice for new plugin installations.
2284
+ $this->_admin_notices->add(
2285
+ sprintf(
2286
+ __fs( 'you-are-step-away', $this->_slug ),
2287
+ sprintf( '<b><a href="%s">%s</a></b>',
2288
+ $this->get_activation_url(),
2289
+ sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
2290
+ )
2291
+ ),
2292
+ '',
2293
+ 'update-nag'
2294
+ );
2295
+ } else {
2296
+ if ( ! isset( $this->_storage->sticky_optin_added ) ) {
2297
+ $this->_storage->sticky_optin_added = true;
2298
+
2299
+ // Show notice for new plugin installations.
2300
+ $this->_admin_notices->add_sticky(
2301
+ sprintf(
2302
+ __fs( 'few-plugin-tweaks', $this->_slug ),
2303
+ sprintf( '<b><a href="%s">%s</a></b>',
2304
+ $this->get_activation_url(),
2305
+ sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
2306
+ )
2307
+ ),
2308
+ 'connect_account',
2309
+ '',
2310
+ 'update-nag'
2311
+ );
2312
+ }
2313
+ }
2314
+ }
2315
+ }
2316
+ }
2317
+
2318
+ $this->_add_upgrade_action_link();
2319
+ }
2320
+
2321
+ /**
2322
+ * Enqueue connect requires scripts and styles.
2323
+ *
2324
+ * @author Vova Feldman (@svovaf)
2325
+ * @since 1.1.4
2326
+ */
2327
+ function _enqueue_connect_essentials() {
2328
+ wp_enqueue_script( 'jquery' );
2329
+ wp_enqueue_script( 'json2' );
2330
+
2331
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
2332
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
2333
+
2334
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
2335
+ }
2336
+ /**
2337
+ * Return current page's URL.
2338
+ *
2339
+ * @author Vova Feldman (@svovaf)
2340
+ * @since 1.0.7
2341
+ *
2342
+ * @return string
2343
+ */
2344
+ function current_page_url() {
2345
+ $url = 'http';
2346
+
2347
+ if ( isset( $_SERVER["HTTPS"] ) ) {
2348
+ if ( $_SERVER["HTTPS"] == "on" ) {
2349
+ $url .= "s";
2350
+ }
2351
+ }
2352
+ $url .= "://";
2353
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
2354
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
2355
+ } else {
2356
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
2357
+ }
2358
+
2359
+ return esc_url( $url );
2360
+ }
2361
+
2362
+ /**
2363
+ * Check if the current page is the plugin's main admin settings page.
2364
+ *
2365
+ * @author Vova Feldman (@svovaf)
2366
+ * @since 1.0.7
2367
+ *
2368
+ * @return bool
2369
+ */
2370
+ function _is_plugin_page() {
2371
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
2372
+ fs_is_plugin_page( $this->_slug );
2373
+ }
2374
+
2375
+ /* Events
2376
+ ------------------------------------------------------------------------------------------------------------------*/
2377
+ /**
2378
+ * Delete site install from Database.
2379
+ *
2380
+ * @author Vova Feldman (@svovaf)
2381
+ * @since 1.0.1
2382
+ *
2383
+ * @param bool $store
2384
+ */
2385
+ function _delete_site( $store = true ) {
2386
+ $sites = self::get_all_sites();
2387
+
2388
+ if ( isset( $sites[ $this->_slug ] ) ) {
2389
+ unset( $sites[ $this->_slug ] );
2390
+ }
2391
+
2392
+ self::$_accounts->set_option( 'sites', $sites, $store );
2393
+ }
2394
+
2395
+ /**
2396
+ * Delete plugin's plans information.
2397
+ *
2398
+ * @param bool $store Flush to Database if true.
2399
+ *
2400
+ * @author Vova Feldman (@svovaf)
2401
+ * @since 1.0.9
2402
+ */
2403
+ private function _delete_plans( $store = true ) {
2404
+ $this->_logger->entrance();
2405
+
2406
+ $plans = self::get_all_plans();
2407
+
2408
+ unset( $plans[ $this->_slug ] );
2409
+
2410
+ self::$_accounts->set_option( 'plans', $plans, $store );
2411
+ }
2412
+
2413
+ /**
2414
+ * Delete all plugin licenses.
2415
+ *
2416
+ * @author Vova Feldman (@svovaf)
2417
+ * @since 1.0.9
2418
+ *
2419
+ * @param bool $store
2420
+ * @param string|bool $plugin_slug
2421
+ */
2422
+ private function _delete_licenses( $store = true, $plugin_slug = false ) {
2423
+ $this->_logger->entrance();
2424
+
2425
+ $all_licenses = self::get_all_licenses();
2426
+
2427
+ if ( ! is_string( $plugin_slug ) ) {
2428
+ $plugin_slug = $this->_slug;
2429
+ }
2430
+
2431
+ unset( $all_licenses[ $plugin_slug ] );
2432
+
2433
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
2434
+ }
2435
+
2436
+ /**
2437
+ * Check if Freemius was added on new plugin installation.
2438
+ *
2439
+ * @author Vova Feldman (@svovaf)
2440
+ * @since 1.1.5
2441
+ *
2442
+ * @return bool
2443
+ */
2444
+ function is_plugin_new_install() {
2445
+ return isset( $this->_storage->is_plugin_new_install ) &&
2446
+ $this->_storage->is_plugin_new_install;
2447
+ }
2448
+
2449
+ /**
2450
+ * Plugin activated hook.
2451
+ *
2452
+ * @author Vova Feldman (@svovaf)
2453
+ * @since 1.0.1
2454
+ *
2455
+ * @uses FS_Api
2456
+ */
2457
+ function _activate_plugin_event_hook() {
2458
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
2459
+
2460
+ if ( ! current_user_can( 'activate_plugins' ) ) {
2461
+ return;
2462
+ }
2463
+
2464
+ // Clear API cache on activation.
2465
+ FS_Api::clear_cache();
2466
+
2467
+ if ( $this->is_registered() ) {
2468
+ // Send re-activation event and sync.
2469
+ $this->sync_install( array(), true );
2470
+
2471
+ /**
2472
+ * @todo Work on automatic deactivation of the Free plugin version. It doesn't work since the slug of the free & premium versions is identical. Therefore, only one instance of Freemius is created and the activation hook of the premium version is not being added.
2473
+ */
2474
+ if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
2475
+ // Deactivate Free plugin version on premium plugin activation.
2476
+ deactivate_plugins( $this->_free_plugin_basename );
2477
+
2478
+ $this->_admin_notices->add(
2479
+ sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
2480
+ __fs( 'woot', $this->_slug ) . '!'
2481
+ );
2482
+ }
2483
+ } else if ( $this->is_anonymous() ) {
2484
+ /**
2485
+ * Reset "skipped" click cache on the following:
2486
+ * 1. Development mode.
2487
+ * 2. If the user skipped the exact same version before.
2488
+ *
2489
+ * @todo 3. If explicitly asked to retry after every activation.
2490
+ */
2491
+ if ( WP_FS__DEV_MODE ||
2492
+ $this->get_plugin_version() == $this->_storage->is_anonymous['version']
2493
+ ) {
2494
+ $this->reset_anonymous_mode();
2495
+ }
2496
+ }
2497
+
2498
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
2499
+ /**
2500
+ * If no previous version of plugin's version exist, it means that it's either
2501
+ * the first time that the plugin installed on the site, or the plugin was installed
2502
+ * before but didn't have Freemius integrated.
2503
+ *
2504
+ * Since register_activation_hook() do NOT fires since 3.1, and only fires
2505
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
2506
+ * only after immediate activation.
2507
+ *
2508
+ * @since 1.1.4
2509
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
2510
+ */
2511
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
2512
+ }
2513
+
2514
+ if ( $this->has_api_connectivity( true ) ) {
2515
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
2516
+ add_option( "fs_{$this->_slug}_activated", true );
2517
+ }
2518
+ }
2519
+
2520
+ /**
2521
+ * Delete account.
2522
+ *
2523
+ * @author Vova Feldman (@svovaf)
2524
+ * @since 1.0.3
2525
+ *
2526
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
2527
+ */
2528
+ function delete_account_event( $check_user = true ) {
2529
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
2530
+
2531
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
2532
+ return;
2533
+ }
2534
+
2535
+ $this->do_action( 'before_account_delete' );
2536
+
2537
+ // Clear all admin notices.
2538
+ $this->_admin_notices->clear_all_sticky();
2539
+
2540
+ $this->_delete_site( false );
2541
+
2542
+ $this->_delete_plans( false );
2543
+
2544
+ $this->_delete_licenses( false );
2545
+
2546
+ // Delete add-ons related to plugin's account.
2547
+ $this->_delete_account_addons( false );
2548
+
2549
+ // @todo Delete plans and licenses of add-ons.
2550
+
2551
+ self::$_accounts->store();
2552
+
2553
+ // Clear all storage data.
2554
+ $this->_storage->clear_all( true, array(
2555
+ 'connectivity_test',
2556
+ 'is_on',
2557
+ ) );
2558
+
2559
+ // Send delete event.
2560
+ $this->get_api_site_scope()->call( '/', 'delete' );
2561
+
2562
+ $this->do_action( 'after_account_delete' );
2563
+ }
2564
+
2565
+ /**
2566
+ * Plugin deactivation hook.
2567
+ *
2568
+ * @author Vova Feldman (@svovaf)
2569
+ * @since 1.0.1
2570
+ */
2571
+ function _deactivate_plugin_hook() {
2572
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
2573
+
2574
+ if ( ! current_user_can( 'activate_plugins' ) ) {
2575
+ return;
2576
+ }
2577
+
2578
+ $this->_admin_notices->clear_all_sticky();
2579
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
2580
+ unset( $this->_storage->sticky_optin_added );
2581
+ }
2582
+
2583
+ if ( ! $this->has_api_connectivity() ) {
2584
+ // Reset connectivity test cache.
2585
+ unset( $this->_storage->connectivity_test );
2586
+ }
2587
+
2588
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
2589
+ // Remember that plugin was already installed.
2590
+ $this->_storage->is_plugin_new_install = false;
2591
+ }
2592
+
2593
+ if ( $this->is_registered() ) {
2594
+ // Send deactivation event.
2595
+ $this->sync_install( array(
2596
+ 'is_active' => false,
2597
+ ) );
2598
+ }
2599
+
2600
+ // Clear API cache on deactivation.
2601
+ FS_Api::clear_cache();
2602
+
2603
+ $this->remove_sdk_reference();
2604
+ }
2605
+
2606
+ /**
2607
+ * @author Vova Feldman (@svovaf)
2608
+ * @since 1.1.6
2609
+ */
2610
+ private function remove_sdk_reference() {
2611
+ global $fs_active_plugins;
2612
+
2613
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
2614
+ if ( $this->_plugin_basename == $data->plugin_path ) {
2615
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
2616
+ break;
2617
+ }
2618
+ }
2619
+
2620
+ fs_fallback_to_newest_active_sdk();
2621
+ }
2622
+
2623
+ /**
2624
+ * @author Vova Feldman (@svovaf)
2625
+ * @since 1.1.3
2626
+ *
2627
+ * @param bool $is_anonymous
2628
+ */
2629
+ private function set_anonymous_mode( $is_anonymous = true ) {
2630
+ // Store information regarding skip to try and opt-in the user
2631
+ // again in the future.
2632
+ $this->_storage->is_anonymous = array(
2633
+ 'is' => $is_anonymous,
2634
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2635
+ 'version' => $this->get_plugin_version(),
2636
+ );
2637
+
2638
+ // Update anonymous mode cache.
2639
+ $this->_is_anonymous = $is_anonymous;
2640
+ }
2641
+
2642
+ /**
2643
+ * @author Vova Feldman (@svovaf)
2644
+ * @since 1.1.3
2645
+ */
2646
+ private function reset_anonymous_mode() {
2647
+ unset( $this->_storage->is_anonymous );
2648
+ }
2649
+
2650
+ /**
2651
+ * Clears the anonymous mode and redirects to the opt-in screen.
2652
+ *
2653
+ * @author Vova Feldman (@svovaf)
2654
+ * @since 1.1.7
2655
+ */
2656
+ function connect_again() {
2657
+ if ( ! $this->is_anonymous() ) {
2658
+ return;
2659
+ }
2660
+
2661
+ $this->reset_anonymous_mode();
2662
+
2663
+ if ( fs_redirect( $this->get_activation_url() ) ) {
2664
+ exit();
2665
+ }
2666
+ }
2667
+
2668
+ /**
2669
+ * Skip account connect, and set anonymous mode.
2670
+ *
2671
+ * @author Vova Feldman (@svovaf)
2672
+ * @since 1.1.1
2673
+ */
2674
+ private function skip_connection() {
2675
+ $this->_logger->entrance();
2676
+
2677
+ $this->_admin_notices->remove_sticky( 'connect_account' );
2678
+
2679
+ $this->set_anonymous_mode();
2680
+
2681
+ // Send anonymous skip event.
2682
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
2683
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
2684
+ 'uid' => $this->get_anonymous_id(),
2685
+ ) );
2686
+ }
2687
+
2688
+ /**
2689
+ * Plugin version update hook.
2690
+ *
2691
+ * @author Vova Feldman (@svovaf)
2692
+ * @since 1.0.4
2693
+ */
2694
+ private function update_plugin_version_event() {
2695
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
2696
+
2697
+ // Send update event.
2698
+ $site = $this->send_install_update( array(), true );
2699
+
2700
+ if ( false !== $site && ! $this->is_api_error( $site ) ) {
2701
+ $this->_site = new FS_Site( $site );
2702
+ $this->_site->plan = $this->_get_plan_by_id( $site->plan_id );
2703
+ }
2704
+
2705
+ $this->_site->version = $this->get_plugin_version();
2706
+ $this->_store_site( true );
2707
+ }
2708
+
2709
+ /**
2710
+ * Update install details.
2711
+ *
2712
+ * @author Vova Feldman (@svovaf)
2713
+ * @since 1.1.2
2714
+ *
2715
+ * @param string[] string $override
2716
+ *
2717
+ * @return array
2718
+ */
2719
+ private function get_install_data_for_api( $override = array() ) {
2720
+ return array_merge( array(
2721
+ 'version' => $this->get_plugin_version(),
2722
+ 'is_premium' => $this->is_premium(),
2723
+ 'language' => get_bloginfo( 'language' ),
2724
+ 'charset' => get_bloginfo( 'charset' ),
2725
+ 'platform_version' => get_bloginfo( 'version' ),
2726
+ 'programming_language_version' => phpversion(),
2727
+ 'title' => get_bloginfo( 'name' ),
2728
+ 'url' => get_site_url(),
2729
+ // Special params.
2730
+ 'is_active' => true,
2731
+ 'is_uninstalled' => false,
2732
+ ), $override );
2733
+ }
2734
+
2735
+ /**
2736
+ * Update install only if changed.
2737
+ *
2738
+ * @author Vova Feldman (@svovaf)
2739
+ * @since 1.0.9
2740
+ *
2741
+ * @param string[] string $override
2742
+ * @param bool $flush
2743
+ *
2744
+ * @return false|object|string
2745
+ */
2746
+ private function send_install_update( $override = array(), $flush = false ) {
2747
+ $this->_logger->entrance();
2748
+
2749
+ $check_properties = $this->get_install_data_for_api( $override );
2750
+
2751
+ if ( $flush ) {
2752
+ $params = $check_properties;
2753
+ } else {
2754
+ $params = array();
2755
+ $special = array();
2756
+ $special_override = false;
2757
+
2758
+ foreach ( $check_properties as $p => $v ) {
2759
+ if ( property_exists( $this->_site, $p ) ) {
2760
+ if ( ! empty( $this->_site->{$p} ) &&
2761
+ $this->_site->{$p} != $v
2762
+ ) {
2763
+ $this->_site->{$p} = $v;
2764
+ $params[ $p ] = $v;
2765
+ }
2766
+ } else {
2767
+ $special[ $p ] = $v;
2768
+
2769
+ if ( isset( $override[ $p ] ) ) {
2770
+ $special_override = true;
2771
+ }
2772
+ }
2773
+ }
2774
+
2775
+ if ( $special_override || 0 < count( $params ) ) {
2776
+ // Add special params only if has at least one
2777
+ // standard param, or if explicitly requested to
2778
+ // override a special param or a pram which is not exist
2779
+ // in the install object.
2780
+ $params = array_merge( $params, $special );
2781
+ }
2782
+ }
2783
+
2784
+ if ( 0 < count( $params ) ) {
2785
+ // Send updated values to FS.
2786
+ return $this->get_api_site_scope()->call( '/', 'put', $params );
2787
+ }
2788
+
2789
+ return false;
2790
+ }
2791
+
2792
+ /**
2793
+ * Update install only if changed.
2794
+ *
2795
+ * @author Vova Feldman (@svovaf)
2796
+ * @since 1.0.9
2797
+ *
2798
+ * @param string[] string $override
2799
+ * @param bool $flush
2800
+ *
2801
+ * @return false|object|string
2802
+ */
2803
+ private function sync_install( $override = array(), $flush = false ) {
2804
+ $this->_logger->entrance();
2805
+
2806
+ $site = $this->send_install_update( $override, $flush );
2807
+
2808
+ if ( false === $site ) {
2809
+ // No sync required.
2810
+ return;
2811
+ }
2812
+
2813
+ if ( $this->is_api_error( $site ) ) {
2814
+ // Failed to sync, don't update locally.
2815
+ return;
2816
+ }
2817
+
2818
+ $plan = $this->get_plan();
2819
+ $this->_site = new FS_Site( $site );
2820
+ $this->_site->plan = $plan;
2821
+
2822
+ $this->_store_site( true );
2823
+ }
2824
+
2825
+ /**
2826
+ * Plugin uninstall hook.
2827
+ *
2828
+ * @author Vova Feldman (@svovaf)
2829
+ * @since 1.0.1
2830
+ *
2831
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
2832
+ */
2833
+ function _uninstall_plugin_event( $check_user = true ) {
2834
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
2835
+
2836
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
2837
+ return;
2838
+ }
2839
+
2840
+ $params = array();
2841
+ if ( isset( $this->_storage->uninstall_reason ) ) {
2842
+ $params['reason_id'] = $this->_storage->uninstall_reason->id;
2843
+ $params['reason_info'] = $this->_storage->uninstall_reason->info;
2844
+ }
2845
+
2846
+ if ( ! $this->is_registered() && isset( $this->_storage->uninstall_reason ) ) {
2847
+ // Send anonymous uninstall event only if user submitted a feedback.
2848
+ $params['uid'] = $this->get_anonymous_id();
2849
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
2850
+ } else {
2851
+ // Send uninstall event.
2852
+ $this->send_install_update( array_merge( $params, array(
2853
+ 'is_active' => false,
2854
+ 'is_uninstalled' => true,
2855
+ ) ) );
2856
+ }
2857
+
2858
+ // @todo Decide if we want to delete plugin information from db.
2859
+ }
2860
+
2861
+ /**
2862
+ * @author Vova Feldman (@svovaf)
2863
+ * @since 1.1.1
2864
+ *
2865
+ * @return string
2866
+ */
2867
+ private function premium_plugin_basename() {
2868
+ return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
2869
+ }
2870
+
2871
+ /**
2872
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
2873
+ *
2874
+ * @author Vova Feldman (@svovaf)
2875
+ * @since 1.0.2
2876
+ */
2877
+ public static function _uninstall_plugin_hook() {
2878
+ self::_load_required_static();
2879
+
2880
+ self::$_static_logger->entrance();
2881
+
2882
+ if ( ! current_user_can( 'activate_plugins' ) ) {
2883
+ return;
2884
+ }
2885
+
2886
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
2887
+
2888
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
2889
+
2890
+ define( 'WP_FS__UNINSTALL_MODE', true );
2891
+
2892
+ $fs = self::get_instance_by_file( $plugin_file );
2893
+
2894
+ if ( is_object( $fs ) ) {
2895
+ self::require_plugin_essentials();
2896
+
2897
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
2898
+ is_plugin_active( $fs->premium_plugin_basename() )
2899
+ ) {
2900
+ // Deleting Free or Premium plugin version while the other version still installed.
2901
+ return;
2902
+ }
2903
+
2904
+ $fs->_uninstall_plugin_event();
2905
+
2906
+ $fs->do_action( 'after_uninstall' );
2907
+ }
2908
+ }
2909
+
2910
+ #region Plugin Information ------------------------------------------------------------------
2911
+
2912
+ /**
2913
+ * Load WordPress core plugin.php essential module.
2914
+ *
2915
+ * @author Vova Feldman (@svovaf)
2916
+ * @since 1.1.1
2917
+ */
2918
+ private static function require_plugin_essentials() {
2919
+ if ( ! function_exists( 'get_plugins' ) ) {
2920
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
2921
+ }
2922
+ }
2923
+
2924
+ /**
2925
+ * Load WordPress core pluggable.php module.
2926
+ *
2927
+ * @author Vova Feldman (@svovaf)
2928
+ * @since 1.1.2
2929
+ */
2930
+ private static function require_pluggable_essentials() {
2931
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
2932
+ require_once( ABSPATH . 'wp-includes/pluggable.php' );
2933
+ }
2934
+ }
2935
+
2936
+ /**
2937
+ * Return plugin data.
2938
+ *
2939
+ * @author Vova Feldman (@svovaf)
2940
+ * @since 1.0.1
2941
+ *
2942
+ * @return array
2943
+ */
2944
+ function get_plugin_data() {
2945
+ if ( ! isset( $this->_plugin_data ) ) {
2946
+ self::require_plugin_essentials();
2947
+
2948
+ $this->_plugin_data = get_plugin_data( $this->_plugin_main_file_path );
2949
+ }
2950
+
2951
+ return $this->_plugin_data;
2952
+ }
2953
+
2954
+ /**
2955
+ * @author Vova Feldman (@svovaf)
2956
+ * @since 1.0.1
2957
+ *
2958
+ * @return string Plugin slug.
2959
+ */
2960
+ function get_slug() {
2961
+ return $this->_slug;
2962
+ }
2963
+
2964
+ /**
2965
+ * @author Vova Feldman (@svovaf)
2966
+ * @since 1.0.1
2967
+ *
2968
+ * @return number Plugin ID.
2969
+ */
2970
+ function get_id() {
2971
+ return $this->_plugin->id;
2972
+ }
2973
+
2974
+ /**
2975
+ * @author Vova Feldman (@svovaf)
2976
+ * @since 1.0.1
2977
+ *
2978
+ * @return string Plugin public key.
2979
+ */
2980
+ function get_public_key() {
2981
+ return $this->_plugin->public_key;
2982
+ }
2983
+
2984
+ /**
2985
+ * Will be available only on sandbox mode.
2986
+ *
2987
+ * @author Vova Feldman (@svovaf)
2988
+ * @since 1.0.4
2989
+ *
2990
+ * @return mixed Plugin secret key.
2991
+ */
2992
+ function get_secret_key() {
2993
+ return $this->_plugin->secret_key;
2994
+ }
2995
+
2996
+ /**
2997
+ * @author Vova Feldman (@svovaf)
2998
+ * @since 1.1.1
2999
+ *
3000
+ * @return bool
3001
+ */
3002
+ function has_secret_key() {
3003
+ return ! empty( $this->_plugin->secret_key );
3004
+ }
3005
+
3006
+ /**
3007
+ * @author Vova Feldman (@svovaf)
3008
+ * @since 1.0.9
3009
+ *
3010
+ * @return string
3011
+ */
3012
+ function get_plugin_name() {
3013
+ $this->_logger->entrance();
3014
+
3015
+ if ( ! isset( $this->_plugin_name ) ) {
3016
+ $plugin_data = $this->get_plugin_data();
3017
+
3018
+ // Get name.
3019
+ $this->_plugin_name = $plugin_data['Name'];
3020
+
3021
+ // Check if plugin name contains [Premium] suffix and remove it.
3022
+ $suffix = '[premium]';
3023
+ $suffix_len = strlen( $suffix );
3024
+
3025
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
3026
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
3027
+ ) {
3028
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
3029
+ }
3030
+
3031
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
3032
+ }
3033
+
3034
+ return $this->_plugin_name;
3035
+ }
3036
+
3037
+ /**
3038
+ * @author Vova Feldman (@svovaf)
3039
+ * @since 1.0.0
3040
+ *
3041
+ * @return string
3042
+ */
3043
+ function get_plugin_version() {
3044
+ $this->_logger->entrance();
3045
+
3046
+ $plugin_data = $this->get_plugin_data();
3047
+
3048
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
3049
+
3050
+ return $plugin_data['Version'];
3051
+ }
3052
+
3053
+ /**
3054
+ * @author Vova Feldman (@svovaf)
3055
+ * @since 1.0.4
3056
+ *
3057
+ * @return string
3058
+ */
3059
+ function get_plugin_basename() {
3060
+ return $this->_plugin_basename;
3061
+ }
3062
+
3063
+ function get_plugin_folder_name() {
3064
+ $this->_logger->entrance();
3065
+
3066
+ $plugin_folder = $this->_plugin_basename;
3067
+
3068
+ while ( '.' !== dirname( $plugin_folder ) ) {
3069
+ $plugin_folder = dirname( $plugin_folder );
3070
+ }
3071
+
3072
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
3073
+
3074
+ return $plugin_folder;
3075
+ }
3076
+
3077
+ #endregion ------------------------------------------------------------------
3078
+
3079
+ /* Account
3080
+ ------------------------------------------------------------------------------------------------------------------*/
3081
+
3082
+ /**
3083
+ * Find plugin's slug by plugin's basename.
3084
+ *
3085
+ * @author Vova Feldman (@svovaf)
3086
+ * @since 1.0.9
3087
+ *
3088
+ * @param string $plugin_base_name
3089
+ *
3090
+ * @return false|string
3091
+ */
3092
+ private static function find_slug_by_basename( $plugin_base_name ) {
3093
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
3094
+
3095
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
3096
+ return false;
3097
+ }
3098
+
3099
+ return $file_slug_map[ $plugin_base_name ];
3100
+ }
3101
+
3102
+ /**
3103
+ * Store the map between the plugin's basename to the slug.
3104
+ *
3105
+ * @author Vova Feldman (@svovaf)
3106
+ * @since 1.0.9
3107
+ */
3108
+ private function store_file_slug_map() {
3109
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
3110
+
3111
+ if ( ! array( $file_slug_map ) ) {
3112
+ $file_slug_map = array();
3113
+ }
3114
+
3115
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
3116
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
3117
+ ) {
3118
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
3119
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
3120
+ }
3121
+ }
3122
+
3123
+ /**
3124
+ * @return FS_User[]
3125
+ */
3126
+ static function get_all_users() {
3127
+ $users = self::$_accounts->get_option( 'users', array() );
3128
+
3129
+ if ( ! is_array( $users ) ) {
3130
+ $users = array();
3131
+ }
3132
+
3133
+ return $users;
3134
+ }
3135
+
3136
+ /**
3137
+ * @return FS_Site[]
3138
+ */
3139
+ private static function get_all_sites() {
3140
+ $sites = self::$_accounts->get_option( 'sites', array() );
3141
+
3142
+ if ( ! is_array( $sites ) ) {
3143
+ $sites = array();
3144
+ }
3145
+
3146
+ return $sites;
3147
+ }
3148
+
3149
+ /**
3150
+ * @author Vova Feldman (@svovaf)
3151
+ * @since 1.0.6
3152
+ *
3153
+ * @return FS_Plugin_License[]
3154
+ */
3155
+ private static function get_all_licenses() {
3156
+ $licenses = self::$_accounts->get_option( 'licenses', array() );
3157
+
3158
+ if ( ! is_array( $licenses ) ) {
3159
+ $licenses = array();
3160
+ }
3161
+
3162
+ return $licenses;
3163
+ }
3164
+
3165
+ /**
3166
+ * @return FS_Plugin_Plan[]
3167
+ */
3168
+ private static function get_all_plans() {
3169
+ $plans = self::$_accounts->get_option( 'plans', array() );
3170
+
3171
+ if ( ! is_array( $plans ) ) {
3172
+ $plans = array();
3173
+ }
3174
+
3175
+ return $plans;
3176
+ }
3177
+
3178
+ /**
3179
+ * @author Vova Feldman (@svovaf)
3180
+ * @since 1.0.4
3181
+ *
3182
+ * @return FS_Plugin_Tag[]
3183
+ */
3184
+ private static function get_all_updates() {
3185
+ $updates = self::$_accounts->get_option( 'updates', array() );
3186
+
3187
+ if ( ! is_array( $updates ) ) {
3188
+ $updates = array();
3189
+ }
3190
+
3191
+ return $updates;
3192
+ }
3193
+
3194
+ /**
3195
+ * @author Vova Feldman (@svovaf)
3196
+ * @since 1.0.6
3197
+ *
3198
+ * @return FS_Plugin[]|false
3199
+ */
3200
+ private static function get_all_addons() {
3201
+ $addons = self::$_accounts->get_option( 'addons', array() );
3202
+
3203
+ if ( ! is_array( $addons ) ) {
3204
+ $addons = array();
3205
+ }
3206
+
3207
+ return $addons;
3208
+ }
3209
+
3210
+ /**
3211
+ * @author Vova Feldman (@svovaf)
3212
+ * @since 1.0.6
3213
+ *
3214
+ * @return FS_Plugin[]|false
3215
+ */
3216
+ private static function get_all_account_addons() {
3217
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
3218
+
3219
+ if ( ! is_array( $addons ) ) {
3220
+ $addons = array();
3221
+ }
3222
+
3223
+ return $addons;
3224
+ }
3225
+
3226
+ /**
3227
+ * Check if user is registered.
3228
+ *
3229
+ * @author Vova Feldman (@svovaf)
3230
+ * @since 1.0.1
3231
+ * @return bool
3232
+ */
3233
+ function is_registered() {
3234
+ return is_object( $this->_user );
3235
+ }
3236
+
3237
+ /**
3238
+ * @author Vova Feldman (@svovaf)
3239
+ * @since 1.0.4
3240
+ *
3241
+ * @return FS_Plugin
3242
+ */
3243
+ function get_plugin() {
3244
+ return $this->_plugin;
3245
+ }
3246
+
3247
+ /**
3248
+ * @author Vova Feldman (@svovaf)
3249
+ * @since 1.0.3
3250
+ *
3251
+ * @return FS_User
3252
+ */
3253
+ function get_user() {
3254
+ return $this->_user;
3255
+ }
3256
+
3257
+ /**
3258
+ * @author Vova Feldman (@svovaf)
3259
+ * @since 1.0.3
3260
+ *
3261
+ * @return FS_Site
3262
+ */
3263
+ function get_site() {
3264
+ return $this->_site;
3265
+ }
3266
+
3267
+ /**
3268
+ * @author Vova Feldman (@svovaf)
3269
+ * @since 1.0.6
3270
+ *
3271
+ * @return FS_Plugin[]|false
3272
+ */
3273
+ function get_addons() {
3274
+ $this->_logger->entrance();
3275
+
3276
+ $addons = self::get_all_addons();
3277
+
3278
+ if ( ! is_array( $addons ) ||
3279
+ ! isset( $addons[ $this->_plugin->id ] ) ||
3280
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
3281
+ 0 === count( $addons[ $this->_plugin->id ] )
3282
+ ) {
3283
+ return false;
3284
+ }
3285
+
3286
+ return $addons[ $this->_plugin->id ];
3287
+ }
3288
+
3289
+ /**
3290
+ * @author Vova Feldman (@svovaf)
3291
+ * @since 1.0.6
3292
+ *
3293
+ * @return FS_Plugin[]|false
3294
+ */
3295
+ function get_account_addons() {
3296
+ $this->_logger->entrance();
3297
+
3298
+ $addons = self::get_all_account_addons();
3299
+
3300
+ if ( ! is_array( $addons ) ||
3301
+ ! isset( $addons[ $this->_plugin->id ] ) ||
3302
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
3303
+ 0 === count( $addons[ $this->_plugin->id ] )
3304
+ ) {
3305
+ return false;
3306
+ }
3307
+
3308
+ return $addons[ $this->_plugin->id ];
3309
+ }
3310
+
3311
+ /**
3312
+ * Check if user has any
3313
+ *
3314
+ * @author Vova Feldman (@svovaf)
3315
+ * @since 1.1.6
3316
+ *
3317
+ * @return bool
3318
+ */
3319
+ function has_account_addons() {
3320
+ $addons = $this->get_account_addons();
3321
+
3322
+ return is_array( $addons ) && ( 0 < count( $addons ) );
3323
+ }
3324
+
3325
+
3326
+ /**
3327
+ * Get add-on by ID (from local data).
3328
+ *
3329
+ * @author Vova Feldman (@svovaf)
3330
+ * @since 1.0.6
3331
+ *
3332
+ * @param number $id
3333
+ *
3334
+ * @return FS_Plugin|false
3335
+ */
3336
+ function get_addon( $id ) {
3337
+ $this->_logger->entrance();
3338
+
3339
+ $addons = $this->get_addons();
3340
+
3341
+ if ( is_array( $addons ) ) {
3342
+ foreach ( $addons as $addon ) {
3343
+ if ( $id == $addon->id ) {
3344
+ return $addon;
3345
+ }
3346
+ }
3347
+ }
3348
+
3349
+ return false;
3350
+ }
3351
+
3352
+ /**
3353
+ * Get add-on by slug (from local data).
3354
+ *
3355
+ * @author Vova Feldman (@svovaf)
3356
+ * @since 1.0.6
3357
+ *
3358
+ * @param string $slug
3359
+ *
3360
+ * @return FS_Plugin|false
3361
+ */
3362
+ function get_addon_by_slug( $slug ) {
3363
+ $this->_logger->entrance();
3364
+
3365
+ $addons = $this->get_addons();
3366
+
3367
+ if ( is_array( $addons ) ) {
3368
+ foreach ( $addons as $addon ) {
3369
+ if ( $slug == $addon->slug ) {
3370
+ return $addon;
3371
+ }
3372
+ }
3373
+ }
3374
+
3375
+ return false;
3376
+ }
3377
+
3378
+ #region Plans & Licensing ------------------------------------------------------------------
3379
+
3380
+ /**
3381
+ * Check if running premium plugin code.
3382
+ *
3383
+ * @author Vova Feldman (@svovaf)
3384
+ * @since 1.0.5
3385
+ *
3386
+ * @return bool
3387
+ */
3388
+ function is_premium() {
3389
+ return $this->_plugin->is_premium;
3390
+ }
3391
+
3392
+ /**
3393
+ * Get site's plan ID.
3394
+ *
3395
+ * @author Vova Feldman (@svovaf)
3396
+ * @since 1.0.2
3397
+ *
3398
+ * @return number
3399
+ */
3400
+ function get_plan_id() {
3401
+ return $this->_site->plan->id;
3402
+ }
3403
+
3404
+ /**
3405
+ * Get site's plan title.
3406
+ *
3407
+ * @author Vova Feldman (@svovaf)
3408
+ * @since 1.0.2
3409
+ *
3410
+ * @return string
3411
+ */
3412
+ function get_plan_title() {
3413
+ return $this->_site->plan->title;
3414
+ }
3415
+
3416
+ /**
3417
+ * @author Vova Feldman (@svovaf)
3418
+ * @since 1.0.9
3419
+ *
3420
+ * @return FS_Plugin_Plan
3421
+ */
3422
+ function get_plan() {
3423
+ return is_object( $this->_site->plan ) ? $this->_site->plan : false;
3424
+ }
3425
+
3426
+ /**
3427
+ * @author Vova Feldman (@svovaf)
3428
+ * @since 1.0.3
3429
+ *
3430
+ * @return bool
3431
+ */
3432
+ function is_trial() {
3433
+ $this->_logger->entrance();
3434
+
3435
+ if ( ! $this->is_registered() ) {
3436
+ return false;
3437
+ }
3438
+
3439
+ // Paid plan beats trial.
3440
+ return $this->is_free_plan() && $this->_site->is_trial();
3441
+ }
3442
+
3443
+ /**
3444
+ * Check if trial already utilized.
3445
+ *
3446
+ * @since 1.0.9
3447
+ *
3448
+ * @return bool
3449
+ */
3450
+ function is_trial_utilized() {
3451
+ $this->_logger->entrance();
3452
+
3453
+ if ( ! $this->is_registered() ) {
3454
+ return false;
3455
+ }
3456
+
3457
+ return $this->_site->is_trial_utilized();
3458
+ }
3459
+
3460
+ /**
3461
+ * Get trial plan information (if in trial).
3462
+ *
3463
+ * @author Vova Feldman (@svovaf)
3464
+ * @since 1.0.9
3465
+ *
3466
+ * @return bool|FS_Plugin_Plan
3467
+ */
3468
+ function get_trial_plan() {
3469
+ $this->_logger->entrance();
3470
+
3471
+ if ( ! $this->is_trial() ) {
3472
+ return false;
3473
+ }
3474
+
3475
+ return $this->_storage->trial_plan;
3476
+ }
3477
+
3478
+ /**
3479
+ * Check if the user has an activated and valid paid license on current plugin's install.
3480
+ *
3481
+ * @since 1.0.9
3482
+ *
3483
+ * @return bool
3484
+ */
3485
+ function is_paying() {
3486
+ $this->_logger->entrance();
3487
+
3488
+ if ( ! $this->is_registered() ) {
3489
+ return false;
3490
+ }
3491
+
3492
+ return (
3493
+ ! $this->is_trial() &&
3494
+ 'free' !== $this->_site->plan->name &&
3495
+ $this->has_features_enabled_license()
3496
+ );
3497
+ }
3498
+
3499
+ /**
3500
+ * @author Vova Feldman (@svovaf)
3501
+ * @since 1.0.4
3502
+ *
3503
+ * @return bool
3504
+ */
3505
+ function is_free_plan() {
3506
+ if ( ! $this->is_registered() ) {
3507
+ return true;
3508
+ }
3509
+
3510
+ return (
3511
+ 'free' === $this->_site->plan->name ||
3512
+ ! $this->has_features_enabled_license()
3513
+ );
3514
+ }
3515
+
3516
+ /**
3517
+ * @author Vova Feldman (@svovaf)
3518
+ * @since 1.0.5
3519
+ *
3520
+ * @return bool
3521
+ */
3522
+ function _has_premium_license() {
3523
+ $this->_logger->entrance();
3524
+
3525
+ $premium_license = $this->_get_available_premium_license();
3526
+
3527
+ return ( false !== $premium_license );
3528
+ }
3529
+
3530
+ /**
3531
+ * @author Vova Feldman (@svovaf)
3532
+ * @since 1.0.5
3533
+ *
3534
+ * @return FS_Plugin_License
3535
+ */
3536
+ function _get_available_premium_license() {
3537
+ $this->_logger->entrance();
3538
+
3539
+ if ( is_array( $this->_licenses ) ) {
3540
+ foreach ( $this->_licenses as $license ) {
3541
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
3542
+ return $license;
3543
+ }
3544
+ }
3545
+ }
3546
+
3547
+ return false;
3548
+ }
3549
+
3550
+ /**
3551
+ * Sync local plugin plans with remote server.
3552
+ *
3553
+ * @author Vova Feldman (@svovaf)
3554
+ * @since 1.0.5
3555
+ *
3556
+ * @return FS_Plugin_Plan[]|object
3557
+ */
3558
+ function _sync_plans() {
3559
+ $plans = $this->_fetch_plugin_plans();
3560
+ if ( ! $this->is_api_error( $plans ) ) {
3561
+ $this->_plans = $plans;
3562
+ $this->_store_plans();
3563
+ }
3564
+
3565
+ $this->do_action( 'after_plans_sync', $plans );
3566
+
3567
+ return $this->_plans;
3568
+ }
3569
+
3570
+ /**
3571
+ * @author Vova Feldman (@svovaf)
3572
+ * @since 1.0.5
3573
+ *
3574
+ * @param number $id
3575
+ *
3576
+ * @return FS_Plugin_Plan
3577
+ */
3578
+ function _get_plan_by_id( $id ) {
3579
+ $this->_logger->entrance();
3580
+
3581
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
3582
+ $this->_sync_plans();
3583
+ }
3584
+
3585
+ foreach ( $this->_plans as $plan ) {
3586
+ if ( $id == $plan->id ) {
3587
+ return $plan;
3588
+ }
3589
+ }
3590
+
3591
+ return false;
3592
+ }
3593
+
3594
+ /**
3595
+ * Sync local plugin plans with remote server.
3596
+ *
3597
+ * @author Vova Feldman (@svovaf)
3598
+ * @since 1.0.6
3599
+ *
3600
+ * @return FS_Plugin_License[]|object
3601
+ */
3602
+ function _sync_licenses() {
3603
+ $licenses = $this->_fetch_licenses();
3604
+ if ( ! isset( $licenses->error ) ) {
3605
+ $this->_licenses = $licenses;
3606
+ $this->_store_licenses();
3607
+ }
3608
+
3609
+ // Update current license.
3610
+ if ( is_object( $this->_license ) ) {
3611
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
3612
+ }
3613
+
3614
+ return $this->_licenses;
3615
+ }
3616
+
3617
+ /**
3618
+ * @author Vova Feldman (@svovaf)
3619
+ * @since 1.0.5
3620
+ *
3621
+ * @param number $id
3622
+ *
3623
+ * @return FS_Plugin_License
3624
+ */
3625
+ function _get_license_by_id( $id ) {
3626
+ $this->_logger->entrance();
3627
+
3628
+ if ( ! is_numeric( $id ) ) {
3629
+ return false;
3630
+ }
3631
+
3632
+ if ( ! is_array( $this->_licenses ) || 0 === count( $this->_licenses ) ) {
3633
+ $this->_sync_licenses();
3634
+ }
3635
+
3636
+ foreach ( $this->_licenses as $license ) {
3637
+ if ( $id == $license->id ) {
3638
+ return $license;
3639
+ }
3640
+ }
3641
+
3642
+ return false;
3643
+ }
3644
+
3645
+ /**
3646
+ * Sync site's license with user licenses.
3647
+ *
3648
+ * @author Vova Feldman (@svovaf)
3649
+ * @since 1.0.6
3650
+ *
3651
+ * @param FS_Plugin_License|null $new_license
3652
+ */
3653
+ function _update_site_license( $new_license ) {
3654
+ $this->_logger->entrance();
3655
+
3656
+ $this->_license = $new_license;
3657
+
3658
+ if ( ! is_object( $new_license ) ) {
3659
+ $this->_site->license_id = null;
3660
+ $this->_sync_site_subscription( null );
3661
+
3662
+ return;
3663
+ }
3664
+
3665
+ $this->_site->license_id = $this->_license->id;
3666
+
3667
+ if ( ! is_array( $this->_licenses ) ) {
3668
+ $this->_licenses = array();
3669
+ }
3670
+
3671
+ $is_license_found = false;
3672
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
3673
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
3674
+ $this->_licenses[ $i ] = $new_license;
3675
+
3676
+ $is_license_found = true;
3677
+ break;
3678
+ }
3679
+ }
3680
+
3681
+ // If new license just append.
3682
+ if ( ! $is_license_found ) {
3683
+ $this->_licenses[] = $new_license;
3684
+ }
3685
+
3686
+ $this->_sync_site_subscription( $new_license );
3687
+ }
3688
+
3689
+ /**
3690
+ * Sync site's subscription.
3691
+ *
3692
+ * @author Vova Feldman (@svovaf)
3693
+ * @since 1.0.9
3694
+ *
3695
+ * @param FS_Plugin_License|null $license
3696
+ *
3697
+ * @return bool|\FS_Subscription
3698
+ */
3699
+ private function _sync_site_subscription( $license ) {
3700
+ if ( ! is_object( $license ) ) {
3701
+ unset( $this->_storage->subscription );
3702
+
3703
+ return false;
3704
+ }
3705
+
3706
+ // Load subscription details if not lifetime.
3707
+ $subscription = $license->is_lifetime() ?
3708
+ false :
3709
+ $this->_fetch_site_license_subscription();
3710
+
3711
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
3712
+ $this->_storage->subscription = $subscription;
3713
+ } else {
3714
+ unset( $this->_storage->subscription );
3715
+ }
3716
+
3717
+ return $subscription;
3718
+ }
3719
+
3720
+ /**
3721
+ * @author Vova Feldman (@svovaf)
3722
+ * @since 1.0.6
3723
+ *
3724
+ * @return bool|\FS_Plugin_License
3725
+ */
3726
+ function _get_license() {
3727
+ return $this->_license;
3728
+ }
3729
+
3730
+ /**
3731
+ * @return bool|\FS_Subscription
3732
+ */
3733
+ function _get_subscription() {
3734
+ return isset( $this->_storage->subscription ) ?
3735
+ $this->_storage->subscription :
3736
+ false;
3737
+ }
3738
+
3739
+ /**
3740
+ * @author Vova Feldman (@svovaf)
3741
+ * @since 1.0.2
3742
+ *
3743
+ * @param string $plan Plan name
3744
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
3745
+ *
3746
+ * @return bool
3747
+ */
3748
+ function is_plan( $plan, $exact = false ) {
3749
+ $this->_logger->entrance();
3750
+
3751
+ if ( ! $this->is_registered() ) {
3752
+ return false;
3753
+ }
3754
+
3755
+ $plan = strtolower( $plan );
3756
+
3757
+ if ( $this->_site->plan->name === $plan ) // Exact plan.
3758
+ {
3759
+ return true;
3760
+ } else if ( $exact ) // Required exact, but plans are different.
3761
+ {
3762
+ return false;
3763
+ }
3764
+
3765
+ $current_plan_order = - 1;
3766
+ $required_plan_order = - 1;
3767
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
3768
+ if ( $plan === $this->_plans[ $i ]->name ) {
3769
+ $required_plan_order = $i;
3770
+ } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
3771
+ $current_plan_order = $i;
3772
+ }
3773
+ }
3774
+
3775
+ return ( $current_plan_order > $required_plan_order );
3776
+ }
3777
+
3778
+ /**
3779
+ * Check if plan based on trial. If not in trial mode, should return false.
3780
+ *
3781
+ * @since 1.0.9
3782
+ *
3783
+ * @param string $plan Plan name
3784
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
3785
+ *
3786
+ * @return bool
3787
+ */
3788
+ function is_trial_plan( $plan, $exact = false ) {
3789
+ $this->_logger->entrance();
3790
+
3791
+ if ( ! $this->is_registered() ) {
3792
+ return false;
3793
+ }
3794
+
3795
+ if ( ! $this->is_trial() ) {
3796
+ return false;
3797
+ }
3798
+
3799
+ if ( ! isset( $this->_storage->trial_plan ) ) {
3800
+ // Store trial plan information.
3801
+ $this->_enrich_site_trial_plan( true );
3802
+ }
3803
+
3804
+ if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
3805
+ {
3806
+ return true;
3807
+ } else if ( $exact ) // Required exact, but plans are different.
3808
+ {
3809
+ return false;
3810
+ }
3811
+
3812
+ $current_plan_order = - 1;
3813
+ $required_plan_order = - 1;
3814
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
3815
+ if ( $plan === $this->_plans[ $i ]->name ) {
3816
+ $required_plan_order = $i;
3817
+ } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
3818
+ $current_plan_order = $i;
3819
+ }
3820
+ }
3821
+
3822
+ return ( $current_plan_order > $required_plan_order );
3823
+ }
3824
+
3825
+ /**
3826
+ * Check if plugin has any paid plans.
3827
+ *
3828
+ * @author Vova Feldman (@svovaf)
3829
+ * @since 1.0.7
3830
+ *
3831
+ * @return bool
3832
+ */
3833
+ function has_paid_plan() {
3834
+ return $this->_has_paid_plans || FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
3835
+ }
3836
+
3837
+ /**
3838
+ * Check if plugin has any plan with a trail.
3839
+ *
3840
+ * @author Vova Feldman (@svovaf)
3841
+ * @since 1.0.9
3842
+ *
3843
+ * @return bool
3844
+ */
3845
+ function has_trial_plan() {
3846
+ if ( ! $this->is_registered() ) {
3847
+ return false;
3848
+ }
3849
+
3850
+ return $this->_storage->get( 'has_trial_plan', false );
3851
+ }
3852
+
3853
+ /**
3854
+ * Check if plugin has any free plan, or is it premium only.
3855
+ *
3856
+ * Note: If no plans configured, assume plugin is free.
3857
+ *
3858
+ * @author Vova Feldman (@svovaf)
3859
+ * @since 1.0.7
3860
+ *
3861
+ * @return bool
3862
+ */
3863
+ function has_free_plan() {
3864
+ return FS_Plan_Manager::instance()->has_free_plan( $this->_plans );
3865
+ }
3866
+
3867
+ #region URL Generators
3868
+
3869
+ /**
3870
+ * Alias to pricing_url().
3871
+ *
3872
+ * @author Vova Feldman (@svovaf)
3873
+ * @since 1.0.2
3874
+ *
3875
+ * @uses pricing_url
3876
+ *
3877
+ * @param string $period Billing cycle
3878
+ *
3879
+ * @return string
3880
+ */
3881
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY ) {
3882
+ return $this->pricing_url( $period );
3883
+ }
3884
+
3885
+ /**
3886
+ * @author Vova Feldman (@svovaf)
3887
+ * @since 1.0.9
3888
+ *
3889
+ * @uses get_upgrade_url
3890
+ *
3891
+ * @return string
3892
+ */
3893
+ function get_trial_url() {
3894
+ return $this->get_upgrade_url( 'trial' );
3895
+ }
3896
+
3897
+ /**
3898
+ * Plugin's pricing URL.
3899
+ *
3900
+ * @author Vova Feldman (@svovaf)
3901
+ * @since 1.0.4
3902
+ *
3903
+ * @param string $period Billing cycle
3904
+ *
3905
+ * @return string
3906
+ */
3907
+ function pricing_url( $period = WP_FS__PERIOD_ANNUALLY ) {
3908
+ $this->_logger->entrance();
3909
+
3910
+ return $this->_get_admin_page_url( 'pricing', array( 'billing_cycle' => $period ) );
3911
+ }
3912
+
3913
+ /**
3914
+ * Checkout page URL.
3915
+ *
3916
+ * @author Vova Feldman (@svovaf)
3917
+ * @since 1.0.6
3918
+ *
3919
+ * @param string $period Billing cycle
3920
+ * @param bool|string $plan_name
3921
+ * @param bool|number $plan_id
3922
+ * @param bool|int $licenses
3923
+ *
3924
+ * @return string
3925
+ */
3926
+ function checkout_url(
3927
+ $period = WP_FS__PERIOD_ANNUALLY,
3928
+ $plan_name = false,
3929
+ $plan_id = false,
3930
+ $licenses = false
3931
+ ) {
3932
+ $this->_logger->entrance();
3933
+
3934
+ $params = array(
3935
+ 'checkout' => 'true',
3936
+ 'billing_cycle' => $period,
3937
+ );
3938
+
3939
+ if ( false !== $plan_name ) {
3940
+ $params['plan_name'] = $plan_name;
3941
+ }
3942
+ if ( false !== $plan_id ) {
3943
+ $params['plan_id'] = $plan_id;
3944
+ }
3945
+ if ( false !== $licenses ) {
3946
+ $params['licenses'] = $licenses;
3947
+ }
3948
+
3949
+ return $this->_get_admin_page_url( 'pricing', $params );
3950
+ }
3951
+
3952
+ #endregion
3953
+
3954
+ #endregion ------------------------------------------------------------------
3955
+
3956
+ /**
3957
+ * Check if plugin has any add-ons.
3958
+ *
3959
+ * @author Vova Feldman (@svovaf)
3960
+ * @since 1.0.5
3961
+ *
3962
+ * @return bool
3963
+ */
3964
+ function _has_addons() {
3965
+ $this->_logger->entrance();
3966
+
3967
+ return ( $this->_has_addons || false !== $this->get_addons() );
3968
+ }
3969
+
3970
+ /**
3971
+ * Check if plugin can work in anonymous mode.
3972
+ *
3973
+ * @author Vova Feldman (@svovaf)
3974
+ * @since 1.0.9
3975
+ *
3976
+ * @return bool
3977
+ */
3978
+ function enable_anonymous() {
3979
+ return $this->_enable_anonymous;
3980
+ }
3981
+
3982
+ /**
3983
+ * Check if feature supported with current site's plan.
3984
+ *
3985
+ * @author Vova Feldman (@svovaf)
3986
+ * @since 1.0.1
3987
+ *
3988
+ * @todo IMPLEMENT
3989
+ *
3990
+ * @param number $feature_id
3991
+ *
3992
+ * @throws Exception
3993
+ */
3994
+ function is_feature_supported( $feature_id ) {
3995
+ throw new Exception( 'not implemented' );
3996
+ }
3997
+
3998
+ /**
3999
+ * @author Vova Feldman (@svovaf)
4000
+ * @since 1.0.1
4001
+ *
4002
+ * @return bool Is running in SSL/HTTPS
4003
+ */
4004
+ function is_ssl() {
4005
+ return WP_FS__IS_HTTPS;
4006
+ }
4007
+
4008
+ /**
4009
+ * @author Vova Feldman (@svovaf)
4010
+ * @since 1.0.9
4011
+ *
4012
+ * @return bool Is running in AJAX call.
4013
+ *
4014
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
4015
+ */
4016
+ function is_ajax() {
4017
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
4018
+ }
4019
+
4020
+ /**
4021
+ * Check if running in HTTPS and if site's plan matching the specified plan.
4022
+ *
4023
+ * @param string $plan
4024
+ * @param bool $exact
4025
+ *
4026
+ * @return bool
4027
+ */
4028
+ function is_ssl_and_plan( $plan, $exact = false ) {
4029
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
4030
+ }
4031
+
4032
+ /**
4033
+ * Construct plugin's settings page URL.
4034
+ *
4035
+ * @author Vova Feldman (@svovaf)
4036
+ * @since 1.0.4
4037
+ *
4038
+ * @param string $page
4039
+ * @param array $params
4040
+ *
4041
+ * @return string
4042
+ */
4043
+ function _get_admin_page_url( $page = '', $params = array() ) {
4044
+ if ( ! $this->_menu->is_top_level() ) {
4045
+ $parent_slug = $this->_menu->get_parent_slug();
4046
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
4047
+ $parent_slug :
4048
+ 'admin.php';
4049
+
4050
+ return add_query_arg( array_merge( $params, array(
4051
+ 'page' => $this->_menu->get_slug( $page ),
4052
+ ) ), admin_url( $menu_file, 'admin' ) );
4053
+ }
4054
+
4055
+ if ( $this->_menu->is_cpt() ) {
4056
+ if ( empty( $page ) && $this->is_activation_mode() ) {
4057
+ return add_query_arg( array_merge( $params, array(
4058
+ 'page' => $this->_menu->get_slug()
4059
+ ) ), admin_url( 'admin.php', 'admin' ) );
4060
+ } else {
4061
+ if ( ! empty( $page ) ) {
4062
+ $params['page'] = $this->_menu->get_slug( $page );
4063
+ }
4064
+
4065
+ return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
4066
+ }
4067
+ } else {
4068
+ return add_query_arg( array_merge( $params, array(
4069
+ 'page' => $this->_menu->get_slug( $page ),
4070
+ ) ), admin_url( 'admin.php', 'admin' ) );
4071
+ }
4072
+ }
4073
+
4074
+
4075
+ /**
4076
+ * Plugin's account URL.
4077
+ *
4078
+ * @author Vova Feldman (@svovaf)
4079
+ * @since 1.0.4
4080
+ *
4081
+ * @param bool|string $action
4082
+ * @param array $params
4083
+ *
4084
+ * @param bool $add_action_nonce
4085
+ *
4086
+ * @return string
4087
+ */
4088
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
4089
+ if ( is_string( $action ) ) {
4090
+ $params['fs_action'] = $action;
4091
+ }
4092
+
4093
+ self::require_pluggable_essentials();
4094
+
4095
+ return ( $add_action_nonce && is_string( $action ) ) ?
4096
+ wp_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
4097
+ $this->_get_admin_page_url( 'account', $params );
4098
+ }
4099
+
4100
+ /**
4101
+ * Plugin's account URL.
4102
+ *
4103
+ * @author Vova Feldman (@svovaf)
4104
+ * @since 1.0.4
4105
+ *
4106
+ * @param bool|string $topic
4107
+ * @param bool|string $message
4108
+ *
4109
+ * @return string
4110
+ */
4111
+ function contact_url( $topic = false, $message = false ) {
4112
+ $params = array();
4113
+ if ( is_string( $topic ) ) {
4114
+ $params['topic'] = $topic;
4115
+ }
4116
+ if ( is_string( $message ) ) {
4117
+ $params['message'] = $message;
4118
+ }
4119
+
4120
+ if ( $this->is_addon() ) {
4121
+ $params['addon_id'] = $this->get_id();
4122
+
4123
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
4124
+ } else {
4125
+ return $this->_get_admin_page_url( 'contact', $params );
4126
+ }
4127
+ }
4128
+
4129
+ /**
4130
+ * Add-on direct info URL.
4131
+ *
4132
+ * @author Vova Feldman (@svovaf)
4133
+ * @since 1.1.0
4134
+ *
4135
+ * @param string $slug
4136
+ *
4137
+ * @return string
4138
+ */
4139
+ function addon_url( $slug ) {
4140
+ return $this->_get_admin_page_url( 'addons', array(
4141
+ 'slug' => $slug
4142
+ ) );
4143
+ }
4144
+
4145
+ /* Logger
4146
+ ------------------------------------------------------------------------------------------------------------------*/
4147
+ /**
4148
+ * @param string $id
4149
+ * @param bool $prefix_slug
4150
+ *
4151
+ * @return FS_Logger
4152
+ */
4153
+ function get_logger( $id = '', $prefix_slug = true ) {
4154
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
4155
+ }
4156
+
4157
+ /**
4158
+ * @param $id
4159
+ * @param bool $load_options
4160
+ * @param bool $prefix_slug
4161
+ *
4162
+ * @return FS_Option_Manager
4163
+ */
4164
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
4165
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
4166
+ }
4167
+
4168
+ /* Security
4169
+ ------------------------------------------------------------------------------------------------------------------*/
4170
+ private function _encrypt( $str ) {
4171
+ if ( is_null( $str ) ) {
4172
+ return null;
4173
+ }
4174
+
4175
+ return base64_encode( $str );
4176
+ }
4177
+
4178
+ private function _decrypt( $str ) {
4179
+ if ( is_null( $str ) ) {
4180
+ return null;
4181
+ }
4182
+
4183
+ return base64_decode( $str );
4184
+ }
4185
+
4186
+ /**
4187
+ * @author Vova Feldman (@svovaf)
4188
+ * @since 1.0.5
4189
+ *
4190
+ * @param FS_Entity $entity
4191
+ *
4192
+ * @return FS_Entity Return an encrypted clone entity.
4193
+ */
4194
+ private function _encrypt_entity( FS_Entity $entity ) {
4195
+ $clone = clone $entity;
4196
+ $props = get_object_vars( $entity );
4197
+
4198
+ foreach ( $props as $key => $val ) {
4199
+ $clone->{$key} = $this->_encrypt( $val );
4200
+ }
4201
+
4202
+ return $clone;
4203
+ }
4204
+
4205
+ /**
4206
+ * @author Vova Feldman (@svovaf)
4207
+ * @since 1.0.5
4208
+ *
4209
+ * @param FS_Entity $entity
4210
+ *
4211
+ * @return FS_Entity Return an decrypted clone entity.
4212
+ */
4213
+ private function _decrypt_entity( FS_Entity $entity ) {
4214
+ $clone = clone $entity;
4215
+ $props = get_object_vars( $entity );
4216
+
4217
+ foreach ( $props as $key => $val ) {
4218
+ $clone->{$key} = $this->_decrypt( $val );
4219
+ }
4220
+
4221
+ return $clone;
4222
+ }
4223
+
4224
+ /**
4225
+ * Tries to activate account based on POST params.
4226
+ *
4227
+ * @author Vova Feldman (@svovaf)
4228
+ * @since 1.0.2
4229
+ */
4230
+ function _activate_account() {
4231
+ if ( $this->is_registered() ) {
4232
+ // Already activated.
4233
+ return;
4234
+ }
4235
+
4236
+ self::_clean_admin_content_section();
4237
+
4238
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
4239
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
4240
+
4241
+ // Verify matching plugin details.
4242
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
4243
+ return;
4244
+ }
4245
+
4246
+ $user = new FS_User();
4247
+ $user->id = fs_request_get( 'user_id' );
4248
+ $user->public_key = fs_request_get( 'user_public_key' );
4249
+ $user->secret_key = fs_request_get( 'user_secret_key' );
4250
+ $user->email = fs_request_get( 'user_email' );
4251
+ $user->first = fs_request_get( 'user_first' );
4252
+ $user->last = fs_request_get( 'user_last' );
4253
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
4254
+
4255
+ $site = new FS_Site();
4256
+ $site->id = fs_request_get( 'install_id' );
4257
+ $site->public_key = fs_request_get( 'install_public_key' );
4258
+ $site->secret_key = fs_request_get( 'install_secret_key' );
4259
+ $site->plan->id = fs_request_get( 'plan_id' );
4260
+ $site->plan->title = fs_request_get( 'plan_title' );
4261
+ $site->plan->name = fs_request_get( 'plan_name' );
4262
+
4263
+ $plans = array();
4264
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
4265
+ foreach ( $plans_data as $p ) {
4266
+ $plans[] = new FS_Plugin_Plan( $p );
4267
+ }
4268
+
4269
+ $this->_set_account( $user, $site, $plans );
4270
+
4271
+ // Reload the page with the keys.
4272
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
4273
+ exit();
4274
+ }
4275
+ }
4276
+ }
4277
+
4278
+ /**
4279
+ * @author Vova Feldman (@svovaf)
4280
+ * @since 1.0.7
4281
+ *
4282
+ * @param string $email
4283
+ *
4284
+ * @return FS_User|bool
4285
+ */
4286
+ static function _get_user_by_email( $email ) {
4287
+ self::$_static_logger->entrance();
4288
+
4289
+ $email = trim( strtolower( $email ) );
4290
+ $users = self::get_all_users();
4291
+ if ( is_array( $users ) ) {
4292
+ foreach ( $users as $u ) {
4293
+ if ( $email === trim( strtolower( $u->email ) ) ) {
4294
+ return $u;
4295
+ }
4296
+ }
4297
+ }
4298
+
4299
+ return false;
4300
+ }
4301
+
4302
+ #region Account (Loading, Updates & Activation) ------------------------------------------------------------------
4303
+
4304
+ /***
4305
+ * Load account information (user + site).
4306
+ *
4307
+ * @author Vova Feldman (@svovaf)
4308
+ * @since 1.0.1
4309
+ */
4310
+ private function _load_account() {
4311
+ $this->_logger->entrance();
4312
+
4313
+ $this->do_action( 'before_account_load' );
4314
+
4315
+ $sites = self::get_all_sites();
4316
+ $users = self::get_all_users();
4317
+ $plans = self::get_all_plans();
4318
+ $licenses = self::get_all_licenses();
4319
+
4320
+ if ( $this->_logger->is_on() && is_admin() ) {
4321
+ $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
4322
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
4323
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
4324
+ $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
4325
+ }
4326
+
4327
+ $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
4328
+
4329
+ if ( is_object( $site ) &&
4330
+ is_numeric( $site->id ) &&
4331
+ is_numeric( $site->user_id ) &&
4332
+ is_object( $site->plan )
4333
+ ) {
4334
+ // Load site.
4335
+ $this->_site = clone $site;
4336
+ $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
4337
+
4338
+ // Load relevant user.
4339
+ $this->_user = clone $users[ $this->_site->user_id ];
4340
+
4341
+ // Load plans.
4342
+ $this->_plans = $plans[ $this->_slug ];
4343
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
4344
+ $this->_sync_plans( true );
4345
+ } else {
4346
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4347
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
4348
+ $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
4349
+ } else {
4350
+ unset( $this->_plans[ $i ] );
4351
+ }
4352
+ }
4353
+ }
4354
+
4355
+ // Load licenses.
4356
+ $this->_licenses = array();
4357
+ if ( is_array( $licenses ) &&
4358
+ isset( $licenses[ $this->_slug ] ) &&
4359
+ isset( $licenses[ $this->_slug ][ $this->_user->id ] )
4360
+ ) {
4361
+ $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
4362
+ }
4363
+
4364
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
4365
+
4366
+ if ( $this->_site->version != $this->get_plugin_version() ) {
4367
+ // If stored install version is different than current installed plugin version,
4368
+ // then update plugin version event.
4369
+ $this->update_plugin_version_event();
4370
+ }
4371
+ }
4372
+
4373
+ $this->_register_account_hooks();
4374
+ }
4375
+
4376
+ /**
4377
+ * @author Vova Feldman (@svovaf)
4378
+ * @since 1.0.1
4379
+ *
4380
+ * @param FS_User $user
4381
+ * @param FS_Site $site
4382
+ * @param bool|array $plans
4383
+ */
4384
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
4385
+ $site->slug = $this->_slug;
4386
+ $site->user_id = $user->id;
4387
+
4388
+ $this->_site = $site;
4389
+ $this->_user = $user;
4390
+ if ( false !== $plans ) {
4391
+ $this->_plans = $plans;
4392
+ }
4393
+
4394
+ $this->send_install_update( array(), true );
4395
+
4396
+ $this->_store_account();
4397
+
4398
+ }
4399
+
4400
+ /**
4401
+ * Set user and site identities.
4402
+ *
4403
+ * @author Vova Feldman (@svovaf)
4404
+ * @since 1.0.9
4405
+ *
4406
+ * @param FS_User $user
4407
+ * @param FS_Site $site
4408
+ * @param bool $redirect
4409
+ *
4410
+ * @return bool False if account already set.
4411
+ */
4412
+ function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
4413
+ $this->_user = $user;
4414
+ $this->_site = $site;
4415
+
4416
+ $this->_sync_plans();
4417
+
4418
+ $this->_enrich_site_plan( false );
4419
+
4420
+ $this->_set_account( $user, $site );
4421
+
4422
+ if ( $this->is_trial() ) {
4423
+ // Store trial plan information.
4424
+ $this->_enrich_site_trial_plan( true );
4425
+ }
4426
+
4427
+ $this->do_action( 'after_account_connection', $user, $site );
4428
+
4429
+ if ( is_numeric( $site->license_id ) ) {
4430
+ $this->_license = $this->_get_license_by_id( $site->license_id );
4431
+ }
4432
+
4433
+ if ( $this->is_pending_activation() ) {
4434
+ // Remove pending activation sticky notice (if still exist).
4435
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
4436
+
4437
+ // Remove plugin from pending activation mode.
4438
+ unset( $this->_storage->is_pending_activation );
4439
+
4440
+ if ( ! $this->is_paying() ) {
4441
+ $this->_admin_notices->add_sticky(
4442
+ sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
4443
+ 'activation_complete'
4444
+ );
4445
+ }
4446
+ }
4447
+
4448
+ if ( $this->is_paying() && ! $this->is_premium() ) {
4449
+ $this->_admin_notices->add_sticky(
4450
+ sprintf(
4451
+ __fs( 'activation-with-plan-x-message', $this->_slug ),
4452
+ $this->_site->plan->title
4453
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
4454
+ __fs( 'download-latest-x-version', $this->_slug ),
4455
+ $this->_site->plan->title
4456
+ ) ),
4457
+ 'plan_upgraded',
4458
+ __fs( 'yee-haw', $this->_slug ) . '!'
4459
+ );
4460
+ }
4461
+
4462
+ $plugin_id = fs_request_get( 'plugin_id', false );
4463
+
4464
+ // Store activation time ONLY for plugins (not add-ons).
4465
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
4466
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
4467
+ }
4468
+
4469
+ if ( is_numeric( $plugin_id ) ) {
4470
+ if ( $plugin_id != $this->_plugin->id ) {
4471
+ // Add-on was installed - sync license right after install.
4472
+ if ( $redirect && fs_redirect( fs_nonce_url( $this->_get_admin_page_url(
4473
+ 'account',
4474
+ array(
4475
+ 'fs_action' => $this->_slug . '_sync_license',
4476
+ 'plugin_id' => $plugin_id
4477
+ )
4478
+ ), $this->_slug . '_sync_license' ) )
4479
+ ) {
4480
+ exit();
4481
+ }
4482
+
4483
+ }
4484
+ } else {
4485
+ // Reload the page with the keys.
4486
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_connect_url' ) ) ) {
4487
+ exit();
4488
+ }
4489
+ }
4490
+ }
4491
+
4492
+ /**
4493
+ * Install plugin with new user information after approval.
4494
+ *
4495
+ * @author Vova Feldman (@svovaf)
4496
+ * @since 1.0.7
4497
+ */
4498
+ function _install_with_new_user() {
4499
+ $this->_logger->entrance();
4500
+
4501
+ if ( $this->is_registered() ) {
4502
+ return;
4503
+ }
4504
+
4505
+ if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
4506
+ // check_admin_referer( $this->_slug . '_activate_new' );
4507
+
4508
+ $this->_admin_notices->remove_sticky( 'connect_account' );
4509
+
4510
+ if ( fs_request_has( 'user_secret_key' ) ) {
4511
+ $user = new FS_User();
4512
+ $user->id = fs_request_get( 'user_id' );
4513
+ $user->public_key = fs_request_get( 'user_public_key' );
4514
+ $user->secret_key = fs_request_get( 'user_secret_key' );
4515
+
4516
+ $this->_user = $user;
4517
+ $user_result = $this->get_api_user_scope()->get();
4518
+ $user = new FS_User( $user_result );
4519
+ $this->_user = $user;
4520
+
4521
+ $site = new FS_Site();
4522
+ $site->id = fs_request_get( 'install_id' );
4523
+ $site->public_key = fs_request_get( 'install_public_key' );
4524
+ $site->secret_key = fs_request_get( 'install_secret_key' );
4525
+
4526
+ $this->_site = $site;
4527
+ $site_result = $this->get_api_site_scope()->get();
4528
+ $site = new FS_Site( $site_result );
4529
+ $this->_site = $site;
4530
+
4531
+ $this->setup_account( $this->_user, $this->_site );
4532
+ } else if ( fs_request_has( 'pending_activation' ) ) {
4533
+ // Install must be activated via email since
4534
+ // user with the same email already exist.
4535
+ $this->_storage->is_pending_activation = true;
4536
+ $this->_add_pending_activation_notice( fs_request_get( 'user_email' ) );
4537
+
4538
+ // Reload the page with with pending activation message.
4539
+ if ( fs_redirect( $this->get_after_activation_url( 'after_pending_connect_url' ) ) ) {
4540
+ exit();
4541
+ }
4542
+ }
4543
+ }
4544
+ }
4545
+
4546
+ /**
4547
+ * Install plugin with current logged WP user info.
4548
+ *
4549
+ * @author Vova Feldman (@svovaf)
4550
+ * @since 1.0.7
4551
+ */
4552
+ function _install_with_current_user() {
4553
+ $this->_logger->entrance();
4554
+
4555
+ if ( $this->is_registered() ) {
4556
+ return;
4557
+ }
4558
+
4559
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
4560
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
4561
+
4562
+ $this->_admin_notices->remove_sticky( 'connect_account' );
4563
+
4564
+ // Get current logged WP user.
4565
+ $current_user = wp_get_current_user();
4566
+
4567
+ // Find the relevant FS user by the email.
4568
+ $user = self::_get_user_by_email( $current_user->user_email );
4569
+
4570
+ // We have to set the user before getting user scope API handler.
4571
+ $this->_user = $user;
4572
+
4573
+ // Install the plugin.
4574
+ $install = $this->get_api_user_scope()->call(
4575
+ "/plugins/{$this->get_id()}/installs.json",
4576
+ 'post',
4577
+ $this->get_install_data_for_api( array(
4578
+ 'uid' => $this->get_anonymous_id(),
4579
+ ) )
4580
+ );
4581
+
4582
+ if ( isset( $install->error ) ) {
4583
+ $this->_admin_notices->add(
4584
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
4585
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
4586
+ __fs( 'oops', $this->_slug ) . '...',
4587
+ 'error'
4588
+ );
4589
+
4590
+ return;
4591
+ }
4592
+
4593
+ $site = new FS_Site( $install );
4594
+ $this->_site = $site;
4595
+ // $this->_enrich_site_plan( false );
4596
+
4597
+ // $this->_set_account( $user, $site );
4598
+ // $this->_sync_plans();
4599
+
4600
+ $this->setup_account( $this->_user, $this->_site );
4601
+ }
4602
+ }
4603
+
4604
+ /**
4605
+ * Tries to activate add-on account based on parent plugin info.
4606
+ *
4607
+ * @author Vova Feldman (@svovaf)
4608
+ * @since 1.0.6
4609
+ *
4610
+ * @param Freemius $parent_fs
4611
+ */
4612
+ private function _activate_addon_account( Freemius $parent_fs ) {
4613
+ if ( $this->is_registered() ) {
4614
+ // Already activated.
4615
+ return;
4616
+ }
4617
+
4618
+ // Activate add-on with parent plugin credentials.
4619
+ $addon_install = $parent_fs->get_api_site_scope()->call(
4620
+ "/addons/{$this->_plugin->id}/installs.json",
4621
+ 'post',
4622
+ $this->get_install_data_for_api( array(
4623
+ 'uid' => $this->get_anonymous_id(),
4624
+ ) )
4625
+ );
4626
+
4627
+ if ( isset( $addon_install->error ) ) {
4628
+ $this->_admin_notices->add(
4629
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
4630
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
4631
+ __fs( 'oops', $this->_slug ) . '...',
4632
+ 'error'
4633
+ );
4634
+
4635
+ return;
4636
+ }
4637
+
4638
+ // First of all, set site info - otherwise we won't
4639
+ // be able to invoke API calls.
4640
+ $this->_site = new FS_Site( $addon_install );
4641
+
4642
+ // Sync add-on plans.
4643
+ $this->_sync_plans();
4644
+
4645
+ // Get site's current plan.
4646
+ $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
4647
+
4648
+ // Get user information based on parent's plugin.
4649
+ $user = $parent_fs->get_user();
4650
+
4651
+ $this->_set_account( $user, $this->_site );
4652
+
4653
+ // Sync licenses.
4654
+ $this->_sync_licenses();
4655
+
4656
+ // Try to activate premium license.
4657
+ $this->_activate_license( true );
4658
+ }
4659
+
4660
+ #endregion ------------------------------------------------------------------
4661
+
4662
+ #region Admin Menu Items ------------------------------------------------------------------
4663
+
4664
+ private $_menu_items = array();
4665
+
4666
+ /**
4667
+ * @author Vova Feldman (@svovaf)
4668
+ * @since 1.0.7
4669
+ *
4670
+ * @return string
4671
+ */
4672
+ function get_menu_slug() {
4673
+ return $this->_menu->get_slug();
4674
+ }
4675
+
4676
+ /**
4677
+ * @author Vova Feldman (@svovaf)
4678
+ * @since 1.0.9
4679
+ */
4680
+ function _prepare_admin_menu() {
4681
+ if ( ! $this->is_on() ) {
4682
+ return;
4683
+ }
4684
+
4685
+ if ( ! $this->has_api_connectivity() && ! $this->enable_anonymous() ) {
4686
+ $this->_menu->remove_menu_item();
4687
+ } else {
4688
+ $this->add_submenu_items();
4689
+ $this->add_menu_action();
4690
+ }
4691
+ }
4692
+
4693
+ /**
4694
+ * Admin dashboard menu items modifications.
4695
+ *
4696
+ * NOTE: admin_menu action executed before admin_init.
4697
+ *
4698
+ * @author Vova Feldman (@svovaf)
4699
+ * @since 1.0.7
4700
+ *
4701
+ */
4702
+ private function add_menu_action() {
4703
+ if ( $this->is_activation_mode() ) {
4704
+ $this->override_plugin_menu_with_activation();
4705
+ } else {
4706
+ // If not registered try to install user.
4707
+ if ( ! $this->is_registered() &&
4708
+ fs_request_is_action( $this->_slug . '_activate_new' )
4709
+ ) {
4710
+ $this->_install_with_new_user();
4711
+ }
4712
+ }
4713
+ }
4714
+
4715
+ /**
4716
+ * @author Vova Feldman (@svovaf)
4717
+ * @since 1.0.1
4718
+ *
4719
+ * @return string
4720
+ */
4721
+ function _redirect_on_clicked_menu_link() {
4722
+ $this->_logger->entrance();
4723
+
4724
+ $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
4725
+
4726
+ $this->_logger->log( 'page = ' . $page );
4727
+
4728
+ foreach ( $this->_menu_items as $priority => $items ) {
4729
+ foreach ( $items as $item ) {
4730
+ if ( isset( $item['url'] ) ) {
4731
+ if ( $page === $item['menu_slug'] ) {
4732
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
4733
+
4734
+ fs_redirect( $item['url'] );
4735
+ }
4736
+ }
4737
+ }
4738
+ }
4739
+ }
4740
+
4741
+ /**
4742
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
4743
+ *
4744
+ * @author Vova Feldman (@svovaf)
4745
+ * @since 1.0.1
4746
+ */
4747
+ private function override_plugin_menu_with_activation() {
4748
+ $this->_logger->entrance();
4749
+
4750
+ $hook = false;
4751
+
4752
+ if ( $this->_menu->is_top_level() ) {
4753
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
4754
+
4755
+ if ( false === $hook ) {
4756
+ // Create new menu item just for the opt-in.
4757
+ $hook = add_menu_page(
4758
+ $this->get_plugin_name(),
4759
+ $this->get_plugin_name(),
4760
+ 'manage_options',
4761
+ $this->_menu->get_slug(),
4762
+ array( &$this, '_connect_page_render' )
4763
+ );
4764
+ }
4765
+ } else {
4766
+ $menus = array( $this->_menu->get_parent_slug() );
4767
+
4768
+ if ( $this->_menu->is_override_exact() ) {
4769
+ // Make sure the current page is matching the activation page.
4770
+ $activation_url = strtolower( $this->get_activation_url() );
4771
+ $request_url = strtolower( $_SERVER['REQUEST_URI'] );
4772
+
4773
+ if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
4774
+ // Different path - DO NOT OVERRIDE PAGE.
4775
+ return;
4776
+ }
4777
+
4778
+ $activation_url_params = array();
4779
+ parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
4780
+
4781
+ $request_url_params = array();
4782
+ parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
4783
+
4784
+
4785
+ foreach ( $activation_url_params as $key => $val ) {
4786
+ if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
4787
+ // Not matching query string - DO NOT OVERRIDE PAGE.
4788
+ return;
4789
+ }
4790
+ }
4791
+ }
4792
+
4793
+ foreach ( $menus as $parent_slug ) {
4794
+ $hook = $this->_menu->override_submenu_action(
4795
+ $parent_slug,
4796
+ $this->_menu->get_raw_slug(),
4797
+ array( &$this, '_connect_page_render' )
4798
+ );
4799
+
4800
+ if ( false !== $hook ) {
4801
+ // Found plugin's submenu item.
4802
+ break;
4803
+ }
4804
+ }
4805
+ }
4806
+
4807
+ if ( $this->_menu->is_activation_page() ) {
4808
+ // Clean admin page from distracting content.
4809
+ self::_clean_admin_content_section();
4810
+ }
4811
+
4812
+ if ( false !== $hook ) {
4813
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
4814
+ add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
4815
+ } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
4816
+ add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
4817
+ }
4818
+ }
4819
+ }
4820
+
4821
+ /**
4822
+ * @author Vova Feldman (@svovaf)
4823
+ * @since 1.0.0
4824
+ *
4825
+ * @return string
4826
+ */
4827
+ private function get_top_level_menu_slug() {
4828
+ return ( $this->is_addon() ?
4829
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
4830
+ $this->_menu->get_top_level_menu_slug() );
4831
+ }
4832
+
4833
+ /**
4834
+ * Add default Freemius menu items.
4835
+ *
4836
+ * @author Vova Feldman (@svovaf)
4837
+ * @since 1.0.0
4838
+ */
4839
+ private function add_submenu_items() {
4840
+ $this->_logger->entrance();
4841
+
4842
+ $this->do_action( 'before_admin_menu_init' );
4843
+
4844
+ if ( ! $this->is_addon() ) {
4845
+ if ( $this->is_registered() || $this->is_anonymous() ) {
4846
+ if ( $this->is_registered() ) {
4847
+ // Add user account page.
4848
+ $this->add_submenu_item(
4849
+ __fs( 'account', $this->_slug ),
4850
+ array( &$this, '_account_page_render' ),
4851
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
4852
+ 'manage_options',
4853
+ 'account',
4854
+ array( &$this, '_account_page_load' ),
4855
+ WP_FS__DEFAULT_PRIORITY,
4856
+ $this->_menu->is_submenu_item_visible( 'account' )
4857
+ );
4858
+ }
4859
+
4860
+ // Add contact page.
4861
+ $this->add_submenu_item(
4862
+ __fs( 'contact-us', $this->_slug ),
4863
+ array( &$this, '_contact_page_render' ),
4864
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
4865
+ 'manage_options',
4866
+ 'contact',
4867
+ 'Freemius::_clean_admin_content_section',
4868
+ WP_FS__DEFAULT_PRIORITY,
4869
+ $this->_menu->is_submenu_item_visible( 'contact' )
4870
+ );
4871
+
4872
+ if ( $this->_has_addons() ) {
4873
+ $this->add_submenu_item(
4874
+ __fs( 'add-ons', $this->_slug ),
4875
+ array( &$this, '_addons_page_render' ),
4876
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
4877
+ 'manage_options',
4878
+ 'addons',
4879
+ array( &$this, '_addons_page_load' ),
4880
+ WP_FS__LOWEST_PRIORITY - 1,
4881
+ $this->_menu->is_submenu_item_visible( 'addons' )
4882
+ );
4883
+ }
4884
+
4885
+ $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
4886
+ // If user don't have paid plans, add pricing page
4887
+ // to support add-ons checkout but don't add the submenu item.
4888
+ // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
4889
+
4890
+ // Add upgrade/pricing page.
4891
+ $this->add_submenu_item(
4892
+ ( $this->is_paying() ? __fs( 'pricing', $this->_slug ) : __fs( 'upgrade', $this->_slug ) . '&nbsp;&nbsp;&#x27a4;' ),
4893
+ array( &$this, '_pricing_page_render' ),
4894
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
4895
+ 'manage_options',
4896
+ 'pricing',
4897
+ 'Freemius::_clean_admin_content_section',
4898
+ WP_FS__LOWEST_PRIORITY,
4899
+ $show_pricing
4900
+ );
4901
+ }
4902
+ }
4903
+
4904
+
4905
+ if ( 0 < count( $this->_menu_items ) ) {
4906
+ if ( ! $this->_menu->is_top_level() ) {
4907
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
4908
+
4909
+ // Append submenu items right after the plugin's submenu item.
4910
+ $this->order_sub_submenu_items();
4911
+ } else {
4912
+ // Append submenu items.
4913
+ $this->embed_submenu_items();
4914
+ }
4915
+ }
4916
+ }
4917
+
4918
+ /**
4919
+ * Moved the actual submenu item additions to a separated function,
4920
+ * in order to support sub-submenu items when the plugin's settings
4921
+ * only have a submenu and not top-level menu item.
4922
+ *
4923
+ * @author Vova Feldman (@svovaf)
4924
+ * @since 1.1.4
4925
+ */
4926
+ private function embed_submenu_items() {
4927
+ $item_template = $this->_menu->is_top_level() ?
4928
+ '<span class="fs-submenu-item">%s</span>' :
4929
+ '<span class="fs-submenu-item fs-sub">%s</span>';
4930
+
4931
+ ksort( $this->_menu_items );
4932
+
4933
+ foreach ( $this->_menu_items as $priority => $items ) {
4934
+ foreach ( $items as $item ) {
4935
+ if ( ! isset( $item['url'] ) ) {
4936
+ $hook = add_submenu_page(
4937
+ $item['show_submenu'] ?
4938
+ $this->get_top_level_menu_slug() :
4939
+ null,
4940
+ $item['page_title'],
4941
+ sprintf( $item_template, $item['menu_title'] ),
4942
+ $item['capability'],
4943
+ $item['menu_slug'],
4944
+ $item['render_function']
4945
+ );
4946
+
4947
+ if ( false !== $item['before_render_function'] ) {
4948
+ add_action( "load-$hook", $item['before_render_function'] );
4949
+ }
4950
+ } else {
4951
+ add_submenu_page(
4952
+ $this->get_top_level_menu_slug(),
4953
+ $item['page_title'],
4954
+ sprintf( $item_template, $item['menu_title'] ),
4955
+ $item['capability'],
4956
+ $item['menu_slug'],
4957
+ array( $this, '' )
4958
+ );
4959
+ }
4960
+ }
4961
+ }
4962
+ }
4963
+
4964
+ /**
4965
+ * Re-order the submenu items so all Freemius added new submenu items
4966
+ * are added right after the plugin's settings submenu item.
4967
+ *
4968
+ * @author Vova Feldman (@svovaf)
4969
+ * @since 1.1.4
4970
+ */
4971
+ private function order_sub_submenu_items() {
4972
+ global $submenu;
4973
+
4974
+ $top_level_menu = &$submenu[ $this->_menu->get_top_level_menu_slug() ];
4975
+
4976
+ $all_submenu_items_after = array();
4977
+
4978
+ $found_submenu_item = false;
4979
+
4980
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
4981
+ if ( $found_submenu_item ) {
4982
+ // Remove all submenu items after the plugin's submenu item.
4983
+ $all_submenu_items_after[] = $meta;
4984
+ unset( $top_level_menu[ $submenu_id ] );
4985
+ }
4986
+
4987
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
4988
+ // Found the submenu item, put all below.
4989
+ $found_submenu_item = true;
4990
+ continue;
4991
+ }
4992
+ }
4993
+
4994
+ // Embed all plugin's new submenu items.
4995
+ $this->embed_submenu_items();
4996
+
4997
+ // Start with specially high number to make sure it's appended.
4998
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
4999
+ foreach ( $all_submenu_items_after as $meta ) {
5000
+ $top_level_menu[ $i ] = $meta;
5001
+ $i ++;
5002
+ }
5003
+
5004
+ // Sort submenu items.
5005
+ ksort( $top_level_menu );
5006
+ }
5007
+
5008
+ /**
5009
+ * Displays the Support Forum link when enabled.
5010
+ *
5011
+ * Can be filtered like so:
5012
+ *
5013
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
5014
+ * if ( 'support' === $menu_id ) {
5015
+ * return _fs->is_registered();
5016
+ * }
5017
+ * return $is_visible;
5018
+ * }
5019
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
5020
+ *
5021
+ */
5022
+ function _add_default_submenu_items() {
5023
+ if ( ! $this->is_on() ) {
5024
+ return;
5025
+ }
5026
+
5027
+ if ( $this->is_registered() || $this->is_anonymous() ) {
5028
+ if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
5029
+ $this->add_submenu_link_item(
5030
+ $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
5031
+ $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
5032
+ 'wp-support-forum',
5033
+ 'read',
5034
+ 50
5035
+ );
5036
+ }
5037
+ }
5038
+ }
5039
+
5040
+ /**
5041
+ * @author Vova Feldman (@svovaf)
5042
+ * @since 1.0.1
5043
+ *
5044
+ * @param string $menu_title
5045
+ * @param callable $render_function
5046
+ * @param bool|string $page_title
5047
+ * @param string $capability
5048
+ * @param bool|string $menu_slug
5049
+ * @param bool|callable $before_render_function
5050
+ * @param int $priority
5051
+ * @param bool $show_submenu
5052
+ */
5053
+ function add_submenu_item(
5054
+ $menu_title,
5055
+ $render_function,
5056
+ $page_title = false,
5057
+ $capability = 'manage_options',
5058
+ $menu_slug = false,
5059
+ $before_render_function = false,
5060
+ $priority = WP_FS__DEFAULT_PRIORITY,
5061
+ $show_submenu = true
5062
+ ) {
5063
+ $this->_logger->entrance( 'Title = ' . $menu_title );
5064
+
5065
+ if ( $this->is_addon() ) {
5066
+ $parent_fs = $this->get_parent_instance();
5067
+
5068
+ if ( is_object( $parent_fs ) ) {
5069
+ $parent_fs->add_submenu_item(
5070
+ $menu_title,
5071
+ $render_function,
5072
+ $page_title,
5073
+ $capability,
5074
+ $menu_slug,
5075
+ $before_render_function,
5076
+ $priority,
5077
+ $show_submenu
5078
+ );
5079
+
5080
+ return;
5081
+ }
5082
+ }
5083
+
5084
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
5085
+ $this->_menu_items[ $priority ] = array();
5086
+ }
5087
+
5088
+ $this->_menu_items[ $priority ][] = array(
5089
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
5090
+ 'menu_title' => $menu_title,
5091
+ 'capability' => $capability,
5092
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
5093
+ 'render_function' => $render_function,
5094
+ 'before_render_function' => $before_render_function,
5095
+ 'show_submenu' => $show_submenu,
5096
+ );
5097
+ }
5098
+
5099
+ /**
5100
+ * @author Vova Feldman (@svovaf)
5101
+ * @since 1.0.1
5102
+ *
5103
+ * @param string $menu_title
5104
+ * @param string $url
5105
+ * @param bool $menu_slug
5106
+ * @param string $capability
5107
+ * @param int $priority
5108
+ *
5109
+ */
5110
+ function add_submenu_link_item(
5111
+ $menu_title,
5112
+ $url,
5113
+ $menu_slug = false,
5114
+ $capability = 'read',
5115
+ $priority = WP_FS__DEFAULT_PRIORITY
5116
+ ) {
5117
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
5118
+
5119
+ if ( $this->is_addon() ) {
5120
+ $parent_fs = $this->get_parent_instance();
5121
+
5122
+ if ( is_object( $parent_fs ) ) {
5123
+ $parent_fs->add_submenu_link_item(
5124
+ $menu_title,
5125
+ $url,
5126
+ $menu_slug,
5127
+ $capability,
5128
+ $priority
5129
+ );
5130
+
5131
+ return;
5132
+ }
5133
+ }
5134
+
5135
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
5136
+ $this->_menu_items[ $priority ] = array();
5137
+ }
5138
+
5139
+ $this->_menu_items[ $priority ][] = array(
5140
+ 'menu_title' => $menu_title,
5141
+ 'capability' => $capability,
5142
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
5143
+ 'url' => $url,
5144
+ 'page_title' => $menu_title,
5145
+ 'render_function' => 'fs_dummy',
5146
+ 'before_render_function' => '',
5147
+ );
5148
+ }
5149
+
5150
+ #endregion ------------------------------------------------------------------
5151
+
5152
+ /* Actions / Hooks / Filters
5153
+ ------------------------------------------------------------------------------------------------------------------*/
5154
+ /**
5155
+ * Do action, specific for the current context plugin.
5156
+ *
5157
+ * @author Vova Feldman (@svovaf)
5158
+ * @since 1.0.1
5159
+ *
5160
+ * @param string $tag The name of the action to be executed.
5161
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
5162
+ * functions hooked to the action. Default empty.
5163
+ *
5164
+ * @uses do_action()
5165
+ */
5166
+ function do_action( $tag, $arg = '' ) {
5167
+ $this->_logger->entrance( $tag );
5168
+
5169
+ $args = func_get_args();
5170
+
5171
+ call_user_func_array( 'do_action', array_merge(
5172
+ array( 'fs_' . $tag . '_' . $this->_slug ),
5173
+ array_slice( $args, 1 ) )
5174
+ );
5175
+ }
5176
+
5177
+ /**
5178
+ * Add action, specific for the current context plugin.
5179
+ *
5180
+ * @author Vova Feldman (@svovaf)
5181
+ * @since 1.0.1
5182
+ *
5183
+ * @param string $tag
5184
+ * @param callable $function_to_add
5185
+ * @param int $priority
5186
+ * @param int $accepted_args
5187
+ *
5188
+ * @uses add_action()
5189
+ */
5190
+ function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
5191
+ $this->_logger->entrance( $tag );
5192
+
5193
+ add_action( 'fs_' . $tag . '_' . $this->_slug, $function_to_add, $priority, $accepted_args );
5194
+ }
5195
+
5196
+ /**
5197
+ * Apply filter, specific for the current context plugin.
5198
+ *
5199
+ * @author Vova Feldman (@svovaf)
5200
+ * @since 1.0.9
5201
+ *
5202
+ * @param string $tag The name of the filter hook.
5203
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
5204
+ *
5205
+ * @return mixed The filtered value after all hooked functions are applied to it.
5206
+ *
5207
+ * @uses apply_filters()
5208
+ */
5209
+ function apply_filters( $tag, $value ) {
5210
+ $this->_logger->entrance( $tag );
5211
+
5212
+ $args = func_get_args();
5213
+ array_unshift($args, $this->_slug);
5214
+
5215
+ return call_user_func_array( 'fs_apply_filter', $args);
5216
+ }
5217
+
5218
+ /**
5219
+ * Add filter, specific for the current context plugin.
5220
+ *
5221
+ * @author Vova Feldman (@svovaf)
5222
+ * @since 1.0.9
5223
+ *
5224
+ * @param string $tag
5225
+ * @param callable $function_to_add
5226
+ * @param int $priority
5227
+ * @param int $accepted_args
5228
+ *
5229
+ * @uses add_filter()
5230
+ */
5231
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
5232
+ $this->_logger->entrance( $tag );
5233
+
5234
+ add_filter( 'fs_' . $tag . '_' . $this->_slug, $function_to_add, $priority, $accepted_args );
5235
+ }
5236
+
5237
+ /**
5238
+ * Check if has filter.
5239
+ *
5240
+ * @author Vova Feldman (@svovaf)
5241
+ * @since 1.1.4
5242
+ *
5243
+ * @param string $tag
5244
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
5245
+ *
5246
+ * @return false|int
5247
+ *
5248
+ * @uses has_filter()
5249
+ */
5250
+ function has_filter( $tag, $function_to_check = false ) {
5251
+ $this->_logger->entrance( $tag );
5252
+
5253
+ return has_filter( 'fs_' . $tag . '_' . $this->_slug, $function_to_check );
5254
+ }
5255
+
5256
+ /**
5257
+ * Override default i18n text phrases.
5258
+ *
5259
+ * @author Vova Feldman (@svovaf)
5260
+ * @since 1.1.6
5261
+ *
5262
+ * @param string[] string $key_value
5263
+ *
5264
+ * @uses fs_override_i18n()
5265
+ */
5266
+ function override_i18n( $key_value ) {
5267
+ fs_override_i18n( $key_value, $this->_slug );
5268
+ }
5269
+
5270
+ /* Account Page
5271
+ ------------------------------------------------------------------------------------------------------------------*/
5272
+ /**
5273
+ * Update site information.
5274
+ *
5275
+ * @author Vova Feldman (@svovaf)
5276
+ * @since 1.0.1
5277
+ *
5278
+ * @param bool $store Flush to Database if true.
5279
+ */
5280
+ private function _store_site( $store = true ) {
5281
+ $this->_logger->entrance();
5282
+
5283
+ $encrypted_site = clone $this->_site;
5284
+ $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
5285
+
5286
+ $sites = self::get_all_sites();
5287
+ $sites[ $this->_slug ] = $encrypted_site;
5288
+ self::$_accounts->set_option( 'sites', $sites, $store );
5289
+ }
5290
+
5291
+ /**
5292
+ * Update plugin's plans information.
5293
+ *
5294
+ * @author Vova Feldman (@svovaf)
5295
+ * @since 1.0.2
5296
+ *
5297
+ * @param bool $store Flush to Database if true.
5298
+ */
5299
+ private function _store_plans( $store = true ) {
5300
+ $this->_logger->entrance();
5301
+
5302
+ $plans = self::get_all_plans();
5303
+
5304
+ // Copy plans.
5305
+ $encrypted_plans = array();
5306
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5307
+ $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
5308
+ }
5309
+
5310
+ $plans[ $this->_slug ] = $encrypted_plans;
5311
+ self::$_accounts->set_option( 'plans', $plans, $store );
5312
+ }
5313
+
5314
+ /**
5315
+ * Update user's plugin licenses.
5316
+ *
5317
+ * @author Vova Feldman (@svovaf)
5318
+ * @since 1.0.5
5319
+ *
5320
+ * @param bool $store
5321
+ * @param string|bool $plugin_slug
5322
+ * @param FS_Plugin_License[] $licenses
5323
+ */
5324
+ private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
5325
+ $this->_logger->entrance();
5326
+
5327
+ $all_licenses = self::get_all_licenses();
5328
+
5329
+ if ( ! is_string( $plugin_slug ) ) {
5330
+ $plugin_slug = $this->_slug;
5331
+ $licenses = $this->_licenses;
5332
+ }
5333
+
5334
+ if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
5335
+ $all_licenses[ $plugin_slug ] = array();
5336
+ }
5337
+
5338
+ $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
5339
+
5340
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
5341
+ }
5342
+
5343
+ /**
5344
+ * Update user information.
5345
+ *
5346
+ * @author Vova Feldman (@svovaf)
5347
+ * @since 1.0.1
5348
+ *
5349
+ * @param bool $store Flush to Database if true.
5350
+ */
5351
+ private function _store_user( $store = true ) {
5352
+ $this->_logger->entrance();
5353
+
5354
+ $users = self::get_all_users();
5355
+ $users[ $this->_user->id ] = $this->_user;
5356
+ self::$_accounts->set_option( 'users', $users, $store );
5357
+ }
5358
+
5359
+ /**
5360
+ * Update new updates information.
5361
+ *
5362
+ * @author Vova Feldman (@svovaf)
5363
+ * @since 1.0.4
5364
+ *
5365
+ * @param FS_Plugin_Tag|null $update
5366
+ * @param bool $store Flush to Database if true.
5367
+ * @param bool|number $plugin_id
5368
+ */
5369
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
5370
+ $this->_logger->entrance();
5371
+
5372
+ if ( $update instanceof FS_Plugin_Tag ) {
5373
+ $update->updated = time();
5374
+ }
5375
+
5376
+ if ( ! is_numeric( $plugin_id ) ) {
5377
+ $plugin_id = $this->_plugin->id;
5378
+ }
5379
+
5380
+ $updates = self::get_all_updates();
5381
+ $updates[ $plugin_id ] = $update;
5382
+ self::$_accounts->set_option( 'updates', $updates, $store );
5383
+ }
5384
+
5385
+ /**
5386
+ * Update new updates information.
5387
+ *
5388
+ * @author Vova Feldman (@svovaf)
5389
+ * @since 1.0.6
5390
+ *
5391
+ * @param FS_Plugin[] $plugin_addons
5392
+ * @param bool $store Flush to Database if true.
5393
+ */
5394
+ private function _store_addons( $plugin_addons, $store = true ) {
5395
+ $this->_logger->entrance();
5396
+
5397
+ $addons = self::get_all_addons();
5398
+ $addons[ $this->_plugin->id ] = $plugin_addons;
5399
+ self::$_accounts->set_option( 'addons', $addons, $store );
5400
+ }
5401
+
5402
+ /**
5403
+ * Delete plugin's associated add-ons.
5404
+ *
5405
+ * @author Vova Feldman (@svovaf)
5406
+ * @since 1.0.8
5407
+ *
5408
+ * @param bool $store
5409
+ *
5410
+ * @return bool
5411
+ */
5412
+ private function _delete_account_addons( $store = true ) {
5413
+ $all_addons = self::get_all_account_addons();
5414
+
5415
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
5416
+ return false;
5417
+ }
5418
+
5419
+ unset( $all_addons[ $this->_plugin->id ] );
5420
+
5421
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
5422
+
5423
+ return true;
5424
+ }
5425
+
5426
+ /**
5427
+ * Update account add-ons list.
5428
+ *
5429
+ * @author Vova Feldman (@svovaf)
5430
+ * @since 1.0.6
5431
+ *
5432
+ * @param FS_Plugin[] $addons
5433
+ * @param bool $store Flush to Database if true.
5434
+ */
5435
+ private function _store_account_addons( $addons, $store = true ) {
5436
+ $this->_logger->entrance();
5437
+
5438
+ $all_addons = self::get_all_account_addons();
5439
+ $all_addons[ $this->_plugin->id ] = $addons;
5440
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
5441
+ }
5442
+
5443
+ /**
5444
+ * Store account params in the Database.
5445
+ *
5446
+ * @author Vova Feldman (@svovaf)
5447
+ * @since 1.0.1
5448
+ */
5449
+ private function _store_account() {
5450
+ $this->_logger->entrance();
5451
+
5452
+ $this->_store_site( false );
5453
+ $this->_store_user( false );
5454
+ $this->_store_plans( false );
5455
+ $this->_store_licenses( false );
5456
+
5457
+ self::$_accounts->store();
5458
+ }
5459
+
5460
+ /**
5461
+ * Sync user's information.
5462
+ *
5463
+ * @author Vova Feldman (@svovaf)
5464
+ * @since 1.0.3
5465
+ * @uses FS_Api
5466
+ */
5467
+ private function _handle_account_user_sync() {
5468
+ $this->_logger->entrance();
5469
+
5470
+ $api = $this->get_api_user_scope();
5471
+
5472
+ // Get user's information.
5473
+ $user = $api->get( '/', true );
5474
+
5475
+ if ( isset( $user->id ) ) {
5476
+ $this->_user->first = $user->first;
5477
+ $this->_user->last = $user->last;
5478
+ $this->_user->email = $user->email;
5479
+
5480
+ $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
5481
+
5482
+ if ( $user->is_verified &&
5483
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
5484
+ ) {
5485
+ $this->_user->is_verified = true;
5486
+
5487
+ $this->do_action( 'account_email_verified', $user->email );
5488
+
5489
+ $this->_admin_notices->add(
5490
+ __fs( 'email-verified-message', $this->_slug ),
5491
+ __fs( 'right-on', $this->_slug ) . '!',
5492
+ 'success',
5493
+ // Make admin sticky if account menu item is invisible,
5494
+ // since the page will be auto redirected to the plugin's
5495
+ // main settings page, and the non-sticky message
5496
+ // will disappear.
5497
+ ! $is_menu_item_account_visible,
5498
+ false,
5499
+ 'email_verified'
5500
+ );
5501
+ }
5502
+
5503
+ // Flush user details to DB.
5504
+ $this->_store_user();
5505
+
5506
+ $this->do_action( 'after_account_user_sync', $user );
5507
+
5508
+ /**
5509
+ * If account menu item is hidden, redirect to plugin's main settings page.
5510
+ *
5511
+ * @author Vova Feldman (@svovaf)
5512
+ * @since 1.1.6
5513
+ *
5514
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
5515
+ */
5516
+ if ( ! $is_menu_item_account_visible ) {
5517
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
5518
+ exit();
5519
+ }
5520
+ }
5521
+ }
5522
+ }
5523
+
5524
+ /**
5525
+ * @author Vova Feldman (@svovaf)
5526
+ * @since 1.0.5
5527
+ * @uses FS_Api
5528
+ *
5529
+ * @param bool $flush
5530
+ *
5531
+ * @return object|\FS_Site
5532
+ */
5533
+ private function _fetch_site( $flush = false ) {
5534
+ $this->_logger->entrance();
5535
+ $api = $this->get_api_site_scope();
5536
+
5537
+ $site = $api->get( '/', $flush );
5538
+
5539
+ if ( ! isset( $site->error ) ) {
5540
+ $site = new FS_Site( $site );
5541
+ $site->slug = $this->_slug;
5542
+ $site->version = $this->get_plugin_version();
5543
+ }
5544
+
5545
+ return $site;
5546
+ }
5547
+
5548
+ /**
5549
+ * @param bool $store
5550
+ *
5551
+ * @return FS_Plugin_Plan|object|false
5552
+ */
5553
+ private function _enrich_site_plan( $store = true ) {
5554
+ // Try to load plan from local cache.
5555
+ $plan = $this->_get_plan_by_id( $this->_site->plan->id );
5556
+
5557
+ if ( false === $plan ) {
5558
+ $plan = $this->_fetch_site_plan();
5559
+ }
5560
+
5561
+ if ( $plan instanceof FS_Plugin_Plan ) {
5562
+ $this->_update_plan( $plan, $store );
5563
+ }
5564
+
5565
+ return $plan;
5566
+ }
5567
+
5568
+ /**
5569
+ * @author Vova Feldman (@svovaf)
5570
+ * @since 1.0.9
5571
+ * @uses FS_Api
5572
+ *
5573
+ * @param bool $store
5574
+ *
5575
+ * @return FS_Plugin_Plan|object|false
5576
+ */
5577
+ private function _enrich_site_trial_plan( $store = true ) {
5578
+ // Try to load plan from local cache.
5579
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
5580
+
5581
+ if ( false === $trial_plan ) {
5582
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
5583
+ }
5584
+
5585
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
5586
+ $this->_storage->store( 'trial_plan', $trial_plan, $store );
5587
+ }
5588
+
5589
+ return $trial_plan;
5590
+ }
5591
+
5592
+ /**
5593
+ * @author Vova Feldman (@svovaf)
5594
+ * @since 1.0.9
5595
+ * @uses FS_Api
5596
+ *
5597
+ * @param number|bool $license_id
5598
+ *
5599
+ * @return FS_Subscription|object|bool
5600
+ */
5601
+ private function _fetch_site_license_subscription( $license_id = false ) {
5602
+ $this->_logger->entrance();
5603
+ $api = $this->get_api_site_scope();
5604
+
5605
+ if ( ! is_numeric( $license_id ) ) {
5606
+ $license_id = $this->_license->id;
5607
+ }
5608
+
5609
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
5610
+
5611
+ return ! isset( $result->error ) ?
5612
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
5613
+ new FS_Subscription( $result->subscriptions[0] ) :
5614
+ false
5615
+ ) :
5616
+ $result;
5617
+ }
5618
+
5619
+ /**
5620
+ * @author Vova Feldman (@svovaf)
5621
+ * @since 1.0.4
5622
+ * @uses FS_Api
5623
+ *
5624
+ * @param number|bool $plan_id
5625
+ *
5626
+ * @return FS_Plugin_Plan|object
5627
+ */
5628
+ private function _fetch_site_plan( $plan_id = false ) {
5629
+ $this->_logger->entrance();
5630
+ $api = $this->get_api_site_scope();
5631
+
5632
+ if ( ! is_numeric( $plan_id ) ) {
5633
+ $plan_id = $this->_site->plan->id;
5634
+ }
5635
+
5636
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
5637
+
5638
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
5639
+ }
5640
+
5641
+ /**
5642
+ * @author Vova Feldman (@svovaf)
5643
+ * @since 1.0.5
5644
+ * @uses FS_Api
5645
+ *
5646
+ * @return FS_Plugin_Plan[]|object
5647
+ */
5648
+ private function _fetch_plugin_plans() {
5649
+ $this->_logger->entrance();
5650
+ $api = $this->get_api_site_scope();
5651
+
5652
+ $result = $api->get( '/plans.json', true );
5653
+
5654
+ if ( ! $this->is_api_error( $result ) ) {
5655
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
5656
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
5657
+ }
5658
+
5659
+ $result = $result->plans;
5660
+ }
5661
+
5662
+ return $result;
5663
+ }
5664
+
5665
+ /**
5666
+ * @author Vova Feldman (@svovaf)
5667
+ * @since 1.0.5
5668
+ * @uses FS_Api
5669
+ *
5670
+ * @param number|bool $plugin_id
5671
+ *
5672
+ * @return FS_Plugin_License[]|object
5673
+ */
5674
+ private function _fetch_licenses( $plugin_id = false ) {
5675
+ $this->_logger->entrance();
5676
+
5677
+ $api = $this->get_api_user_scope();
5678
+
5679
+ if ( ! is_numeric( $plugin_id ) ) {
5680
+ $plugin_id = $this->_plugin->id;
5681
+ }
5682
+
5683
+ $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
5684
+
5685
+ if ( ! isset( $result->error ) ) {
5686
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
5687
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
5688
+ }
5689
+
5690
+ $result = $result->licenses;
5691
+ }
5692
+
5693
+ return $result;
5694
+ }
5695
+
5696
+ /**
5697
+ * @author Vova Feldman (@svovaf)
5698
+ * @since 1.0.4
5699
+ *
5700
+ * @param FS_Plugin_Plan $plan
5701
+ * @param bool $store
5702
+ */
5703
+ private function _update_plan( $plan, $store = false ) {
5704
+ $this->_logger->entrance();
5705
+
5706
+ $this->_site->plan = $plan;
5707
+ $this->_store_site( $store );
5708
+ }
5709
+
5710
+ /**
5711
+ * @author Vova Feldman (@svovaf)
5712
+ * @since 1.0.5
5713
+ *
5714
+ * @param FS_Plugin_License[] $licenses
5715
+ * @param string|bool $plugin_slug
5716
+ */
5717
+ private function _update_licenses( $licenses, $plugin_slug = false ) {
5718
+ $this->_logger->entrance();
5719
+
5720
+ if ( is_array( $licenses ) ) {
5721
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
5722
+ $licenses[ $i ]->updated = time();
5723
+ }
5724
+ }
5725
+
5726
+ if ( ! is_string( $plugin_slug ) ) {
5727
+ $this->_licenses = $licenses;
5728
+ }
5729
+
5730
+ $this->_store_licenses( true, $plugin_slug, $licenses );
5731
+ }
5732
+
5733
+ /**
5734
+ * @author Vova Feldman (@svovaf)
5735
+ * @since 1.0.4
5736
+ *
5737
+ * @param bool|number $plugin_id
5738
+ *
5739
+ * @return object|false New plugin tag info if exist.
5740
+ */
5741
+ private function _fetch_newer_version( $plugin_id = false ) {
5742
+ $latest_tag = $this->_fetch_latest_version( $plugin_id );
5743
+
5744
+ if ( ! is_object( $latest_tag ) ) {
5745
+ return false;
5746
+ }
5747
+
5748
+ // Check if version is actually newer.
5749
+ $has_new_version =
5750
+ // If it's an non-installed add-on then always return latest.
5751
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
5752
+ // Compare versions.
5753
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
5754
+
5755
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
5756
+
5757
+ return $has_new_version ? $latest_tag : false;
5758
+ }
5759
+
5760
+ /**
5761
+ * @author Vova Feldman (@svovaf)
5762
+ * @since 1.0.5
5763
+ *
5764
+ * @param bool|number $plugin_id
5765
+ *
5766
+ * @return bool|FS_Plugin_Tag
5767
+ */
5768
+ function get_update( $plugin_id = false ) {
5769
+ $this->_logger->entrance();
5770
+
5771
+ if ( ! is_numeric( $plugin_id ) ) {
5772
+ $plugin_id = $this->_plugin->id;
5773
+ }
5774
+
5775
+ $this->_check_updates( true, $plugin_id );
5776
+ $updates = $this->get_all_updates();
5777
+
5778
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
5779
+ }
5780
+
5781
+ /**
5782
+ * Check if site assigned with active license.
5783
+ *
5784
+ * @author Vova Feldman (@svovaf)
5785
+ * @since 1.0.6
5786
+ */
5787
+ function has_active_license() {
5788
+ return (
5789
+ is_object( $this->_license ) &&
5790
+ is_numeric( $this->_license->id ) &&
5791
+ ! $this->_license->is_expired()
5792
+ );
5793
+ }
5794
+
5795
+ /**
5796
+ * Check if site assigned with license with enabled features.
5797
+ *
5798
+ * @author Vova Feldman (@svovaf)
5799
+ * @since 1.0.6
5800
+ *
5801
+ * @return bool
5802
+ */
5803
+ function has_features_enabled_license() {
5804
+ return (
5805
+ is_object( $this->_license ) &&
5806
+ is_numeric( $this->_license->id ) &&
5807
+ $this->_license->is_features_enabled()
5808
+ );
5809
+ }
5810
+
5811
+ /**
5812
+ * Sync site's plan.
5813
+ *
5814
+ * @author Vova Feldman (@svovaf)
5815
+ * @since 1.0.3
5816
+ *
5817
+ * @uses FS_Api
5818
+ *
5819
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
5820
+ * the admin.
5821
+ */
5822
+ private function _sync_license( $background = false ) {
5823
+ $this->_logger->entrance();
5824
+
5825
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
5826
+
5827
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
5828
+
5829
+ if ( $is_addon_sync ) {
5830
+ $this->_sync_addon_license( $plugin_id, $background );
5831
+ } else {
5832
+ $this->_sync_plugin_license( $background );
5833
+ }
5834
+
5835
+ $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
5836
+ }
5837
+
5838
+ /**
5839
+ * Sync plugin's add-on license.
5840
+ *
5841
+ * @author Vova Feldman (@svovaf)
5842
+ * @since 1.0.6
5843
+ * @uses FS_Api
5844
+ *
5845
+ * @param number $addon_id
5846
+ * @param bool $background
5847
+ */
5848
+ private function _sync_addon_license( $addon_id, $background ) {
5849
+ $this->_logger->entrance();
5850
+
5851
+ if ( $this->is_addon_activated( $addon_id ) ) {
5852
+ // If already installed, use add-on sync.
5853
+ $fs_addon = self::get_instance_by_id( $addon_id );
5854
+ $fs_addon->_sync_license( $background );
5855
+
5856
+ return;
5857
+ }
5858
+
5859
+ // Validate add-on exists.
5860
+ $addon = $this->get_addon( $addon_id );
5861
+
5862
+ if ( ! is_object( $addon ) ) {
5863
+ return;
5864
+ }
5865
+
5866
+ // Add add-on into account add-ons.
5867
+ $account_addons = $this->get_account_addons();
5868
+ if ( ! is_array( $account_addons ) ) {
5869
+ $account_addons = array();
5870
+ }
5871
+ $account_addons[] = $addon->id;
5872
+ $account_addons = array_unique( $account_addons );
5873
+ $this->_store_account_addons( $account_addons );
5874
+
5875
+ // Load add-on licenses.
5876
+ $licenses = $this->_fetch_licenses( $addon->id );
5877
+
5878
+ // Sync add-on licenses.
5879
+ if ( ! isset( $licenses->error ) ) {
5880
+ $this->_update_licenses( $licenses, $addon->slug );
5881
+
5882
+ if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
5883
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
5884
+
5885
+ if ( ! isset( $plans_result->error ) ) {
5886
+ $plans = array();
5887
+ foreach ( $plans_result->plans as $plan ) {
5888
+ $plans[] = new FS_Plugin_Plan( $plan );
5889
+ }
5890
+
5891
+ $this->_admin_notices->add_sticky(
5892
+ FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
5893
+ sprintf(
5894
+ __fs( 'addon-successfully-upgraded-message', $this->_slug ),
5895
+ $addon->title
5896
+ ) . ' ' . $this->_get_latest_download_link(
5897
+ __fs( 'download-latest-version', $this->_slug ),
5898
+ $addon_id
5899
+ )
5900
+ :
5901
+ sprintf(
5902
+ __fs( 'addon-successfully-purchased-message', $this->_slug ),
5903
+ $addon->title
5904
+ ) . ' ' . $this->_get_latest_download_link(
5905
+ __fs( 'download-latest-version', $this->_slug ),
5906
+ $addon_id
5907
+ ),
5908
+ 'addon_plan_upgraded_' . $addon->slug,
5909
+ __fs( 'yee-haw', $this->_slug ) . '!'
5910
+ );
5911
+ }
5912
+ }
5913
+ }
5914
+ }
5915
+
5916
+ /**
5917
+ * Sync site's plugin plan.
5918
+ *
5919
+ * @author Vova Feldman (@svovaf)
5920
+ * @since 1.0.6
5921
+ * @uses FS_Api
5922
+ *
5923
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
5924
+ * the admin.
5925
+ */
5926
+ private function _sync_plugin_license( $background = false ) {
5927
+ $this->_logger->entrance();
5928
+
5929
+ // Sync site info.
5930
+ $site = $this->send_install_update( array(), true );
5931
+
5932
+ $plan_change = 'none';
5933
+
5934
+ if ( $this->is_api_error( $site ) ) {
5935
+ // Show API messages only if not background sync or if paying customer.
5936
+ if ( ! $background || $this->is_paying() ) {
5937
+ // Try to ping API to see if not blocked.
5938
+ if ( ! FS_Api::test() ) {
5939
+ /**
5940
+ * Failed to ping API - blocked!
5941
+ *
5942
+ * @author Vova Feldman (@svovaf)
5943
+ * @since 1.1.6 Only show message related to one of the Freemius powered plugins. Once it will be resolved it will fix the issue for all plugins anyways. There's no point to scare users with multiple error messages.
5944
+ */
5945
+ $api = $this->get_api_site_scope();
5946
+
5947
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
5948
+ self::$_global_admin_notices->add(
5949
+ sprintf(
5950
+ __fs( 'server-blocking-access', $this->_slug ),
5951
+ $this->get_plugin_name(),
5952
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
5953
+ ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
5954
+ __fs( 'oops', $this->_slug ) . '...',
5955
+ 'error',
5956
+ $background,
5957
+ false,
5958
+ 'api_blocked'
5959
+ );
5960
+ }
5961
+ } else {
5962
+ // Authentication params are broken.
5963
+ $this->_admin_notices->add(
5964
+ __fs( 'wrong-authentication-param-message', $this->_slug ),
5965
+ __fs( 'oops', $this->_slug ) . '...',
5966
+ 'error'
5967
+ );
5968
+ }
5969
+ }
5970
+ } else {
5971
+ // Remove sticky API connectivity message.
5972
+ self::$_global_admin_notices->remove_sticky('api_blocked');
5973
+
5974
+ $site = new FS_Site( $site );
5975
+
5976
+ // Sync licenses.
5977
+ $this->_sync_licenses();
5978
+
5979
+ // Sync plans.
5980
+ $this->_sync_plans();
5981
+
5982
+ // Check if plan / license changed.
5983
+ if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
5984
+ // Check if trial started.
5985
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
5986
+ $site->trial_ends != $this->_site->trial_ends ||
5987
+ // Check if license changed.
5988
+ $site->license_id != $this->_site->license_id
5989
+ ) {
5990
+ if ( $site->is_trial() && ! $this->_site->is_trial() ) {
5991
+ // New trial started.
5992
+ $this->_site = $site;
5993
+ $plan_change = 'trial_started';
5994
+
5995
+ // Store trial plan information.
5996
+ $this->_enrich_site_trial_plan( true );
5997
+
5998
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
5999
+ // Was in trial, but now trial expired and no license ID.
6000
+ // New trial started.
6001
+ $this->_site = $site;
6002
+ $plan_change = 'trial_expired';
6003
+
6004
+ // Clear trial plan information.
6005
+ $this->_storage->trial_plan = null;
6006
+
6007
+ } else {
6008
+ $is_free = $this->is_free_plan();
6009
+
6010
+ // Make sure license exist and not expired.
6011
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
6012
+
6013
+ if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
6014
+ // The license is expired, so ignore upgrade method.
6015
+ } else {
6016
+ // License changed.
6017
+ $this->_site = $site;
6018
+ $this->_update_site_license( $new_license );
6019
+ $this->_store_licenses();
6020
+ $this->_enrich_site_plan( true );
6021
+
6022
+ $plan_change = $is_free ?
6023
+ 'upgraded' :
6024
+ ( is_object( $new_license ) ?
6025
+ 'changed' :
6026
+ 'downgraded' );
6027
+ }
6028
+ }
6029
+
6030
+ // Store updated site info.
6031
+ $this->_store_site();
6032
+ } else {
6033
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
6034
+ if ( ! $this->has_features_enabled_license() ) {
6035
+ $this->_deactivate_license();
6036
+ $plan_change = 'downgraded';
6037
+ } else {
6038
+ $plan_change = 'expired';
6039
+ }
6040
+ }
6041
+
6042
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
6043
+ $this->_sync_site_subscription( $this->_license );
6044
+ }
6045
+ }
6046
+ }
6047
+
6048
+ switch ( $plan_change ) {
6049
+ case 'none':
6050
+ if ( ! $background && is_admin() ) {
6051
+ $this->_admin_notices->add(
6052
+ sprintf(
6053
+ __fs( 'plan-did-not-change-message', $this->_slug ) . ' ' .
6054
+ sprintf(
6055
+ '<a href="%s">%s</a>',
6056
+ $this->contact_url(
6057
+ 'bug',
6058
+ sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
6059
+ strtoupper( $this->_site->plan->name )
6060
+ )
6061
+ ),
6062
+ __fs( 'contact-us-here', $this->_slug )
6063
+ )
6064
+ ),
6065
+ __fs( 'hmm', $this->_slug ) . '...',
6066
+ 'error'
6067
+ );
6068
+ }
6069
+ break;
6070
+ case 'upgraded':
6071
+ $this->_admin_notices->add_sticky(
6072
+ sprintf(
6073
+ __fs( 'plan-upgraded-message', $this->_slug ),
6074
+ '<i>' . $this->get_plugin_name() . '</i>'
6075
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
6076
+ __fs( 'download-latest-x-version', $this->_slug ),
6077
+ $this->_site->plan->title
6078
+ ) )
6079
+ ),
6080
+ 'plan_upgraded',
6081
+ __fs( 'yee-haw', $this->_slug ) . '!'
6082
+ );
6083
+
6084
+ $this->_admin_notices->remove_sticky( array(
6085
+ 'trial_started',
6086
+ 'trial_promotion',
6087
+ 'trial_expired',
6088
+ 'activation_complete',
6089
+ ) );
6090
+ break;
6091
+ case 'changed':
6092
+ $this->_admin_notices->add_sticky(
6093
+ sprintf(
6094
+ __fs( 'plan-changed-to-x-message', $this->_slug ),
6095
+ $this->_site->plan->title
6096
+ ),
6097
+ 'plan_changed'
6098
+ );
6099
+
6100
+ $this->_admin_notices->remove_sticky( array(
6101
+ 'trial_started',
6102
+ 'trial_promotion',
6103
+ 'trial_expired',
6104
+ 'activation_complete',
6105
+ ) );
6106
+ break;
6107
+ case 'downgraded':
6108
+ $this->_admin_notices->add_sticky(
6109
+ sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
6110
+ 'license_expired',
6111
+ __fs( 'hmm', $this->_slug ) . '...'
6112
+ );
6113
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
6114
+ break;
6115
+ case 'expired':
6116
+ $this->_admin_notices->add_sticky(
6117
+ sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
6118
+ 'license_expired',
6119
+ __fs( 'hmm', $this->_slug ) . '...'
6120
+ );
6121
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
6122
+ break;
6123
+ case 'trial_started':
6124
+ $this->_admin_notices->add_sticky(
6125
+ sprintf(
6126
+ __fs( 'trial-started-message', $this->_slug ),
6127
+ '<i>' . $this->get_plugin_name() . '</i>'
6128
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
6129
+ __fs( 'download-latest-x-version', $this->_slug ),
6130
+ $this->_storage->trial_plan->title
6131
+ ) ) ),
6132
+ 'trial_started',
6133
+ __fs( 'yee-haw', $this->_slug ) . '!'
6134
+ );
6135
+
6136
+ $this->_admin_notices->remove_sticky( array(
6137
+ 'trial_promotion',
6138
+ ) );
6139
+ break;
6140
+ case 'trial_expired':
6141
+ $this->_admin_notices->add_sticky(
6142
+ __fs( 'trial-expired-message', $this->_slug ),
6143
+ 'trial_expired',
6144
+ __fs( 'hmm', $this->_slug ) . '...'
6145
+ );
6146
+ $this->_admin_notices->remove_sticky( array(
6147
+ 'trial_started',
6148
+ 'trial_promotion',
6149
+ 'plan_upgraded',
6150
+ ) );
6151
+ break;
6152
+ }
6153
+
6154
+ if ( 'none' !== $plan_change ) {
6155
+ $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
6156
+ }
6157
+ }
6158
+
6159
+ /**
6160
+ * @author Vova Feldman (@svovaf)
6161
+ * @since 1.0.5
6162
+ *
6163
+ * @param bool $background
6164
+ */
6165
+ protected function _activate_license( $background = false ) {
6166
+ $this->_logger->entrance();
6167
+
6168
+ $premium_license = $this->_get_available_premium_license();
6169
+
6170
+ if ( ! is_object( $premium_license ) ) {
6171
+ return;
6172
+ }
6173
+
6174
+ $api = $this->get_api_site_scope();
6175
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put' );
6176
+
6177
+ if ( isset( $license->error ) ) {
6178
+ if ( ! $background ) {
6179
+ $this->_admin_notices->add(
6180
+ __fs( 'license-activation-failed-message', $this->_slug ) . '<br> ' .
6181
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
6182
+ __fs( 'hmm', $this->_slug ) . '...',
6183
+ 'error'
6184
+ );
6185
+ }
6186
+
6187
+ return;
6188
+ }
6189
+
6190
+ $premium_license = new FS_Plugin_License( $license );
6191
+
6192
+ // Updated site plan.
6193
+ $this->_site->plan->id = $premium_license->plan_id;
6194
+ $this->_update_site_license( $premium_license );
6195
+ $this->_enrich_site_plan( false );
6196
+
6197
+ $this->_store_account();
6198
+
6199
+ if ( ! $background ) {
6200
+ $this->_admin_notices->add_sticky(
6201
+ __fs( 'license-activated-message', $this->_slug ) .
6202
+ ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
6203
+ __fs( 'download-latest-x-version', $this->_slug ),
6204
+ $this->_site->plan->title
6205
+ ) ) ),
6206
+ 'license_activated',
6207
+ __fs( 'yee-haw', $this->_slug ) . '!'
6208
+ );
6209
+ }
6210
+
6211
+ $this->_admin_notices->remove_sticky( array(
6212
+ 'trial_promotion',
6213
+ 'license_expired',
6214
+ ) );
6215
+ }
6216
+
6217
+ /**
6218
+ * @author Vova Feldman (@svovaf)
6219
+ * @since 1.0.5
6220
+ *
6221
+ * @param bool $show_notice
6222
+ */
6223
+ protected function _deactivate_license( $show_notice = true ) {
6224
+ $this->_logger->entrance();
6225
+
6226
+ if ( ! is_object( $this->_license ) ) {
6227
+ $this->_admin_notices->add(
6228
+ sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
6229
+ __fs( 'hmm', $this->_slug ) . '...'
6230
+ );
6231
+
6232
+ return;
6233
+ }
6234
+
6235
+ $api = $this->get_api_site_scope();
6236
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
6237
+
6238
+ if ( isset( $license->error ) ) {
6239
+ $this->_admin_notices->add(
6240
+ __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
6241
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
6242
+ __fs( 'hmm', $this->_slug ) . '...',
6243
+ 'error'
6244
+ );
6245
+
6246
+ return;
6247
+ }
6248
+
6249
+ // Update license cache.
6250
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
6251
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
6252
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
6253
+ }
6254
+ }
6255
+
6256
+ // Updated site plan to default.
6257
+ $this->_sync_plans();
6258
+ $this->_site->plan->id = $this->_plans[0]->id;
6259
+ // Unlink license from site.
6260
+ $this->_update_site_license( null );
6261
+ $this->_enrich_site_plan( false );
6262
+
6263
+ $this->_store_account();
6264
+
6265
+ if ( $show_notice ) {
6266
+ $this->_admin_notices->add(
6267
+ sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
6268
+ __fs( 'ok', $this->_slug )
6269
+ );
6270
+ }
6271
+
6272
+ $this->_admin_notices->remove_sticky( array(
6273
+ 'plan_upgraded',
6274
+ 'license_activated',
6275
+ ) );
6276
+ }
6277
+
6278
+ /**
6279
+ * Site plan downgrade.
6280
+ *
6281
+ * @author Vova Feldman (@svovaf)
6282
+ * @since 1.0.4
6283
+ *
6284
+ * @uses FS_Api
6285
+ */
6286
+ private function _downgrade_site() {
6287
+ $this->_logger->entrance();
6288
+
6289
+ $api = $this->get_api_site_scope();
6290
+ $site = $api->call( 'downgrade.json', 'put' );
6291
+
6292
+ $plan_downgraded = false;
6293
+ $plan = false;
6294
+ if ( ! isset( $site->error ) ) {
6295
+ $prev_plan_id = $this->_site->plan->id;
6296
+
6297
+ // Update new site plan id.
6298
+ $this->_site->plan->id = $site->plan_id;
6299
+
6300
+ $plan = $this->_enrich_site_plan();
6301
+ $subscription = $this->_sync_site_subscription( $this->_license );
6302
+
6303
+ // Plan downgraded if plan was changed or subscription was cancelled.
6304
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
6305
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
6306
+ } else {
6307
+ // handle different error cases.
6308
+
6309
+ }
6310
+
6311
+ if ( $plan_downgraded ) {
6312
+ // Remove previous sticky message about upgrade (if exist).
6313
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
6314
+
6315
+ $this->_admin_notices->add(
6316
+ sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
6317
+ $plan->title,
6318
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
6319
+ )
6320
+ );
6321
+
6322
+ // Store site updates.
6323
+ $this->_store_site();
6324
+ } else {
6325
+ $this->_admin_notices->add(
6326
+ __fs( 'plan-downgraded-failure-message', $this->_slug ),
6327
+ __fs( 'oops', $this->_slug ) . '...',
6328
+ 'error'
6329
+ );
6330
+ }
6331
+ }
6332
+
6333
+ /**
6334
+ * Cancel site trial.
6335
+ *
6336
+ * @author Vova Feldman (@svovaf)
6337
+ * @since 1.0.9
6338
+ *
6339
+ * @uses FS_Api
6340
+ */
6341
+ private function _cancel_trial() {
6342
+ $this->_logger->entrance();
6343
+
6344
+ if ( ! $this->is_trial() ) {
6345
+ $this->_admin_notices->add(
6346
+ __fs( 'trial-cancel-no-trial-message', $this->_slug ),
6347
+ __fs( 'oops', $this->_slug ) . '...',
6348
+ 'error'
6349
+ );
6350
+
6351
+ return;
6352
+ }
6353
+
6354
+ $api = $this->get_api_site_scope();
6355
+ $site = $api->call( 'trials.json', 'delete' );
6356
+
6357
+ $trial_cancelled = false;
6358
+
6359
+ if ( ! isset( $site->error ) ) {
6360
+ $prev_trial_ends = $this->_site->trial_ends;
6361
+
6362
+ // Update new site plan id.
6363
+ $this->_site->trial_ends = $site->trial_ends;
6364
+
6365
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
6366
+ } else {
6367
+ // handle different error cases.
6368
+
6369
+ }
6370
+
6371
+ if ( $trial_cancelled ) {
6372
+ // Remove previous sticky message about upgrade (if exist).
6373
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
6374
+
6375
+ $this->_admin_notices->add(
6376
+ sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
6377
+ );
6378
+
6379
+ $this->_admin_notices->remove_sticky( array(
6380
+ 'trial_started',
6381
+ 'trial_promotion',
6382
+ 'plan_upgraded',
6383
+ ) );
6384
+
6385
+ // Store site updates.
6386
+ $this->_store_site();
6387
+
6388
+ // Clear trial plan information.
6389
+ unset( $this->_storage->trial_plan );
6390
+ } else {
6391
+ $this->_admin_notices->add(
6392
+ __fs( 'trial-cancel-failure-message', $this->_slug ),
6393
+ __fs( 'oops', $this->_slug ) . '...',
6394
+ 'error'
6395
+ );
6396
+ }
6397
+ }
6398
+
6399
+ /**
6400
+ * @author Vova Feldman (@svovaf)
6401
+ * @since 1.0.6
6402
+ *
6403
+ * @param bool|number $plugin_id
6404
+ *
6405
+ * @return bool
6406
+ */
6407
+ private function _is_addon_id( $plugin_id ) {
6408
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
6409
+ }
6410
+
6411
+ /**
6412
+ * Check if user eligible to download premium version updates.
6413
+ *
6414
+ * @author Vova Feldman (@svovaf)
6415
+ * @since 1.0.6
6416
+ *
6417
+ * @return bool
6418
+ */
6419
+ private function _can_download_premium() {
6420
+ return $this->has_active_license() ||
6421
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
6422
+ }
6423
+
6424
+ /**
6425
+ *
6426
+ * @author Vova Feldman (@svovaf)
6427
+ * @since 1.0.6
6428
+ *
6429
+ * @param bool|number $addon_id
6430
+ * @param string $type "json" or "zip"
6431
+ *
6432
+ * @return string
6433
+ */
6434
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
6435
+
6436
+ $is_addon = $this->_is_addon_id( $addon_id );
6437
+
6438
+ $is_premium = null;
6439
+ if ( ! $is_addon ) {
6440
+ $is_premium = $this->_can_download_premium();
6441
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
6442
+ $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
6443
+ }
6444
+
6445
+ return // If add-on, then append add-on ID.
6446
+ ( $is_addon ? "/addons/$addon_id" : '' ) .
6447
+ '/updates/latest.' . $type .
6448
+ // If add-on and not yet activated, try to fetch based on server licensing.
6449
+ ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
6450
+ }
6451
+
6452
+ /**
6453
+ * @author Vova Feldman (@svovaf)
6454
+ * @since 1.0.4
6455
+ *
6456
+ * @param bool|number $addon_id
6457
+ *
6458
+ * @return object|false Plugin latest tag info.
6459
+ */
6460
+ function _fetch_latest_version( $addon_id = false ) {
6461
+ $tag = $this->get_api_site_or_plugin_scope()->get(
6462
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
6463
+ true
6464
+ );
6465
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
6466
+ $this->_logger->departure( 'Latest version ' . $latest_version );
6467
+
6468
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
6469
+ }
6470
+
6471
+ #region Download Plugin ------------------------------------------------------------------
6472
+
6473
+ /**
6474
+ * Download latest plugin version, based on plan.
6475
+ * The download will be fetched via the API first.
6476
+ *
6477
+ * @author Vova Feldman (@svovaf)
6478
+ * @since 1.0.4
6479
+ *
6480
+ * @param bool|number $plugin_id
6481
+ *
6482
+ * @uses FS_Api
6483
+ *
6484
+ * @deprecated
6485
+ */
6486
+ private function _download_latest( $plugin_id = false ) {
6487
+ $this->_logger->entrance();
6488
+
6489
+ $is_addon = $this->_is_addon_id( $plugin_id );
6490
+
6491
+ $is_premium = $this->_can_download_premium();
6492
+
6493
+ $latest = $this->get_api_site_scope()->call(
6494
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
6495
+ );
6496
+
6497
+ $slug = $this->_slug;
6498
+ if ( $is_addon ) {
6499
+ $addon = $this->get_addon( $plugin_id );
6500
+ $slug = is_object( $addon ) ? $addon->slug : 'addon';
6501
+ }
6502
+
6503
+ if ( ! is_object( $latest ) ) {
6504
+ header( "Content-Type: application/zip" );
6505
+ header( "Content-Disposition: attachment; filename={$slug}" . ( ! $is_addon && $is_premium ? '-premium' : '' ) . ".zip" );
6506
+ header( "Content-Length: " . strlen( $latest ) );
6507
+ echo $latest;
6508
+
6509
+ exit();
6510
+ }
6511
+ }
6512
+
6513
+ /**
6514
+ * Download latest plugin version, based on plan.
6515
+ *
6516
+ * Not like _download_latest(), this will redirect the page
6517
+ * to secure download url to prevent dual download (from FS to WP server,
6518
+ * and then from WP server to the client / browser).
6519
+ *
6520
+ * @author Vova Feldman (@svovaf)
6521
+ * @since 1.0.9
6522
+ *
6523
+ * @param bool|number $plugin_id
6524
+ *
6525
+ * @uses FS_Api
6526
+ * @uses wp_redirect()
6527
+ */
6528
+ private function _download_latest_directly( $plugin_id = false ) {
6529
+ $this->_logger->entrance();
6530
+
6531
+ wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
6532
+ }
6533
+
6534
+ /**
6535
+ * Get latest plugin FS API download URL.
6536
+ *
6537
+ * @author Vova Feldman (@svovaf)
6538
+ * @since 1.0.9
6539
+ *
6540
+ * @param bool|number $plugin_id
6541
+ *
6542
+ * @return string
6543
+ */
6544
+ private function _get_latest_download_api_url( $plugin_id = false ) {
6545
+ $this->_logger->entrance();
6546
+
6547
+ return $this->get_api_site_scope()->get_signed_url(
6548
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
6549
+ );
6550
+ }
6551
+
6552
+ /**
6553
+ * Get latest plugin download link.
6554
+ *
6555
+ * @author Vova Feldman (@svovaf)
6556
+ * @since 1.0.9
6557
+ *
6558
+ * @param string $label
6559
+ * @param bool|number $plugin_id
6560
+ *
6561
+ * @return string
6562
+ */
6563
+ private function _get_latest_download_link( $label, $plugin_id = false ) {
6564
+ return sprintf(
6565
+ '<a target="_blank" href="%s">%s</a>',
6566
+ $this->_get_latest_download_local_url( $plugin_id ),
6567
+ $label
6568
+ );
6569
+ }
6570
+
6571
+ /**
6572
+ * Get latest plugin download local URL.
6573
+ *
6574
+ * @author Vova Feldman (@svovaf)
6575
+ * @since 1.0.9
6576
+ *
6577
+ * @param bool|number $plugin_id
6578
+ *
6579
+ * @return string
6580
+ */
6581
+ function _get_latest_download_local_url( $plugin_id = false ) {
6582
+ // Add timestamp to protect from caching.
6583
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
6584
+
6585
+ if ( ! empty( $plugin_id ) ) {
6586
+ $params['plugin_id'] = $plugin_id;
6587
+ }
6588
+
6589
+ return $this->get_account_url( 'download_latest', $params );
6590
+ }
6591
+
6592
+ #endregion Download Plugin ------------------------------------------------------------------
6593
+
6594
+ /**
6595
+ * @author Vova Feldman (@svovaf)
6596
+ * @since 1.0.4
6597
+ *
6598
+ * @uses FS_Api
6599
+ *
6600
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
6601
+ * was initiated by the admin.
6602
+ * @param bool|number $plugin_id
6603
+ */
6604
+ private function _check_updates( $background = false, $plugin_id = false ) {
6605
+ $this->_logger->entrance();
6606
+
6607
+ // Check if there's a newer version for download.
6608
+ $new_version = $this->_fetch_newer_version( $plugin_id );
6609
+
6610
+ $update = null;
6611
+ if ( is_object( $new_version ) ) {
6612
+ $update = new FS_Plugin_Tag( $new_version );
6613
+
6614
+ if ( ! $background ) {
6615
+ $this->_admin_notices->add(
6616
+ sprintf(
6617
+ __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
6618
+ $update->version,
6619
+ sprintf(
6620
+ '<a href="%s" target="_blank">%s</a>',
6621
+ $this->get_account_url( 'download_latest' ),
6622
+ sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
6623
+ )
6624
+ ),
6625
+ __fs( 'new', $this->_slug ) . '!'
6626
+ );
6627
+ }
6628
+ } else if ( false === $new_version && ! $background ) {
6629
+ $this->_admin_notices->add(
6630
+ __fs( 'you-have-latest', $this->_slug ),
6631
+ __fs( 'you-are-good', $this->_slug )
6632
+ );
6633
+ }
6634
+
6635
+ $this->_store_update( $update, true, $plugin_id );
6636
+ }
6637
+
6638
+ /**
6639
+ * @author Vova Feldman (@svovaf)
6640
+ * @since 1.0.4
6641
+ *
6642
+ * @uses FS_Api
6643
+ *
6644
+ */
6645
+ private function _sync_addons() {
6646
+ $this->_logger->entrance();
6647
+
6648
+ $result = $this->get_api_site_or_plugin_scope()->get( '/addons.json?enriched=true', true );
6649
+
6650
+ if ( isset( $result->error ) ) {
6651
+ return;
6652
+ }
6653
+
6654
+ $addons = array();
6655
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
6656
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
6657
+ }
6658
+
6659
+ $this->_store_addons( $addons, true );
6660
+ }
6661
+
6662
+ /**
6663
+ * Handle user email update.
6664
+ *
6665
+ * @author Vova Feldman (@svovaf)
6666
+ * @since 1.0.3
6667
+ * @uses FS_Api
6668
+ *
6669
+ * @param string $new_email
6670
+ *
6671
+ * @return object
6672
+ */
6673
+ private function _update_email( $new_email ) {
6674
+ $this->_logger->entrance();
6675
+
6676
+
6677
+ $api = $this->get_api_user_scope();
6678
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
6679
+ 'email' => $new_email,
6680
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
6681
+ 'account',
6682
+ array( 'fs_action' => 'sync_user' )
6683
+ ),
6684
+ ) );
6685
+
6686
+ if ( ! isset( $user->error ) ) {
6687
+ $this->_user->email = $user->email;
6688
+ $this->_user->is_verified = $user->is_verified;
6689
+ $this->_store_user();
6690
+ } else {
6691
+ // handle different error cases.
6692
+
6693
+ }
6694
+
6695
+ return $user;
6696
+ }
6697
+
6698
+ /**
6699
+ * @author Vova Feldman (@svovaf)
6700
+ * @since 1.1.1
6701
+ *
6702
+ * @param mixed $result
6703
+ *
6704
+ * @return bool Is API result contains an error.
6705
+ */
6706
+ private function is_api_error( $result ) {
6707
+ return ( is_object( $result ) && isset( $result->error ) ) ||
6708
+ is_string( $result );
6709
+ }
6710
+
6711
+ /**
6712
+ * Start install ownership change.
6713
+ *
6714
+ * @author Vova Feldman (@svovaf)
6715
+ * @since 1.1.1
6716
+ * @uses FS_Api
6717
+ *
6718
+ * @param string $candidate_email
6719
+ *
6720
+ * @return bool Is ownership change successfully initiated.
6721
+ */
6722
+ private function init_change_owner( $candidate_email ) {
6723
+ $this->_logger->entrance();
6724
+
6725
+ $api = $this->get_api_site_scope();
6726
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
6727
+ 'email' => $candidate_email,
6728
+ 'after_confirm_url' => $this->_get_admin_page_url(
6729
+ 'account',
6730
+ array( 'fs_action' => 'change_owner' )
6731
+ ),
6732
+ ) );
6733
+
6734
+ return ! $this->is_api_error( $result );
6735
+ }
6736
+
6737
+ /**
6738
+ * Handle install ownership change.
6739
+ *
6740
+ * @author Vova Feldman (@svovaf)
6741
+ * @since 1.1.1
6742
+ * @uses FS_Api
6743
+ *
6744
+ * @return bool Was ownership change successfully complete.
6745
+ */
6746
+ private function complete_change_owner() {
6747
+ $this->_logger->entrance();
6748
+
6749
+ $site_result = $this->get_api_site_scope( true )->get();
6750
+ $site = new FS_Site( $site_result );
6751
+ $this->_site = $site;
6752
+
6753
+ $user = new FS_User();
6754
+ $user->id = fs_request_get( 'user_id' );
6755
+
6756
+ // Validate install's user and given user.
6757
+ if ( $user->id != $this->_site->user_id ) {
6758
+ return false;
6759
+ }
6760
+
6761
+ $user->public_key = fs_request_get( 'user_public_key' );
6762
+ $user->secret_key = fs_request_get( 'user_secret_key' );
6763
+
6764
+ // Fetch new user information.
6765
+ $this->_user = $user;
6766
+ $user_result = $this->get_api_user_scope( true )->get();
6767
+ $user = new FS_User( $user_result );
6768
+ $this->_user = $user;
6769
+
6770
+ $this->_set_account( $user, $site );
6771
+
6772
+ return true;
6773
+ }
6774
+
6775
+ /**
6776
+ * Handle user name update.
6777
+ *
6778
+ * @author Vova Feldman (@svovaf)
6779
+ * @since 1.0.9
6780
+ * @uses FS_Api
6781
+ *
6782
+ * @return object
6783
+ */
6784
+ private function update_user_name() {
6785
+ $this->_logger->entrance();
6786
+ $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
6787
+
6788
+ $api = $this->get_api_user_scope();
6789
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
6790
+ 'name' => $name,
6791
+ ) );
6792
+
6793
+ if ( ! isset( $user->error ) ) {
6794
+ $this->_user->first = $user->first;
6795
+ $this->_user->last = $user->last;
6796
+ $this->_store_user();
6797
+ } else {
6798
+ // handle different error cases.
6799
+
6800
+ }
6801
+
6802
+ return $user;
6803
+ }
6804
+
6805
+ /**
6806
+ * Verify user email.
6807
+ *
6808
+ * @author Vova Feldman (@svovaf)
6809
+ * @since 1.0.3
6810
+ * @uses FS_Api
6811
+ */
6812
+ private function verify_email() {
6813
+ $this->_handle_account_user_sync();
6814
+
6815
+ if ( $this->_user->is_verified() ) {
6816
+ return;
6817
+ }
6818
+
6819
+ $api = $this->get_api_site_scope();
6820
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
6821
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
6822
+ 'account',
6823
+ array( 'fs_action' => 'sync_user' )
6824
+ )
6825
+ ) );
6826
+
6827
+ if ( ! isset( $result->error ) ) {
6828
+ $this->_admin_notices->add( sprintf(
6829
+ __fs( 'verification-email-sent-message', $this->_slug ),
6830
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
6831
+ ) );
6832
+ } else {
6833
+ // handle different error cases.
6834
+
6835
+ }
6836
+ }
6837
+
6838
+ /**
6839
+ * @author Vova Feldman (@svovaf)
6840
+ * @since 1.1.2
6841
+ *
6842
+ * @return string
6843
+ */
6844
+ private function get_activation_url() {
6845
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url() );
6846
+ }
6847
+
6848
+ /**
6849
+ * @author Vova Feldman (@svovaf)
6850
+ * @since 1.1.3
6851
+ *
6852
+ * @param string $filter Filter name.
6853
+ *
6854
+ * @return string
6855
+ */
6856
+ private function get_after_activation_url( $filter ) {
6857
+ $first_time_path = $this->_menu->get_first_time_path();
6858
+
6859
+ return $this->apply_filters(
6860
+ $filter,
6861
+ empty( $first_time_path ) ?
6862
+ $this->_get_admin_page_url() :
6863
+ $first_time_path
6864
+ );
6865
+ }
6866
+
6867
+ /**
6868
+ * Handle account page updates / edits / actions.
6869
+ *
6870
+ * @author Vova Feldman (@svovaf)
6871
+ * @since 1.0.2
6872
+ *
6873
+ */
6874
+ private function _handle_account_edits() {
6875
+ if ( ! current_user_can( 'activate_plugins' ) ) {
6876
+ return;
6877
+ }
6878
+
6879
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
6880
+ $action = fs_get_action();
6881
+
6882
+ switch ( $action ) {
6883
+ case 'delete_account':
6884
+ check_admin_referer( $action );
6885
+
6886
+ if ( $plugin_id == $this->get_id() ) {
6887
+ $this->delete_account_event();
6888
+
6889
+ // Clear user and site.
6890
+ $this->_site = null;
6891
+ $this->_user = null;
6892
+
6893
+ if ( fs_redirect( $this->get_activation_url() ) ) {
6894
+ exit();
6895
+ }
6896
+ } else {
6897
+ if ( $this->is_addon_activated( $plugin_id ) ) {
6898
+ $fs_addon = self::get_instance_by_id( $plugin_id );
6899
+ $fs_addon->delete_account_event();
6900
+
6901
+ if ( fs_redirect( $this->_get_admin_page_url( 'account' ) ) ) {
6902
+ exit();
6903
+ }
6904
+ }
6905
+ }
6906
+
6907
+ return;
6908
+
6909
+ case 'downgrade_account':
6910
+ check_admin_referer( $action );
6911
+ $this->_downgrade_site();
6912
+
6913
+ return;
6914
+
6915
+ case 'activate_license':
6916
+ check_admin_referer( $action );
6917
+
6918
+ if ( $plugin_id == $this->get_id() ) {
6919
+ $this->_activate_license();
6920
+ } else {
6921
+ if ( $this->is_addon_activated( $plugin_id ) ) {
6922
+ $fs_addon = self::get_instance_by_id( $plugin_id );
6923
+ $fs_addon->_activate_license();
6924
+ }
6925
+ }
6926
+
6927
+ return;
6928
+
6929
+ case 'deactivate_license':
6930
+ check_admin_referer( $action );
6931
+
6932
+ if ( $plugin_id == $this->get_id() ) {
6933
+ $this->_deactivate_license();
6934
+ } else {
6935
+ if ( $this->is_addon_activated( $plugin_id ) ) {
6936
+ $fs_addon = self::get_instance_by_id( $plugin_id );
6937
+ $fs_addon->_deactivate_license();
6938
+ }
6939
+ }
6940
+
6941
+ return;
6942
+
6943
+ case 'check_updates':
6944
+ check_admin_referer( $action );
6945
+ $this->_check_updates();
6946
+
6947
+ return;
6948
+
6949
+ case 'change_owner':
6950
+ $state = fs_request_get( 'state', 'init' );
6951
+ switch ( $state ) {
6952
+ case 'init':
6953
+ $candidate_email = fs_request_get( 'candidate_email', '' );
6954
+
6955
+ if ( $this->init_change_owner( $candidate_email ) ) {
6956
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
6957
+ }
6958
+ break;
6959
+ case 'owner_confirmed':
6960
+ $candidate_email = fs_request_get( 'candidate_email', '' );
6961
+
6962
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
6963
+ break;
6964
+ case 'candidate_confirmed':
6965
+ if ( $this->complete_change_owner() ) {
6966
+ $this->_admin_notices->add_sticky(
6967
+ sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
6968
+ 'ownership_changed',
6969
+ __fs( 'congrats', $this->_slug ) . '!'
6970
+ );
6971
+ } else {
6972
+ // @todo Handle failed ownership change message.
6973
+ }
6974
+ break;
6975
+ }
6976
+
6977
+ return;
6978
+
6979
+ case 'update_email':
6980
+ check_admin_referer( 'update_email' );
6981
+
6982
+ $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
6983
+ $result = $this->_update_email( $new_email );
6984
+
6985
+ if ( isset( $result->error ) ) {
6986
+ switch ( $result->error->code ) {
6987
+ case 'user_exist':
6988
+ $this->_admin_notices->add(
6989
+ __fs( 'user-exist-message', $this->_slug ) . ' ' .
6990
+ sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
6991
+ sprintf(
6992
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
6993
+ $this->get_account_url( 'change_owner', array(
6994
+ 'state' => 'init',
6995
+ 'candidate_email' => $new_email
6996
+ ) ),
6997
+ __fs( 'change-ownership', $this->_slug )
6998
+ ),
6999
+ __fs( 'oops', $this->_slug ) . '...',
7000
+ 'error'
7001
+ );
7002
+ break;
7003
+ }
7004
+ } else {
7005
+ $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
7006
+ }
7007
+
7008
+ return;
7009
+
7010
+ case 'update_user_name':
7011
+ check_admin_referer( 'update_user_name' );
7012
+
7013
+ $result = $this->update_user_name();
7014
+
7015
+ if ( isset( $result->error ) ) {
7016
+ $this->_admin_notices->add(
7017
+ __fs( 'name-update-failed-message', $this->_slug ),
7018
+ __fs( 'oops', $this->_slug ) . '...',
7019
+ 'error'
7020
+ );
7021
+ } else {
7022
+ $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
7023
+ }
7024
+
7025
+ return;
7026
+
7027
+ #region Actions that might be called from external links (e.g. email)
7028
+
7029
+ case 'cancel_trial':
7030
+ $this->_cancel_trial();
7031
+
7032
+ return;
7033
+
7034
+ case 'verify_email':
7035
+ $this->verify_email();
7036
+
7037
+ return;
7038
+
7039
+ case 'sync_user':
7040
+ $this->_handle_account_user_sync();
7041
+
7042
+ return;
7043
+
7044
+ case $this->_slug . '_sync_license':
7045
+ $this->_sync_license();
7046
+
7047
+ return;
7048
+
7049
+ case 'download_latest':
7050
+ $this->_download_latest_directly( $plugin_id );
7051
+
7052
+ return;
7053
+
7054
+ #endregion
7055
+ }
7056
+
7057
+ if ( WP_FS__IS_POST_REQUEST ) {
7058
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
7059
+ foreach ( $properties as $p ) {
7060
+ if ( 'update_' . $p === $action ) {
7061
+ check_admin_referer( $action );
7062
+
7063
+ $this->_logger->log( $action );
7064
+
7065
+ $site_property = substr( $p, strlen( 'site_' ) );
7066
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
7067
+ $this->get_site()->{$site_property} = $site_property_value;
7068
+
7069
+ // Store account after modification.
7070
+ $this->_store_site();
7071
+
7072
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
7073
+
7074
+ $this->_admin_notices->add( sprintf(
7075
+ __fs( 'x-updated', $this->_slug ),
7076
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
7077
+
7078
+ return;
7079
+ }
7080
+ }
7081
+ }
7082
+ }
7083
+
7084
+ /**
7085
+ * Account page resources load.
7086
+ *
7087
+ * @author Vova Feldman (@svovaf)
7088
+ * @since 1.0.6
7089
+ */
7090
+ function _account_page_load() {
7091
+ $this->_logger->entrance();
7092
+
7093
+ $this->_logger->info( var_export( $_REQUEST, true ) );
7094
+
7095
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
7096
+
7097
+ if ( $this->_has_addons() ) {
7098
+ wp_enqueue_script( 'plugin-install' );
7099
+ add_thickbox();
7100
+
7101
+ function fs_addons_body_class( $classes ) {
7102
+ $classes .= ' plugins-php';
7103
+
7104
+ return $classes;
7105
+ }
7106
+
7107
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
7108
+ }
7109
+
7110
+ $this->_handle_account_edits();
7111
+
7112
+ $this->do_action( 'account_page_load_before_departure' );
7113
+ }
7114
+
7115
+ /**
7116
+ * Render account page.
7117
+ *
7118
+ * @author Vova Feldman (@svovaf)
7119
+ * @since 1.0.0
7120
+ */
7121
+ function _account_page_render() {
7122
+ $this->_logger->entrance();
7123
+
7124
+ $vars = array( 'slug' => $this->_slug );
7125
+ fs_require_once_template( 'account.php', $vars );
7126
+ }
7127
+
7128
+ /**
7129
+ * Render account connect page.
7130
+ *
7131
+ * @author Vova Feldman (@svovaf)
7132
+ * @since 1.0.7
7133
+ */
7134
+ function _connect_page_render() {
7135
+ $this->_logger->entrance();
7136
+
7137
+ $vars = array( 'slug' => $this->_slug );
7138
+ fs_require_once_template( 'connect.php', $vars );
7139
+ }
7140
+
7141
+ /**
7142
+ * Load required resources before add-ons page render.
7143
+ *
7144
+ * @author Vova Feldman (@svovaf)
7145
+ * @since 1.0.6
7146
+ */
7147
+ function _addons_page_load() {
7148
+ $this->_logger->entrance();
7149
+
7150
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
7151
+
7152
+ wp_enqueue_script( 'plugin-install' );
7153
+ add_thickbox();
7154
+
7155
+ function fs_addons_body_class( $classes ) {
7156
+ $classes .= ' plugins-php';
7157
+
7158
+ return $classes;
7159
+ }
7160
+
7161
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
7162
+
7163
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
7164
+ $this->_admin_notices->add(
7165
+ sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
7166
+ __fs( 'heads-up', $this->_slug ),
7167
+ 'update-nag'
7168
+ );
7169
+ }
7170
+ }
7171
+
7172
+ /**
7173
+ * Render add-ons page.
7174
+ *
7175
+ * @author Vova Feldman (@svovaf)
7176
+ * @since 1.0.6
7177
+ */
7178
+ function _addons_page_render() {
7179
+ $this->_logger->entrance();
7180
+
7181
+ $vars = array( 'slug' => $this->_slug );
7182
+ fs_require_once_template( 'add-ons.php', $vars );
7183
+ }
7184
+
7185
+ /* Pricing & Upgrade
7186
+ ------------------------------------------------------------------------------------------------------------------*/
7187
+ /**
7188
+ * Render pricing page.
7189
+ *
7190
+ * @author Vova Feldman (@svovaf)
7191
+ * @since 1.0.0
7192
+ */
7193
+ function _pricing_page_render() {
7194
+ $this->_logger->entrance();
7195
+
7196
+ $vars = array( 'slug' => $this->_slug );
7197
+
7198
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
7199
+ fs_require_once_template( 'checkout.php', $vars );
7200
+ } else {
7201
+ fs_require_once_template( 'pricing.php', $vars );
7202
+ }
7203
+ }
7204
+
7205
+ #region Contact Us ------------------------------------------------------------------
7206
+
7207
+ /**
7208
+ * Render contact-us page.
7209
+ *
7210
+ * @author Vova Feldman (@svovaf)
7211
+ * @since 1.0.3
7212
+ */
7213
+ function _contact_page_render() {
7214
+ $this->_logger->entrance();
7215
+
7216
+ $vars = array( 'slug' => $this->_slug );
7217
+ fs_require_once_template( 'contact.php', $vars );
7218
+ }
7219
+
7220
+ #endregion ------------------------------------------------------------------
7221
+
7222
+ /**
7223
+ * Hide all admin notices to prevent distractions.
7224
+ *
7225
+ * @author Vova Feldman (@svovaf)
7226
+ * @since 1.0.3
7227
+ *
7228
+ * @uses remove_all_actions()
7229
+ */
7230
+ private static function _hide_admin_notices() {
7231
+ remove_all_actions( 'admin_notices' );
7232
+ remove_all_actions( 'network_admin_notices' );
7233
+ remove_all_actions( 'all_admin_notices' );
7234
+ remove_all_actions( 'user_admin_notices' );
7235
+ }
7236
+
7237
+ static function _clean_admin_content_section_hook() {
7238
+ self::_hide_admin_notices();
7239
+
7240
+ // Hide footer.
7241
+ echo '<style>#wpfooter { display: none !important; }</style>';
7242
+ }
7243
+
7244
+ /**
7245
+ * Attach to admin_head hook to hide all admin notices.
7246
+ *
7247
+ * @author Vova Feldman (@svovaf)
7248
+ * @since 1.0.3
7249
+ */
7250
+ static function _clean_admin_content_section() {
7251
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
7252
+ }
7253
+
7254
+ /* CSS & JavaScript
7255
+ ------------------------------------------------------------------------------------------------------------------*/
7256
+ /* function _enqueue_script($handle, $src) {
7257
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
7258
+
7259
+ $this->_logger->entrance( 'script = ' . $url );
7260
+
7261
+ wp_enqueue_script( $handle, $url );
7262
+ }*/
7263
+
7264
+ /* SDK
7265
+ ------------------------------------------------------------------------------------------------------------------*/
7266
+ private $_user_api;
7267
+
7268
+ /**
7269
+ *
7270
+ * @author Vova Feldman (@svovaf)
7271
+ * @since 1.0.2
7272
+ *
7273
+ * @param bool $flush
7274
+ *
7275
+ * @return FS_Api
7276
+ */
7277
+ function get_api_user_scope( $flush = false ) {
7278
+ if ( ! isset( $this->_user_api ) || $flush ) {
7279
+ $this->_user_api = FS_Api::instance(
7280
+ $this->_slug,
7281
+ 'user',
7282
+ $this->_user->id,
7283
+ $this->_user->public_key,
7284
+ ! $this->is_live(),
7285
+ $this->_user->secret_key
7286
+ );
7287
+ }
7288
+
7289
+ return $this->_user_api;
7290
+ }
7291
+
7292
+ private $_site_api;
7293
+
7294
+ /**
7295
+ *
7296
+ * @author Vova Feldman (@svovaf)
7297
+ * @since 1.0.2
7298
+ *
7299
+ * @param bool $flush
7300
+ *
7301
+ * @return FS_Api
7302
+ */
7303
+ function get_api_site_scope( $flush = false ) {
7304
+ if ( ! isset( $this->_site_api ) || $flush ) {
7305
+ $this->_site_api = FS_Api::instance(
7306
+ $this->_slug,
7307
+ 'install',
7308
+ $this->_site->id,
7309
+ $this->_site->public_key,
7310
+ ! $this->is_live(),
7311
+ $this->_site->secret_key
7312
+ );
7313
+ }
7314
+
7315
+ return $this->_site_api;
7316
+ }
7317
+
7318
+ private $_plugin_api;
7319
+
7320
+ /**
7321
+ * Get plugin public API scope.
7322
+ *
7323
+ * @author Vova Feldman (@svovaf)
7324
+ * @since 1.0.7
7325
+ *
7326
+ * @return FS_Api
7327
+ */
7328
+ function get_api_plugin_scope() {
7329
+ if ( ! isset( $this->_plugin_api ) ) {
7330
+ $this->_plugin_api = FS_Api::instance(
7331
+ $this->_slug,
7332
+ 'plugin',
7333
+ $this->_plugin->id,
7334
+ $this->_plugin->public_key,
7335
+ ! $this->is_live()
7336
+ );
7337
+ }
7338
+
7339
+ return $this->_plugin_api;
7340
+ }
7341
+
7342
+ /**
7343
+ * Get site API scope object (fallback to public plugin scope when not registered).
7344
+ *
7345
+ * @author Vova Feldman (@svovaf)
7346
+ * @since 1.0.7
7347
+ *
7348
+ * @return FS_Api
7349
+ */
7350
+ function get_api_site_or_plugin_scope() {
7351
+ return $this->is_registered() ?
7352
+ $this->get_api_site_scope() :
7353
+ $this->get_api_plugin_scope();
7354
+ }
7355
+
7356
+ /**
7357
+ * Show trial promotional notice (if any trial exist).
7358
+ *
7359
+ * @author Vova Feldman (@svovaf)
7360
+ * @since 1.0.9
7361
+ *
7362
+ * @param $plans
7363
+ */
7364
+ function _check_for_trial_plans( $plans ) {
7365
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
7366
+ }
7367
+
7368
+ /**
7369
+ * Show trial promotional notice (if any trial exist).
7370
+ *
7371
+ * @author Vova Feldman (@svovaf)
7372
+ * @since 1.0.9
7373
+ */
7374
+ function _add_trial_notice() {
7375
+ // Check if trial already utilized.
7376
+ if ( $this->_site->is_trial_utilized() ) {
7377
+ return;
7378
+ }
7379
+
7380
+ // Check if already paying.
7381
+ if ( $this->is_paying() ) {
7382
+ return;
7383
+ }
7384
+
7385
+ // Check if trial message is already shown.
7386
+ if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
7387
+ return;
7388
+ }
7389
+
7390
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
7391
+ $trial_plans_count = count( $trial_plans );
7392
+
7393
+ // Check if any of the plans contains trial.
7394
+ if ( 0 === $trial_plans_count ) {
7395
+ return;
7396
+ }
7397
+
7398
+ /**
7399
+ * @var FS_Plugin_Plan $paid_plan
7400
+ */
7401
+ $paid_plan = $trial_plans[0];
7402
+ $require_subscription = $paid_plan->is_require_subscription;
7403
+ $upgrade_url = $this->get_trial_url();
7404
+ $cc_string = $require_subscription ?
7405
+ sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $paid_plan->trial_period ) :
7406
+ __fs( 'no-cc-required', $this->_slug ) . '!';
7407
+
7408
+
7409
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
7410
+
7411
+ if ( $total_paid_plans === $trial_plans_count ) {
7412
+ // All paid plans have trials.
7413
+ $message = sprintf(
7414
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
7415
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
7416
+ strtolower( __fs( 'awesome', $this->_slug ) ),
7417
+ $paid_plan->trial_period
7418
+ );
7419
+ } else {
7420
+ $plans_string = '';
7421
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
7422
+ $plans_string .= sprintf( '<a href="%s">%s</a>', $upgrade_url, $trial_plans[ $i ]->title );
7423
+
7424
+ if ( $i < $trial_plans_count - 2 ) {
7425
+ $plans_string .= ', ';
7426
+ } else if ( $i == $trial_plans_count - 2 ) {
7427
+ $plans_string .= ' and ';
7428
+ }
7429
+ }
7430
+
7431
+ // Not all paid plans have trials.
7432
+ $message = sprintf(
7433
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
7434
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
7435
+ $plans_string,
7436
+ $paid_plan->trial_period
7437
+ );
7438
+ }
7439
+
7440
+ $message .= ' ' . $cc_string;
7441
+
7442
+ // Add start trial button.
7443
+ $message .= ' ' . sprintf(
7444
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
7445
+ $upgrade_url,
7446
+ __fs( 'start-free-trial', $this->_slug )
7447
+ );
7448
+
7449
+ $this->_admin_notices->add_sticky(
7450
+ $this->apply_filters( 'trial_promotion_message', $message ),
7451
+ 'trial_promotion',
7452
+ '',
7453
+ 'promotion'
7454
+ );
7455
+
7456
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
7457
+ }
7458
+
7459
+ /* Action Links
7460
+ ------------------------------------------------------------------------------------------------------------------*/
7461
+ private $_action_links_hooked = false;
7462
+ private $_action_links = array();
7463
+
7464
+ /**
7465
+ * @author Vova Feldman (@svovaf)
7466
+ * @since 1.0.0
7467
+ *
7468
+ * @return bool
7469
+ */
7470
+ private function is_plugin_action_links_hooked() {
7471
+ $this->_logger->entrance( json_encode( $this->_action_links_hooked ) );
7472
+
7473
+ return $this->_action_links_hooked;
7474
+ }
7475
+
7476
+ /**
7477
+ * Hook to plugin action links filter.
7478
+ *
7479
+ * @author Vova Feldman (@svovaf)
7480
+ * @since 1.0.0
7481
+ */
7482
+ private function hook_plugin_action_links() {
7483
+ $this->_logger->entrance();
7484
+
7485
+ $this->_action_links_hooked = true;
7486
+
7487
+ $this->_logger->log( 'Adding action links hooks.' );
7488
+
7489
+ // Add action link to settings page.
7490
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
7491
+ &$this,
7492
+ '_modify_plugin_action_links_hook'
7493
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
7494
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
7495
+ &$this,
7496
+ '_modify_plugin_action_links_hook'
7497
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
7498
+ }
7499
+
7500
+ /**
7501
+ * Add plugin action link.
7502
+ *
7503
+ * @author Vova Feldman (@svovaf)
7504
+ * @since 1.0.0
7505
+ *
7506
+ * @param $label
7507
+ * @param $url
7508
+ * @param bool $external
7509
+ * @param int $priority
7510
+ * @param bool $key
7511
+ */
7512
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
7513
+ $this->_logger->entrance();
7514
+
7515
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
7516
+ $this->_action_links[ $priority ] = array();
7517
+ }
7518
+
7519
+ if ( false === $key ) {
7520
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
7521
+ }
7522
+
7523
+ $this->_action_links[ $priority ][] = array(
7524
+ 'label' => $label,
7525
+ 'href' => $url,
7526
+ 'key' => $key,
7527
+ 'external' => $external
7528
+ );
7529
+ }
7530
+
7531
+ /**
7532
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
7533
+ *
7534
+ * @author Vova Feldman (@svovaf)
7535
+ * @since 1.0.0
7536
+ */
7537
+ function _add_upgrade_action_link() {
7538
+ $this->_logger->entrance();
7539
+
7540
+ if ( $this->is_registered() ) {
7541
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
7542
+ $this->add_plugin_action_link(
7543
+ __fs( 'upgrade', $this->_slug ),
7544
+ $this->get_upgrade_url(),
7545
+ false,
7546
+ 20,
7547
+ 'upgrade'
7548
+ );
7549
+ }
7550
+
7551
+ if ( $this->_has_addons() ) {
7552
+ $this->add_plugin_action_link(
7553
+ __fs( 'add-ons', $this->_slug ),
7554
+ $this->_get_admin_page_url( 'addons' ),
7555
+ false,
7556
+ WP_FS__DEFAULT_PRIORITY,
7557
+ 'addons'
7558
+ );
7559
+ }
7560
+ }
7561
+ }
7562
+
7563
+ /**
7564
+ * Forward page to activation page.
7565
+ *
7566
+ * @author Vova Feldman (@svovaf)
7567
+ * @since 1.0.3
7568
+ */
7569
+ function _redirect_on_activation_hook() {
7570
+ $url = false;
7571
+ $plugin_fs = false;
7572
+
7573
+ if ( ! $this->is_addon() ) {
7574
+ $first_time_path = $this->_menu->get_first_time_path();
7575
+ $plugin_fs = $this;
7576
+ $url = $plugin_fs->is_activation_mode() ?
7577
+ $plugin_fs->get_activation_url() :
7578
+ ( empty( $first_time_path ) ?
7579
+ $this->_get_admin_page_url() :
7580
+ $first_time_path );
7581
+ } else {
7582
+ if ( $this->is_parent_plugin_installed() ) {
7583
+ $plugin_fs = self::get_parent_instance();
7584
+ }
7585
+
7586
+ if ( is_object( $plugin_fs ) ) {
7587
+ if ( ! $plugin_fs->is_registered() ) {
7588
+ // Forward to parent plugin connect when parent not registered.
7589
+ $url = $plugin_fs->get_activation_url();
7590
+ } else {
7591
+ // Forward to account page.
7592
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
7593
+ }
7594
+ }
7595
+ }
7596
+
7597
+ if ( is_string( $url ) ) {
7598
+ fs_redirect( $url );
7599
+ exit();
7600
+ }
7601
+ }
7602
+
7603
+ /**
7604
+ * Modify plugin's page action links collection.
7605
+ *
7606
+ * @author Vova Feldman (@svovaf)
7607
+ * @since 1.0.0
7608
+ *
7609
+ * @param array $links
7610
+ * @param $file
7611
+ *
7612
+ * @return array
7613
+ */
7614
+ function _modify_plugin_action_links_hook( $links, $file ) {
7615
+ $this->_logger->entrance();
7616
+
7617
+ ksort( $this->_action_links );
7618
+
7619
+ foreach ( $this->_action_links as $new_links ) {
7620
+ foreach ( $new_links as $link ) {
7621
+ $links[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
7622
+ }
7623
+ }
7624
+
7625
+ /*
7626
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
7627
+ *
7628
+ * If user is paying or in trial and have the free version installed,
7629
+ * assume that the deactivation is for the upgrade process, so this is not needed.
7630
+ */
7631
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
7632
+ if ( isset( $links['deactivate'] ) ) {
7633
+ $links['deactivate'] .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
7634
+ }
7635
+ }
7636
+
7637
+ return $links;
7638
+ }
7639
+
7640
+ /**
7641
+ * Adds admin message.
7642
+ *
7643
+ * @author Vova Feldman (@svovaf)
7644
+ * @since 1.0.4
7645
+ *
7646
+ * @param string $message
7647
+ * @param string $title
7648
+ * @param string $type
7649
+ */
7650
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
7651
+ $this->_admin_notices->add( $message, $title, $type );
7652
+ }
7653
+
7654
+ /**
7655
+ * Adds sticky admin message.
7656
+ *
7657
+ * @author Vova Feldman (@svovaf)
7658
+ * @since 1.1.0
7659
+ *
7660
+ * @param string $message
7661
+ * @param string $id
7662
+ * @param string $title
7663
+ * @param string $type
7664
+ */
7665
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
7666
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
7667
+ }
7668
+
7669
+ /* Plugin Auto-Updates (@since 1.0.4)
7670
+ ------------------------------------------------------------------------------------------------------------------*/
7671
+ /**
7672
+ * @var string[]
7673
+ */
7674
+ private static $_auto_updated_plugins;
7675
+
7676
+ /**
7677
+ * @todo TEST IF IT WORKS!!!
7678
+ *
7679
+ * Include plugins for automatic updates based on stored settings.
7680
+ *
7681
+ * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
7682
+ *
7683
+ * @author Vova Feldman (@svovaf)
7684
+ * @since 1.0.4
7685
+ *
7686
+ * @param bool $update Whether to update (not used for plugins)
7687
+ * @param object $item The plugin's info
7688
+ *
7689
+ * @return bool
7690
+ */
7691
+ static function _include_plugins_in_auto_update( $update, $item ) {
7692
+ // Before version 3.8.2 the $item was the file name of the plugin,
7693
+ // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
7694
+ $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
7695
+
7696
+ if ( ! isset( self::$_auto_updated_plugins ) ) {
7697
+ $plugins = self::$_accounts->get_option( 'plugins', array() );
7698
+
7699
+ $identifiers = array();
7700
+ foreach ( $plugins as $p ) {
7701
+ /**
7702
+ * @var FS_Plugin $p
7703
+ */
7704
+ if ( isset( $p->auto_update ) && $p->auto_update ) {
7705
+ $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
7706
+ }
7707
+ }
7708
+
7709
+ self::$_auto_updated_plugins = $identifiers;
7710
+ }
7711
+
7712
+ if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
7713
+ return true;
7714
+ }
7715
+
7716
+ // Pass update decision to next filters
7717
+ return $update;
7718
+ }
7719
+
7720
+ #region Versioning ------------------------------------------------------------------
7721
+
7722
+ /**
7723
+ * Check if Freemius in SDK upgrade mode.
7724
+ *
7725
+ * @author Vova Feldman (@svovaf)
7726
+ * @since 1.0.9
7727
+ *
7728
+ * @return bool
7729
+ */
7730
+ function is_sdk_upgrade_mode() {
7731
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
7732
+ $this->_storage->sdk_upgrade_mode :
7733
+ false;
7734
+ }
7735
+
7736
+ /**
7737
+ * Turn SDK upgrade mode off.
7738
+ *
7739
+ * @author Vova Feldman (@svovaf)
7740
+ * @since 1.0.9
7741
+ *
7742
+ * @return bool
7743
+ */
7744
+ function set_sdk_upgrade_complete() {
7745
+ $this->_storage->sdk_upgrade_mode = false;
7746
+ }
7747
+
7748
+ /**
7749
+ * Check if plugin upgrade mode.
7750
+ *
7751
+ * @author Vova Feldman (@svovaf)
7752
+ * @since 1.0.9
7753
+ *
7754
+ * @return bool
7755
+ */
7756
+ function is_plugin_upgrade_mode() {
7757
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
7758
+ $this->_storage->plugin_upgrade_mode :
7759
+ false;
7760
+ }
7761
+
7762
+ /**
7763
+ * Turn plugin upgrade mode off.
7764
+ *
7765
+ * @author Vova Feldman (@svovaf)
7766
+ * @since 1.0.9
7767
+ *
7768
+ * @return bool
7769
+ */
7770
+ function set_plugin_upgrade_complete() {
7771
+ $this->_storage->plugin_upgrade_mode = false;
7772
+ }
7773
+
7774
+ #endregion ------------------------------------------------------------------
7775
+
7776
+ #region Permissions ------------------------------------------------------------------
7777
+
7778
+ /**
7779
+ * Check if specific permission requested.
7780
+ *
7781
+ * @author Vova Feldman (@svovaf)
7782
+ * @since 1.1.6
7783
+ *
7784
+ * @param string $permission
7785
+ *
7786
+ * @return bool
7787
+ */
7788
+ function is_permission_requested( $permission ) {
7789
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
7790
+ }
7791
+
7792
+ #endregion Permissions ------------------------------------------------------------------
7793
+
7794
+ #region Marketing ------------------------------------------------------------------
7795
+
7796
+ /**
7797
+ * Check if current user purchased any other plugins before.
7798
+ *
7799
+ * @author Vova Feldman (@svovaf)
7800
+ * @since 1.0.9
7801
+ *
7802
+ * @return bool
7803
+ */
7804
+ function has_purchased_before() {
7805
+ // TODO: Implement has_purchased_before() method.
7806
+ }
7807
+
7808
+ /**
7809
+ * Check if current user classified as an agency.
7810
+ *
7811
+ * @author Vova Feldman (@svovaf)
7812
+ * @since 1.0.9
7813
+ *
7814
+ * @return bool
7815
+ */
7816
+ function is_agency() {
7817
+ // TODO: Implement is_agency() method.
7818
+ }
7819
+
7820
+ /**
7821
+ * Check if current user classified as a developer.
7822
+ *
7823
+ * @author Vova Feldman (@svovaf)
7824
+ * @since 1.0.9
7825
+ *
7826
+ * @return bool
7827
+ */
7828
+ function is_developer() {
7829
+ // TODO: Implement is_developer() method.
7830
+ }
7831
+
7832
+ /**
7833
+ * Check if current user classified as a business.
7834
+ *
7835
+ * @author Vova Feldman (@svovaf)
7836
+ * @since 1.0.9
7837
+ *
7838
+ * @return bool
7839
+ */
7840
+ function is_business() {
7841
+ // TODO: Implement is_business() method.
7842
+ }
7843
+
7844
+ #endregion ------------------------------------------------------------------
7845
+ }
freemius/includes/class-fs-api.php ADDED
@@ -0,0 +1,454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Api
15
+ *
16
+ * Wraps Freemius API SDK to handle:
17
+ * 1. Clock sync.
18
+ * 2. Fallback to HTTP when HTTPS fails.
19
+ * 3. Adds caching layer to GET requests.
20
+ * 4. Adds consistency for failed requests by using last cached version.
21
+ */
22
+ class FS_Api {
23
+ /**
24
+ * @var FS_Api[]
25
+ */
26
+ private static $_instances = array();
27
+
28
+ /**
29
+ * @var FS_Option_Manager Freemius options, options-manager.
30
+ */
31
+ private static $_options;
32
+
33
+ /**
34
+ * @var FS_Cache_Manager API Caching layer
35
+ */
36
+ private static $_cache;
37
+
38
+ /**
39
+ * @var int Clock diff in seconds between current server to API server.
40
+ */
41
+ private static $_clock_diff;
42
+
43
+ /**
44
+ * @var Freemius_Api
45
+ */
46
+ private $_api;
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ private $_slug;
52
+
53
+ /**
54
+ * @var FS_Logger
55
+ * @since 1.0.4
56
+ */
57
+ private $_logger;
58
+
59
+ /**
60
+ * @param string $slug
61
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
62
+ * @param number $id Element's id.
63
+ * @param string $public_key Public key.
64
+ * @param bool $is_sandbox
65
+ * @param bool|string $secret_key Element's secret key.
66
+ *
67
+ * @return FS_Api
68
+ */
69
+ static function instance( $slug, $scope, $id, $public_key, $is_sandbox, $secret_key = false ) {
70
+ $identifier = md5( $slug . $scope . $id . $public_key . ( is_string( $secret_key ) ? $secret_key : '' ) . json_encode( $is_sandbox ) );
71
+
72
+ if ( ! isset( self::$_instances[ $identifier ] ) ) {
73
+ self::_init();
74
+
75
+ self::$_instances[ $identifier ] = new FS_Api( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox );
76
+ }
77
+
78
+ return self::$_instances[ $identifier ];
79
+ }
80
+
81
+ private static function _init() {
82
+ if ( isset( self::$_options ) ) {
83
+ return;
84
+ }
85
+
86
+ if ( ! class_exists( 'Freemius_Api' ) ) {
87
+ require_once( WP_FS__DIR_SDK . '/Freemius.php' );
88
+ }
89
+
90
+ self::$_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true );
91
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
92
+
93
+ self::$_clock_diff = self::$_options->get_option( 'api_clock_diff', 0 );
94
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
95
+
96
+ if ( self::$_options->get_option( 'api_force_http', false ) ) {
97
+ Freemius_Api::SetHttp();
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @param string $slug
103
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
104
+ * @param number $id Element's id.
105
+ * @param string $public_key Public key.
106
+ * @param bool|string $secret_key Element's secret key.
107
+ * @param bool $is_sandbox
108
+ */
109
+ private function __construct( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox ) {
110
+ $this->_api = new Freemius_Api( $scope, $id, $public_key, $secret_key, $is_sandbox );
111
+
112
+ $this->_slug = $slug;
113
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_api', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
114
+ }
115
+
116
+ /**
117
+ * Find clock diff between server and API server, and store the diff locally.
118
+ *
119
+ * @param bool|int $diff
120
+ *
121
+ * @return bool|int False if clock diff didn't change, otherwise returns the clock diff in seconds.
122
+ */
123
+ private function _sync_clock_diff( $diff = false ) {
124
+ $this->_logger->entrance();
125
+
126
+ // Sync clock and store.
127
+ $new_clock_diff = ( false === $diff ) ?
128
+ Freemius_Api::FindClockDiff() :
129
+ $diff;
130
+
131
+ if ( $new_clock_diff === self::$_clock_diff ) {
132
+ return false;
133
+ }
134
+
135
+ self::$_clock_diff = $new_clock_diff;
136
+
137
+ // Update API clock's diff.
138
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
139
+
140
+ // Store new clock diff in storage.
141
+ self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
142
+
143
+ return $new_clock_diff;
144
+ }
145
+
146
+ /**
147
+ * Override API call to enable retry with servers' clock auto sync method.
148
+ *
149
+ * @param string $path
150
+ * @param string $method
151
+ * @param array $params
152
+ * @param bool $retry Is in retry or first call attempt.
153
+ *
154
+ * @return array|mixed|string|void
155
+ */
156
+ private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
157
+ $this->_logger->entrance();
158
+
159
+ if ( self::is_temporary_down() ) {
160
+ $result = $this->get_temporary_unavailable_error();
161
+ } else {
162
+ $result = $this->_api->Api( $path, $method, $params );
163
+
164
+ if ( null !== $result &&
165
+ isset( $result->error ) &&
166
+ isset( $result->error->code ) &&
167
+ 'request_expired' === $result->error->code
168
+ ) {
169
+ if ( ! $retry ) {
170
+ $diff = isset( $result->error->timestamp ) ?
171
+ ( time() - strtotime( $result->error->timestamp ) ) :
172
+ false;
173
+
174
+ // Try to sync clock diff.
175
+ if ( false !== $this->_sync_clock_diff( $diff ) ) {
176
+ // Retry call with new synced clock.
177
+ return $this->_call( $path, $method, $params, true );
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ if ( null !== $result && isset( $result->error ) && isset( $result->error->message ) ) {
184
+ // Log API errors.
185
+ $this->_logger->error( $result->error->message );
186
+ }
187
+
188
+ return $result;
189
+ }
190
+
191
+ /**
192
+ * Override API call to wrap it in servers' clock sync method.
193
+ *
194
+ * @param string $path
195
+ * @param string $method
196
+ * @param array $params
197
+ *
198
+ * @return array|mixed|string|void
199
+ * @throws Freemius_Exception
200
+ */
201
+ function call( $path, $method = 'GET', $params = array() ) {
202
+ return $this->_call( $path, $method, $params );
203
+ }
204
+
205
+ /**
206
+ * Get API request URL signed via query string.
207
+ *
208
+ * @param string $path
209
+ *
210
+ * @return string
211
+ */
212
+ function get_signed_url( $path ) {
213
+ return $this->_api->GetSignedUrl( $path );
214
+ }
215
+
216
+ /**
217
+ * @param string $path
218
+ * @param bool $flush
219
+ * @param int $expiration (optional) Time until expiration in seconds from now, defaults to 24 hours
220
+ *
221
+ * @return stdClass|mixed
222
+ */
223
+ function get( $path = '/', $flush = false, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
224
+ $this->_logger->entrance();
225
+
226
+ $cache_key = $this->get_cache_key( $path );
227
+
228
+ // Always flush during development.
229
+ if ( WP_FS__DEV_MODE || $this->_api->IsSandbox() ) {
230
+ $flush = true;
231
+ }
232
+
233
+ $cached_result = self::$_cache->get( $cache_key );
234
+
235
+ if ( $flush || ! self::$_cache->has_valid( $cache_key ) ) {
236
+ $result = $this->call( $path );
237
+
238
+ if ( ! is_object( $result ) || isset( $result->error ) ) {
239
+ // Api returned an error.
240
+ if ( is_object( $cached_result ) &&
241
+ ! isset( $cached_result )
242
+ ) {
243
+ // If there was an error during a newer data fetch,
244
+ // fallback to older data version.
245
+ $result = $cached_result;
246
+ } else {
247
+ // If no older data version, return result without
248
+ // caching the error.
249
+ return $result;
250
+ }
251
+ }
252
+
253
+ self::$_cache->set( $cache_key, $result, $expiration );
254
+
255
+ $cached_result = $result;
256
+ }
257
+
258
+ return $cached_result;
259
+ }
260
+
261
+ private function get_cache_key( $path, $method = 'GET', $params = array() ) {
262
+ $canonized = $this->_api->CanonizePath( $path );
263
+ // $exploded = explode('/', $canonized);
264
+ // return $method . '_' . array_pop($exploded) . '_' . md5($canonized . json_encode($params));
265
+ return $method . ':' . $canonized . ( ! empty( $params ) ? '#' . md5( json_encode( $params ) ) : '' );
266
+ }
267
+
268
+ /**
269
+ * Test API connectivity.
270
+ *
271
+ * @author Vova Feldman (@svovaf)
272
+ * @since 1.0.9 If fails, try to fallback to HTTP.
273
+ * @since 1.1.6 Added a 5-min caching mechanism, to prevent from overloading the server if the API if
274
+ * temporary down.
275
+ *
276
+ * @return bool True if successful connectivity to the API.
277
+ */
278
+ static function test() {
279
+ self::_init();
280
+
281
+ $cache_key = 'ping_test';
282
+
283
+ $test = self::$_cache->get_valid( $cache_key, null );
284
+
285
+ if ( is_null( $test ) ) {
286
+ $test = Freemius_Api::Test();
287
+
288
+ if ( false === $test && Freemius_Api::IsHttps() ) {
289
+ // Fallback to HTTP, since HTTPS fails.
290
+ Freemius_Api::SetHttp();
291
+
292
+ self::$_options->set_option( 'api_force_http', true, true );
293
+
294
+ $test = Freemius_Api::Test();
295
+
296
+ if ( false === $test ) {
297
+ /**
298
+ * API connectivity test fail also in HTTP request, therefore,
299
+ * fallback to HTTPS to keep connection secure.
300
+ *
301
+ * @since 1.1.6
302
+ */
303
+ self::$_options->set_option( 'api_force_http', false, true );
304
+ }
305
+ }
306
+
307
+ self::$_cache->set( $cache_key, $test, WP_FS__TIME_5_MIN_IN_SEC );
308
+ }
309
+
310
+ return $test;
311
+ }
312
+
313
+ /**
314
+ * Check if API is temporary down.
315
+ *
316
+ * @author Vova Feldman (@svovaf)
317
+ * @since 1.1.6
318
+ *
319
+ * @return bool
320
+ */
321
+ static function is_temporary_down() {
322
+ self::_init();
323
+
324
+ $test = self::$_cache->get_valid( 'ping_test', null );
325
+
326
+ return ( false === $test );
327
+ }
328
+
329
+ /**
330
+ * @author Vova Feldman (@svovaf)
331
+ * @since 1.1.6
332
+ *
333
+ * @return object
334
+ */
335
+ private function get_temporary_unavailable_error() {
336
+ return (object) array(
337
+ 'error' => array(
338
+ 'type' => 'TemporaryUnavailable',
339
+ 'message' => 'API is temporary unavailable.',
340
+ 'code' => 'temporary_unavailable',
341
+ 'http' => 503
342
+ )
343
+ );
344
+ }
345
+
346
+ /**
347
+ * Ping API for connectivity test, and return result object.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.0.9
351
+ *
352
+ * @param null|string $unique_anonymous_id
353
+ * @param bool $is_update False if new plugin installation.
354
+ *
355
+ * @return object
356
+ */
357
+ function ping( $unique_anonymous_id = null, $is_update = false ) {
358
+ $this->_logger->entrance();
359
+
360
+ if ( self::is_temporary_down() ) {
361
+ return $this->get_temporary_unavailable_error();
362
+ }
363
+
364
+ $pong = is_null( $unique_anonymous_id ) ?
365
+ Freemius_Api::Ping() :
366
+ $this->_call( 'ping.json?' . http_build_query( array(
367
+ 'uid' => $unique_anonymous_id,
368
+ 'is_update' => $is_update,
369
+ ) ) );
370
+
371
+ if ( $this->is_valid_ping( $pong ) ) {
372
+ return $pong;
373
+ }
374
+
375
+ if ( self::should_try_with_http( $pong ) ) {
376
+ // Fallback to HTTP, since HTTPS fails.
377
+ Freemius_Api::SetHttp();
378
+
379
+ self::$_options->set_option( 'api_force_http', true, true );
380
+
381
+ $pong = is_null( $unique_anonymous_id ) ?
382
+ Freemius_Api::Ping() :
383
+ $this->_call( 'ping.json?' . http_build_query( array(
384
+ 'uid' => $unique_anonymous_id,
385
+ 'is_update' => $is_update,
386
+ ) ) );
387
+
388
+ if ( ! $this->is_valid_ping( $pong ) ) {
389
+ self::$_options->set_option( 'api_force_http', false, true );
390
+ }
391
+ }
392
+
393
+ return $pong;
394
+ }
395
+
396
+ /**
397
+ * Check if based on the API result we should try
398
+ * to re-run the same request with HTTP instead of HTTPS.
399
+ *
400
+ * @author Vova Feldman (@svovaf)
401
+ * @since 1.1.6
402
+ *
403
+ * @param $result
404
+ *
405
+ * @return bool
406
+ */
407
+ private static function should_try_with_http($result) {
408
+ if ( ! Freemius_Api::IsHttps() ) {
409
+ return false;
410
+ }
411
+
412
+ return ( ! is_object( $result ) ||
413
+ ! isset( $result->error ) ||
414
+ ! isset( $result->error->code ) ||
415
+ ! in_array( $result->error->code, array(
416
+ 'curl_missing',
417
+ 'cloudflare_ddos_protection',
418
+ 'squid_cache_block',
419
+ 'too_many_requests',
420
+ ) ) );
421
+
422
+ }
423
+
424
+ /**
425
+ * Check if valid ping request result.
426
+ *
427
+ * @author Vova Feldman (@svovaf)
428
+ * @since 1.1.1
429
+ *
430
+ * @param mixed $pong
431
+ *
432
+ * @return bool
433
+ */
434
+ function is_valid_ping( $pong ) {
435
+ return Freemius_Api::Test( $pong );
436
+ }
437
+
438
+ function get_url( $path = '' ) {
439
+ return Freemius_Api::GetUrl( $path, $this->_api->IsSandbox() );
440
+ }
441
+
442
+ /**
443
+ * Clear API cache.
444
+ *
445
+ * @author Vova Feldman (@svovaf)
446
+ * @since 1.0.9
447
+ */
448
+ static function clear_cache() {
449
+ self::_init();
450
+
451
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
452
+ self::$_cache->clear();
453
+ }
454
+ }
freemius/includes/class-fs-logger.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Logger {
14
+ private $_id;
15
+ private $_on = false;
16
+ private $_echo = false;
17
+ private $_file_start = 0;
18
+
19
+ private static $LOGGERS = array();
20
+ private static $LOG = array();
21
+ private static $CNT = 0;
22
+ private static $_HOOKED_FOOTER = false;
23
+
24
+ private function __construct( $id, $on = false, $echo = false ) {
25
+ $this->_id = $id;
26
+
27
+ $bt = debug_backtrace();
28
+ $caller = $bt[2];
29
+
30
+ $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
31
+
32
+ if ( $on ) {
33
+ $this->on();
34
+ }
35
+ if ( $echo ) {
36
+ $this->echo_on();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @param string $id
42
+ * @param bool $on
43
+ * @param bool $echo
44
+ *
45
+ * @return FS_Logger
46
+ */
47
+ public static function get_logger( $id, $on = false, $echo = false ) {
48
+ $id = strtolower( $id );
49
+
50
+ if ( ! isset( self::$LOGGERS[ $id ] ) ) {
51
+ self::$LOGGERS[ $id ] = new FS_Logger( $id, $on, $echo );
52
+ }
53
+
54
+ return self::$LOGGERS[ $id ];
55
+ }
56
+
57
+ private static function _hook_footer() {
58
+ if ( self::$_HOOKED_FOOTER ) {
59
+ return;
60
+ }
61
+
62
+ if ( is_admin() ) {
63
+ add_action( 'admin_footer', 'FS_Logger::dump', 100 );
64
+ } else {
65
+ add_action( 'wp_footer', 'FS_Logger::dump', 100 );
66
+ }
67
+ }
68
+
69
+ function is_on() {
70
+ return $this->_on;
71
+ }
72
+
73
+ function on() {
74
+ $this->_on = true;
75
+
76
+ self::_hook_footer();
77
+ }
78
+
79
+ function echo_on() {
80
+ $this->_on;
81
+
82
+ $this->_echo = true;
83
+ }
84
+
85
+ function is_echo_on() {
86
+ return $this->_echo;
87
+ }
88
+
89
+
90
+ private function _log( &$message, $type = 'log', $wrapper ) {
91
+ if ( ! $this->is_on() ) {
92
+ return;
93
+ }
94
+
95
+ $bt = debug_backtrace();
96
+ $depth = $wrapper ? 3 : 2;
97
+ while ( $depth < count( $bt ) - 1 && 'eval' === $bt[ $depth ]['function'] ) {
98
+ $depth ++;
99
+ }
100
+
101
+ $caller = $bt[ $depth ];
102
+
103
+ $log = array_merge( $caller, array(
104
+ 'cnt' => self::$CNT ++,
105
+ 'logger' => $this,
106
+ 'timestamp' => date( WP_FS__LOG_DATETIME_FORMAT . ':u' ),
107
+ 'type' => $type,
108
+ 'msg' => $message,
109
+ ) );
110
+
111
+ self::$LOG[] = $log;
112
+
113
+ if ( $this->is_echo_on() ) {
114
+ echo self::_format_html( $log ) . "\n";
115
+ }
116
+ }
117
+
118
+ function log( $message, $wrapper = false ) {
119
+ $this->_log( $message, 'log', $wrapper );
120
+ }
121
+
122
+ function info( $message, $wrapper = false ) {
123
+ $this->_log( $message, 'info', $wrapper );
124
+ }
125
+
126
+ function warn( $message, $wrapper = false ) {
127
+ $this->_log( $message, 'warn', $wrapper );
128
+ }
129
+
130
+ function error( $message, $wrapper = false ) {
131
+ $this->_log( $message, 'error', $wrapper );
132
+ }
133
+
134
+ function entrance( $message = '', $wrapper = false ) {
135
+ $msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;
136
+
137
+ $this->_log( $msg, 'log', $wrapper );
138
+ }
139
+
140
+ function departure( $message = '', $wrapper = false ) {
141
+ $msg = 'Departure' . ( empty( $message ) ? '' : ' > ' ) . $message;
142
+
143
+ $this->_log( $msg, 'log', $wrapper );
144
+ }
145
+
146
+ private static function _format( $log, $show_type = true ) {
147
+ return '[' . str_pad( $log['cnt'], strlen( self::$CNT ), '0', STR_PAD_LEFT ) . '] [' . $log['logger']->_id . '] ' . ( $show_type ? '[' . $log['type'] . ']' : '' ) . $log['function'] . ' >> ' . $log['msg'] . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ') ' : '' ) . ' [' . $log['timestamp'] . ']';
148
+ }
149
+
150
+ private static function _format_html( $log ) {
151
+ return '<div style="font-size: 11px; padding: 3px; background: #ccc; margin-bottom: 3px;">[' . $log['cnt'] . '] [' . $log['logger']->_id . '] [' . $log['type'] . '] <b><code style="color: blue;">' . $log['function'] . '</code> >> <b style="color: darkorange;">' . $log['msg'] . '</b></b>' . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ')' : '' ) . ' [' . $log['timestamp'] . ']</div>';
152
+ }
153
+
154
+ static function dump() {
155
+ ?>
156
+ <!-- BEGIN: Freemius PHP Console Log -->
157
+ <script type="text/javascript">
158
+ <?php
159
+ foreach (self::$LOG as $log)
160
+ {
161
+ echo 'console.' . $log['type'] . '(' . json_encode(self::_format($log, false)) . ')' . "\n";
162
+ }
163
+ ?>
164
+ </script>
165
+ <!-- END: Freemius PHP Console Log -->
166
+ <?php
167
+ }
168
+ }
freemius/includes/class-fs-plugin-updater.php ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ *
8
+ * @link https://github.com/easydigitaldownloads/EDD-License-handler/blob/master/EDD_SL_Plugin_Updater.php
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ // Uncomment this line for testing.
16
+ // set_site_transient( 'update_plugins', null );
17
+
18
+ class FS_Plugin_Updater {
19
+
20
+ /**
21
+ * @var Freemius
22
+ * @since 1.0.4
23
+ */
24
+ private $_fs;
25
+ /**
26
+ * @var FS_Logger
27
+ * @since 1.0.4
28
+ */
29
+ private $_logger;
30
+
31
+ function __construct( Freemius $freemius ) {
32
+ $this->_fs = $freemius;
33
+
34
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $freemius->get_slug() . '_updater', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
35
+
36
+ $this->_filters();
37
+ }
38
+
39
+ /**
40
+ * Initiate required filters.
41
+ *
42
+ * @author Vova Feldman (@svovaf)
43
+ * @since 1.0.4
44
+ */
45
+ private function _filters() {
46
+ // Override request for plugin information
47
+ add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
48
+
49
+ // WP 3.0+
50
+ add_filter( 'pre_set_site_transient_update_plugins', array(
51
+ &$this,
52
+ 'pre_set_site_transient_update_plugins_filter'
53
+ ) );
54
+
55
+ if ( ! $this->_fs->has_active_license() ) {
56
+ /**
57
+ * If user has the premium plugin's code but do NOT have an active license,
58
+ * encourage him to upgrade by showing that there's a new release, but instead
59
+ * of showing an update link, show upgrade link to the pricing page.
60
+ *
61
+ * @since 1.1.6
62
+ *
63
+ */
64
+ // WP 2.9+
65
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
66
+ &$this,
67
+ 'catch_plugin_update_row'
68
+ ), 9 );
69
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
70
+ &$this,
71
+ 'edit_and_echo_plugin_update_row'
72
+ ), 11, 2 );
73
+ }
74
+
75
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
76
+ add_filter( 'http_request_host_is_external', array(
77
+ $this,
78
+ 'http_request_host_is_external_filter'
79
+ ), 10, 3 );
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Capture plugin update row by turning output buffering.
85
+ *
86
+ * @author Vova Feldman (@svovaf)
87
+ * @since 1.1.6
88
+ */
89
+ function catch_plugin_update_row() {
90
+ ob_start();
91
+ }
92
+
93
+ /**
94
+ * Overrides default update message format with "renew your license" message.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.6
98
+ */
99
+ function edit_and_echo_plugin_update_row( $file, $plugin_data ) {
100
+ $plugin_update_row = ob_get_clean();
101
+
102
+ $current = get_site_transient( 'update_plugins' );
103
+ if ( ! isset( $current->response[ $file ] ) ) {
104
+ echo $plugin_update_row;
105
+
106
+ return false;
107
+ }
108
+
109
+ $r = $current->response[ $file ];
110
+
111
+ $plugin_update_row = preg_replace(
112
+ '/(\<div.+>)(.+)(\<a.+\<a.+)\<\/div\>/is',
113
+ '$1 $2 ' . sprintf(
114
+ __fs( 'renew-license-now' ),
115
+ '<a href="' . $this->_fs->pricing_url() . '">', '</a>',
116
+ $r->new_version ) .
117
+ '$4',
118
+ $plugin_update_row
119
+ );
120
+
121
+ echo $plugin_update_row;
122
+ }
123
+
124
+ /**
125
+ * Since WP version 3.6, a new security feature was added that denies access to repository with a local ip.
126
+ * During development mode we want to be able updating plugin versions via our localhost repository. This
127
+ * filter white-list all domains including "api.freemius".
128
+ *
129
+ * @link http://www.emanueletessore.com/wordpress-download-failed-valid-url-provided/
130
+ *
131
+ * @author Vova Feldman (@svovaf)
132
+ * @since 1.0.4
133
+ *
134
+ * @param bool $allow
135
+ * @param string $host
136
+ * @param string $url
137
+ *
138
+ * @return bool
139
+ */
140
+ function http_request_host_is_external_filter( $allow, $host, $url ) {
141
+ return ( false !== strpos( $host, 'freemius' ) ) ? true : $allow;
142
+ }
143
+
144
+ /**
145
+ * Check for Updates at the defined API endpoint and modify the update array.
146
+ *
147
+ * This function dives into the update api just when WordPress creates its update array,
148
+ * then adds a custom API call and injects the custom plugin data retrieved from the API.
149
+ * It is reassembled from parts of the native WordPress plugin update code.
150
+ * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
151
+ *
152
+ * @author Vova Feldman (@svovaf)
153
+ * @since 1.0.4
154
+ *
155
+ * @uses FS_Api
156
+ *
157
+ * @param stdClass $transient_data Update array build by WordPress.
158
+ *
159
+ * @return array Modified update array with custom plugin data.
160
+ */
161
+ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
162
+ $this->_logger->entrance();
163
+
164
+ if ( empty( $transient_data ) ||
165
+ defined( 'WP_FS__UNINSTALL_MODE' )
166
+ ) {
167
+ return $transient_data;
168
+ }
169
+
170
+ // Get plugin's newest update.
171
+ $new_version = $this->_fs->get_update();
172
+
173
+ if ( is_object( $new_version ) ) {
174
+ $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
175
+
176
+ $plugin_details = new stdClass();
177
+ $plugin_details->slug = $this->_fs->get_slug();
178
+ $plugin_details->new_version = $new_version->version;
179
+ $plugin_details->url = WP_FS__ADDRESS;
180
+ $plugin_details->package = $new_version->url;
181
+ $plugin_details->plugin = $this->_fs->get_plugin_basename();
182
+
183
+ // Add plugin to transient data.
184
+ $transient_data->response[ $this->_fs->get_plugin_basename() ] = $plugin_details;
185
+ }
186
+
187
+ return $transient_data;
188
+ }
189
+
190
+ /**
191
+ * Try to fetch plugin's info from .org repository.
192
+ *
193
+ * @author Vova Feldman (@svovaf)
194
+ * @since 1.0.5
195
+ *
196
+ * @param string $action
197
+ * @param array $args
198
+ *
199
+ * @return bool|mixed
200
+ */
201
+ private function _fetch_plugin_info_from_repository( $action, $args ) {
202
+ $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
203
+ if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
204
+ $url = set_url_scheme( $url, 'https' );
205
+ }
206
+
207
+ $args = array(
208
+ 'timeout' => 15,
209
+ 'body' => array(
210
+ 'action' => $action,
211
+ 'request' => serialize( $args )
212
+ )
213
+ );
214
+
215
+ $request = wp_remote_post( $url, $args );
216
+
217
+ if ( is_wp_error( $request ) ) {
218
+ return false;
219
+ }
220
+
221
+ $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
222
+
223
+ if ( ! is_object( $res ) && ! is_array( $res ) ) {
224
+ return false;
225
+ }
226
+
227
+ return $res;
228
+ }
229
+
230
+ /**
231
+ * Updates information on the "View version x.x details" page with custom data.
232
+ *
233
+ * @author Vova Feldman (@svovaf)
234
+ * @since 1.0.4
235
+ *
236
+ * @uses FS_Api
237
+ *
238
+ * @param object $data
239
+ * @param string $action
240
+ * @param mixed $args
241
+ *
242
+ * @return object
243
+ */
244
+ function plugins_api_filter( $data, $action = '', $args = null ) {
245
+ $this->_logger->entrance();
246
+
247
+ if ( ( 'plugin_information' !== $action ) ||
248
+ ! isset( $args->slug )
249
+ ) {
250
+ return $data;
251
+ }
252
+
253
+ $addon = false;
254
+ $is_addon = false;
255
+
256
+ if ( $this->_fs->get_slug() !== $args->slug ) {
257
+ $addon = $this->_fs->get_addon_by_slug( $args->slug );
258
+
259
+ if ( ! is_object( $addon ) ) {
260
+ return $data;
261
+ }
262
+
263
+ $is_addon = true;
264
+ }
265
+
266
+ $plugin_in_repo = false;
267
+ if ( ! $is_addon ) {
268
+ // Try to fetch info from .org repository.
269
+ $data = $this->_fetch_plugin_info_from_repository( $action, $args );
270
+
271
+ $plugin_in_repo = ( false !== $data );
272
+ }
273
+
274
+ if ( ! $plugin_in_repo ) {
275
+ $data = $args;
276
+
277
+ // Fetch as much as possible info from local files.
278
+ $plugin_local_data = $this->_fs->get_plugin_data();
279
+ $data->name = $plugin_local_data['Name'];
280
+ $data->author = $plugin_local_data['Author'];
281
+ $data->sections = array(
282
+ 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
283
+ );
284
+
285
+ // @todo Store extra plugin info on Freemius or parse readme.txt markup.
286
+ /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
287
+
288
+ if ( !isset($info->error) ) {
289
+ $data = $info;
290
+ }*/
291
+ }
292
+
293
+ // Get plugin's newest update.
294
+ $new_version = $this->_fs->_fetch_latest_version( $is_addon ? $addon->id : false );
295
+
296
+ if ( $is_addon ) {
297
+ $data->name = $addon->title . ' ' . __fs( 'addon', $this->_fs->get_slug() );
298
+ $data->slug = $addon->slug;
299
+ $data->url = WP_FS__ADDRESS;
300
+ $data->package = $new_version->url;
301
+ }
302
+
303
+ if ( ! $plugin_in_repo ) {
304
+ $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
305
+ $data->requires = $new_version->requires_platform_version;
306
+ $data->tested = $new_version->tested_up_to_version;
307
+ }
308
+
309
+ $data->version = $new_version->version;
310
+ $data->download_link = $new_version->url;
311
+
312
+ return $data;
313
+ }
314
+ }
freemius/includes/class-fs-security.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SECURITY_PARAMS_PREFIX', 's_' );
14
+
15
+ class FS_Security {
16
+ /**
17
+ * @var FS_Security
18
+ * @since 1.0.3
19
+ */
20
+ private static $_instance;
21
+ /**
22
+ * @var FS_Logger
23
+ * @since 1.0.3
24
+ */
25
+ private static $_logger;
26
+
27
+ public static function instance() {
28
+ if ( ! isset( self::$_instance ) ) {
29
+ self::$_instance = new FS_Security();
30
+ self::$_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
31
+ }
32
+
33
+ return self::$_instance;
34
+ }
35
+
36
+ private function __construct() {
37
+ }
38
+
39
+ function get_secure_token( FS_Scope_Entity $entity, $timestamp, $action = '' ) {
40
+ return md5(
41
+ $timestamp .
42
+ $entity->id .
43
+ $entity->secret_key .
44
+ $entity->public_key .
45
+ $action
46
+ );
47
+ }
48
+
49
+ function get_context_params( FS_Scope_Entity $entity, $timestamp = false, $action = '' ) {
50
+ if ( false === $timestamp ) {
51
+ $timestamp = time();
52
+ }
53
+
54
+ return array(
55
+ 's_ctx_type' => $entity->get_type(),
56
+ 's_ctx_id' => $entity->id,
57
+ 's_ctx_ts' => $timestamp,
58
+ 's_ctx_secure' => $this->get_secure_token( $entity, $timestamp, $action ),
59
+ );
60
+ }
61
+ }
freemius/includes/entities/class-fs-entity.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Get object's public variables.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.0.0
18
+ *
19
+ * @param object $object
20
+ *
21
+ * @return array
22
+ */
23
+ function fs_get_object_public_vars( $object ) {
24
+ return get_object_vars( $object );
25
+ }
26
+
27
+ class FS_Entity {
28
+ /**
29
+ * @var number
30
+ */
31
+ public $id;
32
+ /**
33
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
34
+ */
35
+ public $updated;
36
+ /**
37
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
38
+ */
39
+ public $created;
40
+
41
+ /**
42
+ * @param bool|stdClass $entity
43
+ */
44
+ function __construct( $entity = false ) {
45
+ if ( ! ( $entity instanceof stdClass ) ) {
46
+ return;
47
+ }
48
+
49
+ $props = fs_get_object_public_vars( $this );
50
+
51
+ foreach ( $props as $key => $def_value ) {
52
+ $this->{$key} = isset( $entity->{$key} ) ?
53
+ $entity->{$key} :
54
+ $def_value;
55
+ }
56
+ }
57
+
58
+ static function get_type() {
59
+ return 'type';
60
+ }
61
+
62
+ /**
63
+ * @author Vova Feldman (@svovaf)
64
+ * @since 1.0.6
65
+ *
66
+ * @param FS_Entity $entity1
67
+ * @param FS_Entity $entity2
68
+ *
69
+ * @return bool
70
+ */
71
+ static function equals( $entity1, $entity2 ) {
72
+ if ( is_null( $entity1 ) && is_null( $entity2 ) ) {
73
+ return true;
74
+ } else if ( is_object( $entity1 ) && is_object( $entity2 ) ) {
75
+ return ( $entity1->id == $entity2->id );
76
+ } else if ( is_object( $entity1 ) ) {
77
+ return is_null( $entity1->id );
78
+ } else {
79
+ return is_null( $entity2->id );
80
+ }
81
+ }
82
+
83
+ private $_is_updated = false;
84
+
85
+ /**
86
+ * Update object property.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.9
90
+ *
91
+ * @param string|array[string]mixed $key
92
+ * @param string|bool $val
93
+ *
94
+ * @return bool
95
+ */
96
+ function update( $key, $val = false ) {
97
+ if ( ! is_array( $key ) ) {
98
+ $key = array( $key => $val );
99
+ }
100
+
101
+ $is_updated = false;
102
+
103
+ foreach ( $key as $k => $v ) {
104
+ if ( $this->{$k} === $v ) {
105
+ continue;
106
+ }
107
+
108
+ if ( ( is_string( $this->{$k} ) && is_numeric( $v ) ||
109
+ ( is_numeric( $this->{$k} ) && is_string( $v ) ) ) &&
110
+ $this->{$k} == $v
111
+ ) {
112
+ continue;
113
+ }
114
+
115
+ // Update value.
116
+ $this->{$k} = $v;
117
+
118
+ $is_updated = true;
119
+ }
120
+
121
+ $this->_is_updated = $is_updated;
122
+
123
+ return $is_updated;
124
+ }
125
+
126
+ /**
127
+ * Checks if entity was updated.
128
+ *
129
+ * @author Vova Feldman (@svovaf)
130
+ * @since 1.0.9
131
+ *
132
+ * @return bool
133
+ */
134
+ function is_updated() {
135
+ return $this->_is_updated;
136
+ }
137
+
138
+ /**
139
+ * @param $id
140
+ *
141
+ * @author Vova Feldman (@svovaf)
142
+ * @since 1.1.2
143
+ *
144
+ * @return bool
145
+ */
146
+ static function is_valid_id($id){
147
+ return is_numeric($id);
148
+ }
149
+ }
freemius/includes/entities/class-fs-plugin-info.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Info extends FS_Entity {
14
+ public $plugin_id;
15
+ public $description;
16
+ public $short_description;
17
+ public $banner_url;
18
+ public $card_banner_url;
19
+ public $selling_point_0;
20
+ public $selling_point_1;
21
+ public $selling_point_2;
22
+ public $screenshots;
23
+
24
+ /**
25
+ * @param stdClass|bool $plugin_info
26
+ */
27
+ function __construct( $plugin_info = false ) {
28
+ parent::__construct( $plugin_info );
29
+ }
30
+
31
+ static function get_type() {
32
+ return 'plugin';
33
+ }
34
+ }
freemius/includes/entities/class-fs-plugin-license.php ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_License extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $user_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $pricing_id;
33
+ /**
34
+ * @var int
35
+ */
36
+ public $quota;
37
+ /**
38
+ * @var int
39
+ */
40
+ public $activated;
41
+ /**
42
+ * @var int
43
+ */
44
+ public $activated_local;
45
+ /**
46
+ * @var string
47
+ */
48
+ public $expiration;
49
+ /**
50
+ * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
51
+ * license.
52
+ */
53
+ public $is_free_localhost;
54
+ /**
55
+ * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
56
+ * block updates and support.
57
+ */
58
+ public $is_block_features;
59
+ /**
60
+ * @var bool
61
+ */
62
+ public $is_cancelled;
63
+
64
+ #endregion Properties
65
+
66
+ /**
67
+ * @param stdClass|bool $license
68
+ */
69
+ function __construct( $license = false ) {
70
+ parent::__construct( $license );
71
+ }
72
+
73
+ static function get_type() {
74
+ return 'license';
75
+ }
76
+
77
+ /**
78
+ * Check how many site activations left.
79
+ *
80
+ * @author Vova Feldman (@svovaf)
81
+ * @since 1.0.5
82
+ *
83
+ * @return int
84
+ */
85
+ function left() {
86
+ if ( $this->is_expired() ) {
87
+ return 0;
88
+ }
89
+
90
+ return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
91
+ }
92
+
93
+ /**
94
+ * @author Vova Feldman (@svovaf)
95
+ * @since 1.0.5
96
+ *
97
+ * @return bool
98
+ */
99
+ function is_expired() {
100
+ return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
101
+ }
102
+
103
+ /**
104
+ * @author Vova Feldman (@svovaf)
105
+ * @since 1.0.6
106
+ *
107
+ * @return bool
108
+ */
109
+ function is_lifetime() {
110
+ return is_null( $this->expiration );
111
+ }
112
+
113
+ /**
114
+ * Check if license is fully utilized.
115
+ *
116
+ * @author Vova Feldman (@svovaf)
117
+ * @since 1.0.6
118
+ *
119
+ * @param bool $is_localhost
120
+ *
121
+ * @return bool
122
+ */
123
+ function is_utilized( $is_localhost = null ) {
124
+ if ( is_null( $is_localhost ) ) {
125
+ $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
126
+ }
127
+
128
+ return ! ( $this->is_free_localhost && $is_localhost ) &&
129
+ ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
130
+ }
131
+
132
+ /**
133
+ * Check if license's plan features are enabled.
134
+ *
135
+ * - Either if plan not expired
136
+ * - If expired, based on the configuration to block features or not.
137
+ *
138
+ * @author Vova Feldman (@svovaf)
139
+ * @since 1.0.6
140
+ *
141
+ * @return bool
142
+ */
143
+ function is_features_enabled() {
144
+ return ( ! $this->is_block_features || ! $this->is_expired() );
145
+ }
146
+
147
+ /**
148
+ * Subscription considered to be new without any payments
149
+ * if the license expires in less than 24 hours
150
+ * from the license creation.
151
+ *
152
+ * @author Vova Feldman (@svovaf)
153
+ * @since 1.0.9
154
+ *
155
+ * @return bool
156
+ */
157
+ function is_first_payment_pending() {
158
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
159
+ }
160
+ }
freemius/includes/entities/class-fs-plugin-plan.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Plan extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ public $title;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $name;
25
+ /**
26
+ * @var int Trial days.
27
+ */
28
+ public $trial_period;
29
+ /**
30
+ * @var string If true, require payment for trial.
31
+ */
32
+ public $is_require_subscription;
33
+
34
+ #endregion Properties
35
+
36
+ /**
37
+ * @param object|bool $plan
38
+ */
39
+ function __construct( $plan = false ) {
40
+ parent::__construct( $plan );
41
+
42
+ if ( is_object( $plan ) ) {
43
+ $this->name = strtolower( $plan->name );
44
+ }
45
+ }
46
+
47
+ static function get_type() {
48
+ return 'plan';
49
+ }
50
+
51
+ /**
52
+ * @author Vova Feldman (@svovaf)
53
+ * @since 1.0.9
54
+ *
55
+ * @return bool
56
+ */
57
+ function is_free() {
58
+ return ( 'free' === $this->name );
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.0.9
64
+ *
65
+ * @return bool
66
+ */
67
+ function has_trial() {
68
+ return ! $this->is_free() &&
69
+ is_numeric( $this->trial_period ) && ( $this->trial_period > 0 );
70
+ }
71
+ }
freemius/includes/entities/class-fs-plugin-tag.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Tag extends FS_Entity {
14
+ public $version;
15
+ public $url;
16
+
17
+ function __construct( $tag = false ) {
18
+ parent::__construct( $tag );
19
+ }
20
+
21
+ static function get_type() {
22
+ return 'tag';
23
+ }
24
+ }
freemius/includes/entities/class-fs-plugin.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin extends FS_Scope_Entity {
14
+ /**
15
+ * @since 1.0.6
16
+ * @var null|number
17
+ */
18
+ public $parent_plugin_id;
19
+ /**
20
+ * @var string
21
+ */
22
+ public $title;
23
+ /**
24
+ * @var string
25
+ */
26
+ public $slug;
27
+
28
+ #region Install Specific Properties
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ public $file;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $version;
38
+ /**
39
+ * @var bool
40
+ */
41
+ public $auto_update;
42
+ /**
43
+ * @var FS_Plugin_Info
44
+ */
45
+ public $info;
46
+ /**
47
+ * @since 1.0.9
48
+ *
49
+ * @var bool
50
+ */
51
+ public $is_premium;
52
+ /**
53
+ * @since 1.0.9
54
+ *
55
+ * @var bool
56
+ */
57
+ public $is_live;
58
+
59
+ #endregion Install Specific Properties
60
+
61
+ /**
62
+ * @param stdClass|bool $plugin
63
+ */
64
+ function __construct( $plugin = false ) {
65
+ parent::__construct( $plugin );
66
+
67
+ $this->is_premium = false;
68
+ $this->is_live = true;
69
+
70
+ if ( isset( $plugin->info ) && is_object( $plugin->info ) ) {
71
+ $this->info = new FS_Plugin_Info( $plugin->info );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Check if plugin is an add-on (has parent).
77
+ *
78
+ * @author Vova Feldman (@svovaf)
79
+ * @since 1.0.6
80
+ *
81
+ * @return bool
82
+ */
83
+ function is_addon() {
84
+ return isset( $this->parent_plugin_id ) && is_numeric( $this->parent_plugin_id );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'plugin';
89
+ }
90
+ }
freemius/includes/entities/class-fs-scope-entity.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Scope_Entity extends FS_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $public_key;
18
+ /**
19
+ * @var string
20
+ */
21
+ public $secret_key;
22
+
23
+ /**
24
+ * @param bool|stdClass $scope_entity
25
+ */
26
+ function __construct( $scope_entity = false ) {
27
+ parent::__construct( $scope_entity );
28
+ }
29
+ }
freemius/includes/entities/class-fs-site.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Site extends FS_Scope_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $slug;
18
+ /**
19
+ * @var number
20
+ */
21
+ public $user_id;
22
+ /**
23
+ * @var string
24
+ */
25
+ public $title;
26
+ /**
27
+ * @var string
28
+ */
29
+ public $url;
30
+ /**
31
+ * @var string
32
+ */
33
+ public $version;
34
+ /**
35
+ * @var string E.g. en-GB
36
+ */
37
+ public $language;
38
+ /**
39
+ * @var string E.g. UTF-8
40
+ */
41
+ public $charset;
42
+ /**
43
+ * @var string Platform version (e.g WordPress version).
44
+ */
45
+ public $platform_version;
46
+ /**
47
+ * @var string Programming language version (e.g PHP version).
48
+ */
49
+ public $programming_language_version;
50
+ /**
51
+ * @var FS_Plugin_Plan $plan
52
+ */
53
+ public $plan;
54
+ /**
55
+ * @var number|null
56
+ */
57
+ public $license_id;
58
+ /**
59
+ * @var number|null
60
+ */
61
+ public $trial_plan_id;
62
+ /**
63
+ * @var string|null
64
+ */
65
+ public $trial_ends;
66
+ /**
67
+ * @since 1.0.9
68
+ *
69
+ * @var bool
70
+ */
71
+ public $is_premium = false;
72
+
73
+ /**
74
+ * @param stdClass|bool $site
75
+ */
76
+ function __construct( $site = false ) {
77
+ $this->plan = new FS_Plugin_Plan();
78
+
79
+ parent::__construct( $site );
80
+
81
+ if ( is_object( $site ) ) {
82
+ $this->plan->id = $site->plan_id;
83
+ }
84
+ }
85
+
86
+ static function get_type() {
87
+ return 'install';
88
+ }
89
+
90
+ function is_localhost() {
91
+ // The server has no way to verify if localhost unless localhost appears in domain.
92
+ return WP_FS__IS_LOCALHOST_FOR_SERVER;
93
+ // return (substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1');
94
+ }
95
+
96
+ /**
97
+ * Check if site in trial.
98
+ *
99
+ * @author Vova Feldman (@svovaf)
100
+ * @since 1.0.9
101
+ *
102
+ * @return bool
103
+ */
104
+ function is_trial() {
105
+ return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME );
106
+ }
107
+
108
+ /**
109
+ * Check if user already utilized the trial with the current install.
110
+ *
111
+ * @author Vova Feldman (@svovaf)
112
+ * @since 1.0.9
113
+ *
114
+ * @return bool
115
+ */
116
+ function is_trial_utilized() {
117
+ return is_numeric( $this->trial_plan_id );
118
+ }
119
+ }
freemius/includes/entities/class-fs-subscription.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.9
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Subscription extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $user_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $install_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $license_id;
33
+ /**
34
+ * @var float
35
+ */
36
+ public $total_gross;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $amount_per_cycle;
41
+ /**
42
+ * @var int # of months
43
+ */
44
+ public $billing_cycle;
45
+ /**
46
+ * @var float
47
+ */
48
+ public $outstanding_balance;
49
+ /**
50
+ * @var int
51
+ */
52
+ public $failed_payments;
53
+ /**
54
+ * @var string
55
+ */
56
+ public $gateway;
57
+ /**
58
+ * @var string
59
+ */
60
+ public $external_id;
61
+ /**
62
+ * @var string|null
63
+ */
64
+ public $trial_ends;
65
+ /**
66
+ * @var string|null Datetime of the next payment, or null if cancelled
67
+ */
68
+ public $next_payment;
69
+ /**
70
+ * @var string|null
71
+ */
72
+ public $vat_id;
73
+ /**
74
+ * @var string Two characters country code
75
+ */
76
+ public $country_code;
77
+
78
+ #endregion Properties
79
+
80
+ /**
81
+ * @param object|bool $subscription
82
+ */
83
+ function __construct( $subscription = false ) {
84
+ parent::__construct( $subscription );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'subscription';
89
+ }
90
+
91
+ /**
92
+ * Check if subscription is active.
93
+ *
94
+ * @author Vova Feldman (@svovaf)
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ function is_active() {
100
+ return ! empty( $this->next_payment ) &&
101
+ ( strtotime( $this->next_payment ) > WP_FS__SCRIPT_START_TIME );
102
+ }
103
+
104
+ /**
105
+ * Subscription considered to be new without any payments
106
+ * if the next payment should be made within less than 24 hours
107
+ * from the subscription creation.
108
+ *
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.9
111
+ *
112
+ * @return bool
113
+ */
114
+ function is_first_payment_pending() {
115
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->next_payment ) - strtotime( $this->created ) );
116
+ }
117
+ }
freemius/includes/entities/class-fs-user.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_User extends FS_Scope_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ public $email;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $first;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $last;
29
+ /**
30
+ * @var bool
31
+ */
32
+ public $is_verified;
33
+ /**
34
+ * @var string|null
35
+ */
36
+ public $customer_id;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $gross;
41
+
42
+ #endregion Properties
43
+
44
+ /**
45
+ * @param object|bool $user
46
+ */
47
+ function __construct( $user = false ) {
48
+ parent::__construct( $user );
49
+ }
50
+
51
+ function get_name() {
52
+ return trim( ucfirst( trim( is_string( $this->first ) ? $this->first : '' ) ) . ' ' . ucfirst( trim( is_string( $this->last ) ? $this->last : '' ) ) );
53
+ }
54
+
55
+ function is_verified() {
56
+ return ( isset( $this->is_verified ) && true === $this->is_verified );
57
+ }
58
+
59
+ static function get_type() {
60
+ return 'user';
61
+ }
62
+ }
freemius/includes/fs-core-functions.php ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ global $fs_core_logger;
14
+
15
+ $fs_core_logger = FS_Logger::get_logger( WP_FS__SLUG . '_core', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
16
+
17
+ function fs_dummy() {
18
+ }
19
+
20
+ /* Url.
21
+ --------------------------------------------------------------------------------------------*/
22
+ function fs_get_url_daily_cache_killer() {
23
+ return date( '\YY\Mm\Dd' );
24
+ }
25
+
26
+ /* Templates / Views.
27
+ --------------------------------------------------------------------------------------------*/
28
+ function fs_get_template_path( $path ) {
29
+ return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
30
+ }
31
+
32
+ function fs_include_template( $path, &$params = null ) {
33
+ $VARS = &$params;
34
+ include( fs_get_template_path( $path ) );
35
+ }
36
+
37
+ function fs_include_once_template( $path, &$params = null ) {
38
+ $VARS = &$params;
39
+ include_once( fs_get_template_path( $path ) );
40
+ }
41
+
42
+ function fs_require_template( $path, &$params = null ) {
43
+ $VARS = &$params;
44
+ require( fs_get_template_path( $path ) );
45
+ }
46
+
47
+ function fs_require_once_template( $path, &$params = null ) {
48
+ $VARS = &$params;
49
+ require_once( fs_get_template_path( $path ) );
50
+ }
51
+
52
+ function fs_get_template( $path, &$params = null ) {
53
+ ob_start();
54
+
55
+ $VARS = &$params;
56
+ require_once( fs_get_template_path( $path ) );
57
+
58
+ return ob_get_clean();
59
+ }
60
+
61
+ /* Scripts and styles including.
62
+ --------------------------------------------------------------------------------------------*/
63
+ function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
64
+ global $fs_core_logger;
65
+ if ( $fs_core_logger->is_on() ) {
66
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
67
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_CSS . trim( $path, '/' ) ) );
68
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ) );
69
+ }
70
+
71
+ wp_enqueue_style( $handle, plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $media );
72
+ }
73
+
74
+ function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
75
+ global $fs_core_logger;
76
+ if ( $fs_core_logger->is_on() ) {
77
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
78
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_JS . trim( $path, '/' ) ) );
79
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ) );
80
+ }
81
+
82
+ wp_enqueue_script( $handle, plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $in_footer );
83
+ }
84
+
85
+ function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
86
+ return plugins_url( plugin_basename( $img_dir . '/' . trim( $path, '/' ) ) );
87
+ }
88
+
89
+ /* Request handlers.
90
+ --------------------------------------------------------------------------------------------*/
91
+ /**
92
+ * @param string $key
93
+ * @param mixed $def
94
+ *
95
+ * @return mixed
96
+ */
97
+ function fs_request_get( $key, $def = false ) {
98
+ return isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
99
+ }
100
+
101
+ function fs_request_has( $key ) {
102
+ return isset( $_REQUEST[ $key ] );
103
+ }
104
+
105
+ function fs_request_get_bool( $key, $def = false ) {
106
+ return ( isset( $_REQUEST[ $key ] ) && ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) ) ? true : $def;
107
+ }
108
+
109
+ function fs_request_is_post() {
110
+ return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
111
+ }
112
+
113
+ function fs_request_is_get() {
114
+ return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
115
+ }
116
+
117
+ function fs_get_action( $action_key = 'action' ) {
118
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
119
+ return strtolower( $_REQUEST[ $action_key ] );
120
+ }
121
+
122
+ if ( 'action' == $action_key ) {
123
+ $action_key = 'fs_action';
124
+
125
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
126
+ return strtolower( $_REQUEST[ $action_key ] );
127
+ }
128
+ }
129
+
130
+ return false;
131
+ }
132
+
133
+ function fs_request_is_action( $action, $action_key = 'action' ) {
134
+ return ( strtolower( $action ) === fs_get_action( $action_key ) );
135
+ }
136
+
137
+ function fs_is_plugin_page( $menu_slug ) {
138
+ return ( is_admin() && $_REQUEST['page'] === $menu_slug );
139
+ }
140
+
141
+ /* Core UI.
142
+ --------------------------------------------------------------------------------------------*/
143
+ function fs_ui_action_button( $slug, $page, $action, $title, $params = array(), $is_primary = true ) {
144
+ ?><a class="button<?php if ( $is_primary ) {
145
+ echo ' button-primary';
146
+ } ?>"
147
+ href="<?php echo wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
148
+ }
149
+
150
+ function fs_ui_action_link( $slug, $page, $action, $title, $params = array() ) {
151
+ ?><a class=""
152
+ href="<?php echo wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
153
+ }
154
+
155
+ /*function fs_error_handler($errno, $errstr, $errfile, $errline)
156
+ {
157
+ if (false === strpos($errfile, 'freemius/'))
158
+ {
159
+ // @todo Dump Freemius errors to local log.
160
+ }
161
+
162
+ // switch ($errno) {
163
+ // case E_USER_ERROR:
164
+ // break;
165
+ // case E_WARNING:
166
+ // case E_USER_WARNING:
167
+ // break;
168
+ // case E_NOTICE:
169
+ // case E_USER_NOTICE:
170
+ // break;
171
+ // default:
172
+ // break;
173
+ // }
174
+ }
175
+
176
+ set_error_handler('fs_error_handler');*/
177
+
178
+ function fs_nonce_url( $actionurl, $action = - 1, $name = '_wpnonce' ) {
179
+ // $actionurl = str_replace( '&amp;', '&', $actionurl );
180
+ return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
181
+ }
182
+
183
+ /**
184
+ * Check if string starts with.
185
+ *
186
+ * @author Vova Feldman (@svovaf)
187
+ * @since 1.1.3
188
+ *
189
+ * @param string $haystack
190
+ * @param string $needle
191
+ *
192
+ * @return bool
193
+ */
194
+ function fs_starts_with( $haystack, $needle ) {
195
+ $length = strlen( $needle );
196
+
197
+ return ( substr( $haystack, 0, $length ) === $needle );
198
+ }
199
+
200
+ #region Url Canonization ------------------------------------------------------------------
201
+
202
+ /**
203
+ * @author Vova Feldman (@svovaf)
204
+ * @since 1.1.3
205
+ *
206
+ * @param string $url
207
+ * @param bool $omit_host
208
+ * @param array $ignore_params
209
+ *
210
+ * @return string
211
+ */
212
+ function fs_canonize_url( $url, $omit_host = false, $ignore_params = array() ) {
213
+ $parsed_url = parse_url( strtolower( $url ) );
214
+
215
+ // if ( ! isset( $parsed_url['host'] ) ) {
216
+ // return $url;
217
+ // }
218
+
219
+ $canonical = ( ( $omit_host || ! isset( $parsed_url['host'] ) ) ? '' : $parsed_url['host'] ) . $parsed_url['path'];
220
+
221
+ if ( isset( $parsed_url['query'] ) ) {
222
+ parse_str( $parsed_url['query'], $queryString );
223
+ $canonical .= '?' . fs_canonize_query_string( $queryString, $ignore_params );
224
+ }
225
+
226
+ return $canonical;
227
+ }
228
+
229
+ /**
230
+ * @author Vova Feldman (@svovaf)
231
+ * @since 1.1.3
232
+ *
233
+ * @param array $params
234
+ * @param array $ignore_params
235
+ * @param bool $params_prefix
236
+ *
237
+ * @return string
238
+ */
239
+ function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) {
240
+ if ( ! is_array( $params ) || 0 === count( $params ) ) {
241
+ return '';
242
+ }
243
+
244
+ // Urlencode both keys and values
245
+ $keys = fs_urlencode_rfc3986( array_keys( $params ) );
246
+ $values = fs_urlencode_rfc3986( array_values( $params ) );
247
+ $params = array_combine( $keys, $values );
248
+
249
+ // Parameters are sorted by name, using lexicographical byte value ordering.
250
+ // Ref: Spec: 9.1.1 (1)
251
+ uksort( $params, 'strcmp' );
252
+
253
+ $pairs = array();
254
+ foreach ( $params as $parameter => $value ) {
255
+ $lower_param = strtolower( $parameter );
256
+
257
+ // Skip ignore params.
258
+ if ( in_array( $lower_param, $ignore_params ) || ( false !== $params_prefix && startsWith( $lower_param, $params_prefix ) ) ) {
259
+ continue;
260
+ }
261
+
262
+ if ( is_array( $value ) ) {
263
+ // If two or more parameters share the same name, they are sorted by their value
264
+ // Ref: Spec: 9.1.1 (1)
265
+ natsort( $value );
266
+ foreach ( $value as $duplicate_value ) {
267
+ $pairs[] = $lower_param . '=' . $duplicate_value;
268
+ }
269
+ } else {
270
+ $pairs[] = $lower_param . '=' . $value;
271
+ }
272
+ }
273
+
274
+ if ( 0 === count( $pairs ) ) {
275
+ return '';
276
+ }
277
+
278
+ return implode( "&", $pairs );
279
+ }
280
+
281
+ /**
282
+ * @author Vova Feldman (@svovaf)
283
+ * @since 1.1.3
284
+ *
285
+ * @param string|string[] $input
286
+ *
287
+ * @return array|mixed|string
288
+ */
289
+ function fs_urlencode_rfc3986( $input ) {
290
+ if ( is_array( $input ) ) {
291
+ return array_map( 'fs_urlencode_rfc3986', $input );
292
+ } else if ( is_scalar( $input ) ) {
293
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) );
294
+ }
295
+
296
+ return '';
297
+ }
298
+
299
+ #endregion Url Canonization ------------------------------------------------------------------
300
+
301
+ function fs_download_image( $from, $to ) {
302
+ $ch = curl_init( $from );
303
+ $fp = fopen( fs_normalize_path( $to ), 'wb' );
304
+ curl_setopt( $ch, CURLOPT_FILE, $fp );
305
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
306
+ curl_exec( $ch );
307
+ curl_close( $ch );
308
+ fclose( $fp );
309
+ }
310
+
311
+ /* General Utilities
312
+ --------------------------------------------------------------------------------------------*/
313
+
314
+ /**
315
+ * Sorts an array by the value of the priority key.
316
+ *
317
+ * @author Daniel Iser (@danieliser)
318
+ * @since 1.1.7
319
+ *
320
+ * @param $a
321
+ * @param $b
322
+ *
323
+ * @return int
324
+ */
325
+ function fs_sort_by_priority( $a, $b ) {
326
+
327
+ // If b has a priority and a does not, b wins.
328
+ if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) {
329
+ return 1;
330
+ }
331
+ // If b has a priority and a does not, b wins.
332
+ elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) {
333
+ return -1;
334
+ }
335
+ // If neither has a priority or both priorities are equal its a tie.
336
+ elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) {
337
+ return 0;
338
+ }
339
+
340
+ // If both have priority return the winner.
341
+ return ( $a['priority'] < $b['priority'] ) ? - 1 : 1;
342
+ }
343
+
freemius/includes/fs-essential-functions.php ADDED
@@ -0,0 +1,403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.5
7
+ */
8
+
9
+ if ( ! function_exists( 'fs_normalize_path' ) ) {
10
+ if ( function_exists( 'wp_normalize_path' ) ) {
11
+ /**
12
+ * Normalize a filesystem path.
13
+ *
14
+ * Replaces backslashes with forward slashes for Windows systems, and ensures
15
+ * no duplicate slashes exist.
16
+ *
17
+ * @param string $path Path to normalize.
18
+ *
19
+ * @return string Normalized path.
20
+ */
21
+ function fs_normalize_path( $path ) {
22
+ return wp_normalize_path( $path );
23
+ }
24
+ } else {
25
+ function fs_normalize_path( $path ) {
26
+ $path = str_replace( '\\', '/', $path );
27
+ $path = preg_replace( '|/+|', '/', $path );
28
+
29
+ return $path;
30
+ }
31
+ }
32
+ }
33
+
34
+ #region Core Redirect (copied from BuddyPress) -----------------------------------------
35
+
36
+ if ( ! function_exists( 'fs_redirect' ) ) {
37
+ /**
38
+ * Redirects to another page, with a workaround for the IIS Set-Cookie bug.
39
+ *
40
+ * @link http://support.microsoft.com/kb/q176113/
41
+ * @since 1.5.1
42
+ * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
43
+ *
44
+ * @param string $location The path to redirect to
45
+ * @param int $status Status code to use
46
+ *
47
+ * @return bool False if $location is not set
48
+ */
49
+ function fs_redirect( $location, $status = 302 ) {
50
+ global $is_IIS;
51
+
52
+ if ( headers_sent() ) {
53
+ return false;
54
+ }
55
+
56
+ if ( ! $location ) // allows the wp_redirect filter to cancel a redirect
57
+ {
58
+ return false;
59
+ }
60
+
61
+ $location = fs_sanitize_redirect( $location );
62
+
63
+ if ( $is_IIS ) {
64
+ header( "Refresh: 0;url=$location" );
65
+ } else {
66
+ if ( php_sapi_name() != 'cgi-fcgi' ) {
67
+ status_header( $status );
68
+ } // This causes problems on IIS and some FastCGI setups
69
+ header( "Location: $location" );
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ /**
76
+ * Sanitizes a URL for use in a redirect.
77
+ *
78
+ * @since 2.3
79
+ *
80
+ * @param string $location
81
+ *
82
+ * @return string redirect-sanitized URL
83
+ */
84
+ function fs_sanitize_redirect( $location ) {
85
+ $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
86
+ $location = fs_kses_no_null( $location );
87
+
88
+ // remove %0d and %0a from location
89
+ $strip = array( '%0d', '%0a' );
90
+ $found = true;
91
+ while ( $found ) {
92
+ $found = false;
93
+ foreach ( (array) $strip as $val ) {
94
+ while ( strpos( $location, $val ) !== false ) {
95
+ $found = true;
96
+ $location = str_replace( $val, '', $location );
97
+ }
98
+ }
99
+ }
100
+
101
+ return $location;
102
+ }
103
+
104
+ /**
105
+ * Removes any NULL characters in $string.
106
+ *
107
+ * @since 1.0.0
108
+ *
109
+ * @param string $string
110
+ *
111
+ * @return string
112
+ */
113
+ function fs_kses_no_null( $string ) {
114
+ $string = preg_replace( '/\0+/', '', $string );
115
+ $string = preg_replace( '/(\\\\0)+/', '', $string );
116
+
117
+ return $string;
118
+ }
119
+ }
120
+
121
+ #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
122
+
123
+ if ( ! function_exists( '__fs' ) ) {
124
+ global $fs_text_overrides;
125
+
126
+ if ( ! isset( $fs_text_overrides ) ) {
127
+ $fs_text_overrides = array();
128
+ }
129
+
130
+ /**
131
+ * Retrieve a translated text by key.
132
+ *
133
+ * @author Vova Feldman (@svovaf)
134
+ * @since 1.1.4
135
+ *
136
+ * @param string $key
137
+ * @param string $slug
138
+ *
139
+ * @return string
140
+ *
141
+ * @global $fs_text , $fs_text_overrides
142
+ */
143
+ function __fs( $key, $slug = 'freemius' ) {
144
+ global $fs_text, $fs_text_overrides;
145
+
146
+ if ( ! isset( $fs_text ) ) {
147
+ require_once( ( defined( 'WP_FS__DIR_INCLUDES' ) ? WP_FS__DIR_INCLUDES : dirname( __FILE__ ) ) . '/i18n.php' );
148
+ }
149
+
150
+ if ( isset( $fs_text_overrides[ $slug ] ) &&
151
+ isset( $fs_text_overrides[ $slug ][ $key ] )
152
+ ) {
153
+ return $fs_text_overrides[ $slug ][ $key ];
154
+ }
155
+
156
+ return isset( $fs_text[ $key ] ) ?
157
+ $fs_text[ $key ] :
158
+ $key;
159
+ }
160
+
161
+ /**
162
+ * Display a translated text by key.
163
+ *
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.1.4
166
+ *
167
+ * @param string $key
168
+ * @param string $slug
169
+ */
170
+ function _efs( $key, $slug = 'freemius' ) {
171
+ echo __fs( $key, $slug );
172
+ }
173
+
174
+ /**
175
+ * Override default i18n text phrases.
176
+ *
177
+ * @author Vova Feldman (@svovaf)
178
+ * @since 1.1.6
179
+ *
180
+ * @param string[] $key_value
181
+ * @param string $slug
182
+ *
183
+ * @global $fs_text_overrides
184
+ */
185
+ function fs_override_i18n( array $key_value, $slug = 'freemius' ) {
186
+ global $fs_text_overrides;
187
+
188
+ if ( ! isset( $fs_text_overrides[ $slug ] ) ) {
189
+ $fs_text_overrides[ $slug ] = array();
190
+ }
191
+
192
+ foreach ( $key_value as $key => $value ) {
193
+ $fs_text_overrides[ $slug ][ $key ] = $value;
194
+ }
195
+ }
196
+ }
197
+
198
+ if ( ! function_exists( 'fs_get_ip' ) ) {
199
+ /**
200
+ * Get client IP.
201
+ *
202
+ * @author Vova Feldman (@svovaf)
203
+ * @since 1.1.2
204
+ *
205
+ * @return string|null
206
+ */
207
+ function fs_get_ip() {
208
+ $fields = array(
209
+ 'HTTP_CF_CONNECTING_IP',
210
+ 'HTTP_CLIENT_IP',
211
+ 'HTTP_X_FORWARDED_FOR',
212
+ 'HTTP_X_FORWARDED',
213
+ 'HTTP_FORWARDED_FOR',
214
+ 'HTTP_FORWARDED',
215
+ 'REMOTE_ADDR',
216
+ );
217
+
218
+ foreach ( $fields as $ip_field ) {
219
+ if ( ! empty( $_SERVER[ $ip_field ] ) ) {
220
+ return $_SERVER[ $ip_field ];
221
+ }
222
+ }
223
+
224
+ return null;
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Leverage backtrace to find caller plugin main file path.
230
+ *
231
+ * @author Vova Feldman (@svovaf)
232
+ * @since 1.0.6
233
+ *
234
+ * @return string
235
+ */
236
+ function fs_find_caller_plugin_file() {
237
+ /**
238
+ * All the code below will be executed once on activation.
239
+ * If the user changes the main plugin's file name, the file_exists()
240
+ * will catch it.
241
+ */
242
+ if ( ! function_exists( 'get_plugins' ) ) {
243
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
244
+ }
245
+
246
+ $all_plugins = get_plugins();
247
+ $all_plugins_paths = array();
248
+
249
+ // Get active plugin's main files real full names (might be symlinks).
250
+ foreach ( $all_plugins as $relative_path => &$data ) {
251
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
252
+ }
253
+
254
+ $plugin_file = null;
255
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
256
+ if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
257
+ $plugin_file = $bt[ $i ]['file'];
258
+ break;
259
+ }
260
+ }
261
+
262
+ if ( is_null( $plugin_file ) ) {
263
+ // Throw an error to the developer in case of some edge case dev environment.
264
+ wp_die( __fs( 'failed-finding-main-path' ), __fs( 'error' ), array( 'back_link' => true ) );
265
+ }
266
+
267
+ return $plugin_file;
268
+ }
269
+
270
+ require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
271
+
272
+ /**
273
+ * Update SDK newest version reference.
274
+ *
275
+ * @author Vova Feldman (@svovaf)
276
+ * @since 1.1.6
277
+ *
278
+ * @param string $sdk_relative_path
279
+ * @param string|bool $plugin_file
280
+ *
281
+ * @global $fs_active_plugins
282
+ */
283
+ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
284
+ global $fs_active_plugins;
285
+
286
+ if ( ! is_string( $plugin_file ) ) {
287
+ $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
288
+ }
289
+
290
+ $fs_active_plugins->newest = (object) array(
291
+ 'plugin_path' => $plugin_file,
292
+ 'sdk_path' => $sdk_relative_path,
293
+ 'version' => $fs_active_plugins->plugins[ $sdk_relative_path ]->version,
294
+ 'in_activation' => ! is_plugin_active( $plugin_file ),
295
+ 'timestamp' => time(),
296
+ );
297
+
298
+ // Update DB with latest SDK version and path.
299
+ update_option( 'fs_active_plugins', $fs_active_plugins );
300
+ }
301
+
302
+ /**
303
+ * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
304
+ *
305
+ * @author Vova Feldman (@svovaf)
306
+ * @since 1.1.6
307
+ *
308
+ * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
309
+ *
310
+ * @global $fs_active_plugins
311
+ */
312
+ function fs_newest_sdk_plugin_first() {
313
+ global $fs_active_plugins;
314
+
315
+ /**
316
+ * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
317
+ *
318
+ * @link https://github.com/Freemius/wordpress-sdk/issues/26
319
+ */
320
+ // $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
321
+
322
+ $active_plugins = get_option( 'active_plugins' );
323
+ $newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins );
324
+ if ( 0 == $newest_sdk_plugin_key ) {
325
+ // if it's 0 it's the first plugin already, no need to continue
326
+ return false;
327
+ }
328
+
329
+ array_splice( $active_plugins, $newest_sdk_plugin_key, 1 );
330
+ array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path );
331
+ update_option( 'active_plugins', $active_plugins );
332
+
333
+ return true;
334
+ }
335
+
336
+ /**
337
+ * Go over all Freemius SDKs in the system and find and "remember"
338
+ * the newest SDK which is associated with an active plugin.
339
+ *
340
+ * @author Vova Feldman (@svovaf)
341
+ * @since 1.1.6
342
+ *
343
+ * @global $fs_active_plugins
344
+ */
345
+ function fs_fallback_to_newest_active_sdk() {
346
+ global $fs_active_plugins;
347
+
348
+ $newest_sdk_data = null;
349
+ $newest_sdk_path = null;
350
+
351
+ foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
352
+ if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
353
+ ) {
354
+ // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
355
+ if ( ! is_plugin_active( $data->plugin_path ) ||
356
+ ! file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) )
357
+ ) {
358
+ unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
359
+
360
+ // No need to store the data since it will be stored in fs_update_sdk_newest_version()
361
+ // or explicitly with update_option().
362
+ } else {
363
+ $newest_sdk_data = $data;
364
+ $newest_sdk_path = $sdk_relative_path;
365
+ }
366
+ }
367
+ }
368
+
369
+ if ( is_null( $newest_sdk_data ) ) {
370
+ // Couldn't find any SDK reference.
371
+ $fs_active_plugins = new stdClass();
372
+ update_option( 'fs_active_plugins', $fs_active_plugins );
373
+ } else {
374
+ fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
375
+ }
376
+ }
377
+
378
+ #region Actions / Filters -----------------------------------------
379
+
380
+ /**
381
+ * Apply filter for specific plugin.
382
+ *
383
+ * @author Vova Feldman (@svovaf)
384
+ * @since 1.0.9
385
+ *
386
+ * @param string $slug Plugin slug
387
+ * @param string $tag The name of the filter hook.
388
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
389
+ *
390
+ * @return mixed The filtered value after all hooked functions are applied to it.
391
+ *
392
+ * @uses apply_filters()
393
+ */
394
+ function fs_apply_filter( $slug, $tag, $value ) {
395
+ $args = func_get_args();
396
+
397
+ return call_user_func_array( 'apply_filters', array_merge(
398
+ array( 'fs_' . $tag . '_' . $slug ),
399
+ array_slice( $args, 2 ) )
400
+ );
401
+ }
402
+
403
+ #endregion Actions / Filters -----------------------------------------
freemius/includes/fs-plugin-functions.php ADDED
@@ -0,0 +1,413 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Display plugin information in dialog box form.
15
+ *
16
+ * @since 2.7.0
17
+ */
18
+ function fs_install_plugin_information() {
19
+ global $tab;
20
+
21
+ if ( empty( $_REQUEST['plugin'] ) ) {
22
+ return;
23
+ }
24
+
25
+ $args = array(
26
+ 'slug' => wp_unslash( $_REQUEST['plugin'] ),
27
+ 'is_ssl' => is_ssl(),
28
+ 'fields' => array( 'banners' => true, 'reviews' => true )
29
+ );
30
+
31
+ if ( is_array( $args ) ) {
32
+ $args = (object) $args;
33
+ }
34
+
35
+ if ( ! isset( $args->per_page ) ) {
36
+ $args->per_page = 24;
37
+ }
38
+
39
+ if ( ! isset( $args->locale ) ) {
40
+ $args->locale = get_locale();
41
+ }
42
+
43
+ $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args );
44
+
45
+ if ( is_wp_error( $api ) ) {
46
+ wp_die( $api );
47
+ }
48
+
49
+ $plugins_allowedtags = array(
50
+ 'a' => array(
51
+ 'href' => array(),
52
+ 'title' => array(),
53
+ 'target' => array(),
54
+ // Add image style for screenshots.
55
+ 'class' => array()
56
+ ),
57
+ 'style' => array(),
58
+ 'abbr' => array( 'title' => array() ),
59
+ 'acronym' => array( 'title' => array() ),
60
+ 'code' => array(),
61
+ 'pre' => array(),
62
+ 'em' => array(),
63
+ 'strong' => array(),
64
+ 'div' => array( 'class' => array() ),
65
+ 'span' => array( 'class' => array() ),
66
+ 'p' => array(),
67
+ 'ul' => array(),
68
+ 'ol' => array(),
69
+ 'li' => array( 'class' => array() ),
70
+ 'i' => array( 'class' => array() ),
71
+ 'h1' => array(),
72
+ 'h2' => array(),
73
+ 'h3' => array(),
74
+ 'h4' => array(),
75
+ 'h5' => array(),
76
+ 'h6' => array(),
77
+ 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
78
+ // 'table' => array(),
79
+ // 'td' => array(),
80
+ // 'tr' => array(),
81
+ // 'th' => array(),
82
+ // 'thead' => array(),
83
+ // 'tbody' => array(),
84
+ );
85
+
86
+ $plugins_section_titles = array(
87
+ 'description' => _x( 'Description', 'Plugin installer section title' ),
88
+ 'installation' => _x( 'Installation', 'Plugin installer section title' ),
89
+ 'faq' => _x( 'FAQ', 'Plugin installer section title' ),
90
+ 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
91
+ 'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
92
+ 'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
93
+ 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
94
+ );
95
+
96
+ // Sanitize HTML
97
+ // foreach ( (array) $api->sections as $section_name => $content ) {
98
+ // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
99
+ // }
100
+
101
+ foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
102
+ if ( isset( $api->$key ) ) {
103
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
104
+ }
105
+ }
106
+
107
+ // Add after $api->slug is ready.
108
+ $plugins_section_titles['features'] = __fs( 'features-and-pricing', $api->slug );
109
+
110
+ $_tab = esc_attr( $tab );
111
+
112
+ $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
113
+ if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
114
+ $section_titles = array_keys( (array) $api->sections );
115
+ $section = array_shift( $section_titles );
116
+ }
117
+
118
+ iframe_header( __( 'Plugin Install' ) );
119
+
120
+ $_with_banner = '';
121
+
122
+ // var_dump($api->banners);
123
+ if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
124
+ $_with_banner = 'with-banner';
125
+ $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
126
+ $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
127
+ ?>
128
+ <style type="text/css">
129
+ #plugin-information-title.with-banner
130
+ {
131
+ background-image: url( <?php echo esc_url( $low ); ?> );
132
+ }
133
+
134
+ @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 )
135
+ {
136
+ #plugin-information-title.with-banner
137
+ {
138
+ background-image: url( <?php echo esc_url( $high ); ?> );
139
+ }
140
+ }
141
+ </style>
142
+ <?php
143
+ }
144
+
145
+ echo '<div id="plugin-information-scrollable">';
146
+ echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
147
+ echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
148
+
149
+ foreach ( (array) $api->sections as $section_name => $content ) {
150
+ if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
151
+ continue;
152
+ }
153
+
154
+ if ( isset( $plugins_section_titles[ $section_name ] ) ) {
155
+ $title = $plugins_section_titles[ $section_name ];
156
+ } else {
157
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
158
+ }
159
+
160
+ $class = ( $section_name === $section ) ? ' class="current"' : '';
161
+ $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) );
162
+ $href = esc_url( $href );
163
+ $san_section = esc_attr( $section_name );
164
+ echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
165
+ }
166
+
167
+ echo "</div>\n";
168
+
169
+ ?>
170
+ <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
171
+ <div class="fyi">
172
+ <?php if ( isset( $api->plans ) ) : ?>
173
+ <div class="plugin-information-pricing">
174
+ <?php foreach ($api->plans as $plan) : ?>
175
+ <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan', $api->slug ), $plan->title ) ?></h3>
176
+ <ul>
177
+ <?php $billing_cycle = 'annual' ?>
178
+ <?php if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) : ?>
179
+ <?php $pricing = $plan->pricing[0] ?>
180
+ <li><label><?php _efs( 'price', $api->slug ) ?>: $<?php
181
+ if ( isset( $pricing->annual_price ) ) {
182
+ echo $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
183
+ $billing_cycle = 'annual';
184
+ } else if ( isset( $pricing->monthly_price ) ) {
185
+ echo $pricing->monthly_price . ' / mo';
186
+ $billing_cycle = 'monthly';
187
+ } else if ( isset( $pricing->lifetime_price ) ) {
188
+ echo $pricing->lifetime_price;
189
+ $billing_cycle = 'lifetime';
190
+ }
191
+ ?></label></li>
192
+ <?php else : ?>
193
+ <?php $first = true;
194
+ foreach ( $plan->pricing as $pricing ) : ?>
195
+ <li><label><input name="pricing-<?php echo $plan->id ?>" type="radio"
196
+ value="<?php echo $pricing->id ?>"<?php checked( $first, true ) ?>><?php
197
+ switch ( $pricing->licenses ) {
198
+ case '1':
199
+ _efs( 'license-single-site', $api->slug );
200
+ break;
201
+ case null:
202
+ _efs( 'license-unlimited', $api->slug );
203
+ break;
204
+ default:
205
+ printf( __fs( 'license-x-sites', $api->slug ), $pricing->licenses );
206
+ break;
207
+ }
208
+ ?> - $<?php
209
+ if ( isset( $pricing->annual_price ) ) {
210
+ echo $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
211
+ $billing_cycle = 'annual';
212
+ } else if ( isset( $pricing->monthly_price ) ) {
213
+ echo $pricing->monthly_price . ' / mo';
214
+ $billing_cycle = 'monthly';
215
+ } else if ( isset( $pricing->lifetime_price ) ) {
216
+ echo $pricing->lifetime_price;
217
+ $billing_cycle = 'lifetime';
218
+ }
219
+ ?></label></li>
220
+ <?php $first = false; endforeach ?>
221
+ <?php endif ?>
222
+ </ul>
223
+ <?php echo ' <a class="button button-primary right" href="' . esc_url( add_query_arg( array(
224
+ 'plugin_id' => $plan->plugin_id,
225
+ 'plan_id' => $plan->id,
226
+ 'pricing_id' => $plan->pricing[0]->id,
227
+ 'billing_cycle' => $billing_cycle,
228
+ ), $api->checkout_link ) ) . '" target="_parent">' . __fs( 'purchase', $api->slug ) . '</a>' ?>
229
+ </div>
230
+ <?php endforeach ?>
231
+ <?php wp_enqueue_script( 'jquery' ); ?>
232
+ <script type="text/javascript">
233
+ (function ($) {
234
+ $('.plugin-information-pricing input[type=radio]').click(function () {
235
+ var checkout_url = '<?php echo esc_url_raw(add_query_arg(array(
236
+ 'plugin_id' => $plan->plugin_id,
237
+ 'billing_cycle' => $billing_cycle,
238
+ ), $api->checkout_link)) ?>&plan_id=' +
239
+ $(this).parents('.plugin-information-pricing').find('h3').attr('data-plan') +
240
+ '&pricing_id=' + $(this).val();
241
+
242
+ $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', checkout_url);
243
+ });
244
+ })(jQuery);
245
+ </script>
246
+ <?php endif ?>
247
+ <div>
248
+ <h3><?php _efs( 'details', $api->slug ) ?></h3>
249
+ <ul>
250
+ <?php if ( ! empty( $api->version ) ) { ?>
251
+ <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
252
+ <?php }
253
+ if ( ! empty( $api->author ) ) { ?>
254
+ <li>
255
+ <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?>
256
+ </li>
257
+ <?php }
258
+ if ( ! empty( $api->last_updated ) ) { ?>
259
+ <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span
260
+ title="<?php echo $api->last_updated; ?>">
261
+ <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
262
+ </span></li>
263
+ <?php }
264
+ if ( ! empty( $api->requires ) ) { ?>
265
+ <li>
266
+ <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?>
267
+ </li>
268
+ <?php }
269
+ if ( ! empty( $api->tested ) ) { ?>
270
+ <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li>
271
+ <?php }
272
+ if ( ! empty( $api->downloaded ) ) { ?>
273
+ <li>
274
+ <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?>
275
+ </li>
276
+ <?php }
277
+ if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?>
278
+ <li><a target="_blank"
279
+ href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a>
280
+ </li>
281
+ <?php }
282
+ if ( ! empty( $api->homepage ) ) { ?>
283
+ <li><a target="_blank"
284
+ href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a>
285
+ </li>
286
+ <?php }
287
+ if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?>
288
+ <li><a target="_blank"
289
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
290
+ </li>
291
+ <?php } ?>
292
+ </ul>
293
+ </div>
294
+ <?php if ( ! empty( $api->rating ) ) { ?>
295
+ <h3><?php _e( 'Average Rating' ); ?></h3>
296
+ <?php wp_star_rating( array(
297
+ 'rating' => $api->rating,
298
+ 'type' => 'percent',
299
+ 'number' => $api->num_ratings
300
+ ) ); ?>
301
+ <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
302
+ <?php
303
+ }
304
+
305
+ if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
306
+ foreach ( $api->ratings as $key => $ratecount ) {
307
+ // Avoid div-by-zero.
308
+ $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
309
+ ?>
310
+ <div class="counter-container">
311
+ <span class="counter-label"><a
312
+ href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
313
+ target="_blank"
314
+ title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
315
+ <span class="counter-back">
316
+ <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
317
+ </span>
318
+ <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
319
+ </div>
320
+ <?php
321
+ }
322
+ }
323
+ if ( ! empty( $api->contributors ) ) {
324
+ ?>
325
+ <h3><?php _e( 'Contributors' ); ?></h3>
326
+ <ul class="contributors">
327
+ <?php
328
+ foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
329
+ if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
330
+ continue;
331
+ }
332
+ if ( empty( $contrib_username ) ) {
333
+ $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
334
+ }
335
+ $contrib_username = sanitize_user( $contrib_username );
336
+ if ( empty( $contrib_profile ) ) {
337
+ echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
338
+ } else {
339
+ echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
340
+ }
341
+ }
342
+ ?>
343
+ </ul>
344
+ <?php if ( ! empty( $api->donate_link ) ) { ?>
345
+ <a target="_blank"
346
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
347
+ <?php } ?>
348
+ <?php } ?>
349
+ </div>
350
+ <div id="section-holder" class="wrap">
351
+ <?php
352
+ if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
353
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>';
354
+ } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
355
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been marked as compatible with your version of WordPress.' ) . '</p></div>';
356
+ }
357
+
358
+ foreach ( (array) $api->sections as $section_name => $content ) {
359
+ $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
360
+ $content = links_add_target( $content, '_blank' );
361
+
362
+ $san_section = esc_attr( $section_name );
363
+
364
+ $display = ( $section_name === $section ) ? 'block' : 'none';
365
+
366
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
367
+ echo $content;
368
+ echo "\t</div>\n";
369
+ }
370
+ echo "</div>\n";
371
+ echo "</div>\n";
372
+ echo "</div>\n"; // #plugin-information-scrollable
373
+ echo "<div id='$tab-footer'>\n";
374
+ if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
375
+
376
+ if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) {
377
+ echo ' <a class="button button-primary right" href="' . esc_url( add_query_arg( array(
378
+ 'plugin_id' => $plan->plugin_id,
379
+ 'plan_id' => $plan->id,
380
+ 'pricing_id' => $plan->pricing[0]->id,
381
+ 'billing_cycle' => $billing_cycle,
382
+ ), $api->checkout_link ) ) . '" target="_parent">' . __fs( 'purchase', $api->slug ) . '</a>';
383
+
384
+ // @todo Add Cart concept.
385
+ // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>';
386
+
387
+ } else if ( ! empty( $api->download_link ) ) {
388
+ $status = install_plugin_install_status( $api );
389
+ switch ( $status['status'] ) {
390
+ case 'install':
391
+ if ( $status['url'] ) {
392
+ echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
393
+ }
394
+ break;
395
+ case 'update_available':
396
+ if ( $status['url'] ) {
397
+ echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
398
+ }
399
+ break;
400
+ case 'newer_installed':
401
+ echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
402
+ break;
403
+ case 'latest_installed':
404
+ echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
405
+ break;
406
+ }
407
+ }
408
+ }
409
+ echo "</div>\n";
410
+
411
+ iframe_footer();
412
+ exit;
413
+ }
freemius/includes/i18n.php ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * All strings can now be overridden.
15
+ *
16
+ * For example, if we want to override:
17
+ * 'you-are-step-away' => 'You are just one step away - %s',
18
+ *
19
+ * We can use the filter:
20
+ * fs_override_i18n( array(
21
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
22
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
23
+ * ), '{plugin_slug}' );
24
+ *
25
+ * Or with the Freemius instance:
26
+ *
27
+ * my_freemius->override_i18n( array(
28
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
29
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
30
+ * );
31
+ */
32
+ global $fs_text;
33
+
34
+ $fs_text = array(
35
+ 'account' => __( 'Account', 'freemius' ),
36
+ 'addon' => __( 'Add On', 'freemius' ),
37
+ 'contact-us' => __( 'Contact Us', 'freemius' ),
38
+ 'change-ownership' => __( 'Change Ownership', 'freemius' ),
39
+ 'support' => __( 'Support', 'freemius' ),
40
+ 'support-forum' => __( 'Support Forum', 'freemius' ),
41
+ 'add-ons' => __( 'Add Ons', 'freemius' ),
42
+ 'upgrade' => _x( 'Upgrade', 'verb', 'freemius' ),
43
+ 'awesome' => __( 'Awesome', 'freemius' ),
44
+ 'pricing' => _x( 'Pricing', 'noun', 'freemius' ),
45
+ 'price' => _x( 'Price', 'noun', 'freemius' ),
46
+ 'unlimited-updates' => __( 'Unlimited Updates', 'freemius' ),
47
+ 'downgrade' => _x( 'Downgrade', 'verb', 'freemius' ),
48
+ 'free-trial' => __( 'Free Trial', 'freemius' ),
49
+ 'details' => __( 'Details', 'freemius' ),
50
+ 'account-details' => __( 'Account Details', 'freemius' ),
51
+ 'delete' => _x( 'Delete', 'verb', 'freemius' ),
52
+ 'delete-account' => __( 'Delete Account', 'freemius' ),
53
+ 'dismiss' => _x( 'Dismiss', 'as close a window', 'freemius' ),
54
+ 'plan' => _x( 'Plan', 'as product pricing plan', 'freemius' ),
55
+ 'change-plan' => __( 'Change Plan', 'freemius' ),
56
+ 'download-x-version' => _x( 'Download %s Version', 'as download professional version', 'freemius' ),
57
+ 'download-x-version-now' => _x( 'Download %s version now', 'as download professional version now', 'freemius' ),
58
+ 'download-latest' => _x( 'Download Latest', 'as download latest version', 'freemius' ),
59
+ 'you-have-x-license' => _x( 'You have a %s license.', 'E.g. you have a professional license.', 'freemius' ),
60
+ 'new' => __( 'New', 'freemius' ),
61
+ 'free' => __( 'Free', 'freemius' ),
62
+ 'trial' => _x( 'Trial', 'as trial plan', 'freemius' ),
63
+ 'purchase' => _x( 'Purchase', 'verb', 'freemius' ),
64
+ 'license-single-site' => __( 'Single Site License', 'freemius' ),
65
+ 'license-unlimited' => __( 'Unlimited Licenses', 'freemius' ),
66
+ 'license-x-sites' => __( 'Up to %s Sites', 'freemius' ),
67
+ 'renew-license-now' => __( '%sRenew your license now%s to access version %s features and support.', 'freemius' ),
68
+ 'x-plan' => _x( '%s Plan', 'e.g. Professional Plan', 'freemius' ),
69
+ 'you-are-step-away' => __( 'You are just one step away - %s', 'freemius' ),
70
+ 'activate-x-now' => _x( 'Complete "%s" Activation Now', '%s - plugin name. As complete "Jetpack" activation now', 'freemius' ),
71
+ 'few-plugin-tweaks' => __( 'We made a few tweaks to the plugin, %s', 'freemius' ),
72
+ 'optin-x-now' => __( 'Opt-in to make "%s" Better!', 'freemius' ),
73
+ 'error' => __( 'Error', 'freemius' ),
74
+ 'failed-finding-main-path' => __( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'freemius' ),
75
+ #region Account
76
+
77
+ 'expiration' => _x( 'Expiration', 'as expiration date', 'freemius' ),
78
+ 'not-verified' => __( 'not verified', 'freemius' ),
79
+ 'verify-email' => __( 'Verify Email', 'freemius' ),
80
+ 'expires-in' => _x( 'Expires in %s', 'e.g. expires in 2 months', 'freemius' ),
81
+ 'renews-in' => _x( 'Auto renews in %s', 'e.g. auto renews in 2 months', 'freemius' ),
82
+ 'no-expiration' => __( 'No expiration', 'freemius' ),
83
+ 'expired' => __( 'Expired', 'freemius' ),
84
+ 'in-x' => __( 'In %s', 'freemius' ),
85
+ 'version' => _x( 'Version', 'as plugin version', 'freemius' ),
86
+ 'name' => __( 'Name', 'freemius' ),
87
+ 'email' => __( 'Email', 'freemius' ),
88
+ 'verified' => __( 'Verified', 'freemius' ),
89
+ 'plugin' => __( 'Plugin', 'freemius' ),
90
+ 'plugins' => __( 'Plugins', 'freemius' ),
91
+ 'path' => _x( 'Path', 'as file/folder path', 'freemius' ),
92
+ 'title' => __( 'Title', 'freemius' ),
93
+ 'slug' => _x( 'Slug', 'as WP plugin slug', 'freemius' ),
94
+ 'id' => __( 'ID', 'freemius' ),
95
+ 'users' => __( 'Users', 'freemius' ),
96
+ 'plugin-installs' => __( 'Plugin Installs', 'freemius' ),
97
+ 'sites' => _x( 'Sites', 'like websites', 'freemius' ),
98
+ 'user-id' => __( 'User ID', 'freemius' ),
99
+ 'site-id' => __( 'Site ID', 'freemius' ),
100
+ 'public-key' => __( 'Public Key', 'freemius' ),
101
+ 'secret-key' => __( 'Secret Key', 'freemius' ),
102
+ 'no-secret' => _x( 'No Secret', 'as secret encryption key missing', 'freemius' ),
103
+ 'no-id' => __( 'No ID', 'freemius' ),
104
+ 'sync-license' => _x( 'Sync License', 'as synchronize license', 'freemius' ),
105
+ 'sync' => _x( 'Sync', 'as synchronize', 'freemius' ),
106
+ 'deactivate-license' => __( 'Deactivate License', 'freemius' ),
107
+ 'activate' => __( 'Activate', 'freemius' ),
108
+ 'deactivate' => __( 'Deactivate', 'freemius' ),
109
+ 'active' => _x( 'Active', 'active mode', 'freemius' ),
110
+ 'is-active' => _x( 'Is Active', 'is active mode?', 'freemius' ),
111
+ 'install-now' => __( 'Install Now', 'freemius' ),
112
+ 'install-update-now' => __( 'Install Update Now', 'freemius' ),
113
+ 'more-information-about-x' => __( 'More information about %s', 'freemius' ),
114
+ 'localhost' => __( 'Localhost', 'freemius' ),
115
+ 'activate-x-plan' => _x( 'Activate %s Plan', 'as activate Professional plan', 'freemius' ),
116
+ 'what-is-your-x' => __( 'What is your %s?', 'freemius' ),
117
+ 'activate-this-addon' => __( 'Activate this add-on', 'freemius' ),
118
+ 'deactivate-license-confirm' => __( 'Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?', 'freemius' ),
119
+ 'delete-account-x-confirm' => __( 'Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the "Cancel" button, and first "Downgrade" your account. Are you sure you would like to continue with the deletion?', 'freemius' ),
120
+ 'delete-account-confirm' => __( 'Deletion is not temporary. Only delete if you no longer want to use this plugin anymore. Are you sure you would like to continue with the deletion?', 'freemius' ),
121
+ 'downgrade-x-confirm' => __( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'freemius' ),
122
+ 'after-downgrade-non-blocking' => __( 'You can still enjoy all %s features but you will not have access to plugin updates and support.', 'freemius' ),
123
+ 'after-downgrade-blocking' => __( 'Once your license expire you can still use the Free version but you will NOT have access to the %s features.', 'freemius' ),
124
+ 'proceed-confirmation' => __( 'Are you sure you want to proceed?', 'freemius' ),
125
+ #endregion Account
126
+
127
+ 'add-ons-for-x' => __( 'Add Ons for %s', 'freemius' ),
128
+ #region Plugin Deactivation
129
+ 'deactivation-share-reason' => __( 'If you have a moment, please let us know why you are deactivating', 'freemius' ),
130
+ 'deactivation-modal-button-deactivate' => __( 'Deactivate', 'freemius' ),
131
+ 'deactivation-modal-button-confirm' => __( 'Yes - Deactivate', 'freemius' ),
132
+ 'deactivation-modal-button-submit' => __( 'Submit & Deactivate', 'freemius' ),
133
+ 'deactivation-modal-button-cancel' => _x( 'Cancel', 'the text of the cancel button of the plugin deactivation dialog box.', 'freemius' ),
134
+ 'reason-no-longer-needed' => __( 'I no longer need the plugin', 'freemius' ),
135
+ 'reason-found-a-better-plugin' => __( 'I found a better plugin', 'freemius' ),
136
+ 'reason-needed-for-a-short-period' => __( 'I only needed the plugin for a short period', 'freemius' ),
137
+ 'reason-broke-my-site' => __( 'The plugin broke my site', 'freemius' ),
138
+ 'reason-suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'freemius' ),
139
+ 'reason-cant-pay-anymore' => __( "I can't pay for it anymore", 'freemius' ),
140
+ 'reason-other' => _x( 'Other', 'the text of the "other" reason for deactivating the plugin that is shown in the modal box.', 'freemius' ),
141
+ 'placeholder-plugin-name' => __( "What's the plugin's name?", 'freemius' ),
142
+ 'placeholder-comfortable-price' => __( 'What price would you feel comfortable paying?', 'freemius' ),
143
+ 'reason-couldnt-make-it-work' => __( "I couldn't understand how to make it work", 'freemius' ),
144
+ 'reason-great-but-need-specific-feature' => __( "The plugin is great, but I need specific feature that you don't support", 'freemius' ),
145
+ 'reason-not-working' => __( 'The plugin is not working', 'freemius' ),
146
+ 'reason-not-what-i-was-looking-for' => __( "It's not what I was looking for", 'freemius' ),
147
+ 'reason-didnt-work-as-expected' => __( "The plugin didn't work as expected", 'freemius' ),
148
+ 'placeholder-feature' => __( 'What feature?', 'freemius' ),
149
+ 'placeholder-share-what-didnt-work' => __( "Kindly share what didn't work so we can fix it for future users...", 'freemius' ),
150
+ 'placeholder-what-youve-been-looking-for' => __( "What you've been looking for?", 'freemius' ),
151
+ 'placeholder-what-did-you-expect' => __( "What did you expect?", 'freemius' ),
152
+ 'reason-didnt-work' => __( "The plugin didn't work", 'freemius' ),
153
+ 'reason-dont-like-to-share-my-information' => __( "I don't like to share my information with you", 'freemius' ),
154
+ #endregion Plugin Deactivation
155
+
156
+ #region Connect
157
+ 'hey-x' => _x( 'Hey %s,', 'greeting', 'freemius' ),
158
+ 'thanks-x' => _x( 'Thanks %s!', 'a greeting. E.g. Thanks John!', 'freemius' ),
159
+ 'connect-message' => __( 'In order to enjoy all our features and functionality, %s needs to connect your user, %s at %s, to %s', 'freemius' ),
160
+ 'connect-message_on-update' => __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'freemius' ),
161
+ 'pending-activation-message' => __( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to complete the install.', 'freemius' ),
162
+ 'what-permissions' => __( 'What permissions are being granted?', 'freemius' ),
163
+ 'permissions-profile' => __( 'Your Profile Overview', 'freemius' ),
164
+ 'permissions-profile_desc' => __( 'Name and email address', 'freemius' ),
165
+ 'permissions-site' => __( 'Your Site Overview', 'freemius' ),
166
+ 'permissions-site_desc' => __( 'Site address, WordPress version, PHP Version', 'freemius' ),
167
+ 'permissions-events' => __( 'Plugin Events', 'freemius' ),
168
+ 'permissions-events_desc' => __( 'Activation, deactivation and uninstall', 'freemius' ),
169
+ 'permissions-newsletter' => __( 'Newsletter', 'freemius' ),
170
+ 'permissions-newsletter_desc' => __( 'Updates, announcements, marketing, no spam', 'freemius' ),
171
+ 'privacy-policy' => __( 'Privacy Policy', 'freemius' ),
172
+ 'tos' => __( 'Terms of Service', 'freemius' ),
173
+ 'activating' => _x( 'Activating', 'as activating plugin', 'freemius' ),
174
+ 'sending-email' => _x( 'Sending email', 'as in the process of sending an email', 'freemius' ),
175
+ 'opt-in-connect' => _x( 'Allow & Continue', 'button label', 'freemius' ),
176
+ 'skip' => _x( 'Skip', 'verb', 'freemius' ),
177
+ 'resend-activation-email' => __( 'Re-send activation email', 'freemius' ),
178
+ #endregion Connect
179
+
180
+ #region Screenshots
181
+ 'screenshots' => __( 'Screenshots', 'freemius' ),
182
+ 'view-full-size-x' => __( 'Click to view full-size screenshot %d', 'freemius' ),
183
+ #endregion Screenshots
184
+
185
+ #region Debug
186
+ 'freemius-debug' => __( 'Freemius Debug', 'freemius' ),
187
+ 'on' => _x( 'On', 'as turned on', 'freemius' ),
188
+ 'off' => _x( 'Off', 'as turned off', 'freemius' ),
189
+ 'freemius-state' => __( 'Freemius State', 'freemius' ),
190
+ 'connected' => _x( 'Connected', 'as connection was successful', 'freemius' ),
191
+ 'blocked' => _x( 'Blocked', 'as connection blocked', 'freemius' ),
192
+ 'api' => _x( 'API', 'as application program interface', 'freemius' ),
193
+ 'sdk' => _x( 'SDK', 'as software development kit versions', 'freemius' ),
194
+ 'sdk-versions' => _x( 'SDK Versions', 'as software development kit versions', 'freemius' ),
195
+ 'plugin-path' => _x( 'Plugin Path', 'as plugin folder path', 'freemius' ),
196
+ 'sdk-path' => _x( 'SDK Path', 'as sdk path', 'freemius' ),
197
+ 'addons-of-x' => __( 'Add Ons of Plugin %s', 'freemius' ),
198
+ 'delete-all-confirm' => __( 'Are you sure you want to delete the all Freemius data?', 'freemius' ),
199
+ 'actions' => __( 'Actions', 'freemius' ),
200
+ 'delete-all-accounts' => __( 'Delete All Accounts', 'freemius' ),
201
+ 'clear-api-cache' => __( 'Clear API Cache', 'freemius' ),
202
+ 'sync-data-from-server' => __( 'Sync Data From Server', 'freemius' ),
203
+ #endregion Debug
204
+
205
+ #region Expressions
206
+ 'congrats' => _x( 'Congrats', 'as congratulations', 'freemius' ),
207
+ 'oops' => _x( 'Oops', 'exclamation', 'freemius' ),
208
+ 'yee-haw' => _x( 'Yee-haw', 'interjection expressing joy or exuberance', 'freemius' ),
209
+ 'woot' => _x( 'W00t', '(especially in electronic communication) used to express elation, enthusiasm, or triumph.', 'freemius' ),
210
+ 'right-on' => _x( 'Right on', 'a positive response', 'freemius' ),
211
+ 'hmm' => _x( 'Hmm', 'something somebody says when they are thinking about what you have just said. ', 'freemius' ),
212
+ 'ok' => __( 'O.K', 'freemius' ),
213
+ 'hey' => _x( 'Hey', 'exclamation', 'freemius' ),
214
+ 'heads-up' => _x( 'Heads up', 'advance notice of something that will need attention.', 'freemius' ),
215
+ #endregion Expressions
216
+
217
+ #region Admin Notices
218
+ 'you-have-latest' => __( 'Seems like you got the latest release.', 'freemius' ),
219
+ 'you-are-good' => __( 'You are all good!', 'freemius' ),
220
+ 'user-exist-message' => __( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'freemius' ),
221
+ 'user-exist-message_ownership' => __( 'If you would like to give up the ownership of the plugin\'s account to %s click the Change Ownership button.', 'freemius' ),
222
+ 'email-updated-message' => __( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'freemius' ),
223
+ 'name-updated-message' => __( 'Your name was successfully updated.', 'freemius' ),
224
+ 'x-updated' => __( 'You have successfully updated your %s.', 'freemius' ),
225
+ 'name-update-failed-message' => __( 'Please provide your full name.', 'freemius' ),
226
+ 'verification-email-sent-message' => __( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'freemius' ),
227
+ 'addons-info-external-message' => __( 'Just letting you know that the add-ons information of %s is being pulled from external server.', 'freemius' ),
228
+ 'no-cc-required' => __( 'No credit card required', 'freemius' ),
229
+ 'premium-activated-message' => __( 'Premium plugin version was successfully activated.', 'freemius' ),
230
+ 'successful-version-upgrade-message' => __( 'The upgrade of %s was successfully completed.', 'freemius' ),
231
+ 'activation-with-plan-x-message' => __( 'Your account was successfully activated with the %s plan.', 'freemius' ),
232
+ 'download-latest-x-version' => __( 'Download the latest %s version now', 'freemius' ),
233
+ 'download-latest-version' => __( 'Download the latest version now', 'freemius' ),
234
+ 'addon-successfully-purchased-message' => _x( '%s Add-on was successfully purchased.', '%s - product name, e.g. Facebook add-on was successfully...', 'freemius' ),
235
+ 'addon-successfully-upgraded-message' => __( 'Your %s Add-on plan was successfully upgraded.', 'freemius' ),
236
+ 'email-verified-message' => __( 'Your email has been successfully verified - you are AWESOME!', 'freemius' ),
237
+ 'plan-upgraded-message' => __( 'Your plan was successfully upgraded.', 'freemius' ),
238
+ 'plan-changed-to-x-message' => __( 'Your plan was successfully changed to %s.', 'freemius' ),
239
+ 'license-expired-blocking-message' => __( 'Your license has expired. You can still continue using the free plugin forever.', 'freemius' ),
240
+ 'trial-started-message' => __( 'Your trial has been successfully started.', 'freemius' ),
241
+ 'license-activated-message' => __( 'Your license was successfully activated.', 'freemius' ),
242
+ 'no-active-license-message' => __( 'It looks like your site currently don\'t have an active license.', 'freemius' ),
243
+ 'license-deactivation-message' => __( 'Your license was successfully deactivated, you are back to the %s plan.', 'freemius' ),
244
+ 'license-deactivation-failed-message' => __( 'It looks like the license deactivation failed.', 'freemius' ),
245
+ 'license-activation-failed-message' => __( 'It looks like the license could not be activated.', 'freemius' ),
246
+ 'server-error-message' => __( 'Error received from the server:', 'freemius' ),
247
+ 'trial-expired-message' => __( 'Your trial has expired. You can still continue using all our free features.', 'freemius' ),
248
+ 'plan-x-downgraded-message' => __( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'freemius' ),
249
+ 'plan-downgraded-failure-message' => __( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'freemius' ),
250
+ 'trial-cancel-no-trial-message' => __( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'freemius' ),
251
+ 'trial-cancel-message' => __( 'Your %s Plan trial was successfully cancelled.', 'freemius' ),
252
+ 'version-x-released' => _x( 'Version %s was released.', '%s - numeric version number', 'freemius' ),
253
+ 'please-download-x' => __( 'Please download %s.', 'freemius' ),
254
+ 'latest-x-version' => _x( 'the latest %s version here', '%s - plan name, as the latest professional version here', 'freemius' ),
255
+ 'trial-x-promotion-message' => __( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'freemius' ),
256
+ 'start-free-trial' => _x( 'Start free trial', 'call to action', 'freemius' ),
257
+ 'trial-cancel-failure-message' => __( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'freemius' ),
258
+ 'no-commitment-for-x-days' => __( 'No commitment for %s days - cancel anytime!', 'freemius' ),
259
+ 'license-expired-non-blocking-message' => __( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'freemius' ),
260
+ 'could-not-activate-x' => __( 'Couldn\'t activate %s.', 'freemius' ),
261
+ 'contact-us-with-error-message' => __( 'Please contact us with the following message:', 'freemius' ),
262
+ 'plan-did-not-change-message' => __( 'It looks like your plan did\'t change. If you did upgrade, it\'s probably an issue on our side - sorry.', 'freemius' ),
263
+ 'contact-us-here' => __( 'Please contact us here', 'freemius' ),
264
+ 'plan-did-not-change-email-message' => __( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'freemius' ),
265
+ #endregion Admin Notices
266
+ #region Connectivity Issues
267
+ 'connectivity-test-fails-message' => __( 'From unknown reason, the API connectivity test fails.', 'freemius' ),
268
+ 'curl-missing-message' => __( 'We use PHP cURL library for the API calls, which is a very common library and usually installed out of the box. Unfortunately, cURL is not installed on your server.', 'freemius' ),
269
+ 'cloudflare-blocks-connection-message' => __( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'freemius' ),
270
+ 'x-requires-access-to-api' => _x( '%s requires an access to our API.', 'as pluginX requires an access to our API', 'freemius' ),
271
+ 'squid-blocks-connection-message' => __( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'freemius' ),
272
+ 'squid-no-clue-title' => __( 'I don\'t know what is Squid or ACL, help me!', 'freemius' ),
273
+ 'squid-no-clue-desc' => __( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'freemius' ),
274
+ 'sysadmin-title' => __( 'I\'m a system administrator', 'freemius' ),
275
+ 'squid-sysadmin-desc' => __( 'Great, please whitelist the following domains: %s. Once you done, deactivate the plugin and activate it again.', 'freemius' ),
276
+ 'curl-missing-no-clue-title' => __( 'I don\'t know what is cURL or how to install it, help me!', 'freemius' ),
277
+ 'curl-missing-no-clue-desc' => __( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'freemius' ),
278
+ 'curl-missing-sysadmin-desc' => __( 'Great, please install cURL and enable it in your php.ini file. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the plugin and reactivate it back again.', 'freemius' ),
279
+ 'happy-to-resolve-issue-asap' => __( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'freemius' ),
280
+ 'fix-issue-title' => __( 'Yes - I\'m giving you a chance to fix it', 'freemius' ),
281
+ 'fix-issue-desc' => __( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'freemius' ),
282
+ 'install-previous-title' => __( 'Let\'s try your previous version', 'freemius' ),
283
+ 'install-previous-desc' => __( 'Uninstall this version and install the previous one.', 'freemius' ),
284
+ 'deactivate-plugin-title' => __( 'That\'s exhausting, please deactivate', 'freemius' ),
285
+ 'deactivate-plugin-desc' => __( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'freemius' ),
286
+ 'fix-request-sent-message' => __( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'freemius' ),
287
+ 'server-blocking-access' => _x( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'freemius' ),
288
+ 'wrong-authentication-param-message' => __( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'freemius' ),
289
+ #endregion Connectivity Issues
290
+ #region Change Owner
291
+ 'change-owner-request-sent-x' => __( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'freemius' ),
292
+ 'change-owner-request_owner-confirmed' => __( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'freemius' ),
293
+ 'change-owner-request_candidate-confirmed' => __( '%s is the new owner of the account.', 'freemius' ),
294
+ #endregion Change Owner
295
+ 'addon-x-cannot-run-without-y' => _x( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'freemius' ),
296
+ 'addon-x-cannot-run-without-parent' => _x( '%s cannot run without the plugin.', 'addonX cannot run...', 'freemius' ),
297
+ 'plugin-x-activation-message' => _x( '%s activation was successfully completed.', 'pluginX activation was successfully...', 'freemius' ),
298
+ 'features-and-pricing' => _x( 'Features & Pricing', 'Plugin installer section title', 'freemius' ),
299
+ );
freemius/includes/managers/class-fs-admin-menu-manager.php ADDED
@@ -0,0 +1,549 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Menu_Manager {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ protected $_plugin_slug;
21
+
22
+ /**
23
+ * @since 1.0.6
24
+ *
25
+ * @var string
26
+ */
27
+ private $_menu_slug;
28
+ /**
29
+ * @since 1.1.3
30
+ *
31
+ * @var string
32
+ */
33
+ private $_parent_slug;
34
+ /**
35
+ * @since 1.1.3
36
+ *
37
+ * @var string
38
+ */
39
+ private $_parent_type;
40
+ /**
41
+ * @since 1.1.3
42
+ *
43
+ * @var string
44
+ */
45
+ private $_type;
46
+ /**
47
+ * @since 1.1.3
48
+ *
49
+ * @var bool
50
+ */
51
+ private $_is_top_level;
52
+ /**
53
+ * @since 1.1.3
54
+ *
55
+ * @var bool
56
+ */
57
+ private $_is_override_exact;
58
+ /**
59
+ * @since 1.1.3
60
+ *
61
+ * @var string[]bool
62
+ */
63
+ private $_default_submenu_items;
64
+ /**
65
+ * @since 1.1.3
66
+ *
67
+ * @var string
68
+ */
69
+ private $_first_time_path;
70
+
71
+ #endregion Properties
72
+
73
+ /**
74
+ * @var FS_Logger
75
+ */
76
+ protected $_logger;
77
+
78
+ #region Singleton
79
+
80
+ /**
81
+ * @var FS_Admin_Menu_Manager[]
82
+ */
83
+ private static $_instances = array();
84
+
85
+ /**
86
+ * @param string $plugin_slug
87
+ *
88
+ * @return FS_Admin_Notice_Manager
89
+ */
90
+ static function instance( $plugin_slug ) {
91
+ if ( ! isset( self::$_instances[ $plugin_slug ] ) ) {
92
+ self::$_instances[ $plugin_slug ] = new FS_Admin_Menu_Manager( $plugin_slug );
93
+ }
94
+
95
+ return self::$_instances[ $plugin_slug ];
96
+ }
97
+
98
+ protected function __construct( $plugin_slug ) {
99
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $plugin_slug . '_admin_menu', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
100
+
101
+ $this->_plugin_slug = $plugin_slug;
102
+ }
103
+
104
+ #endregion Singleton
105
+
106
+ #region Helpers
107
+
108
+ private function get_option( &$options, $key, $default = false ) {
109
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
110
+ }
111
+
112
+ private function get_bool_option( &$options, $key, $default = false ) {
113
+ return isset( $options[ $key ] ) &&is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
114
+ }
115
+
116
+ #endregion Helpers
117
+
118
+ /**
119
+ * @param array $menu
120
+ * @param bool $is_addon
121
+ */
122
+ function init( $menu, $is_addon = false ) {
123
+ $this->_menu_slug = $menu['slug'];
124
+
125
+ $this->_default_submenu_items = array();
126
+ // @deprecated
127
+ $this->_type = 'page';
128
+ $this->_is_top_level = true;
129
+ $this->_is_override_exact = false;
130
+ $this->_parent_slug = false;
131
+ // @deprecated
132
+ $this->_parent_type = 'page';
133
+
134
+ if ( ! $is_addon && isset( $menu ) ) {
135
+ $this->_default_submenu_items = array(
136
+ 'contact' => $this->get_bool_option( $menu, 'contact', true ),
137
+ 'support' => $this->get_bool_option( $menu, 'support', true ),
138
+ 'account' => $this->get_bool_option( $menu, 'account', true ),
139
+ 'pricing' => $this->get_bool_option( $menu, 'pricing', true ),
140
+ 'addons' => $this->get_bool_option( $menu, 'addons', true ),
141
+ );
142
+
143
+ // @deprecated
144
+ $this->_type = $this->get_option( $menu, 'type', 'page' );
145
+ $this->_is_override_exact = $this->get_bool_option( $menu, 'override_exact' );
146
+
147
+ if ( isset( $menu['parent'] ) ) {
148
+ $this->_parent_slug = $this->get_option( $menu['parent'], 'slug' );
149
+ // @deprecated
150
+ $this->_parent_type = $this->get_option( $menu['parent'], 'type', 'page' );
151
+
152
+ // If parent's slug is different, then it's NOT a top level menu item.
153
+ $this->_is_top_level = ( $this->_parent_slug === $this->_menu_slug );
154
+ } else {
155
+ /**
156
+ * If no parent then top level if:
157
+ * - Has custom admin menu ('page')
158
+ * - CPT menu type ('cpt')
159
+ */
160
+ // $this->_is_top_level = in_array( $this->_type, array(
161
+ // 'cpt',
162
+ // 'page'
163
+ // ) );
164
+ }
165
+
166
+ $this->_first_time_path = $this->get_option( $menu, 'first-path', false );
167
+ if ( ! empty( $this->_first_time_path ) && is_string( $this->_first_time_path ) ) {
168
+ $this->_first_time_path = admin_url( $this->_first_time_path, 'admin' );
169
+ }
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Check if top level menu.
175
+ *
176
+ * @author Vova Feldman (@svovaf)
177
+ * @since 1.1.3
178
+ *
179
+ * @return bool False if submenu item.
180
+ */
181
+ function is_top_level() {
182
+ return $this->_is_top_level;
183
+ }
184
+
185
+ /**
186
+ * Check if the page should be override on exact URL match.
187
+ *
188
+ * @author Vova Feldman (@svovaf)
189
+ * @since 1.1.3
190
+ *
191
+ * @return bool False if submenu item.
192
+ */
193
+ function is_override_exact() {
194
+ return $this->_is_override_exact;
195
+ }
196
+
197
+
198
+ /**
199
+ * Get the path of the page the user should be forwarded to after first activation.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.3
203
+ *
204
+ * @return string
205
+ */
206
+ function get_first_time_path() {
207
+ return $this->_first_time_path;
208
+ }
209
+
210
+ /**
211
+ * Check if plugin's menu item is part of a custom top level menu.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.1.3
215
+ *
216
+ * @return bool
217
+ */
218
+ function has_custom_parent() {
219
+ return ! $this->_is_top_level && is_string( $this->_parent_slug );
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.1.3
225
+ *
226
+ * @return string
227
+ */
228
+ // function slug(){
229
+ // return $this->_menu_slug;
230
+ // }
231
+
232
+ /**
233
+ * @author Vova Feldman (@svovaf)
234
+ * @since 1.1.3
235
+ *
236
+ * @param string $id
237
+ * @param bool $default
238
+ *
239
+ * @return bool
240
+ */
241
+ function is_submenu_item_visible( $id, $default = true ) {
242
+ return fs_apply_filter(
243
+ $this->_plugin_slug,
244
+ 'is_submenu_visible',
245
+ $this->get_bool_option( $this->_default_submenu_items, $id, $default ),
246
+ $id
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Calculates admin settings menu slug.
252
+ * If plugin's menu slug is a file (e.g. CPT), uses plugin's slug as the menu slug.
253
+ *
254
+ * @author Vova Feldman (@svovaf)
255
+ * @since 1.1.3
256
+ *
257
+ * @param string $page
258
+ *
259
+ * @return string
260
+ */
261
+ function get_slug( $page = '' ) {
262
+ return ( ( false === strpos( $this->_menu_slug, '.php?' ) ) ?
263
+ $this->_menu_slug :
264
+ $this->_plugin_slug ) . ( empty( $page ) ? '' : ( '-' . $page ) );
265
+ }
266
+
267
+ /**
268
+ * @author Vova Feldman (@svovaf)
269
+ * @since 1.1.3
270
+ *
271
+ * @return string
272
+ */
273
+ function get_parent_slug() {
274
+ return $this->_parent_slug;
275
+ }
276
+
277
+ /**
278
+ * @author Vova Feldman (@svovaf)
279
+ * @since 1.1.3
280
+ *
281
+ * @return string
282
+ */
283
+ function get_type() {
284
+ return $this->_type;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.3
290
+ *
291
+ * @return bool
292
+ */
293
+ function is_cpt() {
294
+ return ( 0 === strpos( $this->_menu_slug, 'edit.php?post_type=' ) ||
295
+ // Back compatibility.
296
+ 'cpt' === $this->_type
297
+ );
298
+ }
299
+
300
+ /**
301
+ * @author Vova Feldman (@svovaf)
302
+ * @since 1.1.3
303
+ *
304
+ * @return string
305
+ */
306
+ function get_parent_type() {
307
+ return $this->_parent_type;
308
+ }
309
+
310
+ /**
311
+ * @author Vova Feldman (@svovaf)
312
+ * @since 1.1.3
313
+ *
314
+ * @return string
315
+ */
316
+ function get_raw_slug() {
317
+ return $this->_menu_slug;
318
+ }
319
+
320
+ /**
321
+ * Get plugin's original menu slug.
322
+ *
323
+ * @author Vova Feldman (@svovaf)
324
+ * @since 1.1.3
325
+ *
326
+ * @return string
327
+ */
328
+ function get_original_menu_slug() {
329
+ if ( 'cpt' === $this->_type ) {
330
+ return add_query_arg( array(
331
+ 'post_type' => $this->_menu_slug
332
+ ), 'edit.php' );
333
+ }
334
+
335
+ if ( false === strpos( $this->_menu_slug, '.php?' ) ) {
336
+ return $this->_menu_slug;
337
+ } else {
338
+ return $this->_plugin_slug;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * @author Vova Feldman (@svovaf)
344
+ * @since 1.1.3
345
+ *
346
+ * @return string
347
+ */
348
+ function get_top_level_menu_slug() {
349
+ return $this->has_custom_parent() ?
350
+ $this->get_parent_slug() :
351
+ $this->get_raw_slug();
352
+ }
353
+
354
+ /**
355
+ * Is user on plugin's admin activation page.
356
+ *
357
+ * @author Vova Feldman (@svovaf)
358
+ * @since 1.0.8
359
+ *
360
+ * @return bool
361
+ */
362
+ function is_activation_page() {
363
+ return isset( $_GET['page'] ) &&
364
+ ( ( strtolower( $this->_menu_slug ) === strtolower( $_GET['page'] ) ) ||
365
+ ( strtolower( $this->_plugin_slug ) === strtolower( $_GET['page'] ) ) );
366
+ }
367
+
368
+ #region Submenu Override
369
+
370
+ /**
371
+ * Override submenu's action.
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ * @since 1.1.0
375
+ *
376
+ * @param string $parent_slug
377
+ * @param string $menu_slug
378
+ * @param callable $function
379
+ *
380
+ * @return false|string If submenu exist, will return the hook name.
381
+ */
382
+ function override_submenu_action( $parent_slug, $menu_slug, $function ) {
383
+ global $submenu;
384
+
385
+ $menu_slug = plugin_basename( $menu_slug );
386
+ $parent_slug = plugin_basename( $parent_slug );
387
+
388
+ if ( ! isset( $submenu[ $parent_slug ] ) ) {
389
+ // Parent menu not exist.
390
+ return false;
391
+ }
392
+
393
+ $found_submenu_item = false;
394
+ foreach ( $submenu[ $parent_slug ] as $submenu_item ) {
395
+ if ( $menu_slug === $submenu_item[2] ) {
396
+ $found_submenu_item = $submenu_item;
397
+ break;
398
+ }
399
+ }
400
+
401
+ if ( false === $found_submenu_item ) {
402
+ // Submenu item not found.
403
+ return false;
404
+ }
405
+
406
+ // Remove current function.
407
+ $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
408
+ remove_all_actions( $hookname );
409
+
410
+ // Attach new action.
411
+ add_action( $hookname, $function );
412
+
413
+ return $hookname;
414
+ }
415
+
416
+ #endregion Submenu Override
417
+
418
+ #region Top level menu Override
419
+
420
+ /**
421
+ * Find plugin's admin dashboard main menu item.
422
+ *
423
+ * @author Vova Feldman (@svovaf)
424
+ * @since 1.0.2
425
+ *
426
+ * @return string[]|false
427
+ */
428
+ private function find_top_level_menu() {
429
+ global $menu;
430
+
431
+ $position = - 1;
432
+ $found_menu = false;
433
+
434
+ $menu_slug = $this->get_raw_slug();
435
+
436
+ $hook_name = get_plugin_page_hookname( $menu_slug, '' );
437
+ foreach ( $menu as $pos => $m ) {
438
+ if ( $menu_slug === $m[2] ) {
439
+ $position = $pos;
440
+ $found_menu = $m;
441
+ break;
442
+ }
443
+ }
444
+
445
+ if ( false === $found_menu ) {
446
+ return false;
447
+ }
448
+
449
+ return array(
450
+ 'menu' => $found_menu,
451
+ 'position' => $position,
452
+ 'hook_name' => $hook_name
453
+ );
454
+ }
455
+
456
+ /**
457
+ * Remove all sub-menu items.
458
+ *
459
+ * @author Vova Feldman (@svovaf)
460
+ * @since 1.0.7
461
+ *
462
+ * @return bool If submenu with plugin's menu slug was found.
463
+ */
464
+ private function remove_all_submenu_items() {
465
+ global $submenu;
466
+
467
+ $menu_slug = $this->get_raw_slug();
468
+
469
+ if ( ! isset( $submenu[ $menu_slug ] ) ) {
470
+ return false;
471
+ }
472
+
473
+ $submenu[ $menu_slug ] = array();
474
+
475
+ return true;
476
+ }
477
+
478
+ /**
479
+ *
480
+ * @author Vova Feldman (@svovaf)
481
+ * @since 1.0.9
482
+ *
483
+ * @return array[string]mixed
484
+ */
485
+ function remove_menu_item() {
486
+ $this->_logger->entrance();
487
+
488
+ // Find main menu item.
489
+ $menu = $this->find_top_level_menu();
490
+
491
+ if ( false === $menu ) {
492
+ return false;
493
+ }
494
+
495
+ // Remove it with its actions.
496
+ remove_all_actions( $menu['hook_name'] );
497
+
498
+ // Remove all submenu items.
499
+ $this->remove_all_submenu_items();
500
+
501
+ return $menu;
502
+ }
503
+
504
+ /**
505
+ *
506
+ * @author Vova Feldman (@svovaf)
507
+ * @since 1.1.4
508
+ *
509
+ * @param callable $function
510
+ *
511
+ * @return array[string]mixed
512
+ */
513
+ function override_menu_item( $function ) {
514
+ $found_menu = $this->remove_menu_item();
515
+
516
+ if ( false === $found_menu ) {
517
+ return false;
518
+ }
519
+
520
+ if ( ! $this->is_top_level() || ! $this->is_cpt() ) {
521
+ $menu_slug = plugin_basename( $this->get_slug() );
522
+
523
+ $hookname = get_plugin_page_hookname( $menu_slug, '' );
524
+
525
+ // Override menu action.
526
+ add_action( $hookname, $function );
527
+ } else {
528
+ global $menu;
529
+
530
+ // Create new top-level menu action.
531
+ $hookname = add_menu_page(
532
+ $found_menu['menu'][3],
533
+ $found_menu['menu'][0],
534
+ 'manage_options',
535
+ $this->get_slug(),
536
+ $function,
537
+ $found_menu['menu'][6],
538
+ $found_menu['position']
539
+ );
540
+
541
+ // Remove original CPT menu.
542
+ unset( $menu[ $found_menu['position'] ] );
543
+ }
544
+
545
+ return $hookname;
546
+ }
547
+
548
+ #endregion Top level menu Override
549
+ }
freemius/includes/managers/class-fs-admin-notice-manager.php ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Notice_Manager {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_slug;
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_title;
22
+ /**
23
+ * @var array[]
24
+ */
25
+ private $_admin_messages = array();
26
+ /**
27
+ * @var FS_Key_Value_Storage
28
+ */
29
+ private $_sticky_storage;
30
+ /**
31
+ * @var FS_Plugin_Manager[]
32
+ */
33
+ private static $_instances = array();
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ protected $_logger;
38
+
39
+ /**
40
+ * @param string $slug
41
+ * @param string $title
42
+ *
43
+ * @return FS_Admin_Notice_Manager
44
+ */
45
+ static function instance( $slug, $title = '' ) {
46
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
47
+ self::$_instances[ $slug ] = new FS_Admin_Notice_Manager( $slug, $title );
48
+ }
49
+
50
+ return self::$_instances[ $slug ];
51
+ }
52
+
53
+ protected function __construct( $slug, $title = '' ) {
54
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_data', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
55
+
56
+ $this->_slug = $slug;
57
+ $this->_title = ! empty( $title ) ? $title : '';
58
+ $this->_sticky_storage = FS_Key_Value_Storage::instance( 'admin_notices', $this->_slug );
59
+
60
+ if ( is_admin() ) {
61
+ if ( 0 < count( $this->_sticky_storage ) ) {
62
+ // If there are sticky notices for the current slug, add a callback
63
+ // to the AJAX action that handles message dismiss.
64
+ add_action( "wp_ajax_{$slug}_dismiss_notice_action", array(
65
+ &$this,
66
+ 'dismiss_notice_ajax_callback'
67
+ ) );
68
+
69
+ foreach ( $this->_sticky_storage as $id => $msg ) {
70
+ // Add admin notice.
71
+ $this->add(
72
+ $msg['message'],
73
+ $msg['title'],
74
+ $msg['type'],
75
+ true,
76
+ $msg['all'],
77
+ $msg['id'],
78
+ false
79
+ );
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Remove sticky message by ID.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.7
90
+ *
91
+ */
92
+ function dismiss_notice_ajax_callback() {
93
+ $this->_sticky_storage->remove( $_POST['message_id'] );
94
+ wp_die();
95
+ }
96
+
97
+ /**
98
+ * Rendered sticky message dismiss JavaScript.
99
+ *
100
+ * @author Vova Feldman (@svovaf)
101
+ * @since 1.0.7
102
+ */
103
+ static function _add_sticky_dismiss_javascript() {
104
+ $params = array();
105
+ fs_require_once_template( 'sticky-admin-notice-js.php', $params );
106
+ }
107
+
108
+ private static $_added_sticky_javascript = false;
109
+
110
+ /**
111
+ * Hook to the admin_footer to add sticky message dismiss JavaScript handler.
112
+ *
113
+ * @author Vova Feldman (@svovaf)
114
+ * @since 1.0.7
115
+ */
116
+ private static function has_sticky_messages() {
117
+ if ( ! self::$_added_sticky_javascript ) {
118
+ add_action( 'admin_footer', array( 'FS_Admin_Notice_Manager', '_add_sticky_dismiss_javascript' ) );
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Handle admin_notices by printing the admin messages stacked in the queue.
124
+ *
125
+ * @author Vova Feldman (@svovaf)
126
+ * @since 1.0.4
127
+ *
128
+ */
129
+ function _admin_notices_hook() {
130
+ $notice_type = 'admin_notices';
131
+
132
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
133
+ return;
134
+ }
135
+
136
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
137
+ fs_require_template( 'admin-notice.php', $msg );
138
+
139
+ if ( $msg['sticky'] ) {
140
+ self::has_sticky_messages();
141
+ }
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Handle all_admin_notices by printing the admin messages stacked in the queue.
147
+ *
148
+ * @author Vova Feldman (@svovaf)
149
+ * @since 1.0.4
150
+ *
151
+ */
152
+ function _all_admin_notices_hook() {
153
+ $notice_type = 'all_admin_notices';
154
+
155
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
156
+ return;
157
+ }
158
+
159
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
160
+ fs_require_template( 'all-admin-notice.php', $msg );
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Enqueue common stylesheet to style admin notice.
166
+ *
167
+ * @author Vova Feldman (@svovaf)
168
+ * @since 1.0.7
169
+ */
170
+ function _enqueue_styles() {
171
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
172
+ }
173
+
174
+ /**
175
+ * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
176
+ *
177
+ * @author Vova Feldman (@svovaf)
178
+ * @since 1.0.4
179
+ *
180
+ * @param string $message
181
+ * @param string $title
182
+ * @param string $type
183
+ * @param bool $is_sticky
184
+ * @param bool $all_admin
185
+ * @param string $id Message ID
186
+ * @param bool $store_if_sticky
187
+ *
188
+ * @uses add_action()
189
+ */
190
+ function add( $message, $title = '', $type = 'success', $is_sticky = false, $all_admin = false, $id = '', $store_if_sticky = true ) {
191
+ $key = ( $all_admin ? 'all_admin_notices' : 'admin_notices' );
192
+
193
+ if ( ! isset( $this->_admin_messages[ $key ] ) ) {
194
+ $this->_admin_messages[ $key ] = array();
195
+
196
+ add_action( $key, array( &$this, "_{$key}_hook" ) );
197
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_styles' ) );
198
+
199
+ }
200
+
201
+ if ( '' === $id ) {
202
+ $id = md5( $title . ' ' . $message . ' ' . $type );
203
+ }
204
+
205
+ $message_object = array(
206
+ 'message' => $message,
207
+ 'title' => $title,
208
+ 'type' => $type,
209
+ 'sticky' => $is_sticky,
210
+ 'id' => $id,
211
+ 'all' => $all_admin,
212
+ 'slug' => $this->_slug,
213
+ 'plugin' => $this->_title,
214
+ );
215
+
216
+ if ( $is_sticky && $store_if_sticky ) {
217
+ $this->_sticky_storage->{$id} = $message_object;
218
+ }
219
+
220
+ $this->_admin_messages[ $key ][ $id ] = $message_object;
221
+ }
222
+
223
+ /**
224
+ * @author Vova Feldman (@svovaf)
225
+ * @since 1.0.7
226
+ *
227
+ * @param string $ids
228
+ */
229
+ function remove_sticky( $ids ) {
230
+ if ( ! is_array( $ids ) ) {
231
+ $ids = array( $ids );
232
+ }
233
+
234
+ foreach ( $ids as $id ) {
235
+ // Remove from sticky storage.
236
+ $this->_sticky_storage->remove( $id );
237
+
238
+ // Remove from current admin messages.
239
+ if ( isset( $this->_admin_messages['all_admin_notices'] ) && isset( $this->_admin_messages['all_admin_notices'][ $id ] ) ) {
240
+ unset( $this->_admin_messages['all_admin_notices'][ $id ] );
241
+ }
242
+ if ( isset( $this->_admin_messages['admin_notices'] ) && isset( $this->_admin_messages['admin_notices'][ $id ] ) ) {
243
+ unset( $this->_admin_messages['admin_notices'][ $id ] );
244
+ }
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Check if sticky message exists by id.
250
+ *
251
+ * @author Vova Feldman (@svovaf)
252
+ * @since 1.0.9
253
+ *
254
+ * @param $id
255
+ *
256
+ * @return bool
257
+ */
258
+ function has_sticky( $id ) {
259
+ return isset( $this->_sticky_storage[ $id ] );
260
+ }
261
+
262
+ /**
263
+ * Adds sticky admin notification.
264
+ *
265
+ * @author Vova Feldman (@svovaf)
266
+ * @since 1.0.7
267
+ *
268
+ * @param string $message
269
+ * @param string $id Message ID
270
+ * @param string $title
271
+ * @param string $type
272
+ * @param bool $all_admin
273
+ */
274
+ function add_sticky( $message, $id, $title = '', $type = 'success', $all_admin = false ) {
275
+ $this->add( $message, $title, $type, true, $all_admin, $id );
276
+ }
277
+
278
+ /**
279
+ * Clear all sticky messages.
280
+ *
281
+ * @author Vova Feldman (@svovaf)
282
+ * @since 1.0.8
283
+ */
284
+ function clear_all_sticky() {
285
+ $this->_sticky_storage->clear_all();
286
+ }
287
+
288
+ /**
289
+ * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
290
+ *
291
+ * @author Vova Feldman (@svovaf)
292
+ * @since 1.0.4
293
+ *
294
+ * @param string $message
295
+ * @param string $title
296
+ * @param string $type
297
+ * @param bool $is_sticky
298
+ * @param string $id Message ID
299
+ */
300
+ function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
301
+ $this->add( $message, $title, $type, $is_sticky, true, $id );
302
+ }
303
+ }
freemius/includes/managers/class-fs-cache-manager.php ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Cache_Manager {
14
+ /**
15
+ * @var FS_Option_Manager
16
+ */
17
+ private $_options;
18
+ /**
19
+ * @var FS_Logger
20
+ */
21
+ private $_logger;
22
+
23
+ /**
24
+ * @var FS_Cache_Manager[]
25
+ */
26
+ private static $_MANAGERS = array();
27
+
28
+ /**
29
+ * @author Vova Feldman (@svovaf)
30
+ * @since 1.1.3
31
+ *
32
+ * @param string $id
33
+ */
34
+ private function __construct( $id ) {
35
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
36
+
37
+ $this->_logger->entrance();
38
+ $this->_logger->log( 'id = ' . $id );
39
+
40
+ $this->_options = FS_Option_Manager::get_manager( $id, true );
41
+ }
42
+
43
+ /**
44
+ * @author Vova Feldman (@svovaf)
45
+ * @since 1.1.6
46
+ *
47
+ * @param $id
48
+ *
49
+ * @return FS_Cache_Manager
50
+ */
51
+ static function get_manager( $id ) {
52
+ $id = strtolower( $id );
53
+
54
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
55
+ self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
56
+ }
57
+
58
+ return self::$_MANAGERS[ $id ];
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.6
64
+ *
65
+ * @return bool
66
+ */
67
+ function is_empty() {
68
+ $this->_logger->entrance();
69
+
70
+ return $this->_options->is_empty();
71
+ }
72
+
73
+ /**
74
+ * @author Vova Feldman (@svovaf)
75
+ * @since 1.1.6
76
+ */
77
+ function clear() {
78
+ $this->_logger->entrance();
79
+
80
+ $this->_options->clear( true );
81
+ }
82
+
83
+ /**
84
+ * Delete cache manager from DB.
85
+ *
86
+ * @author Vova Feldman (@svovaf)
87
+ * @since 1.0.9
88
+ */
89
+ function delete() {
90
+ $this->_options->delete();
91
+ }
92
+
93
+ /**
94
+ * Check if there's a cached item.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.6
98
+ *
99
+ * @param string $key
100
+ *
101
+ * @return bool
102
+ */
103
+ function has( $key ) {
104
+ $cache_entry = $this->_options->get_option( $key, false );
105
+
106
+ return ( is_object( $cache_entry ) &&
107
+ isset( $cache_entry->timestamp ) &&
108
+ is_numeric( $cache_entry->timestamp )
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Check if there's a valid cached item.
114
+ *
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.1.6
117
+ *
118
+ * @param string $key
119
+ *
120
+ * @return bool
121
+ */
122
+ function has_valid( $key ) {
123
+ $cache_entry = $this->_options->get_option( $key, false );
124
+
125
+ return ( is_object( $cache_entry ) &&
126
+ isset( $cache_entry->timestamp ) &&
127
+ is_numeric( $cache_entry->timestamp ) &&
128
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
129
+ );
130
+ }
131
+
132
+ /**
133
+ * @author Vova Feldman (@svovaf)
134
+ * @since 1.1.6
135
+ *
136
+ * @param string $key
137
+ * @param mixed $default
138
+ *
139
+ * @return mixed
140
+ */
141
+ function get( $key, $default = null ) {
142
+ $this->_logger->entrance( 'key = ' . $key );
143
+
144
+ $cache_entry = $this->_options->get_option( $key, false );
145
+
146
+ if ( is_object( $cache_entry ) &&
147
+ isset( $cache_entry->timestamp ) &&
148
+ is_numeric( $cache_entry->timestamp )
149
+ ) {
150
+ return $cache_entry->result;
151
+ }
152
+
153
+ return $default;
154
+ }
155
+
156
+ /**
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.1.6
159
+ *
160
+ * @param string $key
161
+ * @param mixed $default
162
+ *
163
+ * @return mixed
164
+ */
165
+ function get_valid( $key, $default = null ) {
166
+ $this->_logger->entrance( 'key = ' . $key );
167
+
168
+ $cache_entry = $this->_options->get_option( $key, false );
169
+
170
+ if ( is_object( $cache_entry ) &&
171
+ isset( $cache_entry->timestamp ) &&
172
+ is_numeric( $cache_entry->timestamp ) &&
173
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
174
+ ) {
175
+ return $cache_entry->result;
176
+ }
177
+
178
+ return $default;
179
+ }
180
+
181
+ /**
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.1.6
184
+ *
185
+ * @param string $key
186
+ * @param mixed $value
187
+ * @param int $expiration
188
+ */
189
+ function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
190
+ $this->_logger->entrance( 'key = ' . $key );
191
+
192
+ $cache_entry = new stdClass();
193
+ $cache_entry->result = $value;
194
+ $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME + $expiration;
195
+ $this->_options->set_option( $key, $cache_entry, true );
196
+ }
197
+
198
+ /**
199
+ * Purge cached item.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.6
203
+ *
204
+ * @param string $key
205
+ */
206
+ function purge( $key ) {
207
+ $this->_logger->entrance( 'key = ' . $key );
208
+
209
+ $this->_options->unset_option( $key, true );
210
+ }
211
+ }
freemius/includes/managers/class-fs-key-value-storage.php ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Key_Value_Storage implements ArrayAccess, Iterator, Countable {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_id;
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_slug;
22
+ /**
23
+ * @var array
24
+ */
25
+ protected $_data;
26
+
27
+ /**
28
+ * @var FS_Plugin_Manager[]
29
+ */
30
+ private static $_instances = array();
31
+ /**
32
+ * @var FS_Logger
33
+ */
34
+ protected $_logger;
35
+
36
+ /**
37
+ * @param string $id
38
+ * @param string $slug
39
+ *
40
+ * @return FS_Key_Value_Storage
41
+ */
42
+ static function instance( $id, $slug ) {
43
+ $key = $id . ':' . $slug;
44
+ if ( ! isset( self::$_instances[ $key ] ) ) {
45
+ self::$_instances[ $key ] = new FS_Key_Value_Storage( $id, $slug );
46
+ }
47
+
48
+ return self::$_instances[ $key ];
49
+ }
50
+
51
+ protected function __construct( $id, $slug ) {
52
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
+
54
+ $this->_slug = $slug;
55
+ $this->_id = $id;
56
+ $this->load();
57
+ }
58
+
59
+ protected function get_option_manager() {
60
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
61
+ }
62
+
63
+ protected function get_all_data() {
64
+ return $this->get_option_manager()->get_option( $this->_id, array() );
65
+ }
66
+
67
+ /**
68
+ * Load plugin data from local DB.
69
+ *
70
+ * @author Vova Feldman (@svovaf)
71
+ * @since 1.0.7
72
+ */
73
+ function load() {
74
+ $all_plugins_data = $this->get_all_data();
75
+ $this->_data = isset( $all_plugins_data[ $this->_slug ] ) ?
76
+ $all_plugins_data[ $this->_slug ] :
77
+ array();
78
+ }
79
+
80
+ /**
81
+ * @author Vova Feldman (@svovaf)
82
+ * @since 1.0.7
83
+ *
84
+ * @param string $key
85
+ * @param mixed $value
86
+ * @param bool $flush
87
+ */
88
+ function store( $key, $value, $flush = true ) {
89
+ if ( array_key_exists( $key, $this->_data ) && $value === $this->_data[ $key ] ) {
90
+ // No need to store data if the value wasn't changed.
91
+ return;
92
+ }
93
+
94
+ $all_data = $this->get_all_data();
95
+
96
+ $this->_data[ $key ] = $value;
97
+
98
+ $all_data[ $this->_slug ] = $this->_data;
99
+
100
+ $options_manager = $this->get_option_manager();
101
+ $options_manager->set_option( $this->_id, $all_data, $flush );
102
+ }
103
+
104
+ /**
105
+ * @author Vova Feldman (@svovaf)
106
+ * @since 1.0.7
107
+ *
108
+ * @param bool $store
109
+ * @param string[] $exceptions Set of keys to keep and not clear.
110
+ */
111
+ function clear_all( $store = true, $exceptions = array() ) {
112
+ $new_data = array();
113
+ foreach ( $exceptions as $key ) {
114
+ if ( isset( $this->_data[ $key ] ) ) {
115
+ $new_data[ $key ] = $this->_data[ $key ];
116
+ }
117
+ }
118
+
119
+ $this->_data = $new_data;
120
+
121
+ if ( $store ) {
122
+ $all_data = $this->get_all_data();
123
+ $all_data[ $this->_slug ] = $this->_data;
124
+ $options_manager = $this->get_option_manager();
125
+ $options_manager->set_option( $this->_id, $all_data, true );
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Delete key-value storage.
131
+ *
132
+ * @author Vova Feldman (@svovaf)
133
+ * @since 1.0.9
134
+ */
135
+ function delete() {
136
+ $this->_data = array();
137
+
138
+ $all_data = $this->get_all_data();
139
+ unset( $all_data[ $this->_slug ] );
140
+ $options_manager = $this->get_option_manager();
141
+ $options_manager->set_option( $this->_id, $all_data, true );
142
+ }
143
+
144
+ /**
145
+ * @author Vova Feldman (@svovaf)
146
+ * @since 1.0.7
147
+ *
148
+ * @param string $key
149
+ * @param bool $store
150
+ */
151
+ function remove( $key, $store = true ) {
152
+ if ( ! array_key_exists( $key, $this->_data ) ) {
153
+ return;
154
+ }
155
+
156
+ unset( $this->_data[ $key ] );
157
+
158
+ if ( $store ) {
159
+ $all_data = $this->get_all_data();
160
+ $all_data[ $this->_slug ] = $this->_data;
161
+ $options_manager = $this->get_option_manager();
162
+ $options_manager->set_option( $this->_id, $all_data, true );
163
+ }
164
+ }
165
+
166
+ /**
167
+ * @author Vova Feldman (@svovaf)
168
+ * @since 1.0.7
169
+ *
170
+ * @param string $key
171
+ * @param mixed $default
172
+ *
173
+ * @return bool|\FS_Plugin
174
+ */
175
+ function get( $key, $default = false ) {
176
+ return array_key_exists( $key, $this->_data ) ?
177
+ $this->_data[ $key ] :
178
+ $default;
179
+ }
180
+
181
+
182
+ /* ArrayAccess + Magic Access (better for refactoring)
183
+ -----------------------------------------------------------------------------------*/
184
+ function __set( $k, $v ) {
185
+ $this->store( $k, $v );
186
+ }
187
+
188
+ function __isset( $k ) {
189
+ return array_key_exists( $k, $this->_data );
190
+ }
191
+
192
+ function __unset( $k ) {
193
+ $this->remove( $k );
194
+ }
195
+
196
+ function __get( $k ) {
197
+ return $this->get( $k, null );
198
+ }
199
+
200
+ function offsetSet( $k, $v ) {
201
+ if ( is_null( $k ) ) {
202
+ throw new Exception( 'Can\'t append value to request params.' );
203
+ } else {
204
+ $this->{$k} = $v;
205
+ }
206
+ }
207
+
208
+ function offsetExists( $k ) {
209
+ return array_key_exists( $k, $this->_data );
210
+ }
211
+
212
+ function offsetUnset( $k ) {
213
+ unset( $this->$k );
214
+ }
215
+
216
+ function offsetGet( $k ) {
217
+ return $this->get( $k, null );
218
+ }
219
+
220
+ /**
221
+ * (PHP 5 &gt;= 5.0.0)<br/>
222
+ * Return the current element
223
+ *
224
+ * @link http://php.net/manual/en/iterator.current.php
225
+ * @return mixed Can return any type.
226
+ */
227
+ public function current() {
228
+ return current( $this->_data );
229
+ }
230
+
231
+ /**
232
+ * (PHP 5 &gt;= 5.0.0)<br/>
233
+ * Move forward to next element
234
+ *
235
+ * @link http://php.net/manual/en/iterator.next.php
236
+ * @return void Any returned value is ignored.
237
+ */
238
+ public function next() {
239
+ return next( $this->_data );
240
+ }
241
+
242
+ /**
243
+ * (PHP 5 &gt;= 5.0.0)<br/>
244
+ * Return the key of the current element
245
+ *
246
+ * @link http://php.net/manual/en/iterator.key.php
247
+ * @return mixed scalar on success, or null on failure.
248
+ */
249
+ public function key() {
250
+ return key( $this->_data );
251
+ }
252
+
253
+ /**
254
+ * (PHP 5 &gt;= 5.0.0)<br/>
255
+ * Checks if current position is valid
256
+ *
257
+ * @link http://php.net/manual/en/iterator.valid.php
258
+ * @return boolean The return value will be casted to boolean and then evaluated.
259
+ * Returns true on success or false on failure.
260
+ */
261
+ public function valid() {
262
+ $key = key( $this->_data );
263
+
264
+ return ( $key !== null && $key !== false );
265
+ }
266
+
267
+ /**
268
+ * (PHP 5 &gt;= 5.0.0)<br/>
269
+ * Rewind the Iterator to the first element
270
+ *
271
+ * @link http://php.net/manual/en/iterator.rewind.php
272
+ * @return void Any returned value is ignored.
273
+ */
274
+ public function rewind() {
275
+ reset( $this->_data );
276
+ }
277
+
278
+ /**
279
+ * (PHP 5 &gt;= 5.1.0)<br/>
280
+ * Count elements of an object
281
+ *
282
+ * @link http://php.net/manual/en/countable.count.php
283
+ * @return int The custom count as an integer.
284
+ * </p>
285
+ * <p>
286
+ * The return value is cast to an integer.
287
+ */
288
+ public function count() {
289
+ return count( $this->_data );
290
+ }
291
+ }
freemius/includes/managers/class-fs-license-manager.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_License_Manager /*extends FS_Abstract_Manager*/
14
+ {
15
+ //
16
+ //
17
+ // /**
18
+ // * @var FS_License_Manager[]
19
+ // */
20
+ // private static $_instances = array();
21
+ //
22
+ // static function instance( Freemius $fs ) {
23
+ // $slug = strtolower( $fs->get_slug() );
24
+ //
25
+ // if ( ! isset( self::$_instances[ $slug ] ) ) {
26
+ // self::$_instances[ $slug ] = new FS_License_Manager( $slug, $fs );
27
+ // }
28
+ //
29
+ // return self::$_instances[ $slug ];
30
+ // }
31
+ //
32
+ //// private function __construct($slug) {
33
+ //// parent::__construct($slug);
34
+ //// }
35
+ //
36
+ // function entry_id() {
37
+ // return 'licenses';
38
+ // }
39
+ //
40
+ // function sync( $id ) {
41
+ //
42
+ // }
43
+ //
44
+ // /**
45
+ // * @author Vova Feldman (@svovaf)
46
+ // * @since 1.0.5
47
+ // * @uses FS_Api
48
+ // *
49
+ // * @param number|bool $plugin_id
50
+ // *
51
+ // * @return FS_Plugin_License[]|stdClass Licenses or API error.
52
+ // */
53
+ // function api_get_user_plugin_licenses( $plugin_id = false ) {
54
+ // $api = $this->_fs->get_api_user_scope();
55
+ //
56
+ // if ( ! is_numeric( $plugin_id ) ) {
57
+ // $plugin_id = $this->_fs->get_id();
58
+ // }
59
+ //
60
+ // $result = $api->call( "/plugins/{$plugin_id}/licenses.json" );
61
+ //
62
+ // if ( ! isset( $result->error ) ) {
63
+ // for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
64
+ // $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
65
+ // }
66
+ //
67
+ // $result = $result->licenses;
68
+ // }
69
+ //
70
+ // return $result;
71
+ // }
72
+ //
73
+ // function api_get_many() {
74
+ //
75
+ // }
76
+ //
77
+ // function api_activate( $id ) {
78
+ //
79
+ // }
80
+ //
81
+ // function api_deactivate( $id ) {
82
+ //
83
+ // }
84
+
85
+ /**
86
+ * @param FS_Plugin_License[] $licenses
87
+ *
88
+ * @return bool
89
+ */
90
+ static function has_premium_license( $licenses ) {
91
+ if ( is_array( $licenses ) ) {
92
+ foreach ( $licenses as $license ) {
93
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
94
+ return true;
95
+ }
96
+ }
97
+ }
98
+
99
+ return false;
100
+ }
101
+ }
freemius/includes/managers/class-fs-option-manager.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * 3-layer lazy options manager.
15
+ * layer 3: Memory
16
+ * layer 2: Cache (if there's any caching plugin and if WP_FS__DEBUG_SDK is FALSE)
17
+ * layer 1: Database (options table). All options stored as one option record in the DB to reduce number of DB
18
+ * queries.
19
+ *
20
+ * If load() is not explicitly called, starts as empty manager. Same thing about saving the data - you have to
21
+ * explicitly call store().
22
+ *
23
+ * Class Freemius_Option_Manager
24
+ */
25
+ class FS_Option_Manager {
26
+ /**
27
+ * @var string
28
+ */
29
+ private $_id;
30
+ /**
31
+ * @var array
32
+ */
33
+ private $_options;
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ private $_logger;
38
+
39
+ /**
40
+ * @var FS_Option_Manager[]
41
+ */
42
+ private static $_MANAGERS = array();
43
+
44
+ /**
45
+ * @author Vova Feldman (@svovaf)
46
+ * @since 1.0.3
47
+ *
48
+ * @param string $id
49
+ * @param bool $load
50
+ */
51
+ private function __construct( $id, $load = false ) {
52
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_opt_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
+
54
+ $this->_logger->entrance();
55
+ $this->_logger->log( 'id = ' . $id );
56
+
57
+ $this->_id = $id;
58
+
59
+ if ( $load ) {
60
+ $this->load();
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @author Vova Feldman (@svovaf)
66
+ * @since 1.0.3
67
+ *
68
+ * @param $id
69
+ * @param $load
70
+ *
71
+ * @return FS_Option_Manager
72
+ */
73
+ static function get_manager( $id, $load = false ) {
74
+ $id = strtolower( $id );
75
+
76
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
77
+ self::$_MANAGERS[ $id ] = new FS_Option_Manager( $id, $load );
78
+ } // If load required but not yet loaded, load.
79
+ else if ( $load && ! self::$_MANAGERS[ $id ]->is_loaded() ) {
80
+ self::$_MANAGERS[ $id ]->load();
81
+ }
82
+
83
+ return self::$_MANAGERS[ $id ];
84
+ }
85
+
86
+ private function _get_option_manager_name() {
87
+ // return WP_FS__SLUG . '_' . $this->_id;
88
+ return $this->_id;
89
+ }
90
+
91
+ /**
92
+ * @author Vova Feldman (@svovaf)
93
+ * @since 1.0.3
94
+ *
95
+ * @param bool $flush
96
+ */
97
+ function load( $flush = false ) {
98
+ $this->_logger->entrance();
99
+
100
+ $option_name = $this->_get_option_manager_name();
101
+
102
+ if ( $flush || ! isset( $this->_options ) ) {
103
+ if ( ! WP_FS__DEBUG_SDK ) {
104
+ $this->_options = wp_cache_get( $option_name, WP_FS__SLUG );
105
+ }
106
+
107
+ // $this->_logger->info('wp_cache_get = ' . var_export($this->_options, true));
108
+
109
+ // if ( is_array( $this->_options ) ) {
110
+ // $this->clear();
111
+ // }
112
+
113
+ $cached = true;
114
+
115
+ if ( empty( $this->_options ) ) {
116
+ $this->_options = get_option( $option_name );
117
+
118
+ if ( is_string( $this->_options ) ) {
119
+ $this->_options = json_decode( $this->_options );
120
+ }
121
+
122
+ // $this->_logger->info('get_option = ' . var_export($this->_options, true));
123
+
124
+ if ( false === $this->_options ) {
125
+ $this->clear();
126
+ }
127
+
128
+ $cached = false;
129
+ }
130
+
131
+ if ( ! WP_FS__DEBUG_SDK && ! $cached ) // Set non encoded cache.
132
+ {
133
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * @author Vova Feldman (@svovaf)
140
+ * @since 1.0.3
141
+ *
142
+ * @return bool
143
+ */
144
+ function is_loaded() {
145
+ return isset( $this->_options );
146
+ }
147
+
148
+ /**
149
+ * @author Vova Feldman (@svovaf)
150
+ * @since 1.0.3
151
+ *
152
+ * @return bool
153
+ */
154
+ function is_empty() {
155
+ return ( $this->is_loaded() && false === $this->_options );
156
+ }
157
+
158
+ /**
159
+ * @author Vova Feldman (@svovaf)
160
+ * @since 1.0.6
161
+ *
162
+ * @param bool $flush
163
+ */
164
+ function clear( $flush = false ) {
165
+ $this->_logger->entrance();
166
+
167
+ $this->_options = array();
168
+
169
+ if ( $flush ) {
170
+ $this->store();
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Delete options manager from DB.
176
+ *
177
+ * @author Vova Feldman (@svovaf)
178
+ * @since 1.0.9
179
+ */
180
+ function delete() {
181
+ delete_option( $this->_get_option_manager_name() );
182
+ }
183
+
184
+ /**
185
+ * @author Vova Feldman (@svovaf)
186
+ * @since 1.0.6
187
+ *
188
+ * @param string $option
189
+ *
190
+ * @return bool
191
+ */
192
+ function has_option( $option ) {
193
+ return array_key_exists( $option, $this->_options );
194
+ }
195
+
196
+ /**
197
+ * @author Vova Feldman (@svovaf)
198
+ * @since 1.0.3
199
+ *
200
+ * @param string $option
201
+ * @param mixed $default
202
+ *
203
+ * @return mixed
204
+ */
205
+ function get_option( $option, $default = null ) {
206
+ $this->_logger->entrance( 'option = ' . $option );
207
+
208
+ if ( is_array( $this->_options ) ) {
209
+ return isset( $this->_options[ $option ] ) ? $this->_options[ $option ] : $default;
210
+ } else if ( is_object( $this->_options ) ) {
211
+ return isset( $this->_options->{$option} ) ? $this->_options->{$option} : $default;
212
+ }
213
+
214
+ return $default;
215
+ }
216
+
217
+ /**
218
+ * @author Vova Feldman (@svovaf)
219
+ * @since 1.0.3
220
+ *
221
+ * @param string $option
222
+ * @param mixed $value
223
+ * @param bool $flush
224
+ */
225
+ function set_option( $option, $value, $flush = false ) {
226
+ $this->_logger->entrance( 'option = ' . $option );
227
+
228
+ if ( ! $this->is_loaded() ) {
229
+ $this->clear();
230
+ }
231
+
232
+ if ( is_array( $this->_options ) ) {
233
+ $this->_options[ $option ] = $value;
234
+ } else if ( is_object( $this->_options ) ) {
235
+ $this->_options->{$option} = $value;
236
+ }
237
+
238
+ if ( $flush ) {
239
+ $this->store();
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Unset option.
245
+ *
246
+ * @author Vova Feldman (@svovaf)
247
+ * @since 1.0.3
248
+ *
249
+ * @param string $option
250
+ * @param bool $flush
251
+ */
252
+ function unset_option( $option, $flush = false ) {
253
+ $this->_logger->entrance( 'option = ' . $option );
254
+
255
+ if ( is_array( $this->_options ) ) {
256
+ if ( ! isset( $this->_options[ $option ] ) ) {
257
+ return;
258
+ }
259
+
260
+ unset( $this->_options[ $option ] );
261
+
262
+ } else if ( is_object( $this->_options ) ) {
263
+ if ( ! isset( $this->_options->{$option} ) ) {
264
+ return;
265
+ }
266
+
267
+ unset( $this->_options->{$option} );
268
+ }
269
+
270
+ if ( $flush ) {
271
+ $this->store();
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Dump options to database.
277
+ *
278
+ * @author Vova Feldman (@svovaf)
279
+ * @since 1.0.3
280
+ */
281
+ function store() {
282
+ $this->_logger->entrance();
283
+
284
+ $option_name = $this->_get_option_manager_name();
285
+
286
+ if ( $this->_logger->is_on() ) {
287
+ $this->_logger->info( $option_name . ' = ' . var_export( $this->_options, true ) );
288
+ }
289
+
290
+ // Update DB.
291
+ update_option( $option_name, $this->_options );
292
+
293
+ if ( ! WP_FS__DEBUG_SDK ) {
294
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
295
+ }
296
+ }
297
+ }
freemius/includes/managers/class-fs-plan-manager.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plan_Manager {
14
+ /**
15
+ * @var FS_Plan_Manager
16
+ */
17
+ private static $_instance;
18
+
19
+ /**
20
+ * @return FS_Plan_Manager
21
+ */
22
+ static function instance() {
23
+ if ( ! isset( self::$_instance ) ) {
24
+ self::$_instance = new FS_Plan_Manager();
25
+ }
26
+
27
+ return self::$_instance;
28
+ }
29
+
30
+ private function __construct() {
31
+ }
32
+
33
+ /**
34
+ * @param FS_Plugin_License[] $licenses
35
+ *
36
+ * @return bool
37
+ */
38
+ function has_premium_license( $licenses ) {
39
+ if ( is_array( $licenses ) ) {
40
+ foreach ( $licenses as $license ) {
41
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
42
+ return true;
43
+ }
44
+ }
45
+ }
46
+
47
+ return false;
48
+ }
49
+
50
+ /**
51
+ * Check if plugin has any paid plans.
52
+ *
53
+ * @author Vova Feldman (@svovaf)
54
+ * @since 1.0.7
55
+ *
56
+ * @param FS_Plugin_Plan[] $plans
57
+ *
58
+ * @return bool
59
+ */
60
+ function has_paid_plan( $plans ) {
61
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
62
+ return false;
63
+ }
64
+
65
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
66
+ if ( ! $plans[ $i ]->is_free() ) {
67
+ return true;
68
+ }
69
+ }
70
+
71
+ return false;
72
+ }
73
+
74
+ /**
75
+ * Check if plugin has any free plan, or is it premium only.
76
+ *
77
+ * Note: If no plans configured, assume plugin is free.
78
+ *
79
+ * @author Vova Feldman (@svovaf)
80
+ * @since 1.0.7
81
+ *
82
+ * @param FS_Plugin_Plan[] $plans
83
+ *
84
+ * @return bool
85
+ */
86
+ function has_free_plan( $plans ) {
87
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
88
+ return true;
89
+ }
90
+
91
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
92
+ if ( $plans[ $i ]->is_free() ) {
93
+ return true;
94
+ }
95
+ }
96
+
97
+ return false;
98
+ }
99
+
100
+ /**
101
+ * Find all plans that have trial.
102
+ *
103
+ * @author Vova Feldman (@svovaf)
104
+ * @since 1.0.9
105
+ *
106
+ * @param FS_Plugin_Plan[] $plans
107
+ *
108
+ * @return FS_Plugin_Plan[]
109
+ */
110
+ function get_trial_plans( $plans ) {
111
+ $trial_plans = array();
112
+
113
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
114
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
115
+ if ( $plans[ $i ]->has_trial() ) {
116
+ $trial_plans[] = $plans[ $i ];
117
+ }
118
+ }
119
+ }
120
+
121
+ return $trial_plans;
122
+ }
123
+
124
+ /**
125
+ * Check if plugin has any trial plan.
126
+ *
127
+ * @author Vova Feldman (@svovaf)
128
+ * @since 1.0.9
129
+ *
130
+ * @param FS_Plugin_Plan[] $plans
131
+ *
132
+ * @return bool
133
+ */
134
+ function has_trial_plan( $plans ) {
135
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
136
+ return true;
137
+ }
138
+
139
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
140
+ if ( $plans[ $i ]->has_trial() ) {
141
+ return true;
142
+ }
143
+ }
144
+
145
+ return false;
146
+ }
147
+ }
freemius/includes/managers/class-fs-plugin-manager.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Manager {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_slug;
18
+ /**
19
+ * @var FS_Plugin
20
+ */
21
+ protected $_plugin;
22
+
23
+ /**
24
+ * @var FS_Plugin_Manager[]
25
+ */
26
+ private static $_instances = array();
27
+ /**
28
+ * @var FS_Logger
29
+ */
30
+ protected $_logger;
31
+
32
+ /**
33
+ * @param string $slug
34
+ *
35
+ * @return FS_Plugin_Manager
36
+ */
37
+ static function instance( $slug ) {
38
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
39
+ self::$_instances[ $slug ] = new FS_Plugin_Manager( $slug );
40
+ }
41
+
42
+ return self::$_instances[ $slug ];
43
+ }
44
+
45
+ protected function __construct( $slug ) {
46
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . 'plugins', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
47
+
48
+ $this->_slug = $slug;
49
+ $this->load();
50
+ }
51
+
52
+ protected function get_option_manager() {
53
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
54
+ }
55
+
56
+ protected function get_all_plugins() {
57
+ return $this->get_option_manager()->get_option( 'plugins', array() );
58
+ }
59
+
60
+ /**
61
+ * Load plugin data from local DB.
62
+ *
63
+ * @author Vova Feldman (@svovaf)
64
+ * @since 1.0.6
65
+ */
66
+ function load() {
67
+ $all_plugins = $this->get_all_plugins();
68
+ $this->_plugin = isset( $all_plugins[ $this->_slug ] ) ?
69
+ $all_plugins[ $this->_slug ] :
70
+ null;
71
+ }
72
+
73
+ /**
74
+ * Store plugin on local DB.
75
+ *
76
+ * @author Vova Feldman (@svovaf)
77
+ * @since 1.0.6
78
+ *
79
+ * @param bool|FS_Plugin $plugin
80
+ * @param bool $flush
81
+ *
82
+ * @return bool|\FS_Plugin
83
+ */
84
+ function store( $plugin = false, $flush = true ) {
85
+ $all_plugins = $this->get_all_plugins();
86
+
87
+ if ( false !== $plugin ) {
88
+ $this->_plugin = $plugin;
89
+ }
90
+
91
+ $all_plugins[ $this->_slug ] = $this->_plugin;
92
+
93
+ $options_manager = $this->get_option_manager();
94
+ $options_manager->set_option( 'plugins', $all_plugins, $flush );
95
+
96
+ return $this->_plugin;
97
+ }
98
+
99
+ /**
100
+ * Update local plugin data if different.
101
+ *
102
+ * @author Vova Feldman (@svovaf)
103
+ * @since 1.0.6
104
+ *
105
+ * @param \FS_Plugin $plugin
106
+ * @param bool $store
107
+ *
108
+ * @return bool True if plugin was updated.
109
+ */
110
+ function update( FS_Plugin $plugin, $store = true ) {
111
+ if ( ! ( $this->_plugin instanceof FS_Plugin ) ||
112
+ $this->_plugin->slug != $plugin->slug ||
113
+ $this->_plugin->public_key != $plugin->public_key ||
114
+ $this->_plugin->secret_key != $plugin->secret_key ||
115
+ $this->_plugin->parent_plugin_id != $plugin->parent_plugin_id ||
116
+ $this->_plugin->title != $plugin->title
117
+ ) {
118
+ $this->store( $plugin, $store );
119
+
120
+ return true;
121
+ }
122
+
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * @author Vova Feldman (@svovaf)
128
+ * @since 1.0.6
129
+ *
130
+ * @param FS_Plugin $plugin
131
+ * @param bool $store
132
+ */
133
+ function set( FS_Plugin $plugin, $store = false ) {
134
+ $this->_plugin = $plugin;
135
+
136
+ if ( $store ) {
137
+ $this->store();
138
+ }
139
+ }
140
+
141
+ /**
142
+ * @author Vova Feldman (@svovaf)
143
+ * @since 1.0.6
144
+ *
145
+ * @return bool|\FS_Plugin
146
+ */
147
+ function get() {
148
+ return isset( $this->_plugin ) ?
149
+ $this->_plugin :
150
+ false;
151
+ }
152
+
153
+
154
+ }
freemius/includes/sdk/Exceptions/ArgumentNotExistException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_ArgumentNotExistException extends Freemius_InvalidArgumentException { }
freemius/includes/sdk/Exceptions/EmptyArgumentException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_EmptyArgumentException extends Freemius_InvalidArgumentException { }
freemius/includes/sdk/Exceptions/Exception.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Thrown when an API call returns an exception.
4
+ *
5
+ */
6
+ class Freemius_Exception extends Exception
7
+ {
8
+ protected $_result;
9
+ protected $_type;
10
+ protected $_code;
11
+
12
+ /**
13
+ * Make a new API Exception with the given result.
14
+ *
15
+ * @param array $result The result from the API server.
16
+ */
17
+ public function __construct($result)
18
+ {
19
+ $this->_result = $result;
20
+
21
+ $code = 0;
22
+ $message = 'Unknown error, please check GetResult().';
23
+ $type = '';
24
+
25
+ if (isset($result['error']) && is_array($result['error']))
26
+ {
27
+ if (isset($result['error']['code']))
28
+ $code = $result['error']['code'];
29
+ if (isset($result['error']['message']))
30
+ $message = $result['error']['message'];
31
+ if (isset($result['error']['type']))
32
+ $type = $result['error']['type'];
33
+ }
34
+
35
+ $this->_type = $type;
36
+ $this->_code = $code;
37
+
38
+ parent::__construct($message, is_numeric($code) ? $code : 0);
39
+ }
40
+
41
+ /**
42
+ * Return the associated result object returned by the API server.
43
+ *
44
+ * @return array The result from the API server
45
+ */
46
+ public function getResult()
47
+ {
48
+ return $this->_result;
49
+ }
50
+
51
+ public function getStringCode()
52
+ {
53
+ return $this->_code;
54
+ }
55
+
56
+ public function getType()
57
+ {
58
+ return $this->_type;
59
+ }
60
+
61
+ /**
62
+ * To make debugging easier.
63
+ *
64
+ * @return string The string representation of the error
65
+ */
66
+ public function __toString()
67
+ {
68
+ $str = $this->getType() . ': ';
69
+
70
+ if ($this->code != 0)
71
+ $str .= $this->getStringCode() . ': ';
72
+
73
+ return $str . $this->getMessage();
74
+ }
75
+ }
freemius/includes/sdk/Exceptions/InvalidArgumentException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_InvalidArgumentException extends Freemius_Exception { }
freemius/includes/sdk/Exceptions/OAuthException.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_OAuthException extends Freemius_Exception
7
+ {
8
+ public function __construct($pResult)
9
+ {
10
+ parent::__construct($pResult);
11
+ }
12
+ }
freemius/includes/sdk/Freemius.php ADDED
@@ -0,0 +1,533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2014 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ require_once( dirname( __FILE__ ) . '/FreemiusBase.php' );
19
+
20
+ define( 'FS_SDK__USER_AGENT', 'fs-php-' . Freemius_Api_Base::VERSION );
21
+
22
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_CURL' ) ) {
23
+ define( 'FS_SDK__SIMULATE_NO_CURL', false );
24
+ }
25
+
26
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
27
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
28
+ }
29
+
30
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
+ }
33
+
34
+ define( 'FS_SDK__HAS_CURL', ! FS_SDK__SIMULATE_NO_CURL && function_exists( 'curl_version' ) );
35
+
36
+ if ( ! FS_SDK__HAS_CURL ) {
37
+ $curl_version = array( 'version' => '7.0.0' );
38
+ } else {
39
+ $curl_version = curl_version();
40
+ }
41
+
42
+ define( 'FS_API__PROTOCOL', version_compare( $curl_version['version'], '7.37', '>=' ) ? 'https' : 'http' );
43
+
44
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
45
+ define( 'FS_API__ADDRESS', '://api.freemius.com' );
46
+ }
47
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
48
+ define( 'FS_API__SANDBOX_ADDRESS', '://sandbox-api.freemius.com' );
49
+ }
50
+
51
+ class Freemius_Api extends Freemius_Api_Base {
52
+ /**
53
+ * Default options for curl.
54
+ */
55
+ public static $CURL_OPTS = array(
56
+ CURLOPT_CONNECTTIMEOUT => 10,
57
+ CURLOPT_RETURNTRANSFER => true,
58
+ CURLOPT_TIMEOUT => 60,
59
+ CURLOPT_USERAGENT => FS_SDK__USER_AGENT,
60
+ );
61
+
62
+ /**
63
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
64
+ * @param number $pID Element's id.
65
+ * @param string $pPublic Public key.
66
+ * @param string|bool $pSecret Element's secret key.
67
+ * @param bool $pSandbox Whether or not to run API in sandbox mode.
68
+ */
69
+ public function __construct( $pScope, $pID, $pPublic, $pSecret = false, $pSandbox = false ) {
70
+ // If secret key not provided, use public key encryption.
71
+ if ( is_bool( $pSecret ) ) {
72
+ $pSecret = $pPublic;
73
+ }
74
+
75
+ parent::Init( $pScope, $pID, $pPublic, $pSecret, $pSandbox );
76
+ }
77
+
78
+ public static function GetUrl( $pCanonizedPath = '', $pIsSandbox = false ) {
79
+ $address = ( $pIsSandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS );
80
+
81
+ if ( ':' === $address[0] ) {
82
+ $address = self::$_protocol . $address;
83
+ }
84
+
85
+ return $address . $pCanonizedPath;
86
+ }
87
+
88
+ #region Servers Clock Diff ------------------------------------------------------
89
+
90
+ /**
91
+ * @var int Clock diff in seconds between current server to API server.
92
+ */
93
+ private static $_clock_diff = 0;
94
+
95
+ /**
96
+ * Set clock diff for all API calls.
97
+ *
98
+ * @since 1.0.3
99
+ *
100
+ * @param $pSeconds
101
+ */
102
+ public static function SetClockDiff( $pSeconds ) {
103
+ self::$_clock_diff = $pSeconds;
104
+ }
105
+
106
+ /**
107
+ * Find clock diff between current server to API server.
108
+ *
109
+ * @since 1.0.2
110
+ * @return int Clock diff in seconds.
111
+ */
112
+ public static function FindClockDiff() {
113
+ $time = time();
114
+ $pong = self::Ping();
115
+
116
+ return ( $time - strtotime( $pong->timestamp ) );
117
+ }
118
+
119
+ #endregion Servers Clock Diff ------------------------------------------------------
120
+
121
+ /**
122
+ * @var string http or https
123
+ */
124
+ private static $_protocol = FS_API__PROTOCOL;
125
+
126
+ /**
127
+ * Set API connection protocol.
128
+ *
129
+ * @since 1.0.4
130
+ */
131
+ public static function SetHttp() {
132
+ self::$_protocol = 'http';
133
+ }
134
+
135
+ /**
136
+ * @since 1.0.4
137
+ *
138
+ * @return bool
139
+ */
140
+ public static function IsHttps() {
141
+ return ( 'https' === self::$_protocol );
142
+ }
143
+
144
+ /**
145
+ * Sign request with the following HTTP headers:
146
+ * Content-MD5: MD5(HTTP Request body)
147
+ * Date: Current date (i.e Sat, 14 Feb 2015 20:24:46 +0000)
148
+ * Authorization: FS {scope_entity_id}:{scope_entity_public_key}:base64encode(sha256(string_to_sign,
149
+ * {scope_entity_secret_key}))
150
+ *
151
+ * @param string $pResourceUrl
152
+ * @param array $pCurlOptions
153
+ *
154
+ * @return array
155
+ */
156
+ function SignRequest( $pResourceUrl, $pCurlOptions ) {
157
+ $eol = "\n";
158
+ $content_md5 = '';
159
+ $now = ( time() - self::$_clock_diff );
160
+ $date = date( 'r', $now );
161
+ $content_type = '';
162
+
163
+ if ( isset( $pCurlOptions[ CURLOPT_POST ] ) && 0 < $pCurlOptions[ CURLOPT_POST ] ) {
164
+ $content_md5 = md5( $pCurlOptions[ CURLOPT_POSTFIELDS ] );
165
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Content-MD5: ' . $content_md5;
166
+ $content_type = 'application/json';
167
+ }
168
+
169
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Date: ' . $date;
170
+
171
+ $string_to_sign = implode( $eol, array(
172
+ $pCurlOptions[ CURLOPT_CUSTOMREQUEST ],
173
+ $content_md5,
174
+ $content_type,
175
+ $date,
176
+ $pResourceUrl
177
+ ) );
178
+
179
+ // If secret and public keys are identical, it means that
180
+ // the signature uses public key hash encoding.
181
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
182
+
183
+ // Add authorization header.
184
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Authorization: ' .
185
+ $auth_type . ' ' .
186
+ $this->_id . ':' .
187
+ $this->_public . ':' .
188
+ self::Base64UrlEncode(
189
+ hash_hmac( 'sha256', $string_to_sign, $this->_secret )
190
+ );
191
+
192
+ return $pCurlOptions;
193
+ }
194
+
195
+ /**
196
+ * Get API request URL signed via query string.
197
+ *
198
+ * @param string $pPath
199
+ *
200
+ * @throws Freemius_Exception
201
+ *
202
+ * @return string
203
+ */
204
+ function GetSignedUrl( $pPath ) {
205
+ $resource = explode( '?', $this->CanonizePath( $pPath ) );
206
+ $pResourceUrl = $resource[0];
207
+
208
+ $eol = "\n";
209
+ $content_md5 = '';
210
+ $content_type = '';
211
+ $now = ( time() - self::$_clock_diff );
212
+ $date = date( 'r', $now );
213
+
214
+ $string_to_sign = implode( $eol, array(
215
+ 'GET',
216
+ $content_md5,
217
+ $content_type,
218
+ $date,
219
+ $pResourceUrl
220
+ ) );
221
+
222
+ // If secret and public keys are identical, it means that
223
+ // the signature uses public key hash encoding.
224
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
225
+
226
+ return Freemius_Api::GetUrl(
227
+ $pResourceUrl . '?' .
228
+ ( 1 < count( $resource ) && ! empty( $resource[1] ) ? $resource[1] . '&' : '' ) .
229
+ http_build_query( array(
230
+ 'auth_date' => $date,
231
+ 'authorization' => $auth_type . ' ' . $this->_id . ':' .
232
+ $this->_public . ':' .
233
+ self::Base64UrlEncode( hash_hmac(
234
+ 'sha256', $string_to_sign, $this->_secret
235
+ ) )
236
+ ) ), $this->_isSandbox );
237
+ }
238
+
239
+ /**
240
+ * @param string $pCanonizedPath
241
+ * @param string $pMethod
242
+ * @param array $pParams
243
+ * @param null|resource $pCurlHandler
244
+ * @param bool $pIsSandbox
245
+ * @param null|callable $pBeforeExecutionFunction
246
+ *
247
+ * @return object[]|object|null
248
+ *
249
+ * @throws \Freemius_Exception
250
+ */
251
+ private static function MakeStaticRequest(
252
+ $pCanonizedPath,
253
+ $pMethod = 'GET',
254
+ $pParams = array(),
255
+ $pCurlHandler = null,
256
+ $pIsSandbox = false,
257
+ $pBeforeExecutionFunction = null
258
+ ) {
259
+ if ( ! FS_SDK__HAS_CURL ) {
260
+ self::ThrowNoCurlException();
261
+ }
262
+
263
+ // Connectivity errors simulation.
264
+ if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
265
+ self::ThrowCloudFlareDDoSException();
266
+ } else if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
267
+ self::ThrowSquidAclException();
268
+ }
269
+
270
+ if ( ! $pCurlHandler ) {
271
+ $pCurlHandler = curl_init();
272
+ }
273
+
274
+ $opts = self::$CURL_OPTS;
275
+
276
+ if ( ! isset( $opts[ CURLOPT_HTTPHEADER ] ) || ! is_array( $opts[ CURLOPT_HTTPHEADER ] ) ) {
277
+ $opts[ CURLOPT_HTTPHEADER ] = array();
278
+ }
279
+
280
+ if ( 'POST' === $pMethod || 'PUT' === $pMethod ) {
281
+ if ( is_array( $pParams ) && 0 < count( $pParams ) ) {
282
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Content-Type: application/json';
283
+ $opts[ CURLOPT_POST ] = count( $pParams );
284
+ $opts[ CURLOPT_POSTFIELDS ] = json_encode( $pParams );
285
+ }
286
+
287
+ $opts[ CURLOPT_RETURNTRANSFER ] = true;
288
+ }
289
+
290
+ $opts[ CURLOPT_URL ] = Freemius_Api::GetUrl( $pCanonizedPath, $pIsSandbox );
291
+ $opts[ CURLOPT_CUSTOMREQUEST ] = $pMethod;
292
+
293
+ $resource = explode( '?', $pCanonizedPath );
294
+
295
+ // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
296
+ // for 2 seconds if the server does not support this header.
297
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Expect:';
298
+
299
+ if ( 'https' === substr( strtolower( $pCanonizedPath ), 0, 5 ) ) {
300
+ $opts[ CURLOPT_SSL_VERIFYHOST ] = false;
301
+ $opts[ CURLOPT_SSL_VERIFYPEER ] = false;
302
+ }
303
+
304
+ if ( false !== $pBeforeExecutionFunction &&
305
+ is_callable( $pBeforeExecutionFunction )
306
+ ) {
307
+ $opts = call_user_func( $pBeforeExecutionFunction, $resource[0], $opts );
308
+ }
309
+
310
+ curl_setopt_array( $pCurlHandler, $opts );
311
+ $result = curl_exec( $pCurlHandler );
312
+
313
+ /*if (curl_errno($ch) == 60) // CURLE_SSL_CACERT
314
+ {
315
+ self::errorLog('Invalid or no certificate authority found, using bundled information');
316
+ curl_setopt($ch, CURLOPT_CAINFO,
317
+ dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
318
+ $result = curl_exec($ch);
319
+ }*/
320
+
321
+ // With dual stacked DNS responses, it's possible for a server to
322
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
323
+ // the case, curl will try IPv4 first and if that fails, then it will
324
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
325
+ // operating system.
326
+ if ( false === $result && empty( $opts[ CURLOPT_IPRESOLVE ] ) ) {
327
+ $matches = array();
328
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
329
+ if ( preg_match( $regex, curl_error( $pCurlHandler ), $matches ) ) {
330
+ if ( strlen( @inet_pton( $matches[1] ) ) === 16 ) {
331
+ // self::errorLog('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
332
+ self::$CURL_OPTS[ CURLOPT_IPRESOLVE ] = CURL_IPRESOLVE_V4;
333
+ curl_setopt( $pCurlHandler, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
334
+ $result = curl_exec( $pCurlHandler );
335
+ }
336
+ }
337
+ }
338
+
339
+ if ( $result === false ) {
340
+ self::ThrowCurlException( $pCurlHandler );
341
+ }
342
+
343
+ curl_close( $pCurlHandler );
344
+
345
+ if ( empty( $result ) ) {
346
+ return null;
347
+ }
348
+
349
+ $decoded = json_decode( $result );
350
+
351
+ if ( is_null( $decoded ) ) {
352
+ if ( preg_match( '/Please turn JavaScript on/i', $result ) &&
353
+ preg_match( '/text\/javascript/', $result )
354
+ ) {
355
+ self::ThrowCloudFlareDDoSException( $result );
356
+ } else if ( preg_match( '/Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect./', $result ) &&
357
+ preg_match( '/squid/', $result )
358
+ ) {
359
+ self::ThrowSquidAclException( $result );
360
+ } else {
361
+ $decoded = (object) array(
362
+ 'error' => (object) array(
363
+ 'type' => 'Unknown',
364
+ 'message' => $result,
365
+ 'code' => 'unknown',
366
+ 'http' => 402
367
+ )
368
+ );
369
+ }
370
+ }
371
+
372
+ return $decoded;
373
+ }
374
+
375
+
376
+ /**
377
+ * Makes an HTTP request. This method can be overridden by subclasses if
378
+ * developers want to do fancier things or use something other than curl to
379
+ * make the request.
380
+ *
381
+ * @param string $pCanonizedPath The URL to make the request to
382
+ * @param string $pMethod HTTP method
383
+ * @param array $pParams The parameters to use for the POST body
384
+ * @param null|resource $pCurlHandler Initialized curl handle
385
+ *
386
+ * @return object[]|object|null
387
+ *
388
+ * @throws Freemius_Exception
389
+ */
390
+ public function MakeRequest(
391
+ $pCanonizedPath,
392
+ $pMethod = 'GET',
393
+ $pParams = array(),
394
+ $pCurlHandler = null
395
+ ) {
396
+ $resource = explode( '?', $pCanonizedPath );
397
+
398
+ // Only sign request if not ping.json connectivity test.
399
+ $sign_request = ( '/v1/ping.json' !== strtolower( substr( $resource[0], - strlen( '/v1/ping.json' ) ) ) );
400
+
401
+ return self::MakeStaticRequest(
402
+ $pCanonizedPath,
403
+ $pMethod,
404
+ $pParams,
405
+ $pCurlHandler,
406
+ $this->_isSandbox,
407
+ $sign_request ? array( &$this, 'SignRequest' ) : null
408
+ );
409
+ }
410
+
411
+ #region Connectivity Test ------------------------------------------------------
412
+
413
+ /**
414
+ * If successful connectivity to the API endpoint using ping.json endpoint.
415
+ *
416
+ * - OR -
417
+ *
418
+ * Validate if ping result object is valid.
419
+ *
420
+ * @param mixed $pPong
421
+ *
422
+ * @return bool
423
+ */
424
+ public static function Test( $pPong = null ) {
425
+ $pong = is_null( $pPong ) ?
426
+ self::Ping() :
427
+ $pPong;
428
+
429
+ return (
430
+ is_object( $pong ) &&
431
+ isset( $pong->api ) &&
432
+ 'pong' === $pong->api
433
+ );
434
+ }
435
+
436
+ /**
437
+ * Ping API to test connectivity.
438
+ *
439
+ * @return object
440
+ */
441
+ public static function Ping() {
442
+ try {
443
+ $result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
444
+ } catch ( Freemius_Exception $e ) {
445
+ // Map to error object.
446
+ $result = (object) $e->getResult();
447
+ } catch ( Exception $e ) {
448
+ // Map to error object.
449
+ $result = (object) array(
450
+ 'error' => array(
451
+ 'type' => 'Unknown',
452
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
453
+ 'code' => 'unknown',
454
+ 'http' => 402
455
+ )
456
+ );
457
+ }
458
+
459
+ return $result;
460
+ }
461
+
462
+ #endregion Connectivity Test ------------------------------------------------------
463
+
464
+ #region Connectivity Exceptions ------------------------------------------------------
465
+
466
+ /**
467
+ * @param resource $pCurlHandler
468
+ *
469
+ * @throws Freemius_Exception
470
+ */
471
+ private static function ThrowCurlException( $pCurlHandler ) {
472
+ $e = new Freemius_Exception( array(
473
+ 'error' => array(
474
+ 'code' => curl_errno( $pCurlHandler ),
475
+ 'message' => curl_error( $pCurlHandler ),
476
+ 'type' => 'CurlException',
477
+ ),
478
+ ) );
479
+
480
+ curl_close( $pCurlHandler );
481
+ throw $e;
482
+ }
483
+
484
+ /**
485
+ * @param string $pResult
486
+ *
487
+ * @throws Freemius_Exception
488
+ */
489
+ private static function ThrowNoCurlException( $pResult = '' ) {
490
+ throw new Freemius_Exception( array(
491
+ 'error' => (object) array(
492
+ 'type' => 'cUrlMissing',
493
+ 'message' => $pResult,
494
+ 'code' => 'curl_missing',
495
+ 'http' => 402
496
+ )
497
+ ) );
498
+ }
499
+
500
+ /**
501
+ * @param string $pResult
502
+ *
503
+ * @throws Freemius_Exception
504
+ */
505
+ private static function ThrowCloudFlareDDoSException( $pResult = '' ) {
506
+ throw new Freemius_Exception( array(
507
+ 'error' => (object) array(
508
+ 'type' => 'CloudFlareDDoSProtection',
509
+ 'message' => $pResult,
510
+ 'code' => 'cloudflare_ddos_protection',
511
+ 'http' => 402
512
+ )
513
+ ) );
514
+ }
515
+
516
+ /**
517
+ * @param string $pResult
518
+ *
519
+ * @throws Freemius_Exception
520
+ */
521
+ private static function ThrowSquidAclException( $pResult = '' ) {
522
+ throw new Freemius_Exception( array(
523
+ 'error' => (object) array(
524
+ 'type' => 'SquidCacheBlock',
525
+ 'message' => $pResult,
526
+ 'code' => 'squid_cache_block',
527
+ 'http' => 402
528
+ )
529
+ ) );
530
+ }
531
+
532
+ #endregion Connectivity Exceptions ------------------------------------------------------
533
+ }
freemius/includes/sdk/FreemiusBase.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2014 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ define( 'FS_API__VERSION', '1' );
19
+ define( 'FS_SDK__PATH', dirname( __FILE__ ) );
20
+ define( 'FS_SDK__EXCEPTIONS_PATH', FS_SDK__PATH . '/Exceptions/' );
21
+
22
+ if ( ! function_exists( 'json_decode' ) ) {
23
+ throw new Exception( 'Freemius needs the JSON PHP extension.' );
24
+ }
25
+
26
+ // Include all exception files.
27
+ $exceptions = array(
28
+ 'Exception',
29
+ 'InvalidArgumentException',
30
+ 'ArgumentNotExistException',
31
+ 'EmptyArgumentException',
32
+ 'OAuthException'
33
+ );
34
+
35
+ foreach ( $exceptions as $e ) {
36
+ require FS_SDK__EXCEPTIONS_PATH . $e . '.php';
37
+ }
38
+
39
+ abstract class Freemius_Api_Base {
40
+ const VERSION = '1.0.4';
41
+ const FORMAT = 'json';
42
+
43
+ protected $_id;
44
+ protected $_public;
45
+ protected $_secret;
46
+ protected $_scope;
47
+ protected $_isSandbox;
48
+
49
+ /**
50
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
51
+ * @param number $pID Element's id.
52
+ * @param string $pPublic Public key.
53
+ * @param string $pSecret Element's secret key.
54
+ * @param bool $pIsSandbox Whether or not to run API in sandbox mode.
55
+ */
56
+ public function Init( $pScope, $pID, $pPublic, $pSecret, $pIsSandbox = false ) {
57
+ $this->_id = $pID;
58
+ $this->_public = $pPublic;
59
+ $this->_secret = $pSecret;
60
+ $this->_scope = $pScope;
61
+ $this->_isSandbox = $pIsSandbox;
62
+ }
63
+
64
+ public function IsSandbox() {
65
+ return $this->_isSandbox;
66
+ }
67
+
68
+ function CanonizePath( $pPath ) {
69
+ $pPath = trim( $pPath, '/' );
70
+ $query_pos = strpos( $pPath, '?' );
71
+ $query = '';
72
+
73
+ if ( false !== $query_pos ) {
74
+ $query = substr( $pPath, $query_pos );
75
+ $pPath = substr( $pPath, 0, $query_pos );
76
+ }
77
+
78
+ // Trim '.json' suffix.
79
+ $format_length = strlen( '.' . self::FORMAT );
80
+ $start = $format_length * ( - 1 ); //negative
81
+ if ( substr( strtolower( $pPath ), $start ) === ( '.' . self::FORMAT ) ) {
82
+ $pPath = substr( $pPath, 0, strlen( $pPath ) - $format_length );
83
+ }
84
+
85
+ switch ( $this->_scope ) {
86
+ case 'app':
87
+ $base = '/apps/' . $this->_id;
88
+ break;
89
+ case 'developer':
90
+ $base = '/developers/' . $this->_id;
91
+ break;
92
+ case 'user':
93
+ $base = '/users/' . $this->_id;
94
+ break;
95
+ case 'plugin':
96
+ $base = '/plugins/' . $this->_id;
97
+ break;
98
+ case 'install':
99
+ $base = '/installs/' . $this->_id;
100
+ break;
101
+ default:
102
+ throw new Freemius_Exception( 'Scope not implemented.' );
103
+ }
104
+
105
+ return '/v' . FS_API__VERSION . $base .
106
+ ( ! empty( $pPath ) ? '/' : '' ) . $pPath .
107
+ ( ( false === strpos( $pPath, '.' ) ) ? '.' . self::FORMAT : '' ) . $query;
108
+ }
109
+
110
+ abstract function MakeRequest( $pCanonizedPath, $pMethod = 'GET', $pParams = array() );
111
+
112
+ /**
113
+ * @param string $pPath
114
+ * @param string $pMethod
115
+ * @param array $pParams
116
+ *
117
+ * @return object[]|object|null
118
+ */
119
+ private function _Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
120
+ $pMethod = strtoupper( $pMethod );
121
+
122
+ try {
123
+ $result = $this->MakeRequest( $pPath, $pMethod, $pParams );
124
+ } catch ( Freemius_Exception $e ) {
125
+ // Map to error object.
126
+ $result = (object) $e->getResult();
127
+ } catch ( Exception $e ) {
128
+ // Map to error object.
129
+ $result = (object) array(
130
+ 'error' => array(
131
+ 'type' => 'Unknown',
132
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
133
+ 'code' => 'unknown',
134
+ 'http' => 402
135
+ )
136
+ );
137
+ }
138
+
139
+ return $result;
140
+ }
141
+
142
+ public function Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
143
+ return $this->_Api( $this->CanonizePath( $pPath ), $pMethod, $pParams );
144
+ }
145
+
146
+ /**
147
+ * Base64 encoding that does not need to be urlencode()ed.
148
+ * Exactly the same as base64_encode except it uses
149
+ * - instead of +
150
+ * _ instead of /
151
+ * No padded =
152
+ *
153
+ * @param string $input base64UrlEncoded string
154
+ *
155
+ * @return string
156
+ */
157
+ protected static function Base64UrlDecode( $input ) {
158
+ return base64_decode( strtr( $input, '-_', '+/' ) );
159
+ }
160
+
161
+ /**
162
+ * Base64 encoding that does not need to be urlencode()ed.
163
+ * Exactly the same as base64_encode except it uses
164
+ * - instead of +
165
+ * _ instead of /
166
+ *
167
+ * @param string $input string
168
+ *
169
+ * @return string base64Url encoded string
170
+ */
171
+ protected static function Base64UrlEncode( $input ) {
172
+ $str = strtr( base64_encode( $input ), '+/', '-_' );
173
+ $str = str_replace( '=', '', $str );
174
+
175
+ return $str;
176
+ }
177
+
178
+ }
freemius/includes/sdk/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
freemius/includes/supplements/fs-essential-functions-1.1.7.1.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Find the plugin main file path based on any give file inside the plugin's folder.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.1
18
+ *
19
+ * @param string $file Absolute path to a file inside a plugin's folder.
20
+ *
21
+ * @return string
22
+ */
23
+ function fs_find_direct_caller_plugin_file( $file ) {
24
+ /**
25
+ * All the code below will be executed once on activation.
26
+ * If the user changes the main plugin's file name, the file_exists()
27
+ * will catch it.
28
+ */
29
+ if ( ! function_exists( 'get_plugins' ) ) {
30
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
31
+ }
32
+
33
+ $all_plugins = get_plugins();
34
+
35
+ $file_real_path = fs_normalize_path( realpath( $file ) );
36
+
37
+ // Get active plugin's main files real full names (might be symlinks).
38
+ foreach ( $all_plugins as $relative_path => &$data ) {
39
+ if ( 0 === strpos( $file_real_path, fs_normalize_path( dirname( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) ) ) ) ) {
40
+ return $relative_path;
41
+ }
42
+ }
43
+
44
+ return null;
45
+ }
freemius/start.php ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $this_sdk_version = '1.1.7.1';
14
+
15
+ #region SDK Selection Logic --------------------------------------------------------------------
16
+
17
+ /**
18
+ * Special logic added on 1.1.6 to make sure that every Freemius powered plugin
19
+ * will ALWAYS be loaded with the newest SDK from the active Freemius powered plugins.
20
+ *
21
+ * Since Freemius SDK is backward compatible, this will make sure that all Freemius powered
22
+ * plugins will run correctly.
23
+ *
24
+ * @since 1.1.6
25
+ */
26
+
27
+ global $fs_active_plugins;
28
+
29
+ $this_sdk_relative_path = plugin_basename( dirname( __FILE__ ) );
30
+
31
+ if ( ! isset( $fs_active_plugins ) ) {
32
+ // Require SDK essentials.
33
+ require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php';
34
+
35
+ // Load all Freemius powered active plugins.
36
+ $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() );
37
+
38
+ if ( ! isset( $fs_active_plugins->plugins ) ) {
39
+ $fs_active_plugins->plugins = array();
40
+ }
41
+ }
42
+
43
+ if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
44
+ require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
45
+ }
46
+
47
+ // Update current SDK info based on the SDK path.
48
+ if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) ||
49
+ $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version
50
+ ) {
51
+ $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
52
+ 'version' => $this_sdk_version,
53
+ 'timestamp' => time(),
54
+ 'plugin_path' => plugin_basename( fs_find_direct_caller_plugin_file( __FILE__ ) ),
55
+ );
56
+ }
57
+
58
+ $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path );
59
+
60
+ if ( ! isset( $fs_active_plugins->newest ) ) {
61
+ /**
62
+ * This will be executed only once, for the first time a Freemius powered plugin is activated.
63
+ */
64
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
65
+
66
+ $is_current_sdk_newest = true;
67
+ } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) {
68
+ /**
69
+ * Current SDK is newer than the newest stored SDK.
70
+ */
71
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
72
+
73
+ if ( class_exists( 'Freemius' ) ) {
74
+ // Older SDK version was already loaded.
75
+
76
+ if ( ! $fs_active_plugins->newest->in_activation ) {
77
+ // Re-order plugins to load this plugin first.
78
+ fs_newest_sdk_plugin_first();
79
+ }
80
+
81
+ // Refresh page.
82
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
83
+ exit();
84
+ }
85
+ }
86
+ } else {
87
+ if ( ! function_exists( 'get_plugins' ) ) {
88
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
89
+ }
90
+
91
+ $is_newest_sdk_plugin_activate = is_plugin_active( $fs_active_plugins->newest->plugin_path );
92
+
93
+ if ( $is_current_sdk_newest &&
94
+ ! $is_newest_sdk_plugin_activate &&
95
+ ! $fs_active_plugins->newest->in_activation
96
+ ) {
97
+ // If current SDK is the newest and the plugin is NOT active, it means
98
+ // that the current plugin in activation mode.
99
+ $fs_active_plugins->newest->in_activation = true;
100
+ update_option( 'fs_active_plugins', $fs_active_plugins );
101
+ }
102
+
103
+ $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) && file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' ) );
104
+
105
+ if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
106
+ // Plugin with newest SDK is no longer active, or SDK was moved to a different location.
107
+ unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
108
+ }
109
+
110
+ if ( ! ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) ||
111
+ ! $is_newest_sdk_path_valid ||
112
+ // Is newest SDK downgraded.
113
+ ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
114
+ version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
115
+ ) {
116
+ /**
117
+ * Plugin with newest SDK is no longer active.
118
+ * OR
119
+ * The newest SDK was in the current plugin. BUT, seems like the version of
120
+ * the SDK was downgraded to a lower SDK.
121
+ */
122
+ // Find the active plugin with the newest SDK version and update the newest reference.
123
+ fs_fallback_to_newest_active_sdk();
124
+ } else {
125
+ if ( $is_newest_sdk_plugin_activate &&
126
+ $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
127
+ ( $fs_active_plugins->newest->in_activation ||
128
+ ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
129
+ )
130
+
131
+ ) {
132
+ if ( $fs_active_plugins->newest->in_activation ) {
133
+ // Plugin no more in activation.
134
+ $fs_active_plugins->newest->in_activation = false;
135
+ update_option( 'fs_active_plugins', $fs_active_plugins );
136
+ }
137
+
138
+ // Reorder plugins to load plugin with newest SDK first.
139
+ if ( fs_newest_sdk_plugin_first() ) {
140
+ // Refresh page after re-order to make sure activated plugin loads newest SDK.
141
+ if ( class_exists( 'Freemius' ) ) {
142
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
143
+ exit();
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ }
150
+
151
+ if ( class_exists( 'Freemius' ) ) {
152
+ // SDK was already loaded.
153
+ return;
154
+ }
155
+
156
+ if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
157
+ $newest_sdk_starter = fs_normalize_path( WP_PLUGIN_DIR . '/' . $fs_active_plugins->newest->sdk_path . '/start.php' );
158
+
159
+ if ( file_exists( $newest_sdk_starter ) ) {
160
+ // Reorder plugins to load plugin with newest SDK first.
161
+ fs_newest_sdk_plugin_first();
162
+
163
+ // There's a newer SDK version, load it instead of the current one!
164
+ require_once $newest_sdk_starter;
165
+
166
+ return;
167
+ }
168
+ }
169
+
170
+ #endregion SDK Selection Logic --------------------------------------------------------------------
171
+
172
+ #region Hooks & Filters Collection --------------------------------------------------------------------
173
+
174
+ /**
175
+ * Freemius hooks (actions & filters) tags structure:
176
+ *
177
+ * fs_{filter/action_name}_{plugin_slug}
178
+ *
179
+ * --------------------------------------------------------
180
+ *
181
+ * Usage with WordPress' add_action() / add_filter():
182
+ *
183
+ * add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
184
+ *
185
+ * --------------------------------------------------------
186
+ *
187
+ * Usage with Freemius' instance add_action() / add_filter():
188
+ *
189
+ * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
190
+ * my_freemius()->add_action('{action_name}', $callable);
191
+ *
192
+ * --------------------------------------------------------
193
+ *
194
+ * Freemius filters collection:
195
+ *
196
+ * fs_connect_url_{plugin_slug}
197
+ * fs_trial_promotion_message_{plugin_slug}
198
+ * fs_is_long_term_user_{plugin_slug}
199
+ * fs_uninstall_reasons_{plugin_slug}
200
+ * fs_is_plugin_update_{plugin_slug}
201
+ * fs_api_domains_{plugin_slug}
202
+ * fs_email_template_sections_{plugin_slug}
203
+ * fs_support_forum_submenu_{plugin_slug}
204
+ * fs_support_forum_url_{plugin_slug}
205
+ * fs_connect_message_{plugin_slug}
206
+ * fs_connect_message_on_update_{plugin_slug}
207
+ * fs_uninstall_confirmation_message_{plugin_slug}
208
+ * fs_pending_activation_message_{plugin_slug}
209
+ * fs_is_submenu_visible_{plugin_slug}
210
+ *
211
+ * --------------------------------------------------------
212
+ *
213
+ * Freemius actions collection:
214
+ *
215
+ * fs_after_license_loaded_{plugin_slug}
216
+ * fs_after_license_change_{plugin_slug}
217
+ * fs_after_plans_sync_{plugin_slug}
218
+ *
219
+ * fs_after_account_details_{plugin_slug}
220
+ * fs_after_account_user_sync_{plugin_slug}
221
+ * fs_after_account_plan_sync_{plugin_slug}
222
+ * fs_before_account_load_{plugin_slug}
223
+ * fs_after_account_connection_{plugin_slug}
224
+ * fs_account_property_edit_{plugin_slug}
225
+ * fs_account_email_verified_{plugin_slug}
226
+ * fs_account_page_load_before_departure_{plugin_slug}
227
+ * fs_before_account_delete_{plugin_slug}
228
+ * fs_after_account_delete_{plugin_slug}
229
+ *
230
+ * fs_sdk_version_update_{plugin_slug}
231
+ * fs_plugin_version_update_{plugin_slug}
232
+ *
233
+ * fs_initiated_{plugin_slug}
234
+ * fs_after_init_plugin_registered_{plugin_slug}
235
+ * fs_after_init_plugin_anonymous_{plugin_slug}
236
+ * fs_after_init_plugin_pending_activations_{plugin_slug}
237
+ * fs_after_init_addon_registered_{plugin_slug}
238
+ * fs_after_init_addon_anonymous_{plugin_slug}
239
+ * fs_after_init_addon_pending_activations_{plugin_slug}
240
+ *
241
+ * fs_after_premium_version_activation_{plugin_slug}
242
+ * fs_after_free_version_reactivation_{plugin_slug}
243
+ *
244
+ * fs_after_uninstall_{plugin_slug}
245
+ * fs_before_admin_menu_init_{plugin_slug}
246
+ */
247
+
248
+ #endregion Hooks & Filters Collection --------------------------------------------------------------------
249
+
250
+ if ( ! class_exists( 'Freemius' ) ) {
251
+
252
+ if ( ! defined( 'WP_FS__SDK_VERSION' ) ) {
253
+ define( 'WP_FS__SDK_VERSION', $this_sdk_version );
254
+ }
255
+
256
+ // Configuration should be loaded first.
257
+ require_once dirname( __FILE__ ) . '/config.php';
258
+
259
+ // Logger must be loaded before any other.
260
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-logger.php';
261
+
262
+ require_once WP_FS__DIR_INCLUDES . '/fs-core-functions.php';
263
+ // require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-abstract-manager.php';
264
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-option-manager.php';
265
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-cache-manager.php';
266
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-notice-manager.php';
267
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-menu-manager.php';
268
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-key-value-storage.php';
269
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-license-manager.php';
270
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plan-manager.php';
271
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plugin-manager.php';
272
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-entity.php';
273
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-scope-entity.php';
274
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-user.php';
275
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-site.php';
276
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin.php';
277
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-info.php';
278
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-tag.php';
279
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-plan.php';
280
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-license.php';
281
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-subscription.php';
282
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-api.php';
283
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-plugin-updater.php';
284
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-security.php';
285
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius-abstract.php';
286
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';
287
+
288
+ /**
289
+ * Quick shortcut to get Freemius for specified plugin.
290
+ * Used by various templates.
291
+ *
292
+ * @param string $slug
293
+ *
294
+ * @return Freemius
295
+ */
296
+ function freemius( $slug ) {
297
+ return Freemius::instance( $slug );
298
+ }
299
+
300
+ /**
301
+ * @param string $slug
302
+ * @param number $plugin_id
303
+ * @param string $public_key
304
+ * @param bool $is_live Is live or test plugin.
305
+ * @param bool $is_premium Hints freemius if running the premium plugin or not.
306
+ *
307
+ * @return Freemius
308
+ */
309
+ function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) {
310
+ $fs = Freemius::instance( $slug );
311
+ $fs->init( $plugin_id, $public_key, $is_live, $is_premium );
312
+
313
+ return $fs;
314
+ }
315
+
316
+ /**
317
+ * @param array [string]string $plugin
318
+ *
319
+ * @return Freemius
320
+ * @throws Freemius_Exception
321
+ */
322
+ function fs_dynamic_init( $plugin ) {
323
+ $fs = Freemius::instance( $plugin['slug'] );
324
+ $fs->dynamic_init( $plugin );
325
+
326
+ return $fs;
327
+ }
328
+
329
+ function fs_dump_log() {
330
+ FS_Logger::dump();
331
+ }
332
+ }
freemius/templates/account.php ADDED
@@ -0,0 +1,455 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ /**
15
+ * @var Freemius $fs
16
+ */
17
+ $fs = freemius( $slug );
18
+
19
+ /**
20
+ * @var FS_Plugin_Tag $update
21
+ */
22
+ $update = $fs->get_update();
23
+
24
+ $is_paying = $fs->is_paying();
25
+ $user = $fs->get_user();
26
+ $site = $fs->get_site();
27
+ $name = $user->get_name();
28
+ $license = $fs->_get_license();
29
+ $subscription = $fs->_get_subscription();
30
+ $plan = $fs->get_plan();
31
+ $is_active_subscription = ( is_object( $subscription ) && $subscription->is_active() );
32
+ ?>
33
+
34
+ <div class="wrap">
35
+ <h2 class="nav-tab-wrapper">
36
+ <a href="<?php $fs->get_account_url() ?>" class="nav-tab nav-tab-active"><?php _efs( 'account', $slug ) ?></a>
37
+ <?php if ( $fs->_has_addons() ) : ?>
38
+ <a href="<?php echo $fs->_get_admin_page_url( 'addons' ) ?>"
39
+ class="nav-tab"><?php _efs( 'add-ons', $slug ) ?></a>
40
+ <?php endif ?>
41
+ <?php if ( $fs->is_not_paying() && $fs->has_paid_plan() ) : ?>
42
+ <a href="<?php echo $fs->get_upgrade_url() ?>" class="nav-tab"><?php _efs( 'upgrade', $slug ) ?></a>
43
+ <?php if ( ! $fs->is_trial_utilized() && $fs->has_trial_plan() ) : ?>
44
+ <a href="<?php echo $fs->get_trial_url() ?>" class="nav-tab"><?php _efs( 'free-trial', $slug ) ?></a>
45
+ <?php endif ?>
46
+ <?php endif ?>
47
+ </h2>
48
+
49
+ <div id="poststuff">
50
+ <div id="fs_account">
51
+ <div class="has-sidebar has-right-sidebar">
52
+ <div class="has-sidebar-content">
53
+ <div class="postbox">
54
+ <h3><?php _efs( 'account-details', $slug ) ?></h3>
55
+
56
+ <div class="fs-header-actions">
57
+ <ul>
58
+ <li>
59
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
60
+ <input type="hidden" name="fs_action" value="delete_account">
61
+ <?php wp_nonce_field( 'delete_account' ) ?>
62
+ <a href="#" onclick="if (confirm('<?php
63
+ if ( $is_active_subscription ) {
64
+ echo esc_attr( sprintf( __fs( 'delete-account-x-confirm', $slug ), $plan->title ) );
65
+ } else {
66
+ _efs( 'delete-account-confirm', $slug );
67
+ }
68
+ ?>')) this.parentNode.submit(); return false;"><i class="dashicons dashicons-no"></i> <?php _efs( 'delete-account', $slug ) ?></a>
69
+ </form>
70
+ </li>
71
+ <li>
72
+ &nbsp;•&nbsp;
73
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
74
+ <input type="hidden" name="fs_action" value="<?php echo $slug ?>_sync_license">
75
+ <?php wp_nonce_field( $slug . '_sync_license' ) ?>
76
+ <a href="#" onclick="this.parentNode.submit(); return false;"><i class="dashicons dashicons-image-rotate"></i> <?php _efs( 'sync', $slug ) ?></a>
77
+ </form>
78
+ </li>
79
+ <?php if ( $is_paying ) : ?>
80
+ <li>
81
+ &nbsp;•&nbsp;
82
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
83
+ <input type="hidden" name="fs_action" value="deactivate_license">
84
+ <?php wp_nonce_field( 'deactivate_license' ) ?>
85
+ <a href="#"
86
+ onclick="if (confirm('<?php _efs( 'deactivate-license-confirm', $slug ) ?>')) this.parentNode.submit(); return false;"><i class="dashicons dashicons-admin-network"></i> <?php _efs( 'deactivate-license', $slug ) ?></a>
87
+ </form>
88
+ </li>
89
+ <?php if ( ! $license->is_lifetime() &&
90
+ $is_active_subscription
91
+ ) : ?>
92
+ <li>
93
+ &nbsp;•&nbsp;
94
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
95
+ <input type="hidden" name="fs_action" value="downgrade_account">
96
+ <?php wp_nonce_field( 'downgrade_account' ) ?>
97
+ <a href="#"
98
+ onclick="if (confirm('<?php printf( __fs( 'downgrade-x-confirm', $slug ), $plan->title, human_time_diff( time(), strtotime( $license->expiration ) ) ) ?> <?php if ( ! $license->is_block_features ) {
99
+ printf( __fs( 'after-downgrade-non-blocking', $slug ), $plan->title );
100
+ } else {
101
+ printf( __fs( 'after-downgrade-blocking', $slug ), $plan->title );
102
+ }?> <?php _efs( 'proceed-confirmation', $slug ) ?>')) this.parentNode.submit(); return false;"><i class="dashicons dashicons-download"></i> <?php _efs( 'downgrade', $slug ) ?></a>
103
+ </form>
104
+ </li>
105
+ <?php endif ?>
106
+ <li>
107
+ &nbsp;•&nbsp;
108
+ <a href="<?php echo $fs->get_upgrade_url() ?>"><i class="dashicons dashicons-grid-view"></i> <?php _efs( 'change-plan', $slug ) ?></a>
109
+ </li>
110
+ <?php endif ?>
111
+ </ul>
112
+ </div>
113
+ <div class="inside">
114
+ <table id="fs_account_details" cellspacing="0" class="fs-key-value-table">
115
+ <?php
116
+ $profile = array();
117
+ $profile[] = array(
118
+ 'id' => 'user_name',
119
+ 'title' => __fs( 'name', $slug ),
120
+ 'value' => $name
121
+ );
122
+ // if (isset($user->email) && false !== strpos($user->email, '@'))
123
+ $profile[] = array(
124
+ 'id' => 'email',
125
+ 'title' => __fs( 'email', $slug ),
126
+ 'value' => $user->email
127
+ );
128
+ if ( is_numeric( $user->id ) ) {
129
+ $profile[] = array(
130
+ 'id' => 'user_id',
131
+ 'title' => __fs( 'user-id', $slug ),
132
+ 'value' => $user->id
133
+ );
134
+ }
135
+
136
+ $profile[] = array(
137
+ 'id' => 'site_id',
138
+ 'title' => __fs( 'site-id', $slug ),
139
+ 'value' => is_string( $site->id ) ?
140
+ $site->id :
141
+ __fs( 'no-id', $slug )
142
+ );
143
+
144
+ $profile[] = array(
145
+ 'id' => 'site_public_key',
146
+ 'title' => __fs( 'public-key', $slug ),
147
+ 'value' => $site->public_key
148
+ );
149
+
150
+ $profile[] = array(
151
+ 'id' => 'site_secret_key',
152
+ 'title' => __fs( 'secret-key', $slug ),
153
+ 'value' => ( ( is_string( $site->secret_key ) ) ?
154
+ $site->secret_key :
155
+ __fs( 'no-secret', $slug )
156
+ )
157
+ );
158
+
159
+ if ( $fs->is_trial() ) {
160
+ $trial_plan = $fs->get_trial_plan();
161
+
162
+ $profile[] = array(
163
+ 'id' => 'plan',
164
+ 'title' => __fs( 'plan', $slug ),
165
+ 'value' => ( is_string( $trial_plan->name ) ?
166
+ strtoupper( $trial_plan->title ) . ' ' :
167
+ '' ) . strtoupper( __fs( 'trial', $slug ) )
168
+ );
169
+ } else {
170
+ $profile[] = array(
171
+ 'id' => 'plan',
172
+ 'title' => __fs( 'plan', $slug ),
173
+ 'value' => is_string( $site->plan->name ) ?
174
+ strtoupper( $site->plan->title ) :
175
+ strtoupper( __fs( 'free', $slug ) )
176
+ );
177
+ }
178
+
179
+ $profile[] = array(
180
+ 'id' => 'version',
181
+ 'title' => __fs( 'version', $slug ),
182
+ 'value' => $fs->get_plugin_version()
183
+ );
184
+ ?>
185
+ <?php $odd = true;
186
+ foreach ( $profile as $p ) : ?>
187
+ <?php
188
+ if ( 'plan' === $p['id'] && ! $fs->has_paid_plan() ) {
189
+ // If plugin don't have any paid plans, there's no reason
190
+ // to show current plan.
191
+ continue;
192
+ }
193
+ ?>
194
+ <tr class="fs-field-<?php echo $p['id'] ?><?php if ( $odd ) : ?> alternate<?php endif ?>">
195
+ <td>
196
+ <nobr><?php echo $p['title'] ?>:</nobr>
197
+ </td>
198
+ <td>
199
+ <code><?php echo htmlspecialchars( $p['value'] ) ?></code>
200
+ <?php if ( 'email' === $p['id'] && ! $user->is_verified() ) : ?>
201
+ <label><?php _efs( 'not-verified', $slug ) ?></label>
202
+ <?php endif ?>
203
+ <?php if ( 'plan' === $p['id'] ) : ?>
204
+ <?php if ( $fs->is_trial() ) : ?>
205
+ <label><?php printf( __fs( 'expires-in', $slug ), human_time_diff( time(), strtotime( $site->trial_ends ) ) ) ?></label>
206
+ <?php elseif ( is_object( $license ) && ! $license->is_lifetime() ) : ?>
207
+ <?php if ( ! $is_active_subscription && ! $license->is_first_payment_pending() ) : ?>
208
+ <label><?php printf( __fs( 'expires-in', $slug ), human_time_diff( time(), strtotime( $license->expiration ) ) ) ?></label>
209
+ <?php elseif ( $is_active_subscription && ! $subscription->is_first_payment_pending() ) : ?>
210
+ <label><?php printf( __fs( 'renews-in', $slug ), human_time_diff( time(), strtotime( $subscription->next_payment ) ) ) ?></label>
211
+ <?php endif ?>
212
+ <?php endif ?>
213
+ <?php endif ?>
214
+
215
+ </td>
216
+ <td class="fs-right">
217
+ <?php if ( 'email' === $p['id'] && ! $user->is_verified() ) : ?>
218
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST">
219
+ <input type="hidden" name="fs_action" value="verify_email">
220
+ <?php wp_nonce_field( 'verify_email' ) ?>
221
+ <input type="submit" class="button button-small"
222
+ value="<?php _efs( 'verify-email', $slug ) ?>">
223
+ </form>
224
+ <?php endif ?>
225
+ <?php if ( 'plan' === $p['id'] ) : ?>
226
+ <div class="button-group">
227
+ <?php $license = $fs->is_not_paying() ? $fs->_get_available_premium_license() : false ?>
228
+ <?php if ( false !== $license && ( $license->left() > 0 || ( $site->is_localhost() && $license->is_free_localhost ) ) ) : ?>
229
+ <?php $premium_plan = $fs->_get_plan_by_id( $license->plan_id ) ?>
230
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>"
231
+ method="POST">
232
+ <input type="hidden" name="fs_action" value="activate_license">
233
+ <?php wp_nonce_field( 'activate_license' ) ?>
234
+ <input type="submit" class="button button-primary"
235
+ value="<?php printf(
236
+ __fs( 'activate-x-plan', $slug ),
237
+ $premium_plan->title,
238
+ ( $site->is_localhost() && $license->is_free_localhost ) ?
239
+ '[' . __fs( 'localhost', $slug ) . ']' :
240
+ ( 1 < $license->left() ? $license->left() . ' left' : '' )
241
+ ) ?> ">
242
+ </form>
243
+ <?php else : ?>
244
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>"
245
+ method="POST" class="button-group">
246
+ <input type="submit" class="button"
247
+ value="<?php _efs( 'sync-license', $slug ) ?>">
248
+ <input type="hidden" name="fs_action"
249
+ value="<?php echo $slug ?>_sync_license">
250
+ <?php wp_nonce_field( $slug . '_sync_license' ) ?>
251
+ <a href="<?php echo $fs->get_upgrade_url() ?>"
252
+ class="button<?php if ( ! $is_paying ) {
253
+ echo ' button-primary';
254
+ } ?> button-upgrade"><?php ( ! $is_paying ) ?
255
+ _efs( 'upgrade', $slug ) :
256
+ _efs( 'change-plan', $slug )
257
+ ?></a>
258
+ </form>
259
+ <?php endif ?>
260
+ </div>
261
+ <?php elseif ( 'version' === $p['id'] ) : ?>
262
+ <div class="button-group">
263
+ <?php if ( $is_paying || $fs->is_trial() ) : ?>
264
+ <?php if ( ! $fs->is_allowed_to_install() ) : ?>
265
+ <a target="_blank" class="button button-primary"
266
+ href="<?php echo $fs->_get_latest_download_local_url() ?>"><?php echo sprintf( __fs( 'download-x-version', $slug ), $site->plan->title ) . ( is_object( $update ) ? ' [' . $update->version . ']' : '' ) ?></a>
267
+ <?php elseif ( is_object( $update ) ) : ?>
268
+ <a class="button button-primary"
269
+ href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $fs->get_plugin_basename() ), 'upgrade-plugin_' . $fs->get_plugin_basename() ) ?>"><?php echo __fs( 'install-update-now', $slug ) . ' [' . $update->version . ']' ?></a>
270
+ <?php endif ?>
271
+ <?php endif; ?>
272
+ </div>
273
+ <?php
274
+ elseif (/*in_array($p['id'], array('site_secret_key', 'site_id', 'site_public_key')) ||*/
275
+ ( is_string( $user->secret_key ) && in_array( $p['id'], array(
276
+ 'email',
277
+ 'user_name'
278
+ ) ) )
279
+ ) : ?>
280
+ <form action="<?php echo $fs->_get_admin_page_url( 'account' ) ?>" method="POST"
281
+ onsubmit="var val = prompt('<?php printf( __fs( 'what-is-your-x', $slug ), $p['title'] ) ?>', '<?php echo $p['value'] ?>'); if (null == val || '' === val) return false; jQuery('input[name=fs_<?php echo $p['id'] ?>_<?php echo $slug ?>]').val(val); return true;">
282
+ <input type="hidden" name="fs_action" value="update_<?php echo $p['id'] ?>">
283
+ <input type="hidden" name="fs_<?php echo $p['id'] ?>_<?php echo $slug ?>"
284
+ value="">
285
+ <?php wp_nonce_field( 'update_' . $p['id'] ) ?>
286
+ <input type="submit" class="button button-small"
287
+ value="<?php _ex( 'Edit', 'verb', 'freemius' ) ?>">
288
+ </form>
289
+ <?php endif ?>
290
+ </td>
291
+ </tr>
292
+ <?php $odd = ! $odd; endforeach ?>
293
+ </table>
294
+ </div>
295
+ </div>
296
+ <?php
297
+ $account_addons = $fs->get_account_addons();
298
+ if ( ! is_array( $account_addons ) ) {
299
+ $account_addons = array();
300
+ }
301
+
302
+ $installed_addons = $fs->get_installed_addons();
303
+ $installed_addons_ids = array();
304
+ foreach ( $installed_addons as $fs_addon ) {
305
+ $installed_addons_ids[] = $fs_addon->get_id();
306
+ }
307
+
308
+ $addons_to_show = array_unique( array_merge( $installed_addons_ids, $account_addons ) );
309
+ ?>
310
+ <?php if ( 0 < count( $addons_to_show ) ) : ?>
311
+ <div class="postbox">
312
+ <table id="fs_addons" class="widefat">
313
+ <thead>
314
+ <tr>
315
+ <th></th>
316
+ <th><?php _efs( 'version', $slug ) ?></th>
317
+ <th><?php _efs( 'plan', $slug ) ?></th>
318
+ <th><?php _efs( 'expiration', $slug ) ?></th>
319
+ <th></th>
320
+ <?php if ( defined( 'WP_FS__DEV_MODE' ) && WP_FS__DEV_MODE ) : ?>
321
+ <th></th>
322
+ <?php endif ?>
323
+ </tr>
324
+ </thead>
325
+ <tbody>
326
+ <?php foreach ( $addons_to_show as $addon_id ) : ?>
327
+ <?php
328
+ $addon = $fs->get_addon( $addon_id );
329
+ $is_addon_activated = $fs->is_addon_activated( $addon->slug );
330
+
331
+ $fs_addon = $is_addon_activated ? freemius( $addon->slug ) : false;
332
+ ?>
333
+ <tr>
334
+ <td>
335
+ <?php echo $addon->title ?>
336
+ </td>
337
+ <?php if ( $is_addon_activated ) : ?>
338
+ <?php // Add-on Installed ?>
339
+ <?php $addon_site = $fs_addon->get_site(); ?>
340
+ <td><?php echo $fs_addon->get_plugin_version() ?></td>
341
+ <td><?php echo is_string( $addon_site->plan->name ) ? strtoupper( $addon_site->plan->title ) : 'FREE' ?></td>
342
+ <?php
343
+ $current_license = $fs_addon->_get_license();
344
+ $is_current_license_expired = is_object( $current_license ) && $current_license->is_expired();
345
+ ?>
346
+ <?php if ( $fs_addon->is_not_paying() ) : ?>
347
+ <?php if ( $is_current_license_expired ) : ?>
348
+ <td><?php _efs( 'expired', $slug ) ?></td>
349
+ <?php endif ?>
350
+ <?php $premium_license = $fs_addon->_get_available_premium_license() ?>
351
+ <td<?php if ( ! $is_current_license_expired ) {
352
+ echo ' colspan="2"';
353
+ } ?>>
354
+ <?php if ( is_object( $premium_license ) && ! $premium_license->is_utilized() ) : ?>
355
+ <?php $site = $fs_addon->get_site() ?>
356
+ <?php fs_ui_action_button(
357
+ $slug, 'account',
358
+ 'activate_license',
359
+ sprintf( __fs( 'activate-x-plan', $slug ), $fs_addon->get_plan_title(), ( $site->is_localhost() && $premium_license->is_free_localhost ) ? '[localhost]' : ( 1 < $premium_license->left() ? $premium_license->left() . ' left' : '' ) ),
360
+ array( 'plugin_id' => $addon_id )
361
+ ) ?>
362
+ <?php else : ?>
363
+ <div class="button-group">
364
+ <?php fs_ui_action_button(
365
+ $slug, 'account',
366
+ $slug . '_sync_license',
367
+ __fs( 'sync-license', $slug ),
368
+ array( 'plugin_id' => $addon_id ),
369
+ false
370
+ ) ?>
371
+ <?php echo sprintf( '<a href="%s" class="thickbox button button-primary" aria-label="%s" data-title="%s">%s</a>',
372
+ esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
373
+ '&TB_iframe=true&width=600&height=550' ) ),
374
+ esc_attr( sprintf( __fs( 'more-information-about-x', $slug ), $addon->title ) ),
375
+ esc_attr( $addon->title ),
376
+ __fs( 'upgrade', $slug )
377
+ ) ?>
378
+ </div>
379
+ <?php endif ?>
380
+ </td>
381
+ <?php else : ?>
382
+ <?php if ( is_object( $current_license ) ) : ?>
383
+ <td><?php
384
+ if ( $current_license->is_lifetime() ) {
385
+ _efs( 'no-expiration', $slug );
386
+ } else if ( $current_license->is_expired() ) {
387
+ _efs( 'expired', $slug );
388
+ } else {
389
+ echo sprintf(
390
+ __fs( 'in-x', $slug ),
391
+ human_time_diff( time(), strtotime( $current_license->expiration ) )
392
+ );
393
+ }
394
+ ?></td>
395
+ <td>
396
+ <?php fs_ui_action_button(
397
+ $slug, 'account',
398
+ 'deactivate_license',
399
+ __fs( 'deactivate-license', $slug ),
400
+ array( 'plugin_id' => $addon_id ),
401
+ false
402
+ ) ?>
403
+ </td>
404
+ <?php endif ?>
405
+ <?php endif ?>
406
+ <?php else : ?>
407
+ <?php // Add-on NOT Installed
408
+ ?>
409
+ <td colspan="4">
410
+ <?php if ( $fs->is_addon_installed( $addon->slug ) ) : ?>
411
+ <?php $addon_file = $fs->get_addon_basename( $addon->slug ) ?>
412
+ <a class="button button-primary"
413
+ href="<?php echo wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file ) ?>"
414
+ title="<?php esc_attr( __fs( 'activate-this-addon', $slug ) ) ?>"
415
+ class="edit"><?php _efs( 'activate', $slug ) ?></a>
416
+ <?php else : ?>
417
+ <?php if ( $fs->is_allowed_to_install() ) : ?>
418
+ <a class="button button-primary"
419
+ href="<?php echo wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $addon->slug ), 'install-plugin_' . $addon->slug ) ?>"><?php _efs( 'install-now', $slug ) ?></a>
420
+ <?php else : ?>
421
+ <a target="_blank" class="button button-primary"
422
+ href="<?php echo $fs->_get_latest_download_local_url( $addon_id ) ?>"><?php _efs( 'download-latest', $slug ) ?></a>
423
+ <?php endif ?>
424
+ <?php endif ?>
425
+ </td>
426
+ <?php endif ?>
427
+ <?php if ( defined( 'WP_FS__DEV_MODE' ) && WP_FS__DEV_MODE ) : ?>
428
+ <td>
429
+ <?php
430
+ if ( $is_addon_activated ) {
431
+ fs_ui_action_button(
432
+ $slug, 'account',
433
+ 'delete_account',
434
+ __fs( 'delete', $slug ),
435
+ array( 'plugin_id' => $addon_id ),
436
+ false
437
+ );
438
+ }
439
+ ?>
440
+ </td>
441
+ <?php endif ?>
442
+ </tr>
443
+ <?php endforeach ?>
444
+ </tbody>
445
+ </table>
446
+ </div>
447
+ <?php endif ?>
448
+
449
+ <?php $fs->do_action( 'after_account_details' ) ?>
450
+ </div>
451
+ </div>
452
+ </div>
453
+ </div>
454
+ </div>
455
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/add-ons.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ /**
15
+ * @var Freemius
16
+ */
17
+ $fs = freemius( $slug );
18
+
19
+ $open_addon_slug = fs_request_get( 'slug' );
20
+
21
+ $open_addon = false;
22
+
23
+ /**
24
+ * @var FS_Plugin[]
25
+ */
26
+ $addons = $fs->get_addons();
27
+ ?>
28
+ <div id="fs_addons" class="wrap">
29
+ <h2><?php printf( __fs( 'add-ons-for-x', $slug ), $fs->get_plugin_name() ) ?></h2>
30
+
31
+ <div id="poststuff">
32
+ <ul class="fs-cards-list">
33
+ <?php foreach ( $addons as $addon ) : ?>
34
+ <?php
35
+ $open_addon = ( $open_addon || ( $open_addon_slug === $addon->slug ) );
36
+
37
+ $price = 0;
38
+ $plans_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans.json" );
39
+ if ( ! isset( $plans_result->error ) ) {
40
+ $plans = $plans_result->plans;
41
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
42
+ $plan = $plans[0];
43
+ $pricing_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans/{$plan->id}/pricing.json" );
44
+ if ( ! isset( $pricing_result->error ) ) {
45
+ // Update plan's pricing.
46
+ $plan->pricing = $pricing_result->pricing;
47
+
48
+ if ( is_array( $plan->pricing ) && 0 < count( $plan->pricing ) ) {
49
+ $min_price = 999999;
50
+ foreach ( $plan->pricing as $pricing ) {
51
+ if ( ! is_null( $pricing->annual_price ) && $pricing->annual_price > 0 ) {
52
+ $min_price = min( $min_price, $pricing->annual_price );
53
+ } else if ( ! is_null( $pricing->monthly_price ) && $pricing->monthly_price > 0 ) {
54
+ $min_price = min( $min_price, 12 * $pricing->monthly_price );
55
+ }
56
+ }
57
+
58
+ if ( $min_price < 999999 ) {
59
+ $price = $min_price;
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ?>
66
+ <li class="fs-card" data-slug="<?php echo $addon->slug ?>">
67
+ <?php
68
+ echo sprintf( '<a href="%s" class="thickbox fs-overlay" aria-label="%s" data-title="%s"></a>',
69
+ esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
70
+ '&TB_iframe=true&width=600&height=550' ) ),
71
+ esc_attr( sprintf( __fs( 'more-information-about-x', $slug ), $addon->title ) ),
72
+ esc_attr( $addon->title )
73
+ );
74
+ ?>
75
+ <?php
76
+ if ( is_null( $addon->info ) ) {
77
+ $addon->info = new stdClass();
78
+ }
79
+ if ( ! isset( $addon->info->card_banner_url ) ) {
80
+ $addon->info->card_banner_url = '//dashboard.freemius.com/assets/img/marketing/blueprint-300x100.jpg';
81
+ }
82
+ if ( ! isset( $addon->info->short_description ) ) {
83
+ $addon->info->short_description = 'What\'s the one thing your add-on does really, really well?';
84
+ }
85
+ ?>
86
+ <div class="fs-inner">
87
+ <ul>
88
+ <li class="fs-card-banner"
89
+ style="background-image: url('<?php echo $addon->info->card_banner_url ?>');"></li>
90
+ <li class="fs-title"><?php echo $addon->title ?></li>
91
+ <li class="fs-offer">
92
+ <span
93
+ class="fs-price"><?php echo ( 0 == $price ) ? __fs( 'free', $slug ) : '$' . number_format( $price, 2 ) ?></span>
94
+ </li>
95
+ <li class="fs-description"><?php echo ! empty( $addon->info->short_description ) ? $addon->info->short_description : 'SHORT DESCRIPTION' ?></li>
96
+ </ul>
97
+ </div>
98
+ </li>
99
+ <?php endforeach ?>
100
+ </ul>
101
+ </div>
102
+ </div>
103
+ <?php if ( $open_addon ) : ?>
104
+ <script type="text/javascript">
105
+ (function ($) {
106
+ var interval = setInterval(function () {
107
+ // Open add-on information page.
108
+ $('.fs-card[data-slug=<?php echo $open_addon_slug ?>] a').click();
109
+ if ($('#TB_iframeContent').length > 0) {
110
+ clearInterval(interval);
111
+ interval = null;
112
+ }
113
+ }, 200);
114
+ })(jQuery);
115
+ </script>
116
+ <?php endif ?>
117
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/admin-notice.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+ <div data-id="<?php echo $VARS['id'] ?>" data-slug="<?php echo $VARS['slug'] ?>" class="<?php
14
+ switch ( $VARS['type'] ) {
15
+ case 'error':
16
+ echo 'error form-invalid';
17
+ break;
18
+ case 'promotion':
19
+ echo 'updated promotion';
20
+ break;
21
+ case 'update':
22
+ // echo 'update-nag update';
23
+ // break;
24
+ case 'success':
25
+ default:
26
+ echo 'updated success';
27
+ break;
28
+ }
29
+ ?> fs-notice<?php if ( $VARS['sticky'] ) {
30
+ echo ' fs-sticky';
31
+ } ?><?php if ( ! empty( $VARS['plugin'] ) ) {
32
+ echo ' fs-has-title';
33
+ } ?>"><?php if ( ! empty( $VARS['plugin'] ) ) : ?><label
34
+ class="fs-plugin-title"><?php echo $VARS['plugin'] ?></label><?php endif ?><?php if ( $VARS['sticky'] ) : ?>
35
+ <div class="fs-close"><i class="dashicons dashicons-no"
36
+ title="<?php _efs( 'dismiss' ) ?>"></i> <span><?php _efs( 'dismiss' ) ?></span>
37
+ </div><?php endif ?>
38
+ <div class="fs-notice-body">
39
+ <?php if ( ! empty( $VARS['title'] ) ) : ?><b><?php echo $VARS['title'] ?></b> <?php endif ?>
40
+ <?php echo $VARS['message'] ?>
41
+ </div>
42
+ </div>
freemius/templates/all-admin-notice.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+ <div class="<?php
14
+ switch ($VARS['type']) {
15
+ case 'error':
16
+ echo 'error form-invalid';
17
+ break;
18
+ case 'update-nag':
19
+ echo 'update-nag ';
20
+ break;
21
+ case 'update':
22
+ case 'success':
23
+ default:
24
+ echo 'updated success';
25
+ break;
26
+ }
27
+ ?> fs-notice">
28
+ <?php if ('update-nag' !== $VARS['type']) : ?><p><?php endif ?>
29
+ <?php if (!empty($VARS['title'])) : ?>
30
+ <b><?php echo $VARS['title'] ?></b>
31
+ <?php endif ?>
32
+ <?php echo $VARS['message'] ?>
33
+ <?php if ('update-nag' !== $VARS['type']) : ?></p><?php endif ?>
34
+ <?php if ($VARS['sticky']) : ?><i class="dashicons dashicons-no"></i><?php endif ?>
35
+ </div>
freemius/templates/checkout.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
18
+
19
+ $slug = $VARS['slug'];
20
+ $fs = freemius( $slug );
21
+
22
+ $timestamp = time();
23
+
24
+ $context_params = array(
25
+ 'plugin_id' => $fs->get_id(),
26
+ 'plugin_public_key' => $fs->get_public_key(),
27
+ 'plugin_version' => $fs->get_plugin_version(),
28
+ );
29
+
30
+ // Get site context secure params.
31
+ if ( $fs->is_registered() ) {
32
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
33
+ $fs->get_site(),
34
+ $timestamp,
35
+ 'checkout'
36
+ ) );
37
+ } else {
38
+ $current_user = wp_get_current_user();
39
+
40
+ // Add site and user info to the request, this information
41
+ // is NOT being stored unless the user complete the purchase
42
+ // and agrees to the TOS.
43
+ $context_params = array_merge( $context_params, array(
44
+ 'user_firstname' => $current_user->user_firstname,
45
+ 'user_lastname' => $current_user->user_lastname,
46
+ 'user_email' => $current_user->user_email,
47
+ // 'user_nickname' => $current_user->user_nicename,
48
+ // 'plugin_slug' => $slug,
49
+ // 'site_url' => get_site_url(),
50
+ // 'site_name' => get_bloginfo( 'name' ),
51
+ // 'platform_version' => get_bloginfo( 'version' ),
52
+ // 'language' => get_bloginfo( 'language' ),
53
+ // 'charset' => get_bloginfo( 'charset' ),
54
+ // 'account_url' => fs_nonce_url( $fs->_get_admin_page_url(
55
+ // 'account',
56
+ // array( 'fs_action' => 'sync_user' )
57
+ // ), 'sync_user' ),
58
+ ) );
59
+
60
+ $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
61
+
62
+ if ( is_object( $fs_user ) ) {
63
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
64
+ $fs_user,
65
+ $timestamp,
66
+ 'checkout'
67
+ ) );
68
+ }
69
+ }
70
+
71
+ if ( $fs->is_payments_sandbox() ) // Append plugin secure token for sandbox mode authentication.)
72
+ {
73
+ $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
74
+ $fs->get_plugin(),
75
+ $timestamp,
76
+ 'checkout'
77
+ );
78
+ }
79
+
80
+ $return_url = fs_nonce_url( $fs->_get_admin_page_url(
81
+ 'account',
82
+ array(
83
+ 'fs_action' => $slug . '_sync_license',
84
+ 'plugin_id' => isset( $_GET['plugin_id'] ) ? $_GET['plugin_id'] : $fs->get_id()
85
+ )
86
+ ), $slug . '_sync_license' );
87
+
88
+ $query_params = array_merge( $context_params, $_GET, array(
89
+ // Current plugin version.
90
+ 'plugin_version' => $fs->get_plugin_version(),
91
+ 'return_url' => $return_url,
92
+ // Admin CSS URL for style/design competability.
93
+ // 'wp_admin_css' => get_bloginfo('wpurl') . "/wp-admin/load-styles.php?c=1&load=buttons,wp-admin,dashicons",
94
+ ) );
95
+ ?>
96
+ <div class="fs-secure-notice">
97
+ <i class="dashicons dashicons-lock"></i>
98
+ <span><b>Secure HTTPS Checkout</b> - PCI compliant, running via iframe from external domain</span>
99
+ </div>
100
+ <div id="fs_contact" class="wrap" style="margin: 40px 0 -65px -20px;">
101
+ <div id="iframe"></div>
102
+ <script type="text/javascript">
103
+ // http://stackoverflow.com/questions/4583703/jquery-post-request-not-ajax
104
+ jQuery(function ($) {
105
+ $.extend({
106
+ form: function (url, data, method) {
107
+ if (method == null) method = 'POST';
108
+ if (data == null) data = {};
109
+
110
+ var form = $('<form>').attr({
111
+ method: method,
112
+ action: url
113
+ }).css({
114
+ display: 'none'
115
+ });
116
+
117
+ var addData = function (name, data) {
118
+ if ($.isArray(data)) {
119
+ for (var i = 0; i < data.length; i++) {
120
+ var value = data[i];
121
+ addData(name + '[]', value);
122
+ }
123
+ } else if (typeof data === 'object') {
124
+ for (var key in data) {
125
+ if (data.hasOwnProperty(key)) {
126
+ addData(name + '[' + key + ']', data[key]);
127
+ }
128
+ }
129
+ } else if (data != null) {
130
+ form.append($('<input>').attr({
131
+ type : 'hidden',
132
+ name : String(name),
133
+ value: String(data)
134
+ }));
135
+ }
136
+ };
137
+
138
+ for (var key in data) {
139
+ if (data.hasOwnProperty(key)) {
140
+ addData(key, data[key]);
141
+ }
142
+ }
143
+
144
+ return form.appendTo('body');
145
+ }
146
+ });
147
+ });
148
+
149
+ (function ($) {
150
+ $(function () {
151
+
152
+ var
153
+ // Keep track of the iframe height.
154
+ iframe_height = 800,
155
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
156
+ // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
157
+ // passed via query string or hard coded into the child page, it depends on your needs).
158
+ src = base_url + '/checkout/?<?php echo (isset($_REQUEST['XDEBUG_SESSION']) ? 'XDEBUG_SESSION=' . $_REQUEST['XDEBUG_SESSION'] . '&' : '') . http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
159
+
160
+ // Append the Iframe into the DOM.
161
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
162
+ .appendTo('#iframe');
163
+
164
+ FS.PostMessage.init(base_url);
165
+ FS.PostMessage.receiveOnce('height', function (data) {
166
+ var h = data.height;
167
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
168
+ iframe_height = h;
169
+ $("#iframe iframe").height(iframe_height + 'px');
170
+ }
171
+ });
172
+
173
+ FS.PostMessage.receiveOnce('install', function (data) {
174
+ // Post data to activation URL.
175
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
176
+ 'fs_action' => $slug . '_activate_new',
177
+ 'plugin_id' => isset($_GET['plugin_id']) ? $_GET['plugin_id'] : $fs->get_id()
178
+ )), $slug . '_activate_new') ?>', {
179
+ user_id : data.user.id,
180
+ user_secret_key : data.user.secret_key,
181
+ user_public_key : data.user.public_key,
182
+ install_id : data.install.id,
183
+ install_secret_key: data.install.secret_key,
184
+ install_public_key: data.install.public_key
185
+ }).submit();
186
+ });
187
+
188
+ FS.PostMessage.receiveOnce('pending_activation', function (data) {
189
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
190
+ 'fs_action' => $slug . '_activate_new',
191
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
192
+ 'pending_activation' => true,
193
+ )), $slug . '_activate_new') ?>', {
194
+ user_email: data.user_email
195
+ }).submit();
196
+ });
197
+
198
+ FS.PostMessage.receiveOnce('get_context', function () {
199
+ console.debug('receiveOnce', 'get_context');
200
+
201
+ // If the user didn't connect his account with Freemius,
202
+ // once he accepts the Terms of Service and Privacy Policy,
203
+ // and then click the purchase button, the context information
204
+ // of the user will be shared with Freemius in order to complete the
205
+ // purchase workflow and activate the license for the right user.
206
+ <?php $current_user = wp_get_current_user() ?>
207
+ FS.PostMessage.post('context', {
208
+ // user_firstname: '<?php //echo $current_user->user_firstname ?>//',
209
+ // user_lastname: '<?php //echo $current_user->user_lastname ?>//',
210
+ // user_email: '<?php //echo $current_user->user_email ?>//'
211
+ plugin_id : '<?php echo $fs->get_id() ?>',
212
+ plugin_public_key: '<?php echo $fs->get_public_key() ?>',
213
+ plugin_version : '<?php echo $fs->get_plugin_version() ?>',
214
+ plugin_slug : '<?php echo $slug ?>',
215
+ site_name : '<?php echo get_bloginfo('name') ?>',
216
+ platform_version : '<?php echo get_bloginfo('version') ?>',
217
+ language : '<?php echo get_bloginfo('language') ?>',
218
+ charset : '<?php echo get_bloginfo('charset') ?>',
219
+ return_url : '<?php echo $return_url ?>',
220
+ account_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url(
221
+ 'account',
222
+ array('fs_action' => 'sync_user')
223
+ ), 'sync_user') ?>',
224
+ activation_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url('',
225
+ array(
226
+ 'fs_action' => $slug . '_activate_new',
227
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
228
+
229
+ )),
230
+ $slug . '_activate_new') ?>'
231
+ }, iframe[0]);
232
+ });
233
+
234
+ FS.PostMessage.receiveOnce('get_dimensions', function (data) {
235
+ console.debug('receiveOnce', 'get_dimensions');
236
+
237
+ FS.PostMessage.post('dimensions', {
238
+ height : $(document.body).height(),
239
+ scrollTop: $(document).scrollTop()
240
+ }, iframe[0]);
241
+ });
242
+ });
243
+ })(jQuery);
244
+ </script>
245
+ </div>
246
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/connect.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+ $is_pending_activation = $fs->is_pending_activation();
16
+
17
+ $fs->_enqueue_connect_essentials();
18
+
19
+ $current_user = wp_get_current_user();
20
+
21
+ $first_name = $current_user->user_firstname;
22
+ if ( empty( $first_name ) ) {
23
+ $first_name = $current_user->nickname;
24
+ }
25
+
26
+ $site_url = get_site_url();
27
+ $protocol_pos = strpos( $site_url, '://' );
28
+ if ( false !== $protocol_pos ) {
29
+ $site_url = substr( $site_url, $protocol_pos + 3 );
30
+ }
31
+
32
+ $freemius_site_url = $fs->has_paid_plan() ?
33
+ 'https://freemius.com/wordpress/' :
34
+ // Insights platform information.
35
+ 'https://freemius.com/wordpress/insights/';
36
+ ?>
37
+ <div id="fs_connect" class="wrap<?php if ( ! $fs->enable_anonymous() || $is_pending_activation ) {
38
+ echo ' fs-anonymous-disabled';
39
+ } ?>">
40
+ <div class="fs-visual">
41
+ <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b>
42
+ <i class="dashicons dashicons-plus fs-first"></i>
43
+ <?php
44
+ $vars = array( 'slug' => $slug );
45
+ fs_require_once_template( 'plugin-icon.php', $vars );
46
+ ?>
47
+ <i class="dashicons dashicons-plus fs-second"></i>
48
+ <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/>
49
+ </div>
50
+ <div class="fs-content">
51
+ <p><?php
52
+ if ( $is_pending_activation ) {
53
+ echo $fs->apply_filters( 'pending_activation_message', sprintf(
54
+ __fs( 'thanks-x', $slug ) . '<br>' .
55
+ __fs( 'pending-activation-message', $slug ),
56
+ $first_name,
57
+ '<b>' . $fs->get_plugin_name() . '</b>',
58
+ '<b>' . $current_user->user_email . '</b>'
59
+ ) );
60
+ } else {
61
+ $filter = 'connect_message';
62
+ $default_optin_message = 'connect-message';
63
+
64
+ if ( $fs->is_plugin_update() ) {
65
+ // If Freemius was added on a plugin update, set different
66
+ // opt-in message.
67
+ $default_optin_message = 'connect-message_on-update';
68
+
69
+ // If user customized the opt-in message on update, use
70
+ // that message. Otherwise, fallback to regular opt-in
71
+ // custom message if exist.
72
+ if ( $fs->has_filter( 'connect_message_on_update' ) ) {
73
+ $filter = 'connect_message_on_update';
74
+ }
75
+ }
76
+
77
+ echo $fs->apply_filters( $filter,
78
+ sprintf(
79
+ __fs( 'hey-x', $slug ) . '<br>' .
80
+ __fs( $default_optin_message, $slug ),
81
+ $first_name,
82
+ '<b>' . $fs->get_plugin_name() . '</b>',
83
+ '<b>' . $current_user->user_login . '</b>',
84
+ '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
85
+ '<a href="' . $freemius_site_url . '" target="_blank">freemius.com</a>'
86
+ ),
87
+ $first_name,
88
+ $fs->get_plugin_name(),
89
+ $current_user->user_login,
90
+ '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
91
+ '<a href="' . $freemius_site_url . '" target="_blank">freemius.com</a>'
92
+ );
93
+ }
94
+ ?></p>
95
+ </div>
96
+ <div class="fs-actions">
97
+ <?php if ( $fs->enable_anonymous() && ! $is_pending_activation ) : ?>
98
+ <a href="<?php echo wp_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $slug . '_skip_activation' ) ), $slug . '_skip_activation' ) ?>"
99
+ class="button button-secondary" tabindex="2"><?php _efs( 'skip', $slug ) ?></a>
100
+ <?php endif ?>
101
+
102
+ <?php $fs_user = Freemius::_get_user_by_email( $current_user->user_email ) ?>
103
+ <?php if ( is_object( $fs_user ) && ! $is_pending_activation ) : ?>
104
+ <form action="" method="POST">
105
+ <input type="hidden" name="fs_action" value="<?php echo $slug ?>_activate_existing">
106
+ <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?>
107
+ <button class="button button-primary" tabindex="1"
108
+ type="submit"><?php _efs( 'opt-in-connect', $slug ) ?></button>
109
+ </form>
110
+ <?php else : ?>
111
+ <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
112
+ <?php
113
+ $params = array(
114
+ 'user_firstname' => $current_user->user_firstname,
115
+ 'user_lastname' => $current_user->user_lastname,
116
+ 'user_nickname' => $current_user->user_nicename,
117
+ 'user_email' => $current_user->user_email,
118
+ 'user_ip' => WP_FS__REMOTE_ADDR,
119
+ 'plugin_slug' => $slug,
120
+ 'plugin_id' => $fs->get_id(),
121
+ 'plugin_public_key' => $fs->get_public_key(),
122
+ 'plugin_version' => $fs->get_plugin_version(),
123
+ 'return_url' => wp_nonce_url( $fs->_get_admin_page_url(
124
+ '',
125
+ array( 'fs_action' => $slug . '_activate_new' )
126
+ ), $slug . '_activate_new' ),
127
+ 'account_url' => wp_nonce_url( $fs->_get_admin_page_url(
128
+ 'account',
129
+ array( 'fs_action' => 'sync_user' )
130
+ ), 'sync_user' ),
131
+ 'site_uid' => $fs->get_anonymous_id(),
132
+ 'site_url' => get_site_url(),
133
+ 'site_name' => get_bloginfo( 'name' ),
134
+ 'platform_version' => get_bloginfo( 'version' ),
135
+ 'php_version' => phpversion(),
136
+ 'language' => get_bloginfo( 'language' ),
137
+ 'charset' => get_bloginfo( 'charset' ),
138
+ );
139
+
140
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $fs->has_secret_key() ) {
141
+ // Even though rand() is known for its security issues,
142
+ // the timestamp adds another layer of protection.
143
+ // It would be very hard for an attacker to get the secret key form here.
144
+ // Plus, this should never run in production since the secret should never
145
+ // be included in the production version.
146
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
147
+ $params['salt'] = md5( uniqid( rand() ) );
148
+ $params['secure'] = md5(
149
+ $params['ts'] .
150
+ $params['salt'] .
151
+ $fs->get_secret_key()
152
+ );
153
+ }
154
+ ?>
155
+ <?php foreach ( $params as $name => $value ) : ?>
156
+ <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
157
+ <?php endforeach ?>
158
+ <button class="button button-primary" tabindex="1"
159
+ type="submit"><?php _efs( $is_pending_activation ? 'resend-activation-email' : 'opt-in-connect', $slug ) ?></button>
160
+ </form>
161
+ <?php endif ?>
162
+ </div><?php
163
+
164
+ // Set core permission list items.
165
+ $permissions = array(
166
+ 'profile' => array(
167
+ 'icon-class' => 'dashicons dashicons-admin-users',
168
+ 'label' => __fs( 'permissions-profile' ),
169
+ 'desc' => __fs( 'permissions-profile_desc' ),
170
+ 'priority' => 5,
171
+ ),
172
+ 'site' => array(
173
+ 'icon-class' => 'dashicons dashicons-wordpress',
174
+ 'label' => __fs( 'permissions-site' ),
175
+ 'desc' => __fs( 'permissions-site_desc' ),
176
+ 'priority' => 10,
177
+ ),
178
+ 'events' => array(
179
+ 'icon-class' => 'dashicons dashicons-admin-plugins',
180
+ 'label' => __fs( 'permissions-events' ),
181
+ 'desc' => __fs( 'permissions-events_desc' ),
182
+ 'priority' => 20,
183
+ ),
184
+ );
185
+
186
+ // Add newsletter permissions if enabled.
187
+ if ( $fs->is_permission_requested( 'newsletter' ) ) {
188
+ $permissions['newsletter'] = array(
189
+ 'icon-class' => 'dashicons dashicons-email-alt',
190
+ 'label' => __fs( 'permissions-newsletter' ),
191
+ 'desc' => __fs( 'permissions-newsletter_desc' ),
192
+ 'priority' => 15,
193
+ );
194
+ }
195
+
196
+ // Allow filtering of the permissions list.
197
+ $permissions = $fs->apply_filters( 'permission_list', $permissions );
198
+
199
+ // Sort by priority.
200
+ uasort( $permissions, 'fs_sort_by_priority' );
201
+
202
+ if ( ! empty( $permissions ) ) : ?>
203
+ <div class="fs-permissions">
204
+ <a class="fs-trigger" href="#"><?php _efs( 'what-permissions', $slug ) ?></a>
205
+ <ul><?php
206
+ foreach ( $permissions as $id => $permission ) : ?>
207
+ <li id="fs-permission-<?php esc_attr_e( $id ); ?>"
208
+ class="fs-permission fs-<?php esc_attr_e( $id ); ?>">
209
+ <i class="<?php esc_attr_e( $permission['icon-class'] ); ?>"></i>
210
+
211
+ <div>
212
+ <span><?php esc_html_e( $permission['label'] ); ?></span>
213
+
214
+ <p><?php esc_html_e( $permission['desc'] ); ?></p>
215
+ </div>
216
+ </li>
217
+ <?php endforeach; ?>
218
+ </ul>
219
+ </div>
220
+ <?php endif; ?>
221
+
222
+ <div class="fs-terms">
223
+ <a href="https://freemius.com/privacy/" target="_blank"><?php _efs( 'privacy-policy', $slug ) ?></a>
224
+ &nbsp;&nbsp;-&nbsp;&nbsp;
225
+ <a href="https://freemius.com/terms/" target="_blank"><?php _efs( 'tos', $slug ) ?></a>
226
+ </div>
227
+ </div>
228
+ <script type="text/javascript">
229
+ (function ($) {
230
+ $('.button').on('click', function () {
231
+ // Set loading mode.
232
+ $(document.body).css({'cursor': 'wait'});
233
+ });
234
+ $('.button.button-primary').on('click', function () {
235
+ $(this).addClass('fs-loading');
236
+ $(this).html('<?php _efs( $is_pending_activation ? 'sending-email' : 'activating' , $slug ) ?>...').css({'cursor': 'wait'});
237
+ });
238
+ $('.fs-permissions .fs-trigger').on('click', function () {
239
+ $('.fs-permissions').toggleClass('fs-open');
240
+ });
241
+ })(jQuery);
242
+ </script>
freemius/templates/contact.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+ fs_enqueue_local_style( 'fs_checkout', '/admin/common.css' );
18
+
19
+ $slug = $VARS['slug'];
20
+ $fs = freemius( $slug );
21
+
22
+ $context_params = array(
23
+ 'plugin_id' => $fs->get_id(),
24
+ 'plugin_public_key' => $fs->get_public_key(),
25
+ 'plugin_version' => $fs->get_plugin_version(),
26
+ );
27
+
28
+
29
+ // Get site context secure params.
30
+ if ( $fs->is_registered() ) {
31
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
32
+ $fs->get_site(),
33
+ time(),
34
+ 'contact'
35
+ ) );
36
+ }
37
+
38
+ $query_params = array_merge( $_GET, array_merge( $context_params, array(
39
+ 'plugin_version' => $fs->get_plugin_version(),
40
+ 'wp_login_url' => wp_login_url(),
41
+ 'site_url' => get_site_url(),
42
+ // 'wp_admin_css' => get_bloginfo('wpurl') . "/wp-admin/load-styles.php?c=1&load=buttons,wp-admin,dashicons",
43
+ ) ) );
44
+ ?>
45
+ <div class="fs-secure-notice">
46
+ <i class="dashicons dashicons-lock"></i>
47
+ <span><b>Secure HTTPS contact page</b>, running via iframe from external domain</span>
48
+ </div>
49
+ <div id="fs_contact" class="wrap" style="margin: 40px 0 -65px -20px;">
50
+ <div id="iframe"></div>
51
+ <script type="text/javascript">
52
+ (function ($) {
53
+ $(function () {
54
+
55
+ var
56
+ // Keep track of the iframe height.
57
+ iframe_height = 800,
58
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
59
+ src = base_url + '/contact/?<?php echo http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
60
+
61
+ // Append the Iframe into the DOM.
62
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
63
+ .appendTo('#iframe');
64
+
65
+ FS.PostMessage.init(base_url);
66
+ FS.PostMessage.receive('height', function (data) {
67
+ var h = data.height;
68
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
69
+ iframe_height = h;
70
+ $("#iframe iframe").height(iframe_height + 'px');
71
+ }
72
+ });
73
+ });
74
+ })(jQuery);
75
+ </script>
76
+ </div>
77
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/deactivation-feedback-modal.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.2
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ $confirmation_message = $fs->apply_filters( 'uninstall_confirmation_message', '' );
17
+
18
+ $reasons = $VARS['reasons'];
19
+
20
+ $reasons_list_items_html = '';
21
+
22
+ foreach ( $reasons as $reason ) {
23
+ $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
24
+ $reasons_list_items_html .= '<li class="' . $list_item_classes . '" data-input-type="' . $reason['input_type'] . '" data-input-placeholder="' . $reason['input_placeholder'] . '"><label><span><input type="radio" name="selected-reason" value="' . $reason['id'] . '"/></span><span>' . $reason['text'] . '</span></label></li>';
25
+ }
26
+ ?>
27
+ <script type="text/javascript">
28
+ (function( $ ) {
29
+ var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ); ?>,
30
+ modalHtml =
31
+ '<div class="fs-modal<?php echo empty( $confirmation_message ) ? ' no-confirmation-message' : ''; ?>">'
32
+ + ' <div class="fs-modal-dialog">'
33
+ + ' <div class="fs-modal-body">'
34
+ + ' <div class="fs-modal-panel" data-panel-id="confirm"><p><?php echo $confirmation_message; ?></p></div>'
35
+ + ' <div class="fs-modal-panel active" data-panel-id="reasons"><h3><strong><?php printf( __fs( 'deactivation-share-reason' , $slug ) ); ?>:</strong></h3><ul id="reasons-list">' + reasonsHtml + '</ul></div>'
36
+ + ' </div>'
37
+ + ' <div class="fs-modal-footer">'
38
+ + ' <a href="#" class="button button-secondary button-deactivate"></a>'
39
+ + ' <a href="#" class="button button-primary button-close"><?php printf( __fs( 'deactivation-modal-button-cancel' , $slug ) ); ?></a>'
40
+ + ' </div>'
41
+ + ' </div>'
42
+ + '</div>',
43
+ $modal = $( modalHtml ),
44
+ $deactivateLink = $( '#the-list .deactivate > [data-slug=<?php echo $VARS['slug']; ?>].fs-slug' ).prev();
45
+
46
+ $modal.appendTo( $( 'body' ) );
47
+
48
+ registerEventHandlers();
49
+
50
+ function registerEventHandlers() {
51
+ $deactivateLink.click(function ( evt ) {
52
+ evt.preventDefault();
53
+
54
+ showModal();
55
+ });
56
+
57
+ $modal.on( 'click', '.button', function( evt ) {
58
+ evt.preventDefault();
59
+
60
+ if ( $( this ).hasClass( 'disabled' ) ) {
61
+ return;
62
+ }
63
+
64
+ var _parent = $( this ).parents( '.fs-modal:first' );
65
+ var _this = $( this );
66
+
67
+ if ( _this.hasClass( 'allow-deactivate' ) ) {
68
+ var $radio = $( 'input[type="radio"]:checked' );
69
+
70
+ if ( 0 === $radio.length ) {
71
+ // If no selected reason, just deactivate the plugin.
72
+ window.location.href = $deactivateLink.attr( 'href' );
73
+ return;
74
+ }
75
+
76
+ var $selected_reason = $radio.parents( 'li:first' ),
77
+ $input = $selected_reason.find( 'textarea, input[type="text"]' );
78
+
79
+ $.ajax({
80
+ url: ajaxurl,
81
+ method: 'POST',
82
+ data: {
83
+ 'action' : 'submit-uninstall-reason',
84
+ 'reason_id' : $radio.val(),
85
+ 'reason_info' : ( 0 !== $input.length ) ? $input.val().trim() : ''
86
+ },
87
+ beforeSend: function() {
88
+ _parent.find( '.button' ).addClass( 'disabled' );
89
+ _parent.find( '.button-secondary' ).text( 'Processing...' );
90
+ },
91
+ complete: function() {
92
+ // Do not show the dialog box, deactivate the plugin.
93
+ window.location.href = $deactivateLink.attr( 'href' );
94
+ }
95
+ });
96
+ } else if ( _this.hasClass( 'button-deactivate' ) ) {
97
+ // Change the Deactivate button's text and show the reasons panel.
98
+ _parent.find( '.button-deactivate').addClass( 'allow-deactivate' );
99
+
100
+ showPanel( 'reasons' );
101
+ }
102
+ });
103
+
104
+ $modal.on( 'click', 'input[type="radio"]', function() {
105
+ var _parent = $( this ).parents( 'li:first' );
106
+
107
+ $modal.find( '.reason-input' ).remove();
108
+ $modal.find( '.button-deactivate').text( '<?php printf( __fs( 'deactivation-modal-button-submit' , $slug ) ); ?>' );
109
+
110
+ if ( _parent.hasClass( 'has-input' ) ) {
111
+ var inputType = _parent.data( 'input-type' ),
112
+ inputPlaceholder = _parent.data( 'input-placeholder' ),
113
+ reasonInputHtml = '<div class="reason-input">' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>';
114
+
115
+ _parent.append( $( reasonInputHtml ) );
116
+ _parent.find( 'input, textarea' ).attr( 'placeholder', inputPlaceholder ).focus();
117
+ }
118
+ });
119
+
120
+ // If the user has clicked outside the window, cancel it.
121
+ $modal.on( 'click', function( evt ) {
122
+ var $target = $( evt.target );
123
+
124
+ // If the user has clicked anywhere in the modal dialog, just return.
125
+ if ( $target.hasClass( 'fs-modal-body' ) || $target.hasClass( 'fs-modal-footer' ) ) {
126
+ return;
127
+ }
128
+
129
+ // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
130
+ if ( ! $target.hasClass( 'button-close' ) && ( $target.parents( '.fs-modal-body').length > 0 || $target.parents( '.fs-modal-footer').length > 0 ) ) {
131
+ return;
132
+ }
133
+
134
+ closeModal();
135
+ });
136
+ }
137
+
138
+ function showModal() {
139
+ resetModal();
140
+
141
+ // Display the dialog box.
142
+ $modal.addClass( 'active' );
143
+
144
+ $( 'body' ).addClass( 'has-fs-modal' );
145
+ }
146
+
147
+ function closeModal() {
148
+ $modal.removeClass( 'active' );
149
+
150
+ $( 'body' ).removeClass( 'has-fs-modal' );
151
+ }
152
+
153
+ function resetModal() {
154
+ $modal.find( '.button' ).removeClass( 'disabled' );
155
+
156
+ // Uncheck all radio buttons.
157
+ $modal.find( 'input[type="radio"]' ).prop( 'checked', false );
158
+
159
+ // Remove all input fields ( textfield, textarea ).
160
+ $modal.find( '.reason-input' ).remove();
161
+
162
+ var $deactivateButton = $modal.find( '.button-deactivate' );
163
+
164
+ /*
165
+ * If the modal dialog has no confirmation message, that is, it has only one panel, then ensure
166
+ * that clicking the deactivate button will actually deactivate the plugin.
167
+ */
168
+ if ( $modal.hasClass( 'no-confirmation-message' ) ) {
169
+ $deactivateButton.addClass( 'allow-deactivate' );
170
+
171
+ showPanel( 'reasons' );
172
+ } else {
173
+ $deactivateButton.removeClass( 'allow-deactivate' );
174
+
175
+ showPanel( 'confirm' );
176
+ }
177
+ }
178
+
179
+ function showPanel( panelType ) {
180
+ $modal.find( '.fs-modal-panel' ).removeClass( 'active ');
181
+ $modal.find( '[data-panel-id="' + panelType + '"]' ).addClass( 'active' );
182
+
183
+ updateButtonLabels();
184
+ }
185
+
186
+ function updateButtonLabels() {
187
+ var $deactivateButton = $modal.find( '.button-deactivate' );
188
+
189
+ // Reset the deactivate button's text.
190
+ if ( 'confirm' === getCurrentPanel() ) {
191
+ $deactivateButton.text( '<?php printf( __fs( 'deactivation-modal-button-confirm' , $slug ) ); ?>' );
192
+ } else {
193
+ $deactivateButton.text( '<?php printf( __fs( 'deactivation-modal-button-deactivate' , $slug ) ); ?>' );
194
+ }
195
+ }
196
+
197
+ function getCurrentPanel() {
198
+ return $modal.find( '.fs-modal-panel.active' ).attr( 'data-panel-id' );
199
+ }
200
+ })( jQuery );
201
+ </script>
freemius/templates/debug.php ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ global $fs_active_plugins;
14
+
15
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
16
+ ?>
17
+ <h1><?php echo __fs( 'Freemius Debug' ) . ' - ' . __fs( 'SDK' ) . ' v.' . $fs_active_plugins->newest->version ?></h1>
18
+ <h2><?php _efs( 'actions' ) ?></h2>
19
+ <table>
20
+ <tbody>
21
+ <tr>
22
+ <td>
23
+ <!-- Delete All Accounts -->
24
+ <form action="" method="POST">
25
+ <input type="hidden" name="fs_action" value="delete_all_accounts">
26
+ <?php wp_nonce_field( 'delete_all_accounts' ) ?>
27
+ <button class="button button-primary"
28
+ onclick="if (confirm('<?php _efs( 'delete-all-confirm' ) ?>')) this.parentNode.submit(); return false;"><?php _efs( 'delete-all-accounts' ) ?></button>
29
+ </form>
30
+ </td>
31
+ <td>
32
+ <!-- Clear API Cache -->
33
+ <form action="" method="POST">
34
+ <input type="hidden" name="fs_clear_api_cache" value="true">
35
+ <button class="button button-primary"><?php _efs( 'clear-api-cache' ) ?></button>
36
+ </form>
37
+ </td>
38
+ <td>
39
+ <!-- Sync Data with Server -->
40
+ <form action="" method="POST">
41
+ <input type="hidden" name="background_sync" value="true">
42
+ <button class="button button-primary"><?php _efs( 'sync-data-from-server' ) ?></button>
43
+ </form>
44
+ </td>
45
+ </tr>
46
+ </tbody>
47
+ </table>
48
+ <h2><?php _efs( 'sdk-versions' ) ?></h2>
49
+ <table id="fs_sdks" class="widefat">
50
+ <thead>
51
+ <tr>
52
+ <th><?php _efs( 'version' ) ?></th>
53
+ <th><?php _efs( 'sdk-path' ) ?></th>
54
+ <th><?php _efs( 'plugin-path' ) ?></th>
55
+ <th><?php _efs( 'is-active' ) ?></th>
56
+ </tr>
57
+ </thead>
58
+ <tbody>
59
+ <?php foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) : ?>
60
+ <?php $is_active = ( WP_FS__SDK_VERSION == $data->version ) ?>
61
+ <tr<?php if ( $is_active ) {
62
+ echo ' style="background: #E6FFE6; font-weight: bold"';
63
+ } ?>>
64
+ <td><?php echo $data->version ?></td>
65
+ <td><?php echo $sdk_path ?></td>
66
+ <td><?php echo $data->plugin_path ?></td>
67
+ <td><?php echo ( $is_active ) ? 'Active' : 'Inactive' ?></td>
68
+ </tr>
69
+ <?php endforeach ?>
70
+ </tbody>
71
+ </table>
72
+ <?php $plugins = $fs_options->get_option( 'plugins' ) ?>
73
+ <?php if ( is_array( $plugins ) && 0 < count( $plugins ) ) : ?>
74
+ <h2><?php _efs( 'plugins' ) ?></h2>
75
+ <table id="fs_plugins" class="widefat">
76
+ <thead>
77
+ <tr>
78
+ <th><?php _efs( 'id' ) ?></th>
79
+ <th><?php _efs( 'slug' ) ?></th>
80
+ <th><?php _efs( 'version' ) ?></th>
81
+ <th><?php _efs( 'title' ) ?></th>
82
+ <th><?php _efs( 'api' ) ?></th>
83
+ <th><?php _efs( 'freemius-state' ) ?></th>
84
+ <th><?php _efs( 'plugin-path' ) ?></th>
85
+ <th><?php _efs( 'public-key' ) ?></th>
86
+ </tr>
87
+ </thead>
88
+ <tbody>
89
+ <?php foreach ( $plugins as $slug => $data ) : ?>
90
+ <?php $is_active = is_plugin_active( $data->file ) ?>
91
+ <?php $fs = $is_active ? freemius( $slug ) : null ?>
92
+ <tr<?php if ( $is_active ) {
93
+ echo ' style="background: #E6FFE6; font-weight: bold"';
94
+ } ?>>
95
+ <td><?php echo $data->id ?></td>
96
+ <td><?php echo $slug ?></td>
97
+ <td><?php echo $data->version ?></td>
98
+ <td><?php echo $data->title ?></td>
99
+ <td><?php if ( $is_active ) {
100
+ echo $fs->has_api_connectivity() ?
101
+ __fs( 'connected' ) :
102
+ __fs( 'blocked' );
103
+ } ?></td>
104
+ <td><?php if ( $is_active ) {
105
+ echo $fs->is_on() ?
106
+ __fs( 'on' ) :
107
+ __fs( 'off' );
108
+ } ?></td>
109
+ <td><?php echo $data->file ?></td>
110
+ <td><?php echo $data->public_key ?></td>
111
+ </tr>
112
+ <?php endforeach ?>
113
+ </tbody>
114
+ </table>
115
+ <?php endif ?>
116
+ <?php
117
+ /**
118
+ * @var FS_Site[] $sites
119
+ */
120
+ $sites = $VARS['sites'];
121
+ ?>
122
+ <?php if ( is_array( $sites ) && 0 < count( $sites ) ) : ?>
123
+ <h2><?php _efs( 'plugin-installs' ) ?> / <?php _efs( 'sites' ) ?></h2>
124
+ <table id="fs_installs" class="widefat">
125
+ <thead>
126
+ <tr>
127
+ <th><?php _efs( 'id' ) ?></th>
128
+ <th><?php _efs( 'plan' ) ?></th>
129
+ <th><?php _efs( 'public-key' ) ?></th>
130
+ <th><?php _efs( 'secret-key' ) ?></th>
131
+ </tr>
132
+ </thead>
133
+ <tbody>
134
+ <?php foreach ( $sites as $slug => $site ) : ?>
135
+ <tr>
136
+ <td><?php echo $site->id ?></td>
137
+ <td><?php
138
+ echo is_object( $site->plan ) ? $site->plan->name : ''
139
+ ?></td>
140
+ <td><?php echo $site->public_key ?></td>
141
+ <td><?php echo $site->secret_key ?></td>
142
+ </tr>
143
+ <?php endforeach ?>
144
+ </tbody>
145
+ </table>
146
+ <?php endif ?>
147
+ <?php
148
+ $addons = $VARS['addons'];
149
+ ?>
150
+ <?php foreach ( $addons as $plugin_id => $plugin_addons ) : ?>
151
+ <h2><?php printf( __fs( 'addons-of-x' ), $plugin_id ) ?></h2>
152
+ <table id="fs_addons" class="widefat">
153
+ <thead>
154
+ <tr>
155
+ <th><?php _efs( 'id' ) ?></th>
156
+ <th><?php _efs( 'title' ) ?></th>
157
+ <th><?php _efs( 'slug' ) ?></th>
158
+ <th><?php _efs( 'version' ) ?></th>
159
+ <th><?php _efs( 'public-key' ) ?></th>
160
+ <th><?php _efs( 'secret-key' ) ?></th>
161
+ </tr>
162
+ </thead>
163
+ <tbody>
164
+ <?php
165
+ /**
166
+ * @var FS_Plugin[] $plugin_addons
167
+ */
168
+ foreach ( $plugin_addons as $addon ) : ?>
169
+ <tr>
170
+ <td><?php echo $addon->id ?></td>
171
+ <td><?php echo $addon->title ?></td>
172
+ <td><?php echo $addon->slug ?></td>
173
+ <td><?php echo $addon->version ?></td>
174
+ <td><?php echo $addon->public_key ?></td>
175
+ <td><?php echo $addon->secret_key ?></td>
176
+ </tr>
177
+ <?php endforeach ?>
178
+ </tbody>
179
+ </table>
180
+ <?php endforeach ?>
181
+ <?php
182
+ /**
183
+ * @var FS_User[] $users
184
+ */
185
+ $users = $VARS['users'];
186
+ ?>
187
+ <?php if ( is_array( $users ) && 0 < count( $users ) ) : ?>
188
+ <h2><?php _efs( 'users' ) ?></h2>
189
+ <table id="fs_users" class="widefat">
190
+ <thead>
191
+ <tr>
192
+ <th><?php _efs( 'id' ) ?></th>
193
+ <th><?php _efs( 'name' ) ?></th>
194
+ <th><?php _efs( 'email' ) ?></th>
195
+ <th><?php _efs( 'verified' ) ?></th>
196
+ <th><?php _efs( 'public-key' ) ?></th>
197
+ <th><?php _efs( 'secret-key' ) ?></th>
198
+ </tr>
199
+ </thead>
200
+ <tbody>
201
+ <?php foreach ( $users as $user_id => $user ) : ?>
202
+ <tr>
203
+ <td><?php echo $user->id ?></td>
204
+ <td><?php echo $user->get_name() ?></td>
205
+ <td><?php echo $user->email ?></td>
206
+ <td><?php echo json_encode( $user->is_verified ) ?></td>
207
+ <td><?php echo $user->public_key ?></td>
208
+ <td><?php echo $user->secret_key ?></td>
209
+ </tr>
210
+ <?php endforeach ?>
211
+ </tbody>
212
+ </table>
213
+ <?php endif ?>
freemius/templates/email.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $sections = $VARS['sections'];
14
+ ?>
15
+ <table>
16
+ <?php
17
+ foreach ( $sections as $section_id => $section ) {
18
+ ?>
19
+ <thead>
20
+ <tr><th colspan="2" style="text-align: left; background: #333; color: #fff; padding: 5px;"><?php echo $section['title']; ?></th></tr>
21
+ </thead>
22
+ <tbody>
23
+ <?php
24
+ foreach ( $section['rows'] as $row_id => $row ) {
25
+ $col_count = count( $row );
26
+ ?>
27
+ <tr>
28
+ <?php
29
+ if ( 1 === $col_count ) { ?>
30
+ <td style="vertical-align: top;" colspan="2"><?php echo $row[0]; ?></td>
31
+ <?php
32
+ } else { ?>
33
+ <td style="vertical-align: top;"><b><?php echo $row[0]; ?>:</b></td>
34
+ <td><?php echo $row[1]; ?></td>
35
+ <?php
36
+ }
37
+ ?>
38
+ </tr>
39
+ <?php
40
+ }
41
+ ?>
42
+ </tbody>
43
+ <?php
44
+ }
45
+ ?>
46
+ </table>
freemius/templates/firewall-issues-js.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * API connectivity issues (CloudFlare's firewall) handler for handling different
4
+ * scenarios selected by the user after connectivity issue is detected, by sending
5
+ * AJAX call to the server in order to make the actual actions.
6
+ *
7
+ * @package Freemius
8
+ * @copyright Copyright (c) 2015, Freemius, Inc.
9
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10
+ * @since 1.0.9
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) {
14
+ exit;
15
+ }
16
+ ?>
17
+ <script type="text/javascript">
18
+ jQuery(document).ready(function ($) {
19
+ $('#fs_firewall_issue_options a.fs-resolve').click(function () {
20
+ var
21
+ error_type = $(this).attr('data-type'),
22
+ notice = $(this).parents('.fs-notice'),
23
+ slug = notice.attr('data-slug');
24
+
25
+ var data = {
26
+ action : slug + '_resolve_firewall_issues',
27
+ slug : slug,
28
+ error_type: error_type
29
+ };
30
+
31
+ if ('squid' === error_type) {
32
+ data.hosting_company = prompt('What is the name or URL of your hosting company?');
33
+ if (null == data.hosting_company)
34
+ return false;
35
+
36
+ if ('' === data.hosting_company) {
37
+ alert('We won\'t be able to help without knowing your hosting company.');
38
+ return false;
39
+ }
40
+ }
41
+
42
+ $(this).css({'cursor': 'wait'});
43
+
44
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
45
+ $.post(ajaxurl, data, function (response) {
46
+ if (1 == response) {
47
+ // Refresh page on success.
48
+ location.reload();
49
+ }
50
+ });
51
+ });
52
+ });
53
+ </script>
freemius/templates/plugin-icon.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ global $fs_active_plugins;
17
+
18
+ $img_dir = WP_FS__DIR_IMG;
19
+
20
+ if ( 1 < count( $fs_active_plugins->plugins ) ) {
21
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
22
+ if ( $data->plugin_path == $fs->get_plugin_basename() ) {
23
+ $img_dir = WP_PLUGIN_DIR . '/' . $sdk_path . '/assets/img';
24
+ break;
25
+ }
26
+ }
27
+ }
28
+
29
+ $icons = glob( fs_normalize_path( $img_dir . '/icon.*' ) );
30
+ if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
31
+ $icon_found = false;
32
+ $local_path = fs_normalize_path( $img_dir . '/icon.png' );
33
+
34
+ if ( WP_FS__IS_LOCALHOST && $fs->is_org_repo_compliant() ) {
35
+ /**
36
+ * IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
37
+ *
38
+ * This code will only be executed once during the testing
39
+ * of the plugin in a local environment. The plugin icon file WILL
40
+ * already exist in the assets folder when the plugin is deployed to
41
+ * the repository.
42
+ */
43
+ $suffixes = array(
44
+ '-128x128.png',
45
+ '-128x128.jpg',
46
+ '-256x256.png',
47
+ '-256x256.jpg',
48
+ '.svg',
49
+ );
50
+
51
+ $base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';
52
+
53
+ foreach ( $suffixes as $s ) {
54
+ $headers = get_headers( $base_url . $s );
55
+ if ( strpos( $headers[0], '200' ) ) {
56
+ $local_path = fs_normalize_path( $img_dir . '/icon.' . substr( $s, strpos( $s, '.' ) + 1 ) );
57
+ fs_download_image( $base_url . $s, $local_path );
58
+ $icon_found = true;
59
+ break;
60
+ }
61
+ }
62
+ }
63
+
64
+ if ( ! $icon_found ) {
65
+ // No icons found, fallback to default icon.
66
+ copy( fs_normalize_path( $img_dir . '/plugin-icon.png' ), $local_path );
67
+ }
68
+
69
+ $icons = array( $local_path );
70
+ }
71
+
72
+ $relative_url = fs_img_url( substr( $icons[0], strlen( fs_normalize_path( $img_dir ) ) ), $img_dir );
73
+ ?>
74
+ <div class="fs-plugin-icon">
75
+ <img src="<?php echo $relative_url ?>"/>
76
+ </div>
freemius/templates/plugin-info/description.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ if ( ! empty( $plugin->info->selling_point_0 ) ||
19
+ ! empty( $plugin->info->selling_point_1 ) ||
20
+ ! empty( $plugin->info->selling_point_2 )
21
+ ) : ?>
22
+ <div class="fs-selling-points">
23
+ <ul>
24
+ <?php for ( $i = 0; $i < 3; $i ++ ) : ?>
25
+ <?php if ( ! empty( $plugin->info->{'selling_point_' . $i} ) ) : ?>
26
+ <li><i class="dashicons dashicons-yes"></i>
27
+
28
+ <h3><?php echo $plugin->info->{'selling_point_' . $i} ?></h3></li>
29
+ <?php endif ?>
30
+ <?php endfor ?>
31
+ </ul>
32
+ </div>
33
+ <?php endif ?>
34
+ <div>
35
+ <?php
36
+ echo wp_kses( $plugin->info->description, array(
37
+ 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),
38
+ 'b' => array(),
39
+ 'i' => array(),
40
+ 'p' => array(),
41
+ 'blockquote' => array(),
42
+ 'h2' => array(),
43
+ 'h3' => array(),
44
+ 'ul' => array(),
45
+ 'ol' => array(),
46
+ 'li' => array()
47
+ ) );
48
+ ?>
49
+ </div>
50
+ <?php if ( ! empty( $plugin->info->screenshots ) ) : ?>
51
+ <?php $screenshots = $plugin->info->screenshots ?>
52
+ <div class="fs-screenshots clearfix">
53
+ <h2><?php _efs( 'screenshots', $plugin->slug ) ?></h2>
54
+ <ul>
55
+ <?php $i = 0;
56
+ foreach ( $screenshots as $s => $url ) : ?>
57
+ <?php
58
+ // Relative URLs are replaced with WordPress.org base URL
59
+ // therefore we need to set absolute URLs.
60
+ $url = 'http' . ( WP_FS__IS_HTTPS ? 's' : '' ) . ':' . $url; ?>
61
+ <li class="<?php echo ( 0 === $i % 2 ) ? 'odd' : 'even' ?>">
62
+ <style>
63
+ #section-description .fs-screenshots <?php echo ".fs-screenshot-{$i}" ?>
64
+ {
65
+ background-image: url('<?php echo $url ?>');
66
+ }
67
+ </style>
68
+ <a href="<?php echo $url ?>"
69
+ title="<?php printf( __fs( 'view-full-size-x', $plugin->slug ), $i ) ?>"
70
+ class="fs-screenshot-<?php echo $i ?>"></a>
71
+ </li>
72
+ <?php $i ++; endforeach ?>
73
+ </ul>
74
+ </div>
75
+ <?php endif ?>
freemius/templates/plugin-info/features.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ $plans = $VARS['plans'];
19
+
20
+ $features_plan_map = array();
21
+ foreach ( $plans as $plan ) {
22
+ foreach ( $plan->features as $feature ) {
23
+ if ( ! isset( $features_plan_map[ $feature->id ] ) ) {
24
+ $features_plan_map[ $feature->id ] = array( 'feature' => $feature, 'plans' => array() );
25
+ }
26
+
27
+ $features_plan_map[ $feature->id ]['plans'][ $plan->id ] = $feature;
28
+ }
29
+
30
+ // Add support as a feature.
31
+ if ( ! empty( $plan->support_email ) ||
32
+ ! empty( $plan->support_skype ) ||
33
+ ! empty( $plan->support_phone ) ||
34
+ true === $plan->is_success_manager
35
+ ) {
36
+ if ( ! isset( $features_plan_map['support'] ) ) {
37
+ $support_feature = new stdClass();
38
+ $support_feature->id = 'support';
39
+ $support_feature->title = __fs( 'Support', $plugin->slug );
40
+ $features_plan_map[ $support_feature->id ] = array( 'feature' => $support_feature, 'plans' => array() );
41
+ } else {
42
+ $support_feature = $features_plan_map['support'];
43
+ }
44
+
45
+ $features_plan_map[ $support_feature->id ]['plans'][ $plan->id ] = $support_feature;
46
+ }
47
+ }
48
+
49
+ // Add updates as a feature for all plans.
50
+ $updates_feature = new stdClass();
51
+ $updates_feature->id = 'updates';
52
+ $updates_feature->title = __fs( 'unlimited-updates', $plugin->slug );
53
+ $features_plan_map[ $updates_feature->id ] = array( 'feature' => $updates_feature, 'plans' => array() );
54
+ foreach ( $plans as $plan ) {
55
+ $features_plan_map[ $updates_feature->id ]['plans'][ $plan->id ] = $updates_feature;
56
+ }
57
+ ?>
58
+ <div class="fs-features">
59
+ <table>
60
+ <thead>
61
+ <tr>
62
+ <th></th>
63
+ <?php foreach ( $plans as $plan ) : ?>
64
+ <th>
65
+ <?php echo $plan->title ?>
66
+ <span class="fs-price">
67
+ <?php foreach ( $plan->pricing as $pricing ) : ?>
68
+ <?php if ( 1 == $pricing->licenses ) : ?>
69
+ $<?php echo $pricing->annual_price ?> / year
70
+ <?php endif ?>
71
+ <?php endforeach ?>
72
+ </span>
73
+ </th>
74
+ <?php endforeach ?>
75
+ </tr>
76
+ </thead>
77
+ <tbody>
78
+ <?php $odd = true;
79
+ foreach ( $features_plan_map as $feature_id => $data ) : ?>
80
+ <tr class="fs-<?php echo $odd ? 'odd' : 'even' ?>">
81
+ <td><?php echo ucfirst( $data['feature']->title ) ?></td>
82
+ <?php foreach ( $plans as $plan ) : ?>
83
+ <td>
84
+ <?php if ( isset( $data['plans'][ $plan->id ] ) ) : ?>
85
+ <?php if ( ! empty( $data['plans'][ $plan->id ]->value ) ) : ?>
86
+ <b><?php echo $data['plans'][ $plan->id ]->value ?></b>
87
+ <?php else : ?>
88
+ <i class="dashicons dashicons-yes"></i>
89
+ <?php endif ?>
90
+ <?php endif ?>
91
+ </td>
92
+ <?php endforeach ?>
93
+ </tr>
94
+ <?php $odd = ! $odd; endforeach ?>
95
+ </tbody>
96
+ </table>
97
+ </div>
freemius/templates/plugin-info/screenshots.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ $screenshots = $VARS['screenshots'];
19
+ ?>
20
+ <ol>
21
+ <?php $i = 0;
22
+ foreach ( $screenshots as $s => $url ) : ?>
23
+ <?php
24
+ // Relative URLs are replaced with WordPress.org base URL
25
+ // therefore we need to set absolute URLs.
26
+ $url = 'http' . ( WP_FS__IS_HTTPS ? 's' : '' ) . ':' . $url; ?>
27
+ <li>
28
+ <a href="<?php echo $url ?>"
29
+ title="<?php printf( __fs( 'view-full-size-x', $plugin->slug ), $i ) ?>"><img
30
+ src="<?php echo $url ?>"></a>
31
+ </li>
32
+ <?php $i ++; endforeach ?>
33
+ </ol>
freemius/templates/powered-by.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * KEEP THE POWERED BY TAB AND GET ADDITIONAL - 1% - OFF THE COMMISSION
15
+ */
16
+
17
+ wp_enqueue_script( 'jquery' );
18
+ wp_enqueue_script( 'json2' );
19
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
20
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
21
+ ?>
22
+
23
+ <div id="piframe"></div>
24
+ <script type="text/javascript">
25
+ (function ($) {
26
+ $(function () {
27
+ var
28
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
29
+ piframe = $('<iframe id="fs_promo_tab" src="' + base_url + '/promotional-tab/?page=contact#' + encodeURIComponent(document.location.href) + '" height="350" width="60" frameborder="0" style=" background: transparent; position: fixed; top: 20%; right: 0;" scrolling="no"></iframe>')
30
+ .appendTo('#piframe');
31
+
32
+ FS.PostMessage.init(base_url);
33
+ FS.PostMessage.receive('state', function (state) {
34
+ if ('closed' === state)
35
+ $('#fs_promo_tab').css('width', '60px');
36
+ else
37
+ $('#fs_promo_tab').css('width', '345px');
38
+ });
39
+ });
40
+ })(jQuery);
41
+ </script>
freemius/templates/pricing.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+
18
+ $slug = $VARS['slug'];
19
+ $fs = freemius( $slug );
20
+ $timestamp = time();
21
+
22
+ $context_params = array(
23
+ 'plugin_id' => $fs->get_id(),
24
+ 'plugin_public_key' => $fs->get_public_key(),
25
+ 'plugin_version' => $fs->get_plugin_version(),
26
+ );
27
+
28
+ // Get site context secure params.
29
+ if ( $fs->is_registered() ) {
30
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
31
+ $fs->get_site(),
32
+ $timestamp,
33
+ 'upgrade'
34
+ ) );
35
+ }
36
+
37
+ if ( $fs->is_payments_sandbox() ) // Append plugin secure token for sandbox mode authentication.)
38
+ {
39
+ $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
40
+ $fs->get_plugin(),
41
+ $timestamp,
42
+ 'checkout'
43
+ );
44
+ }
45
+
46
+ $query_params = array_merge( $context_params, $_GET, array(
47
+ 'next' => $fs->_get_admin_page_url( 'account', array( 'fs_action' => $slug . '_sync_license' ) ),
48
+ 'plugin_version' => $fs->get_plugin_version(),
49
+ // Billing cycle.
50
+ 'billing_cycle' => fs_request_get( 'billing_cycle', WP_FS__PERIOD_ANNUALLY ),
51
+ ) );
52
+ ?>
53
+
54
+ <div id="fs_pricing" class="wrap" style="margin: 0 0 -65px -20px;">
55
+ <div id="iframe"></div>
56
+ <form action="" method="POST">
57
+ <input type="hidden" name="user_id"/>
58
+ <input type="hidden" name="user_email"/>
59
+ <input type="hidden" name="site_id"/>
60
+ <input type="hidden" name="public_key"/>
61
+ <input type="hidden" name="secret_key"/>
62
+ <input type="hidden" name="action" value="account"/>
63
+ </form>
64
+
65
+ <script type="text/javascript">
66
+ (function ($, undef) {
67
+ $(function () {
68
+ var
69
+ // Keep track of the iframe height.
70
+ iframe_height = 800,
71
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
72
+ // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
73
+ // passed via query string or hard coded into the child page, it depends on your needs).
74
+ src = base_url + '/pricing/?<?php echo http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
75
+
76
+ // Append the Iframe into the DOM.
77
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
78
+ .appendTo('#iframe');
79
+
80
+ FS.PostMessage.init(base_url);
81
+
82
+ FS.PostMessage.receive('height', function (data) {
83
+ var h = data.height;
84
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
85
+ iframe_height = h;
86
+ $("#iframe iframe").height(iframe_height + 'px');
87
+ }
88
+ });
89
+
90
+ FS.PostMessage.receive('get_dimensions', function (data) {
91
+ FS.PostMessage.post('dimensions', {
92
+ height : $(document.body).height(),
93
+ scrollTop: $(document).scrollTop()
94
+ }, iframe[0]);
95
+ });
96
+ });
97
+ })(jQuery);
98
+ </script>
99
+ </div>
100
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/sticky-admin-notice-js.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sticky admin notices JavaScript handler for dismissing notice messages
4
+ * by sending AJAX call to the server in order to remove the message from the Database.
5
+ *
6
+ * @package Freemius
7
+ * @copyright Copyright (c) 2015, Freemius, Inc.
8
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
+ * @since 1.0.7
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+ ?>
16
+ <script type="text/javascript" >
17
+ jQuery(document).ready(function($) {
18
+ $('.fs-notice.fs-sticky .fs-close').click(function(){
19
+ var
20
+ notice = $(this).parents('.fs-notice'),
21
+ id = notice.attr('data-id'),
22
+ slug = notice.attr('data-slug');
23
+
24
+ notice.fadeOut('fast', function(){
25
+ var data = {
26
+ action: slug + '_dismiss_notice_action',
27
+ slug: slug,
28
+ message_id: id
29
+ };
30
+
31
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
32
+ $.post(ajaxurl, data, function(response) {
33
+
34
+ });
35
+
36
+ notice.remove();
37
+ });
38
+ });
39
+ });
40
+ </script>
images/icon.png ADDED
Binary file
js/base.js CHANGED
@@ -17,12 +17,26 @@ jQuery(document).ready(function ($) {
17
  $('.wp-to-twitter .expandable').hide();
18
  $('.wp-to-twitter .tweet-toggle').on('click', function (e) {
19
  e.preventDefault();
 
 
 
 
 
 
 
20
  $('.wp-to-twitter .expandable').toggle('slow');
21
  });
22
  // tweet history log
23
  $('.wp-to-twitter .history').hide();
24
  $('.wp-to-twitter .history-toggle').on('click', function (e) {
25
  e.preventDefault();
 
 
 
 
 
 
 
26
  $('.wp-to-twitter .history').toggle('slow');
27
  });
28
  });
17
  $('.wp-to-twitter .expandable').hide();
18
  $('.wp-to-twitter .tweet-toggle').on('click', function (e) {
19
  e.preventDefault();
20
+ if ( $( '.wp-to-twitter .expandable' ).is( ':visible' ) ) {
21
+ $( '.wp-to-twitter .tweet-toggle span ').addClass( 'dashicons-plus' );
22
+ $( '.wp-to-twitter .tweet-toggle span' ).removeClass( 'dashicons-minus' );
23
+ } else {
24
+ $( '.wp-to-twitter .tweet-toggle span ').removeClass( 'dashicons-plus' );
25
+ $( '.wp-to-twitter .tweet-toggle span' ).addClass( 'dashicons-minus' );
26
+ }
27
  $('.wp-to-twitter .expandable').toggle('slow');
28
  });
29
  // tweet history log
30
  $('.wp-to-twitter .history').hide();
31
  $('.wp-to-twitter .history-toggle').on('click', function (e) {
32
  e.preventDefault();
33
+ if ( $( '.wp-to-twitter .history' ).is( ':visible' ) ) {
34
+ $( '.wp-to-twitter .history-toggle span ').addClass( 'dashicons-plus' );
35
+ $( '.wp-to-twitter .history-toggle span' ).removeClass( 'dashicons-minus' );
36
+ } else {
37
+ $( '.wp-to-twitter .history-toggle span ').removeClass( 'dashicons-plus' );
38
+ $( '.wp-to-twitter .history-toggle span' ).addClass( 'dashicons-minus' );
39
+ }
40
  $('.wp-to-twitter .history').toggle('slow');
41
  });
42
  });
readme.txt CHANGED
@@ -2,11 +2,11 @@
2
  Contributors: joedolson
3
  Donate link: http://www.joedolson.com/donate/
4
  Tags: twitter, microblogging, su.pr, bitly, yourls, redirect, shortener, post, links, social, sharing, media, tweet
5
- Requires at least: 4.0
6
- Tested up to: 4.4.0
7
  License: GPLv2 or later
8
  Text Domain: wp-to-twitter
9
- Stable tag: 3.1.8
10
 
11
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
12
 
@@ -67,6 +67,24 @@ Translating my plug-ins is always appreciated. Work on WP to Twitter translation
67
  * 4.2 added compat function for mb_substr; drop mine when I drop support for 4.1
68
  * WP to Twitter timing bug with images?
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  = 3.1.9 =
71
 
72
  * CSS update in Twitter feed for new iframe generated follow button
2
  Contributors: joedolson
3
  Donate link: http://www.joedolson.com/donate/
4
  Tags: twitter, microblogging, su.pr, bitly, yourls, redirect, shortener, post, links, social, sharing, media, tweet
5
+ Requires at least: 4.1
6
+ Tested up to: 4.4.2
7
  License: GPLv2 or later
8
  Text Domain: wp-to-twitter
9
+ Stable tag: 3.1.9
10
 
11
  Posts a Twitter update when you update your WordPress blog or add a link, with your chosen URL shortening service.
12
 
67
  * 4.2 added compat function for mb_substr; drop mine when I drop support for 4.1
68
  * WP to Twitter timing bug with images?
69
 
70
+ = 3.2.0 =
71
+
72
+ * Bug fix: if user without permissions to edit WP to Twitter meta updated profiles, Twitter profile data was deleted.
73
+ * Bug fix: PHP notices (2) in Twitter search widget
74
+ * Bug fix: no notice to update settings when setting new URL shortener.
75
+ * Bug fix: permissions tabs non functional if custom role name had a space
76
+ * Bug fix: remove notice thrown when rate limiting is run on a Tweet not associated with a post
77
+ * Bug fix: remove notice thrown when no error defined by custom shortener.
78
+ * Design update in metabox panel
79
+ * Misc. design & text updates
80
+ * Ability to add new URL shorteners via filters ('wpt_shorten_link', 'wpt_shortener_settings', 'wpt_choose_shortener')
81
+ * Remove ability to set YOURLS as a local resource in new installs
82
+ * Added filter to disable storing URLs in post meta
83
+ * Deprecate more old jd_ prefixed functions
84
+ * Change admin page URL to match Pro version.
85
+ * Remove dependency on is_plugin_active()
86
+ * Added opt-in usage tracking via Freemius.com
87
+
88
  = 3.1.9 =
89
 
90
  * CSS update in Twitter feed for new iframe generated follow button
wp-to-twitter-manager.php CHANGED
@@ -14,7 +14,7 @@ function wpt_updated_settings() {
14
  }
15
 
16
  if ( isset( $_POST['oauth_settings'] ) ) {
17
- $oauth_message = jd_update_oauth_settings( false, $_POST );
18
  } else {
19
  $oauth_message = '';
20
  }
@@ -24,7 +24,7 @@ function wpt_updated_settings() {
24
  // notifications from oauth connection
25
  if ( isset( $_POST['oauth_settings'] ) ) {
26
  if ( $oauth_message == "success" ) {
27
- $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro?tab=basic' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php&amp;tab=basic' );
28
 
29
  print( '
30
  <div id="message" class="updated fade">
@@ -324,7 +324,7 @@ function wpt_update_settings() {
324
  }
325
  ?>
326
  <fieldset>
327
- <legend><span><?php echo $name ?></span></legend>
328
  <p>
329
  <input type="checkbox"
330
  name="wpt_post_types[<?php echo $slug; ?>][post-published-update]"
@@ -445,7 +445,6 @@ function wpt_update_settings() {
445
  <div class="ui-sortable meta-box-sortables">
446
  <div class="postbox">
447
  <h3><span><?php _e( 'Advanced Settings', 'wp-to-twitter' ); ?></span></h3>
448
-
449
  <div class="inside">
450
  <form method="post" action="">
451
  <div>
@@ -455,7 +454,7 @@ function wpt_update_settings() {
455
  ?>
456
 
457
  <fieldset>
458
- <legend><?php _e( 'Tags', 'wp-to-twitter' ); ?></legend>
459
  <p>
460
  <input type="checkbox" name="jd_strip_nonan" id="jd_strip_nonan"
461
  value="1" <?php echo jd_checkCheckbox( 'jd_strip_nonan' ); ?> /> <label
@@ -492,16 +491,16 @@ function wpt_update_settings() {
492
  </p>
493
  </fieldset>
494
  <fieldset>
495
- <legend><?php _e( 'Template Tag Settings', 'wp-to-twitter' ); ?></legend>
496
  <p>
497
  <label
498
- for="jd_post_excerpt"><?php _e( "Length of post excerpt (in characters):", 'wp-to-twitter' ); ?></label>
499
  <input type="text" name="jd_post_excerpt" id="jd_post_excerpt" size="3" maxlength="3" value="<?php echo( esc_attr( get_option( 'jd_post_excerpt' ) ) ) ?>"/>
500
  </p>
501
 
502
  <p>
503
  <label
504
- for="jd_date_format"><?php _e( "WP to Twitter Date Formatting:", 'wp-to-twitter' ); ?></label>
505
  <input type="text" aria-describedby="date_format_label" name="jd_date_format"
506
  id="jd_date_format" size="12" maxlength="12"
507
  value="<?php if ( get_option( 'jd_date_format' ) == '' ) {
@@ -521,56 +520,17 @@ function wpt_update_settings() {
521
  <input type="text" name="jd_twit_prepend" id="jd_twit_prepend" size="20"
522
  value="<?php esc_attr_e( stripslashes( get_option( 'jd_twit_prepend' ) ) ) ?>"/>
523
  </p>
524
-
525
  <p>
526
  <label for="jd_twit_append"><?php _e( "Custom text after Tweets:", 'wp-to-twitter' ); ?></label>
527
  <input type="text" name="jd_twit_append" id="jd_twit_append" size="20"
528
  value="<?php esc_attr_e( stripslashes( get_option( 'jd_twit_append' ) ) ) ?>"/>
529
  </p>
530
-
531
  <p>
532
  <label for="jd_twit_custom_url"><?php _e( "Custom field for alternate post URL:", 'wp-to-twitter' ); ?></label>
533
  <input type="text" name="jd_twit_custom_url" id="jd_twit_custom_url" size="30" maxlength="120"
534
  value="<?php esc_attr_e( stripslashes( get_option( 'jd_twit_custom_url' ) ) ) ?>"/>
535
  </p>
536
  </fieldset>
537
-
538
- <?php
539
- $inputs = '';
540
- $default_order = array(
541
- 'excerpt' => 0,
542
- 'title' => 1,
543
- 'date' => 2,
544
- 'category' => 3,
545
- 'blogname' => 4,
546
- 'author' => 5,
547
- 'account' => 6,
548
- 'tags' => 7,
549
- 'modified' => 8,
550
- '@' => 9,
551
- 'cat_desc' => 10
552
- );
553
- $preferred_order = get_option( 'wpt_truncation_order' );
554
- if ( ! $preferred_order ) {
555
- $preferred_order = array();
556
- }
557
- $preferred_order = array_merge( $default_order, $preferred_order );
558
- if ( is_array( $preferred_order ) ) {
559
- $default_order = $preferred_order;
560
- }
561
- asort( $default_order );
562
- foreach ( $default_order as $k => $v ) {
563
- $label = '<code>#' . $k . '#</code>';
564
- $inputs .= "<div class='wpt-truncate'><label for='$k-$v'>$label</label><br /><input type='number' size='3' value='$v' name='wpt_truncation_order[$k]' /></div> ";
565
- }
566
- ?>
567
- <fieldset>
568
- <legend><?php _e( 'Template tag priority order', 'wp-to-twitter' ); ?></legend>
569
- <p><?php _e( 'The order in which items will be abbreviated or removed from your Tweet if the Tweet is too long to send to Twitter.', 'wp-to-twitter' ); ?> <?php _e( 'Tags with lower values will be modified first.', 'wp-to-twitter' ); ?></p>
570
- <p>
571
- <?php echo $inputs; ?>
572
- </p>
573
- </fieldset>
574
  <fieldset>
575
  <legend id="special_cases"><?php _e( "Special Cases", 'wp-to-twitter' ); ?></legend>
576
  <p>
@@ -669,8 +629,8 @@ function wpt_update_settings() {
669
  if ( $role == 'administrator' ) {
670
  continue;
671
  }
672
- $role_tabs .= "<li><a href='#wpt_$role'>$rolename</a></li>\n";
673
- $role_container .= "<div class='wptab wpt_$role' id='wpt_$role' aria-live='assertive'><fieldset id='wpt_$role' class='roles'><legend>$rolename</legend>";
674
  $role_container .= "<input type='hidden' value='none' name='wpt_caps[" . $role . "][none]' />
675
  <ul class='wpt-settings checkboxes'>";
676
  foreach ( $caps as $cap => $name ) {
@@ -687,8 +647,44 @@ function wpt_update_settings() {
687
  ?>
688
  </fieldset>
689
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
690
  <fieldset>
691
- <legend><?php _e( 'Error Messages and Debugging', 'wp-to-twitter' ); ?></legend>
692
  <ul>
693
  <li>
694
  <input type="checkbox" name="wpt_permit_feed_styles" id="wpt_permit_feed_styles" value="1" <?php echo jd_checkCheckbox( 'wpt_permit_feed_styles' ) ?> />
@@ -888,6 +884,6 @@ function wpt_do_server_check( $test = false ) {
888
  update_option( 'wpt_server_string', $wpt_server_string );
889
  }
890
  echo $wpt_server_string;
891
- $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro&amp;refresh_wpt_server_string=true' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php&amp;refresh_wpt_server_string=true' );
892
  echo "<p><a href='" . $admin_url . "'>" . __( 'Test again', 'wp-to-twitter' ) . "</a></p>";
893
  }
14
  }
15
 
16
  if ( isset( $_POST['oauth_settings'] ) ) {
17
+ $oauth_message = wpt_update_oauth_settings( false, $_POST );
18
  } else {
19
  $oauth_message = '';
20
  }
24
  // notifications from oauth connection
25
  if ( isset( $_POST['oauth_settings'] ) ) {
26
  if ( $oauth_message == "success" ) {
27
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro?tab=basic' );
28
 
29
  print( '
30
  <div id="message" class="updated fade">
324
  }
325
  ?>
326
  <fieldset>
327
+ <legend><?php _e( 'Tweet Templates', 'wp-to-twitter' ); ?></legend>
328
  <p>
329
  <input type="checkbox"
330
  name="wpt_post_types[<?php echo $slug; ?>][post-published-update]"
445
  <div class="ui-sortable meta-box-sortables">
446
  <div class="postbox">
447
  <h3><span><?php _e( 'Advanced Settings', 'wp-to-twitter' ); ?></span></h3>
 
448
  <div class="inside">
449
  <form method="post" action="">
450
  <div>
454
  ?>
455
 
456
  <fieldset>
457
+ <legend><?php _e( 'Hashtags', 'wp-to-twitter' ); ?></legend>
458
  <p>
459
  <input type="checkbox" name="jd_strip_nonan" id="jd_strip_nonan"
460
  value="1" <?php echo jd_checkCheckbox( 'jd_strip_nonan' ); ?> /> <label
491
  </p>
492
  </fieldset>
493
  <fieldset>
494
+ <legend><?php _e( 'Template Settings', 'wp-to-twitter' ); ?></legend>
495
  <p>
496
  <label
497
+ for="jd_post_excerpt"><?php _e( "Post excerpt (#post#) in characters:", 'wp-to-twitter' ); ?></label>
498
  <input type="text" name="jd_post_excerpt" id="jd_post_excerpt" size="3" maxlength="3" value="<?php echo( esc_attr( get_option( 'jd_post_excerpt' ) ) ) ?>"/>
499
  </p>
500
 
501
  <p>
502
  <label
503
+ for="jd_date_format"><?php _e( "Date Format (#date#):", 'wp-to-twitter' ); ?></label>
504
  <input type="text" aria-describedby="date_format_label" name="jd_date_format"
505
  id="jd_date_format" size="12" maxlength="12"
506
  value="<?php if ( get_option( 'jd_date_format' ) == '' ) {
520
  <input type="text" name="jd_twit_prepend" id="jd_twit_prepend" size="20"
521
  value="<?php esc_attr_e( stripslashes( get_option( 'jd_twit_prepend' ) ) ) ?>"/>
522
  </p>
 
523
  <p>
524
  <label for="jd_twit_append"><?php _e( "Custom text after Tweets:", 'wp-to-twitter' ); ?></label>
525
  <input type="text" name="jd_twit_append" id="jd_twit_append" size="20"
526
  value="<?php esc_attr_e( stripslashes( get_option( 'jd_twit_append' ) ) ) ?>"/>
527
  </p>
 
528
  <p>
529
  <label for="jd_twit_custom_url"><?php _e( "Custom field for alternate post URL:", 'wp-to-twitter' ); ?></label>
530
  <input type="text" name="jd_twit_custom_url" id="jd_twit_custom_url" size="30" maxlength="120"
531
  value="<?php esc_attr_e( stripslashes( get_option( 'jd_twit_custom_url' ) ) ) ?>"/>
532
  </p>
533
  </fieldset>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  <fieldset>
535
  <legend id="special_cases"><?php _e( "Special Cases", 'wp-to-twitter' ); ?></legend>
536
  <p>
629
  if ( $role == 'administrator' ) {
630
  continue;
631
  }
632
+ $role_tabs .= "<li><a href='#wpt_" . sanitize_title( $role ) . "'>$rolename</a></li>\n";
633
+ $role_container .= "<div class='wptab wpt_$role' id='wpt_" . sanitize_title( $role ) . "' aria-live='assertive'><fieldset id='wpt_$role' class='roles'><legend>$rolename</legend>";
634
  $role_container .= "<input type='hidden' value='none' name='wpt_caps[" . $role . "][none]' />
635
  <ul class='wpt-settings checkboxes'>";
636
  foreach ( $caps as $cap => $name ) {
647
  ?>
648
  </fieldset>
649
  </div>
650
+ <?php
651
+ $inputs = '';
652
+ $default_order = array(
653
+ 'excerpt' => 0,
654
+ 'title' => 1,
655
+ 'date' => 2,
656
+ 'category' => 3,
657
+ 'blogname' => 4,
658
+ 'author' => 5,
659
+ 'account' => 6,
660
+ 'tags' => 7,
661
+ 'modified' => 8,
662
+ '@' => 9,
663
+ 'cat_desc' => 10
664
+ );
665
+ $preferred_order = get_option( 'wpt_truncation_order' );
666
+ if ( ! $preferred_order ) {
667
+ $preferred_order = array();
668
+ }
669
+ $preferred_order = array_merge( $default_order, $preferred_order );
670
+ if ( is_array( $preferred_order ) ) {
671
+ $default_order = $preferred_order;
672
+ }
673
+ asort( $default_order );
674
+ foreach ( $default_order as $k => $v ) {
675
+ $label = '<code>#' . $k . '#</code>';
676
+ $inputs .= "<div class='wpt-truncate'><label for='$k-$v'>$label</label><br /><input type='number' size='3' value='$v' name='wpt_truncation_order[$k]' /></div> ";
677
+ }
678
+ ?>
679
+ <fieldset>
680
+ <legend><?php _e( 'Template tag priority order', 'wp-to-twitter' ); ?></legend>
681
+ <p><?php _e( 'The order in which items will be abbreviated or removed from your Tweet if the Tweet is too long to send to Twitter.', 'wp-to-twitter' ); ?> <?php _e( 'Tags with lower values will be modified first.', 'wp-to-twitter' ); ?></p>
682
+ <p>
683
+ <?php echo $inputs; ?>
684
+ </p>
685
+ </fieldset>
686
  <fieldset>
687
+ <legend><?php _e( 'Miscellaneous Settings', 'wp-to-twitter' ); ?></legend>
688
  <ul>
689
  <li>
690
  <input type="checkbox" name="wpt_permit_feed_styles" id="wpt_permit_feed_styles" value="1" <?php echo jd_checkCheckbox( 'wpt_permit_feed_styles' ) ?> />
884
  update_option( 'wpt_server_string', $wpt_server_string );
885
  }
886
  echo $wpt_server_string;
887
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro&amp;refresh_wpt_server_string=true' );
888
  echo "<p><a href='" . $admin_url . "'>" . __( 'Test again', 'wp-to-twitter' ) . "</a></p>";
889
  }
wp-to-twitter-oauth.php CHANGED
@@ -42,7 +42,7 @@ function wtt_oauth_connection( $auth = false ) {
42
  }
43
  if ( ! empty( $ack ) && ! empty( $acs ) && ! empty( $ot ) && ! empty( $ots ) ) {
44
  require_once( plugin_dir_path( __FILE__ ) . 'wpt_twitter_oauth.php' );
45
- $connection = new jd_TwitterOAuth( $ack, $acs, $ot, $ots );
46
  $connection->useragent = get_option( 'blogname' ) . ' ' . home_url();
47
 
48
  return $connection;
@@ -62,8 +62,15 @@ function wtt_oauth_credentials_to_hash( $auth = false ) {
62
  return $hash;
63
  }
64
 
65
- // response to settings updates
 
 
66
  function jd_update_oauth_settings( $auth = false, $post = false ) {
 
 
 
 
 
67
  if ( isset( $post['oauth_settings'] ) ) {
68
  switch ( $post['oauth_settings'] ) {
69
  case 'wtt_oauth_test':
@@ -190,7 +197,7 @@ function wtt_connect_oauth( $auth = false ) {
190
 
191
  // show notification to authenticate with OAuth. No longer global; settings only.
192
  if ( ! wpt_check_oauth() ) {
193
- $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php' );
194
  $message = sprintf( __( "Twitter requires authentication by OAuth. You will need to <a href='%s'>update your settings</a> to complete installation of WP to Twitter.", 'wp-to-twitter' ), $admin_url );
195
  echo "<div class='error'><p>$message</p></div>";
196
  }
@@ -207,7 +214,7 @@ function wtt_connect_oauth( $auth = false ) {
207
  <div class="notes">
208
  <h4>' . __( 'WP to Twitter Set-up', 'wp-to-twitter' ) . '</h4>
209
  </div>
210
- <h4>' . __( '1. Register this site as an application on ', 'wp-to-twitter' ) . '<a href="https://apps.twitter.com/app/new/" target="_blank">' . __( 'Twitter\'s application registration page', 'wp-to-twitter' ) . '</a></h4>
211
  <ul>
212
  <li>' . __( 'If you\'re not currently logged in to Twitter, log-in to the account you want associated with this site', 'wp-to-twitter' ) . '</li>
213
  <li>' . __( 'Your application name cannot include the word "Twitter."', 'wp-to-twitter' ) . '</li>
42
  }
43
  if ( ! empty( $ack ) && ! empty( $acs ) && ! empty( $ot ) && ! empty( $ots ) ) {
44
  require_once( plugin_dir_path( __FILE__ ) . 'wpt_twitter_oauth.php' );
45
+ $connection = new wpt_TwitterOAuth( $ack, $acs, $ot, $ots );
46
  $connection->useragent = get_option( 'blogname' ) . ' ' . home_url();
47
 
48
  return $connection;
62
  return $hash;
63
  }
64
 
65
+ /**
66
+ * Back compat
67
+ */
68
  function jd_update_oauth_settings( $auth = false, $post = false ) {
69
+ return wpt_update_oauth_settings( $auth, $post );
70
+ }
71
+
72
+ // response to settings updates
73
+ function wpt_update_oauth_settings( $auth = false, $post = false ) {
74
  if ( isset( $post['oauth_settings'] ) ) {
75
  switch ( $post['oauth_settings'] ) {
76
  case 'wtt_oauth_test':
197
 
198
  // show notification to authenticate with OAuth. No longer global; settings only.
199
  if ( ! wpt_check_oauth() ) {
200
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
201
  $message = sprintf( __( "Twitter requires authentication by OAuth. You will need to <a href='%s'>update your settings</a> to complete installation of WP to Twitter.", 'wp-to-twitter' ), $admin_url );
202
  echo "<div class='error'><p>$message</p></div>";
203
  }
214
  <div class="notes">
215
  <h4>' . __( 'WP to Twitter Set-up', 'wp-to-twitter' ) . '</h4>
216
  </div>
217
+ <h4>' . __( '1. Register this site as an application on ', 'wp-to-twitter' ) . '<a href="https://apps.twitter.com/app/new/">' . __( 'Twitter\'s application registration page', 'wp-to-twitter' ) . '</a></h4>
218
  <ul>
219
  <li>' . __( 'If you\'re not currently logged in to Twitter, log-in to the account you want associated with this site', 'wp-to-twitter' ) . '</li>
220
  <li>' . __( 'Your application name cannot include the word "Twitter."', 'wp-to-twitter' ) . '</li>
wp-to-twitter-shorteners.php CHANGED
@@ -1,18 +1,17 @@
1
  <?php
2
- //jd_shorten_link
3
- //jd_expand_url
4
- //jd_expand_yourl
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  } // Exit if accessed directly
8
 
9
- if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in replacement.
10
- add_filter( 'wptt_shorten_link', 'jd_shorten_link', 10, 4 );
11
 
12
- function jd_shorten_link( $url, $thisposttitle, $post_ID, $testmode = false ) {
13
  wpt_mail( "Initial Link Data: #$post_ID", "$url, $thisposttitle, $post_ID, $testmode" ); // DEBUG
14
  // filter link before sending to shortener or adding analytics
15
- $url = apply_filters( 'wpt_shorten_link', $url, $post_ID );
 
16
  if ( $testmode == false ) {
17
  if ( get_option( 'use-twitter-analytics' ) == 1 || get_option( 'use_dynamic_analytics' ) == 1 ) {
18
  if ( get_option( 'use_dynamic_analytics' ) == '1' ) {
@@ -52,180 +51,183 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
52
  $keyword_format = ( get_option( 'jd_keyword_format' ) == '1' ) ? $post_ID : '';
53
  $keyword_format = ( get_option( 'jd_keyword_format' ) == '2' ) ? get_post_meta( $post_ID, '_yourls_keyword', true ) : $keyword_format;
54
  // Generate and grab the short url
55
- $shrink = $url;
 
56
  $error = false;
57
- switch ( get_option( 'jd_shortener' ) ) {
58
- case 4:
59
- if ( function_exists( 'wp_get_shortlink' ) ) {
60
- // wp_get_shortlink doesn't natively support custom post types; but don't return an error in that case.
61
- $shrink = ( $post_ID != false ) ? wp_get_shortlink( $post_ID, 'post' ) : $url;
62
- }
63
- if ( ! $shrink ) {
64
- $shrink = $url;
65
- }
66
- break;
67
- case 2: // updated to v3 3/31/2010
68
- $bitlyapi = trim( get_option( 'bitlyapi' ) );
69
- $bitlylogin = trim( strtolower( get_option( 'bitlylogin' ) ) );
70
- $decoded = jd_remote_json( "https://api-ssl.bitly.com/v3/shorten?longUrl=" . $encoded . "&login=" . $bitlylogin . "&apiKey=" . $bitlyapi . "&format=json" );
71
- if ( $decoded && isset( $decoded['status_code'] ) ) {
72
- if ( $decoded['status_code'] != 200 ) {
73
- $shrink = $decoded;
74
- $error = $decoded['status_txt'];
 
 
 
 
75
  } else {
76
- $shrink = $decoded['data']['url'];
77
  }
78
- } else {
79
- $shrink = false;
80
- }
81
- if ( ! is_valid_url( $shrink ) ) {
82
- $shrink = false;
83
- }
84
- break;
85
- case 5:
86
- // local YOURLS installation
87
- global $yourls_reserved_URL;
88
- define( 'YOURLS_INSTALLING', true ); // Pretend we're installing YOURLS to bypass test for install or upgrade
89
- define( 'YOURLS_FLOOD_DELAY_SECONDS', 0 ); // Disable flood check
90
- $opath = get_option( 'yourlspath' );
91
- $ypath = str_replace( 'user', 'includes', $opath );
92
- if ( file_exists( dirname( $ypath ) . '/load-yourls.php' ) ) { // YOURLS 1.4+
93
- require_once( dirname( $ypath ) . '/load-yourls.php' );
94
- global $ydb;
95
- if ( function_exists( 'yourls_add_new_link' ) ) {
96
- $yourls_result = yourls_add_new_link( $url, $keyword_format, $thisposttitle );
 
 
 
 
 
 
 
 
 
97
  } else {
98
- $yourls_result = $url;
99
  }
100
- } else { // YOURLS 1.3
101
- if ( file_exists( get_option( 'yourslpath' ) ) ) {
102
- require_once( get_option( 'yourlspath' ) );
103
- $yourls_db = new wpdb( YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST );
104
- $yourls_result = yourls_add_new_link( $url, $keyword_format, $yourls_db );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
- }
107
- if ( $yourls_result ) {
108
- $shrink = $yourls_result['shorturl'];
109
- } else {
110
- $shrink = false;
111
- }
112
- break;
113
- case 6:
114
- // remote YOURLS installation
115
- $yourlslogin = trim( get_option( 'yourlslogin' ) );
116
- $yourlsapi = stripcslashes( get_option( 'yourlsapi' ) );
117
- $token = stripcslashes( get_option( 'yourlstoken' ) );
118
- $yourlsurl = esc_url( get_option( 'yourlsurl' ) );
119
- if ( $token ) {
120
- $api_url = add_query_arg( array(
121
- 'signature' => $token,
122
- 'url' => $encoded,
123
- 'action' => 'shorturl',
124
- 'keyword' => $keyword_format,
125
- 'format' => 'json',
126
- 'title' => urlencode( $thisposttitle )
127
- ), $yourlsurl );
128
- } else {
129
- $api_url = add_query_arg( array(
130
- 'username' => $yourlslogin,
131
- 'password' => $yourlsapi,
132
- 'url' => $encoded,
133
- 'action' => 'shorturl',
134
- 'keyword' => $keyword_format,
135
- 'format' => 'json',
136
- 'title' => urlencode( $thisposttitle )
137
- ), $yourlsurl );
138
- }
139
- $json = jd_remote_json( $api_url, false );
140
- wpt_mail( "YOURLS JSON Response", print_r( $json, 1 ) ); // DEBUG YOURLS response
141
- if ( is_object( $json ) ) {
142
- $shrink = $json->shorturl;
143
- } else {
144
- $error = "Error code: " . $json->shorturl . ' ' . $json->message;
145
- $shrink = false;
146
- }
147
- break;
148
- case 7:
149
- $suprapi = trim( get_option( 'suprapi' ) );
150
- $suprlogin = trim( get_option( 'suprlogin' ) );
151
- if ( $suprapi != '' ) {
152
- $decoded = jd_remote_json( "http://su.pr/api/shorten?longUrl=" . $encoded . "&login=" . $suprlogin . "&apiKey=" . $suprapi );
153
- } else {
154
- $decoded = jd_remote_json( "http://su.pr/api/shorten?longUrl=" . $encoded );
155
- }
156
- if ( $decoded && isset( $decoded['statusCode'] ) ) {
157
- if ( $decoded['statusCode'] == 'OK' ) {
158
- $page = str_replace( "&", "&#38;", urldecode( $url ) );
159
- $shrink = $decoded['results'][ $page ]['shortUrl'];
160
- $error = $decoded['errorMessage'];
161
  } else {
 
162
  $shrink = false;
163
- $error = $decoded['errorMessage'];
164
  }
165
- } else {
166
- $shrink = false;
167
- $error = __( 'Su.pr query returned invalid data.', 'wp-to-twitter' );
168
- }
169
- if ( ! is_valid_url( $shrink ) ) {
170
- $shrink = false;
171
- }
172
- break;
173
- case 8:
174
- // Goo.gl
175
- $target = "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyBSnqQOg3vX1gwR7y2l-40yEG9SZiaYPUQ";
176
- $body = "{'longUrl':'$url'}";
177
- $json = jd_fetch_url( $target, 'POST', $body, 'Content-Type: application/json' );
178
- $decoded = json_decode( $json );
179
- $shrink = $decoded->id;
180
- if ( ! is_valid_url( $shrink ) ) {
181
- $shrink = false;
182
- }
183
- break;
184
- case 9:
185
- // Twitter Friendly Links
186
- $shrink = $url;
187
- if ( function_exists( 'twitter_link' ) ) { // use twitter_link if available
188
- $shrink = twitter_link( $post_ID );
189
- }
190
- break;
191
- case 10: // jotURL
192
- //jotURL, added: 2013-04-10
193
- $joturlapi = trim( get_option( 'joturlapi' ) );
194
- $joturllogin = trim( get_option( 'joturllogin' ) );
195
- $joturl_longurl_params = trim( get_option( 'joturl_longurl_params' ) );
196
- if ( $joturl_longurl_params != '' ) {
197
- if ( strpos( $url, "%3F" ) === false && strpos( $url, "?" ) === false ) {
198
- $ct = "?";
199
  } else {
200
- $ct = "&";
201
  }
202
- $url .= $ct . $joturl_longurl_params;
203
- $encoded = urlencode( urldecode( trim( $url ) ) ); // prevent double-encoding
204
- }
205
- //\jotURL
206
- $decoded = jd_fetch_url( "https://api.joturl.com/a/v1/shorten?url=" . $encoded . "&login=" . $joturllogin . "&key=" . $joturlapi . "&format=plain" );
207
- if ( $decoded !== false ) {
208
- $shrink = $decoded;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  //jotURL, added: 2013-04-10
210
- $joturl_shorturl_params = trim( get_option( 'joturl_shorturl_params' ) );
211
- if ( $joturl_shorturl_params != '' ) {
212
- if ( strpos( $shrink, "%3F" ) === false && strpos( $shrink, "?" ) === false ) {
 
 
213
  $ct = "?";
214
  } else {
215
  $ct = "&";
216
  }
217
- $shrink .= $ct . $joturl_shorturl_params;
 
218
  }
219
  //\jotURL
220
- } else {
221
- $error = $decoded;
222
- $shrink = false;
223
- }
224
- if ( ! is_valid_url( $shrink ) ) {
225
- $shrink = false;
226
- }
227
- break;
228
- default: $shrink = $url;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  }
230
  if ( $error ) {
231
  update_option( 'wpt_shortener_status', "$shrink : $error" );
@@ -238,14 +240,17 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
238
  update_option( 'wp_url_failure', '0' );
239
  }
240
  }
241
- wpt_store_url( $post_ID, $shrink );
 
 
 
242
 
243
  return $shrink;
244
  }
245
 
246
  function wpt_store_url( $post_ID, $url ) {
247
  $store_urls = apply_filters( 'wpt_store_urls', true, $post_ID, $url );
248
- if ( function_exists( 'jd_shorten_link' ) && $store_urls ) {
249
  $shortener = get_option( 'jd_shortener' );
250
  if ( get_post_meta( $post_ID, '_wpt_short_url', true ) != $url ) {
251
  update_post_meta( $post_ID, '_wpt_short_url', $url );
@@ -256,11 +261,11 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
256
  case 2:
257
  case 7:
258
  case 8:
259
- $target = jd_expand_url( $url );
260
  break;
261
  case 5:
262
  case 6:
263
- $target = jd_expand_yourl( $url, $shortener );
264
  break;
265
  default:
266
  $target = $url;
@@ -270,10 +275,14 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
270
  }
271
  update_post_meta( $post_ID, '_wp_jd_target', $target );
272
  }
273
-
274
  function jd_expand_url( $short_url ) {
 
 
 
 
275
  $short_url = urlencode( $short_url );
276
- $decoded = jd_remote_json( "http://api.longurl.org/v2/expand?format=json&url=" . $short_url );
277
  if ( isset( $decoded['long-url'] ) ) {
278
  $url = $decoded['long-url'];
279
  } else {
@@ -283,8 +292,12 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
283
  return $url;
284
  //return $short_url;
285
  }
286
-
287
  function jd_expand_yourl( $short_url, $remote ) {
 
 
 
 
288
  if ( $remote == 6 ) {
289
  $short_url = urlencode( $short_url );
290
  $yourl_api = get_option( 'yourlsurl' );
@@ -292,9 +305,9 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
292
  $pass = stripcslashes( get_option( 'yourlsapi' ) );
293
  $token = get_option( 'yourlstoken' );
294
  if ( $token ) {
295
- $decoded = jd_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&signature=$token&username=$user&password=$pass" );
296
  } else {
297
- $decoded = jd_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&username=$user&password=$pass" );
298
  }
299
  $url = ( isset( $decoded['longurl'] ) ) ? $decoded['longurl'] : $short_url;
300
 
@@ -325,6 +338,20 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
325
 
326
  add_filter( 'wpt_shortener_controls', 'wpt_shortener_controls' );
327
  function wpt_shortener_controls() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  // for the moment, this just displays the fields. Eventually, a real filter.
329
  ?>
330
  <div class="ui-sortable meta-box-sortables">
@@ -334,195 +361,144 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
334
  </h3>
335
 
336
  <div class="inside">
337
- <?php if ( get_option( 'jd_shortener' ) == 7 ) { ?>
338
- <div class="panel">
339
- <h4 class="supr">
340
- <span><?php _e( "Your Su.pr account details", 'wp-to-twitter' ); ?> <?php _e( '(optional)', 'wp-to-twitter' ); ?></span>
341
- </h4>
342
-
343
- <form method="post" action="">
344
- <div><input type='hidden' name='wpt_shortener_update' value='true'/></div>
345
- <div>
346
- <p>
347
- <label
348
- for="suprlogin"><?php _e( "Your Su.pr Username:", 'wp-to-twitter' ); ?></label>
349
- <input type="text" name="suprlogin" id="suprlogin" size="40"
350
- value="<?php esc_attr_e( get_option( 'suprlogin' ) ) ?>"/>
351
- </p>
352
-
353
- <p>
354
- <label
355
- for="suprapi"><?php _e( "Your Su.pr <abbr title='application programming interface'>API</abbr> Key:", 'wp-to-twitter' ); ?></label>
356
- <input type="text" name="suprapi" id="suprapi" size="40"
357
- value="<?php esc_attr_e( get_option( 'suprapi' ) ) ?>"/>
358
- </p>
359
-
360
- <div>
361
- <input type="hidden" name="submit-type" value="suprapi"/>
362
- </div>
363
- <?php $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
364
- echo "<div>$nonce</div>"; ?>
365
- <p>
366
- <input type="submit" name="submit" value="<?php _e( 'Save Su.pr API Key', 'wp-to-twitter' ); ?>" class="button-primary"/>
367
- <input type="submit" name="clear" value="<?php _e( 'Clear Su.pr API Key', 'wp-to-twitter' ); ?>" class="button-secondary" />
368
- <br />
369
- <small><?php _e( "Don't have a Su.pr account or API key? <a href='http://su.pr/'>Get one here!</a> You'll need an API key in order to associate the URLs you create with your Su.pr account.", 'wp-to-twitter' ); ?></small>
370
- </p>
371
- </div>
372
- </form>
373
  </div>
374
- <?php } else if ( get_option( 'jd_shortener' ) == 2 ) { ?>
375
- <div class="panel">
376
- <h4 class="bitly">
377
- <span><?php _e( "Your Bit.ly account details", 'wp-to-twitter' ); ?></span></h4>
378
-
379
- <form method="post" action="">
380
- <div><input type='hidden' name='wpt_shortener_update' value='true'/></div>
381
- <div>
382
- <p>
383
- <label
384
- for="bitlylogin"><?php _e( "Your Bit.ly username:", 'wp-to-twitter' ); ?></label>
385
- <input type="text" name="bitlylogin" id="bitlylogin"
386
- value="<?php esc_attr_e( get_option( 'bitlylogin' ) ) ?>"/>
387
- </p>
388
-
389
- <p>
390
- <label
391
- for="bitlyapi"><?php _e( "Your Bit.ly <abbr title='application programming interface'>API</abbr> Key:", 'wp-to-twitter' ); ?></label>
392
- <input type="text" name="bitlyapi" id="bitlyapi" size="40"
393
- value="<?php esc_attr_e( get_option( 'bitlyapi' ) ) ?>"/>
394
- </p>
395
-
396
- <p>
397
- <a href="http://bitly.com/a/your_api_key"><?php _e( 'View your Bit.ly username and API key', 'wp-to-twitter' ); ?></a>
398
- </p>
399
-
400
- <div>
401
- <input type="hidden" name="submit-type" value="bitlyapi"/>
402
- </div>
403
- <?php $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
404
- echo "<div>$nonce</div>"; ?>
405
- <p>
406
- <input type="submit" name="submit" value="<?php _e( 'Save Bit.ly API Key', 'wp-to-twitter' ); ?>" class="button-primary"/> <input type="submit" name="clear" value="<?php _e( 'Clear Bit.ly API Key', 'wp-to-twitter' ); ?>" class="button-secondary" />
407
- </p>
408
- </div>
409
- </form>
410
  </div>
411
- <?php } else if ( get_option( 'jd_shortener' ) == 5 || get_option( 'jd_shortener' ) == 6 ) { ?>
412
- <div class="panel">
413
- <h4 class="yourls">
414
- <span><?php _e( "Your YOURLS account details", 'wp-to-twitter' ); ?></span></h4>
415
-
416
- <form method="post" action="">
417
- <div><input type='hidden' name='wpt_shortener_update' value='true'/></div>
418
- <div>
419
- <p>
420
- <label
421
- for="yourlspath"><?php _e( 'Path to your YOURLS config file (Local installations)', 'wp-to-twitter' ); ?></label><br/><input
422
- type="text" id="yourlspath" name="yourlspath" size="60"
423
- value="<?php esc_attr_e( get_option( 'yourlspath' ) ); ?>"/><br/>
424
- <small><?php _e( 'Example:', 'wp-to-twitter' ); ?> <code>/home/username/www/www/yourls/user/config.php</code>
425
- </small>
426
- </p>
427
- <p>
428
- <label
429
- for="yourlsurl"><?php _e( 'URI to the YOURLS API (Remote installations)', 'wp-to-twitter' ); ?></label><br/><input
430
- type="text" id="yourlsurl" name="yourlsurl" size="60"
431
- value="<?php esc_attr_e( get_option( 'yourlsurl' ) ); ?>"/><br/>
432
- <small><?php _e( 'Example:', 'wp-to-twitter' ); ?> <code>http://domain.com/yourls-api.php</code>
433
- </small>
434
- </p>
435
- <p>
436
- <label
437
- for="yourlstoken"><?php _e( "YOURLS signature token:", 'wp-to-twitter' ); ?></label>
438
- <input type="text" name="yourlstoken" id="yourlstoken" size="30"
439
- value="<?php esc_attr_e( get_option( 'yourlstoken' ) ) ?>"/>
440
- </p>
441
- <?php if ( get_option( 'yourlsapi' ) && get_option( 'yourlslogin' ) ) { ?>
442
- <p>
443
- <em><?php _e( 'Your YOURLS username and password are saved. If you add a signature token, that will be used for API calls and your username and password will be deleted from the database.', 'wp-to-twitter' ); ?></em>
444
- </p>
445
- <?php } ?>
446
- <p>
447
- <input type="radio" name="jd_keyword_format" id="jd_keyword_id"
448
- value="1" <?php echo jd_checkSelect( 'jd_keyword_format', 1, 'checkbox' ); ?> />
449
- <label
450
- for="jd_keyword_id"><?php _e( "Post ID for YOURLS url slug.", 'wp-to-twitter' ); ?></label><br/>
451
- <input type="radio" name="jd_keyword_format" id="jd_keyword"
452
- value="2" <?php echo jd_checkSelect( 'jd_keyword_format', 2, 'checkbox' ); ?> />
453
- <label
454
- for="jd_keyword"><?php _e( "Custom keyword for YOURLS url slug.", 'wp-to-twitter' ); ?></label><br/>
455
- <input type="radio" name="jd_keyword_format" id="jd_keyword_default"
456
- value="0" <?php echo jd_checkSelect( 'jd_keyword_format', 0, 'checkbox' ); ?> />
457
- <label
458
- for="jd_keyword_default"><?php _e( "Default: sequential URL numbering.", 'wp-to-twitter' ); ?></label>
459
- </p>
460
-
461
- <div>
462
- <input type="hidden" name="submit-type" value="yourlsapi"/>
463
- </div>
464
- <?php $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
465
- echo "<div>$nonce</div>"; ?>
466
- <p><input type="submit" name="submit" value="<?php _e( 'Save YOURLS settings', 'wp-to-twitter' ); ?>" class="button-primary" /> <input type="submit" name="clear" value="<?php _e( 'Clear YOURLS settings', 'wp-to-twitter' ); ?>" class="button-secondary" />
467
- </p>
468
- </div>
469
- </form>
470
- </div>
471
- <?php } else if ( get_option( 'jd_shortener' ) == 10 ) { ?>
472
- <div class="panel">
473
- <h4 class="joturl">
474
- <span><?php _e( "Your jotURL account details", 'wp-to-twitter' ); ?></span></h4>
475
-
476
- <form method="post" action="">
477
- <div><input type='hidden' name='wpt_shortener_update' value='true'/></div>
478
- <div>
479
- <p>
480
- <label
481
- for="joturllogin"><?php _e( "Your jotURL public <abbr title='application programming interface'>API</abbr> key:", 'wp-to-twitter' ); ?></label>
482
- <input type="text" name="joturllogin" id="joturllogin"
483
- value="<?php esc_attr_e( get_option( 'joturllogin' ) ) ?>"/>
484
- </p>
485
-
486
- <p>
487
- <label
488
- for="joturlapi"><?php _e( "Your jotURL private <abbr title='application programming interface'>API</abbr> key:", 'wp-to-twitter' ); ?></label>
489
- <input type="text" name="joturlapi" id="joturlapi" size="40"
490
- value="<?php esc_attr_e( get_option( 'joturlapi' ) ) ?>"/>
491
- </p>
492
-
493
- <p>
494
- <label
495
- for="joturl_longurl_params"><?php _e( "Parameters to add to the long URL (before shortening):", 'wp-to-twitter' ); ?></label>
496
- <input type="text" name="joturl_longurl_params" id="joturl_longurl_params"
497
- size="40"
498
- value="<?php esc_attr_e( get_option( 'joturl_longurl_params' ) ) ?>"/>
499
- </p>
500
-
501
- <p>
502
- <label
503
- for="joturl_shorturl_params"><?php _e( "Parameters to add to the short URL (after shortening):", 'wp-to-twitter' ); ?></label>
504
- <input type="text" name="joturl_shorturl_params" id="joturl_shorturl_params"
505
- size="40"
506
- value="<?php esc_attr_e( get_option( 'joturl_shorturl_params' ) ) ?>"/>
507
- </p>
508
-
509
- <p>
510
- <a href="https://www.joturl.com/reserved/api.html"><?php _e( 'View your jotURL public and private API key', 'wp-to-twitter' ); ?></a>
511
- </p>
512
-
513
- <div><input type="hidden" name="submit-type" value="joturlapi"/></div>
514
- <?php $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
515
- echo "<div>$nonce</div>"; ?>
516
- <p>
517
- <input type="submit" name="submit" value="<?php _e( 'Save jotURL settings', 'wp-to-twitter' ); ?>" class="button-primary" />
518
- <input type="submit" name="clear" value="<?php _e( 'Clear jotURL settings', 'wp-to-twitter' ); ?>" class="button-secondary" />
519
- </p>
520
- </div>
521
- </form>
522
  </div>
523
- <?php } else { ?>
524
- <?php _e( 'Your shortener does not require any account settings.', 'wp-to-twitter' ); ?>
525
- <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  </div>
527
  </div>
528
  </div>
@@ -540,6 +516,7 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
540
  $message .= __( 'YOURLS signature token updated.', 'wp-to-twitter' );
541
  }
542
  update_option( 'yourlsurl', trim( $post['yourlsurl'] ) );
 
543
  if ( $post['yourlspath'] != '' ) {
544
  update_option( 'yourlspath', trim( $post['yourlspath'] ) );
545
  if ( file_exists( $post['yourlspath'] ) ) {
@@ -580,6 +557,7 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
580
  $message = __( "Su.pr API Key not added - <a href='http://su.pr/'>get one here</a>! ", 'wp-to-twitter' );
581
  }
582
  }
 
583
  if ( isset( $post['submit-type'] ) && $post['submit-type'] == 'bitlyapi' ) {
584
  if ( $post['bitlyapi'] != '' && isset( $post['submit'] ) ) {
585
  update_option( 'bitlyapi', trim( $post['bitlyapi'] ) );
@@ -600,6 +578,7 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
600
  $message = __( "Bit.ly Login not added - <a href='http://bit.ly/account/'>get one here</a>! ", 'wp-to-twitter' );
601
  }
602
  }
 
603
  if ( isset( $post['submit-type'] ) && $post['submit-type'] == 'joturlapi' ) {
604
  if ( $post['joturlapi'] != '' && isset( $post['submit'] ) ) {
605
  update_option( 'joturlapi', trim( $post['joturlapi'] ) );
@@ -642,57 +621,58 @@ if ( ! function_exists( 'jd_shorten_link' ) ) { // prep work for future plug-in
642
  $message = __( "Short URL parameters deleted. ", 'wp-to-twitter' );
643
  }
644
  }
 
 
645
 
646
  return $message;
647
  }
648
 
649
  function wpt_select_shortener( $post ) {
650
  $message = '';
651
- update_option( 'jd_shortener', $post['jd_shortener'] );
652
  if ( $post['jd_shortener'] == get_option( 'jd_shortener' ) ) {
653
- return '';
654
- } // no message if no change.
655
- if ( get_option( 'jd_shortener' ) == 2 && ( get_option( 'bitlylogin' ) == "" || get_option( 'bitlyapi' ) == "" ) ) {
656
- $message .= __( 'You must add your Bit.ly login and API key in order to shorten URLs with Bit.ly.', 'wp-to-twitter' );
657
- $message .= "<br />";
658
  }
659
- if ( get_option( 'jd_shortener' ) == 10 && ( get_option( 'joturllogin' ) == "" || get_option( 'joturlapi' ) == "" ) ) {
660
- $message .= __( 'You must add your jotURL public and private API key in order to shorten URLs with jotURL.', 'wp-to-twitter' );
661
- $message .= "<br />";
662
- }
663
- if ( get_option( 'jd_shortener' ) == 6 && ( get_option( 'yourlslogin' ) == "" || get_option( 'yourlsapi' ) == "" || get_option( 'yourlsurl' ) == "" ) ) {
664
- $message .= __( 'You must add your YOURLS remote URL, login, and password in order to shorten URLs with a remote installation of YOURLS.', 'wp-to-twitter' );
665
- $message .= "<br />";
 
 
666
  }
667
- if ( get_option( 'jd_shortener' ) == 5 && ( get_option( 'yourlspath' ) == "" ) ) {
668
- $message .= __( 'You must add your YOURLS server path in order to shorten URLs with a remote installation of YOURLS.', 'wp-to-twitter' );
669
  $message .= "<br />";
670
  }
671
-
672
  return $message;
673
  }
674
 
675
  add_filter( 'wpt_pick_shortener', 'wpt_pick_shortener' );
676
  function wpt_pick_shortener() {
 
677
  ?>
678
  <p>
679
- <label
680
- for="jd_shortener"><?php _e( "Choose a short URL service (account settings below)", 'wp-to-twitter' ); ?></label>
681
  <select name="jd_shortener" id="jd_shortener">
682
- <option
683
- value="3" <?php echo jd_checkSelect( 'jd_shortener', '3' ); ?>><?php _e( "Don't shorten URLs.", 'wp-to-twitter' ); ?></option>
684
- <option value="7" <?php echo jd_checkSelect( 'jd_shortener', '7' ); ?>>Su.pr</option>
685
- <option value="2" <?php echo jd_checkSelect( 'jd_shortener', '2' ); ?>>Bit.ly</option>
686
- <option value="8" <?php echo jd_checkSelect( 'jd_shortener', '8' ); ?>>Goo.gl</option>
687
- <option
688
- value="5" <?php echo jd_checkSelect( 'jd_shortener', '5' ); ?>><?php _e( "YOURLS (on this server)", 'wp-to-twitter' ); ?></option>
689
- <option
690
- value="6" <?php echo jd_checkSelect( 'jd_shortener', '6' ); ?>><?php _e( "YOURLS (on a remote server)", 'wp-to-twitter' ); ?></option>
691
- <option value="4" <?php echo jd_checkSelect( 'jd_shortener', '4' ); ?>>WordPress</option>
692
- <option value="10" <?php echo jd_checkSelect( 'jd_shortener', '10' ); ?>>jotURL</option>
693
  <?php if ( function_exists( 'twitter_link' ) ) { ?>
694
- <option
695
- value="9" <?php echo jd_checkSelect( 'jd_shortener', '9' ); ?>><?php _e( "Use Twitter Friendly Links.", 'wp-to-twitter' ); ?></option><?php } ?>
 
 
696
  </select>
697
  </p>
698
  <?php
1
  <?php
2
+
 
 
3
  if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  } // Exit if accessed directly
6
 
7
+ if ( ! function_exists( 'wpt_shorten_url' ) ) { // prep work for future plug-in replacement.
8
+ add_filter( 'wptt_shorten_link', 'wpt_shorten_url', 10, 4 );
9
 
10
+ function wpt_shorten_url( $url, $thisposttitle, $post_ID, $testmode = false ) {
11
  wpt_mail( "Initial Link Data: #$post_ID", "$url, $thisposttitle, $post_ID, $testmode" ); // DEBUG
12
  // filter link before sending to shortener or adding analytics
13
+ $shortener = get_option( 'jd_shortener' );
14
+ $url = apply_filters( 'wpt_shorten_link', $url, $shortener, $post_ID );
15
  if ( $testmode == false ) {
16
  if ( get_option( 'use-twitter-analytics' ) == 1 || get_option( 'use_dynamic_analytics' ) == 1 ) {
17
  if ( get_option( 'use_dynamic_analytics' ) == '1' ) {
51
  $keyword_format = ( get_option( 'jd_keyword_format' ) == '1' ) ? $post_ID : '';
52
  $keyword_format = ( get_option( 'jd_keyword_format' ) == '2' ) ? get_post_meta( $post_ID, '_yourls_keyword', true ) : $keyword_format;
53
  // Generate and grab the short url
54
+ $shrink = apply_filters( 'wpt_do_shortening', false, $shortener, $url, $thisposttitle, $post_ID, $testmode );
55
+ // if an add-on has shortened the link, skip shortening
56
  $error = false;
57
+ if ( !$shrink ) {
58
+ switch ( $shortener ) {
59
+ case 4:
60
+ if ( function_exists( 'wp_get_shortlink' ) ) {
61
+ // wp_get_shortlink doesn't natively support custom post types; but don't return an error in that case.
62
+ $shrink = ( $post_ID != false ) ? wp_get_shortlink( $post_ID, 'post' ) : $url;
63
+ }
64
+ if ( ! $shrink ) {
65
+ $shrink = $url;
66
+ }
67
+ break;
68
+ case 2: // updated to v3 3/31/2010
69
+ $bitlyapi = trim( get_option( 'bitlyapi' ) );
70
+ $bitlylogin = trim( strtolower( get_option( 'bitlylogin' ) ) );
71
+ $decoded = wpt_remote_json( "https://api-ssl.bitly.com/v3/shorten?longUrl=" . $encoded . "&login=" . $bitlylogin . "&apiKey=" . $bitlyapi . "&format=json" );
72
+ if ( $decoded && isset( $decoded['status_code'] ) ) {
73
+ if ( $decoded['status_code'] != 200 ) {
74
+ $shrink = $decoded;
75
+ $error = $decoded['status_txt'];
76
+ } else {
77
+ $shrink = $decoded['data']['url'];
78
+ }
79
  } else {
80
+ $shrink = false;
81
  }
82
+ if ( ! is_valid_url( $shrink ) ) {
83
+ $shrink = false;
84
+ }
85
+ break;
86
+ case 5:
87
+ // local YOURLS installation
88
+ global $yourls_reserved_URL;
89
+ define( 'YOURLS_INSTALLING', true ); // Pretend we're installing YOURLS to bypass test for install or upgrade
90
+ define( 'YOURLS_FLOOD_DELAY_SECONDS', 0 ); // Disable flood check
91
+ $opath = get_option( 'yourlspath' );
92
+ $ypath = str_replace( 'user', 'includes', $opath );
93
+ if ( file_exists( dirname( $ypath ) . '/load-yourls.php' ) ) { // YOURLS 1.4+
94
+ require_once( dirname( $ypath ) . '/load-yourls.php' );
95
+ global $ydb;
96
+ if ( function_exists( 'yourls_add_new_link' ) ) {
97
+ $yourls_result = yourls_add_new_link( $url, $keyword_format, $thisposttitle );
98
+ } else {
99
+ $yourls_result = $url;
100
+ }
101
+ } else { // YOURLS 1.3
102
+ if ( file_exists( get_option( 'yourslpath' ) ) ) {
103
+ require_once( get_option( 'yourlspath' ) );
104
+ $yourls_db = new wpdb( YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST );
105
+ $yourls_result = yourls_add_new_link( $url, $keyword_format, $yourls_db );
106
+ }
107
+ }
108
+ if ( $yourls_result ) {
109
+ $shrink = $yourls_result['shorturl'];
110
  } else {
111
+ $shrink = false;
112
  }
113
+ break;
114
+ case 6:
115
+ // remote YOURLS installation
116
+ $yourlslogin = trim( get_option( 'yourlslogin' ) );
117
+ $yourlsapi = stripcslashes( get_option( 'yourlsapi' ) );
118
+ $token = stripcslashes( get_option( 'yourlstoken' ) );
119
+ $yourlsurl = esc_url( get_option( 'yourlsurl' ) );
120
+ if ( $token ) {
121
+ $api_url = add_query_arg( array(
122
+ 'signature' => $token,
123
+ 'url' => $encoded,
124
+ 'action' => 'shorturl',
125
+ 'keyword' => $keyword_format,
126
+ 'format' => 'json',
127
+ 'title' => urlencode( $thisposttitle )
128
+ ), $yourlsurl );
129
+ } else {
130
+ $api_url = add_query_arg( array(
131
+ 'username' => $yourlslogin,
132
+ 'password' => $yourlsapi,
133
+ 'url' => $encoded,
134
+ 'action' => 'shorturl',
135
+ 'keyword' => $keyword_format,
136
+ 'format' => 'json',
137
+ 'title' => urlencode( $thisposttitle )
138
+ ), $yourlsurl );
139
  }
140
+ $json = wpt_remote_json( $api_url, false );
141
+ wpt_mail( "YOURLS JSON Response", print_r( $json, 1 ) ); // DEBUG YOURLS response
142
+ if ( is_object( $json ) ) {
143
+ $shrink = $json->shorturl;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  } else {
145
+ $error = "Error code: " . $json->shorturl . ' ' . $json->message;
146
  $shrink = false;
 
147
  }
148
+ break;
149
+ case 7:
150
+ $suprapi = trim( get_option( 'suprapi' ) );
151
+ $suprlogin = trim( get_option( 'suprlogin' ) );
152
+ if ( $suprapi != '' ) {
153
+ $decoded = wpt_remote_json( "http://su.pr/api/shorten?longUrl=" . $encoded . "&login=" . $suprlogin . "&apiKey=" . $suprapi );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  } else {
155
+ $decoded = wpt_remote_json( "http://su.pr/api/shorten?longUrl=" . $encoded );
156
  }
157
+ if ( $decoded && isset( $decoded['statusCode'] ) ) {
158
+ if ( $decoded['statusCode'] == 'OK' ) {
159
+ $page = str_replace( "&", "&#38;", urldecode( $url ) );
160
+ $shrink = $decoded['results'][ $page ]['shortUrl'];
161
+ $error = $decoded['errorMessage'];
162
+ } else {
163
+ $shrink = false;
164
+ $error = $decoded['errorMessage'];
165
+ }
166
+ } else {
167
+ $shrink = false;
168
+ $error = __( 'Su.pr query returned invalid data.', 'wp-to-twitter' );
169
+ }
170
+ if ( ! is_valid_url( $shrink ) ) {
171
+ $shrink = false;
172
+ }
173
+ break;
174
+ case 8:
175
+ // Goo.gl
176
+ $target = "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyBSnqQOg3vX1gwR7y2l-40yEG9SZiaYPUQ";
177
+ $body = "{'longUrl':'$url'}";
178
+ $json = wpt_fetch_url( $target, 'POST', $body, 'Content-Type: application/json' );
179
+ $decoded = json_decode( $json );
180
+ $shrink = $decoded->id;
181
+ if ( ! is_valid_url( $shrink ) ) {
182
+ $shrink = false;
183
+ }
184
+ break;
185
+ case 9:
186
+ // Twitter Friendly Links
187
+ $shrink = $url;
188
+ if ( function_exists( 'twitter_link' ) ) { // use twitter_link if available
189
+ $shrink = twitter_link( $post_ID );
190
+ }
191
+ break;
192
+ case 10: // jotURL
193
  //jotURL, added: 2013-04-10
194
+ $joturlapi = trim( get_option( 'joturlapi' ) );
195
+ $joturllogin = trim( get_option( 'joturllogin' ) );
196
+ $joturl_longurl_params = trim( get_option( 'joturl_longurl_params' ) );
197
+ if ( $joturl_longurl_params != '' ) {
198
+ if ( strpos( $url, "%3F" ) === false && strpos( $url, "?" ) === false ) {
199
  $ct = "?";
200
  } else {
201
  $ct = "&";
202
  }
203
+ $url .= $ct . $joturl_longurl_params;
204
+ $encoded = urlencode( urldecode( trim( $url ) ) ); // prevent double-encoding
205
  }
206
  //\jotURL
207
+ $decoded = wpt_fetch_url( "https://api.joturl.com/a/v1/shorten?url=" . $encoded . "&login=" . $joturllogin . "&key=" . $joturlapi . "&format=plain" );
208
+ if ( $decoded !== false ) {
209
+ $shrink = $decoded;
210
+ //jotURL, added: 2013-04-10
211
+ $joturl_shorturl_params = trim( get_option( 'joturl_shorturl_params' ) );
212
+ if ( $joturl_shorturl_params != '' ) {
213
+ if ( strpos( $shrink, "%3F" ) === false && strpos( $shrink, "?" ) === false ) {
214
+ $ct = "?";
215
+ } else {
216
+ $ct = "&";
217
+ }
218
+ $shrink .= $ct . $joturl_shorturl_params;
219
+ }
220
+ //\jotURL
221
+ } else {
222
+ $error = $decoded;
223
+ $shrink = false;
224
+ }
225
+ if ( ! is_valid_url( $shrink ) ) {
226
+ $shrink = false;
227
+ }
228
+ break;
229
+ default: $shrink = $url;
230
+ }
231
  }
232
  if ( $error ) {
233
  update_option( 'wpt_shortener_status', "$shrink : $error" );
240
  update_option( 'wp_url_failure', '0' );
241
  }
242
  }
243
+ $store_urls = apply_filters( 'wpt_store_url', true );
244
+ if ( $store_urls ) {
245
+ wpt_store_url( $post_ID, $shrink );
246
+ }
247
 
248
  return $shrink;
249
  }
250
 
251
  function wpt_store_url( $post_ID, $url ) {
252
  $store_urls = apply_filters( 'wpt_store_urls', true, $post_ID, $url );
253
+ if ( function_exists( 'wpt_shorten_url' ) && $store_urls ) {
254
  $shortener = get_option( 'jd_shortener' );
255
  if ( get_post_meta( $post_ID, '_wpt_short_url', true ) != $url ) {
256
  update_post_meta( $post_ID, '_wpt_short_url', $url );
261
  case 2:
262
  case 7:
263
  case 8:
264
+ $target = wpt_expand_url( $url );
265
  break;
266
  case 5:
267
  case 6:
268
+ $target = wpt_expand_yourl( $url, $shortener );
269
  break;
270
  default:
271
  $target = $url;
275
  }
276
  update_post_meta( $post_ID, '_wp_jd_target', $target );
277
  }
278
+
279
  function jd_expand_url( $short_url ) {
280
+ return wpt_expand_url( $short_url );
281
+ }
282
+
283
+ function wpt_expand_url( $short_url ) {
284
  $short_url = urlencode( $short_url );
285
+ $decoded = wpt_remote_json( "http://api.longurl.org/v2/expand?format=json&url=" . $short_url );
286
  if ( isset( $decoded['long-url'] ) ) {
287
  $url = $decoded['long-url'];
288
  } else {
292
  return $url;
293
  //return $short_url;
294
  }
295
+
296
  function jd_expand_yourl( $short_url, $remote ) {
297
+ return wpt_expand_yourl( $short_url, $remote );
298
+ }
299
+
300
+ function wpt_expand_yourl( $short_url, $remote ) {
301
  if ( $remote == 6 ) {
302
  $short_url = urlencode( $short_url );
303
  $yourl_api = get_option( 'yourlsurl' );
305
  $pass = stripcslashes( get_option( 'yourlsapi' ) );
306
  $token = get_option( 'yourlstoken' );
307
  if ( $token ) {
308
+ $decoded = wpt_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&signature=$token&username=$user&password=$pass" );
309
  } else {
310
+ $decoded = wpt_remote_json( $yourl_api . "?action=expand&shorturl=$short_url&format=json&username=$user&password=$pass" );
311
  }
312
  $url = ( isset( $decoded['longurl'] ) ) ? $decoded['longurl'] : $short_url;
313
 
338
 
339
  add_filter( 'wpt_shortener_controls', 'wpt_shortener_controls' );
340
  function wpt_shortener_controls() {
341
+ $shortener = get_option( 'jd_shortener' );
342
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
343
+ $form_start = '<div class="panel">
344
+ <form method="post" action="' . add_query_arg( 'tab', 'shortener', $admin_url ) . '">
345
+ <div><input type="hidden" name="wpt_shortener_update" value="true" /></div>
346
+ <div>';
347
+ $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false );
348
+ $form_end = '<div>' . $nonce . '</div>
349
+ <p>
350
+ <input type="submit" name="submit" value="' . __( 'Save URL Shortener Settings', 'wp-to-twitter' ) . '" class="button-primary" />
351
+ </p>
352
+ </div>
353
+ </form>
354
+ </div>';
355
  // for the moment, this just displays the fields. Eventually, a real filter.
356
  ?>
357
  <div class="ui-sortable meta-box-sortables">
361
  </h3>
362
 
363
  <div class="inside">
364
+ <?php if ( $shortener == 7 ) { ?>
365
+ <?php echo $form_start; ?>
366
+ <p>
367
+ <label
368
+ for="suprlogin"><?php _e( "Your Su.pr Username:", 'wp-to-twitter' ); ?></label>
369
+ <input type="text" name="suprlogin" id="suprlogin" size="40"
370
+ value="<?php esc_attr_e( get_option( 'suprlogin' ) ) ?>"/>
371
+ </p>
372
+
373
+ <p>
374
+ <label
375
+ for="suprapi"><?php _e( "Your Su.pr <abbr title='application programming interface'>API</abbr> Key:", 'wp-to-twitter' ); ?></label>
376
+ <input type="text" name="suprapi" id="suprapi" size="40"
377
+ value="<?php esc_attr_e( get_option( 'suprapi' ) ) ?>"/>
378
+ </p>
379
+
380
+ <div>
381
+ <input type="hidden" name="submit-type" value="suprapi"/>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
  </div>
383
+ <p><small><?php _e( "Don't have a Su.pr account or API key? <a href='http://su.pr/'>Get one here!</a> You'll need an API key in order to associate the URLs you create with your Su.pr account.", 'wp-to-twitter' ); ?></small></p>
384
+ <?php echo $form_end; ?>
385
+ <?php } else if ( $shortener == 2 ) { ?>
386
+ <?php echo $form_start; ?>
387
+ <p>
388
+ <label
389
+ for="bitlylogin"><?php _e( "Your Bit.ly username:", 'wp-to-twitter' ); ?></label>
390
+ <input type="text" name="bitlylogin" id="bitlylogin"
391
+ value="<?php esc_attr_e( get_option( 'bitlylogin' ) ) ?>"/>
392
+ </p>
393
+ <p>
394
+ <label
395
+ for="bitlyapi"><?php _e( "Your Bit.ly <abbr title='application programming interface'>API</abbr> Key:", 'wp-to-twitter' ); ?></label>
396
+ <input type="text" name="bitlyapi" id="bitlyapi" size="40"
397
+ value="<?php esc_attr_e( get_option( 'bitlyapi' ) ) ?>"/>
398
+ </p>
399
+
400
+ <p>
401
+ <a href="http://bitly.com/a/your_api_key"><?php _e( 'View your Bit.ly username and API key', 'wp-to-twitter' ); ?></a>
402
+ </p>
403
+
404
+ <div>
405
+ <input type="hidden" name="submit-type" value="bitlyapi"/>
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  </div>
407
+ <?php echo $form_end; ?>
408
+ <?php } else if ( $shortener == 5 || $shortener == 6 ) { ?>
409
+ <?php echo $form_start; ?>
410
+ <p>
411
+ <label
412
+ for="yourlspath"><?php _e( 'Path to your YOURLS config file (Local installations)', 'wp-to-twitter' ); ?></label><br/><input
413
+ type="text" id="yourlspath" name="yourlspath" size="60"
414
+ value="<?php esc_attr_e( get_option( 'yourlspath' ) ); ?>"/><br/>
415
+ <small><?php _e( 'Example:', 'wp-to-twitter' ); ?> <code>/home/username/www/www/yourls/user/config.php</code>
416
+ </small>
417
+ </p>
418
+ <p>
419
+ <label
420
+ for="yourlsurl"><?php _e( 'URI to the YOURLS API (Remote installations)', 'wp-to-twitter' ); ?></label><br/><input
421
+ type="text" id="yourlsurl" name="yourlsurl" size="60"
422
+ value="<?php esc_attr_e( get_option( 'yourlsurl' ) ); ?>"/><br/>
423
+ <small><?php _e( 'Example:', 'wp-to-twitter' ); ?> <code>http://domain.com/yourls-api.php</code>
424
+ </small>
425
+ </p>
426
+ <p>
427
+ <label
428
+ for="yourlstoken"><?php _e( "YOURLS signature token:", 'wp-to-twitter' ); ?></label>
429
+ <input type="text" name="yourlstoken" id="yourlstoken" size="30"
430
+ value="<?php esc_attr_e( get_option( 'yourlstoken' ) ) ?>"/>
431
+ </p>
432
+ <?php if ( get_option( 'yourlsapi' ) && get_option( 'yourlslogin' ) ) { ?>
433
+ <p>
434
+ <em><?php _e( 'Your YOURLS username and password are saved. If you add a signature token, that will be used for API calls and your username and password will be deleted from the database.', 'wp-to-twitter' ); ?></em>
435
+ </p>
436
+ <?php } ?>
437
+ <p>
438
+ <input type="radio" name="jd_keyword_format" id="jd_keyword_id"
439
+ value="1" <?php echo jd_checkSelect( 'jd_keyword_format', 1, 'checkbox' ); ?> />
440
+ <label
441
+ for="jd_keyword_id"><?php _e( "Post ID for YOURLS url slug.", 'wp-to-twitter' ); ?></label><br/>
442
+ <input type="radio" name="jd_keyword_format" id="jd_keyword"
443
+ value="2" <?php echo jd_checkSelect( 'jd_keyword_format', 2, 'checkbox' ); ?> />
444
+ <label
445
+ for="jd_keyword"><?php _e( "Custom keyword for YOURLS url slug.", 'wp-to-twitter' ); ?></label><br/>
446
+ <input type="radio" name="jd_keyword_format" id="jd_keyword_default"
447
+ value="0" <?php echo jd_checkSelect( 'jd_keyword_format', 0, 'checkbox' ); ?> />
448
+ <label
449
+ for="jd_keyword_default"><?php _e( "Default: sequential URL numbering.", 'wp-to-twitter' ); ?></label>
450
+ </p>
451
+
452
+ <div>
453
+ <input type="hidden" name="submit-type" value="yourlsapi"/>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
  </div>
455
+ <?php echo $form_end; ?>
456
+ <?php } else if ( $shortener == 10 ) { ?>
457
+ <?php echo $form_start; ?>
458
+ <p>
459
+ <label
460
+ for="joturllogin"><?php _e( "Your jotURL public <abbr title='application programming interface'>API</abbr> key:", 'wp-to-twitter' ); ?></label>
461
+ <input type="text" name="joturllogin" id="joturllogin"
462
+ value="<?php esc_attr_e( get_option( 'joturllogin' ) ) ?>"/>
463
+ </p>
464
+
465
+ <p>
466
+ <label
467
+ for="joturlapi"><?php _e( "Your jotURL private <abbr title='application programming interface'>API</abbr> key:", 'wp-to-twitter' ); ?></label>
468
+ <input type="text" name="joturlapi" id="joturlapi" size="40"
469
+ value="<?php esc_attr_e( get_option( 'joturlapi' ) ) ?>"/>
470
+ </p>
471
+
472
+ <p>
473
+ <label
474
+ for="joturl_longurl_params"><?php _e( "Parameters to add to the long URL (before shortening):", 'wp-to-twitter' ); ?></label>
475
+ <input type="text" name="joturl_longurl_params" id="joturl_longurl_params"
476
+ size="40"
477
+ value="<?php esc_attr_e( get_option( 'joturl_longurl_params' ) ) ?>"/>
478
+ </p>
479
+
480
+ <p>
481
+ <label
482
+ for="joturl_shorturl_params"><?php _e( "Parameters to add to the short URL (after shortening):", 'wp-to-twitter' ); ?></label>
483
+ <input type="text" name="joturl_shorturl_params" id="joturl_shorturl_params"
484
+ size="40"
485
+ value="<?php esc_attr_e( get_option( 'joturl_shorturl_params' ) ) ?>"/>
486
+ </p>
487
+
488
+ <p>
489
+ <a href="https://www.joturl.com/reserved/api.html"><?php _e( 'View your jotURL public and private API key', 'wp-to-twitter' ); ?></a>
490
+ </p>
491
+
492
+ <div><input type="hidden" name="submit-type" value="joturlapi"/></div>
493
+ <?php echo $form_end;
494
+ } else {
495
+ $form = apply_filters( 'wpt_shortener_settings', '', $shortener );
496
+ if ( $form != '' ) {
497
+ echo $form_start . $form . $form_end;
498
+ } else {
499
+ _e( 'Your shortener does not require any account settings.', 'wp-to-twitter' );
500
+ }
501
+ } ?>
502
  </div>
503
  </div>
504
  </div>
516
  $message .= __( 'YOURLS signature token updated.', 'wp-to-twitter' );
517
  }
518
  update_option( 'yourlsurl', trim( $post['yourlsurl'] ) );
519
+ // yourls path is deprecated.
520
  if ( $post['yourlspath'] != '' ) {
521
  update_option( 'yourlspath', trim( $post['yourlspath'] ) );
522
  if ( file_exists( $post['yourlspath'] ) ) {
557
  $message = __( "Su.pr API Key not added - <a href='http://su.pr/'>get one here</a>! ", 'wp-to-twitter' );
558
  }
559
  }
560
+
561
  if ( isset( $post['submit-type'] ) && $post['submit-type'] == 'bitlyapi' ) {
562
  if ( $post['bitlyapi'] != '' && isset( $post['submit'] ) ) {
563
  update_option( 'bitlyapi', trim( $post['bitlyapi'] ) );
578
  $message = __( "Bit.ly Login not added - <a href='http://bit.ly/account/'>get one here</a>! ", 'wp-to-twitter' );
579
  }
580
  }
581
+
582
  if ( isset( $post['submit-type'] ) && $post['submit-type'] == 'joturlapi' ) {
583
  if ( $post['joturlapi'] != '' && isset( $post['submit'] ) ) {
584
  update_option( 'joturlapi', trim( $post['joturlapi'] ) );
621
  $message = __( "Short URL parameters deleted. ", 'wp-to-twitter' );
622
  }
623
  }
624
+
625
+ $message = apply_filters( 'wpt_save_shortener_settings', $message );
626
 
627
  return $message;
628
  }
629
 
630
  function wpt_select_shortener( $post ) {
631
  $message = '';
632
+ // don't return a message if unchanged
633
  if ( $post['jd_shortener'] == get_option( 'jd_shortener' ) ) {
634
+ return;
 
 
 
 
635
  }
636
+ update_option( 'jd_shortener', sanitize_key( $post['jd_shortener'] ) );
637
+
638
+ $short = get_option( 'jd_shortener' );
639
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
640
+ $admin_url = add_query_arg( 'tab', 'shortener', $admin_url );
641
+
642
+ // these are the URL shorteners which require settings.
643
+ if ( $short == 2 || $short == 10 || $short == 6 ) {
644
+ $message .= sprintf( __( 'You must <a href="%s">configure your URL shortener settings</a>.', 'wp-to-twitter' ), $admin_url );
645
  }
646
+
647
+ if ( $message != '' ) {
648
  $message .= "<br />";
649
  }
650
+
651
  return $message;
652
  }
653
 
654
  add_filter( 'wpt_pick_shortener', 'wpt_pick_shortener' );
655
  function wpt_pick_shortener() {
656
+ $shortener = get_option( 'jd_shortener' );
657
  ?>
658
  <p>
659
+ <label for="jd_shortener"><?php _e( "Choose a URL shortener", 'wp-to-twitter' ); ?></label>
 
660
  <select name="jd_shortener" id="jd_shortener">
661
+ <option value="3" <?php selected( $shortener, '3' ); ?>><?php _e( "Don't shorten URLs.", 'wp-to-twitter' ); ?></option>
662
+ <option value="4" <?php selected( $shortener, '4' ); ?>>WordPress</option>
663
+ <option value="2" <?php selected( $shortener, '2' ); ?>>Bit.ly</option>
664
+ <option value="8" <?php selected( $shortener, '8' ); ?>>Goo.gl</option>
665
+ <option value="7" <?php selected( $shortener, '7' ); ?>>Su.pr</option>
666
+ <?php if ( $shortener == 5 ) { // if the user has already selected local server, leave available ?>
667
+ <option value="5" <?php selected( $shortener, '5' ); ?>><?php _e( "YOURLS (this server)", 'wp-to-twitter' ); ?></option>
668
+ <?php } ?>
669
+ <option value="6" <?php selected( $shortener, '6' ); ?>><?php _e( "YOURLS (remote server)", 'wp-to-twitter' ); ?></option>
670
+ <option value="10" <?php selected( $shortener, '10' ); ?>>jotURL</option>
 
671
  <?php if ( function_exists( 'twitter_link' ) ) { ?>
672
+ <option value="9" <?php selected( $shortener, '9' ); ?>><?php _e( "Twitter Friendly Links", 'wp-to-twitter' ); ?></option>
673
+ <?php }
674
+ echo apply_filters( 'wpt_choose_shortener', '', $shortener );
675
+ ?>
676
  </select>
677
  </p>
678
  <?php
wp-to-twitter.php CHANGED
@@ -3,13 +3,13 @@
3
  Plugin Name: WP to Twitter
4
  Plugin URI: http://www.joedolson.com/wp-to-twitter/
5
  Description: Posts a Tweet when you update your WordPress blog or post a link, using your URL shortening service. Rich in features for customizing and promoting your Tweets.
6
- Version: 3.1.9
7
  Author: Joseph Dolson
8
  Text Domain: wp-to-twitter
9
  Domain Path: /lang
10
  Author URI: http://www.joedolson.com/
11
  */
12
- /* Copyright 2008-2015 Joseph C Dolson (email : plugins@joedolson.com)
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License as published by
@@ -34,8 +34,6 @@ define( 'WPT_DEBUG_ADDRESS', get_option( 'admin_email' ) );
34
  define( 'WPT_FROM', "From: \"" . get_option( 'blogname' ) . "\" <" . get_option( 'admin_email' ) . ">" );
35
  // define( 'WPT_DEBUG_ADDRESS', 'debug@joedolson.com, yourname@youraddress.com' ); // for multiple recipients.
36
 
37
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); // required in order to access is_plugin_active()
38
-
39
  require_once( plugin_dir_path( __FILE__ ) . '/wpt-functions.php' );
40
  require_once( plugin_dir_path( __FILE__ ) . '/wp-to-twitter-oauth.php' );
41
  require_once( plugin_dir_path( __FILE__ ) . '/wp-to-twitter-shorteners.php' );
@@ -46,7 +44,60 @@ require_once( plugin_dir_path( __FILE__ ) . '/wpt-widget.php' );
46
  require_once( plugin_dir_path( __FILE__ ) . '/wpt-rate-limiting.php' );
47
 
48
  global $wpt_version;
49
- $wpt_version = "3.1.9";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  add_action( 'plugins_loaded', 'wpt_load_textdomain' );
52
  function wpt_load_textdomain() {
@@ -100,7 +151,7 @@ function wptotwitter_activate() {
100
  update_option( 'jd_replace_character', '' );
101
  $administrator = get_role( 'administrator' );
102
  if ( is_object( $administrator ) ) {
103
- $administrator->add_cap( 'wpt_twitter_oauth' );
104
  $administrator->add_cap( 'wpt_twitter_custom' );
105
  $administrator->add_cap( 'wpt_twitter_switch' );
106
  $administrator->add_cap( 'wpt_can_tweet' );
@@ -262,25 +313,6 @@ function wptotwitter_activate() {
262
  update_option( 'wp_to_twitter_version', $wpt_version );
263
  }
264
 
265
-
266
- function wpt_get_migration_posts( $type = 'posts' ) {
267
- $posts = get_posts(
268
- array( 'numberposts'=>-1, 'meta_query'=>
269
- array(
270
- array(
271
- 'key' => '_wp_jd_target',
272
- 'value' => 'http',
273
- 'compare' => 'LIKE'
274
- )
275
- )
276
- )
277
- );
278
-
279
- $count = count( $posts );
280
-
281
- return ( $type == 'posts' ) ? $posts : $count;
282
- }
283
-
284
  /**
285
  * Migrates post meta to new format when post is called in editor.
286
  */
@@ -383,6 +415,7 @@ function wpt_check_recent_tweet( $id, $auth ) {
383
  $expire = apply_filters( 'wpt_recent_tweet_threshold', 30 );
384
  // if expiration is 0, don't set the transient. We don't want permanent transients.
385
  if ( $expire !== 0 ) {
 
386
  if ( $auth == false ) {
387
  set_transient( "_wpt_most_recent_tweet_$id", true, $expire );
388
  } else {
@@ -415,11 +448,12 @@ function jd_doTwitterAPIPost( $twit, $auth = false, $id = false, $media = false
415
  return false;
416
  }
417
  }
418
-
419
  $http_code = 0;
420
  if ( $recent ) {
421
  return false;
422
  }
 
423
  if ( ! wpt_check_oauth( $auth ) ) {
424
  $error = __( 'This account is not authorized to post to Twitter.', 'wp-to-twitter' );
425
  wpt_saves_error( $id, $auth, $twit, $error, '401', time() );
@@ -1180,7 +1214,7 @@ function wpt_add_twitter_inner_box( $post ) {
1180
  $jd_template = ( $status == 'publish' ) ? $options[ $type ]['post-edited-text'] : $options[ $type ]['post-published-text'];
1181
 
1182
  if ( $status == 'publish' && $options[ $type ]['post-edited-update'] != 1 ) {
1183
- $tweet_status = sprintf( __( 'Tweeting %s edits is disabled.', 'wp-to-twitter' ), $type );
1184
  }
1185
 
1186
  if ( $status == 'publish' && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
@@ -1192,7 +1226,7 @@ function wpt_add_twitter_inner_box( $post ) {
1192
  <button class='tweet schedule button-secondary' data-action='schedule'
1193
  disabled><?php _e( 'Schedule', 'wp-to-twitter' ); ?></button>
1194
  <button class='time button-secondary'>
1195
- <span class="dashicons dashicons-clock"><span
1196
  class="screen-reader-text"><?php _e( 'Set Date/Time', 'wp-to-twitter' ); ?></span></span>
1197
  </button>
1198
  <div id="jts">
@@ -1215,9 +1249,6 @@ function wpt_add_twitter_inner_box( $post ) {
1215
  </div>
1216
  <?php
1217
  }
1218
- if ( $tweet_status != '' ) {
1219
- echo "<p class='disabled'>$tweet_status</p>";
1220
- }
1221
  if ( current_user_can( 'wpt_twitter_custom' ) || current_user_can( 'manage_options' ) ) {
1222
  ?>
1223
  <p class='jtw'>
@@ -1234,8 +1265,10 @@ function wpt_add_twitter_inner_box( $post ) {
1234
  $jd_expanded = $jd_expanded . " <span title='" . __( 'Your appended Tweet text; not part of your template.', 'wp-to-twitter' ) . "'>" . stripslashes( get_option( 'jd_twit_append' ) ) . "</span>";
1235
  }
1236
  ?>
1237
- <p class='template'><?php _e( 'Your template:', 'wp-to-twitter' ); ?>
1238
- <code><?php echo stripcslashes( $jd_expanded ); ?></code></p>
 
 
1239
  <?php
1240
  echo apply_filters( 'wpt_custom_retweet_fields', '', $post_id );
1241
  if ( get_option( 'jd_keyword_format' ) == 2 ) {
@@ -1247,22 +1280,7 @@ function wpt_add_twitter_inner_box( $post ) {
1247
  <input type="hidden" name='_jd_twitter' value='<?php esc_attr_e( $tweet ); ?>'/>
1248
  <?php
1249
  }
1250
- if ( current_user_can( 'wpt_twitter_switch' ) || current_user_can( 'manage_options' ) ) {
1251
- // "no" means 'Don't Tweet' (is checked)
1252
- $nochecked = ( $jd_tweet_this == 'no' ) ? ' checked="checked"' : '';
1253
- $yeschecked = ( $jd_tweet_this == 'yes' ) ? ' checked="checked"' : '';
1254
- ?>
1255
- <p class='toggle-btn-group'>
1256
- <input type="radio" name="_jd_tweet_this" value="no" id="jtn"<?php echo $nochecked; ?> /><label for="jtn"><?php _e( "Don't Tweet post.", 'wp-to-twitter' ); ?></label>
1257
- <input type="radio" name="_jd_tweet_this" value="yes" id="jty"<?php echo $yeschecked; ?> />
1258
- <label for="jty"><?php _e( "Tweet post.", 'wp-to-twitter' ); ?></label>
1259
- </p>
1260
- <?php
1261
- } else {
1262
- ?>
1263
- <input type='hidden' name='_jd_tweet_this' value='<?php echo $jd_tweet_this; ?>'/>
1264
- <?php
1265
- } ?>
1266
  <div class='wpt-options'>
1267
  <?php
1268
  if ( $is_pro == 'pro' ) {
@@ -1307,7 +1325,7 @@ function wpt_add_twitter_inner_box( $post ) {
1307
  wpt_schedule_values( $post_id );
1308
  do_action( 'wpt_custom_tab', $post_id, 'visible' );
1309
  } else {
1310
- if ( function_exists( 'wpt_pro_exists' ) ) {
1311
  echo "<p>" .sprintf( __( 'Upgrade to WP Tweets PRO to configure options! <a href="%s">Upgrade now!</a>', 'wp-to-twitter' ), 'http://www.joedolson.com/wp-tweets-pro/' ) . "</p>";
1312
  }
1313
  }
@@ -1339,17 +1357,39 @@ function wpt_add_twitter_inner_box( $post ) {
1339
  <?php
1340
  } ?>
1341
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1342
  <p class="wpt-support">
1343
  <?php if ( ! function_exists( 'wpt_pro_exists' ) ) {
1344
  /* These aren't actually usages that require esc_url. But using it will give people the illusion that it does something. */
1345
  ?>
1346
- <strong><a target="__blank" href="https://www.joedolson.com/wp-tweets-pro/"><?php _e( 'Go Premium', 'wp-to-twitter', 'wp-to-twitter' ) ?></a></strong> &raquo;
1347
  <?php } else { ?>
1348
- <a target="_blank"
1349
- href="<?php echo esc_url( add_query_arg( 'tab', 'support', admin_url( 'admin.php?page=wp-tweets-pro' ) ) ); ?>#get-support"><?php _e( 'Get Support', 'wp-to-twitter', 'wp-to-twitter' ); ?></a> &raquo;
1350
  <?php } ?>
1351
- </p>
1352
- <?php wpt_show_tweets( $previous_tweets, $failed_tweets ); ?>
 
 
 
 
1353
  </div>
1354
  <?php
1355
  } else { // permissions: this user isn't allowed to Tweet;
@@ -1373,8 +1413,8 @@ function wpt_show_tweets( $previous_tweets, $failed_tweets ) {
1373
  if ( ! empty( $previous_tweets ) || ! empty( $failed_tweets ) ) {
1374
  ?>
1375
  <hr>
1376
- <p><span class='dashicons dashicons-plus'></span><a href='#wpt_tweet_history'
1377
- class='history-toggle'><?php _e( 'View Tweet History', 'wp-to-twitter' ); ?></a>
1378
  </p>
1379
  <div class='history'>
1380
  <p class='error'><em><?php _e( 'Previous Tweets', 'wp-to-twitter' ); ?>:</em></p>
@@ -1619,13 +1659,13 @@ function wpt_custom_shortcodes( $sentence, $post_ID ) {
1619
  */
1620
  function wpt_twitter_profile() {
1621
  global $user_ID;
1622
- get_currentuserinfo();
1623
- if ( current_user_can( 'wpt_twitter_oauth' ) || current_user_can( 'manage_options' ) ) {
1624
- $user_edit = ( isset( $_GET['user_id'] ) ) ? (int) $_GET['user_id'] : $user_ID;
1625
 
1626
- $is_enabled = get_user_meta( $user_edit, 'wp-to-twitter-enable-user', true );
1627
- $twitter_username = get_user_meta( $user_edit, 'wp-to-twitter-user-username', true );
1628
- $wpt_remove = get_user_meta( $user_edit, 'wpt-remove', true );
 
1629
  ?>
1630
  <h3><?php _e( 'WP Tweets User Settings', 'wp-to-twitter' ); ?></h3>
1631
  <?php if ( function_exists( 'wpt_connect_oauth_message' ) ) {
@@ -1644,7 +1684,7 @@ function wpt_twitter_profile() {
1644
  for="wp-to-twitter-user-username"><?php _e( "Your Twitter Username", 'wp-to-twitter' ); ?></label>
1645
  </th>
1646
  <td><input type="text" name="wp-to-twitter-user-username" id="wp-to-twitter-user-username"
1647
- value="<?php echo esc_attr( $twitter_username ); ?>"/> <?php _e( 'Enter your own Twitter username.', 'wp-to-twitter' ); ?>
1648
  </td>
1649
  </tr>
1650
  <tr>
@@ -1667,37 +1707,58 @@ function wpt_twitter_profile() {
1667
  wtt_connect_oauth( $user_edit );
1668
  }
1669
  }
 
 
 
 
 
 
 
1670
  }
1671
  }
1672
 
1673
  /**
1674
  * Save user profile data
1675
  */
1676
- function wpt_twitter_save_profile() {
1677
  global $user_ID;
1678
- get_currentuserinfo();
1679
  if ( isset( $_POST['user_id'] ) ) {
1680
  $edit_id = (int) $_POST['user_id'];
1681
  } else {
1682
  $edit_id = $user_ID;
1683
  }
1684
- $enable = ( isset( $_POST['wp-to-twitter-enable-user'] ) ) ? $_POST['wp-to-twitter-enable-user'] : '';
1685
- $username = ( isset( $_POST['wp-to-twitter-user-username'] ) ) ? $_POST['wp-to-twitter-user-username'] : '';
1686
- $wpt_remove = ( isset( $_POST['wpt-remove'] ) ) ? 'on' : '';
1687
- update_user_meta( $edit_id, 'wp-to-twitter-enable-user', $enable );
1688
- update_user_meta( $edit_id, 'wp-to-twitter-user-username', $username );
1689
- update_user_meta( $edit_id, 'wpt-remove', $wpt_remove );
 
 
1690
  //WPT PRO
1691
  apply_filters( 'wpt_save_user', $edit_id, $_POST );
1692
  }
1693
 
 
 
 
 
 
 
 
 
 
 
 
1694
  add_action( 'admin_menu', 'wpt_admin_page' );
1695
  /**
1696
  * Add the administrative settings to the "Settings" menu.
1697
  */
1698
  function wpt_admin_page() {
1699
- if ( function_exists( 'add_options_page' ) && ! function_exists( 'wpt_pro_functions' ) ) {
1700
- add_options_page( 'WP to Twitter', 'WP to Twitter', 'manage_options', __FILE__, 'wpt_update_settings' );
 
1701
  }
1702
  }
1703
 
@@ -1716,7 +1777,7 @@ function wpt_admin_style() {
1716
  */
1717
  function wpt_plugin_action( $links, $file ) {
1718
  if ( $file == plugin_basename( dirname( __FILE__ ) . '/wp-to-twitter.php' ) ) {
1719
- $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php' );
1720
  $links[] = "<a href='$admin_url'>" . __( 'WP to Twitter Settings', 'wp-to-twitter', 'wp-to-twitter' ) . "</a>";
1721
  if ( ! function_exists( 'wpt_pro_exists' ) ) {
1722
  $links[] = "<a href='https://www.joedolson.com/wp-tweets-pro/'>" . __( 'Go Premium', 'wp-to-twitter', 'wp-to-twitter' ) . "</a>";
3
  Plugin Name: WP to Twitter
4
  Plugin URI: http://www.joedolson.com/wp-to-twitter/
5
  Description: Posts a Tweet when you update your WordPress blog or post a link, using your URL shortening service. Rich in features for customizing and promoting your Tweets.
6
+ Version: 3.2.0
7
  Author: Joseph Dolson
8
  Text Domain: wp-to-twitter
9
  Domain Path: /lang
10
  Author URI: http://www.joedolson.com/
11
  */
12
+ /* Copyright 2008-2016 Joseph C Dolson (email : plugins@joedolson.com)
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License as published by
34
  define( 'WPT_FROM', "From: \"" . get_option( 'blogname' ) . "\" <" . get_option( 'admin_email' ) . ">" );
35
  // define( 'WPT_DEBUG_ADDRESS', 'debug@joedolson.com, yourname@youraddress.com' ); // for multiple recipients.
36
 
 
 
37
  require_once( plugin_dir_path( __FILE__ ) . '/wpt-functions.php' );
38
  require_once( plugin_dir_path( __FILE__ ) . '/wp-to-twitter-oauth.php' );
39
  require_once( plugin_dir_path( __FILE__ ) . '/wp-to-twitter-shorteners.php' );
44
  require_once( plugin_dir_path( __FILE__ ) . '/wpt-rate-limiting.php' );
45
 
46
  global $wpt_version;
47
+ $wpt_version = "3.2.0";
48
+
49
+ // Create a helper function for easy SDK access.
50
+ function wtt_fs() {
51
+ global $wtt_fs;
52
+
53
+ if ( ! isset( $wtt_fs ) ) {
54
+ // Include Freemius SDK.
55
+ require_once dirname(__FILE__) . '/freemius/start.php';
56
+
57
+ $wtt_fs = fs_dynamic_init( array(
58
+ 'id' => '176',
59
+ 'slug' => 'wp-to-twitter',
60
+ 'public_key' => 'pk_6f6b0b21c7da9b9d4ad8cded5bd16',
61
+ 'is_premium' => false,
62
+ 'has_addons' => false,
63
+ 'has_paid_plans' => false,
64
+ 'menu' => array(
65
+ 'slug' => 'wp-tweets-pro',
66
+ 'account' => false,
67
+ 'contact' => false,
68
+ 'support' => false
69
+ ),
70
+ ) );
71
+ }
72
+
73
+ return $wtt_fs;
74
+ }
75
+
76
+ wtt_fs();
77
+
78
+ function wtt_fs_custom_connect_message(
79
+ $message,
80
+ $user_first_name,
81
+ $plugin_title,
82
+ $user_login,
83
+ $site_link,
84
+ $freemius_link
85
+ ) {
86
+ return sprintf(
87
+ __fs( 'hey-x' ) . '<br>' .
88
+ __( 'Do you want to help me improve %2$s? Let me gather some data! To do that, I need to connect your user, %3$s at %4$s, to %5$s. </p><p><em>This is purely optional, but I\'d certainly appreciate it!</em>', 'wp-to-twitter' ),
89
+ $user_first_name,
90
+ '<b>' . $plugin_title . '</b>',
91
+ '<b>' . $user_login . '</b>',
92
+ $site_link,
93
+ $freemius_link
94
+ );
95
+ }
96
+
97
+ wtt_fs()->add_action( 'after_uninstall', 'wtt_fs_uninstall_cleanup' );
98
+ wtt_fs()->add_filter( 'connect_message', 'wtt_fs_custom_connect_message', 10, 6 );
99
+ wtt_fs()->add_action( 'after_uninstall', 'wtt_fs_uninstall_cleanup' );
100
+ // Init Freemius.
101
 
102
  add_action( 'plugins_loaded', 'wpt_load_textdomain' );
103
  function wpt_load_textdomain() {
151
  update_option( 'jd_replace_character', '' );
152
  $administrator = get_role( 'administrator' );
153
  if ( is_object( $administrator ) ) {
154
+ $administrator->add_cap( 'wpt_twitter_oauth' ); // wpt_twitter_oauth is the general permission for editing user accounts
155
  $administrator->add_cap( 'wpt_twitter_custom' );
156
  $administrator->add_cap( 'wpt_twitter_switch' );
157
  $administrator->add_cap( 'wpt_can_tweet' );
313
  update_option( 'wp_to_twitter_version', $wpt_version );
314
  }
315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  /**
317
  * Migrates post meta to new format when post is called in editor.
318
  */
415
  $expire = apply_filters( 'wpt_recent_tweet_threshold', 30 );
416
  // if expiration is 0, don't set the transient. We don't want permanent transients.
417
  if ( $expire !== 0 ) {
418
+ wpt_mail( "Tweet transient being set: $id", "$expire / $auth / $id" );
419
  if ( $auth == false ) {
420
  set_transient( "_wpt_most_recent_tweet_$id", true, $expire );
421
  } else {
448
  return false;
449
  }
450
  }
451
+
452
  $http_code = 0;
453
  if ( $recent ) {
454
  return false;
455
  }
456
+
457
  if ( ! wpt_check_oauth( $auth ) ) {
458
  $error = __( 'This account is not authorized to post to Twitter.', 'wp-to-twitter' );
459
  wpt_saves_error( $id, $auth, $twit, $error, '401', time() );
1214
  $jd_template = ( $status == 'publish' ) ? $options[ $type ]['post-edited-text'] : $options[ $type ]['post-published-text'];
1215
 
1216
  if ( $status == 'publish' && $options[ $type ]['post-edited-update'] != 1 ) {
1217
+ $tweet_status = sprintf( __( '%s will not be Tweeted on update.', 'wp-to-twitter' ), ucfirst( $type ) );
1218
  }
1219
 
1220
  if ( $status == 'publish' && ( current_user_can( 'wpt_tweet_now' ) || current_user_can( 'manage_options' ) ) ) {
1226
  <button class='tweet schedule button-secondary' data-action='schedule'
1227
  disabled><?php _e( 'Schedule', 'wp-to-twitter' ); ?></button>
1228
  <button class='time button-secondary'>
1229
+ <span class="dashicons dashicons-clock" aria-hidden="true"><span
1230
  class="screen-reader-text"><?php _e( 'Set Date/Time', 'wp-to-twitter' ); ?></span></span>
1231
  </button>
1232
  <div id="jts">
1249
  </div>
1250
  <?php
1251
  }
 
 
 
1252
  if ( current_user_can( 'wpt_twitter_custom' ) || current_user_can( 'manage_options' ) ) {
1253
  ?>
1254
  <p class='jtw'>
1265
  $jd_expanded = $jd_expanded . " <span title='" . __( 'Your appended Tweet text; not part of your template.', 'wp-to-twitter' ) . "'>" . stripslashes( get_option( 'jd_twit_append' ) ) . "</span>";
1266
  }
1267
  ?>
1268
+ <p class='template'>
1269
+ <?php _e( 'Template:', 'wp-to-twitter' ); ?><br />
1270
+ <code><?php echo stripcslashes( $jd_expanded ); ?></code>
1271
+ </p>
1272
  <?php
1273
  echo apply_filters( 'wpt_custom_retweet_fields', '', $post_id );
1274
  if ( get_option( 'jd_keyword_format' ) == 2 ) {
1280
  <input type="hidden" name='_jd_twitter' value='<?php esc_attr_e( $tweet ); ?>'/>
1281
  <?php
1282
  }
1283
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1284
  <div class='wpt-options'>
1285
  <?php
1286
  if ( $is_pro == 'pro' ) {
1325
  wpt_schedule_values( $post_id );
1326
  do_action( 'wpt_custom_tab', $post_id, 'visible' );
1327
  } else {
1328
+ if ( ! function_exists( 'wpt_pro_exists' ) ) {
1329
  echo "<p>" .sprintf( __( 'Upgrade to WP Tweets PRO to configure options! <a href="%s">Upgrade now!</a>', 'wp-to-twitter' ), 'http://www.joedolson.com/wp-tweets-pro/' ) . "</p>";
1330
  }
1331
  }
1357
  <?php
1358
  } ?>
1359
  </div>
1360
+ <?php
1361
+ if ( current_user_can( 'wpt_twitter_switch' ) || current_user_can( 'manage_options' ) ) {
1362
+ // "no" means 'Don't Tweet' (is checked)
1363
+ $nochecked = ( $jd_tweet_this == 'no' ) ? ' checked="checked"' : '';
1364
+ $yeschecked = ( $jd_tweet_this == 'yes' ) ? ' checked="checked"' : '';
1365
+ ?>
1366
+ <p class='toggle-btn-group'>
1367
+ <input type="radio" name="_jd_tweet_this" value="no" id="jtn"<?php echo $nochecked; ?> /><label for="jtn"><?php _e( "Don't Tweet post", 'wp-to-twitter' ); ?></label>
1368
+ <input type="radio" name="_jd_tweet_this" value="yes" id="jty"<?php echo $yeschecked; ?> />
1369
+ <label for="jty"><?php _e( "Tweet post", 'wp-to-twitter' ); ?></label>
1370
+ </p>
1371
+ <?php
1372
+ } else {
1373
+ ?>
1374
+ <input type='hidden' name='_jd_tweet_this' value='<?php echo $jd_tweet_this; ?>'/>
1375
+ <?php
1376
+ }
1377
+ wpt_show_tweets( $previous_tweets, $failed_tweets );
1378
+ ?>
1379
  <p class="wpt-support">
1380
  <?php if ( ! function_exists( 'wpt_pro_exists' ) ) {
1381
  /* These aren't actually usages that require esc_url. But using it will give people the illusion that it does something. */
1382
  ?>
1383
+ <strong><a href="https://www.joedolson.com/wp-tweets-pro/"><?php _e( 'Go Premium', 'wp-to-twitter', 'wp-to-twitter' ) ?></a></strong> &raquo;
1384
  <?php } else { ?>
1385
+ <a href="<?php echo esc_url( add_query_arg( 'tab', 'support', admin_url( 'admin.php?page=wp-tweets-pro' ) ) ); ?>#get-support"><?php _e( 'Get Support', 'wp-to-twitter', 'wp-to-twitter' ); ?></a> &raquo;
 
1386
  <?php } ?>
1387
+ </p>
1388
+ <?php
1389
+ if ( $tweet_status != '' ) {
1390
+ echo "<p class='disabled'>$tweet_status</p>";
1391
+ }
1392
+ ?>
1393
  </div>
1394
  <?php
1395
  } else { // permissions: this user isn't allowed to Tweet;
1413
  if ( ! empty( $previous_tweets ) || ! empty( $failed_tweets ) ) {
1414
  ?>
1415
  <hr>
1416
+ <p class='panel-toggle'>
1417
+ <a href='#wpt_tweet_history' class='history-toggle'><span class='dashicons dashicons-plus' aria-hidden="true"></span><?php _e( 'View Tweet History', 'wp-to-twitter' ); ?></a>
1418
  </p>
1419
  <div class='history'>
1420
  <p class='error'><em><?php _e( 'Previous Tweets', 'wp-to-twitter' ); ?>:</em></p>
1659
  */
1660
  function wpt_twitter_profile() {
1661
  global $user_ID;
1662
+ $current_user = wp_get_current_user();
1663
+ $user_edit = ( isset( $_GET['user_id'] ) ) ? (int) $_GET['user_id'] : $user_ID;
 
1664
 
1665
+ $is_enabled = get_user_meta( $user_edit, 'wp-to-twitter-enable-user', true );
1666
+ $twitter_username = get_user_meta( $user_edit, 'wp-to-twitter-user-username', true );
1667
+ $wpt_remove = get_user_meta( $user_edit, 'wpt-remove', true );
1668
+ if ( current_user_can( 'wpt_twitter_oauth' ) || current_user_can( 'manage_options' ) ) {
1669
  ?>
1670
  <h3><?php _e( 'WP Tweets User Settings', 'wp-to-twitter' ); ?></h3>
1671
  <?php if ( function_exists( 'wpt_connect_oauth_message' ) ) {
1684
  for="wp-to-twitter-user-username"><?php _e( "Your Twitter Username", 'wp-to-twitter' ); ?></label>
1685
  </th>
1686
  <td><input type="text" name="wp-to-twitter-user-username" id="wp-to-twitter-user-username"
1687
+ value="<?php esc_attr_e( $twitter_username ); ?>"/> <?php _e( 'Enter your own Twitter username.', 'wp-to-twitter' ); ?>
1688
  </td>
1689
  </tr>
1690
  <tr>
1707
  wtt_connect_oauth( $user_edit );
1708
  }
1709
  }
1710
+ } else {
1711
+ // hidden fields. If function is enabled, but this user does not have privileges to edit.
1712
+ ?>
1713
+ <input type="hidden" name="wp-to-twitter-enable-user" value="<?php esc_attr_e( $is_enabled ); ?>" />
1714
+ <input type="hidden" name="wp-to-twitter-user-username" value="<?php esc_attr_e( $twitter_username ); ?>" />
1715
+ <input type="hidden" name="wpt-remove" value="<?php esc_attr_e( $wpt_remove ); ?>" />
1716
+ <?php
1717
  }
1718
  }
1719
 
1720
  /**
1721
  * Save user profile data
1722
  */
1723
+ function wpt_twitter_save_profile() {
1724
  global $user_ID;
1725
+ $current_user = wp_get_current_user();
1726
  if ( isset( $_POST['user_id'] ) ) {
1727
  $edit_id = (int) $_POST['user_id'];
1728
  } else {
1729
  $edit_id = $user_ID;
1730
  }
1731
+ if ( current_user_can( 'wpt_twitter_oauth' ) || current_user_can( 'manage_options' ) ) {
1732
+ $enable = ( isset( $_POST['wp-to-twitter-enable-user'] ) ) ? $_POST['wp-to-twitter-enable-user'] : '';
1733
+ $username = ( isset( $_POST['wp-to-twitter-user-username'] ) ) ? $_POST['wp-to-twitter-user-username'] : '';
1734
+ $wpt_remove = ( isset( $_POST['wpt-remove'] ) ) ? 'on' : '';
1735
+ update_user_meta( $edit_id, 'wp-to-twitter-enable-user', $enable );
1736
+ update_user_meta( $edit_id, 'wp-to-twitter-user-username', $username );
1737
+ update_user_meta( $edit_id, 'wpt-remove', $wpt_remove );
1738
+ }
1739
  //WPT PRO
1740
  apply_filters( 'wpt_save_user', $edit_id, $_POST );
1741
  }
1742
 
1743
+ /**
1744
+ * Send links to old admin to new admin page
1745
+ */
1746
+ add_action( 'init', 'wpt_old_admin_redirect' );
1747
+ function wpt_old_admin_redirect() {
1748
+ if ( is_admin() && isset( $_GET['page'] ) && $_GET['page'] == 'wp-to-twitter/wp-to-twitter.php' ) {
1749
+ wp_safe_redirect( admin_url( 'admin.php?page=wp-tweets-pro' ) );
1750
+ exit;
1751
+ }
1752
+ }
1753
+
1754
  add_action( 'admin_menu', 'wpt_admin_page' );
1755
  /**
1756
  * Add the administrative settings to the "Settings" menu.
1757
  */
1758
  function wpt_admin_page() {
1759
+ if ( function_exists( 'add_menu_page' ) && ! function_exists( 'wpt_pro_functions' ) ) {
1760
+ $icon_path = plugins_url( 'images/icon.png', __FILE__ );
1761
+ $page = add_menu_page(__('WP to Twitter','wp-to-twitter'), __('WP to Twitter','wp-to-twitter'), 'manage_options', 'wp-tweets-pro', 'wpt_update_settings',$icon_path );
1762
  }
1763
  }
1764
 
1777
  */
1778
  function wpt_plugin_action( $links, $file ) {
1779
  if ( $file == plugin_basename( dirname( __FILE__ ) . '/wp-to-twitter.php' ) ) {
1780
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
1781
  $links[] = "<a href='$admin_url'>" . __( 'WP to Twitter Settings', 'wp-to-twitter', 'wp-to-twitter' ) . "</a>";
1782
  if ( ! function_exists( 'wpt_pro_exists' ) ) {
1783
  $links[] = "<a href='https://www.joedolson.com/wp-tweets-pro/'>" . __( 'Go Premium', 'wp-to-twitter', 'wp-to-twitter' ) . "</a>";
wpt-feed.php CHANGED
@@ -184,7 +184,7 @@ class WPT_TwitterFeed {
184
  return array( 'error' => __( 'Missing Twitter Feed Screen Name - Check Settings', 'wp-to-twitter' ) );
185
  }
186
 
187
- $connection = new jd_TwitterOAuth( $key, $secret, $token, $token_secret );
188
 
189
  if ( isset( $options['search'] ) ) {
190
  $args = array( 'q' => urlencode( $options['search'] ),
184
  return array( 'error' => __( 'Missing Twitter Feed Screen Name - Check Settings', 'wp-to-twitter' ) );
185
  }
186
 
187
+ $connection = new wpt_TwitterOAuth( $key, $secret, $token, $token_secret );
188
 
189
  if ( isset( $options['search'] ) ) {
190
  $args = array( 'q' => urlencode( $options['search'] ),
wpt-functions.php CHANGED
@@ -103,7 +103,7 @@ function wpt_settings_tabs() {
103
  $output = '';
104
  $default = ( get_option( 'wtt_twitter_username' ) == '' ) ? 'connection' : 'basic';
105
  $current = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $default;
106
- $pro_text = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? __( 'Pro Settings', 'wp-to-twitter' ) : __( 'Get WP Tweets PRO', 'wp-to-twitter' );
107
  $pages = array(
108
  'connection'=> __( 'Twitter Connection', 'wp-to-twitter' ),
109
  'basic'=> __( 'Basic Settings', 'wp-to-twitter' ),
@@ -113,7 +113,7 @@ function wpt_settings_tabs() {
113
  'pro' => $pro_text
114
  );
115
  $pages = apply_filters( 'wpt_settings_tabs_pages', $pages, $current );
116
- $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php' );
117
 
118
  foreach ( $pages as $key => $value ) {
119
  $selected = ( $key == $current ) ? " nav-tab-active" : '';
@@ -150,7 +150,7 @@ function wpt_handle_errors() {
150
  delete_option( 'wp_url_failure' );
151
  }
152
  if ( get_option( 'wp_url_failure' ) == '1' ) {
153
- $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php' );
154
  $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
155
  $error = '<div class="error">' .
156
  __( "<p>The query to the URL shortener API failed, and your URL was not shrunk. The full post URL was attached to your Tweet. Check with your URL shortening provider to see if there are any known issues.</p>", 'wp-to-twitter' ) .
@@ -207,8 +207,8 @@ function wpt_show_debug() {
207
  }
208
  }
209
 
210
- function jd_remote_json( $url, $array = true ) {
211
- $input = jd_fetch_url( $url );
212
  $obj = json_decode( $input, $array );
213
  if ( function_exists( 'json_last_error' ) ) { // > PHP 5.3
214
  try {
@@ -254,7 +254,7 @@ function is_valid_url( $url ) {
254
  }
255
 
256
  // Fetch a remote page. Input url, return content
257
- function jd_fetch_url( $url, $method = 'GET', $body = '', $headers = '', $return = 'body' ) {
258
  $request = new WP_Http;
259
  $result = $request->request( $url, array( 'method' => $method,
260
  'body' => $body,
@@ -529,13 +529,13 @@ function wpt_post_attachment( $post_ID ) {
529
 
530
  function wpt_get_support_form() {
531
  global $current_user, $wpt_version;
532
- get_currentuserinfo();
533
  $request = '';
534
  $response_email = '';
535
  // send fields for WP to Twitter
536
  $license = ( get_option( 'wpt_license_key' ) != '' ) ? get_option( 'wpt_license_key' ) : 'none';
537
- if ( $license != '' ) {
538
- $valid = ( get_option( 'wpt_license_valid' ) == 'true' ) ? ' (valid)' : ' (invalid)';
539
  } else {
540
  $valid = '';
541
  }
@@ -651,7 +651,7 @@ $plugins_string
651
  } else {
652
  $checked = '';
653
  }
654
- $admin_url = ( is_plugin_active( 'wp-tweets-pro/wpt-pro-functions.php' ) ) ? admin_url( 'admin.php?page=wp-tweets-pro' ) : admin_url( 'options-general.php?page=wp-to-twitter/wp-to-twitter.php' );
655
  $admin_url = add_query_arg( 'tab', 'support', $admin_url );
656
 
657
  echo "
@@ -674,7 +674,7 @@ $plugins_string
674
  <input type='checkbox' name='has_read_faq' id='has_read_faq' value='on' required='required' aria-required='true' /> <label for='has_read_faq'>" . sprintf( __( 'I have read <a href="%1$s">the FAQ for this plug-in</a> <span>(required)</span>', 'wp-to-twitter' ), 'http://www.joedolson.com/wp-to-twitter/support-2/' ) . "
675
  </p>
676
  <p>
677
- <input type='checkbox' name='has_donated' id='has_donated' value='on' $checked /> <label for='has_donated'>" . sprintf( __( 'I <a href="%1$s">made a donation to help support this plug-in</a>', 'wp-to-twitter' ), 'http://www.joedolson.com/donate.php' ) . "</label>
678
  </p>
679
  <p>
680
  <label for='support_request'>" . __( 'Support Request:', 'wp-to-twitter' ) . "</label><br /><textarea class='support-request' name='support_request' id='support_request' cols='80' rows='10' class='widefat'>" . stripslashes( esc_attr( $request ) ) . "</textarea>
@@ -977,6 +977,14 @@ class WPT_Normalizer
977
  /**
978
  * Functions to provide fallbacks for changed function names in case any plug-ins or themes are calling WP to Twitter functions in custom code.
979
  */
 
 
 
 
 
 
 
 
980
  function jd_twit_link( $link_ID ) {
981
  return wpt_twit_link( $link_ID );
982
  }
103
  $output = '';
104
  $default = ( get_option( 'wtt_twitter_username' ) == '' ) ? 'connection' : 'basic';
105
  $current = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : $default;
106
+ $pro_text = ( function_exists( 'wpt_pro_exists' ) ) ? __( 'Pro Settings', 'wp-to-twitter' ) : __( 'Get WP Tweets PRO', 'wp-to-twitter' );
107
  $pages = array(
108
  'connection'=> __( 'Twitter Connection', 'wp-to-twitter' ),
109
  'basic'=> __( 'Basic Settings', 'wp-to-twitter' ),
113
  'pro' => $pro_text
114
  );
115
  $pages = apply_filters( 'wpt_settings_tabs_pages', $pages, $current );
116
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
117
 
118
  foreach ( $pages as $key => $value ) {
119
  $selected = ( $key == $current ) ? " nav-tab-active" : '';
150
  delete_option( 'wp_url_failure' );
151
  }
152
  if ( get_option( 'wp_url_failure' ) == '1' ) {
153
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
154
  $nonce = wp_nonce_field( 'wp-to-twitter-nonce', '_wpnonce', true, false ) . wp_referer_field( false );
155
  $error = '<div class="error">' .
156
  __( "<p>The query to the URL shortener API failed, and your URL was not shrunk. The full post URL was attached to your Tweet. Check with your URL shortening provider to see if there are any known issues.</p>", 'wp-to-twitter' ) .
207
  }
208
  }
209
 
210
+ function wpt_remote_json( $url, $array = true, $method = 'GET' ) {
211
+ $input = wpt_fetch_url( $url, $method );
212
  $obj = json_decode( $input, $array );
213
  if ( function_exists( 'json_last_error' ) ) { // > PHP 5.3
214
  try {
254
  }
255
 
256
  // Fetch a remote page. Input url, return content
257
+ function wpt_fetch_url( $url, $method = 'GET', $body = '', $headers = '', $return = 'body' ) {
258
  $request = new WP_Http;
259
  $result = $request->request( $url, array( 'method' => $method,
260
  'body' => $body,
529
 
530
  function wpt_get_support_form() {
531
  global $current_user, $wpt_version;
532
+ $current_user = wp_get_current_user();
533
  $request = '';
534
  $response_email = '';
535
  // send fields for WP to Twitter
536
  $license = ( get_option( 'wpt_license_key' ) != '' ) ? get_option( 'wpt_license_key' ) : 'none';
537
+ if ( $license != 'none' ) {
538
+ $valid = ( ( get_option( 'wpt_license_valid' ) == 'true' ) || ( get_option( 'wpt_license_valid' ) == 'active' ) ) ? ' (active)' : ' (inactive)';
539
  } else {
540
  $valid = '';
541
  }
651
  } else {
652
  $checked = '';
653
  }
654
+ $admin_url = admin_url( 'admin.php?page=wp-tweets-pro' );
655
  $admin_url = add_query_arg( 'tab', 'support', $admin_url );
656
 
657
  echo "
674
  <input type='checkbox' name='has_read_faq' id='has_read_faq' value='on' required='required' aria-required='true' /> <label for='has_read_faq'>" . sprintf( __( 'I have read <a href="%1$s">the FAQ for this plug-in</a> <span>(required)</span>', 'wp-to-twitter' ), 'http://www.joedolson.com/wp-to-twitter/support-2/' ) . "
675
  </p>
676
  <p>
677
+ <input type='checkbox' name='has_donated' id='has_donated' value='on' $checked /> <label for='has_donated'>" . __( 'I made a donation or purchase to help support this plug-in', 'wp-to-twitter' ) . "</label>
678
  </p>
679
  <p>
680
  <label for='support_request'>" . __( 'Support Request:', 'wp-to-twitter' ) . "</label><br /><textarea class='support-request' name='support_request' id='support_request' cols='80' rows='10' class='widefat'>" . stripslashes( esc_attr( $request ) ) . "</textarea>
977
  /**
978
  * Functions to provide fallbacks for changed function names in case any plug-ins or themes are calling WP to Twitter functions in custom code.
979
  */
980
+ function jd_fetch_url( $url, $method = 'GET', $body = '', $headers = '', $return = 'body' ) {
981
+ return wpt_fetch_url( $url, $method, $body, $headers, $return );
982
+ }
983
+
984
+ function jd_remote_json( $url, $array = true ) {
985
+ return wpt_remote_json( $url, $array );
986
+ }
987
+
988
  function jd_twit_link( $link_ID ) {
989
  return wpt_twit_link( $link_ID );
990
  }
wpt-rate-limiting.php CHANGED
@@ -55,18 +55,23 @@ function wpt_test_rate_limit( $post_ID, $auth ) {
55
  return true;
56
  } else {
57
  $post = get_post( $post_ID );
58
- $post_type = $post->post_type;
59
- $object_taxonomies = get_object_taxonomies( $post_type );
60
- $terms = wp_get_object_terms( $post_ID, $object_taxonomies, array( 'fields' => 'all' ) );
61
-
62
- foreach( $terms as $term ) {
63
- $term_id = $term->term_id;
64
- $limit = wpt_get_rate_limit( $term_id );
65
- $tax = $term->taxonomy;
66
- $count = ( isset( $rate_limit[$auth][$term_id.'+'.$tax] ) ) ? count( $rate_limit[$auth][$term_id.'+'.$tax] ) : false;
67
- if ( $count && $count >= $limit ) {
68
- $return = false;
 
 
69
  }
 
 
 
70
  }
71
  }
72
 
55
  return true;
56
  } else {
57
  $post = get_post( $post_ID );
58
+ if ( is_object( $post ) ) {
59
+ $post_type = $post->post_type;
60
+ $object_taxonomies = get_object_taxonomies( $post_type );
61
+ $terms = wp_get_object_terms( $post_ID, $object_taxonomies, array( 'fields' => 'all' ) );
62
+
63
+ foreach( $terms as $term ) {
64
+ $term_id = $term->term_id;
65
+ $limit = wpt_get_rate_limit( $term_id );
66
+ $tax = $term->taxonomy;
67
+ $count = ( isset( $rate_limit[$auth][$term_id.'+'.$tax] ) ) ? count( $rate_limit[$auth][$term_id.'+'.$tax] ) : false;
68
+ if ( $count && $count >= $limit ) {
69
+ $return = false;
70
+ }
71
  }
72
+ } else {
73
+ // don't rate limit if no post
74
+ $return = true;
75
  }
76
  }
77
 
wpt-widget.php CHANGED
@@ -16,7 +16,7 @@ function wpt_get_user( $twitter_ID = false ) {
16
  $secret = get_option( 'app_consumer_secret' );
17
  $token = get_option( 'oauth_token' );
18
  $token_secret = get_option( 'oauth_token_secret' );
19
- $connection = new jd_TwitterOAuth( $key, $secret, $token, $token_secret );
20
  $result = $connection->get( "https://api.twitter.com/1.1/users/show.json?screen_name=$twitter_ID", $options );
21
 
22
  return json_decode( $result );
@@ -79,9 +79,11 @@ function wpt_twitter_feed( $instance ) {
79
  <span class='wpt-twitter-id'><a href='$follow_url'>@" . esc_html( $twitter_ID ) . "</a></span>
80
  </p>";
81
  $header .= '</div>';
 
 
82
  }
83
 
84
- $hide_header = ( $instance['hide_header'] == 1 ) ? true : false;
85
 
86
  if ( ! isset( $instance['search'] ) ) {
87
  $options['exclude_replies'] = ( isset( $instance['twitter_hide_replies'] ) ) ? $instance['twitter_hide_replies'] : false;
@@ -102,7 +104,7 @@ function wpt_twitter_feed( $instance ) {
102
  $opts['mentions'] = $instance['link_mentions'];
103
  $opts['hashtags'] = $instance['link_hashtags'];
104
  $opts['show_images'] = isset( $instance['show_images'] ) ? $instance['show_images'] : false;
105
- $rawtweets = WPT_getTweets( $instance['twitter_num'], $twitter_ID, $options );
106
 
107
  if ( isset( $rawtweets['error'] ) ) {
108
  $return .= "<li>" . $rawtweets['error'] . "</li>";
16
  $secret = get_option( 'app_consumer_secret' );
17
  $token = get_option( 'oauth_token' );
18
  $token_secret = get_option( 'oauth_token_secret' );
19
+ $connection = new wpt_TwitterOAuth( $key, $secret, $token, $token_secret );
20
  $result = $connection->get( "https://api.twitter.com/1.1/users/show.json?screen_name=$twitter_ID", $options );
21
 
22
  return json_decode( $result );
79
  <span class='wpt-twitter-id'><a href='$follow_url'>@" . esc_html( $twitter_ID ) . "</a></span>
80
  </p>";
81
  $header .= '</div>';
82
+ } else {
83
+ $twitter_ID = false;
84
  }
85
 
86
+ $hide_header = ( isset( $instance['hide_header'] ) && $instance['hide_header'] == 1 ) ? true : false;
87
 
88
  if ( ! isset( $instance['search'] ) ) {
89
  $options['exclude_replies'] = ( isset( $instance['twitter_hide_replies'] ) ) ? $instance['twitter_hide_replies'] : false;
104
  $opts['mentions'] = $instance['link_mentions'];
105
  $opts['hashtags'] = $instance['link_hashtags'];
106
  $opts['show_images'] = isset( $instance['show_images'] ) ? $instance['show_images'] : false;
107
+ $rawtweets = WPT_getTweets( $instance['twitter_num'], $twitter_ID, $options );
108
 
109
  if ( isset( $rawtweets['error'] ) ) {
110
  $return .= "<li>" . $rawtweets['error'] . "</li>";
wpt_twitter_oauth.php CHANGED
@@ -12,12 +12,12 @@ if ( ! defined( 'ABSPATH' ) ) {
12
 
13
  require_once( 'WP_OAuth.php' );
14
 
15
- if ( ! class_exists( 'jd_TwitterOAuth' ) ) {
16
 
17
  /**
18
  * Twitter WPOAuth class
19
  */
20
- class jd_TwitterOAuth {
21
  /* Contains the last HTTP status code returned */
22
  public $http_code;
23
  /* Contains the last API call. */
12
 
13
  require_once( 'WP_OAuth.php' );
14
 
15
+ if ( ! class_exists( 'wpt_TwitterOAuth' ) ) {
16
 
17
  /**
18
  * Twitter WPOAuth class
19
  */
20
+ class wpt_TwitterOAuth {
21
  /* Contains the last HTTP status code returned */
22
  public $http_code;
23
  /* Contains the last API call. */