Meta Tag Manager - Version 2.0

Version Description

  • complete rewrite of plugin using up-to-date WP best practices
  • improved interface for adding meta tags including support for creating tags using either the property, charset, http-equiv or itemprop attributes
  • added ability to add individual meta tags to specific individual CPTs which can be chosen in settings page
Download this release

Release Info

Developer netweblogic
Plugin Icon 128x128 Meta Tag Manager
Version 2.0
Comparing to
See all releases

Code changes from version 1.2 to 2.0

Files changed (125) hide show
  1. css/meta-tag-manager.css +474 -0
  2. css/meta-tag-manager.less +2 -0
  3. css/meta-tag-manager.min.css +1 -0
  4. css/selectize.css +301 -0
  5. css/selectize/plugins/drag_drop.less +16 -0
  6. css/selectize/plugins/dropdown_header.less +20 -0
  7. css/selectize/plugins/optgroup_columns.less +17 -0
  8. css/selectize/plugins/remove_button.less +37 -0
  9. css/selectize/selectize.less +295 -0
  10. freemius/LICENSE.txt +340 -0
  11. freemius/README.md +250 -0
  12. freemius/assets/css/admin/account.css +1 -0
  13. freemius/assets/css/admin/add-ons.css +2 -0
  14. freemius/assets/css/admin/common.css +1 -0
  15. freemius/assets/css/admin/connect.css +1 -0
  16. freemius/assets/css/admin/deactivation-feedback.css +1 -0
  17. freemius/assets/css/admin/debug.css +1 -0
  18. freemius/assets/css/common.css +1 -0
  19. freemius/assets/img/meta-tag-manager.png +0 -0
  20. freemius/assets/img/plugin-icon.png +0 -0
  21. freemius/assets/js/jquery.ba-postmessage.js +222 -0
  22. freemius/assets/js/jquery.ba-postmessage.min.js +9 -0
  23. freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  24. freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  25. freemius/assets/js/postmessage.js +110 -0
  26. freemius/assets/scss/_colors.scss +58 -0
  27. freemius/assets/scss/_functions.scss +0 -0
  28. freemius/assets/scss/_load.scss +4 -0
  29. freemius/assets/scss/_mixins.scss +224 -0
  30. freemius/assets/scss/_start.scss +4 -0
  31. freemius/assets/scss/_vars.scss +5 -0
  32. freemius/assets/scss/admin/account.scss +171 -0
  33. freemius/assets/scss/admin/add-ons.scss +449 -0
  34. freemius/assets/scss/admin/common.scss +134 -0
  35. freemius/assets/scss/admin/connect.scss +421 -0
  36. freemius/assets/scss/admin/deactivation-feedback.scss +120 -0
  37. freemius/assets/scss/admin/debug.scss +91 -0
  38. freemius/composer.json +10 -0
  39. freemius/config.php +229 -0
  40. freemius/includes/class-freemius-abstract.php +404 -0
  41. freemius/includes/class-freemius.php +9452 -0
  42. freemius/includes/class-fs-api.php +455 -0
  43. freemius/includes/class-fs-logger.php +179 -0
  44. freemius/includes/class-fs-plugin-updater.php +334 -0
  45. freemius/includes/class-fs-security.php +61 -0
  46. freemius/includes/debug/class-fs-debug-bar-panel.php +64 -0
  47. freemius/includes/debug/debug-bar-start.php +52 -0
  48. freemius/includes/entities/class-fs-entity.php +149 -0
  49. freemius/includes/entities/class-fs-plugin-info.php +34 -0
  50. freemius/includes/entities/class-fs-plugin-license.php +172 -0
  51. freemius/includes/entities/class-fs-plugin-plan.php +124 -0
  52. freemius/includes/entities/class-fs-plugin-tag.php +24 -0
  53. freemius/includes/entities/class-fs-plugin.php +90 -0
  54. freemius/includes/entities/class-fs-pricing.php +141 -0
  55. freemius/includes/entities/class-fs-scope-entity.php +29 -0
  56. freemius/includes/entities/class-fs-site.php +127 -0
  57. freemius/includes/entities/class-fs-subscription.php +125 -0
  58. freemius/includes/entities/class-fs-user.php +62 -0
  59. freemius/includes/fs-core-functions.php +441 -0
  60. freemius/includes/fs-essential-functions.php +412 -0
  61. freemius/includes/fs-plugin-info-dialog.php +936 -0
  62. freemius/includes/i18n.php +352 -0
  63. freemius/includes/managers/class-fs-admin-menu-manager.php +549 -0
  64. freemius/includes/managers/class-fs-admin-notice-manager.php +310 -0
  65. freemius/includes/managers/class-fs-cache-manager.php +237 -0
  66. freemius/includes/managers/class-fs-key-value-storage.php +295 -0
  67. freemius/includes/managers/class-fs-license-manager.php +101 -0
  68. freemius/includes/managers/class-fs-option-manager.php +302 -0
  69. freemius/includes/managers/class-fs-plan-manager.php +162 -0
  70. freemius/includes/managers/class-fs-plugin-manager.php +154 -0
  71. freemius/includes/sdk/Exceptions/ArgumentNotExistException.php +6 -0
  72. freemius/includes/sdk/Exceptions/EmptyArgumentException.php +6 -0
  73. freemius/includes/sdk/Exceptions/Exception.php +75 -0
  74. freemius/includes/sdk/Exceptions/InvalidArgumentException.php +6 -0
  75. freemius/includes/sdk/Exceptions/OAuthException.php +12 -0
  76. freemius/includes/sdk/Freemius.php +574 -0
  77. freemius/includes/sdk/FreemiusBase.php +178 -0
  78. freemius/includes/sdk/LICENSE.txt +340 -0
  79. freemius/includes/supplements/fs-essential-functions-1.1.7.1.php +45 -0
  80. freemius/start.php +341 -0
  81. freemius/templates/account.php +625 -0
  82. freemius/templates/add-ons.php +144 -0
  83. freemius/templates/admin-notice.php +46 -0
  84. freemius/templates/all-admin-notice.php +35 -0
  85. freemius/templates/checkout.php +260 -0
  86. freemius/templates/connect.php +200 -0
  87. freemius/templates/contact.php +77 -0
  88. freemius/templates/deactivation-feedback-modal.php +282 -0
  89. freemius/templates/debug.php +250 -0
  90. freemius/templates/debug/api-calls.php +138 -0
  91. freemius/templates/debug/logger.php +60 -0
  92. freemius/templates/debug/plugins-themes-sync.php +68 -0
  93. freemius/templates/debug/scheduled-crons.php +100 -0
  94. freemius/templates/email.php +46 -0
  95. freemius/templates/firewall-issues-js.php +60 -0
  96. freemius/templates/plugin-icon.php +93 -0
  97. freemius/templates/plugin-info/description.php +75 -0
  98. freemius/templates/plugin-info/features.php +97 -0
  99. freemius/templates/plugin-info/screenshots.php +33 -0
  100. freemius/templates/powered-by.php +41 -0
  101. freemius/templates/pricing.php +100 -0
  102. freemius/templates/sticky-admin-notice-js.php +40 -0
  103. js/meta-tag-manager-settings.js +48 -0
  104. js/meta-tag-manager.js +155 -0
  105. js/selectize.js +3667 -0
  106. js/selectize.min.js +3 -0
  107. meta-tag-manager-da_DK.mo → languages/meta-tag-manager-da_DK.mo +0 -0
  108. meta-tag-manager-da_DK.po → languages/meta-tag-manager-da_DK.po +0 -0
  109. meta-tag-manager-de_DE.mo → languages/meta-tag-manager-de_DE.mo +0 -0
  110. meta-tag-manager-de_DE.po → languages/meta-tag-manager-de_DE.po +0 -0
  111. meta-tag-manager-es_ES.mo → languages/meta-tag-manager-es_ES.mo +0 -0
  112. meta-tag-manager-es_ES.po → languages/meta-tag-manager-es_ES.po +0 -0
  113. meta-tag-manager-nl_NL.mo → languages/meta-tag-manager-nl_NL.mo +0 -0
  114. meta-tag-manager-nl_NL.po → languages/meta-tag-manager-nl_NL.po +0 -0
  115. meta-tag-manager-admin.php +72 -113
  116. meta-tag-manager.php +133 -29
  117. meta-tag-manager.pot +0 -64
  118. mtm-admin-settings.php +111 -0
  119. mtm-builder.php +246 -0
  120. mtm-tag-admin.php +50 -0
  121. mtm-tag.php +71 -0
  122. mtm-update.php +26 -0
  123. mtm_script.js +0 -68
  124. readme.txt +27 -25
  125. screenshot-1.jpg +0 -0
css/meta-tag-manager.css ADDED
@@ -0,0 +1,474 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* .mtm.postbox { background-color:#dedede;} */
2
+ .mtm-menu-builder { margin-bottom:15px; }
3
+ .mtm-builder {}
4
+
5
+ .mtm-field-template { display:none; visibility:hidden; }
6
+ .mtm-fields {}
7
+
8
+ .mtm-field-placeholder {
9
+ width:100%;
10
+ border:1px dashed #aaa;
11
+ background-color: #ddd;
12
+ font-size:18px;
13
+ padding:30px 0px;
14
+ color:#555;
15
+ text-align:center;
16
+ margin:10px 0px;
17
+ cursor:pointer;
18
+ }
19
+ .no-reference.no-context .mtm-field-placeholder { padding:20px 0px; }
20
+
21
+ .mtm-field {
22
+ display:block;
23
+ clear:both;
24
+ width:100%;
25
+ border: 1px solid #c3c3c3;
26
+ background-color: #fff;
27
+ margin:10px 0px;
28
+ }
29
+ .mtm-field.closed .mtm-field-data { display:none; visibility:hidden; }
30
+
31
+ .mtm-field .mtm-field-actions { clear:both; }
32
+
33
+ /* Field Header / Title section */
34
+ .mtm-field-header {
35
+ padding: 10px 0px;
36
+ cursor:pointer;
37
+ }
38
+ .mtm-col-sort {
39
+ display:block;
40
+ float:left;
41
+ width:20px;
42
+ height:20px;
43
+ padding:10px 0px 0px 10px;
44
+ margin:0px;
45
+ font-size:20px;
46
+ align:center;
47
+ cursor:move;
48
+ color:#dedede
49
+ }
50
+ .no-reference.no-context .mtm-col-sort { padding:0px 0px 0px 10px;}
51
+
52
+ /* Display Title for each Card */
53
+ .mtm-field-title { margin-left:40px; min-height:50px;}
54
+ .no-reference.no-context .mtm-field-title { min-height:20px; }
55
+ .mtm-field-title .mtm-meta-reference { font-size: 18px; padding-bottom:5px; }
56
+ .mtm-field-title .mtm-meta-reference-value { display: inline-block; }
57
+
58
+ .mtm-field-title .mtm-meta-context {
59
+ font-size:12px;
60
+ padding-bottom:3px;
61
+ color:#bcbcbc;
62
+ font-weight:bold;
63
+ font-style:italic;
64
+ }
65
+ .mtm-field-title .mtm-meta-context .dashicons { font-size:15px; }
66
+
67
+ .mtm-field-title code { font-weight:bold; }
68
+ .mtm-field-title code .mtm-meta-type-val, .mtm-field-title code .mtm-meta-content-value {
69
+ font-style:italic;
70
+ font-weight:normal;
71
+ background-color:#fefefe;
72
+ }
73
+ .mtm-field-title code .mtm-meta-content.hidden { display:none; }
74
+
75
+ /* Header toggles */
76
+ .mtm-field-header-toggle:hover,
77
+ .mtm-field-section-toggle:hover {
78
+ cursor:pointer;
79
+ }
80
+ .mtm-field-header-toggle:before,
81
+ .mtm-field-section-toggle:before {
82
+ float:right;
83
+ width: 32px;
84
+ height: 32px;
85
+ content: "\f142";
86
+ display: inline-block;
87
+ font: normal 20px/1 dashicons;
88
+ speak: none;
89
+ -webkit-font-smoothing: antialiased;
90
+ -moz-osx-font-smoothing: grayscale;
91
+ text-decoration: none !important;
92
+ }
93
+ .mtm-field.closed .mtm-field-header-toggle:before {
94
+ content: "\f140";
95
+ }
96
+
97
+ /* Field form data */
98
+ .mtm-field-data {
99
+ /* display: none; */
100
+ border-top: 1px solid #e5e5e5;
101
+ padding:10px 10px 15px;
102
+ }
103
+ .mtm-field-input { margin:0px 0px 15px 0px; clear:both; }
104
+ .mtm-field-input-label {
105
+ display:inline-block;
106
+ margin-bottom:3px;
107
+ padding:2px;
108
+ font-weight:bold;
109
+ display:block;
110
+ }
111
+ .mtm-field-input-label em { font-style:normal; background:#eaeaea; padding:1px 2px; }
112
+ .mtm-field-input input, .mtm-field-input select {
113
+ width:100%;
114
+ padding:4px;
115
+ font-size:13px; /* matches selectize */
116
+ }
117
+
118
+ .mtm-field-type-custom { clear:both; }
119
+ .mtm-field-type-custom > div {
120
+ clear:none;
121
+ float:left;
122
+ width:48%;
123
+ margin:10px 1%;
124
+ }
125
+
126
+ /* Specific type field selectors */
127
+ .mtm-field-input.mtm-field-type-type {
128
+ width:20%;
129
+ float:left;
130
+ clear:none;
131
+ }
132
+ .mtm-field-input.mtm-field-type-value {
133
+ width:79% !important;
134
+ margin-left: 21%;
135
+ clear:none;
136
+ }
137
+ .mtm-field-input input.mtm-field-input-tag-value { float:left; clear:none; }
138
+
139
+
140
+
141
+ .mtm-field-section { margin-top:20px; }
142
+ .mtm-field-section-header { border-bottom:1px solid #e3e3e3; padding-bottom:10px; }
143
+ .mtm-field-section-title { font-weight:bold; font-size:15px; }
144
+ .mtm-field-section-data { margin:10px 10px 20px; padding-bottom:10px; border-bottom:1px solid #e3e3e3; }
145
+
146
+ /*.mtm-builder .selectize-input { padding:4px; }*/
147
+ .mtm-settings .selectize-dropdown-content .optgroup .option { padding-left:10px; }
148
+ .mtm-settings .selectize-dropdown-content .optgroup .optgroup-header { font-weight:bold; }
149
+ .mtm-settings .selectize-control.multi .selectize-input > div { background:#5cb85c; border-color:#4cae4c; color:#fff; }
150
+ .mtm-settings .selectize-control.multi .selectize-input > div .remove { border-color:#4cae4c; }
151
+
152
+ .mtm-builder .mtm-field button.mtm-field-remove { background-color:#f4e3e3; border-color:#d8c5c5; color:#565656; }
153
+ .mtm-builder .mtm-field a.mtm-field-remove { cursor:pointer; color:#d66b6b; }
154
+ .mtm-builder button .dashicons { padding: 3px 0px; margin-left: -5px; color: #888; }
155
+ .mtm-builder button.mtm-add-field .dashicons { padding: 4px 0px; }
156
+
157
+ .mtm-builder .mtm-actions { padding-top:15px; }
158
+ /**
159
+ * selectize.css (v0.12.1)
160
+ * Copyright (c) 2013�2015 Brian Reavis & contributors
161
+ *
162
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
163
+ * file except in compliance with the License. You may obtain a copy of the License at:
164
+ * http://www.apache.org/licenses/LICENSE-2.0
165
+ *
166
+ * Unless required by applicable law or agreed to in writing, software distributed under
167
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
168
+ * ANY KIND, either express or implied. See the License for the specific language
169
+ * governing permissions and limitations under the License.
170
+ *
171
+ * @author Brian Reavis <brian@thirdroute.com>
172
+ */
173
+ .selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder {
174
+ visibility: visible !important;
175
+ background: #f2f2f2 !important;
176
+ background: rgba(0, 0, 0, 0.06) !important;
177
+ border: 0 none !important;
178
+ -webkit-box-shadow: inset 0 0 12px 4px #ffffff;
179
+ box-shadow: inset 0 0 12px 4px #ffffff;
180
+ }
181
+ .selectize-control.plugin-drag_drop .ui-sortable-placeholder::after {
182
+ content: '!';
183
+ visibility: hidden;
184
+ }
185
+ .selectize-control.plugin-drag_drop .ui-sortable-helper {
186
+ -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
187
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
188
+ }
189
+ .selectize-dropdown-header {
190
+ position: relative;
191
+ padding: 5px 4px;
192
+ border-bottom: 1px solid #d0d0d0;
193
+ background: #f8f8f8;
194
+ -webkit-border-radius: 3px 3px 0 0;
195
+ -moz-border-radius: 3px 3px 0 0;
196
+ border-radius: 3px 3px 0 0;
197
+ }
198
+ .selectize-dropdown-header-close {
199
+ position: absolute;
200
+ right: 4px;
201
+ top: 50%;
202
+ color: #303030;
203
+ opacity: 0.4;
204
+ margin-top: -12px;
205
+ line-height: 20px;
206
+ font-size: 20px !important;
207
+ }
208
+ .selectize-dropdown-header-close:hover {
209
+ color: #000000;
210
+ }
211
+ .selectize-dropdown.plugin-optgroup_columns .optgroup {
212
+ border-right: 1px solid #f2f2f2;
213
+ border-top: 0 none;
214
+ float: left;
215
+ -webkit-box-sizing: border-box;
216
+ -moz-box-sizing: border-box;
217
+ box-sizing: border-box;
218
+ }
219
+ .selectize-dropdown.plugin-optgroup_columns .optgroup:last-child {
220
+ border-right: 0 none;
221
+ }
222
+ .selectize-dropdown.plugin-optgroup_columns .optgroup:before {
223
+ display: none;
224
+ }
225
+ .selectize-dropdown.plugin-optgroup_columns .optgroup-header {
226
+ border-top: 0 none;
227
+ }
228
+ .selectize-control.plugin-remove_button [data-value] {
229
+ position: relative;
230
+ padding-right: 24px !important;
231
+ }
232
+ .selectize-control.plugin-remove_button [data-value] .remove {
233
+ z-index: 1;
234
+ /* fixes ie bug (see #392) */
235
+ position: absolute;
236
+ top: 0;
237
+ right: 0;
238
+ bottom: 0;
239
+ width: 17px;
240
+ text-align: center;
241
+ font-weight: bold;
242
+ font-size: 12px;
243
+ color: inherit;
244
+ text-decoration: none;
245
+ vertical-align: middle;
246
+ display: inline-block;
247
+ padding: 2px 0 0 0;
248
+ border-left: 1px solid #d0d0d0;
249
+ -webkit-border-radius: 0 2px 2px 0;
250
+ -moz-border-radius: 0 2px 2px 0;
251
+ border-radius: 0 2px 2px 0;
252
+ -webkit-box-sizing: border-box;
253
+ -moz-box-sizing: border-box;
254
+ box-sizing: border-box;
255
+ }
256
+ .selectize-control.plugin-remove_button [data-value] .remove:hover {
257
+ background: rgba(0, 0, 0, 0.05);
258
+ }
259
+ .selectize-control.plugin-remove_button [data-value].active .remove {
260
+ border-left-color: #cacaca;
261
+ }
262
+ .selectize-control.plugin-remove_button .disabled [data-value] .remove:hover {
263
+ background: none;
264
+ }
265
+ .selectize-control.plugin-remove_button .disabled [data-value] .remove {
266
+ border-left-color: #ffffff;
267
+ }
268
+ .selectize-control {
269
+ position: relative;
270
+ }
271
+ .selectize-dropdown,
272
+ .selectize-input,
273
+ .selectize-input input {
274
+ color: #303030;
275
+ font-family: inherit;
276
+ font-size: 13px;
277
+ line-height: 18px;
278
+ -webkit-font-smoothing: inherit;
279
+ }
280
+ .selectize-input,
281
+ .selectize-control.single .selectize-input.input-active {
282
+ background: #ffffff;
283
+ cursor: text;
284
+ display: inline-block;
285
+ }
286
+ .selectize-input {
287
+ border: 1px solid #d0d0d0;
288
+ padding: 4px 4px;
289
+ display: inline-block;
290
+ width: 100%;
291
+ overflow: hidden;
292
+ position: relative;
293
+ z-index: 1;
294
+ -webkit-box-sizing: border-box;
295
+ -moz-box-sizing: border-box;
296
+ box-sizing: border-box;
297
+ -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
298
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
299
+ -webkit-border-radius: 3px;
300
+ -moz-border-radius: 3px;
301
+ border-radius: 3px;
302
+ }
303
+ .selectize-control.multi .selectize-input.has-items {
304
+ padding: 2px 4px -1px;
305
+ }
306
+ .selectize-input.full {
307
+ background-color: #ffffff;
308
+ }
309
+ .selectize-input.disabled,
310
+ .selectize-input.disabled * {
311
+ cursor: default !important;
312
+ }
313
+ .selectize-input.focus {
314
+ -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
315
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
316
+ }
317
+ .selectize-input.dropdown-active {
318
+ -webkit-border-radius: 3px 3px 0 0;
319
+ -moz-border-radius: 3px 3px 0 0;
320
+ border-radius: 3px 3px 0 0;
321
+ }
322
+ .selectize-input > * {
323
+ vertical-align: baseline;
324
+ display: -moz-inline-stack;
325
+ display: inline-block;
326
+ zoom: 1;
327
+ *display: inline;
328
+ }
329
+ .selectize-control.multi .selectize-input > div {
330
+ cursor: pointer;
331
+ margin: 0 3px 3px 0;
332
+ padding: 2px 6px;
333
+ background: #f2f2f2;
334
+ color: #303030;
335
+ border: 0 solid #d0d0d0;
336
+ }
337
+ .selectize-control.multi .selectize-input > div.active {
338
+ background: #e8e8e8;
339
+ color: #303030;
340
+ border: 0 solid #cacaca;
341
+ }
342
+ .selectize-control.multi .selectize-input.disabled > div,
343
+ .selectize-control.multi .selectize-input.disabled > div.active {
344
+ color: #7d7d7d;
345
+ background: #ffffff;
346
+ border: 0 solid #ffffff;
347
+ }
348
+ .selectize-input > input {
349
+ display: inline-block !important;
350
+ padding: 0 !important;
351
+ min-height: 0 !important;
352
+ max-height: none !important;
353
+ max-width: 100% !important;
354
+ margin: 0 2px 0 0 !important;
355
+ text-indent: 0 !important;
356
+ border: 0 none !important;
357
+ background: none !important;
358
+ line-height: inherit !important;
359
+ -webkit-user-select: auto !important;
360
+ -webkit-box-shadow: none !important;
361
+ box-shadow: none !important;
362
+ }
363
+ .selectize-input > input::-ms-clear {
364
+ display: none;
365
+ }
366
+ .selectize-input > input:focus {
367
+ outline: none !important;
368
+ }
369
+ .selectize-input::after {
370
+ content: ' ';
371
+ display: block;
372
+ clear: left;
373
+ }
374
+ .selectize-input.dropdown-active::before {
375
+ content: ' ';
376
+ display: block;
377
+ position: absolute;
378
+ background: #f0f0f0;
379
+ height: 1px;
380
+ bottom: 0;
381
+ left: 0;
382
+ right: 0;
383
+ }
384
+ .selectize-dropdown {
385
+ position: absolute;
386
+ z-index: 10;
387
+ border: 1px solid #d0d0d0;
388
+ background: #ffffff;
389
+ margin: -1px 0 0 0;
390
+ border-top: 0 none;
391
+ -webkit-box-sizing: border-box;
392
+ -moz-box-sizing: border-box;
393
+ box-sizing: border-box;
394
+ -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
395
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
396
+ -webkit-border-radius: 0 0 3px 3px;
397
+ -moz-border-radius: 0 0 3px 3px;
398
+ border-radius: 0 0 3px 3px;
399
+ }
400
+ .selectize-dropdown [data-selectable] {
401
+ cursor: pointer;
402
+ overflow: hidden;
403
+ }
404
+ .selectize-dropdown [data-selectable] .highlight {
405
+ background: rgba(125, 168, 208, 0.2);
406
+ -webkit-border-radius: 1px;
407
+ -moz-border-radius: 1px;
408
+ border-radius: 1px;
409
+ }
410
+ .selectize-dropdown [data-selectable],
411
+ .selectize-dropdown .optgroup-header {
412
+ padding: 5px 4px;
413
+ }
414
+ .selectize-dropdown .optgroup:first-child .optgroup-header {
415
+ border-top: 0 none;
416
+ }
417
+ .selectize-dropdown .optgroup-header {
418
+ color: #303030;
419
+ background: #ffffff;
420
+ cursor: default;
421
+ }
422
+ .selectize-dropdown .active {
423
+ background-color: #f5fafd;
424
+ color: #495c68;
425
+ }
426
+ .selectize-dropdown .active.create {
427
+ color: #495c68;
428
+ }
429
+ .selectize-dropdown .create {
430
+ color: rgba(48, 48, 48, 0.5);
431
+ }
432
+ .selectize-dropdown-content {
433
+ overflow-y: auto;
434
+ overflow-x: hidden;
435
+ max-height: 200px;
436
+ }
437
+ .selectize-control.single .selectize-input,
438
+ .selectize-control.single .selectize-input input {
439
+ cursor: pointer;
440
+ }
441
+ .selectize-control.single .selectize-input.input-active,
442
+ .selectize-control.single .selectize-input.input-active input {
443
+ cursor: text;
444
+ }
445
+ .selectize-control.single .selectize-input:after {
446
+ content: ' ';
447
+ display: block;
448
+ position: absolute;
449
+ top: 50%;
450
+ right: 15px;
451
+ margin-top: -3px;
452
+ width: 0;
453
+ height: 0;
454
+ border-style: solid;
455
+ border-width: 5px 5px 0 5px;
456
+ border-color: #808080 transparent transparent transparent;
457
+ }
458
+ .selectize-control.single .selectize-input.dropdown-active:after {
459
+ margin-top: -4px;
460
+ border-width: 0 5px 5px 5px;
461
+ border-color: transparent transparent #808080 transparent;
462
+ }
463
+ .selectize-control.rtl.single .selectize-input:after {
464
+ left: 15px;
465
+ right: auto;
466
+ }
467
+ .selectize-control.rtl .selectize-input > input {
468
+ margin: 0 4px 0 -2px !important;
469
+ }
470
+ .selectize-control .selectize-input.disabled {
471
+ opacity: 0.5;
472
+ background-color: #fafafa;
473
+ }
474
+
css/meta-tag-manager.less ADDED
@@ -0,0 +1,2 @@
 
 
1
+ @import (inline) "meta-tag-manager.css";
2
+ @import (inline) "selectize.css";
css/meta-tag-manager.min.css ADDED
@@ -0,0 +1 @@
 
1
+ .mtm-menu-builder{margin-bottom:15px}.mtm-field-template{display:none;visibility:hidden}.mtm-field-placeholder{width:100%;border:1px dashed #aaa;background-color:#ddd;font-size:18px;padding:30px 0;color:#555;text-align:center;margin:10px 0;cursor:pointer}.no-reference.no-context .mtm-field-placeholder{padding:20px 0}.mtm-field{display:block;clear:both;width:100%;border:1px solid #c3c3c3;background-color:#fff;margin:10px 0}.mtm-field.closed .mtm-field-data{display:none;visibility:hidden}.mtm-field .mtm-field-actions{clear:both}.mtm-field-header{padding:10px 0;cursor:pointer}.mtm-col-sort{display:block;float:left;width:20px;height:20px;padding:10px 0 0 10px;margin:0;font-size:20px;align:center;cursor:move;color:#dedede}.no-reference.no-context .mtm-col-sort{padding:0 0 0 10px}.mtm-field-title{margin-left:40px;min-height:50px}.no-reference.no-context .mtm-field-title{min-height:20px}.mtm-field-title .mtm-meta-reference{font-size:18px;padding-bottom:5px}.mtm-field-title .mtm-meta-reference-value{display:inline-block}.mtm-field-title .mtm-meta-context{font-size:12px;padding-bottom:3px;color:#bcbcbc;font-weight:700;font-style:italic}.mtm-field-title .mtm-meta-context .dashicons{font-size:15px}.mtm-field-title code{font-weight:700}.mtm-field-title code .mtm-meta-content-value,.mtm-field-title code .mtm-meta-type-val{font-style:italic;font-weight:400;background-color:#fefefe}.mtm-field-title code .mtm-meta-content.hidden{display:none}.mtm-field-header-toggle:hover,.mtm-field-section-toggle:hover{cursor:pointer}.mtm-field-header-toggle:before,.mtm-field-section-toggle:before{float:right;width:32px;height:32px;content:"\f142";display:inline-block;font:400 20px/1 dashicons;speak:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none!important}.mtm-field.closed .mtm-field-header-toggle:before{content:"\f140"}.mtm-field-data{border-top:1px solid #e5e5e5;padding:10px 10px 15px}.mtm-field-input{margin:0 0 15px;clear:both}.mtm-field-input-label{margin-bottom:3px;padding:2px;font-weight:700;display:block}.mtm-field-input-label em{font-style:normal;background:#eaeaea;padding:1px 2px}.mtm-field-input input,.mtm-field-input select{width:100%;padding:4px;font-size:13px}.mtm-field-type-custom{clear:both}.mtm-field-type-custom>div{clear:none;float:left;width:48%;margin:10px 1%}.mtm-field-input.mtm-field-type-type{width:20%;float:left;clear:none}.mtm-field-input.mtm-field-type-value{width:79%!important;margin-left:21%;clear:none}.mtm-field-input input.mtm-field-input-tag-value{float:left;clear:none}.mtm-field-section{margin-top:20px}.mtm-field-section-header{border-bottom:1px solid #e3e3e3;padding-bottom:10px}.mtm-field-section-title{font-weight:700;font-size:15px}.mtm-field-section-data{margin:10px 10px 20px;padding-bottom:10px;border-bottom:1px solid #e3e3e3}.mtm-settings .selectize-dropdown-content .optgroup .option{padding-left:10px}.mtm-settings .selectize-dropdown-content .optgroup .optgroup-header{font-weight:700}.mtm-settings .selectize-control.multi .selectize-input>div{background:#5cb85c;border-color:#4cae4c;color:#fff}.mtm-settings .selectize-control.multi .selectize-input>div .remove{border-color:#4cae4c}.mtm-builder .mtm-field button.mtm-field-remove{background-color:#f4e3e3;border-color:#d8c5c5;color:#565656}.mtm-builder .mtm-field a.mtm-field-remove{cursor:pointer;color:#d66b6b}.mtm-builder button .dashicons{padding:3px 0;margin-left:-5px;color:#888}.mtm-builder button.mtm-add-field .dashicons{padding:4px 0}.mtm-builder .mtm-actions{padding-top:15px}.selectize-control.plugin-drag_drop.multi>.selectize-input>div.ui-sortable-placeholder{visibility:visible!important;background:#f2f2f2!important;background:rgba(0,0,0,.06)!important;border:0!important;-webkit-box-shadow:inset 0 0 12px 4px #fff;box-shadow:inset 0 0 12px 4px #fff}.selectize-control.plugin-drag_drop .ui-sortable-placeholder::after{content:'!';visibility:hidden}.selectize-control.plugin-drag_drop .ui-sortable-helper{-webkit-box-shadow:0 2px 5px rgba(0,0,0,.2);box-shadow:0 2px 5px rgba(0,0,0,.2)}.selectize-dropdown-header{position:relative;padding:5px 4px;border-bottom:1px solid #d0d0d0;background:#f8f8f8;-webkit-border-radius:3px 3px 0 0;-moz-border-radius:3px 3px 0 0;border-radius:3px 3px 0 0}.selectize-dropdown-header-close{position:absolute;right:4px;top:50%;color:#303030;opacity:.4;margin-top:-12px;line-height:20px;font-size:20px!important}.selectize-dropdown-header-close:hover{color:#000}.selectize-dropdown.plugin-optgroup_columns .optgroup{border-right:1px solid #f2f2f2;border-top:0 none;float:left;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.selectize-dropdown.plugin-optgroup_columns .optgroup:last-child{border-right:0 none}.selectize-dropdown.plugin-optgroup_columns .optgroup:before{display:none}.selectize-dropdown.plugin-optgroup_columns .optgroup-header{border-top:0 none}.selectize-control.plugin-remove_button [data-value]{position:relative;padding-right:24px!important}.selectize-control.plugin-remove_button [data-value] .remove{z-index:1;position:absolute;top:0;right:0;bottom:0;width:17px;text-align:center;font-weight:700;font-size:12px;color:inherit;text-decoration:none;vertical-align:middle;display:inline-block;padding:2px 0 0;border-left:1px solid #d0d0d0;-webkit-border-radius:0 2px 2px 0;-moz-border-radius:0 2px 2px 0;border-radius:0 2px 2px 0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.selectize-control.plugin-remove_button [data-value] .remove:hover{background:rgba(0,0,0,.05)}.selectize-control.plugin-remove_button [data-value].active .remove{border-left-color:#cacaca}.selectize-control.plugin-remove_button .disabled [data-value] .remove:hover{background:0 0}.selectize-control.plugin-remove_button .disabled [data-value] .remove{border-left-color:#fff}.selectize-control{position:relative}.selectize-dropdown,.selectize-input,.selectize-input input{color:#303030;font-family:inherit;font-size:13px;line-height:18px;-webkit-font-smoothing:inherit}.selectize-control.single .selectize-input.input-active,.selectize-input{background:#fff;display:inline-block}.selectize-input{border:1px solid #d0d0d0;padding:4px;display:inline-block;width:100%;overflow:hidden;position:relative;z-index:1;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.1);box-shadow:inset 0 1px 1px rgba(0,0,0,.1);-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px}.selectize-control.multi .selectize-input.has-items{padding:2px 4px -1px}.selectize-input.full{background-color:#fff}.selectize-input.disabled,.selectize-input.disabled *{cursor:default!important}.selectize-input.focus{-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.15);box-shadow:inset 0 1px 2px rgba(0,0,0,.15)}.selectize-input.dropdown-active{-webkit-border-radius:3px 3px 0 0;-moz-border-radius:3px 3px 0 0;border-radius:3px 3px 0 0}.selectize-input>*{vertical-align:baseline;display:-moz-inline-stack;display:inline-block;zoom:1;*display:inline}.selectize-control.multi .selectize-input>div{cursor:pointer;margin:0 3px 3px 0;padding:2px 6px;background:#f2f2f2;color:#303030;border:0 solid #d0d0d0}.selectize-control.multi .selectize-input>div.active{background:#e8e8e8;color:#303030;border:0 solid #cacaca}.selectize-control.multi .selectize-input.disabled>div,.selectize-control.multi .selectize-input.disabled>div.active{color:#7d7d7d;background:#fff;border:0 solid #fff}.selectize-input>input{display:inline-block!important;padding:0!important;min-height:0!important;max-height:none!important;max-width:100%!important;margin:0 2px 0 0!important;text-indent:0!important;border:0!important;background:0 0!important;line-height:inherit!important;-webkit-user-select:auto!important;-webkit-box-shadow:none!important;box-shadow:none!important}.selectize-input>input::-ms-clear{display:none}.selectize-input>input:focus{outline:0!important}.selectize-input::after{content:' ';display:block;clear:left}.selectize-input.dropdown-active::before{content:' ';display:block;position:absolute;background:#f0f0f0;height:1px;bottom:0;left:0;right:0}.selectize-dropdown{position:absolute;z-index:10;border:1px solid #d0d0d0;background:#fff;margin:-1px 0 0;border-top:0 none;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.1);box-shadow:0 1px 3px rgba(0,0,0,.1);-webkit-border-radius:0 0 3px 3px;-moz-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px}.selectize-dropdown [data-selectable]{cursor:pointer;overflow:hidden}.selectize-dropdown [data-selectable] .highlight{background:rgba(125,168,208,.2);-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:1px}.selectize-dropdown .optgroup-header,.selectize-dropdown [data-selectable]{padding:5px 4px}.selectize-dropdown .optgroup:first-child .optgroup-header{border-top:0 none}.selectize-dropdown .optgroup-header{color:#303030;background:#fff;cursor:default}.selectize-dropdown .active{background-color:#f5fafd;color:#495c68}.selectize-dropdown .active.create{color:#495c68}.selectize-dropdown .create{color:rgba(48,48,48,.5)}.selectize-dropdown-content{overflow-y:auto;overflow-x:hidden;max-height:200px}.selectize-control.single .selectize-input,.selectize-control.single .selectize-input input{cursor:pointer}.selectize-control.single .selectize-input.input-active,.selectize-control.single .selectize-input.input-active input{cursor:text}.selectize-control.single .selectize-input:after{content:' ';display:block;position:absolute;top:50%;right:15px;margin-top:-3px;width:0;height:0;border-style:solid;border-width:5px 5px 0;border-color:grey transparent transparent}.selectize-control.single .selectize-input.dropdown-active:after{margin-top:-4px;border-width:0 5px 5px;border-color:transparent transparent grey}.selectize-control.rtl.single .selectize-input:after{left:15px;right:auto}.selectize-control.rtl .selectize-input>input{margin:0 4px 0 -2px!important}.selectize-control .selectize-input.disabled{opacity:.5;background-color:#fafafa}
css/selectize.css ADDED
@@ -0,0 +1,301 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder {
2
+ visibility: visible !important;
3
+ background: #f2f2f2 !important;
4
+ background: rgba(0, 0, 0, 0.06) !important;
5
+ border: 0 none !important;
6
+ -webkit-box-shadow: inset 0 0 12px 4px #ffffff;
7
+ box-shadow: inset 0 0 12px 4px #ffffff;
8
+ }
9
+ .selectize-control.plugin-drag_drop .ui-sortable-placeholder::after {
10
+ content: '!';
11
+ visibility: hidden;
12
+ }
13
+ .selectize-control.plugin-drag_drop .ui-sortable-helper {
14
+ -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
15
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
16
+ }
17
+ .selectize-dropdown-header {
18
+ position: relative;
19
+ padding: 5px 4px;
20
+ border-bottom: 1px solid #d0d0d0;
21
+ background: #f8f8f8;
22
+ -webkit-border-radius: 3px 3px 0 0;
23
+ -moz-border-radius: 3px 3px 0 0;
24
+ border-radius: 3px 3px 0 0;
25
+ }
26
+ .selectize-dropdown-header-close {
27
+ position: absolute;
28
+ right: 4px;
29
+ top: 50%;
30
+ color: #303030;
31
+ opacity: 0.4;
32
+ margin-top: -12px;
33
+ line-height: 20px;
34
+ font-size: 20px !important;
35
+ }
36
+ .selectize-dropdown-header-close:hover {
37
+ color: #000000;
38
+ }
39
+ .selectize-dropdown.plugin-optgroup_columns .optgroup {
40
+ border-right: 1px solid #f2f2f2;
41
+ border-top: 0 none;
42
+ float: left;
43
+ -webkit-box-sizing: border-box;
44
+ -moz-box-sizing: border-box;
45
+ box-sizing: border-box;
46
+ }
47
+ .selectize-dropdown.plugin-optgroup_columns .optgroup:last-child {
48
+ border-right: 0 none;
49
+ }
50
+ .selectize-dropdown.plugin-optgroup_columns .optgroup:before {
51
+ display: none;
52
+ }
53
+ .selectize-dropdown.plugin-optgroup_columns .optgroup-header {
54
+ border-top: 0 none;
55
+ }
56
+ .selectize-control.plugin-remove_button [data-value] {
57
+ position: relative;
58
+ padding-right: 24px !important;
59
+ }
60
+ .selectize-control.plugin-remove_button [data-value] .remove {
61
+ z-index: 1;
62
+ /* fixes ie bug (see #392) */
63
+ position: absolute;
64
+ top: 0;
65
+ right: 0;
66
+ bottom: 0;
67
+ width: 17px;
68
+ text-align: center;
69
+ font-weight: bold;
70
+ font-size: 12px;
71
+ color: inherit;
72
+ text-decoration: none;
73
+ vertical-align: middle;
74
+ display: inline-block;
75
+ padding: 2px 0 0 0;
76
+ border-left: 1px solid #d0d0d0;
77
+ -webkit-border-radius: 0 2px 2px 0;
78
+ -moz-border-radius: 0 2px 2px 0;
79
+ border-radius: 0 2px 2px 0;
80
+ -webkit-box-sizing: border-box;
81
+ -moz-box-sizing: border-box;
82
+ box-sizing: border-box;
83
+ }
84
+ .selectize-control.plugin-remove_button [data-value] .remove:hover {
85
+ background: rgba(0, 0, 0, 0.05);
86
+ }
87
+ .selectize-control.plugin-remove_button [data-value].active .remove {
88
+ border-left-color: #cacaca;
89
+ }
90
+ .selectize-control.plugin-remove_button .disabled [data-value] .remove:hover {
91
+ background: none;
92
+ }
93
+ .selectize-control.plugin-remove_button .disabled [data-value] .remove {
94
+ border-left-color: #ffffff;
95
+ }
96
+ .selectize-control {
97
+ position: relative;
98
+ }
99
+ .selectize-dropdown,
100
+ .selectize-input,
101
+ .selectize-input input {
102
+ color: #303030;
103
+ font-family: inherit;
104
+ font-size: 13px;
105
+ line-height: 18px;
106
+ -webkit-font-smoothing: inherit;
107
+ }
108
+ .selectize-input,
109
+ .selectize-control.single .selectize-input.input-active {
110
+ background: #ffffff;
111
+ cursor: text;
112
+ display: inline-block;
113
+ }
114
+ .selectize-input {
115
+ border: 1px solid #d0d0d0;
116
+ padding: 4px 4px;
117
+ display: inline-block;
118
+ width: 100%;
119
+ overflow: hidden;
120
+ position: relative;
121
+ z-index: 1;
122
+ -webkit-box-sizing: border-box;
123
+ -moz-box-sizing: border-box;
124
+ box-sizing: border-box;
125
+ -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
126
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
127
+ -webkit-border-radius: 3px;
128
+ -moz-border-radius: 3px;
129
+ border-radius: 3px;
130
+ }
131
+ .selectize-control.multi .selectize-input.has-items {
132
+ padding: 2px 4px -1px;
133
+ }
134
+ .selectize-input.full {
135
+ background-color: #ffffff;
136
+ }
137
+ .selectize-input.disabled,
138
+ .selectize-input.disabled * {
139
+ cursor: default !important;
140
+ }
141
+ .selectize-input.focus {
142
+ -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
143
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
144
+ }
145
+ .selectize-input.dropdown-active {
146
+ -webkit-border-radius: 3px 3px 0 0;
147
+ -moz-border-radius: 3px 3px 0 0;
148
+ border-radius: 3px 3px 0 0;
149
+ }
150
+ .selectize-input > * {
151
+ vertical-align: baseline;
152
+ display: -moz-inline-stack;
153
+ display: inline-block;
154
+ zoom: 1;
155
+ *display: inline;
156
+ }
157
+ .selectize-control.multi .selectize-input > div {
158
+ cursor: pointer;
159
+ margin: 0 3px 3px 0;
160
+ padding: 2px 6px;
161
+ background: #f2f2f2;
162
+ color: #303030;
163
+ border: 0 solid #d0d0d0;
164
+ }
165
+ .selectize-control.multi .selectize-input > div.active {
166
+ background: #e8e8e8;
167
+ color: #303030;
168
+ border: 0 solid #cacaca;
169
+ }
170
+ .selectize-control.multi .selectize-input.disabled > div,
171
+ .selectize-control.multi .selectize-input.disabled > div.active {
172
+ color: #7d7d7d;
173
+ background: #ffffff;
174
+ border: 0 solid #ffffff;
175
+ }
176
+ .selectize-input > input {
177
+ display: inline-block !important;
178
+ padding: 0 !important;
179
+ min-height: 0 !important;
180
+ max-height: none !important;
181
+ max-width: 100% !important;
182
+ margin: 0 2px 0 0 !important;
183
+ text-indent: 0 !important;
184
+ border: 0 none !important;
185
+ background: none !important;
186
+ line-height: inherit !important;
187
+ -webkit-user-select: auto !important;
188
+ -webkit-box-shadow: none !important;
189
+ box-shadow: none !important;
190
+ }
191
+ .selectize-input > input::-ms-clear {
192
+ display: none;
193
+ }
194
+ .selectize-input > input:focus {
195
+ outline: none !important;
196
+ }
197
+ .selectize-input::after {
198
+ content: ' ';
199
+ display: block;
200
+ clear: left;
201
+ }
202
+ .selectize-input.dropdown-active::before {
203
+ content: ' ';
204
+ display: block;
205
+ position: absolute;
206
+ background: #f0f0f0;
207
+ height: 1px;
208
+ bottom: 0;
209
+ left: 0;
210
+ right: 0;
211
+ }
212
+ .selectize-dropdown {
213
+ position: absolute;
214
+ z-index: 10;
215
+ border: 1px solid #d0d0d0;
216
+ background: #ffffff;
217
+ margin: -1px 0 0 0;
218
+ border-top: 0 none;
219
+ -webkit-box-sizing: border-box;
220
+ -moz-box-sizing: border-box;
221
+ box-sizing: border-box;
222
+ -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
223
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
224
+ -webkit-border-radius: 0 0 3px 3px;
225
+ -moz-border-radius: 0 0 3px 3px;
226
+ border-radius: 0 0 3px 3px;
227
+ }
228
+ .selectize-dropdown [data-selectable] {
229
+ cursor: pointer;
230
+ overflow: hidden;
231
+ }
232
+ .selectize-dropdown [data-selectable] .highlight {
233
+ background: rgba(125, 168, 208, 0.2);
234
+ -webkit-border-radius: 1px;
235
+ -moz-border-radius: 1px;
236
+ border-radius: 1px;
237
+ }
238
+ .selectize-dropdown [data-selectable],
239
+ .selectize-dropdown .optgroup-header {
240
+ padding: 5px 4px;
241
+ }
242
+ .selectize-dropdown .optgroup:first-child .optgroup-header {
243
+ border-top: 0 none;
244
+ }
245
+ .selectize-dropdown .optgroup-header {
246
+ color: #303030;
247
+ background: #ffffff;
248
+ cursor: default;
249
+ }
250
+ .selectize-dropdown .active {
251
+ background-color: #f5fafd;
252
+ color: #495c68;
253
+ }
254
+ .selectize-dropdown .active.create {
255
+ color: #495c68;
256
+ }
257
+ .selectize-dropdown .create {
258
+ color: rgba(48, 48, 48, 0.5);
259
+ }
260
+ .selectize-dropdown-content {
261
+ overflow-y: auto;
262
+ overflow-x: hidden;
263
+ max-height: 200px;
264
+ }
265
+ .selectize-control.single .selectize-input,
266
+ .selectize-control.single .selectize-input input {
267
+ cursor: pointer;
268
+ }
269
+ .selectize-control.single .selectize-input.input-active,
270
+ .selectize-control.single .selectize-input.input-active input {
271
+ cursor: text;
272
+ }
273
+ .selectize-control.single .selectize-input:after {
274
+ content: ' ';
275
+ display: block;
276
+ position: absolute;
277
+ top: 50%;
278
+ right: 15px;
279
+ margin-top: -3px;
280
+ width: 0;
281
+ height: 0;
282
+ border-style: solid;
283
+ border-width: 5px 5px 0 5px;
284
+ border-color: #808080 transparent transparent transparent;
285
+ }
286
+ .selectize-control.single .selectize-input.dropdown-active:after {
287
+ margin-top: -4px;
288
+ border-width: 0 5px 5px 5px;
289
+ border-color: transparent transparent #808080 transparent;
290
+ }
291
+ .selectize-control.rtl.single .selectize-input:after {
292
+ left: 15px;
293
+ right: auto;
294
+ }
295
+ .selectize-control.rtl .selectize-input > input {
296
+ margin: 0 4px 0 -2px !important;
297
+ }
298
+ .selectize-control .selectize-input.disabled {
299
+ opacity: 0.5;
300
+ background-color: #fafafa;
301
+ }
css/selectize/plugins/drag_drop.less ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .selectize-control.plugin-drag_drop {
2
+ &.multi > .selectize-input > div.ui-sortable-placeholder {
3
+ visibility: visible !important;
4
+ background: #f2f2f2 !important;
5
+ background: rgba(0,0,0,0.06) !important;
6
+ border: 0 none !important;
7
+ .selectize-box-shadow(inset 0 0 12px 4px #fff);
8
+ }
9
+ .ui-sortable-placeholder::after {
10
+ content: '!';
11
+ visibility: hidden;
12
+ }
13
+ .ui-sortable-helper {
14
+ .selectize-box-shadow(0 2px 5px rgba(0,0,0,0.2));
15
+ }
16
+ }
css/selectize/plugins/dropdown_header.less ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .selectize-dropdown-header {
2
+ position: relative;
3
+ padding: @selectize-padding-dropdown-item-y @selectize-padding-dropdown-item-x;
4
+ border-bottom: 1px solid @selectize-color-border;
5
+ background: mix(@selectize-color-dropdown, @selectize-color-border, 85%);
6
+ .selectize-border-radius(@selectize-border-radius @selectize-border-radius 0 0);
7
+ }
8
+ .selectize-dropdown-header-close {
9
+ position: absolute;
10
+ right: @selectize-padding-dropdown-item-x;
11
+ top: 50%;
12
+ color: @selectize-color-text;
13
+ opacity: 0.4;
14
+ margin-top: -12px;
15
+ line-height: 20px;
16
+ font-size: 20px !important;
17
+ }
18
+ .selectize-dropdown-header-close:hover {
19
+ color: darken(@selectize-color-text, 25%);
20
+ }
css/selectize/plugins/optgroup_columns.less ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .selectize-dropdown.plugin-optgroup_columns {
2
+ .optgroup {
3
+ border-right: 1px solid #f2f2f2;
4
+ border-top: 0 none;
5
+ float: left;
6
+ .selectize-box-sizing(border-box);
7
+ }
8
+ .optgroup:last-child {
9
+ border-right: 0 none;
10
+ }
11
+ .optgroup:before {
12
+ display: none;
13
+ }
14
+ .optgroup-header {
15
+ border-top: 0 none;
16
+ }
17
+ }
css/selectize/plugins/remove_button.less ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .selectize-control.plugin-remove_button {
2
+ [data-value] {
3
+ position: relative;
4
+ padding-right: 24px !important;
5
+ }
6
+ [data-value] .remove {
7
+ z-index: 1; /* fixes ie bug (see #392) */
8
+ position: absolute;
9
+ top: 0;
10
+ right: 0;
11
+ bottom: 0;
12
+ width: 17px;
13
+ text-align: center;
14
+ font-weight: bold;
15
+ font-size: 12px;
16
+ color: inherit;
17
+ text-decoration: none;
18
+ vertical-align: middle;
19
+ display: inline-block;
20
+ padding: @selectize-padding-item-y 0 0 0;
21
+ border-left: 1px solid @selectize-color-item-border;
22
+ .selectize-border-radius(0 2px 2px 0);
23
+ .selectize-box-sizing(border-box);
24
+ }
25
+ [data-value] .remove:hover {
26
+ background: rgba(0,0,0,0.05);
27
+ }
28
+ [data-value].active .remove {
29
+ border-left-color: @selectize-color-item-active-border;
30
+ }
31
+ .disabled [data-value] .remove:hover {
32
+ background: none;
33
+ }
34
+ .disabled [data-value] .remove {
35
+ border-left-color: lighten(desaturate(@selectize-color-item-border, 100%), @selectize-lighten-disabled-item-border);
36
+ }
37
+ }
css/selectize/selectize.less ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "plugins/drag_drop";
2
+ @import "plugins/dropdown_header";
3
+ @import "plugins/optgroup_columns";
4
+ @import "plugins/remove_button";
5
+
6
+ // base styles
7
+
8
+ @selectize-font-family: inherit;
9
+ @selectize-font-smoothing: inherit;
10
+ @selectize-font-size: 13px;
11
+ @selectize-line-height: 18px;
12
+
13
+ @selectize-color-text: #303030;
14
+ @selectize-color-border: #d0d0d0;
15
+ @selectize-color-highlight: rgba(125,168,208,0.2);
16
+ @selectize-color-input: #fff;
17
+ @selectize-color-input-full: @selectize-color-input;
18
+ @selectize-color-disabled: #fafafa;
19
+ @selectize-color-item: #f2f2f2;
20
+ @selectize-color-item-text: @selectize-color-text;
21
+ @selectize-color-item-border: #d0d0d0;
22
+ @selectize-color-item-active: #e8e8e8;
23
+ @selectize-color-item-active-text: @selectize-color-text;
24
+ @selectize-color-item-active-border: #cacaca;
25
+ @selectize-color-dropdown: #fff;
26
+ @selectize-color-dropdown-border: @selectize-color-border;
27
+ @selectize-color-dropdown-border-top: #f0f0f0;
28
+ @selectize-color-dropdown-item-active: #f5fafd;
29
+ @selectize-color-dropdown-item-active-text: #495c68;
30
+ @selectize-color-dropdown-item-create-text: rgba(red(@selectize-color-text), green(@selectize-color-text), blue(@selectize-color-text), 0.5);
31
+ @selectize-color-dropdown-item-create-active-text: @selectize-color-dropdown-item-active-text;
32
+ @selectize-color-optgroup: @selectize-color-dropdown;
33
+ @selectize-color-optgroup-text: @selectize-color-text;
34
+ @selectize-lighten-disabled-item: 30%;
35
+ @selectize-lighten-disabled-item-text: 30%;
36
+ @selectize-lighten-disabled-item-border: 30%;
37
+ @selectize-opacity-disabled: 0.5;
38
+
39
+ @selectize-shadow-input: inset 0 1px 1px rgba(0,0,0,0.1);
40
+ @selectize-shadow-input-focus: inset 0 1px 2px rgba(0,0,0,0.15);
41
+ @selectize-border: 1px solid @selectize-color-border;
42
+ @selectize-dropdown-border: 1px solid @selectize-color-dropdown-border;
43
+ @selectize-border-radius: 3px;
44
+
45
+ @selectize-width-item-border: 0;
46
+ @selectize-max-height-dropdown: 200px;
47
+
48
+ @selectize-padding-x: 4px;
49
+ @selectize-padding-y: 4px;
50
+ @selectize-padding-item-x: 6px;
51
+ @selectize-padding-item-y: 2px;
52
+ @selectize-padding-dropdown-item-x: @selectize-padding-x;
53
+ @selectize-padding-dropdown-item-y: 5px;
54
+ @selectize-margin-item-x: 3px;
55
+ @selectize-margin-item-y: 3px;
56
+
57
+ @selectize-arrow-size: 5px;
58
+ @selectize-arrow-color: #808080;
59
+ @selectize-arrow-offset: 15px;
60
+
61
+ @selectize-caret-margin: 0 2px 0 0;
62
+ @selectize-caret-margin-rtl: 0 4px 0 -2px;
63
+
64
+ .selectize-border-radius (@radii) {
65
+ -webkit-border-radius: @radii;
66
+ -moz-border-radius: @radii;
67
+ border-radius: @radii;
68
+ }
69
+ .selectize-unselectable () {
70
+ -webkit-user-select: none;
71
+ -moz-user-select: none;
72
+ -ms-user-select: none;
73
+ user-select: none;
74
+ }
75
+ .selectize-box-shadow (@shadow) {
76
+ -webkit-box-shadow: @shadow;
77
+ box-shadow: @shadow;
78
+ }
79
+ .selectize-box-sizing (@type: border-box) {
80
+ -webkit-box-sizing: @type;
81
+ -moz-box-sizing: @type;
82
+ box-sizing: @type;
83
+ }
84
+ .selectize-vertical-gradient (@color-top, @color-bottom) {
85
+ background-color: mix(@color-top, @color-bottom, 60%);
86
+ background-image: -moz-linear-gradient(top, @color-top, @color-bottom); // FF 3.6+
87
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@color-top), to(@color-bottom)); // Safari 4+, Chrome 2+
88
+ background-image: -webkit-linear-gradient(top, @color-top, @color-bottom); // Safari 5.1+, Chrome 10+
89
+ background-image: -o-linear-gradient(top, @color-top, @color-bottom); // Opera 11.10
90
+ background-image: linear-gradient(to bottom, @color-top, @color-bottom); // Standard, IE10
91
+ background-repeat: repeat-x;
92
+ filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@color-top),argb(@color-bottom))); // IE9 and down
93
+ }
94
+
95
+ .selectize-control {
96
+ position: relative;
97
+ }
98
+
99
+ .selectize-dropdown, .selectize-input, .selectize-input input {
100
+ color: @selectize-color-text;
101
+ font-family: @selectize-font-family;
102
+ font-size: @selectize-font-size;
103
+ line-height: @selectize-line-height;
104
+ -webkit-font-smoothing: @selectize-font-smoothing;
105
+ }
106
+
107
+ .selectize-input, .selectize-control.single .selectize-input.input-active {
108
+ background: @selectize-color-input;
109
+ cursor: text;
110
+ display: inline-block;
111
+ }
112
+
113
+ .selectize-input {
114
+ border: @selectize-border;
115
+ padding: @selectize-padding-y @selectize-padding-x;
116
+ display: inline-block;
117
+ width: 100%;
118
+ overflow: hidden;
119
+ position: relative;
120
+ z-index: 1;
121
+ .selectize-box-sizing(border-box);
122
+ .selectize-box-shadow(@selectize-shadow-input);
123
+ .selectize-border-radius(@selectize-border-radius);
124
+
125
+ .selectize-control.multi &.has-items {
126
+ @padding-x: @selectize-padding-x;
127
+ @padding-top: @selectize-padding-y - @selectize-padding-item-y - @selectize-width-item-border;
128
+ @padding-bottom: @selectize-padding-y - @selectize-padding-item-y - @selectize-margin-item-y - @selectize-width-item-border;
129
+ padding: @padding-top @padding-x @padding-bottom;
130
+ }
131
+
132
+ &.full {
133
+ background-color: @selectize-color-input-full;
134
+ }
135
+ &.disabled, &.disabled * {
136
+ cursor: default !important;
137
+ }
138
+ &.focus {
139
+ .selectize-box-shadow(@selectize-shadow-input-focus);
140
+ }
141
+ &.dropdown-active {
142
+ .selectize-border-radius(@selectize-border-radius @selectize-border-radius 0 0);
143
+ }
144
+
145
+ > * {
146
+ vertical-align: baseline;
147
+ display: -moz-inline-stack;
148
+ display: inline-block;
149
+ zoom: 1;
150
+ *display: inline;
151
+ }
152
+ .selectize-control.multi & > div {
153
+ cursor: pointer;
154
+ margin: 0 @selectize-margin-item-x @selectize-margin-item-y 0;
155
+ padding: @selectize-padding-item-y @selectize-padding-item-x;
156
+ background: @selectize-color-item;
157
+ color: @selectize-color-item-text;
158
+ border: @selectize-width-item-border solid @selectize-color-item-border;
159
+
160
+ &.active {
161
+ background: @selectize-color-item-active;
162
+ color: @selectize-color-item-active-text;
163
+ border: @selectize-width-item-border solid @selectize-color-item-active-border;
164
+ }
165
+ }
166
+ .selectize-control.multi &.disabled > div {
167
+ &, &.active {
168
+ color: lighten(desaturate(@selectize-color-item-text, 100%), @selectize-lighten-disabled-item-text);
169
+ background: lighten(desaturate(@selectize-color-item, 100%), @selectize-lighten-disabled-item);
170
+ border: @selectize-width-item-border solid lighten(desaturate(@selectize-color-item-border, 100%), @selectize-lighten-disabled-item-border);
171
+ }
172
+ }
173
+ > input {
174
+ &::-ms-clear {
175
+ display: none;
176
+ }
177
+ display: inline-block !important;
178
+ padding: 0 !important;
179
+ min-height: 0 !important;
180
+ max-height: none !important;
181
+ max-width: 100% !important;
182
+ margin: @selectize-caret-margin !important;
183
+ text-indent: 0 !important;
184
+ border: 0 none !important;
185
+ background: none !important;
186
+ line-height: inherit !important;
187
+ -webkit-user-select: auto !important;
188
+ .selectize-box-shadow(none) !important;
189
+ &:focus { outline: none !important; }
190
+ }
191
+ }
192
+
193
+ .selectize-input::after {
194
+ content: ' ';
195
+ display: block;
196
+ clear: left;
197
+ }
198
+
199
+ .selectize-input.dropdown-active::before {
200
+ content: ' ';
201
+ display: block;
202
+ position: absolute;
203
+ background: @selectize-color-dropdown-border-top;
204
+ height: 1px;
205
+ bottom: 0;
206
+ left: 0;
207
+ right: 0;
208
+ }
209
+
210
+ .selectize-dropdown {
211
+ position: absolute;
212
+ z-index: 10;
213
+ border: @selectize-dropdown-border;
214
+ background: @selectize-color-dropdown;
215
+ margin: -1px 0 0 0;
216
+ border-top: 0 none;
217
+ .selectize-box-sizing(border-box);
218
+ .selectize-box-shadow(0 1px 3px rgba(0,0,0,0.1));
219
+ .selectize-border-radius(0 0 @selectize-border-radius @selectize-border-radius);
220
+
221
+ [data-selectable] {
222
+ cursor: pointer;
223
+ overflow: hidden;
224
+ .highlight {
225
+ background: @selectize-color-highlight;
226
+ .selectize-border-radius(1px);
227
+ }
228
+ }
229
+ [data-selectable], .optgroup-header {
230
+ padding: @selectize-padding-dropdown-item-y @selectize-padding-dropdown-item-x;
231
+ }
232
+ .optgroup:first-child .optgroup-header {
233
+ border-top: 0 none;
234
+ }
235
+ .optgroup-header {
236
+ color: @selectize-color-optgroup-text;
237
+ background: @selectize-color-optgroup;
238
+ cursor: default;
239
+ }
240
+ .active {
241
+ background-color: @selectize-color-dropdown-item-active;
242
+ color: @selectize-color-dropdown-item-active-text;
243
+ &.create {
244
+ color: @selectize-color-dropdown-item-create-active-text;
245
+ }
246
+ }
247
+ .create {
248
+ color: @selectize-color-dropdown-item-create-text;
249
+ }
250
+ }
251
+
252
+ .selectize-dropdown-content {
253
+ overflow-y: auto;
254
+ overflow-x: hidden;
255
+ max-height: @selectize-max-height-dropdown;
256
+ }
257
+
258
+ .selectize-control.single .selectize-input {
259
+ &, input { cursor: pointer; }
260
+ &.input-active, &.input-active input { cursor: text; }
261
+
262
+ &:after {
263
+ content: ' ';
264
+ display: block;
265
+ position: absolute;
266
+ top: 50%;
267
+ right: @selectize-arrow-offset;
268
+ margin-top: round((-1 * @selectize-arrow-size / 2));
269
+ width: 0;
270
+ height: 0;
271
+ border-style: solid;
272
+ border-width: @selectize-arrow-size @selectize-arrow-size 0 @selectize-arrow-size;
273
+ border-color: @selectize-arrow-color transparent transparent transparent;
274
+ }
275
+ &.dropdown-active:after {
276
+ margin-top: @selectize-arrow-size * -0.8;
277
+ border-width: 0 @selectize-arrow-size @selectize-arrow-size @selectize-arrow-size;
278
+ border-color: transparent transparent @selectize-arrow-color transparent;
279
+ }
280
+ }
281
+
282
+ .selectize-control.rtl {
283
+ &.single .selectize-input:after {
284
+ left: @selectize-arrow-offset;
285
+ right: auto;
286
+ }
287
+ .selectize-input > input {
288
+ margin: @selectize-caret-margin-rtl !important;
289
+ }
290
+ }
291
+
292
+ .selectize-control .selectize-input.disabled {
293
+ opacity: @selectize-opacity-disabled;
294
+ background-color: @selectize-color-disabled;
295
+ }
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,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ## Code Documentation
14
+
15
+ You can find the SDK's PHP-Doc documentation here:
16
+ https://codedoc.pub/freemius/wordpress-sdk/master/
17
+
18
+ ## Initializing the SDK
19
+
20
+ Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
21
+
22
+ ```php
23
+ <?php
24
+ // Create a helper function for easy SDK access.
25
+ function my_prefix_fs() {
26
+ global $my_prefix_fs;
27
+ if ( ! isset( $my_prefix_fs ) ) {
28
+ // Include Freemius SDK.
29
+ require_once dirname(__FILE__) . '/freemius/start.php';
30
+
31
+ $my_prefix_fs = fs_dynamic_init( array(
32
+ 'id' => '1234',
33
+ 'slug' => 'my-plugin-slug',
34
+ 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
35
+ 'public_key' => 'pk_MY_PUBLIC_KEY',
36
+ 'is_live' => true,
37
+ 'is_premium' => true,
38
+ 'has_addons' => false,
39
+ 'has_paid_plans' => false,
40
+ // Set the SDK to work in a sandbox mode (for development & testing).
41
+ // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
42
+ 'secret_key' => 'sk_MY_SECRET_KEY',
43
+ ) );
44
+ }
45
+
46
+ return $my_prefix_fs;
47
+ }
48
+
49
+ // Init Freemius.
50
+ my_prefix_fs();
51
+ ?>
52
+ ```
53
+
54
+ - **1234** - Replace with your plugin's ID.
55
+ - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
56
+ - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
57
+ - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
58
+ - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
59
+
60
+
61
+ ## Usage example
62
+
63
+ You can call the SDK by using the shortcode function:
64
+
65
+ ```php
66
+ <?php my_prefix_fs()->get_upgrade_url(); ?>
67
+ ```
68
+
69
+ Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
70
+
71
+ ```php
72
+ <?php
73
+ global $my_prefix_fs;
74
+ $my_prefix_fs->get_account_url();
75
+ ?>
76
+ ```
77
+
78
+ ## Adding license based logic examples
79
+
80
+ Add marketing content to encourage your users to upgrade for your paid version:
81
+
82
+ ```php
83
+ <?php
84
+ if ( my_prefix_fs()->is_not_paying() ) {
85
+ echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
86
+ echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
87
+ esc_html__('Upgrade Now!', 'my-plugin-slug') .
88
+ '</a>';
89
+ echo '</section>';
90
+ }
91
+ ?>
92
+ ```
93
+
94
+ Add logic which will only be available in your premium plugin version:
95
+
96
+ ```php
97
+ <?php
98
+ // This "if" block will be auto removed from the Free version.
99
+ if ( my_prefix_fs()->is__premium_only() ) {
100
+
101
+ // ... premium only logic ...
102
+
103
+ }
104
+ ?>
105
+ ```
106
+
107
+ 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:
108
+
109
+ ```php
110
+ <?php
111
+ class My_Plugin {
112
+ function init() {
113
+ ...
114
+
115
+ // This "if" block will be auto removed from the free version.
116
+ if ( my_prefix_fs()->is__premium_only() ) {
117
+ // Init premium version.
118
+ $this->admin_init__premium_only();
119
+
120
+ add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
121
+ }
122
+
123
+ ...
124
+ }
125
+
126
+ // This method will be only included in the premium version.
127
+ function admin_init__premium_only() {
128
+ ...
129
+ }
130
+
131
+ // This method will be only included in the premium version.
132
+ function admin_init_hook__premium_only() {
133
+ ...
134
+ }
135
+ }
136
+ ?>
137
+ ```
138
+
139
+ Add logic which will only be executed for customers in your 'professional' plan:
140
+
141
+ ```php
142
+ <?php
143
+ if ( my_prefix_fs()->is_plan('professional', true) ) {
144
+ // .. logic related to Professional plan only ...
145
+ }
146
+ ?>
147
+ ```
148
+
149
+ Add logic which will only be executed for customers in your 'professional' plan or higher plans:
150
+
151
+ ```php
152
+ <?php
153
+ if ( my_prefix_fs()->is_plan('professional') ) {
154
+ // ... logic related to Professional plan and higher plans ...
155
+ }
156
+ ?>
157
+ ```
158
+
159
+ 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):
160
+
161
+ ```php
162
+ <?php
163
+ // This "if" block will be auto removed from the Free version.
164
+ if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
165
+ // ... logic related to Professional plan and higher plans ...
166
+ }
167
+ ?>
168
+ ```
169
+
170
+ Add logic only for users in trial:
171
+
172
+ ```php
173
+ <?php
174
+ if ( my_prefix_fs()->is_trial() ) {
175
+ // ... logic for users in trial ...
176
+ }
177
+ ?>
178
+ ```
179
+
180
+ Add logic for specified paid plan:
181
+
182
+ ```php
183
+ <?php
184
+ // This "if" block will be auto removed from the Free version.
185
+ if ( my_prefix_fs()->is__premium_only() ) {
186
+ if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
187
+
188
+ // ... logic related to Professional plan only ...
189
+
190
+ } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
191
+
192
+ // ... logic related to Business plan and higher plans ...
193
+
194
+ }
195
+ }
196
+ ?>
197
+ ```
198
+
199
+ ## Excluding files and folders from the free plugin version
200
+ There are two ways to exclude files from your free version.
201
+
202
+ 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.
203
+ 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
204
+ ```php
205
+ <?php
206
+ /**
207
+ * Plugin Name: My Very Awesome Plugin
208
+ * Plugin URI: http://my-awesome-plugin.com
209
+ * Description: Create and manage Awesomeness right in WordPress.
210
+ * Version: 1.0.0
211
+ * Author: Awesomattic
212
+ * Author URI: http://my-awesome-plugin.com/me/
213
+ * License: GPLv2
214
+ * Text Domain: myplugin
215
+ * Domain Path: /langs
216
+ *
217
+ * @fs_premium_only /lib/functions.php, /premium-files/
218
+ */
219
+
220
+ if ( ! defined( 'ABSPATH' ) ) {
221
+ exit;
222
+ }
223
+
224
+ // ... my code ...
225
+ ?>
226
+ ```
227
+ The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
228
+
229
+ # WordPress.org Compliance
230
+ 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:
231
+ > 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.
232
+
233
+ 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.
234
+
235
+ ## Deployment
236
+ Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
237
+ The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
238
+
239
+ 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.
240
+ 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
241
+
242
+ 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.
243
+
244
+ ## Reporting Bugs
245
+ Email dev [at] freemius [dot] com
246
+
247
+ ## FAQ
248
+
249
+ ## Copyright
250
+ 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 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 .button i.dashicons{vertical-align:middle}#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 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}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#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;background-size:100% 100%;-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}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{position:absolute;top:112px;right:10px}@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:1em 30px !important}#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{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#F3F3F3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#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;top:100%;bottom: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/admin/debug.css ADDED
@@ -0,0 +1 @@
 
1
+ .switch{position:relative;display:inline-block;font-size:1.6em;font-weight:bold;color:#ccc;text-shadow:0px 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:4px;background:#ececec;box-shadow:0px 0px 4px rgba(0,0,0,0.1),inset 0px 1px 3px 0px rgba(0,0,0,0.1);cursor:pointer}.switch span{display:inline-block;width:35px;text-transform:uppercase}.switch span.on{color:#6bc406}.switch .toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background:-moz-linear-gradient(top, #ececec 0%, #fff 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));background:-webkit-linear-gradient(top, #ececec 0%, #fff 100%);background:-o-linear-gradient(top, #ececec 0%, #fff 100%);background:-ms-linear-gradient(top, #ececec 0%, #fff 100%);background:linear-gradient(top, #ececec 0%, #fff 100%);box-shadow:inset 0px 1px 0px 0px rgba(255,255,255,0.5);z-index:999;-moz-transition:all 0.15s ease-in-out;-o-transition:all 0.15s ease-in-out;-ms-transition:all 0.15s ease-in-out;-webkit-transition:all 0.15s ease-in-out;transition:all 0.15s ease-in-out}.switch.on .toggle{left:2%}.switch.off .toggle{left:54%}.switch.round{padding:0px 20px;border-radius:40px}.switch.round .toggle{border-radius:40px;width:14px;height:14px}.switch.round.on .toggle{left:3%;background:#6bc406}.switch.round.off .toggle{left:58%}.switch-label{font-size:20px;line-height:31px;margin:0 5px}
freemius/assets/css/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice.success{color:green;font-weight:700}
freemius/assets/img/meta-tag-manager.png ADDED
Binary file
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,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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
+ .button
26
+ {
27
+ i.dashicons
28
+ {
29
+ vertical-align: middle;
30
+ }
31
+ }
32
+
33
+ .fs-header-actions
34
+ {
35
+ position: absolute;
36
+ top: 17px;
37
+ right: 15px;
38
+ font-size: 0.9em;
39
+
40
+ ul
41
+ {
42
+ margin: 0;
43
+ }
44
+
45
+ li
46
+ {
47
+ form
48
+ {
49
+ display: inline-block;
50
+ }
51
+
52
+ float: left;
53
+ a
54
+ {
55
+ text-decoration: none;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ .rtl #fs_account .fs-header-actions
62
+ {
63
+ left: 15px;
64
+ right: auto;
65
+ }
66
+
67
+ .fs-key-value-table
68
+ {
69
+ width: 100%;
70
+
71
+ form
72
+ {
73
+ display: inline-block;
74
+ }
75
+
76
+ tr
77
+ {
78
+ td:first-child
79
+ {
80
+ nobr
81
+ {
82
+ font-weight: bold;
83
+ }
84
+
85
+ text-align: right;
86
+
87
+ form
88
+ {
89
+ display: block;
90
+ }
91
+ }
92
+
93
+ td.fs-right
94
+ {
95
+ text-align: right;
96
+ }
97
+
98
+ &.fs-odd
99
+ {
100
+ background: #ebebeb;
101
+ }
102
+ }
103
+
104
+ td, th
105
+ {
106
+ padding: 10px;
107
+ }
108
+
109
+ var, code
110
+ {
111
+ color: #0073AA;
112
+ font-size: 16px;
113
+ background: none;
114
+ }
115
+ }
116
+
117
+ label.fs-tag
118
+ {
119
+ background: #ffba00;
120
+ color: #fff;
121
+ display: inline-block;
122
+ border-radius: 3px;
123
+ padding: 5px;
124
+ font-size: 11px;
125
+ line-height: 11px;
126
+ vertical-align: baseline;
127
+
128
+ &.fs-warn
129
+ {
130
+ background: #ffba00;
131
+ }
132
+ &.fs-success
133
+ {
134
+ background: #46b450;
135
+ }
136
+ &.fs-error
137
+ {
138
+ background: #dc3232;
139
+ }
140
+ }
141
+
142
+ #fs_addons
143
+ {
144
+ h3
145
+ {
146
+ border: none;
147
+ margin-bottom: 0;
148
+ padding: 4px 5px;
149
+ }
150
+
151
+ td
152
+ {
153
+ vertical-align: middle;
154
+ }
155
+
156
+ td:first-child,
157
+ th:first-child
158
+ {
159
+ text-align: left;
160
+ font-weight: bold;
161
+ }
162
+ td:last-child,
163
+ th:last-child
164
+ {
165
+ text-align: right;
166
+ }
167
+ th
168
+ {
169
+ font-weight: bold;
170
+ }
171
+ }
freemius/assets/scss/admin/add-ons.scss ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ li
50
+ {
51
+ list-style: none;
52
+ line-height: 18px;
53
+ padding: 0 15px;
54
+ width: 100%;
55
+ display: block;
56
+ @include box-sizing(border-box);
57
+ }
58
+
59
+ .fs-card-banner
60
+ {
61
+ padding: 0;
62
+ margin: 0;
63
+ line-height: 0;
64
+ display: block;
65
+ height: 100px;
66
+ background-repeat: repeat-x;
67
+ background-size: 100% 100%;
68
+ @include transition(all, 0.15s);
69
+ }
70
+
71
+ .fs-title
72
+ {
73
+ margin: 10px 0 0 0;
74
+ height: 18px;
75
+ overflow: hidden;
76
+ color: #000;
77
+ white-space: nowrap;
78
+ text-overflow: ellipsis;
79
+ font-weight: bold;
80
+ }
81
+
82
+ .fs-offer
83
+ {
84
+ font-size: 0.9em;
85
+ }
86
+
87
+ .fs-description
88
+ {
89
+ background-color: #f9f9f9;
90
+ padding: 10px 15px 100px 15px;
91
+ border-top: 1px solid #eee;
92
+ margin: 0 0 10px 0;
93
+ color: #777;
94
+ }
95
+
96
+ .fs-tag
97
+ {
98
+ position: absolute;
99
+ top: 10px;
100
+ right: 0px;
101
+ background: greenyellow;
102
+ display: block;
103
+ padding: 2px 10px;
104
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.3));
105
+ text-transform: uppercase;
106
+ font-size: 0.9em;
107
+ font-weight: bold;
108
+ }
109
+
110
+ .fs-cta
111
+ {
112
+ .button
113
+ {
114
+ position: absolute;
115
+ top: 112px;
116
+ right: 10px;
117
+ }
118
+ }
119
+ }
120
+
121
+ @media screen and (min-width: 960px) {
122
+ &:hover
123
+ {
124
+ .fs-overlay
125
+ {
126
+ border: 2px solid $fms-link-color;
127
+ margin-left: -1px;
128
+ margin-top: -1px;
129
+ }
130
+
131
+ .fs-inner
132
+ {
133
+ ul
134
+ {
135
+ top: -100px;
136
+ }
137
+
138
+ .fs-card-banner
139
+ {
140
+ // background-position: 50% -100px;
141
+ }
142
+
143
+ .fs-title,
144
+ .fs-offer
145
+ {
146
+ color: $fms-link-color;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ #TB_window
156
+ {
157
+ &, iframe
158
+ {
159
+ width: 772px !important;
160
+ }
161
+ }
162
+
163
+ #plugin-information
164
+ {
165
+ #section-description
166
+ {
167
+ h2, h3, p, b, i, blockquote, li, ul, ol
168
+ {
169
+ clear: none;
170
+ }
171
+
172
+ .fs-selling-points
173
+ {
174
+ padding-bottom: 10px;
175
+ border-bottom: 1px solid #ddd;
176
+
177
+ ul
178
+ {
179
+ margin: 0;
180
+
181
+ li
182
+ {
183
+ padding: 0;
184
+ list-style: none outside none;
185
+
186
+ i.dashicons
187
+ {
188
+ color: $fs-logo-green-color;
189
+ font-size: 3em;
190
+ vertical-align: middle;
191
+ line-height: 30px;
192
+ float: left;
193
+ margin: 0 0 0 -15px;
194
+ }
195
+
196
+ h3
197
+ {
198
+ margin: 1em 30px !important;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ .fs-screenshots
205
+ {
206
+ @include clearfix();
207
+ ul
208
+ {
209
+ list-style: none;
210
+ margin: 0;
211
+
212
+ li
213
+ {
214
+ width: 225px;
215
+ height: 225px;
216
+ float: left;
217
+ margin-bottom: 20px;
218
+ @include box-sizing(content-box);
219
+
220
+ a
221
+ {
222
+ display: block;
223
+ width: 100%;
224
+ height: 100%;
225
+ border: 1px solid;
226
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
227
+ background-size: cover;
228
+ }
229
+
230
+ &.odd
231
+ {
232
+ margin-right: 20px;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ .plugin-information-pricing
240
+ {
241
+ $pricing_color: #FFFEEC;
242
+ $borders_color: #DDD;
243
+ margin: -16px;
244
+ // padding: 20px;
245
+ border-bottom: 1px solid $borders_color;
246
+
247
+ .fs-plan
248
+ {
249
+
250
+ h3
251
+ {
252
+ margin-top: 0;
253
+ padding: 20px;
254
+ font-size: 16px;
255
+ }
256
+
257
+ .nav-tab-wrapper
258
+ {
259
+ border-bottom: 1px solid $borders_color;
260
+
261
+ .nav-tab
262
+ {
263
+ cursor: pointer;
264
+ position: relative;
265
+ padding: 0 10px;
266
+ font-size: 0.9em;
267
+
268
+ label
269
+ {
270
+ text-transform: uppercase;
271
+ color: green;
272
+ background: greenyellow;
273
+ position: absolute;
274
+ left: -1px;
275
+ right: -1px;
276
+ bottom: 100%;
277
+ border: 1px solid darkgreen;
278
+ padding: 2px;
279
+ text-align: center;
280
+ font-size: 0.9em;
281
+ line-height: 1em;
282
+ }
283
+
284
+ &.nav-tab-active
285
+ {
286
+ cursor: default;
287
+ background: $pricing_color;
288
+ border-bottom-color: $pricing_color;
289
+ }
290
+ }
291
+ }
292
+
293
+ &.fs-single-cycle
294
+ {
295
+ h3
296
+ {
297
+ background: $pricing_color;
298
+ margin: 0;
299
+ padding-bottom: 0;
300
+ color: #0073aa;
301
+ }
302
+
303
+ .nav-tab-wrapper,
304
+ .fs-billing-frequency
305
+ {
306
+ display: none;
307
+ }
308
+ }
309
+
310
+ .fs-pricing-body
311
+ {
312
+ background: $pricing_color;
313
+ padding: 20px;
314
+ }
315
+
316
+ .button
317
+ {
318
+ width: 100%;
319
+ text-align: center;
320
+ font-weight: bold;
321
+ text-transform: uppercase;
322
+ font-size: 1.1em;
323
+ }
324
+
325
+ label
326
+ {
327
+ white-space: nowrap;
328
+ }
329
+
330
+ var {
331
+ font-style: normal;
332
+ }
333
+
334
+ .fs-billing-frequency,
335
+ .fs-annual-discount
336
+ {
337
+ text-align: center;
338
+ display: block;
339
+ font-weight: bold;
340
+ margin-bottom: 10px;
341
+ text-transform: uppercase;
342
+ background: #F3F3F3;
343
+ padding: 2px;
344
+ border: 1px solid #ccc;
345
+ }
346
+
347
+ .fs-annual-discount
348
+ {
349
+ text-transform: none;
350
+ color: green;
351
+ background: greenyellow;
352
+ }
353
+
354
+ ul.fs-trial-terms
355
+ {
356
+ font-size: 0.9em;
357
+
358
+ i
359
+ {
360
+ float: left;
361
+ margin: 0 0 0 -15px;
362
+ }
363
+
364
+ li
365
+ {
366
+ margin: 10px 0 0 0;
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ #section-features
373
+ {
374
+ .fs-features
375
+ {
376
+ margin: -20px -26px;
377
+ }
378
+
379
+ table
380
+ {
381
+ width: 100%;
382
+ border-spacing: 0;
383
+ border-collapse: separate;
384
+
385
+ thead
386
+ {
387
+ th
388
+ {
389
+ padding: 10px 0;
390
+ }
391
+
392
+ .fs-price
393
+ {
394
+ color: $fs-logo-green-color;
395
+ font-weight: normal;
396
+ display: block;
397
+ text-align: center;
398
+ }
399
+ }
400
+
401
+ tbody
402
+ {
403
+ td
404
+ {
405
+ border-top: 1px solid #ccc;
406
+ padding: 10px 0;
407
+ text-align: center;
408
+ width: 100px;
409
+ color: $fs-logo-green-color;
410
+
411
+ &:first-child
412
+ {
413
+ text-align: left;
414
+ width: auto;
415
+ color: inherit;
416
+ padding-left: 26px;
417
+ }
418
+ }
419
+ tr.fs-odd
420
+ {
421
+ td
422
+ {
423
+ background: #fefefe;
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ .dashicons-yes
430
+ {
431
+ width: 30px;
432
+ height: 30px;
433
+ font-size: 30px;
434
+ }
435
+ }
436
+ }
437
+
438
+ @media screen and (max-width: 961px) {
439
+ #fs_addons
440
+ {
441
+ .fs-cards-list
442
+ {
443
+ .fs-card
444
+ {
445
+ height: 265px;
446
+ }
447
+ }
448
+ }
449
+ }
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
+ top: 100%;
63
+ bottom: 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/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .switch
4
+ {
5
+ position: relative;
6
+ display: inline-block;
7
+ font-size: 1.6em;
8
+ font-weight: bold;
9
+ color: #ccc;
10
+ text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
+ height: 18px;
12
+ padding: 6px 6px 5px 6px;
13
+ border: 1px solid #ccc;
14
+ border: 1px solid rgba(0, 0, 0, 0.2);
15
+ border-radius: 4px;
16
+ background: #ececec;
17
+ box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
+ cursor: pointer;
19
+
20
+ span
21
+ {
22
+ display: inline-block; width: 35px;
23
+ text-transform: uppercase;
24
+
25
+ &.on
26
+ {
27
+ color: $button-primary-bkg;
28
+ }
29
+ }
30
+
31
+ .toggle
32
+ {
33
+ position: absolute;
34
+ top: 1px;
35
+ width: 37px;
36
+ height: 25px;
37
+ border: 1px solid #ccc;
38
+ border: 1px solid rgba(0, 0, 0, 0.3);
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
+ background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
+ background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
+ background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
+ background: linear-gradient(top, #ececec 0%, #fff 100%);
47
+ box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
+ z-index: 999;
49
+ @include transition(all 0.15s ease-in-out);
50
+ }
51
+
52
+ &.on .toggle
53
+ {
54
+ left: 2%;
55
+ }
56
+ &.off .toggle
57
+ {
58
+ left: 54%;
59
+ }
60
+
61
+ /* Round switch */
62
+ &.round
63
+ {
64
+ padding: 0px 20px;
65
+ border-radius: 40px;
66
+
67
+ .toggle
68
+ {
69
+ border-radius: 40px;
70
+ width: 14px;
71
+ height: 14px;
72
+ }
73
+
74
+ &.on .toggle
75
+ {
76
+ left: 3%;
77
+ background: $button-primary-bkg;
78
+ }
79
+ &.off .toggle
80
+ {
81
+ left: 58%;
82
+ }
83
+ }
84
+ }
85
+
86
+ .switch-label
87
+ {
88
+ font-size: 20px;
89
+ line-height: 31px;
90
+ margin: 0 5px;
91
+ }
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,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
22
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
23
+ }
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
+ }
33
+ if ( WP_FS__SIMULATE_NO_CURL ) {
34
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
37
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
41
+ }
42
+
43
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
44
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
45
+ }
46
+
47
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
48
+ /**
49
+ * @since 1.1.7.3
50
+ * @author Vova Feldman (@svovaf)
51
+ *
52
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
53
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
54
+ * between domains on a daily basis. Therefore, to eliminate the risk of
55
+ * multiple unwanted connectivity test pings, temporary ignore domain or
56
+ * server IP changes.
57
+ */
58
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
59
+ }
60
+
61
+ /**
62
+ * If your dev environment supports custom public network IP setup
63
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
64
+ * and uncomment it during dev.
65
+ */
66
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
67
+ // VVV default public network IP.
68
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
69
+
70
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
71
+ }
72
+
73
+ /**
74
+ * If true and running with secret key, the opt-in process
75
+ * will skip the email activation process which is invoked
76
+ * when the email of the context user already exist in Freemius
77
+ * database (as a security precaution, to prevent sharing user
78
+ * secret with unauthorized entity).
79
+ *
80
+ * IMPORTANT:
81
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
82
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
83
+ * CLOCK IS SYNCED.
84
+ */
85
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
86
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
87
+ }
88
+
89
+
90
+ /**
91
+ * Directories
92
+ */
93
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
94
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
95
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
96
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
97
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
98
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
99
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
100
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
101
+
102
+
103
+ /**
104
+ * Domain / URL / Address
105
+ */
106
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
107
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
108
+
109
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
110
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
111
+ }
112
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
113
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
114
+ }
115
+
116
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
117
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
118
+ }
119
+
120
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
121
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
122
+ }
123
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
124
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
125
+ }
126
+
127
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
128
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
129
+
130
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
131
+ // By default, run with Freemius production servers.
132
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
133
+ }
134
+
135
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
136
+
137
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
138
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
139
+ } else {
140
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
141
+ is_string( WP_FS__REMOTE_ADDR ) &&
142
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) == '127.' ||
143
+ WP_FS__REMOTE_ADDR == '::1' )
144
+ );
145
+ }
146
+
147
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
148
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
149
+
150
+ // Set API address for local testing.
151
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
152
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
153
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
154
+ }
155
+
156
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
157
+
158
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
159
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
160
+ }
161
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
162
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
163
+ }
164
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
165
+
166
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
167
+ // Checks if CloudFlare's HTTPS (Flexible SSL support)
168
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ||
169
+ // Check if HTTPS request.
170
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
171
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
172
+ );
173
+
174
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
175
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
176
+
177
+ /**
178
+ * Billing Frequencies
179
+ */
180
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
181
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
182
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
183
+
184
+ /**
185
+ * Plans
186
+ */
187
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
188
+ define( 'WP_FS__PLAN_FREE', 'free' );
189
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
190
+
191
+ /**
192
+ * Times in seconds
193
+ */
194
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
195
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
196
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
197
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
198
+
199
+ /**
200
+ * Debugging
201
+ */
202
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
203
+ $debug_mode = get_option( 'fs_debug_mode', null );
204
+
205
+ if ( $debug_mode === null ) {
206
+ $debug_mode = false;
207
+ add_option( 'fs_debug_mode', $debug_mode );
208
+ }
209
+
210
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
211
+ }
212
+
213
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
214
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-n-d H:i:s' );
215
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
216
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
217
+ }
218
+
219
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
220
+ error_reporting( E_ALL );
221
+ ini_set( 'error_reporting', E_ALL );
222
+ ini_set( 'display_errors', true );
223
+ ini_set( 'html_errors', true );
224
+ }
225
+
226
+
227
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
228
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
229
+ 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,9452 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1.7.5
101
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
102
+ */
103
+ private $_anonymous_mode;
104
+
105
+ /**
106
+ * @since 1.0.8
107
+ * @var bool Hints the SDK if the plugin has any paid plans.
108
+ */
109
+ private $_has_paid_plans;
110
+
111
+ /**
112
+ * @since 1.0.7
113
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
114
+ */
115
+ private $_is_org_compliant;
116
+
117
+ /**
118
+ * @since 1.0.7
119
+ * @var bool Hints the SDK if the plugin is has add-ons.
120
+ */
121
+ private $_has_addons;
122
+
123
+ /**
124
+ * @since 1.1.6
125
+ * @var string[]bool.
126
+ */
127
+ private $_permissions;
128
+
129
+ /**
130
+ * @var FS_Key_Value_Storage
131
+ */
132
+ private $_storage;
133
+
134
+ /**
135
+ * @since 1.0.0
136
+ *
137
+ * @var FS_Logger
138
+ */
139
+ private $_logger;
140
+ /**
141
+ * @since 1.0.4
142
+ *
143
+ * @var FS_Plugin
144
+ */
145
+ private $_plugin = false;
146
+ /**
147
+ * @since 1.0.4
148
+ *
149
+ * @var FS_Plugin
150
+ */
151
+ private $_parent_plugin = false;
152
+ /**
153
+ * @since 1.1.1
154
+ *
155
+ * @var Freemius
156
+ */
157
+ private $_parent = false;
158
+ /**
159
+ * @since 1.0.1
160
+ *
161
+ * @var FS_User
162
+ */
163
+ private $_user = false;
164
+ /**
165
+ * @since 1.0.1
166
+ *
167
+ * @var FS_Site
168
+ */
169
+ private $_site = false;
170
+ /**
171
+ * @since 1.0.1
172
+ *
173
+ * @var FS_Plugin_License
174
+ */
175
+ private $_license;
176
+ /**
177
+ * @since 1.0.2
178
+ *
179
+ * @var FS_Plugin_Plan[]
180
+ */
181
+ private $_plans = false;
182
+ /**
183
+ * @var FS_Plugin_License[]
184
+ * @since 1.0.5
185
+ */
186
+ private $_licenses = false;
187
+
188
+ /**
189
+ * @since 1.0.1
190
+ *
191
+ * @var FS_Admin_Menu_Manager
192
+ */
193
+ private $_menu;
194
+
195
+ /**
196
+ * @var FS_Admin_Notice_Manager
197
+ */
198
+ private $_admin_notices;
199
+
200
+ /**
201
+ * @since 1.1.6
202
+ *
203
+ * @var FS_Admin_Notice_Manager
204
+ */
205
+ private static $_global_admin_notices;
206
+
207
+ /**
208
+ * @var FS_Logger
209
+ * @since 1.0.0
210
+ */
211
+ private static $_static_logger;
212
+
213
+ /**
214
+ * @var FS_Option_Manager
215
+ * @since 1.0.2
216
+ */
217
+ private static $_accounts;
218
+
219
+ /**
220
+ * @var Freemius[]
221
+ */
222
+ private static $_instances = array();
223
+
224
+
225
+ /* Ctor
226
+ ------------------------------------------------------------------------------------------------------------------*/
227
+
228
+ private function __construct( $slug ) {
229
+ $this->_slug = $slug;
230
+
231
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
232
+
233
+ $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
234
+
235
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file();
236
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
237
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
238
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
239
+
240
+ $base_name_split = explode( '/', $this->_plugin_basename );
241
+ $this->_plugin_dir_name = $base_name_split[0];
242
+
243
+ if ( $this->_logger->is_on() ) {
244
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
245
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
246
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
247
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
248
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
249
+ }
250
+
251
+ // Remember link between file to slug.
252
+ $this->store_file_slug_map();
253
+
254
+ // Store plugin's initial install timestamp.
255
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
256
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
257
+ }
258
+
259
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
260
+
261
+ $this->_admin_notices = FS_Admin_Notice_Manager::instance(
262
+ $slug,
263
+ is_object( $this->_plugin ) ? $this->_plugin->title : ''
264
+ );
265
+
266
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
267
+ 'true' === fs_request_is_action( 'restart_freemius' )
268
+ ) {
269
+ FS_Api::clear_cache();
270
+ }
271
+
272
+ $this->_register_hooks();
273
+
274
+ $this->_load_account();
275
+
276
+ $this->_version_updates_handler();
277
+ }
278
+
279
+ /**
280
+ * @author Vova Feldman (@svovaf)
281
+ * @since 1.0.9
282
+ */
283
+ private function _version_updates_handler() {
284
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
285
+ // Freemius version upgrade mode.
286
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
287
+ $this->_storage->sdk_version = $this->version;
288
+
289
+ if ( empty( $this->_storage->sdk_last_version ) ||
290
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
291
+ ) {
292
+ $this->_storage->sdk_upgrade_mode = true;
293
+ $this->_storage->sdk_downgrade_mode = false;
294
+ } else {
295
+ $this->_storage->sdk_downgrade_mode = true;
296
+ $this->_storage->sdk_upgrade_mode = false;
297
+
298
+ }
299
+
300
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
301
+ }
302
+
303
+ $plugin_version = $this->get_plugin_version();
304
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
305
+ // Plugin version upgrade mode.
306
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
307
+ $this->_storage->plugin_version = $plugin_version;
308
+
309
+ if ( empty( $this->_storage->plugin_last_version ) ||
310
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
311
+ ) {
312
+ $this->_storage->plugin_upgrade_mode = true;
313
+ $this->_storage->plugin_downgrade_mode = false;
314
+ } else {
315
+ $this->_storage->plugin_downgrade_mode = true;
316
+ $this->_storage->plugin_upgrade_mode = false;
317
+ }
318
+
319
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
320
+ // Different version of the plugin was installed before, therefore it's an update.
321
+ $this->_storage->is_plugin_new_install = false;
322
+ }
323
+
324
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
325
+ }
326
+ }
327
+
328
+ /**
329
+ * @author Vova Feldman (@svovaf)
330
+ * @since 1.1.5
331
+ *
332
+ * @param string $sdk_prev_version
333
+ * @param string $sdk_version
334
+ */
335
+ function _data_migration( $sdk_prev_version, $sdk_version ) {
336
+ /**
337
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
338
+ */
339
+ if ( empty( $sdk_prev_version ) ) {
340
+ return;
341
+ }
342
+
343
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
344
+ version_compare( $sdk_version, '1.1.5', '>=' )
345
+ ) {
346
+ // On version 1.1.5 merged connectivity and is_on data.
347
+ if ( isset( $this->_storage->connectivity_test ) ) {
348
+ if ( ! isset( $this->_storage->is_on ) ) {
349
+ unset( $this->_storage->connectivity_test );
350
+ } else {
351
+ $connectivity_data = $this->_storage->connectivity_test;
352
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
353
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
354
+
355
+ // Override.
356
+ $this->_storage->connectivity_test = $connectivity_data;
357
+
358
+ // Remove previous structure.
359
+ unset( $this->_storage->is_on );
360
+ }
361
+
362
+ }
363
+ }
364
+ }
365
+
366
+ /**
367
+ * @author Vova Feldman (@svovaf)
368
+ * @since 1.0.9
369
+ */
370
+ private function _register_hooks() {
371
+ if ( is_admin() ) {
372
+ // Hook to plugin activation
373
+ register_activation_hook( $this->_plugin_main_file_path, array(
374
+ &$this,
375
+ '_activate_plugin_event_hook'
376
+ ) );
377
+
378
+ // Hook to plugin uninstall.
379
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
380
+
381
+ if ( ! $this->is_ajax() ) {
382
+ if ( ! $this->is_addon() ) {
383
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
384
+ add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
385
+ }
386
+ }
387
+ }
388
+
389
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
390
+
391
+ add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
392
+
393
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
394
+
395
+ $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
396
+ }
397
+
398
+ /**
399
+ * @author Vova Feldman (@svovaf)
400
+ * @since 1.0.9
401
+ */
402
+ private function _register_account_hooks() {
403
+ if ( is_admin() ) {
404
+ if ( ! $this->is_ajax() ) {
405
+ if ( $this->apply_filters( 'show_trial', true ) && $this->has_trial_plan() ) {
406
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
407
+ if ( ! $this->_site->is_trial_utilized() &&
408
+ (
409
+ // Show promotion if never shown it yet and 24 hours after initial activation.
410
+ ( false === $last_time_trial_promotion_shown && $this->_storage->activation_timestamp < ( time() - WP_FS__TIME_24_HOURS_IN_SEC ) ) ||
411
+ // Show promotion in every 30 days.
412
+ ( is_numeric( $last_time_trial_promotion_shown ) && 30 * WP_FS__TIME_24_HOURS_IN_SEC < time() - $last_time_trial_promotion_shown ) )
413
+ ) {
414
+ $this->add_action( 'after_init_plugin_registered', array( &$this, '_add_trial_notice' ) );
415
+ }
416
+ }
417
+ }
418
+
419
+ // If user is paying or in trial and have the free version installed,
420
+ // assume that the deactivation is for the upgrade process.
421
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
422
+ add_action( 'wp_ajax_submit-uninstall-reason', array( &$this, '_submit_uninstall_reason_action' ) );
423
+
424
+ global $pagenow;
425
+ if ( 'plugins.php' === $pagenow ) {
426
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Leverage backtrace to find caller plugin file path.
434
+ *
435
+ * @author Vova Feldman (@svovaf)
436
+ * @since 1.0.6
437
+ *
438
+ * @return string
439
+ *
440
+ * @uses fs_find_caller_plugin_file
441
+ */
442
+ private function _find_caller_plugin_file() {
443
+ // Try to load the cached value of the file path.
444
+ if ( isset( $this->_storage->plugin_main_file ) ) {
445
+ if ( file_exists( $this->_storage->plugin_main_file->path ) ) {
446
+ return $this->_storage->plugin_main_file->path;
447
+ }
448
+ }
449
+
450
+ $plugin_file = fs_find_caller_plugin_file();
451
+
452
+ $this->_storage->plugin_main_file = (object) array(
453
+ 'path' => fs_normalize_path( $plugin_file ),
454
+ );
455
+
456
+ return $plugin_file;
457
+ }
458
+
459
+
460
+ #region Deactivation Feedback Form ------------------------------------------------------------------
461
+
462
+ /**
463
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
464
+ * page.
465
+ *
466
+ * @author Vova Feldman (@svovaf)
467
+ * @author Leo Fajardo (@leorw)
468
+ * @since 1.1.2
469
+ */
470
+ function _add_deactivation_feedback_dialog_box() {
471
+ fs_enqueue_local_style( 'fs_deactivation_feedback', '/admin/deactivation-feedback.css' );
472
+
473
+ /* Check the type of user:
474
+ * 1. Long-term (long-term)
475
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
476
+ * 3. Short-term (short-term)
477
+ */
478
+ $is_long_term_user = true;
479
+
480
+ // Check if the site is at least 2 days old.
481
+ $time_installed = $this->_storage->install_timestamp;
482
+
483
+ // Difference in seconds.
484
+ $date_diff = time() - $time_installed;
485
+
486
+ // Convert seconds to days.
487
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
488
+
489
+ if ( $date_diff_days < 2 ) {
490
+ $is_long_term_user = false;
491
+ }
492
+
493
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
494
+
495
+ if ( $is_long_term_user ) {
496
+ $user_type = 'long-term';
497
+ } else {
498
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
499
+ $user_type = 'non-registered-and-non-anonymous-short-term';
500
+ } else {
501
+ $user_type = 'short-term';
502
+ }
503
+ }
504
+
505
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
506
+
507
+ // Load the HTML template for the deactivation feedback dialog box.
508
+ $vars = array(
509
+ 'reasons' => $uninstall_reasons,
510
+ 'slug' => $this->_slug
511
+ );
512
+
513
+ /**
514
+ * @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.
515
+ */
516
+ fs_require_template( 'deactivation-feedback-modal.php', $vars );
517
+ }
518
+
519
+ /**
520
+ * @author Leo Fajardo (leorw)
521
+ * @since 1.1.2
522
+ *
523
+ * @param string $user_type
524
+ *
525
+ * @return array The uninstall reasons for the specified user type.
526
+ */
527
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
528
+ $reason_found_better_plugin = array(
529
+ 'id' => 2,
530
+ 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
531
+ 'input_type' => 'textfield',
532
+ 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
533
+ );
534
+
535
+ $reason_temporary_deactivation = array(
536
+ 'id' => 15,
537
+ 'text' => __fs( 'reason-temporary-deactivation', $this->_slug ),
538
+ 'input_type' => '',
539
+ 'input_placeholder' => ''
540
+ );
541
+
542
+ $reason_other = array(
543
+ 'id' => 7,
544
+ 'text' => __fs( 'reason-other', $this->_slug ),
545
+ 'input_type' => 'textfield',
546
+ 'input_placeholder' => ''
547
+ );
548
+
549
+ $long_term_user_reasons = array(
550
+ array(
551
+ 'id' => 1,
552
+ 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
553
+ 'input_type' => '',
554
+ 'input_placeholder' => ''
555
+ ),
556
+ $reason_found_better_plugin,
557
+ array(
558
+ 'id' => 3,
559
+ 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
560
+ 'input_type' => '',
561
+ 'input_placeholder' => ''
562
+ ),
563
+ array(
564
+ 'id' => 4,
565
+ 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
566
+ 'input_type' => '',
567
+ 'input_placeholder' => ''
568
+ ),
569
+ array(
570
+ 'id' => 5,
571
+ 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
572
+ 'input_type' => '',
573
+ 'input_placeholder' => ''
574
+ )
575
+ );
576
+
577
+ if ( $this->is_paying() ) {
578
+ $long_term_user_reasons[] = array(
579
+ 'id' => 6,
580
+ 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
581
+ 'input_type' => 'textfield',
582
+ 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
583
+ );
584
+ }
585
+
586
+ $long_term_user_reasons[] = $reason_temporary_deactivation;
587
+ $long_term_user_reasons[] = $reason_other;
588
+
589
+ $uninstall_reasons = array(
590
+ 'long-term' => $long_term_user_reasons,
591
+ 'non-registered-and-non-anonymous-short-term' => array(
592
+ array(
593
+ 'id' => 8,
594
+ 'text' => __fs( 'reason-didnt-work', $this->_slug ),
595
+ 'input_type' => '',
596
+ 'input_placeholder' => ''
597
+ ),
598
+ array(
599
+ 'id' => 9,
600
+ 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
601
+ 'input_type' => '',
602
+ 'input_placeholder' => ''
603
+ ),
604
+ $reason_found_better_plugin,
605
+ $reason_temporary_deactivation,
606
+ $reason_other
607
+ ),
608
+ 'short-term' => array(
609
+ array(
610
+ 'id' => 10,
611
+ 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
612
+ 'input_type' => '',
613
+ 'input_placeholder' => ''
614
+ ),
615
+ $reason_found_better_plugin,
616
+ array(
617
+ 'id' => 11,
618
+ 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
619
+ 'input_type' => 'textarea',
620
+ 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
621
+ ),
622
+ array(
623
+ 'id' => 12,
624
+ 'text' => __fs( 'reason-not-working', $this->_slug ),
625
+ 'input_type' => 'textarea',
626
+ 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
627
+ ),
628
+ array(
629
+ 'id' => 13,
630
+ 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
631
+ 'input_type' => 'textarea',
632
+ 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
633
+ ),
634
+ array(
635
+ 'id' => 14,
636
+ 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
637
+ 'input_type' => 'textarea',
638
+ 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
639
+ ),
640
+ $reason_temporary_deactivation,
641
+ $reason_other
642
+ )
643
+ );
644
+
645
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
646
+
647
+ return $uninstall_reasons[ $user_type ];
648
+ }
649
+
650
+ /**
651
+ * Called after the user has submitted his reason for deactivating the plugin.
652
+ *
653
+ * @author Leo Fajardo (@leorw)
654
+ * @since 1.1.2
655
+ */
656
+ function _submit_uninstall_reason_action() {
657
+ if ( ! isset( $_POST['reason_id'] ) ) {
658
+ exit;
659
+ }
660
+
661
+ $reason_info = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
662
+
663
+ $reason = (object) array(
664
+ 'id' => $_POST['reason_id'],
665
+ 'info' => substr( $reason_info, 0, 128 )
666
+ );
667
+
668
+ $this->_storage->store( 'uninstall_reason', $reason );
669
+
670
+ // Print '1' for successful operation.
671
+ echo 1;
672
+ exit;
673
+ }
674
+
675
+ #endregion Deactivation Feedback Form ------------------------------------------------------------------
676
+
677
+ #region Instance ------------------------------------------------------------------
678
+
679
+ /**
680
+ * Main singleton instance.
681
+ *
682
+ * @author Vova Feldman (@svovaf)
683
+ * @since 1.0.0
684
+ *
685
+ * @param $slug
686
+ *
687
+ * @return Freemius
688
+ */
689
+ static function instance( $slug ) {
690
+ $slug = strtolower( $slug );
691
+
692
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
693
+ if ( 0 === count( self::$_instances ) ) {
694
+ self::_load_required_static();
695
+ }
696
+
697
+ self::$_instances[ $slug ] = new Freemius( $slug );
698
+ }
699
+
700
+ return self::$_instances[ $slug ];
701
+ }
702
+
703
+ /**
704
+ * @author Vova Feldman (@svovaf)
705
+ * @since 1.0.6
706
+ *
707
+ * @param string|number $slug_or_id
708
+ *
709
+ * @return bool
710
+ */
711
+ private static function has_instance( $slug_or_id ) {
712
+ return ! is_numeric( $slug_or_id ) ?
713
+ isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
714
+ ( false !== self::get_instance_by_id( $slug_or_id ) );
715
+ }
716
+
717
+ /**
718
+ * @author Vova Feldman (@svovaf)
719
+ * @since 1.0.6
720
+ *
721
+ * @param $id
722
+ *
723
+ * @return false|Freemius
724
+ */
725
+ static function get_instance_by_id( $id ) {
726
+ foreach ( self::$_instances as $slug => $instance ) {
727
+ if ( $id == $instance->get_id() ) {
728
+ return $instance;
729
+ }
730
+ }
731
+
732
+ return false;
733
+ }
734
+
735
+ /**
736
+ *
737
+ * @author Vova Feldman (@svovaf)
738
+ * @since 1.0.1
739
+ *
740
+ * @param $plugin_file
741
+ *
742
+ * @return false|Freemius
743
+ */
744
+ static function get_instance_by_file( $plugin_file ) {
745
+ $slug = self::find_slug_by_basename( $plugin_file );
746
+
747
+ return ( false !== $slug ) ?
748
+ self::instance( $slug ) :
749
+ false;
750
+ }
751
+
752
+ /**
753
+ * @author Vova Feldman (@svovaf)
754
+ * @since 1.0.6
755
+ *
756
+ * @return false|Freemius
757
+ */
758
+ function get_parent_instance() {
759
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
760
+ }
761
+
762
+ /**
763
+ * @author Vova Feldman (@svovaf)
764
+ * @since 1.0.6
765
+ *
766
+ * @param $slug_or_id
767
+ *
768
+ * @return bool|Freemius
769
+ */
770
+ function get_addon_instance( $slug_or_id ) {
771
+ return ! is_numeric( $slug_or_id ) ?
772
+ self::instance( strtolower( $slug_or_id ) ) :
773
+ self::get_instance_by_id( $slug_or_id );
774
+ }
775
+
776
+ #endregion ------------------------------------------------------------------
777
+
778
+ /**
779
+ * @author Vova Feldman (@svovaf)
780
+ * @since 1.0.6
781
+ *
782
+ * @return bool
783
+ */
784
+ function is_parent_plugin_installed() {
785
+ return self::has_instance( $this->_plugin->parent_plugin_id );
786
+ }
787
+
788
+ /**
789
+ * Check if add-on parent plugin in activation mode.
790
+ *
791
+ * @author Vova Feldman (@svovaf)
792
+ * @since 1.0.7
793
+ *
794
+ * @return bool
795
+ */
796
+ function is_parent_in_activation() {
797
+ $parent_fs = $this->get_parent_instance();
798
+ if ( ! is_object( $parent_fs ) ) {
799
+ return false;
800
+ }
801
+
802
+ return ( $parent_fs->is_activation_mode() );
803
+ }
804
+
805
+ /**
806
+ * Is plugin in activation mode.
807
+ *
808
+ * @author Vova Feldman (@svovaf)
809
+ * @since 1.0.7
810
+ *
811
+ * @return bool
812
+ */
813
+ function is_activation_mode() {
814
+ return (
815
+ $this->is_on() &&
816
+ ! $this->is_registered() &&
817
+ ( ! $this->enable_anonymous() ||
818
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
819
+ );
820
+ }
821
+
822
+ /**
823
+ * Get collection of all active plugins.
824
+ *
825
+ * @author Vova Feldman (@svovaf)
826
+ * @since 1.0.9
827
+ *
828
+ * @return array[string]array
829
+ */
830
+ private static function get_active_plugins() {
831
+ self::require_plugin_essentials();
832
+
833
+ $active_plugin = array();
834
+ $all_plugins = get_plugins();
835
+ $active_plugins_basenames = get_option( 'active_plugins' );
836
+
837
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
838
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
839
+ }
840
+
841
+ return $active_plugin;
842
+ }
843
+
844
+ /**
845
+ * Get collection of all plugins.
846
+ *
847
+ * @author Vova Feldman (@svovaf)
848
+ * @since 1.1.8
849
+ *
850
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
851
+ */
852
+ private static function get_all_plugins() {
853
+ self::require_plugin_essentials();
854
+
855
+ $all_plugins = get_plugins();
856
+ $active_plugins_basenames = get_option( 'active_plugins' );
857
+
858
+ foreach ( $all_plugins as $basename => &$data ) {
859
+ // By default set to inactive (next foreach update the active plugins).
860
+ $data['is_active'] = false;
861
+ // Enrich with plugin slug.
862
+ $data['slug'] = self::get_plugin_slug( $basename );
863
+ }
864
+
865
+ // Flag active plugins.
866
+ foreach ( $active_plugins_basenames as $basename ) {
867
+ if ( isset( $all_plugins[ $basename ] ) ) {
868
+ $all_plugins[ $basename ]['is_active'] = true;
869
+ }
870
+ }
871
+
872
+ return $all_plugins;
873
+ }
874
+
875
+
876
+ /**
877
+ * Cached result of get_site_transient( 'update_plugins' )
878
+ *
879
+ * @author Vova Feldman (@svovaf)
880
+ * @since 1.1.8
881
+ *
882
+ * @var object
883
+ */
884
+ private static $_plugins_info;
885
+
886
+ /**
887
+ * Helper function to get specified plugin's slug.
888
+ *
889
+ * @author Vova Feldman (@svovaf)
890
+ * @since 1.1.8
891
+ *
892
+ * @param $basename
893
+ *
894
+ * @return string
895
+ */
896
+ private static function get_plugin_slug( $basename ) {
897
+ if ( ! isset( self::$_plugins_info ) ) {
898
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
899
+ }
900
+
901
+ $slug = '';
902
+
903
+ if ( is_object( self::$_plugins_info ) ) {
904
+ if ( isset( self::$_plugins_info->no_update ) &&
905
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
906
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
907
+ ) {
908
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
909
+ } else if ( isset( self::$_plugins_info->response ) &&
910
+ isset( self::$_plugins_info->response[ $basename ] ) &&
911
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
912
+ ) {
913
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
914
+ }
915
+ }
916
+
917
+ if ( empty( $slug ) ) {
918
+ // Try to find slug from FS data.
919
+ $slug = self::find_slug_by_basename( $basename );
920
+ }
921
+
922
+ if ( empty( $slug ) ) {
923
+ // Fallback to plugin's folder name.
924
+ $slug = dirname( $basename );
925
+ }
926
+
927
+ return $slug;
928
+ }
929
+
930
+ private static $_statics_loaded = false;
931
+
932
+ /**
933
+ * Load static resources.
934
+ *
935
+ * @author Vova Feldman (@svovaf)
936
+ * @since 1.0.1
937
+ */
938
+ private static function _load_required_static() {
939
+ if ( self::$_statics_loaded ) {
940
+ return;
941
+ }
942
+
943
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
944
+
945
+ self::$_static_logger->entrance();
946
+
947
+ self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
948
+
949
+ self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
950
+
951
+ // Configure which Freemius powered plugins should be auto updated.
952
+ // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
953
+
954
+ add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
955
+
956
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
957
+
958
+ self::$_statics_loaded = true;
959
+ }
960
+
961
+ #region Debugging ------------------------------------------------------------------
962
+
963
+ /**
964
+ * @author Vova Feldman (@svovaf)
965
+ * @since 1.0.8
966
+ */
967
+ static function add_debug_page() {
968
+ if ( ! current_user_can( 'activate_plugins' ) ) {
969
+ return;
970
+ }
971
+
972
+ self::$_static_logger->entrance();
973
+
974
+ $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
975
+
976
+ if ( WP_FS__DEV_MODE ) {
977
+ // Add top-level debug menu item.
978
+ $hook = add_menu_page(
979
+ $title,
980
+ $title,
981
+ 'manage_options',
982
+ 'freemius',
983
+ array( 'Freemius', '_debug_page_render' )
984
+ );
985
+ } else {
986
+ // Add hidden debug page.
987
+ $hook = add_submenu_page(
988
+ null,
989
+ $title,
990
+ $title,
991
+ 'manage_options',
992
+ 'freemius',
993
+ array( 'Freemius', '_debug_page_render' )
994
+ );
995
+ }
996
+
997
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
998
+ }
999
+
1000
+ /**
1001
+ * @author Vova Feldman (@svovaf)
1002
+ * @since 1.1.7.3
1003
+ */
1004
+ static function _toggle_debug_mode() {
1005
+ if ( in_array( $_POST['is_on'], array( 0, 1 ) ) ) {
1006
+ update_option( 'fs_debug_mode', $_POST['is_on'] );
1007
+ }
1008
+
1009
+ exit;
1010
+ }
1011
+
1012
+ /**
1013
+ * @author Vova Feldman (@svovaf)
1014
+ * @since 1.0.8
1015
+ */
1016
+ static function _debug_page_actions() {
1017
+ self::_clean_admin_content_section();
1018
+
1019
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
1020
+ check_admin_referer( 'restart_freemius' );
1021
+
1022
+ self::$_accounts->clear( true );
1023
+
1024
+
1025
+ return;
1026
+ }
1027
+ }
1028
+
1029
+ /**
1030
+ * @author Vova Feldman (@svovaf)
1031
+ * @since 1.0.8
1032
+ */
1033
+ static function _debug_page_render() {
1034
+ self::$_static_logger->entrance();
1035
+
1036
+ $sites = self::get_all_sites();
1037
+ $users = self::get_all_users();
1038
+ $addons = self::get_all_addons();
1039
+ $account_addons = self::get_all_account_addons();
1040
+
1041
+ // $plans = self::get_all_plans();
1042
+ // $licenses = self::get_all_licenses();
1043
+
1044
+ $vars = array(
1045
+ 'sites' => $sites,
1046
+ 'users' => $users,
1047
+ 'addons' => $addons,
1048
+ 'account_addons' => $account_addons,
1049
+ );
1050
+
1051
+ fs_enqueue_local_style( 'fs_account', '/admin/debug.css' );
1052
+ fs_require_once_template( 'debug.php', $vars );
1053
+ }
1054
+
1055
+ #endregion ------------------------------------------------------------------
1056
+
1057
+ #region Connectivity Issues ------------------------------------------------------------------
1058
+
1059
+ /**
1060
+ * Check if Freemius should be turned on for the current plugin install.
1061
+ *
1062
+ * Note:
1063
+ * $this->_is_on is updated in has_api_connectivity()
1064
+ *
1065
+ * @author Vova Feldman (@svovaf)
1066
+ * @since 1.0.9
1067
+ *
1068
+ * @return bool
1069
+ */
1070
+ function is_on() {
1071
+ self::$_static_logger->entrance();
1072
+
1073
+ if ( isset( $this->_is_on ) ) {
1074
+ return $this->_is_on;
1075
+ }
1076
+
1077
+ // If already installed or pending then sure it's on :)
1078
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
1079
+ $this->_is_on = true;
1080
+
1081
+ return true;
1082
+ }
1083
+
1084
+ return false;
1085
+ }
1086
+
1087
+ /**
1088
+ * @author Vova Feldman (@svovaf)
1089
+ * @since 1.1.7.3
1090
+ *
1091
+ * @param bool $flush_if_no_connectivity
1092
+ *
1093
+ * @return bool
1094
+ */
1095
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1096
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
1097
+ // Connectivity test was never executed, or cache was cleared.
1098
+ return true;
1099
+ }
1100
+
1101
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1102
+ if ( WP_FS__IS_HTTP_REQUEST ) {
1103
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1104
+ // Domain changed.
1105
+ return true;
1106
+ }
1107
+
1108
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1109
+ // Server IP changed.
1110
+ return true;
1111
+ }
1112
+ }
1113
+ }
1114
+
1115
+ if ( $this->_storage->connectivity_test['is_connected'] &&
1116
+ $this->_storage->connectivity_test['is_active']
1117
+ ) {
1118
+ // API connected and Freemius is active - no need to run connectivity check.
1119
+ return false;
1120
+ }
1121
+
1122
+ if ( $flush_if_no_connectivity ) {
1123
+ /**
1124
+ * If explicitly asked to flush when no connectivity - do it only
1125
+ * if at least 10 sec passed from the last API connectivity test.
1126
+ */
1127
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
1128
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
1129
+ }
1130
+
1131
+ /**
1132
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
1133
+ */
1134
+ $version = $this->get_plugin_version();
1135
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
1136
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
1137
+ return true;
1138
+ }
1139
+
1140
+ return false;
1141
+ }
1142
+
1143
+ /**
1144
+ * @author Vova Feldman (@svovaf)
1145
+ * @since 1.1.7.4
1146
+ *
1147
+ * @return object|false
1148
+ */
1149
+ private function ping() {
1150
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
1151
+ return false;
1152
+ }
1153
+
1154
+ $version = $this->get_plugin_version();
1155
+
1156
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
1157
+
1158
+ return $this->get_api_plugin_scope()->ping(
1159
+ $this->get_anonymous_id(),
1160
+ array(
1161
+ 'is_update' => json_encode( $is_update ),
1162
+ 'version' => $version,
1163
+ 'sdk' => $this->version,
1164
+ 'is_admin' => json_encode( is_admin() ),
1165
+ 'is_ajax' => json_encode( $this->is_ajax() ),
1166
+ 'is_cron' => json_encode( $this->is_cron() ),
1167
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
1168
+ )
1169
+ );
1170
+ }
1171
+
1172
+ /**
1173
+ * Check if there's any connectivity issue to Freemius API.
1174
+ *
1175
+ * @author Vova Feldman (@svovaf)
1176
+ * @since 1.0.9
1177
+ *
1178
+ * @param bool $flush_if_no_connectivity
1179
+ *
1180
+ * @return bool
1181
+ */
1182
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
1183
+ $this->_logger->entrance();
1184
+
1185
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
1186
+ return $this->_has_api_connection;
1187
+ }
1188
+
1189
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
1190
+ isset( $this->_storage->connectivity_test ) &&
1191
+ true === $this->_storage->connectivity_test['is_connected']
1192
+ ) {
1193
+ unset( $this->_storage->connectivity_test );
1194
+ }
1195
+
1196
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
1197
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
1198
+ /**
1199
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
1200
+ */
1201
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
1202
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1203
+
1204
+ return $this->_has_api_connection;
1205
+ }
1206
+
1207
+ $pong = $this->ping();
1208
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1209
+
1210
+ if ( ! $is_connected ) {
1211
+ // API failure.
1212
+ $this->_add_connectivity_issue_message( $pong );
1213
+ }
1214
+
1215
+ $this->store_connectivity_info( $pong, $is_connected );
1216
+
1217
+ return $this->_has_api_connection;
1218
+ }
1219
+
1220
+ /**
1221
+ * @author Vova Feldman (@svovaf)
1222
+ * @since 1.1.7.4
1223
+ *
1224
+ * @param object $pong
1225
+ * @param bool $is_connected
1226
+ */
1227
+ private function store_connectivity_info( $pong, $is_connected ) {
1228
+ $this->_logger->entrance();
1229
+
1230
+ $version = $this->get_plugin_version();
1231
+
1232
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
1233
+ $is_active = false;
1234
+ } else {
1235
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
1236
+ }
1237
+
1238
+ $is_active = $this->apply_filters(
1239
+ 'is_on',
1240
+ $is_active,
1241
+ $this->is_plugin_update(),
1242
+ $version
1243
+ );
1244
+
1245
+ $this->_storage->connectivity_test = array(
1246
+ 'is_connected' => $is_connected,
1247
+ 'host' => $_SERVER['HTTP_HOST'],
1248
+ 'server_ip' => WP_FS__REMOTE_ADDR,
1249
+ 'is_active' => $is_active,
1250
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
1251
+ // Last version with connectivity attempt.
1252
+ 'version' => $version,
1253
+ );
1254
+
1255
+ $this->_has_api_connection = $is_connected;
1256
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1257
+ }
1258
+
1259
+ /**
1260
+ * Force turning Freemius on.
1261
+ *
1262
+ * @author Vova Feldman (@svovaf)
1263
+ * @since 1.1.8.1
1264
+ *
1265
+ * @return bool TRUE if successfully turned on.
1266
+ */
1267
+ private function turn_on() {
1268
+ $this->_logger->entrance();
1269
+
1270
+ if ($this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
1271
+ return false;
1272
+ }
1273
+
1274
+ $updated_connectivity = $this->_storage->connectivity_test;
1275
+ $updated_connectivity['is_active'] = true;
1276
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
1277
+ $this->_storage->connectivity_test = $updated_connectivity;
1278
+
1279
+ $this->_is_on = true;
1280
+
1281
+ return true;
1282
+ }
1283
+
1284
+ /**
1285
+ * Anonymous and unique site identifier (Hash).
1286
+ *
1287
+ * @author Vova Feldman (@svovaf)
1288
+ * @since 1.1.0
1289
+ *
1290
+ * @return string
1291
+ */
1292
+ function get_anonymous_id() {
1293
+ $unique_id = self::$_accounts->get_option( 'unique_id' );
1294
+
1295
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
1296
+ $key = get_site_url();
1297
+
1298
+ // If localhost, assign microtime instead of domain.
1299
+ if ( WP_FS__IS_LOCALHOST ||
1300
+ false !== strpos( $key, 'localhost' ) ||
1301
+ false === strpos( $key, '.' )
1302
+ ) {
1303
+ $key = microtime();
1304
+ }
1305
+
1306
+ $unique_id = md5( $key );
1307
+
1308
+ self::$_accounts->set_option( 'unique_id', $unique_id, true );
1309
+ }
1310
+
1311
+ $this->_logger->departure( $unique_id );
1312
+
1313
+ return $unique_id;
1314
+ }
1315
+
1316
+ /**
1317
+ * @author Vova Feldman (@svovaf)
1318
+ * @since 1.1.7.4
1319
+ *
1320
+ * @return \WP_User
1321
+ */
1322
+ static function _get_current_wp_user() {
1323
+ self::require_pluggable_essentials();
1324
+
1325
+ return wp_get_current_user();
1326
+ }
1327
+
1328
+ /**
1329
+ * Generate API connectivity issue message.
1330
+ *
1331
+ * @author Vova Feldman (@svovaf)
1332
+ * @since 1.0.9
1333
+ *
1334
+ * @param mixed $api_result
1335
+ * @param bool $is_first_failure
1336
+ */
1337
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
1338
+ if ( $this->_enable_anonymous ) {
1339
+ // Don't add message if can run anonymously.
1340
+ return;
1341
+ }
1342
+
1343
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
1344
+ require_once( ABSPATH . 'wp-includes/functions.php' );
1345
+ }
1346
+
1347
+ $current_user = self::_get_current_wp_user();
1348
+ // $admin_email = get_option( 'admin_email' );
1349
+ $admin_email = $current_user->user_email;
1350
+
1351
+ $message = false;
1352
+ if ( is_object( $api_result ) &&
1353
+ isset( $api_result->error ) &&
1354
+ isset( $api_result->error->code )
1355
+ ) {
1356
+ switch ( $api_result->error->code ) {
1357
+ case 'curl_missing':
1358
+ $message = sprintf(
1359
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1360
+ __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1361
+ ' %s',
1362
+ '<b>' . $this->get_plugin_name() . '</b>',
1363
+ sprintf(
1364
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1365
+ sprintf(
1366
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1367
+ __fs( 'curl-missing-no-clue-title', $this->_slug ),
1368
+ ' - ' . sprintf(
1369
+ __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1370
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1371
+ )
1372
+ ),
1373
+ sprintf(
1374
+ '<b>%s</b> - %s',
1375
+ __fs( 'sysadmin-title', $this->_slug ),
1376
+ __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1377
+ ),
1378
+ sprintf(
1379
+ '<a href="%s"><b>%s</b></a>%s',
1380
+ 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 ),
1381
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1382
+ ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1383
+ )
1384
+ )
1385
+ );
1386
+ break;
1387
+ case 'cloudflare_ddos_protection':
1388
+ $message = sprintf(
1389
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1390
+ __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1391
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1392
+ ' %s',
1393
+ '<b>' . $this->get_plugin_name() . '</b>',
1394
+ sprintf(
1395
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1396
+ sprintf(
1397
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1398
+ __fs( 'fix-issue-title', $this->_slug ),
1399
+ ' - ' . sprintf(
1400
+ __fs( 'fix-issue-desc', $this->_slug ),
1401
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1402
+ )
1403
+ ),
1404
+ sprintf(
1405
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1406
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1407
+ __fs( 'install-previous-title', $this->_slug ),
1408
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1409
+ ),
1410
+ sprintf(
1411
+ '<a href="%s"><b>%s</b></a>%s',
1412
+ 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 ),
1413
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1414
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1415
+ )
1416
+ )
1417
+ );
1418
+ break;
1419
+ case 'squid_cache_block':
1420
+ $message = sprintf(
1421
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1422
+ __fs( 'squid-blocks-connection-message', $this->_slug ) .
1423
+ ' %s',
1424
+ '<b>' . $this->get_plugin_name() . '</b>',
1425
+ sprintf(
1426
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1427
+ sprintf(
1428
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1429
+ __fs( 'squid-no-clue-title', $this->_slug ),
1430
+ ' - ' . sprintf(
1431
+ __fs( 'squid-no-clue-desc', $this->_slug ),
1432
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1433
+ )
1434
+ ),
1435
+ sprintf(
1436
+ '<b>%s</b> - %s',
1437
+ __fs( 'sysadmin-title', $this->_slug ),
1438
+ sprintf(
1439
+ __fs( 'squid-sysadmin-desc', $this->_slug ),
1440
+ // We use a filter since the plugin might require additional API connectivity.
1441
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1442
+ ),
1443
+ sprintf(
1444
+ '<a href="%s"><b>%s</b></a>%s',
1445
+ 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 ),
1446
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1447
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1448
+ )
1449
+ )
1450
+ );
1451
+ break;
1452
+ // default:
1453
+ // $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1454
+ // break;
1455
+ }
1456
+ }
1457
+
1458
+ $message_id = 'failed_connect_api';
1459
+ $type = 'error';
1460
+
1461
+ if ( false === $message ) {
1462
+ if ( $is_first_failure ) {
1463
+ // First attempt failed.
1464
+ $message = sprintf(
1465
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1466
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1467
+ __fs( 'connectivity-test-maybe-temporary', $this->_slug ) . '<br><br>' .
1468
+ '%s',
1469
+ '<b>' . $this->get_plugin_name() . '</b>',
1470
+ sprintf(
1471
+ '<div id="fs_firewall_issue_options">%s %s</div>',
1472
+ sprintf(
1473
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
1474
+ __fs( 'yes-do-your-thing', $this->_slug )
1475
+ ),
1476
+ sprintf(
1477
+ '<a href="%s" class="button">%s</a>',
1478
+ 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 ),
1479
+ __fs( 'no-deactivate', $this->_slug )
1480
+ )
1481
+ )
1482
+ );
1483
+
1484
+ $message_id = 'failed_connect_api_first';
1485
+ $type = 'promotion';
1486
+ } else {
1487
+ // Second connectivity attempt failed.
1488
+ $message = sprintf(
1489
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1490
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1491
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1492
+ ' %s',
1493
+ '<b>' . $this->get_plugin_name() . '</b>',
1494
+ sprintf(
1495
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1496
+ sprintf(
1497
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1498
+ __fs( 'fix-issue-title', $this->_slug ),
1499
+ ' - ' . sprintf(
1500
+ __fs( 'fix-issue-desc', $this->_slug ),
1501
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1502
+ )
1503
+ ),
1504
+ sprintf(
1505
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1506
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1507
+ __fs( 'install-previous-title', $this->_slug ),
1508
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1509
+ ),
1510
+ sprintf(
1511
+ '<a href="%s"><b>%s</b></a>%s',
1512
+ 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 ),
1513
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1514
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1515
+ )
1516
+ )
1517
+ );
1518
+ }
1519
+ }
1520
+
1521
+ $this->_admin_notices->add_sticky(
1522
+ $message,
1523
+ $message_id,
1524
+ __fs( 'oops', $this->_slug ) . '...',
1525
+ $type
1526
+ );
1527
+ }
1528
+
1529
+ /**
1530
+ * Handle user request to resolve connectivity issue.
1531
+ * This method will send an email to Freemius API technical staff for resolution.
1532
+ * The email will contain server's info and installed plugins (might be caching issue).
1533
+ *
1534
+ * @author Vova Feldman (@svovaf)
1535
+ * @since 1.0.9
1536
+ */
1537
+ function _email_about_firewall_issue() {
1538
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1539
+
1540
+ $pong = $this->ping();
1541
+
1542
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1543
+
1544
+ if ( $is_connected ) {
1545
+ $this->store_connectivity_info( $pong, $is_connected );
1546
+
1547
+ echo $this->get_after_plugin_activation_redirect_url();
1548
+ exit;
1549
+ }
1550
+
1551
+ $current_user = self::_get_current_wp_user();
1552
+ $admin_email = $current_user->user_email;
1553
+
1554
+ $error_type = fs_request_get( 'error_type', 'general' );
1555
+
1556
+ switch ( $error_type ) {
1557
+ case 'squid':
1558
+ $title = 'Squid ACL Blocking Issue';
1559
+ break;
1560
+ case 'cloudflare':
1561
+ $title = 'CloudFlare Blocking Issue';
1562
+ break;
1563
+ default:
1564
+ $title = 'API Connectivity Issue';
1565
+ break;
1566
+ }
1567
+
1568
+ $custom_email_sections = array();
1569
+
1570
+ if ( 'squid' === $error_type ) {
1571
+ // Override the 'Site' email section.
1572
+ $custom_email_sections['site'] = array(
1573
+ 'rows' => array(
1574
+ 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1575
+ )
1576
+ );
1577
+ }
1578
+
1579
+ // Add 'API Error' custom email section.
1580
+ $custom_email_sections['api_error'] = array(
1581
+ 'title' => 'API Error',
1582
+ 'rows' => array(
1583
+ 'ping' => array( is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong ) )
1584
+ )
1585
+ );
1586
+
1587
+ // Add PHP info for deeper investigation.
1588
+ ob_start();
1589
+ phpinfo();
1590
+ $php_info = ob_get_clean();
1591
+ $custom_email_sections['php_info'] = array(
1592
+ 'title' => 'PHP Info',
1593
+ 'rows' => array(
1594
+ 'info' => array( $php_info )
1595
+ )
1596
+ );
1597
+
1598
+ // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1599
+ $this->send_email(
1600
+ 'api@freemius.com', // recipient
1601
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
1602
+ $custom_email_sections,
1603
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
1604
+ );
1605
+
1606
+ $this->_admin_notices->add_sticky(
1607
+ sprintf(
1608
+ __fs( 'fix-request-sent-message', $this->_slug ),
1609
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1610
+ ),
1611
+ 'server_details_sent'
1612
+ );
1613
+
1614
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
1615
+
1616
+ echo "1";
1617
+ exit;
1618
+ }
1619
+
1620
+ /**
1621
+ * Handle connectivity test retry approved by the user.
1622
+ *
1623
+ * @author Vova Feldman (@svovaf)
1624
+ * @since 1.1.7.4
1625
+ */
1626
+ function _retry_connectivity_test() {
1627
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
1628
+
1629
+ $pong = $this->ping();
1630
+
1631
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1632
+
1633
+ if ( $is_connected ) {
1634
+ $this->store_connectivity_info( $pong, $is_connected );
1635
+
1636
+ echo $this->get_after_plugin_activation_redirect_url();
1637
+ } else {
1638
+ // Add connectivity issue message after 2nd failed attempt.
1639
+ $this->_add_connectivity_issue_message( $pong, false );
1640
+
1641
+ echo "1";
1642
+ }
1643
+
1644
+ exit;
1645
+ }
1646
+
1647
+ static function _add_firewall_issues_javascript() {
1648
+ $params = array();
1649
+ fs_require_once_template( 'firewall-issues-js.php', $params );
1650
+ }
1651
+
1652
+ #endregion Connectivity Issues ------------------------------------------------------------------
1653
+
1654
+ #region Email ------------------------------------------------------------------
1655
+
1656
+ /**
1657
+ * Generates and sends an HTML email with customizable sections.
1658
+ *
1659
+ * @author Leo Fajardo (@leorw)
1660
+ * @since 1.1.2
1661
+ *
1662
+ * @param string $to_address
1663
+ * @param string $subject
1664
+ * @param array $sections
1665
+ * @param array $headers
1666
+ *
1667
+ * @return bool Whether the email contents were sent successfully.
1668
+ */
1669
+ private function send_email(
1670
+ $to_address,
1671
+ $subject,
1672
+ $sections = array(),
1673
+ $headers = array()
1674
+ ) {
1675
+ $default_sections = $this->get_email_sections();
1676
+
1677
+ // Insert new sections or replace the default email sections.
1678
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
1679
+ foreach ( $sections as $section_id => $custom_section ) {
1680
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
1681
+ // If the section does not exist, add it.
1682
+ $default_sections[ $section_id ] = $custom_section;
1683
+ } else {
1684
+ // If the section already exists, override it.
1685
+ $current_section = $default_sections[ $section_id ];
1686
+
1687
+ // Replace the current section's title if a custom section title exists.
1688
+ if ( isset( $custom_section['title'] ) ) {
1689
+ $current_section['title'] = $custom_section['title'];
1690
+ }
1691
+
1692
+ // Insert new rows under the current section or replace the default rows.
1693
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1694
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
1695
+ $current_section['rows'][ $row_id ] = $row;
1696
+ }
1697
+ }
1698
+
1699
+ $default_sections[ $section_id ] = $current_section;
1700
+ }
1701
+ }
1702
+ }
1703
+
1704
+ $vars = array( 'sections' => $default_sections );
1705
+ $message = fs_get_template( 'email.php', $vars );
1706
+
1707
+ // Set the type of email to HTML.
1708
+ $headers[] = 'Content-type: text/html';
1709
+
1710
+ $header_string = implode( "\r\n", $headers );
1711
+
1712
+ return wp_mail(
1713
+ $to_address,
1714
+ $subject,
1715
+ $message,
1716
+ $header_string
1717
+ );
1718
+ }
1719
+
1720
+ /**
1721
+ * Generates the data for the sections of the email content.
1722
+ *
1723
+ * @author Leo Fajardo (@leorw)
1724
+ * @since 1.1.2
1725
+ *
1726
+ * @return array
1727
+ */
1728
+ private function get_email_sections() {
1729
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
1730
+ $current_user = self::_get_current_wp_user();
1731
+
1732
+ // Retrieve the cURL version information so that we can get the version number below.
1733
+ $curl_version_information = curl_version();
1734
+
1735
+ $active_plugin = self::get_active_plugins();
1736
+
1737
+ // Generate the list of active plugins separated by new line.
1738
+ $active_plugin_string = '';
1739
+ foreach ( $active_plugin as $plugin ) {
1740
+ $active_plugin_string .= sprintf(
1741
+ '<a href="%s">%s</a> [v%s]<br>',
1742
+ $plugin['PluginURI'],
1743
+ $plugin['Name'],
1744
+ $plugin['Version']
1745
+ );
1746
+ }
1747
+
1748
+ $server_ip = WP_FS__REMOTE_ADDR;
1749
+
1750
+ // Generate the default email sections.
1751
+ $sections = array(
1752
+ 'sdk' => array(
1753
+ 'title' => 'SDK',
1754
+ 'rows' => array(
1755
+ 'fs_version' => array( 'FS Version', $this->version ),
1756
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
1757
+ )
1758
+ ),
1759
+ 'plugin' => array(
1760
+ 'title' => 'Plugin',
1761
+ 'rows' => array(
1762
+ 'name' => array( 'Name', $this->get_plugin_name() ),
1763
+ 'version' => array( 'Version', $this->get_plugin_version() )
1764
+ )
1765
+ ),
1766
+ 'site' => array(
1767
+ 'title' => 'Site',
1768
+ 'rows' => array(
1769
+ 'unique_id' => array( 'Address', $this->get_anonymous_id() ),
1770
+ 'address' => array( 'Address', site_url() ),
1771
+ 'host' => array(
1772
+ 'HTTP_HOST',
1773
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
1774
+ ),
1775
+ 'server_addr' => array(
1776
+ 'SERVER_ADDR',
1777
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
1778
+ )
1779
+ )
1780
+ ),
1781
+ 'user' => array(
1782
+ 'title' => 'User',
1783
+ 'rows' => array(
1784
+ 'email' => array( 'Email', $current_user->user_email ),
1785
+ 'first' => array( 'First', $current_user->user_firstname ),
1786
+ 'last' => array( 'Last', $current_user->user_lastname )
1787
+ )
1788
+ ),
1789
+ 'plugins' => array(
1790
+ 'title' => 'Plugins',
1791
+ 'rows' => array(
1792
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
1793
+ )
1794
+ ),
1795
+ );
1796
+
1797
+ // Allow the sections to be modified by other code.
1798
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
1799
+
1800
+ return $sections;
1801
+ }
1802
+
1803
+ #endregion Email ------------------------------------------------------------------
1804
+
1805
+ #region Initialization ------------------------------------------------------------------
1806
+
1807
+ /**
1808
+ * Init plugin's Freemius instance.
1809
+ *
1810
+ * @author Vova Feldman (@svovaf)
1811
+ * @since 1.0.1
1812
+ *
1813
+ * @param number $id
1814
+ * @param string $public_key
1815
+ * @param bool $is_live
1816
+ * @param bool $is_premium
1817
+ */
1818
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
1819
+ $this->_logger->entrance();
1820
+
1821
+ $this->dynamic_init( array(
1822
+ 'id' => $id,
1823
+ 'public_key' => $public_key,
1824
+ 'is_live' => $is_live,
1825
+ 'is_premium' => $is_premium,
1826
+ ) );
1827
+ }
1828
+
1829
+ /**
1830
+ * Dynamic initiator, originally created to support initiation
1831
+ * with parent_id for add-ons.
1832
+ *
1833
+ * @author Vova Feldman (@svovaf)
1834
+ * @since 1.0.6
1835
+ *
1836
+ * @param array $plugin_info
1837
+ *
1838
+ * @throws Freemius_Exception
1839
+ */
1840
+ function dynamic_init( array $plugin_info ) {
1841
+ $this->_logger->entrance();
1842
+
1843
+ $this->parse_settings( $plugin_info );
1844
+
1845
+ if ( $this->should_stop_execution() ) {
1846
+ return;
1847
+ }
1848
+
1849
+ if ( ! $this->is_registered() ) {
1850
+ if ( $this->is_anonymous() ) {
1851
+ // If user skipped, no need to test connectivity.
1852
+ $this->_has_api_connection = true;
1853
+ $this->_is_on = true;
1854
+ } else {
1855
+ if ( ! $this->has_api_connectivity() ) {
1856
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
1857
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
1858
+ ) {
1859
+ if ( ! $this->_enable_anonymous ) {
1860
+ // If anonymous mode is disabled, add firewall admin-notice message.
1861
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
1862
+
1863
+ add_action( "wp_ajax_{$this->_slug}_resolve_firewall_issues", array(
1864
+ &$this,
1865
+ '_email_about_firewall_issue'
1866
+ ) );
1867
+
1868
+ add_action( "wp_ajax_{$this->_slug}_retry_connectivity_test", array(
1869
+ &$this,
1870
+ '_retry_connectivity_test'
1871
+ ) );
1872
+ }
1873
+ }
1874
+
1875
+ return;
1876
+ } else {
1877
+ $this->_admin_notices->remove_sticky( array(
1878
+ 'failed_connect_api_first',
1879
+ 'failed_connect_api',
1880
+ ) );
1881
+
1882
+ if ( $this->_anonymous_mode ) {
1883
+ // Simulate anonymous mode.
1884
+ $this->_is_anonymous = true;
1885
+ }
1886
+ }
1887
+ }
1888
+
1889
+ // Check if Freemius is on for the current plugin.
1890
+ // This MUST be executed after all the plugin variables has been loaded.
1891
+ if ( ! $this->is_on() ) {
1892
+ return;
1893
+ }
1894
+ }
1895
+
1896
+ if ( $this->has_api_connectivity() && $this->is_user_in_admin() ) {
1897
+ /**
1898
+ * Schedule daily data sync cron if:
1899
+ *
1900
+ * 1. User opted-in (for tracking).
1901
+ * 2. If plugin has add-ons (update add-ons data).
1902
+ * 3. If skipped, but later upgraded (opted-in via upgrade).
1903
+ *
1904
+ * @author Vova Feldman (@svovaf)
1905
+ * @since 1.1.7.3
1906
+ *
1907
+ */
1908
+ if ( $this->is_registered() ||
1909
+ ( ! $this->is_activation_mode() && $this->_has_addons )
1910
+ ) {
1911
+
1912
+ $this->hook_callback_to_sync_cron();
1913
+
1914
+ if ( ! $this->is_sync_cron_on() ) {
1915
+ $this->schedule_sync_cron();
1916
+ }
1917
+ }
1918
+
1919
+ /**
1920
+ * Check if requested for manual blocking background sync.
1921
+ */
1922
+ if ( fs_request_has( 'background_sync' ) ) {
1923
+ $this->run_manual_sync();
1924
+ }
1925
+ }
1926
+
1927
+ if ( $this->is_registered() ) {
1928
+ $this->hook_callback_to_install_sync();
1929
+ }
1930
+
1931
+ if ( $this->is_addon() ) {
1932
+ if ( $this->is_parent_plugin_installed() ) {
1933
+ // Link to parent FS.
1934
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
1935
+
1936
+ // Get parent plugin reference.
1937
+ $this->_parent_plugin = $this->_parent->get_plugin();
1938
+ }
1939
+ }
1940
+
1941
+ if ( $this->is_user_in_admin() ) {
1942
+ global $pagenow;
1943
+ if ( 'plugins.php' === $pagenow ) {
1944
+ $this->hook_plugin_action_links();
1945
+ }
1946
+
1947
+ if ( $this->is_addon() ) {
1948
+ if ( ! $this->is_parent_plugin_installed() ) {
1949
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
1950
+
1951
+ if ( isset( $plugin_info['parent'] ) ) {
1952
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
1953
+ }
1954
+
1955
+ $this->_admin_notices->add(
1956
+ ( ! empty( $parent_name ) ?
1957
+ sprintf( __fs( 'addon-x-cannot-run-without-y', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
1958
+ sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
1959
+ ),
1960
+ __fs( 'oops', $this->_slug ) . '...',
1961
+ 'error'
1962
+ );
1963
+
1964
+ return;
1965
+ } else {
1966
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
1967
+ // If parent plugin activated, automatically install add-on for the user.
1968
+ $this->_activate_addon_account( $this->_parent );
1969
+ }
1970
+
1971
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
1972
+ if ( $this->is_premium() ) {
1973
+ // Remove add-on download admin-notice.
1974
+ $this->_parent->_admin_notices->remove_sticky( 'addon_plan_upgraded_' . $this->_slug );
1975
+ }
1976
+
1977
+ $this->deactivate_premium_only_addon_without_license();
1978
+ }
1979
+ } else {
1980
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
1981
+
1982
+ if ( $this->has_addons() &&
1983
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
1984
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
1985
+ ) {
1986
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
1987
+
1988
+ new FS_Plugin_Info_Dialog( $this );
1989
+ }
1990
+ }
1991
+
1992
+ if ( $this->is_premium() ) {
1993
+ new FS_Plugin_Updater( $this );
1994
+ }
1995
+
1996
+ // if ( $this->is_registered() ||
1997
+ // $this->is_anonymous() ||
1998
+ // $this->is_pending_activation()
1999
+ // ) {
2000
+ // $this->_init_admin();
2001
+ // }
2002
+ }
2003
+
2004
+ $this->do_action( 'initiated' );
2005
+
2006
+ if ( ! $this->is_addon() ) {
2007
+ if ( $this->is_registered() ) {
2008
+ // Fix for upgrade from versions < 1.0.9.
2009
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
2010
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
2011
+ }
2012
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
2013
+ if ( isset( $this->_storage->prev_is_premium ) ) {
2014
+ add_action( is_admin() ? 'admin_init' : 'init', array(
2015
+ &$this,
2016
+ '_plugin_code_type_changed'
2017
+ ) );
2018
+ } else {
2019
+ // Set for code type for the first time.
2020
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2021
+ }
2022
+ }
2023
+
2024
+ $this->do_action( 'after_init_plugin_registered' );
2025
+ } else if ( $this->is_anonymous() ) {
2026
+ $this->do_action( 'after_init_plugin_anonymous' );
2027
+ } else if ( $this->is_pending_activation() ) {
2028
+ $this->do_action( 'after_init_plugin_pending_activations' );
2029
+ }
2030
+ } else {
2031
+ if ( $this->is_registered() ) {
2032
+ $this->do_action( 'after_init_addon_registered' );
2033
+ } else if ( $this->is_anonymous() ) {
2034
+ $this->do_action( 'after_init_addon_anonymous' );
2035
+ } else if ( $this->is_pending_activation() ) {
2036
+ $this->do_action( 'after_init_addon_pending_activations' );
2037
+ }
2038
+ }
2039
+ }
2040
+
2041
+ /**
2042
+ * Parse plugin's settings (as defined by the plugin dev).
2043
+ *
2044
+ * @author Vova Feldman (@svovaf)
2045
+ * @since 1.1.7.3
2046
+ *
2047
+ * @param array $plugin_info
2048
+ *
2049
+ * @throws \Freemius_Exception
2050
+ */
2051
+ private function parse_settings( &$plugin_info ) {
2052
+ $this->_logger->entrance();
2053
+
2054
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
2055
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
2056
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
2057
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
2058
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2059
+
2060
+ if ( isset( $plugin_info['parent'] ) ) {
2061
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
2062
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
2063
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
2064
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2065
+ }
2066
+
2067
+ if ( false === $id ) {
2068
+ throw new Freemius_Exception( 'Plugin id parameter is not set.' );
2069
+ }
2070
+ if ( false === $public_key ) {
2071
+ throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
2072
+ }
2073
+
2074
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
2075
+ $this->_plugin :
2076
+ new FS_Plugin();
2077
+
2078
+ $plugin->update( array(
2079
+ 'id' => $id,
2080
+ 'public_key' => $public_key,
2081
+ 'slug' => $this->_slug,
2082
+ 'parent_plugin_id' => $parent_id,
2083
+ 'version' => $this->get_plugin_version(),
2084
+ 'title' => $this->get_plugin_name(),
2085
+ 'file' => $this->_plugin_basename,
2086
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
2087
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
2088
+ // 'secret_key' => $secret_key,
2089
+ ) );
2090
+
2091
+ if ( $plugin->is_updated() ) {
2092
+ // Update plugin details.
2093
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
2094
+ }
2095
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
2096
+ $this->_plugin->secret_key = $secret_key;
2097
+
2098
+ if ( ! isset( $plugin_info['menu'] ) ) {
2099
+ // Back compatibility to 1.1.2
2100
+ $plugin_info['menu'] = array(
2101
+ 'slug' => isset( $plugin_info['menu_slug'] ) ?
2102
+ $plugin_info['menu_slug'] :
2103
+ $this->_slug
2104
+ );
2105
+ }
2106
+
2107
+ $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
2108
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
2109
+
2110
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
2111
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
2112
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
2113
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
2114
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
2115
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
2116
+ }
2117
+
2118
+ /**
2119
+ * @param string[] $options
2120
+ * @param string $key
2121
+ * @param mixed $default
2122
+ *
2123
+ * @return bool
2124
+ */
2125
+ private function get_option( &$options, $key, $default = false ) {
2126
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
2127
+ }
2128
+
2129
+ private function get_bool_option( &$options, $key, $default = false ) {
2130
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
2131
+ }
2132
+
2133
+ private function get_numeric_option( &$options, $key, $default = false ) {
2134
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
2135
+ }
2136
+
2137
+ /**
2138
+ * Gate keeper.
2139
+ *
2140
+ * @author Vova Feldman (@svovaf)
2141
+ * @since 1.1.7.3
2142
+ *
2143
+ * @return bool
2144
+ */
2145
+ private function should_stop_execution() {
2146
+ if ( $this->is_activation_mode() ) {
2147
+ if ( ! is_admin() ) {
2148
+ /**
2149
+ * If in activation mode, don't execute Freemius outside of the
2150
+ * admin dashboard.
2151
+ *
2152
+ * @author Vova Feldman (@svovaf)
2153
+ * @since 1.1.7.3
2154
+ */
2155
+ return true;
2156
+ }
2157
+
2158
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
2159
+ /**
2160
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
2161
+ * then don't start Freemius.
2162
+ *
2163
+ * @author Vova Feldman (@svovaf)
2164
+ * @since 1.1.6.3
2165
+ *
2166
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
2167
+ */
2168
+ return true;
2169
+ }
2170
+
2171
+ if ( $this->is_cron() ) {
2172
+ /**
2173
+ * If in activation mode, don't execute Freemius during wp crons
2174
+ * (wp crons have HTTP context - called as HTTP request).
2175
+ *
2176
+ * @author Vova Feldman (@svovaf)
2177
+ * @since 1.1.7.3
2178
+ */
2179
+ return true;
2180
+ }
2181
+
2182
+ if ( $this->is_ajax() &&
2183
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
2184
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
2185
+ ) {
2186
+ /**
2187
+ * During activation, if running in AJAX mode, unless there's a sticky
2188
+ * connectivity issue notice, don't run Freemius.
2189
+ *
2190
+ * @author Vova Feldman (@svovaf)
2191
+ * @since 1.1.7.3
2192
+ */
2193
+ return true;
2194
+ }
2195
+ }
2196
+
2197
+ return false;
2198
+ }
2199
+
2200
+ /**
2201
+ * Handles plugin's code type change (free <--> premium).
2202
+ *
2203
+ * @author Vova Feldman (@svovaf)
2204
+ * @since 1.0.9
2205
+ */
2206
+ function _plugin_code_type_changed() {
2207
+ // Schedule code type changes event.
2208
+ // $this->sync_install();
2209
+ $this->schedule_install_sync();
2210
+
2211
+ if ( $this->is_premium() ) {
2212
+ // Activated premium code.
2213
+ $this->do_action( 'after_premium_version_activation' );
2214
+
2215
+ // Remove all sticky messages related to download of the premium version.
2216
+ $this->_admin_notices->remove_sticky( array(
2217
+ 'trial_started',
2218
+ 'plan_upgraded',
2219
+ 'plan_changed',
2220
+ ) );
2221
+
2222
+ $this->_admin_notices->add_sticky(
2223
+ __fs( 'premium-activated-message', $this->_slug ),
2224
+ 'premium_activated',
2225
+ __fs( 'woot', $this->_slug ) . '!'
2226
+ );
2227
+ } else {
2228
+ // Activated free code (after had the premium before).
2229
+ $this->do_action( 'after_free_version_reactivation' );
2230
+
2231
+ if ( $this->is_paying() && ! $this->is_premium() ) {
2232
+ $this->_admin_notices->add_sticky(
2233
+ sprintf(
2234
+ __fs( 'you-have-x-license', $this->_slug ),
2235
+ $this->_site->plan->title
2236
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
2237
+ __fs( 'download-x-version-now', $this->_slug ),
2238
+ $this->_site->plan->title
2239
+ ) ),
2240
+ 'plan_upgraded',
2241
+ __fs( 'yee-haw', $this->_slug ) . '!'
2242
+ );
2243
+ }
2244
+ }
2245
+
2246
+ // Update is_premium of latest version.
2247
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2248
+ }
2249
+
2250
+ #endregion Initialization ------------------------------------------------------------------
2251
+
2252
+ #region Add-ons -------------------------------------------------------------------------
2253
+
2254
+ /**
2255
+ * Check if add-on installed and activated on site.
2256
+ *
2257
+ * @author Vova Feldman (@svovaf)
2258
+ * @since 1.0.6
2259
+ *
2260
+ * @param string|number $slug_or_id
2261
+ *
2262
+ * @return bool
2263
+ */
2264
+ function is_addon_activated( $slug_or_id ) {
2265
+ return self::has_instance( $slug_or_id );
2266
+ }
2267
+
2268
+ /**
2269
+ * Check if add-on was connected to install
2270
+ *
2271
+ * @author Vova Feldman (@svovaf)
2272
+ * @since 1.1.7
2273
+ *
2274
+ * @param string $slug
2275
+ *
2276
+ * @return bool
2277
+ */
2278
+ function is_addon_connected( $slug ) {
2279
+ $sites = self::get_all_sites();
2280
+
2281
+ if ( ! isset( $sites[ $slug ] ) ) {
2282
+ return false;
2283
+ }
2284
+
2285
+ $site = $sites[ $slug ];
2286
+
2287
+ $plugin = FS_Plugin_Manager::instance( $slug )->get();
2288
+
2289
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
2290
+ // The given slug do NOT belong to any of the plugin's add-ons.
2291
+ return false;
2292
+ }
2293
+
2294
+ return ( is_object( $site ) &&
2295
+ is_numeric( $site->id ) &&
2296
+ is_numeric( $site->user_id ) &&
2297
+ is_object( $site->plan )
2298
+ );
2299
+ }
2300
+
2301
+ /**
2302
+ * Determines if add-on installed.
2303
+ *
2304
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
2305
+ *
2306
+ * @author Vova Feldman (@svovaf)
2307
+ * @since 1.0.6
2308
+ *
2309
+ * @param string $slug
2310
+ *
2311
+ * @return bool
2312
+ */
2313
+ function is_addon_installed( $slug ) {
2314
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
2315
+ }
2316
+
2317
+ /**
2318
+ * Get add-on basename.
2319
+ *
2320
+ * @author Vova Feldman (@svovaf)
2321
+ * @since 1.0.6
2322
+ *
2323
+ * @param string $slug
2324
+ *
2325
+ * @return string
2326
+ */
2327
+ function get_addon_basename( $slug ) {
2328
+ if ( $this->is_addon_activated( $slug ) ) {
2329
+ self::instance( $slug )->get_plugin_basename();
2330
+ }
2331
+
2332
+ $premium_basename = $slug . '-premium/' . $slug . '.php';
2333
+
2334
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
2335
+ return $premium_basename;
2336
+ }
2337
+
2338
+ $free_basename = $slug . '/' . $slug . '.php';
2339
+
2340
+ return $free_basename;
2341
+ }
2342
+
2343
+ /**
2344
+ * Get installed add-ons instances.
2345
+ *
2346
+ * @author Vova Feldman (@svovaf)
2347
+ * @since 1.0.6
2348
+ *
2349
+ * @return Freemius[]
2350
+ */
2351
+ function get_installed_addons() {
2352
+ $installed_addons = array();
2353
+ foreach ( self::$_instances as $slug => $instance ) {
2354
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2355
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2356
+ $installed_addons[] = $instance;
2357
+ }
2358
+ }
2359
+ }
2360
+
2361
+ return $installed_addons;
2362
+ }
2363
+
2364
+ /**
2365
+ * Check if any add-ons of the plugin are installed.
2366
+ *
2367
+ * @author Leo Fajardo (@leorw)
2368
+ * @since 1.1.1
2369
+ *
2370
+ * @return bool
2371
+ */
2372
+ function has_installed_addons() {
2373
+ if ( ! $this->has_addons() ) {
2374
+ return false;
2375
+ }
2376
+
2377
+ foreach ( self::$_instances as $slug => $instance ) {
2378
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2379
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2380
+ return true;
2381
+ }
2382
+ }
2383
+ }
2384
+
2385
+ return false;
2386
+ }
2387
+
2388
+ /**
2389
+ * Tell Freemius that the current plugin is an add-on.
2390
+ *
2391
+ * @author Vova Feldman (@svovaf)
2392
+ * @since 1.0.6
2393
+ *
2394
+ * @param number $parent_plugin_id The parent plugin ID
2395
+ */
2396
+ function init_addon( $parent_plugin_id ) {
2397
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
2398
+ }
2399
+
2400
+ /**
2401
+ * @author Vova Feldman (@svovaf)
2402
+ * @since 1.0.6
2403
+ *
2404
+ * @return bool
2405
+ */
2406
+ function is_addon() {
2407
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2408
+ }
2409
+
2410
+ /**
2411
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
2412
+ *
2413
+ * @param bool $is_after_trial_cancel
2414
+ *
2415
+ * @return bool If add-on was deactivated.
2416
+ */
2417
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
2418
+ if ( ! $this->has_free_plan() &&
2419
+ ! $this->has_features_enabled_license() &&
2420
+ ! $this->_has_premium_license()
2421
+ ) {
2422
+ deactivate_plugins( array( $this->_plugin_basename ), true );
2423
+
2424
+ $this->_parent->_admin_notices->add_sticky(
2425
+ sprintf(
2426
+ __fs( ( $is_after_trial_cancel ?
2427
+ 'addon-trial-cancelled-message' :
2428
+ 'addon-no-license-message' ),
2429
+ $this->_parent->_slug
2430
+ ),
2431
+ '<b>' . $this->_plugin->title . '</b>'
2432
+ ) . ' ' . sprintf(
2433
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
2434
+ $this->_parent->addon_url( $this->_slug ),
2435
+ esc_attr( sprintf( __fs( 'more-information-about-x', $this->_parent->_slug ), $this->_plugin->title ) ),
2436
+ __fs( 'purchase-license', $this->_parent->_slug )
2437
+ ),
2438
+ 'no_addon_license',
2439
+ ( $is_after_trial_cancel ? '' : __fs( 'oops', $this->_parent->_slug ) . '...' ),
2440
+ ( $is_after_trial_cancel ? 'success' : 'error' )
2441
+ );
2442
+
2443
+ return true;
2444
+ }
2445
+
2446
+ return false;
2447
+ }
2448
+
2449
+ #endregion ------------------------------------------------------------------
2450
+
2451
+ #region Sandbox ------------------------------------------------------------------
2452
+
2453
+ /**
2454
+ * Set Freemius into sandbox mode for debugging.
2455
+ *
2456
+ * @author Vova Feldman (@svovaf)
2457
+ * @since 1.0.4
2458
+ *
2459
+ * @param string $secret_key
2460
+ */
2461
+ function init_sandbox( $secret_key ) {
2462
+ $this->_plugin->secret_key = $secret_key;
2463
+
2464
+ // Update plugin details.
2465
+ FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
2466
+ }
2467
+
2468
+ /**
2469
+ * Check if running payments in sandbox mode.
2470
+ *
2471
+ * @author Vova Feldman (@svovaf)
2472
+ * @since 1.0.4
2473
+ *
2474
+ * @return bool
2475
+ */
2476
+ function is_payments_sandbox() {
2477
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
2478
+ }
2479
+
2480
+ #endregion Sandbox ------------------------------------------------------------------
2481
+
2482
+ /**
2483
+ * Check if running test vs. live plugin.
2484
+ *
2485
+ * @author Vova Feldman (@svovaf)
2486
+ * @since 1.0.5
2487
+ *
2488
+ * @return bool
2489
+ */
2490
+ function is_live() {
2491
+ return $this->_plugin->is_live;
2492
+ }
2493
+
2494
+ /**
2495
+ * Check if the user skipped connecting the account with Freemius.
2496
+ *
2497
+ * @author Vova Feldman (@svovaf)
2498
+ * @since 1.0.7
2499
+ *
2500
+ * @return bool
2501
+ */
2502
+ function is_anonymous() {
2503
+ if ( ! isset( $this->_is_anonymous ) ) {
2504
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
2505
+ // Not skipped.
2506
+ $this->_is_anonymous = false;
2507
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
2508
+ // For back compatibility, since the variable was boolean before.
2509
+ $this->_is_anonymous = $this->_storage->is_anonymous;
2510
+
2511
+ // Upgrade stored data format to 1.1.3 format.
2512
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
2513
+ } else {
2514
+ // Version 1.1.3 and later.
2515
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
2516
+ }
2517
+ }
2518
+
2519
+ return $this->_is_anonymous;
2520
+ }
2521
+
2522
+ /**
2523
+ * Check if user connected his account and install pending email activation.
2524
+ *
2525
+ * @author Vova Feldman (@svovaf)
2526
+ * @since 1.0.7
2527
+ *
2528
+ * @return bool
2529
+ */
2530
+ function is_pending_activation() {
2531
+ return $this->_storage->get( 'is_pending_activation', false );
2532
+ }
2533
+
2534
+ /**
2535
+ * Check if plugin must be WordPress.org compliant.
2536
+ *
2537
+ * @since 1.0.7
2538
+ *
2539
+ * @return bool
2540
+ */
2541
+ function is_org_repo_compliant() {
2542
+ return $this->_is_org_compliant;
2543
+ }
2544
+
2545
+ #region Daily Sync Cron ------------------------------------------------------------------
2546
+
2547
+ /**
2548
+ * @author Vova Feldman (@svovaf)
2549
+ * @since 1.1.7.3
2550
+ */
2551
+ private function run_manual_sync() {
2552
+ $this->require_pluggable_essentials();
2553
+
2554
+ if ( ! current_user_can( 'activate_plugins' ) ) {
2555
+ return;
2556
+ }
2557
+
2558
+ // Run manual sync.
2559
+ $this->_sync_cron();
2560
+
2561
+ // Reschedule next cron to run 24 hours from now (performance optimization).
2562
+ $this->clear_sync_cron();
2563
+
2564
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
2565
+ }
2566
+
2567
+ /**
2568
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
2569
+ * that doesn't halt page loading.
2570
+ *
2571
+ * @author Vova Feldman (@svovaf)
2572
+ * @since 1.1.7.3
2573
+ */
2574
+ function _sync_cron() {
2575
+ $this->_logger->entrance();
2576
+
2577
+ // Store the last time data sync was executed.
2578
+ $this->_storage->sync_timestamp = time();
2579
+
2580
+ // Check if API is temporary down.
2581
+ if ( FS_Api::is_temporary_down() ) {
2582
+ return;
2583
+ }
2584
+
2585
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
2586
+
2587
+ if ( $this->is_registered() ) {
2588
+ if ( $this->has_paid_plan() ) {
2589
+ // Initiate background plan sync.
2590
+ $this->_sync_license( true );
2591
+
2592
+ if ( $this->is_paying() ) {
2593
+ // Check for premium plugin updates.
2594
+ $this->_check_updates( true );
2595
+ }
2596
+ } else {
2597
+ // Sync install (only if something changed locally).
2598
+ $this->sync_install();
2599
+ }
2600
+ }
2601
+
2602
+ if ( ! $this->is_addon() && $this->_has_addons ) {
2603
+ // Sync add-ons collection.
2604
+ $this->_sync_addons( true );
2605
+ }
2606
+ }
2607
+
2608
+ /**
2609
+ * Check if sync was executed in the last $period of seconds.
2610
+ *
2611
+ * @author Vova Feldman (@svovaf)
2612
+ * @since 1.1.7.3
2613
+ *
2614
+ * @param int $period In seconds
2615
+ *
2616
+ * @return bool
2617
+ */
2618
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
2619
+ if ( ! isset( $this->_storage->sync_timestamp ) ) {
2620
+ return false;
2621
+ }
2622
+
2623
+ return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
2624
+ }
2625
+
2626
+ /**
2627
+ * @author Vova Feldman (@svovaf)
2628
+ * @since 1.1.7.3
2629
+ *
2630
+ * @return bool
2631
+ */
2632
+ private function is_sync_cron_on() {
2633
+ /**
2634
+ * @var object $sync_cron_data
2635
+ */
2636
+ $sync_cron_data = $this->_storage->get( 'sync_cron', null );
2637
+
2638
+ return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
2639
+ }
2640
+
2641
+ /**
2642
+ * @author Vova Feldman (@svovaf)
2643
+ * @since 1.1.7.3
2644
+ *
2645
+ * @param int $start_at Defaults to now.
2646
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
2647
+ * schedule job to start right away.
2648
+ */
2649
+ private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
2650
+ $this->_logger->entrance();
2651
+
2652
+ if ( $randomize_start ) {
2653
+ // Schedule first sync with a random 12 hour time range from now.
2654
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
2655
+ }
2656
+
2657
+ // Schedule daily WP cron.
2658
+ wp_schedule_event(
2659
+ $start_at,
2660
+ 'daily',
2661
+ $this->get_action_tag( 'data_sync' )
2662
+ );
2663
+
2664
+ $this->_storage->store( 'sync_cron', (object) array(
2665
+ 'version' => $this->get_plugin_version(),
2666
+ 'sdk_version' => $this->version,
2667
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2668
+ 'on' => true,
2669
+ ) );
2670
+ }
2671
+
2672
+ /**
2673
+ * Add the actual sync function to the cron job hook.
2674
+ *
2675
+ * @author Vova Feldman (@svovaf)
2676
+ * @since 1.1.7.3
2677
+ */
2678
+ private function hook_callback_to_sync_cron() {
2679
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
2680
+ }
2681
+
2682
+ /**
2683
+ * @author Vova Feldman (@svovaf)
2684
+ * @since 1.1.7.3
2685
+ */
2686
+ private function clear_sync_cron() {
2687
+ $this->_logger->entrance();
2688
+
2689
+ if ( ! $this->is_sync_cron_on() ) {
2690
+ return;
2691
+ }
2692
+
2693
+ $this->_storage->remove( 'sync_cron' );
2694
+
2695
+ wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
2696
+ }
2697
+
2698
+ /**
2699
+ * Unix timestamp for next sync cron execution or false if not scheduled.
2700
+ *
2701
+ * @author Vova Feldman (@svovaf)
2702
+ * @since 1.1.7.3
2703
+ *
2704
+ * @return int|false
2705
+ */
2706
+ function next_sync_cron() {
2707
+ $this->_logger->entrance();
2708
+
2709
+ if ( ! $this->is_sync_cron_on() ) {
2710
+ return false;
2711
+ }
2712
+
2713
+ return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
2714
+ }
2715
+
2716
+ /**
2717
+ * Unix timestamp for previous sync cron execution or false if never executed.
2718
+ *
2719
+ * @author Vova Feldman (@svovaf)
2720
+ * @since 1.1.7.3
2721
+ *
2722
+ * @return int|false
2723
+ */
2724
+ function last_sync_cron() {
2725
+ $this->_logger->entrance();
2726
+
2727
+ return $this->_storage->get( 'sync_timestamp' );
2728
+ }
2729
+
2730
+ #endregion Daily Sync Cron ------------------------------------------------------------------
2731
+
2732
+ #region Async Install Sync ------------------------------------------------------------------
2733
+
2734
+ /**
2735
+ * @author Vova Feldman (@svovaf)
2736
+ * @since 1.1.7.3
2737
+ *
2738
+ * @return bool
2739
+ */
2740
+ private function is_install_sync_scheduled() {
2741
+ /**
2742
+ * @var object $cron_data
2743
+ */
2744
+ $cron_data = $this->_storage->get( 'install_sync_cron', null );
2745
+
2746
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
2747
+ }
2748
+
2749
+ /**
2750
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
2751
+ *
2752
+ * @author Vova Feldman (@svovaf)
2753
+ * @since 1.1.7.3
2754
+ */
2755
+ private function schedule_install_sync() {
2756
+ $this->_logger->entrance();
2757
+
2758
+ $this->clear_install_sync_cron();
2759
+
2760
+ // Schedule immediate install sync.
2761
+ wp_schedule_single_event(
2762
+ WP_FS__SCRIPT_START_TIME,
2763
+ $this->get_action_tag( 'install_sync' )
2764
+ );
2765
+
2766
+ $this->_storage->store( 'install_sync_cron', (object) array(
2767
+ 'version' => $this->get_plugin_version(),
2768
+ 'sdk_version' => $this->version,
2769
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2770
+ 'on' => true,
2771
+ ) );
2772
+ }
2773
+
2774
+ /**
2775
+ * Unix timestamp for previous install sync cron execution or false if never executed.
2776
+ *
2777
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
2778
+ * updated. But for sure the sync event is working.
2779
+ *
2780
+ * @author Vova Feldman (@svovaf)
2781
+ * @since 1.1.7.3
2782
+ *
2783
+ * @return int|false
2784
+ */
2785
+ function last_install_sync() {
2786
+ $this->_logger->entrance();
2787
+
2788
+ return $this->_storage->get( 'install_sync_timestamp' );
2789
+ }
2790
+
2791
+ /**
2792
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
2793
+ *
2794
+ * @author Vova Feldman (@svovaf)
2795
+ * @since 1.1.7.3
2796
+ *
2797
+ * @return int|false
2798
+ */
2799
+ function next_install_sync() {
2800
+ $this->_logger->entrance();
2801
+
2802
+ if ( ! $this->is_install_sync_scheduled() ) {
2803
+ return false;
2804
+ }
2805
+
2806
+ return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
2807
+ }
2808
+
2809
+ /**
2810
+ * Add the actual install sync function to the cron job hook.
2811
+ *
2812
+ * @author Vova Feldman (@svovaf)
2813
+ * @since 1.1.7.3
2814
+ */
2815
+ private function hook_callback_to_install_sync() {
2816
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
2817
+ }
2818
+
2819
+ /**
2820
+ * @author Vova Feldman (@svovaf)
2821
+ * @since 1.1.7.3
2822
+ */
2823
+ private function clear_install_sync_cron() {
2824
+ $this->_logger->entrance();
2825
+
2826
+ if ( ! $this->is_install_sync_scheduled() ) {
2827
+ return;
2828
+ }
2829
+
2830
+ $this->_storage->remove( 'install_sync_cron' );
2831
+
2832
+ wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
2833
+ }
2834
+
2835
+ /**
2836
+ * @author Vova Feldman (@svovaf)
2837
+ * @since 1.1.7.3
2838
+ */
2839
+ public function _run_sync_install() {
2840
+ $this->_logger->entrance();
2841
+
2842
+ // Update last install sync timestamp.
2843
+ $this->_storage->install_sync_timestamp = time();
2844
+
2845
+ $this->sync_install( array(), true );
2846
+ }
2847
+
2848
+ #endregion Async Install Sync ------------------------------------------------------------------
2849
+
2850
+ /**
2851
+ * Show a notice that activation is currently pending.
2852
+ *
2853
+ * @author Vova Feldman (@svovaf)
2854
+ * @since 1.0.7
2855
+ *
2856
+ * @param bool|string $email
2857
+ */
2858
+ function _add_pending_activation_notice( $email = false ) {
2859
+ if ( ! is_string( $email ) ) {
2860
+ $current_user = self::_get_current_wp_user();
2861
+ $email = $current_user->user_email;
2862
+ }
2863
+
2864
+ $this->_admin_notices->add_sticky(
2865
+ sprintf(
2866
+ __fs( 'pending-activation-message', $this->_slug ),
2867
+ '<b>' . $this->get_plugin_name() . '</b>',
2868
+ '<b>' . $email . '</b>'
2869
+ ),
2870
+ 'activation_pending',
2871
+ 'Thanks!'
2872
+ );
2873
+ }
2874
+
2875
+ /**
2876
+ * Check if currently in plugin activation.
2877
+ *
2878
+ * @author Vova Feldman (@svovaf)
2879
+ * @since 1.1.4
2880
+ *
2881
+ * @return bool
2882
+ */
2883
+ function is_plugin_activation() {
2884
+ return get_option( "fs_{$this->_slug}_activated", false );
2885
+ }
2886
+
2887
+ /**
2888
+ *
2889
+ * NOTE: admin_menu action executed before admin_init.
2890
+ *
2891
+ * @author Vova Feldman (@svovaf)
2892
+ * @since 1.0.7
2893
+ */
2894
+ function _admin_init_action() {
2895
+ /**
2896
+ * Automatically redirect to connect/activation page after plugin activation.
2897
+ *
2898
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
2899
+ */
2900
+ if ( $this->is_plugin_activation() ) {
2901
+ delete_option( "fs_{$this->_slug}_activated" );
2902
+
2903
+ if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
2904
+ $this->_redirect_on_activation_hook();
2905
+
2906
+ return;
2907
+ }
2908
+ }
2909
+
2910
+ if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
2911
+ check_admin_referer( $this->_slug . '_skip_activation' );
2912
+
2913
+ $this->skip_connection();
2914
+
2915
+ if ( fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) ) ) {
2916
+ exit();
2917
+ }
2918
+ }
2919
+
2920
+ if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
2921
+ if ( ! $this->is_pending_activation() ) {
2922
+ if ( ! $this->_menu->is_activation_page() ) {
2923
+ if ( $this->is_plugin_new_install() ) {
2924
+ // Show notice for new plugin installations.
2925
+ $this->_admin_notices->add(
2926
+ sprintf(
2927
+ __fs( 'you-are-step-away', $this->_slug ),
2928
+ sprintf( '<b><a href="%s">%s</a></b>',
2929
+ $this->get_activation_url(),
2930
+ sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
2931
+ )
2932
+ ),
2933
+ '',
2934
+ 'update-nag'
2935
+ );
2936
+ } else {
2937
+ if ( ! isset( $this->_storage->sticky_optin_added ) ) {
2938
+ $this->_storage->sticky_optin_added = true;
2939
+
2940
+ // Show notice for new plugin installations.
2941
+ $this->_admin_notices->add_sticky(
2942
+ sprintf(
2943
+ __fs( 'few-plugin-tweaks', $this->_slug ),
2944
+ sprintf( '<b><a href="%s">%s</a></b>',
2945
+ $this->get_activation_url(),
2946
+ sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
2947
+ )
2948
+ ),
2949
+ 'connect_account',
2950
+ '',
2951
+ 'update-nag'
2952
+ );
2953
+ }
2954
+
2955
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
2956
+ // Don't show admin nag if plugin update.
2957
+ wp_enqueue_script( 'wp-pointer' );
2958
+ wp_enqueue_style( 'wp-pointer' );
2959
+
2960
+ $this->_enqueue_connect_essentials();
2961
+
2962
+ add_action( 'admin_print_footer_scripts', array(
2963
+ $this,
2964
+ '_add_connect_pointer_script'
2965
+ ) );
2966
+ }
2967
+
2968
+ }
2969
+ }
2970
+ }
2971
+ }
2972
+
2973
+ $this->_add_upgrade_action_link();
2974
+ }
2975
+
2976
+ /**
2977
+ * Enqueue connect requires scripts and styles.
2978
+ *
2979
+ * @author Vova Feldman (@svovaf)
2980
+ * @since 1.1.4
2981
+ */
2982
+ function _enqueue_connect_essentials() {
2983
+ wp_enqueue_script( 'jquery' );
2984
+ wp_enqueue_script( 'json2' );
2985
+
2986
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
2987
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
2988
+
2989
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
2990
+ }
2991
+
2992
+ /**
2993
+ * Add connect / opt-in pointer.
2994
+ *
2995
+ * @author Vova Feldman (@svovaf)
2996
+ * @since 1.1.4
2997
+ */
2998
+ function _add_connect_pointer_script() {
2999
+ $vars = array( 'slug' => $this->_slug );
3000
+ $pointer_content = fs_get_template( 'connect.php', $vars );
3001
+ ?>
3002
+ <script type="text/javascript">// <![CDATA[
3003
+ jQuery(document).ready(function ($) {
3004
+ if ('undefined' !== typeof(jQuery().pointer)) {
3005
+
3006
+ var element = <?php echo $this->apply_filters('optin_pointer_element', '$("#non_existing_element");') ?>;
3007
+
3008
+ if (element.length > 0) {
3009
+ var optin = $(element).pointer($.extend(true, {}, {
3010
+ content : <?php echo json_encode($pointer_content) ?>,
3011
+ position : {
3012
+ edge : 'left',
3013
+ align: 'center'
3014
+ },
3015
+ buttons : function () {
3016
+ // Don't show pointer buttons.
3017
+ return '';
3018
+ },
3019
+ pointerWidth: 482
3020
+ }, <?php echo $this->apply_filters('optin_pointer_options_json', '{}') ?>));
3021
+
3022
+ <?php
3023
+ echo $this->apply_filters('optin_pointer_execute', "
3024
+
3025
+ optin.pointer('open');
3026
+
3027
+ // Tag the opt-in pointer with custom class.
3028
+ $('.wp-pointer #fs_connect')
3029
+ .parents('.wp-pointer.wp-pointer-top')
3030
+ .addClass('fs-opt-in-pointer');
3031
+
3032
+ ", 'element', 'optin') ?>
3033
+ }
3034
+ }
3035
+ });
3036
+ // ]]></script>
3037
+ <?php
3038
+ }
3039
+
3040
+ /**
3041
+ * Return current page's URL.
3042
+ *
3043
+ * @author Vova Feldman (@svovaf)
3044
+ * @since 1.0.7
3045
+ *
3046
+ * @return string
3047
+ */
3048
+ function current_page_url() {
3049
+ $url = 'http';
3050
+
3051
+ if ( isset( $_SERVER["HTTPS"] ) ) {
3052
+ if ( $_SERVER["HTTPS"] == "on" ) {
3053
+ $url .= "s";
3054
+ }
3055
+ }
3056
+ $url .= "://";
3057
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
3058
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
3059
+ } else {
3060
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
3061
+ }
3062
+
3063
+ return esc_url( $url );
3064
+ }
3065
+
3066
+ /**
3067
+ * Check if the current page is the plugin's main admin settings page.
3068
+ *
3069
+ * @author Vova Feldman (@svovaf)
3070
+ * @since 1.0.7
3071
+ *
3072
+ * @return bool
3073
+ */
3074
+ function _is_plugin_page() {
3075
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
3076
+ fs_is_plugin_page( $this->_slug );
3077
+ }
3078
+
3079
+ /* Events
3080
+ ------------------------------------------------------------------------------------------------------------------*/
3081
+ /**
3082
+ * Delete site install from Database.
3083
+ *
3084
+ * @author Vova Feldman (@svovaf)
3085
+ * @since 1.0.1
3086
+ *
3087
+ * @param bool $store
3088
+ */
3089
+ function _delete_site( $store = true ) {
3090
+ $sites = self::get_all_sites();
3091
+
3092
+ if ( isset( $sites[ $this->_slug ] ) ) {
3093
+ unset( $sites[ $this->_slug ] );
3094
+ }
3095
+
3096
+ self::$_accounts->set_option( 'sites', $sites, $store );
3097
+ }
3098
+
3099
+ /**
3100
+ * Delete plugin's plans information.
3101
+ *
3102
+ * @param bool $store Flush to Database if true.
3103
+ *
3104
+ * @author Vova Feldman (@svovaf)
3105
+ * @since 1.0.9
3106
+ */
3107
+ private function _delete_plans( $store = true ) {
3108
+ $this->_logger->entrance();
3109
+
3110
+ $plans = self::get_all_plans();
3111
+
3112
+ unset( $plans[ $this->_slug ] );
3113
+
3114
+ self::$_accounts->set_option( 'plans', $plans, $store );
3115
+ }
3116
+
3117
+ /**
3118
+ * Delete all plugin licenses.
3119
+ *
3120
+ * @author Vova Feldman (@svovaf)
3121
+ * @since 1.0.9
3122
+ *
3123
+ * @param bool $store
3124
+ * @param string|bool $plugin_slug
3125
+ */
3126
+ private function _delete_licenses( $store = true, $plugin_slug = false ) {
3127
+ $this->_logger->entrance();
3128
+
3129
+ $all_licenses = self::get_all_licenses();
3130
+
3131
+ if ( ! is_string( $plugin_slug ) ) {
3132
+ $plugin_slug = $this->_slug;
3133
+ }
3134
+
3135
+ unset( $all_licenses[ $plugin_slug ] );
3136
+
3137
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
3138
+ }
3139
+
3140
+ /**
3141
+ * Check if Freemius was added on new plugin installation.
3142
+ *
3143
+ * @author Vova Feldman (@svovaf)
3144
+ * @since 1.1.5
3145
+ *
3146
+ * @return bool
3147
+ */
3148
+ function is_plugin_new_install() {
3149
+ return isset( $this->_storage->is_plugin_new_install ) &&
3150
+ $this->_storage->is_plugin_new_install;
3151
+ }
3152
+
3153
+ /**
3154
+ * Plugin activated hook.
3155
+ *
3156
+ * @author Vova Feldman (@svovaf)
3157
+ * @since 1.0.1
3158
+ *
3159
+ * @uses FS_Api
3160
+ */
3161
+ function _activate_plugin_event_hook() {
3162
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3163
+
3164
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3165
+ return;
3166
+ }
3167
+
3168
+ // Clear API cache on activation.
3169
+ FS_Api::clear_cache();
3170
+
3171
+ if ( $this->is_registered() ) {
3172
+ // Schedule re-activation event and sync.
3173
+ // $this->sync_install( array(), true );
3174
+ $this->schedule_install_sync();
3175
+
3176
+ /**
3177
+ * @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.
3178
+ */
3179
+ if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
3180
+ // Deactivate Free plugin version on premium plugin activation.
3181
+ deactivate_plugins( $this->_free_plugin_basename );
3182
+
3183
+ $this->_admin_notices->add(
3184
+ sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
3185
+ __fs( 'woot', $this->_slug ) . '!'
3186
+ );
3187
+ }
3188
+ } else if ( $this->is_anonymous() ) {
3189
+ /**
3190
+ * Reset "skipped" click cache on the following:
3191
+ * 1. Development mode.
3192
+ * 2. If the user skipped the exact same version before.
3193
+ *
3194
+ * @todo 3. If explicitly asked to retry after every activation.
3195
+ */
3196
+ if ( WP_FS__DEV_MODE ||
3197
+ $this->get_plugin_version() == $this->_storage->is_anonymous['version']
3198
+ ) {
3199
+ $this->reset_anonymous_mode();
3200
+ }
3201
+ }
3202
+
3203
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3204
+ /**
3205
+ * If no previous version of plugin's version exist, it means that it's either
3206
+ * the first time that the plugin installed on the site, or the plugin was installed
3207
+ * before but didn't have Freemius integrated.
3208
+ *
3209
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
3210
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
3211
+ * only after immediate activation.
3212
+ *
3213
+ * @since 1.1.4
3214
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
3215
+ */
3216
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
3217
+ }
3218
+
3219
+ if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
3220
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
3221
+ add_option( "fs_{$this->_slug}_activated", true );
3222
+ }
3223
+ }
3224
+
3225
+ /**
3226
+ * Delete account.
3227
+ *
3228
+ * @author Vova Feldman (@svovaf)
3229
+ * @since 1.0.3
3230
+ *
3231
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3232
+ */
3233
+ function delete_account_event( $check_user = true ) {
3234
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3235
+
3236
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3237
+ return;
3238
+ }
3239
+
3240
+ $this->do_action( 'before_account_delete' );
3241
+
3242
+ // Clear all admin notices.
3243
+ $this->_admin_notices->clear_all_sticky();
3244
+
3245
+ $this->_delete_site( false );
3246
+
3247
+ $this->_delete_plans( false );
3248
+
3249
+ $this->_delete_licenses( false );
3250
+
3251
+ // Delete add-ons related to plugin's account.
3252
+ $this->_delete_account_addons( false );
3253
+
3254
+ // @todo Delete plans and licenses of add-ons.
3255
+
3256
+ self::$_accounts->store();
3257
+
3258
+ /**
3259
+ * IMPORTANT:
3260
+ * Clear crons must be executed before clearing all storage.
3261
+ * Otherwise, the cron will not be cleared.
3262
+ */
3263
+ $this->clear_sync_cron();
3264
+ $this->clear_install_sync_cron();
3265
+
3266
+ // Clear all storage data.
3267
+ $this->_storage->clear_all( true, array(
3268
+ 'connectivity_test',
3269
+ 'is_on',
3270
+ ) );
3271
+
3272
+ // Send delete event.
3273
+ $this->get_api_site_scope()->call( '/', 'delete' );
3274
+
3275
+ $this->do_action( 'after_account_delete' );
3276
+ }
3277
+
3278
+ /**
3279
+ * Plugin deactivation hook.
3280
+ *
3281
+ * @author Vova Feldman (@svovaf)
3282
+ * @since 1.0.1
3283
+ */
3284
+ function _deactivate_plugin_hook() {
3285
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3286
+
3287
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3288
+ return;
3289
+ }
3290
+
3291
+ $this->_admin_notices->clear_all_sticky();
3292
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
3293
+ unset( $this->_storage->sticky_optin_added );
3294
+ }
3295
+
3296
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3297
+ // Remember that plugin was already installed.
3298
+ $this->_storage->is_plugin_new_install = false;
3299
+ }
3300
+
3301
+ $this->clear_sync_cron();
3302
+ $this->clear_install_sync_cron();
3303
+
3304
+ if ( $this->is_registered() ) {
3305
+ // Send deactivation event.
3306
+ $this->sync_install( array(
3307
+ 'is_active' => false,
3308
+ ) );
3309
+ } else {
3310
+ if ( ! $this->has_api_connectivity() ) {
3311
+ // Reset connectivity test cache.
3312
+ unset( $this->_storage->connectivity_test );
3313
+ }
3314
+ }
3315
+
3316
+ // Clear API cache on deactivation.
3317
+ FS_Api::clear_cache();
3318
+
3319
+ $this->remove_sdk_reference();
3320
+ }
3321
+
3322
+ /**
3323
+ * @author Vova Feldman (@svovaf)
3324
+ * @since 1.1.6
3325
+ */
3326
+ private function remove_sdk_reference() {
3327
+ global $fs_active_plugins;
3328
+
3329
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
3330
+ if ( $this->_plugin_basename == $data->plugin_path ) {
3331
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
3332
+ break;
3333
+ }
3334
+ }
3335
+
3336
+ fs_fallback_to_newest_active_sdk();
3337
+ }
3338
+
3339
+ /**
3340
+ * @author Vova Feldman (@svovaf)
3341
+ * @since 1.1.3
3342
+ *
3343
+ * @param bool $is_anonymous
3344
+ */
3345
+ private function set_anonymous_mode( $is_anonymous = true ) {
3346
+ // Store information regarding skip to try and opt-in the user
3347
+ // again in the future.
3348
+ $this->_storage->is_anonymous = array(
3349
+ 'is' => $is_anonymous,
3350
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3351
+ 'version' => $this->get_plugin_version(),
3352
+ );
3353
+
3354
+ // Update anonymous mode cache.
3355
+ $this->_is_anonymous = $is_anonymous;
3356
+ }
3357
+
3358
+ /**
3359
+ * @author Vova Feldman (@svovaf)
3360
+ * @since 1.1.3
3361
+ */
3362
+ private function reset_anonymous_mode() {
3363
+ unset( $this->_storage->is_anonymous );
3364
+ }
3365
+
3366
+ /**
3367
+ * Clears the anonymous mode and redirects to the opt-in screen.
3368
+ *
3369
+ * @author Vova Feldman (@svovaf)
3370
+ * @since 1.1.7
3371
+ */
3372
+ function connect_again() {
3373
+ if ( ! $this->is_anonymous() ) {
3374
+ return;
3375
+ }
3376
+
3377
+ $this->reset_anonymous_mode();
3378
+
3379
+ if ( fs_redirect( $this->get_activation_url() ) ) {
3380
+ exit();
3381
+ }
3382
+ }
3383
+
3384
+ /**
3385
+ * Skip account connect, and set anonymous mode.
3386
+ *
3387
+ * @author Vova Feldman (@svovaf)
3388
+ * @since 1.1.1
3389
+ */
3390
+ private function skip_connection() {
3391
+ $this->_logger->entrance();
3392
+
3393
+ $this->_admin_notices->remove_sticky( 'connect_account' );
3394
+
3395
+ $this->set_anonymous_mode();
3396
+
3397
+ // Send anonymous skip event.
3398
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
3399
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
3400
+ 'uid' => $this->get_anonymous_id(),
3401
+ ) );
3402
+ }
3403
+
3404
+ /**
3405
+ * Plugin version update hook.
3406
+ *
3407
+ * @author Vova Feldman (@svovaf)
3408
+ * @since 1.0.4
3409
+ */
3410
+ private function update_plugin_version_event() {
3411
+ $this->_logger->entrance();
3412
+
3413
+ if ( ! $this->is_registered() ) {
3414
+ return;
3415
+ }
3416
+
3417
+ $this->schedule_install_sync();
3418
+ // $this->sync_install( array(), true );
3419
+ }
3420
+
3421
+ /**
3422
+ * Return a list of modified plugins since the last sync.
3423
+ *
3424
+ * Note:
3425
+ * There's no point to store a plugins counter since even if the number of
3426
+ * plugins didn't change, we still need to check if the versions are all the
3427
+ * same and the activity state is similar.
3428
+ *
3429
+ * @author Vova Feldman (@svovaf)
3430
+ * @since 1.1.8
3431
+ *
3432
+ * @return array|false
3433
+ */
3434
+ private function get_plugins_data_for_api() {
3435
+ // Alias.
3436
+ $option_name = 'all_plugins';
3437
+
3438
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3439
+
3440
+ if ( ! is_object( $all_cached_plugins ) ) {
3441
+ $all_cached_plugins = (object) array(
3442
+ 'timestamp' => '',
3443
+ 'md5' => '',
3444
+ 'plugins' => array(),
3445
+ );
3446
+ }
3447
+
3448
+ $time = time();
3449
+
3450
+ if ( ! empty( $all_cached_plugins->timestamp ) &&
3451
+ ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3452
+ ) {
3453
+ // Don't send plugin updates if last update was in the past 5 min.
3454
+ return false;
3455
+ }
3456
+
3457
+ // Write timestamp to lock the logic.
3458
+ $all_cached_plugins->timestamp = $time;
3459
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3460
+
3461
+ // Reload options from DB.
3462
+ self::$_accounts->load( true );
3463
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3464
+
3465
+ if ( $time != $all_cached_plugins->timestamp ) {
3466
+ // If timestamp is different, then another thread captured the lock.
3467
+ return false;
3468
+ }
3469
+
3470
+ // Check if there's a change in plugins.
3471
+ $all_plugins = self::get_all_plugins();
3472
+
3473
+ // Check if plugins changed.
3474
+ ksort( $all_plugins );
3475
+
3476
+ $plugins_signature = '';
3477
+ foreach ( $all_plugins as $basename => $data ) {
3478
+ $plugins_signature .= $data['slug'] . ',' .
3479
+ $data['Version'] . ',' .
3480
+ ( $data['is_active'] ? '1' : '0' ) . ';';
3481
+ }
3482
+
3483
+ // Check if plugins status changed (version or active/inactive).
3484
+ $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
3485
+
3486
+ $plugins_update_data = array();
3487
+
3488
+ if ( $plugins_changed ) {
3489
+ // Change in plugins, report changes.
3490
+
3491
+ // Update existing plugins info.
3492
+ foreach ( $all_cached_plugins->plugins as $basename => $data ) {
3493
+ if ( ! isset( $all_plugins[ $basename ] ) ) {
3494
+ // Plugin uninstalled.
3495
+ $uninstalled_plugin_data = $data;
3496
+ $uninstalled_plugin_data['is_active'] = false;
3497
+ $uninstalled_plugin_data['is_uninstalled'] = true;
3498
+ $plugins_update_data[] = $uninstalled_plugin_data;
3499
+
3500
+ unset( $all_plugins[ $basename ] );
3501
+ unset( $all_cached_plugins->plugins[ $basename ] );
3502
+ } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
3503
+ $data['version'] !== $all_plugins[ $basename ]['Version']
3504
+ ) {
3505
+ // Plugin activated or deactivated, or version changed.
3506
+ $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
3507
+ $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
3508
+
3509
+ $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
3510
+ }
3511
+ }
3512
+
3513
+ // Find new plugins that weren't yet seen before.
3514
+ foreach ( $all_plugins as $basename => $data ) {
3515
+ if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
3516
+ // New plugin.
3517
+ $new_plugin = array(
3518
+ 'slug' => $data['slug'],
3519
+ 'version' => $data['Version'],
3520
+ 'title' => $data['Name'],
3521
+ 'is_active' => $data['is_active'],
3522
+ 'is_uninstalled' => false,
3523
+ );
3524
+
3525
+ $plugins_update_data[] = $new_plugin;
3526
+ $all_cached_plugins->plugins[ $basename ] = $new_plugin;
3527
+ }
3528
+ }
3529
+
3530
+ $all_cached_plugins->md5 = md5( $plugins_signature );
3531
+ $all_cached_plugins->timestamp = $time;
3532
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3533
+ }
3534
+
3535
+ return $plugins_update_data;
3536
+ }
3537
+
3538
+ /**
3539
+ * Return a list of modified themes since the last sync.
3540
+ *
3541
+ * Note:
3542
+ * There's no point to store a themes counter since even if the number of
3543
+ * themes didn't change, we still need to check if the versions are all the
3544
+ * same and the activity state is similar.
3545
+ *
3546
+ * @author Vova Feldman (@svovaf)
3547
+ * @since 1.1.8
3548
+ *
3549
+ * @return array|false
3550
+ */
3551
+ private function get_themes_data_for_api() {
3552
+ // Alias.
3553
+ $option_name = 'all_themes';
3554
+
3555
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3556
+
3557
+ if ( ! is_object( $all_cached_themes ) ) {
3558
+ $all_cached_themes = (object) array(
3559
+ 'timestamp' => '',
3560
+ 'md5' => '',
3561
+ 'themes' => array(),
3562
+ );
3563
+ }
3564
+
3565
+ $time = time();
3566
+
3567
+ if ( ! empty( $all_cached_themes->timestamp ) &&
3568
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3569
+ ) {
3570
+ // Don't send theme updates if last update was in the past 5 min.
3571
+ return false;
3572
+ }
3573
+
3574
+ // Write timestamp to lock the logic.
3575
+ $all_cached_themes->timestamp = $time;
3576
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3577
+
3578
+ // Reload options from DB.
3579
+ self::$_accounts->load( true );
3580
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3581
+
3582
+ if ( $time != $all_cached_themes->timestamp ) {
3583
+ // If timestamp is different, then another thread captured the lock.
3584
+ return false;
3585
+ }
3586
+
3587
+ // Get active theme.
3588
+ $active_theme = wp_get_theme();
3589
+
3590
+ // Check if there's a change in themes.
3591
+ $all_themes = wp_get_themes();
3592
+
3593
+ // Check if themes changed.
3594
+ ksort( $all_themes );
3595
+
3596
+ $themes_signature = '';
3597
+ foreach ( $all_themes as $slug => $data ) {
3598
+ $is_active = ( $slug === $active_theme->stylesheet );
3599
+ $themes_signature .= $slug . ',' .
3600
+ $data->version . ',' .
3601
+ ( $is_active ? '1' : '0' ) . ';';
3602
+ }
3603
+
3604
+ // Check if themes status changed (version or active/inactive).
3605
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
3606
+
3607
+ $themes_update_data = array();
3608
+
3609
+ if ( $themes_changed ) {
3610
+ // Change in themes, report changes.
3611
+
3612
+ // Update existing themes info.
3613
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
3614
+ $is_active = ( $slug === $active_theme->stylesheet );
3615
+
3616
+ if ( ! isset( $all_themes[ $slug ] ) ) {
3617
+ // Plugin uninstalled.
3618
+ $uninstalled_theme_data = $data;
3619
+ $uninstalled_theme_data['is_active'] = false;
3620
+ $uninstalled_theme_data['is_uninstalled'] = true;
3621
+ $themes_update_data[] = $uninstalled_theme_data;
3622
+
3623
+ unset( $all_themes[ $slug ] );
3624
+ unset( $all_cached_themes->themes[ $slug ] );
3625
+ } else if ( $data['is_active'] !== $is_active ||
3626
+ $data['version'] !== $all_themes[ $slug ]->version
3627
+ ) {
3628
+ // Plugin activated or deactivated, or version changed.
3629
+
3630
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
3631
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
3632
+
3633
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
3634
+ }
3635
+ }
3636
+
3637
+ // Find new themes that weren't yet seen before.
3638
+ foreach ( $all_themes as $slug => $data ) {
3639
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
3640
+ $is_active = ( $slug === $active_theme->stylesheet );
3641
+
3642
+ // New plugin.
3643
+ $new_plugin = array(
3644
+ 'slug' => $slug,
3645
+ 'version' => $data->version,
3646
+ 'title' => $data->name,
3647
+ 'is_active' => $is_active,
3648
+ 'is_uninstalled' => false,
3649
+ );
3650
+
3651
+ $themes_update_data[] = $new_plugin;
3652
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
3653
+ }
3654
+ }
3655
+
3656
+ $all_cached_themes->md5 = md5( $themes_signature );
3657
+ $all_cached_themes->timestamp = time();
3658
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3659
+ }
3660
+
3661
+ return $themes_update_data;
3662
+ }
3663
+
3664
+ /**
3665
+ * Update install details.
3666
+ *
3667
+ * @author Vova Feldman (@svovaf)
3668
+ * @since 1.1.2
3669
+ *
3670
+ * @param string[] string $override
3671
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
3672
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
3673
+ *
3674
+ * @return array
3675
+ */
3676
+ private function get_install_data_for_api(
3677
+ array $override,
3678
+ $include_plugins = true,
3679
+ $include_themes = true
3680
+ ) {
3681
+ /**
3682
+ * @since 1.1.8 Also send plugin updates.
3683
+ */
3684
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
3685
+ $plugins = $this->get_plugins_data_for_api();
3686
+ if ( ! empty( $plugins ) ) {
3687
+ $override['plugins'] = $plugins;
3688
+ }
3689
+ }
3690
+ /**
3691
+ * @since 1.1.8 Also send themes updates.
3692
+ */
3693
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
3694
+ $themes = $this->get_themes_data_for_api();
3695
+ if ( ! empty( $themes ) ) {
3696
+ $override['themes'] = $themes;
3697
+ }
3698
+ }
3699
+
3700
+ return array_merge( array(
3701
+ 'version' => $this->get_plugin_version(),
3702
+ 'is_premium' => $this->is_premium(),
3703
+ 'language' => get_bloginfo( 'language' ),
3704
+ 'charset' => get_bloginfo( 'charset' ),
3705
+ 'platform_version' => get_bloginfo( 'version' ),
3706
+ 'programming_language_version' => phpversion(),
3707
+ 'title' => get_bloginfo( 'name' ),
3708
+ 'url' => get_site_url(),
3709
+ // Special params.
3710
+ 'is_active' => true,
3711
+ 'is_uninstalled' => false,
3712
+ ), $override );
3713
+ }
3714
+
3715
+ /**
3716
+ * Update install only if changed.
3717
+ *
3718
+ * @author Vova Feldman (@svovaf)
3719
+ * @since 1.0.9
3720
+ *
3721
+ * @param string[] string $override
3722
+ * @param bool $flush
3723
+ *
3724
+ * @return false|object|string
3725
+ */
3726
+ private function send_install_update( $override = array(), $flush = false ) {
3727
+ $this->_logger->entrance();
3728
+
3729
+ $check_properties = $this->get_install_data_for_api( $override );
3730
+
3731
+ if ( $flush ) {
3732
+ $params = $check_properties;
3733
+ } else {
3734
+ $params = array();
3735
+ $special = array();
3736
+ $special_override = false;
3737
+
3738
+ foreach ( $check_properties as $p => $v ) {
3739
+ if ( property_exists( $this->_site, $p ) ) {
3740
+ if ( ! empty( $this->_site->{$p} ) &&
3741
+ $this->_site->{$p} != $v
3742
+ ) {
3743
+ $this->_site->{$p} = $v;
3744
+ $params[ $p ] = $v;
3745
+ }
3746
+ } else {
3747
+ $special[ $p ] = $v;
3748
+
3749
+ if ( isset( $override[ $p ] ) ||
3750
+ 'plugins' === $p ||
3751
+ 'themes' === $p
3752
+ ) {
3753
+ $special_override = true;
3754
+ }
3755
+ }
3756
+ }
3757
+
3758
+ if ( $special_override || 0 < count( $params ) ) {
3759
+ // Add special params only if has at least one
3760
+ // standard param, or if explicitly requested to
3761
+ // override a special param or a param which is not exist
3762
+ // in the install object.
3763
+ $params = array_merge( $params, $special );
3764
+ }
3765
+ }
3766
+
3767
+ if ( 0 < count( $params ) ) {
3768
+ // Update last install sync timestamp.
3769
+ $this->_storage->install_sync_timestamp = time();
3770
+
3771
+ $params['uid'] = $this->get_anonymous_id();
3772
+
3773
+ // Send updated values to FS.
3774
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
3775
+
3776
+ if ( ! $this->is_api_error( $site ) ) {
3777
+ // I successfully sent install update, clear scheduled sync if exist.
3778
+ $this->clear_install_sync_cron();
3779
+ }
3780
+
3781
+ return $site;
3782
+ }
3783
+
3784
+ return false;
3785
+ }
3786
+
3787
+ /**
3788
+ * Update install only if changed.
3789
+ *
3790
+ * @author Vova Feldman (@svovaf)
3791
+ * @since 1.0.9
3792
+ *
3793
+ * @param string[] string $override
3794
+ * @param bool $flush
3795
+ *
3796
+ * @return false|object|string
3797
+ */
3798
+ private function sync_install( $override = array(), $flush = false ) {
3799
+ $this->_logger->entrance();
3800
+
3801
+ $site = $this->send_install_update( $override, $flush );
3802
+
3803
+ if ( false === $site ) {
3804
+ // No sync required.
3805
+ return;
3806
+ }
3807
+
3808
+ if ( $this->is_api_error( $site ) ) {
3809
+ // Failed to sync, don't update locally.
3810
+ return;
3811
+ }
3812
+
3813
+ $plan = $this->get_plan();
3814
+ $this->_site = new FS_Site( $site );
3815
+ $this->_site->plan = $plan;
3816
+
3817
+ $this->_store_site( true );
3818
+ }
3819
+
3820
+ /**
3821
+ * Plugin uninstall hook.
3822
+ *
3823
+ * @author Vova Feldman (@svovaf)
3824
+ * @since 1.0.1
3825
+ *
3826
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3827
+ */
3828
+ function _uninstall_plugin_event( $check_user = true ) {
3829
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3830
+
3831
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3832
+ return;
3833
+ }
3834
+
3835
+ $params = array();
3836
+ if ( isset( $this->_storage->uninstall_reason ) ) {
3837
+ $params['reason_id'] = $this->_storage->uninstall_reason->id;
3838
+ $params['reason_info'] = $this->_storage->uninstall_reason->info;
3839
+ }
3840
+
3841
+ if ( ! $this->is_registered() && isset( $this->_storage->uninstall_reason ) ) {
3842
+ // Send anonymous uninstall event only if user submitted a feedback.
3843
+ $params['uid'] = $this->get_anonymous_id();
3844
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
3845
+ } else {
3846
+ // Send uninstall event.
3847
+ $this->send_install_update( array_merge( $params, array(
3848
+ 'is_active' => false,
3849
+ 'is_uninstalled' => true,
3850
+ ) ) );
3851
+ }
3852
+
3853
+ // @todo Decide if we want to delete plugin information from db.
3854
+ }
3855
+
3856
+ /**
3857
+ * @author Vova Feldman (@svovaf)
3858
+ * @since 1.1.1
3859
+ *
3860
+ * @return string
3861
+ */
3862
+ private function premium_plugin_basename() {
3863
+ return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
3864
+ }
3865
+
3866
+ /**
3867
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
3868
+ *
3869
+ * @author Vova Feldman (@svovaf)
3870
+ * @since 1.0.2
3871
+ */
3872
+ public static function _uninstall_plugin_hook() {
3873
+ self::_load_required_static();
3874
+
3875
+ self::$_static_logger->entrance();
3876
+
3877
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3878
+ return;
3879
+ }
3880
+
3881
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
3882
+
3883
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
3884
+
3885
+ define( 'WP_FS__UNINSTALL_MODE', true );
3886
+
3887
+ $fs = self::get_instance_by_file( $plugin_file );
3888
+
3889
+ if ( is_object( $fs ) ) {
3890
+ self::require_plugin_essentials();
3891
+
3892
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
3893
+ is_plugin_active( $fs->premium_plugin_basename() )
3894
+ ) {
3895
+ // Deleting Free or Premium plugin version while the other version still installed.
3896
+ return;
3897
+ }
3898
+
3899
+ $fs->_uninstall_plugin_event();
3900
+
3901
+ $fs->do_action( 'after_uninstall' );
3902
+ }
3903
+ }
3904
+
3905
+ #region Plugin Information ------------------------------------------------------------------
3906
+
3907
+ /**
3908
+ * Load WordPress core plugin.php essential module.
3909
+ *
3910
+ * @author Vova Feldman (@svovaf)
3911
+ * @since 1.1.1
3912
+ */
3913
+ private static function require_plugin_essentials() {
3914
+ if ( ! function_exists( 'get_plugins' ) ) {
3915
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
3916
+ }
3917
+ }
3918
+
3919
+ /**
3920
+ * Load WordPress core pluggable.php module.
3921
+ *
3922
+ * @author Vova Feldman (@svovaf)
3923
+ * @since 1.1.2
3924
+ */
3925
+ private static function require_pluggable_essentials() {
3926
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
3927
+ require_once( ABSPATH . 'wp-includes/pluggable.php' );
3928
+ }
3929
+ }
3930
+
3931
+ /**
3932
+ * Return plugin data.
3933
+ *
3934
+ * @author Vova Feldman (@svovaf)
3935
+ * @since 1.0.1
3936
+ *
3937
+ * @return array
3938
+ */
3939
+ function get_plugin_data() {
3940
+ if ( ! isset( $this->_plugin_data ) ) {
3941
+ self::require_plugin_essentials();
3942
+
3943
+ $this->_plugin_data = get_plugin_data( $this->_plugin_main_file_path );
3944
+ }
3945
+
3946
+ return $this->_plugin_data;
3947
+ }
3948
+
3949
+ /**
3950
+ * @author Vova Feldman (@svovaf)
3951
+ * @since 1.0.1
3952
+ *
3953
+ * @return string Plugin slug.
3954
+ */
3955
+ function get_slug() {
3956
+ return $this->_slug;
3957
+ }
3958
+
3959
+ /**
3960
+ * @author Vova Feldman (@svovaf)
3961
+ * @since 1.0.1
3962
+ *
3963
+ * @return number Plugin ID.
3964
+ */
3965
+ function get_id() {
3966
+ return $this->_plugin->id;
3967
+ }
3968
+
3969
+ /**
3970
+ * @author Vova Feldman (@svovaf)
3971
+ * @since 1.0.1
3972
+ *
3973
+ * @return string Plugin public key.
3974
+ */
3975
+ function get_public_key() {
3976
+ return $this->_plugin->public_key;
3977
+ }
3978
+
3979
+ /**
3980
+ * Will be available only on sandbox mode.
3981
+ *
3982
+ * @author Vova Feldman (@svovaf)
3983
+ * @since 1.0.4
3984
+ *
3985
+ * @return mixed Plugin secret key.
3986
+ */
3987
+ function get_secret_key() {
3988
+ return $this->_plugin->secret_key;
3989
+ }
3990
+
3991
+ /**
3992
+ * @author Vova Feldman (@svovaf)
3993
+ * @since 1.1.1
3994
+ *
3995
+ * @return bool
3996
+ */
3997
+ function has_secret_key() {
3998
+ return ! empty( $this->_plugin->secret_key );
3999
+ }
4000
+
4001
+ /**
4002
+ * @author Vova Feldman (@svovaf)
4003
+ * @since 1.0.9
4004
+ *
4005
+ * @return string
4006
+ */
4007
+ function get_plugin_name() {
4008
+ $this->_logger->entrance();
4009
+
4010
+ if ( ! isset( $this->_plugin_name ) ) {
4011
+ $plugin_data = $this->get_plugin_data();
4012
+
4013
+ // Get name.
4014
+ $this->_plugin_name = $plugin_data['Name'];
4015
+
4016
+ // Check if plugin name contains [Premium] suffix and remove it.
4017
+ $suffix = '[premium]';
4018
+ $suffix_len = strlen( $suffix );
4019
+
4020
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
4021
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
4022
+ ) {
4023
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
4024
+ }
4025
+
4026
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
4027
+ }
4028
+
4029
+ return $this->_plugin_name;
4030
+ }
4031
+
4032
+ /**
4033
+ * @author Vova Feldman (@svovaf)
4034
+ * @since 1.0.0
4035
+ *
4036
+ * @return string
4037
+ */
4038
+ function get_plugin_version() {
4039
+ $this->_logger->entrance();
4040
+
4041
+ $plugin_data = $this->get_plugin_data();
4042
+
4043
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
4044
+
4045
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
4046
+ }
4047
+
4048
+ /**
4049
+ * @author Vova Feldman (@svovaf)
4050
+ * @since 1.0.4
4051
+ *
4052
+ * @return string
4053
+ */
4054
+ function get_plugin_basename() {
4055
+ return $this->_plugin_basename;
4056
+ }
4057
+
4058
+ function get_plugin_folder_name() {
4059
+ $this->_logger->entrance();
4060
+
4061
+ $plugin_folder = $this->_plugin_basename;
4062
+
4063
+ while ( '.' !== dirname( $plugin_folder ) ) {
4064
+ $plugin_folder = dirname( $plugin_folder );
4065
+ }
4066
+
4067
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
4068
+
4069
+ return $plugin_folder;
4070
+ }
4071
+
4072
+ #endregion ------------------------------------------------------------------
4073
+
4074
+ /* Account
4075
+ ------------------------------------------------------------------------------------------------------------------*/
4076
+
4077
+ /**
4078
+ * Find plugin's slug by plugin's basename.
4079
+ *
4080
+ * @author Vova Feldman (@svovaf)
4081
+ * @since 1.0.9
4082
+ *
4083
+ * @param string $plugin_base_name
4084
+ *
4085
+ * @return false|string
4086
+ */
4087
+ private static function find_slug_by_basename( $plugin_base_name ) {
4088
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4089
+
4090
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
4091
+ return false;
4092
+ }
4093
+
4094
+ return $file_slug_map[ $plugin_base_name ];
4095
+ }
4096
+
4097
+ /**
4098
+ * Store the map between the plugin's basename to the slug.
4099
+ *
4100
+ * @author Vova Feldman (@svovaf)
4101
+ * @since 1.0.9
4102
+ */
4103
+ private function store_file_slug_map() {
4104
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4105
+
4106
+ if ( ! array( $file_slug_map ) ) {
4107
+ $file_slug_map = array();
4108
+ }
4109
+
4110
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
4111
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
4112
+ ) {
4113
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
4114
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
4115
+ }
4116
+ }
4117
+
4118
+ /**
4119
+ * @return FS_User[]
4120
+ */
4121
+ static function get_all_users() {
4122
+ $users = self::$_accounts->get_option( 'users', array() );
4123
+
4124
+ if ( ! is_array( $users ) ) {
4125
+ $users = array();
4126
+ }
4127
+
4128
+ return $users;
4129
+ }
4130
+
4131
+ /**
4132
+ * @return FS_Site[]
4133
+ */
4134
+ private static function get_all_sites() {
4135
+ $sites = self::$_accounts->get_option( 'sites', array() );
4136
+
4137
+ if ( ! is_array( $sites ) ) {
4138
+ $sites = array();
4139
+ }
4140
+
4141
+ return $sites;
4142
+ }
4143
+
4144
+ /**
4145
+ * @author Vova Feldman (@svovaf)
4146
+ * @since 1.0.6
4147
+ *
4148
+ * @return FS_Plugin_License[]
4149
+ */
4150
+ private static function get_all_licenses() {
4151
+ $licenses = self::$_accounts->get_option( 'licenses', array() );
4152
+
4153
+ if ( ! is_array( $licenses ) ) {
4154
+ $licenses = array();
4155
+ }
4156
+
4157
+ return $licenses;
4158
+ }
4159
+
4160
+ /**
4161
+ * @return FS_Plugin_Plan[]
4162
+ */
4163
+ private static function get_all_plans() {
4164
+ $plans = self::$_accounts->get_option( 'plans', array() );
4165
+
4166
+ if ( ! is_array( $plans ) ) {
4167
+ $plans = array();
4168
+ }
4169
+
4170
+ return $plans;
4171
+ }
4172
+
4173
+ /**
4174
+ * @author Vova Feldman (@svovaf)
4175
+ * @since 1.0.4
4176
+ *
4177
+ * @return FS_Plugin_Tag[]
4178
+ */
4179
+ private static function get_all_updates() {
4180
+ $updates = self::$_accounts->get_option( 'updates', array() );
4181
+
4182
+ if ( ! is_array( $updates ) ) {
4183
+ $updates = array();
4184
+ }
4185
+
4186
+ return $updates;
4187
+ }
4188
+
4189
+ /**
4190
+ * @author Vova Feldman (@svovaf)
4191
+ * @since 1.0.6
4192
+ *
4193
+ * @return FS_Plugin[]|false
4194
+ */
4195
+ private static function get_all_addons() {
4196
+ $addons = self::$_accounts->get_option( 'addons', array() );
4197
+
4198
+ if ( ! is_array( $addons ) ) {
4199
+ $addons = array();
4200
+ }
4201
+
4202
+ return $addons;
4203
+ }
4204
+
4205
+ /**
4206
+ * @author Vova Feldman (@svovaf)
4207
+ * @since 1.0.6
4208
+ *
4209
+ * @return FS_Plugin[]|false
4210
+ */
4211
+ private static function get_all_account_addons() {
4212
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
4213
+
4214
+ if ( ! is_array( $addons ) ) {
4215
+ $addons = array();
4216
+ }
4217
+
4218
+ return $addons;
4219
+ }
4220
+
4221
+ /**
4222
+ * Check if user is registered.
4223
+ *
4224
+ * @author Vova Feldman (@svovaf)
4225
+ * @since 1.0.1
4226
+ * @return bool
4227
+ */
4228
+ function is_registered() {
4229
+ return is_object( $this->_user );
4230
+ }
4231
+
4232
+ /**
4233
+ * @author Vova Feldman (@svovaf)
4234
+ * @since 1.0.4
4235
+ *
4236
+ * @return FS_Plugin
4237
+ */
4238
+ function get_plugin() {
4239
+ return $this->_plugin;
4240
+ }
4241
+
4242
+ /**
4243
+ * @author Vova Feldman (@svovaf)
4244
+ * @since 1.0.3
4245
+ *
4246
+ * @return FS_User
4247
+ */
4248
+ function get_user() {
4249
+ return $this->_user;
4250
+ }
4251
+
4252
+ /**
4253
+ * @author Vova Feldman (@svovaf)
4254
+ * @since 1.0.3
4255
+ *
4256
+ * @return FS_Site
4257
+ */
4258
+ function get_site() {
4259
+ return $this->_site;
4260
+ }
4261
+
4262
+ /**
4263
+ * Get plugin add-ons.
4264
+ *
4265
+ * @author Vova Feldman (@svovaf)
4266
+ * @since 1.0.6
4267
+ *
4268
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4269
+ *
4270
+ * @return FS_Plugin[]|false
4271
+ */
4272
+ function get_addons() {
4273
+ $this->_logger->entrance();
4274
+
4275
+ $all_addons = self::get_all_addons();
4276
+
4277
+ /**
4278
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4279
+ */
4280
+ if ( ! is_array( $all_addons ) ||
4281
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4282
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4283
+ empty( $all_addons[ $this->_plugin->id ] )
4284
+ ) {
4285
+ if ( $this->_has_addons ) {
4286
+ $addons = $this->_sync_addons();
4287
+
4288
+ if ( ! empty( $addons ) ) {
4289
+ $all_addons = self::get_all_addons();
4290
+ }
4291
+ }
4292
+ }
4293
+
4294
+ if ( ! is_array( $all_addons ) ||
4295
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4296
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4297
+ empty( $all_addons[ $this->_plugin->id ] )
4298
+ ) {
4299
+ return false;
4300
+ }
4301
+
4302
+ return $all_addons[ $this->_plugin->id ];
4303
+ }
4304
+
4305
+ /**
4306
+ * @author Vova Feldman (@svovaf)
4307
+ * @since 1.0.6
4308
+ *
4309
+ * @return FS_Plugin[]|false
4310
+ */
4311
+ function get_account_addons() {
4312
+ $this->_logger->entrance();
4313
+
4314
+ $addons = self::get_all_account_addons();
4315
+
4316
+ if ( ! is_array( $addons ) ||
4317
+ ! isset( $addons[ $this->_plugin->id ] ) ||
4318
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
4319
+ 0 === count( $addons[ $this->_plugin->id ] )
4320
+ ) {
4321
+ return false;
4322
+ }
4323
+
4324
+ return $addons[ $this->_plugin->id ];
4325
+ }
4326
+
4327
+ /**
4328
+ * Check if user has any
4329
+ *
4330
+ * @author Vova Feldman (@svovaf)
4331
+ * @since 1.1.6
4332
+ *
4333
+ * @return bool
4334
+ */
4335
+ function has_account_addons() {
4336
+ $addons = $this->get_account_addons();
4337
+
4338
+ return is_array( $addons ) && ( 0 < count( $addons ) );
4339
+ }
4340
+
4341
+
4342
+ /**
4343
+ * Get add-on by ID (from local data).
4344
+ *
4345
+ * @author Vova Feldman (@svovaf)
4346
+ * @since 1.0.6
4347
+ *
4348
+ * @param number $id
4349
+ *
4350
+ * @return FS_Plugin|false
4351
+ */
4352
+ function get_addon( $id ) {
4353
+ $this->_logger->entrance();
4354
+
4355
+ $addons = $this->get_addons();
4356
+
4357
+ if ( is_array( $addons ) ) {
4358
+ foreach ( $addons as $addon ) {
4359
+ if ( $id == $addon->id ) {
4360
+ return $addon;
4361
+ }
4362
+ }
4363
+ }
4364
+
4365
+ return false;
4366
+ }
4367
+
4368
+ /**
4369
+ * Get add-on by slug (from local data).
4370
+ *
4371
+ * @author Vova Feldman (@svovaf)
4372
+ * @since 1.0.6
4373
+ *
4374
+ * @param string $slug
4375
+ *
4376
+ * @return FS_Plugin|false
4377
+ */
4378
+ function get_addon_by_slug( $slug ) {
4379
+ $this->_logger->entrance();
4380
+
4381
+ $addons = $this->get_addons();
4382
+
4383
+ if ( is_array( $addons ) ) {
4384
+ foreach ( $addons as $addon ) {
4385
+ if ( $slug == $addon->slug ) {
4386
+ return $addon;
4387
+ }
4388
+ }
4389
+ }
4390
+
4391
+ return false;
4392
+ }
4393
+
4394
+ #region Plans & Licensing ------------------------------------------------------------------
4395
+
4396
+ /**
4397
+ * Check if running premium plugin code.
4398
+ *
4399
+ * @author Vova Feldman (@svovaf)
4400
+ * @since 1.0.5
4401
+ *
4402
+ * @return bool
4403
+ */
4404
+ function is_premium() {
4405
+ return $this->_plugin->is_premium;
4406
+ }
4407
+
4408
+ /**
4409
+ * Get site's plan ID.
4410
+ *
4411
+ * @author Vova Feldman (@svovaf)
4412
+ * @since 1.0.2
4413
+ *
4414
+ * @return number
4415
+ */
4416
+ function get_plan_id() {
4417
+ return $this->_site->plan->id;
4418
+ }
4419
+
4420
+ /**
4421
+ * Get site's plan title.
4422
+ *
4423
+ * @author Vova Feldman (@svovaf)
4424
+ * @since 1.0.2
4425
+ *
4426
+ * @return string
4427
+ */
4428
+ function get_plan_title() {
4429
+ return $this->_site->plan->title;
4430
+ }
4431
+
4432
+ /**
4433
+ * @author Vova Feldman (@svovaf)
4434
+ * @since 1.0.9
4435
+ *
4436
+ * @return FS_Plugin_Plan
4437
+ */
4438
+ function get_plan() {
4439
+ return is_object( $this->_site->plan ) ? $this->_site->plan : false;
4440
+ }
4441
+
4442
+ /**
4443
+ * @author Vova Feldman (@svovaf)
4444
+ * @since 1.0.3
4445
+ *
4446
+ * @return bool
4447
+ */
4448
+ function is_trial() {
4449
+ $this->_logger->entrance();
4450
+
4451
+ if ( ! $this->is_registered() ) {
4452
+ return false;
4453
+ }
4454
+
4455
+ return $this->_site->is_trial();
4456
+ }
4457
+
4458
+ /**
4459
+ * Check if currently in a trial with payment method (credit card or paypal).
4460
+ *
4461
+ * @author Vova Feldman (@svovaf)
4462
+ * @since 1.1.7
4463
+ *
4464
+ * @return bool
4465
+ */
4466
+ function is_paid_trial() {
4467
+ $this->_logger->entrance();
4468
+
4469
+ if ( ! $this->is_trial() ) {
4470
+ return false;
4471
+ }
4472
+
4473
+ return $this->has_active_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
4474
+ }
4475
+
4476
+ /**
4477
+ * Check if trial already utilized.
4478
+ *
4479
+ * @since 1.0.9
4480
+ *
4481
+ * @return bool
4482
+ */
4483
+ function is_trial_utilized() {
4484
+ $this->_logger->entrance();
4485
+
4486
+ if ( ! $this->is_registered() ) {
4487
+ return false;
4488
+ }
4489
+
4490
+ return $this->_site->is_trial_utilized();
4491
+ }
4492
+
4493
+ /**
4494
+ * Get trial plan information (if in trial).
4495
+ *
4496
+ * @author Vova Feldman (@svovaf)
4497
+ * @since 1.0.9
4498
+ *
4499
+ * @return bool|FS_Plugin_Plan
4500
+ */
4501
+ function get_trial_plan() {
4502
+ $this->_logger->entrance();
4503
+
4504
+ if ( ! $this->is_trial() ) {
4505
+ return false;
4506
+ }
4507
+
4508
+ return $this->_storage->trial_plan;
4509
+ }
4510
+
4511
+ /**
4512
+ * Check if the user has an activated and valid paid license on current plugin's install.
4513
+ *
4514
+ * @since 1.0.9
4515
+ *
4516
+ * @return bool
4517
+ */
4518
+ function is_paying() {
4519
+ $this->_logger->entrance();
4520
+
4521
+ if ( ! $this->is_registered() ) {
4522
+ return false;
4523
+ }
4524
+
4525
+ if ( ! $this->has_paid_plan() ) {
4526
+ return false;
4527
+ }
4528
+
4529
+ return (
4530
+ ! $this->is_trial() &&
4531
+ 'free' !== $this->_site->plan->name &&
4532
+ $this->has_features_enabled_license()
4533
+ );
4534
+ }
4535
+
4536
+ /**
4537
+ * @author Vova Feldman (@svovaf)
4538
+ * @since 1.0.4
4539
+ *
4540
+ * @return bool
4541
+ */
4542
+ function is_free_plan() {
4543
+ if ( ! $this->is_registered() ) {
4544
+ return true;
4545
+ }
4546
+
4547
+ if ( ! $this->has_paid_plan() ) {
4548
+ return true;
4549
+ }
4550
+
4551
+ return (
4552
+ 'free' === $this->_site->plan->name ||
4553
+ ! $this->has_features_enabled_license()
4554
+ );
4555
+ }
4556
+
4557
+ /**
4558
+ * @author Vova Feldman (@svovaf)
4559
+ * @since 1.0.5
4560
+ *
4561
+ * @return bool
4562
+ */
4563
+ function _has_premium_license() {
4564
+ $this->_logger->entrance();
4565
+
4566
+ $premium_license = $this->_get_available_premium_license();
4567
+
4568
+ return ( false !== $premium_license );
4569
+ }
4570
+
4571
+ /**
4572
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
4573
+ *
4574
+ * @author Vova Feldman (@svovaf)
4575
+ * @since 1.1.7.3
4576
+ *
4577
+ * @return bool
4578
+ */
4579
+ private function has_any_license() {
4580
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
4581
+ }
4582
+
4583
+ /**
4584
+ * @author Vova Feldman (@svovaf)
4585
+ * @since 1.0.5
4586
+ *
4587
+ * @return FS_Plugin_License
4588
+ */
4589
+ function _get_available_premium_license() {
4590
+ $this->_logger->entrance();
4591
+
4592
+ if ( ! $this->has_paid_plan() ) {
4593
+ return false;
4594
+ }
4595
+
4596
+ if ( is_array( $this->_licenses ) ) {
4597
+ foreach ( $this->_licenses as $license ) {
4598
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
4599
+ return $license;
4600
+ }
4601
+ }
4602
+ }
4603
+
4604
+ return false;
4605
+ }
4606
+
4607
+ /**
4608
+ * Sync local plugin plans with remote server.
4609
+ *
4610
+ * @author Vova Feldman (@svovaf)
4611
+ * @since 1.0.5
4612
+ *
4613
+ * @return FS_Plugin_Plan[]|object
4614
+ */
4615
+ function _sync_plans() {
4616
+ $plans = $this->_fetch_plugin_plans();
4617
+ if ( ! $this->is_api_error( $plans ) ) {
4618
+ $this->_plans = $plans;
4619
+ $this->_store_plans();
4620
+ }
4621
+
4622
+ $this->do_action( 'after_plans_sync', $plans );
4623
+
4624
+ return $this->_plans;
4625
+ }
4626
+
4627
+ /**
4628
+ * @author Vova Feldman (@svovaf)
4629
+ * @since 1.0.5
4630
+ *
4631
+ * @param number $id
4632
+ *
4633
+ * @return FS_Plugin_Plan
4634
+ */
4635
+ function _get_plan_by_id( $id ) {
4636
+ $this->_logger->entrance();
4637
+
4638
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4639
+ $this->_sync_plans();
4640
+ }
4641
+
4642
+ foreach ( $this->_plans as $plan ) {
4643
+ if ( $id == $plan->id ) {
4644
+ return $plan;
4645
+ }
4646
+ }
4647
+
4648
+ return false;
4649
+ }
4650
+
4651
+ /**
4652
+ * @author Vova Feldman (@svovaf)
4653
+ * @since 1.1.8.1
4654
+ *
4655
+ * @param string $name
4656
+ *
4657
+ * @return FS_Plugin_Plan|false
4658
+ */
4659
+ private function get_plan_by_name( $name ) {
4660
+ $this->_logger->entrance();
4661
+
4662
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4663
+ $this->_sync_plans();
4664
+ }
4665
+
4666
+ foreach ( $this->_plans as $plan ) {
4667
+ if ( $name == $plan->name ) {
4668
+ return $plan;
4669
+ }
4670
+ }
4671
+
4672
+ return false;
4673
+ }
4674
+
4675
+ /**
4676
+ * Sync local plugin plans with remote server.
4677
+ *
4678
+ * @author Vova Feldman (@svovaf)
4679
+ * @since 1.0.6
4680
+ *
4681
+ * @return FS_Plugin_License[]|object
4682
+ */
4683
+ function _sync_licenses() {
4684
+ $licenses = $this->_fetch_licenses();
4685
+ if ( ! $this->is_api_error( $licenses ) ) {
4686
+ $this->_licenses = $licenses;
4687
+ $this->_store_licenses();
4688
+ }
4689
+
4690
+ // Update current license.
4691
+ if ( is_object( $this->_license ) ) {
4692
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
4693
+ }
4694
+
4695
+ return $this->_licenses;
4696
+ }
4697
+
4698
+ /**
4699
+ * @author Vova Feldman (@svovaf)
4700
+ * @since 1.0.5
4701
+ *
4702
+ * @param number $id
4703
+ *
4704
+ * @return FS_Plugin_License
4705
+ */
4706
+ function _get_license_by_id( $id ) {
4707
+ $this->_logger->entrance();
4708
+
4709
+ if ( ! is_numeric( $id ) ) {
4710
+ return false;
4711
+ }
4712
+
4713
+ if ( ! is_array( $this->_licenses ) || 0 === count( $this->_licenses ) ) {
4714
+ $this->_sync_licenses();
4715
+ }
4716
+
4717
+ foreach ( $this->_licenses as $license ) {
4718
+ if ( $id == $license->id ) {
4719
+ return $license;
4720
+ }
4721
+ }
4722
+
4723
+ return false;
4724
+ }
4725
+
4726
+ /**
4727
+ * Sync site's license with user licenses.
4728
+ *
4729
+ * @author Vova Feldman (@svovaf)
4730
+ * @since 1.0.6
4731
+ *
4732
+ * @param FS_Plugin_License|null $new_license
4733
+ */
4734
+ function _update_site_license( $new_license ) {
4735
+ $this->_logger->entrance();
4736
+
4737
+ $this->_license = $new_license;
4738
+
4739
+ if ( ! is_object( $new_license ) ) {
4740
+ $this->_site->license_id = null;
4741
+ $this->_sync_site_subscription( null );
4742
+
4743
+ return;
4744
+ }
4745
+
4746
+ $this->_site->license_id = $this->_license->id;
4747
+
4748
+ if ( ! is_array( $this->_licenses ) ) {
4749
+ $this->_licenses = array();
4750
+ }
4751
+
4752
+ $is_license_found = false;
4753
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
4754
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
4755
+ $this->_licenses[ $i ] = $new_license;
4756
+
4757
+ $is_license_found = true;
4758
+ break;
4759
+ }
4760
+ }
4761
+
4762
+ // If new license just append.
4763
+ if ( ! $is_license_found ) {
4764
+ $this->_licenses[] = $new_license;
4765
+ }
4766
+
4767
+ $this->_sync_site_subscription( $new_license );
4768
+ }
4769
+
4770
+ /**
4771
+ * Sync site's subscription.
4772
+ *
4773
+ * @author Vova Feldman (@svovaf)
4774
+ * @since 1.0.9
4775
+ *
4776
+ * @param FS_Plugin_License|null $license
4777
+ *
4778
+ * @return bool|\FS_Subscription
4779
+ */
4780
+ private function _sync_site_subscription( $license ) {
4781
+ if ( ! is_object( $license ) ) {
4782
+ unset( $this->_storage->subscription );
4783
+
4784
+ return false;
4785
+ }
4786
+
4787
+ // Load subscription details if not lifetime.
4788
+ $subscription = $license->is_lifetime() ?
4789
+ false :
4790
+ $this->_fetch_site_license_subscription();
4791
+
4792
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
4793
+ $this->_storage->subscription = $subscription;
4794
+ } else {
4795
+ unset( $this->_storage->subscription );
4796
+ }
4797
+
4798
+ return $subscription;
4799
+ }
4800
+
4801
+ /**
4802
+ * @author Vova Feldman (@svovaf)
4803
+ * @since 1.0.6
4804
+ *
4805
+ * @return bool|\FS_Plugin_License
4806
+ */
4807
+ function _get_license() {
4808
+ return $this->_license;
4809
+ }
4810
+
4811
+ /**
4812
+ * @return bool|\FS_Subscription
4813
+ */
4814
+ function _get_subscription() {
4815
+ return isset( $this->_storage->subscription ) ?
4816
+ $this->_storage->subscription :
4817
+ false;
4818
+ }
4819
+
4820
+ /**
4821
+ * @author Vova Feldman (@svovaf)
4822
+ * @since 1.0.2
4823
+ *
4824
+ * @param string $plan Plan name
4825
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
4826
+ *
4827
+ * @return bool
4828
+ */
4829
+ function is_plan( $plan, $exact = false ) {
4830
+ $this->_logger->entrance();
4831
+
4832
+ if ( ! $this->is_registered() ) {
4833
+ return false;
4834
+ }
4835
+
4836
+ $plan = strtolower( $plan );
4837
+
4838
+ if ( $this->_site->plan->name === $plan ) // Exact plan.
4839
+ {
4840
+ return true;
4841
+ } else if ( $exact ) // Required exact, but plans are different.
4842
+ {
4843
+ return false;
4844
+ }
4845
+
4846
+ $current_plan_order = - 1;
4847
+ $required_plan_order = - 1;
4848
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4849
+ if ( $plan === $this->_plans[ $i ]->name ) {
4850
+ $required_plan_order = $i;
4851
+ } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
4852
+ $current_plan_order = $i;
4853
+ }
4854
+ }
4855
+
4856
+ return ( $current_plan_order > $required_plan_order );
4857
+ }
4858
+
4859
+ /**
4860
+ * Check if plan based on trial. If not in trial mode, should return false.
4861
+ *
4862
+ * @since 1.0.9
4863
+ *
4864
+ * @param string $plan Plan name
4865
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
4866
+ *
4867
+ * @return bool
4868
+ */
4869
+ function is_trial_plan( $plan, $exact = false ) {
4870
+ $this->_logger->entrance();
4871
+
4872
+ if ( ! $this->is_registered() ) {
4873
+ return false;
4874
+ }
4875
+
4876
+ if ( ! $this->is_trial() ) {
4877
+ return false;
4878
+ }
4879
+
4880
+ if ( ! isset( $this->_storage->trial_plan ) ) {
4881
+ // Store trial plan information.
4882
+ $this->_enrich_site_trial_plan( true );
4883
+ }
4884
+
4885
+ if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
4886
+ {
4887
+ return true;
4888
+ } else if ( $exact ) // Required exact, but plans are different.
4889
+ {
4890
+ return false;
4891
+ }
4892
+
4893
+ $current_plan_order = - 1;
4894
+ $required_plan_order = - 1;
4895
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4896
+ if ( $plan === $this->_plans[ $i ]->name ) {
4897
+ $required_plan_order = $i;
4898
+ } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
4899
+ $current_plan_order = $i;
4900
+ }
4901
+ }
4902
+
4903
+ return ( $current_plan_order > $required_plan_order );
4904
+ }
4905
+
4906
+ /**
4907
+ * Check if plugin has any paid plans.
4908
+ *
4909
+ * @author Vova Feldman (@svovaf)
4910
+ * @since 1.0.7
4911
+ *
4912
+ * @return bool
4913
+ */
4914
+ function has_paid_plan() {
4915
+ return $this->_has_paid_plans || FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
4916
+ }
4917
+
4918
+ /**
4919
+ * Check if plugin has any plan with a trail.
4920
+ *
4921
+ * @author Vova Feldman (@svovaf)
4922
+ * @since 1.0.9
4923
+ *
4924
+ * @return bool
4925
+ */
4926
+ function has_trial_plan() {
4927
+ if ( ! $this->is_registered() ) {
4928
+ return false;
4929
+ }
4930
+
4931
+ return $this->_storage->get( 'has_trial_plan', false );
4932
+ }
4933
+
4934
+ /**
4935
+ * Check if plugin has any free plan, or is it premium only.
4936
+ *
4937
+ * Note: If no plans configured, assume plugin is free.
4938
+ *
4939
+ * @author Vova Feldman (@svovaf)
4940
+ * @since 1.0.7
4941
+ *
4942
+ * @return bool
4943
+ */
4944
+ function has_free_plan() {
4945
+ return FS_Plan_Manager::instance()->has_free_plan( $this->_plans );
4946
+ }
4947
+
4948
+ #region URL Generators
4949
+
4950
+ /**
4951
+ * Alias to pricing_url().
4952
+ *
4953
+ * @author Vova Feldman (@svovaf)
4954
+ * @since 1.0.2
4955
+ *
4956
+ * @uses pricing_url()
4957
+ *
4958
+ * @param string $period Billing cycle
4959
+ * @param bool $is_trial
4960
+ *
4961
+ * @return string
4962
+ */
4963
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
4964
+ return $this->pricing_url( $period, $is_trial );
4965
+ }
4966
+
4967
+ /**
4968
+ * @author Vova Feldman (@svovaf)
4969
+ * @since 1.0.9
4970
+ *
4971
+ * @uses get_upgrade_url()
4972
+ *
4973
+ * @return string
4974
+ */
4975
+ function get_trial_url() {
4976
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
4977
+ }
4978
+
4979
+ /**
4980
+ * Plugin's pricing URL.
4981
+ *
4982
+ * @author Vova Feldman (@svovaf)
4983
+ * @since 1.0.4
4984
+ *
4985
+ * @param string $billing_cycle Billing cycle
4986
+ *
4987
+ * @param bool $is_trial
4988
+ *
4989
+ * @return string
4990
+ */
4991
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
4992
+ $this->_logger->entrance();
4993
+
4994
+ $params = array(
4995
+ 'billing_cycle' => $billing_cycle
4996
+ );
4997
+
4998
+ if ( $is_trial ) {
4999
+ $params['trial'] = 'true';
5000
+ }
5001
+
5002
+ return $this->_get_admin_page_url( 'pricing', $params );
5003
+ }
5004
+
5005
+ /**
5006
+ * Checkout page URL.
5007
+ *
5008
+ * @author Vova Feldman (@svovaf)
5009
+ * @since 1.0.6
5010
+ *
5011
+ * @param string $billing_cycle Billing cycle
5012
+ * @param bool $is_trial
5013
+ * @param array $extra (optional) Extra parameters, override other query params.
5014
+ *
5015
+ * @return string
5016
+ */
5017
+ function checkout_url(
5018
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5019
+ $is_trial = false,
5020
+ $extra = array()
5021
+ ) {
5022
+ $this->_logger->entrance();
5023
+
5024
+ $params = array(
5025
+ 'checkout' => 'true',
5026
+ 'billing_cycle' => $billing_cycle,
5027
+ );
5028
+
5029
+ if ( $is_trial ) {
5030
+ $params['trial'] = 'true';
5031
+ }
5032
+
5033
+ /**
5034
+ * Params in extra override other params.
5035
+ */
5036
+ $params = array_merge( $params, $extra );
5037
+
5038
+ return $this->_get_admin_page_url( 'pricing', $params );
5039
+ }
5040
+
5041
+ /**
5042
+ * Add-on checkout URL.
5043
+ *
5044
+ * @author Vova Feldman (@svovaf)
5045
+ * @since 1.1.7
5046
+ *
5047
+ * @param number $addon_id
5048
+ * @param number $pricing_id
5049
+ * @param string $billing_cycle
5050
+ * @param bool $is_trial
5051
+ *
5052
+ * @return string
5053
+ */
5054
+ function addon_checkout_url(
5055
+ $addon_id,
5056
+ $pricing_id,
5057
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5058
+ $is_trial = false
5059
+ ) {
5060
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
5061
+ 'plugin_id' => $addon_id,
5062
+ 'pricing_id' => $pricing_id,
5063
+ ) );
5064
+ }
5065
+
5066
+ #endregion
5067
+
5068
+ #endregion ------------------------------------------------------------------
5069
+
5070
+ /**
5071
+ * Check if plugin has any add-ons.
5072
+ *
5073
+ * @author Vova Feldman (@svovaf)
5074
+ * @since 1.0.5
5075
+ *
5076
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
5077
+ *
5078
+ * @return bool
5079
+ */
5080
+ function has_addons() {
5081
+ $this->_logger->entrance();
5082
+
5083
+ return $this->_has_addons;
5084
+ }
5085
+
5086
+ /**
5087
+ * Check if plugin can work in anonymous mode.
5088
+ *
5089
+ * @author Vova Feldman (@svovaf)
5090
+ * @since 1.0.9
5091
+ *
5092
+ * @return bool
5093
+ */
5094
+ function enable_anonymous() {
5095
+ return $this->_enable_anonymous;
5096
+ }
5097
+
5098
+ /**
5099
+ * Check if feature supported with current site's plan.
5100
+ *
5101
+ * @author Vova Feldman (@svovaf)
5102
+ * @since 1.0.1
5103
+ *
5104
+ * @todo IMPLEMENT
5105
+ *
5106
+ * @param number $feature_id
5107
+ *
5108
+ * @throws Exception
5109
+ */
5110
+ function is_feature_supported( $feature_id ) {
5111
+ throw new Exception( 'not implemented' );
5112
+ }
5113
+
5114
+ /**
5115
+ * @author Vova Feldman (@svovaf)
5116
+ * @since 1.0.1
5117
+ *
5118
+ * @return bool Is running in SSL/HTTPS
5119
+ */
5120
+ function is_ssl() {
5121
+ return WP_FS__IS_HTTPS;
5122
+ }
5123
+
5124
+ /**
5125
+ * @author Vova Feldman (@svovaf)
5126
+ * @since 1.0.9
5127
+ *
5128
+ * @return bool Is running in AJAX call.
5129
+ *
5130
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
5131
+ */
5132
+ function is_ajax() {
5133
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
5134
+ }
5135
+
5136
+ /**
5137
+ * @author Vova Feldman (@svovaf)
5138
+ * @since 1.1.7
5139
+ *
5140
+ * @return bool
5141
+ */
5142
+ function is_cron() {
5143
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
5144
+ }
5145
+
5146
+ /**
5147
+ * Check if a real user is visiting the admin dashboard.
5148
+ *
5149
+ * @author Vova Feldman (@svovaf)
5150
+ * @since 1.1.7
5151
+ *
5152
+ * @return bool
5153
+ */
5154
+ function is_user_in_admin() {
5155
+ return is_admin() && ! $this->is_ajax() && ! $this->is_cron();
5156
+ }
5157
+
5158
+ /**
5159
+ * Check if running in HTTPS and if site's plan matching the specified plan.
5160
+ *
5161
+ * @param string $plan
5162
+ * @param bool $exact
5163
+ *
5164
+ * @return bool
5165
+ */
5166
+ function is_ssl_and_plan( $plan, $exact = false ) {
5167
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
5168
+ }
5169
+
5170
+ /**
5171
+ * Construct plugin's settings page URL.
5172
+ *
5173
+ * @author Vova Feldman (@svovaf)
5174
+ * @since 1.0.4
5175
+ *
5176
+ * @param string $page
5177
+ * @param array $params
5178
+ *
5179
+ * @return string
5180
+ */
5181
+ function _get_admin_page_url( $page = '', $params = array() ) {
5182
+ if ( ! $this->_menu->is_top_level() ) {
5183
+ $parent_slug = $this->_menu->get_parent_slug();
5184
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
5185
+ $parent_slug :
5186
+ 'admin.php';
5187
+
5188
+ return add_query_arg( array_merge( $params, array(
5189
+ 'page' => $this->_menu->get_slug( $page ),
5190
+ ) ), admin_url( $menu_file, 'admin' ) );
5191
+ }
5192
+
5193
+ if ( $this->_menu->is_cpt() ) {
5194
+ if ( empty( $page ) && $this->is_activation_mode() ) {
5195
+ return add_query_arg( array_merge( $params, array(
5196
+ 'page' => $this->_menu->get_slug()
5197
+ ) ), admin_url( 'admin.php', 'admin' ) );
5198
+ } else {
5199
+ if ( ! empty( $page ) ) {
5200
+ $params['page'] = $this->_menu->get_slug( $page );
5201
+ }
5202
+
5203
+ return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
5204
+ }
5205
+ } else {
5206
+ return add_query_arg( array_merge( $params, array(
5207
+ 'page' => $this->_menu->get_slug( $page ),
5208
+ ) ), admin_url( 'admin.php', 'admin' ) );
5209
+ }
5210
+ }
5211
+
5212
+
5213
+ /**
5214
+ * Plugin's account URL.
5215
+ *
5216
+ * @author Vova Feldman (@svovaf)
5217
+ * @since 1.0.4
5218
+ *
5219
+ * @param bool|string $action
5220
+ * @param array $params
5221
+ *
5222
+ * @param bool $add_action_nonce
5223
+ *
5224
+ * @return string
5225
+ */
5226
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
5227
+ if ( is_string( $action ) ) {
5228
+ $params['fs_action'] = $action;
5229
+ }
5230
+
5231
+ self::require_pluggable_essentials();
5232
+
5233
+ return ( $add_action_nonce && is_string( $action ) ) ?
5234
+ wp_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
5235
+ $this->_get_admin_page_url( 'account', $params );
5236
+ }
5237
+
5238
+ /**
5239
+ * Plugin's account URL.
5240
+ *
5241
+ * @author Vova Feldman (@svovaf)
5242
+ * @since 1.0.4
5243
+ *
5244
+ * @param bool|string $topic
5245
+ * @param bool|string $message
5246
+ *
5247
+ * @return string
5248
+ */
5249
+ function contact_url( $topic = false, $message = false ) {
5250
+ $params = array();
5251
+ if ( is_string( $topic ) ) {
5252
+ $params['topic'] = $topic;
5253
+ }
5254
+ if ( is_string( $message ) ) {
5255
+ $params['message'] = $message;
5256
+ }
5257
+
5258
+ if ( $this->is_addon() ) {
5259
+ $params['addon_id'] = $this->get_id();
5260
+
5261
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
5262
+ } else {
5263
+ return $this->_get_admin_page_url( 'contact', $params );
5264
+ }
5265
+ }
5266
+
5267
+ /**
5268
+ * Add-on direct info URL.
5269
+ *
5270
+ * @author Vova Feldman (@svovaf)
5271
+ * @since 1.1.0
5272
+ *
5273
+ * @param string $slug
5274
+ *
5275
+ * @return string
5276
+ */
5277
+ function addon_url( $slug ) {
5278
+ return $this->_get_admin_page_url( 'addons', array(
5279
+ 'slug' => $slug
5280
+ ) );
5281
+ }
5282
+
5283
+ /* Logger
5284
+ ------------------------------------------------------------------------------------------------------------------*/
5285
+ /**
5286
+ * @param string $id
5287
+ * @param bool $prefix_slug
5288
+ *
5289
+ * @return FS_Logger
5290
+ */
5291
+ function get_logger( $id = '', $prefix_slug = true ) {
5292
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
5293
+ }
5294
+
5295
+ /**
5296
+ * @param $id
5297
+ * @param bool $load_options
5298
+ * @param bool $prefix_slug
5299
+ *
5300
+ * @return FS_Option_Manager
5301
+ */
5302
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
5303
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
5304
+ }
5305
+
5306
+ /* Security
5307
+ ------------------------------------------------------------------------------------------------------------------*/
5308
+ private function _encrypt( $str ) {
5309
+ if ( is_null( $str ) ) {
5310
+ return null;
5311
+ }
5312
+
5313
+ return base64_encode( $str );
5314
+ }
5315
+
5316
+ private function _decrypt( $str ) {
5317
+ if ( is_null( $str ) ) {
5318
+ return null;
5319
+ }
5320
+
5321
+ return base64_decode( $str );
5322
+ }
5323
+
5324
+ /**
5325
+ * @author Vova Feldman (@svovaf)
5326
+ * @since 1.0.5
5327
+ *
5328
+ * @param FS_Entity $entity
5329
+ *
5330
+ * @return FS_Entity Return an encrypted clone entity.
5331
+ */
5332
+ private function _encrypt_entity( FS_Entity $entity ) {
5333
+ $clone = clone $entity;
5334
+ $props = get_object_vars( $entity );
5335
+
5336
+ foreach ( $props as $key => $val ) {
5337
+ $clone->{$key} = $this->_encrypt( $val );
5338
+ }
5339
+
5340
+ return $clone;
5341
+ }
5342
+
5343
+ /**
5344
+ * @author Vova Feldman (@svovaf)
5345
+ * @since 1.0.5
5346
+ *
5347
+ * @param FS_Entity $entity
5348
+ *
5349
+ * @return FS_Entity Return an decrypted clone entity.
5350
+ */
5351
+ private function _decrypt_entity( FS_Entity $entity ) {
5352
+ $clone = clone $entity;
5353
+ $props = get_object_vars( $entity );
5354
+
5355
+ foreach ( $props as $key => $val ) {
5356
+ $clone->{$key} = $this->_decrypt( $val );
5357
+ }
5358
+
5359
+ return $clone;
5360
+ }
5361
+
5362
+ /**
5363
+ * Tries to activate account based on POST params.
5364
+ *
5365
+ * @author Vova Feldman (@svovaf)
5366
+ * @since 1.0.2
5367
+ */
5368
+ function _activate_account() {
5369
+ if ( $this->is_registered() ) {
5370
+ // Already activated.
5371
+ return;
5372
+ }
5373
+
5374
+ self::_clean_admin_content_section();
5375
+
5376
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
5377
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
5378
+
5379
+ // Verify matching plugin details.
5380
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
5381
+ return;
5382
+ }
5383
+
5384
+ $user = new FS_User();
5385
+ $user->id = fs_request_get( 'user_id' );
5386
+ $user->public_key = fs_request_get( 'user_public_key' );
5387
+ $user->secret_key = fs_request_get( 'user_secret_key' );
5388
+ $user->email = fs_request_get( 'user_email' );
5389
+ $user->first = fs_request_get( 'user_first' );
5390
+ $user->last = fs_request_get( 'user_last' );
5391
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
5392
+
5393
+ $site = new FS_Site();
5394
+ $site->id = fs_request_get( 'install_id' );
5395
+ $site->public_key = fs_request_get( 'install_public_key' );
5396
+ $site->secret_key = fs_request_get( 'install_secret_key' );
5397
+ $site->plan->id = fs_request_get( 'plan_id' );
5398
+ $site->plan->title = fs_request_get( 'plan_title' );
5399
+ $site->plan->name = fs_request_get( 'plan_name' );
5400
+
5401
+ $plans = array();
5402
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
5403
+ foreach ( $plans_data as $p ) {
5404
+ $plans[] = new FS_Plugin_Plan( $p );
5405
+ }
5406
+
5407
+ $this->_set_account( $user, $site, $plans );
5408
+
5409
+ // Reload the page with the keys.
5410
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
5411
+ exit();
5412
+ }
5413
+ }
5414
+ }
5415
+
5416
+ /**
5417
+ * @author Vova Feldman (@svovaf)
5418
+ * @since 1.0.7
5419
+ *
5420
+ * @param string $email
5421
+ *
5422
+ * @return FS_User|bool
5423
+ */
5424
+ static function _get_user_by_email( $email ) {
5425
+ self::$_static_logger->entrance();
5426
+
5427
+ $email = trim( strtolower( $email ) );
5428
+ $users = self::get_all_users();
5429
+ if ( is_array( $users ) ) {
5430
+ foreach ( $users as $u ) {
5431
+ if ( $email === trim( strtolower( $u->email ) ) ) {
5432
+ return $u;
5433
+ }
5434
+ }
5435
+ }
5436
+
5437
+ return false;
5438
+ }
5439
+
5440
+ #region Account (Loading, Updates & Activation) ------------------------------------------------------------------
5441
+
5442
+ /***
5443
+ * Load account information (user + site).
5444
+ *
5445
+ * @author Vova Feldman (@svovaf)
5446
+ * @since 1.0.1
5447
+ */
5448
+ private function _load_account() {
5449
+ $this->_logger->entrance();
5450
+
5451
+ $this->do_action( 'before_account_load' );
5452
+
5453
+ $sites = self::get_all_sites();
5454
+ $users = self::get_all_users();
5455
+ $plans = self::get_all_plans();
5456
+ $licenses = self::get_all_licenses();
5457
+
5458
+ if ( $this->_logger->is_on() && is_admin() ) {
5459
+ $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
5460
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
5461
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
5462
+ $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
5463
+ }
5464
+
5465
+ $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
5466
+
5467
+ if ( is_object( $site ) &&
5468
+ is_numeric( $site->id ) &&
5469
+ is_numeric( $site->user_id ) &&
5470
+ is_object( $site->plan )
5471
+ ) {
5472
+ // Load site.
5473
+ $this->_site = clone $site;
5474
+ $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
5475
+
5476
+ // Load relevant user.
5477
+ $this->_user = clone $users[ $this->_site->user_id ];
5478
+
5479
+ // Load plans.
5480
+ $this->_plans = $plans[ $this->_slug ];
5481
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
5482
+ $this->_sync_plans( true );
5483
+ } else {
5484
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5485
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
5486
+ $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
5487
+ } else {
5488
+ unset( $this->_plans[ $i ] );
5489
+ }
5490
+ }
5491
+ }
5492
+
5493
+ // Load licenses.
5494
+ $this->_licenses = array();
5495
+ if ( is_array( $licenses ) &&
5496
+ isset( $licenses[ $this->_slug ] ) &&
5497
+ isset( $licenses[ $this->_slug ][ $this->_user->id ] )
5498
+ ) {
5499
+ $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
5500
+ }
5501
+
5502
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
5503
+
5504
+ if ( $this->_site->version != $this->get_plugin_version() ) {
5505
+ // If stored install version is different than current installed plugin version,
5506
+ // then update plugin version event.
5507
+ $this->update_plugin_version_event();
5508
+ }
5509
+ }
5510
+
5511
+ $this->_register_account_hooks();
5512
+ }
5513
+
5514
+ /**
5515
+ * @author Vova Feldman (@svovaf)
5516
+ * @since 1.0.1
5517
+ *
5518
+ * @param FS_User $user
5519
+ * @param FS_Site $site
5520
+ * @param bool|array $plans
5521
+ */
5522
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
5523
+ $site->slug = $this->_slug;
5524
+ $site->user_id = $user->id;
5525
+
5526
+ $this->_site = $site;
5527
+ $this->_user = $user;
5528
+ if ( false !== $plans ) {
5529
+ $this->_plans = $plans;
5530
+ }
5531
+
5532
+ $this->send_install_update();
5533
+
5534
+ $this->_store_account();
5535
+
5536
+ }
5537
+
5538
+ /**
5539
+ * @author Vova Feldman (@svovaf)
5540
+ * @since 1.1.7.4
5541
+ *
5542
+ * @param array $override_with
5543
+ *
5544
+ * @return array
5545
+ */
5546
+ function get_opt_in_params( $override_with = array() ) {
5547
+ $this->_logger->entrance();
5548
+
5549
+ $current_user = self::_get_current_wp_user();
5550
+
5551
+ $params = array(
5552
+ 'user_firstname' => $current_user->user_firstname,
5553
+ 'user_lastname' => $current_user->user_lastname,
5554
+ 'user_nickname' => $current_user->user_nicename,
5555
+ 'user_email' => $current_user->user_email,
5556
+ 'user_ip' => WP_FS__REMOTE_ADDR,
5557
+ 'plugin_slug' => $this->_slug,
5558
+ 'plugin_id' => $this->get_id(),
5559
+ 'plugin_public_key' => $this->get_public_key(),
5560
+ 'plugin_version' => $this->get_plugin_version(),
5561
+ 'return_url' => wp_nonce_url( $this->_get_admin_page_url(
5562
+ '',
5563
+ array( 'fs_action' => $this->_slug . '_activate_new' )
5564
+ ), $this->_slug . '_activate_new' ),
5565
+ 'account_url' => wp_nonce_url( $this->_get_admin_page_url(
5566
+ 'account',
5567
+ array( 'fs_action' => 'sync_user' )
5568
+ ), 'sync_user' ),
5569
+ 'site_uid' => $this->get_anonymous_id(),
5570
+ 'site_url' => get_site_url(),
5571
+ 'site_name' => get_bloginfo( 'name' ),
5572
+ 'platform_version' => get_bloginfo( 'version' ),
5573
+ 'php_version' => phpversion(),
5574
+ 'language' => get_bloginfo( 'language' ),
5575
+ 'charset' => get_bloginfo( 'charset' ),
5576
+ );
5577
+
5578
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
5579
+ // Even though rand() is known for its security issues,
5580
+ // the timestamp adds another layer of protection.
5581
+ // It would be very hard for an attacker to get the secret key form here.
5582
+ // Plus, this should never run in production since the secret should never
5583
+ // be included in the production version.
5584
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
5585
+ $params['salt'] = md5( uniqid( rand() ) );
5586
+ $params['secure'] = md5(
5587
+ $params['ts'] .
5588
+ $params['salt'] .
5589
+ $this->get_secret_key()
5590
+ );
5591
+ }
5592
+
5593
+ return array_merge( $params, $override_with );
5594
+ }
5595
+
5596
+ /**
5597
+ * @author Vova Feldman (@svovaf)
5598
+ * @since 1.1.7.4
5599
+ *
5600
+ * @param string|bool $email
5601
+ * @param string|bool $first
5602
+ * @param string|bool $last
5603
+ *
5604
+ * @return bool Is successful opt-in (or set to pending).
5605
+ */
5606
+ function opt_in( $email = false, $first = false, $last = false ) {
5607
+ $this->_logger->entrance();
5608
+
5609
+ if ( false === $email ) {
5610
+ $current_user = self::_get_current_wp_user();
5611
+ $email = $current_user->user_email;
5612
+ }
5613
+
5614
+ $fs_user = Freemius::_get_user_by_email( $email );
5615
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
5616
+ $this->install_with_current_user( false );
5617
+
5618
+ return true;
5619
+ }
5620
+
5621
+ $user_info = array();
5622
+ if ( ! empty( $email ) ) {
5623
+ $user_info['user_email'] = $email;
5624
+ }
5625
+ if ( ! empty( $first ) ) {
5626
+ $user_info['user_firstname'] = $first;
5627
+ }
5628
+ if ( ! empty( $last ) ) {
5629
+ $user_info['user_lastname'] = $last;
5630
+ }
5631
+
5632
+ $params = $this->get_opt_in_params( $user_info );
5633
+ $params['format'] = 'json';
5634
+
5635
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
5636
+ if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
5637
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
5638
+ }
5639
+
5640
+ $response = wp_remote_post( $url, array(
5641
+ 'method' => 'POST',
5642
+ 'body' => $params,
5643
+ 'timeout' => 15,
5644
+ ) );
5645
+
5646
+ if ( $response instanceof WP_Error ) {
5647
+ if ( 'https://' === substr( $url, 0, 8 ) &&
5648
+ isset( $response->errors ) &&
5649
+ isset( $response->errors['http_request_failed'] ) &&
5650
+ false !== strpos( $response->errors['http_request_failed'][0], 'sslv3 alert handshake' )
5651
+ ) {
5652
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
5653
+ $url = 'http://' . substr( $url, 8 );
5654
+
5655
+ $response = wp_remote_post( $url, array(
5656
+ 'method' => 'POST',
5657
+ 'body' => $params,
5658
+ 'timeout' => 15,
5659
+ ) );
5660
+ }
5661
+
5662
+ if ( $response instanceof WP_Error ) {
5663
+ return false;
5664
+ }
5665
+ }
5666
+
5667
+ if ( is_wp_error( $response ) ) {
5668
+ return false;
5669
+ }
5670
+
5671
+ $decoded = @json_decode( $response['body'] );
5672
+
5673
+ if ( empty( $decoded ) ) {
5674
+ return false;
5675
+ }
5676
+
5677
+ if ( isset( $decoded->error ) ) {
5678
+ return false;
5679
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
5680
+ // Pending activation, add message.
5681
+ $this->set_pending_confirmation( false, false );
5682
+
5683
+ return true;
5684
+ } else if ( isset( $decoded->install_secret_key ) ) {
5685
+ $this->install_with_new_user(
5686
+ $decoded->user_id,
5687
+ $decoded->user_public_key,
5688
+ $decoded->user_secret_key,
5689
+ $decoded->install_id,
5690
+ $decoded->install_public_key,
5691
+ $decoded->install_secret_key,
5692
+ false
5693
+ );
5694
+
5695
+ return true;
5696
+ }
5697
+
5698
+ return false;
5699
+ }
5700
+
5701
+ /**
5702
+ * Set user and site identities.
5703
+ *
5704
+ * @author Vova Feldman (@svovaf)
5705
+ * @since 1.0.9
5706
+ *
5707
+ * @param FS_User $user
5708
+ * @param FS_Site $site
5709
+ * @param bool $redirect
5710
+ *
5711
+ * @return bool False if account already set.
5712
+ */
5713
+ function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
5714
+ $this->_user = $user;
5715
+ $this->_site = $site;
5716
+
5717
+ $this->_sync_plans();
5718
+
5719
+ $this->_enrich_site_plan( false );
5720
+
5721
+ $this->_set_account( $user, $site );
5722
+
5723
+ if ( $this->is_trial() ) {
5724
+ // Store trial plan information.
5725
+ $this->_enrich_site_trial_plan( true );
5726
+ }
5727
+
5728
+ // If Freemius was OFF before, turn it on.
5729
+ $this->turn_on();
5730
+
5731
+ $this->do_action( 'after_account_connection', $user, $site );
5732
+
5733
+ if ( is_numeric( $site->license_id ) ) {
5734
+ $this->_license = $this->_get_license_by_id( $site->license_id );
5735
+ }
5736
+
5737
+ if ( $this->is_pending_activation() ) {
5738
+ // Remove pending activation sticky notice (if still exist).
5739
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
5740
+
5741
+ // Remove plugin from pending activation mode.
5742
+ unset( $this->_storage->is_pending_activation );
5743
+
5744
+ if ( ! $this->is_paying() ) {
5745
+ $this->_admin_notices->add_sticky(
5746
+ sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
5747
+ 'activation_complete'
5748
+ );
5749
+ }
5750
+ }
5751
+
5752
+ if ( $this->is_paying() && ! $this->is_premium() ) {
5753
+ $this->_admin_notices->add_sticky(
5754
+ sprintf(
5755
+ __fs( 'activation-with-plan-x-message', $this->_slug ),
5756
+ $this->_site->plan->title
5757
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
5758
+ __fs( 'download-latest-x-version', $this->_slug ),
5759
+ $this->_site->plan->title
5760
+ ) ),
5761
+ 'plan_upgraded',
5762
+ __fs( 'yee-haw', $this->_slug ) . '!'
5763
+ );
5764
+ }
5765
+
5766
+ $plugin_id = fs_request_get( 'plugin_id', false );
5767
+
5768
+ // Store activation time ONLY for plugins (not add-ons).
5769
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
5770
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
5771
+ }
5772
+
5773
+ if ( is_numeric( $plugin_id ) ) {
5774
+ if ( $plugin_id != $this->_plugin->id ) {
5775
+ // Add-on was installed - sync license right after install.
5776
+ if ( $redirect && fs_redirect( fs_nonce_url( $this->_get_admin_page_url(
5777
+ 'account',
5778
+ array(
5779
+ 'fs_action' => $this->_slug . '_sync_license',
5780
+ 'plugin_id' => $plugin_id
5781
+ )
5782
+ ), $this->_slug . '_sync_license' ) )
5783
+ ) {
5784
+ exit();
5785
+ }
5786
+
5787
+ }
5788
+ } else {
5789
+ // Reload the page with the keys.
5790
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_connect_url' ) ) ) {
5791
+ exit();
5792
+ }
5793
+ }
5794
+ }
5795
+
5796
+ /**
5797
+ * Install plugin with new user information after approval.
5798
+ *
5799
+ * @author Vova Feldman (@svovaf)
5800
+ * @since 1.0.7
5801
+ */
5802
+ function _install_with_new_user() {
5803
+ $this->_logger->entrance();
5804
+
5805
+ if ( $this->is_registered() ) {
5806
+ return;
5807
+ }
5808
+
5809
+ if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
5810
+ // check_admin_referer( $this->_slug . '_activate_new' );
5811
+
5812
+ $this->_admin_notices->remove_sticky( 'connect_account' );
5813
+
5814
+ if ( fs_request_has( 'user_secret_key' ) ) {
5815
+ $this->install_with_new_user(
5816
+ fs_request_get( 'user_id' ),
5817
+ fs_request_get( 'user_public_key' ),
5818
+ fs_request_get( 'user_secret_key' ),
5819
+ fs_request_get( 'install_id' ),
5820
+ fs_request_get( 'install_public_key' ),
5821
+ fs_request_get( 'install_secret_key' )
5822
+ );
5823
+ } else if ( fs_request_has( 'pending_activation' ) ) {
5824
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
5825
+ }
5826
+ }
5827
+ }
5828
+
5829
+ /**
5830
+ * Install plugin with new user.
5831
+ *
5832
+ * @author Vova Feldman (@svovaf)
5833
+ * @since 1.1.7.4
5834
+ *
5835
+ * @param number $user_id
5836
+ * @param string $user_public_key
5837
+ * @param string $user_secret_key
5838
+ * @param number $install_id
5839
+ * @param string $install_public_key
5840
+ * @param string $install_secret_key
5841
+ * @param bool $redirect
5842
+ */
5843
+ private function install_with_new_user(
5844
+ $user_id,
5845
+ $user_public_key,
5846
+ $user_secret_key,
5847
+ $install_id,
5848
+ $install_public_key,
5849
+ $install_secret_key,
5850
+ $redirect = true
5851
+ ) {
5852
+ $user = new FS_User();
5853
+ $user->id = $user_id;
5854
+ $user->public_key = $user_public_key;
5855
+ $user->secret_key = $user_secret_key;
5856
+
5857
+ $this->_user = $user;
5858
+ $user_result = $this->get_api_user_scope()->get();
5859
+ $user = new FS_User( $user_result );
5860
+ $this->_user = $user;
5861
+
5862
+ $site = new FS_Site();
5863
+ $site->id = $install_id;
5864
+ $site->public_key = $install_public_key;
5865
+ $site->secret_key = $install_secret_key;
5866
+
5867
+ $this->_site = $site;
5868
+ $site_result = $this->get_api_site_scope()->get();
5869
+ $site = new FS_Site( $site_result );
5870
+ $this->_site = $site;
5871
+
5872
+ $this->setup_account( $this->_user, $this->_site, $redirect );
5873
+ }
5874
+
5875
+ /**
5876
+ * @author Vova Feldman (@svovaf)
5877
+ * @since 1.1.7.4
5878
+ *
5879
+ * @param bool $email
5880
+ * @param bool $redirect
5881
+ */
5882
+ private function set_pending_confirmation( $email = false, $redirect = true ) {
5883
+ // Install must be activated via email since
5884
+ // user with the same email already exist.
5885
+ $this->_storage->is_pending_activation = true;
5886
+ $this->_add_pending_activation_notice( $email );
5887
+
5888
+ // Reload the page with with pending activation message.
5889
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_pending_connect_url' ) ) ) {
5890
+ exit();
5891
+ }
5892
+ }
5893
+
5894
+ /**
5895
+ * Install plugin with current logged WP user info.
5896
+ *
5897
+ * @author Vova Feldman (@svovaf)
5898
+ * @since 1.0.7
5899
+ */
5900
+ function _install_with_current_user() {
5901
+ $this->_logger->entrance();
5902
+
5903
+ if ( $this->is_registered() ) {
5904
+ return;
5905
+ }
5906
+
5907
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
5908
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
5909
+
5910
+ $this->install_with_current_user();
5911
+ }
5912
+ }
5913
+
5914
+
5915
+ /**
5916
+ * @author Vova Feldman (@svovaf)
5917
+ * @since 1.1.7.4
5918
+ *
5919
+ * @param bool $redirect
5920
+ */
5921
+ private function install_with_current_user( $redirect = true ) {
5922
+ $this->_admin_notices->remove_sticky( 'connect_account' );
5923
+
5924
+ // Get current logged WP user.
5925
+ $current_user = self::_get_current_wp_user();
5926
+
5927
+ // Find the relevant FS user by the email.
5928
+ $user = self::_get_user_by_email( $current_user->user_email );
5929
+
5930
+ // We have to set the user before getting user scope API handler.
5931
+ $this->_user = $user;
5932
+
5933
+ // Install the plugin.
5934
+ $install = $this->get_api_user_scope()->call(
5935
+ "/plugins/{$this->get_id()}/installs.json",
5936
+ 'post',
5937
+ $this->get_install_data_for_api( array(
5938
+ 'uid' => $this->get_anonymous_id(),
5939
+ ), false, false )
5940
+ );
5941
+
5942
+ if ( isset( $install->error ) ) {
5943
+ $this->_admin_notices->add(
5944
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
5945
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
5946
+ __fs( 'oops', $this->_slug ) . '...',
5947
+ 'error'
5948
+ );
5949
+
5950
+ return;
5951
+ }
5952
+
5953
+ $site = new FS_Site( $install );
5954
+ $this->_site = $site;
5955
+ // $this->_enrich_site_plan( false );
5956
+
5957
+ // $this->_set_account( $user, $site );
5958
+ // $this->_sync_plans();
5959
+
5960
+ $this->setup_account( $this->_user, $this->_site, $redirect );
5961
+ }
5962
+
5963
+ /**
5964
+ * Tries to activate add-on account based on parent plugin info.
5965
+ *
5966
+ * @author Vova Feldman (@svovaf)
5967
+ * @since 1.0.6
5968
+ *
5969
+ * @param Freemius $parent_fs
5970
+ */
5971
+ private function _activate_addon_account( Freemius $parent_fs ) {
5972
+ if ( $this->is_registered() ) {
5973
+ // Already activated.
5974
+ return;
5975
+ }
5976
+
5977
+ // Activate add-on with parent plugin credentials.
5978
+ $addon_install = $parent_fs->get_api_site_scope()->call(
5979
+ "/addons/{$this->_plugin->id}/installs.json",
5980
+ 'post',
5981
+ $this->get_install_data_for_api( array(
5982
+ 'uid' => $this->get_anonymous_id(),
5983
+ ), false, false )
5984
+ );
5985
+
5986
+ if ( isset( $addon_install->error ) ) {
5987
+ $this->_admin_notices->add(
5988
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
5989
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
5990
+ __fs( 'oops', $this->_slug ) . '...',
5991
+ 'error'
5992
+ );
5993
+
5994
+ return;
5995
+ }
5996
+
5997
+ // First of all, set site info - otherwise we won't
5998
+ // be able to invoke API calls.
5999
+ $this->_site = new FS_Site( $addon_install );
6000
+
6001
+ // Sync add-on plans.
6002
+ $this->_sync_plans();
6003
+
6004
+ // Get site's current plan.
6005
+ $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
6006
+
6007
+ // Get user information based on parent's plugin.
6008
+ $user = $parent_fs->get_user();
6009
+
6010
+ $this->_set_account( $user, $this->_site );
6011
+
6012
+ // Sync licenses.
6013
+ $this->_sync_licenses();
6014
+
6015
+ // Try to activate premium license.
6016
+ $this->_activate_license( true );
6017
+ }
6018
+
6019
+ #endregion ------------------------------------------------------------------
6020
+
6021
+ #region Admin Menu Items ------------------------------------------------------------------
6022
+
6023
+ private $_menu_items = array();
6024
+
6025
+ /**
6026
+ * @author Vova Feldman (@svovaf)
6027
+ * @since 1.0.7
6028
+ *
6029
+ * @return string
6030
+ */
6031
+ function get_menu_slug() {
6032
+ return $this->_menu->get_slug();
6033
+ }
6034
+
6035
+ /**
6036
+ * @author Vova Feldman (@svovaf)
6037
+ * @since 1.0.9
6038
+ */
6039
+ function _prepare_admin_menu() {
6040
+ // if ( ! $this->is_on() ) {
6041
+ // return;
6042
+ // }
6043
+
6044
+ if ( ! $this->has_api_connectivity() && ! $this->enable_anonymous() ) {
6045
+ $this->_menu->remove_menu_item();
6046
+ } else {
6047
+ $this->add_submenu_items();
6048
+ $this->add_menu_action();
6049
+ }
6050
+ }
6051
+
6052
+ /**
6053
+ * Admin dashboard menu items modifications.
6054
+ *
6055
+ * NOTE: admin_menu action executed before admin_init.
6056
+ *
6057
+ * @author Vova Feldman (@svovaf)
6058
+ * @since 1.0.7
6059
+ *
6060
+ */
6061
+ private function add_menu_action() {
6062
+ if ( $this->is_activation_mode() ) {
6063
+ $this->override_plugin_menu_with_activation();
6064
+ } else {
6065
+ // If not registered try to install user.
6066
+ if ( ! $this->is_registered() &&
6067
+ fs_request_is_action( $this->_slug . '_activate_new' )
6068
+ ) {
6069
+ $this->_install_with_new_user();
6070
+ }
6071
+ }
6072
+ }
6073
+
6074
+ /**
6075
+ * @author Vova Feldman (@svovaf)
6076
+ * @since 1.0.1
6077
+ *
6078
+ * @return string
6079
+ */
6080
+ function _redirect_on_clicked_menu_link() {
6081
+ $this->_logger->entrance();
6082
+
6083
+ $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
6084
+
6085
+ $this->_logger->log( 'page = ' . $page );
6086
+
6087
+ foreach ( $this->_menu_items as $priority => $items ) {
6088
+ foreach ( $items as $item ) {
6089
+ if ( isset( $item['url'] ) ) {
6090
+ if ( $page === strtolower( $item['menu_slug'] ) ) {
6091
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
6092
+
6093
+ fs_redirect( $item['url'] );
6094
+ }
6095
+ }
6096
+ }
6097
+ }
6098
+ }
6099
+
6100
+ /**
6101
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
6102
+ *
6103
+ * @author Vova Feldman (@svovaf)
6104
+ * @since 1.0.1
6105
+ */
6106
+ private function override_plugin_menu_with_activation() {
6107
+ $this->_logger->entrance();
6108
+
6109
+ $hook = false;
6110
+
6111
+ if ( $this->_menu->is_top_level() ) {
6112
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
6113
+
6114
+ if ( false === $hook ) {
6115
+ // Create new menu item just for the opt-in.
6116
+ $hook = add_menu_page(
6117
+ $this->get_plugin_name(),
6118
+ $this->get_plugin_name(),
6119
+ 'manage_options',
6120
+ $this->_menu->get_slug(),
6121
+ array( &$this, '_connect_page_render' )
6122
+ );
6123
+ }
6124
+ } else {
6125
+ $menus = array( $this->_menu->get_parent_slug() );
6126
+
6127
+ if ( $this->_menu->is_override_exact() ) {
6128
+ // Make sure the current page is matching the activation page.
6129
+ $activation_url = strtolower( $this->get_activation_url() );
6130
+ $request_url = strtolower( $_SERVER['REQUEST_URI'] );
6131
+
6132
+ if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
6133
+ // Different path - DO NOT OVERRIDE PAGE.
6134
+ return;
6135
+ }
6136
+
6137
+ $activation_url_params = array();
6138
+ parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
6139
+
6140
+ $request_url_params = array();
6141
+ parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
6142
+
6143
+
6144
+ foreach ( $activation_url_params as $key => $val ) {
6145
+ if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
6146
+ // Not matching query string - DO NOT OVERRIDE PAGE.
6147
+ return;
6148
+ }
6149
+ }
6150
+ }
6151
+
6152
+ foreach ( $menus as $parent_slug ) {
6153
+ $hook = $this->_menu->override_submenu_action(
6154
+ $parent_slug,
6155
+ $this->_menu->get_raw_slug(),
6156
+ array( &$this, '_connect_page_render' )
6157
+ );
6158
+
6159
+ if ( false !== $hook ) {
6160
+ // Found plugin's submenu item.
6161
+ break;
6162
+ }
6163
+ }
6164
+ }
6165
+
6166
+ if ( $this->_menu->is_activation_page() ) {
6167
+ // Clean admin page from distracting content.
6168
+ self::_clean_admin_content_section();
6169
+ }
6170
+
6171
+ if ( false !== $hook ) {
6172
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
6173
+ add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
6174
+ } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6175
+ add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
6176
+ }
6177
+ }
6178
+ }
6179
+
6180
+ /**
6181
+ * @author Vova Feldman (@svovaf)
6182
+ * @since 1.0.0
6183
+ *
6184
+ * @return string
6185
+ */
6186
+ private function get_top_level_menu_slug() {
6187
+ return ( $this->is_addon() ?
6188
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
6189
+ $this->_menu->get_top_level_menu_slug() );
6190
+ }
6191
+
6192
+ /**
6193
+ * Add default Freemius menu items.
6194
+ *
6195
+ * @author Vova Feldman (@svovaf)
6196
+ * @since 1.0.0
6197
+ */
6198
+ private function add_submenu_items() {
6199
+ $this->_logger->entrance();
6200
+
6201
+ $this->do_action( 'before_admin_menu_init' );
6202
+
6203
+ if ( ! $this->is_addon() ) {
6204
+ if ( ! $this->is_activation_mode() ) {
6205
+ if ( $this->is_registered() ) {
6206
+ // Add user account page.
6207
+ $this->add_submenu_item(
6208
+ __fs( 'account', $this->_slug ),
6209
+ array( &$this, '_account_page_render' ),
6210
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
6211
+ 'manage_options',
6212
+ 'account',
6213
+ array( &$this, '_account_page_load' ),
6214
+ WP_FS__DEFAULT_PRIORITY,
6215
+ $this->_menu->is_submenu_item_visible( 'account' )
6216
+ );
6217
+ }
6218
+
6219
+ // Add contact page.
6220
+ $this->add_submenu_item(
6221
+ __fs( 'contact-us', $this->_slug ),
6222
+ array( &$this, '_contact_page_render' ),
6223
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
6224
+ 'manage_options',
6225
+ 'contact',
6226
+ 'Freemius::_clean_admin_content_section',
6227
+ WP_FS__DEFAULT_PRIORITY,
6228
+ $this->_menu->is_submenu_item_visible( 'contact' )
6229
+ );
6230
+
6231
+ if ( $this->has_addons() ) {
6232
+ $this->add_submenu_item(
6233
+ __fs( 'add-ons', $this->_slug ),
6234
+ array( &$this, '_addons_page_render' ),
6235
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
6236
+ 'manage_options',
6237
+ 'addons',
6238
+ array( &$this, '_addons_page_load' ),
6239
+ WP_FS__LOWEST_PRIORITY - 1,
6240
+ $this->_menu->is_submenu_item_visible( 'addons' )
6241
+ );
6242
+ }
6243
+
6244
+ $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
6245
+ // If user don't have paid plans, add pricing page
6246
+ // to support add-ons checkout but don't add the submenu item.
6247
+ // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
6248
+
6249
+ // Add upgrade/pricing page.
6250
+ $this->add_submenu_item(
6251
+ ( $this->is_paying() ? __fs( 'pricing', $this->_slug ) : __fs( 'upgrade', $this->_slug ) . '&nbsp;&nbsp;&#x27a4;' ),
6252
+ array( &$this, '_pricing_page_render' ),
6253
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
6254
+ 'manage_options',
6255
+ 'pricing',
6256
+ 'Freemius::_clean_admin_content_section',
6257
+ WP_FS__LOWEST_PRIORITY,
6258
+ $show_pricing
6259
+ );
6260
+ }
6261
+ }
6262
+
6263
+
6264
+ if ( 0 < count( $this->_menu_items ) ) {
6265
+ if ( ! $this->_menu->is_top_level() ) {
6266
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
6267
+
6268
+ // Append submenu items right after the plugin's submenu item.
6269
+ $this->order_sub_submenu_items();
6270
+ } else {
6271
+ // Append submenu items.
6272
+ $this->embed_submenu_items();
6273
+ }
6274
+ }
6275
+ }
6276
+
6277
+ /**
6278
+ * Moved the actual submenu item additions to a separated function,
6279
+ * in order to support sub-submenu items when the plugin's settings
6280
+ * only have a submenu and not top-level menu item.
6281
+ *
6282
+ * @author Vova Feldman (@svovaf)
6283
+ * @since 1.1.4
6284
+ */
6285
+ private function embed_submenu_items() {
6286
+ $item_template = $this->_menu->is_top_level() ?
6287
+ '<span class="fs-submenu-item">%s</span>' :
6288
+ '<span class="fs-submenu-item fs-sub">%s</span>';
6289
+
6290
+ ksort( $this->_menu_items );
6291
+
6292
+ foreach ( $this->_menu_items as $priority => $items ) {
6293
+ foreach ( $items as $item ) {
6294
+ if ( ! isset( $item['url'] ) ) {
6295
+ $hook = add_submenu_page(
6296
+ $item['show_submenu'] ?
6297
+ $this->get_top_level_menu_slug() :
6298
+ null,
6299
+ $item['page_title'],
6300
+ sprintf( $item_template, $item['menu_title'] ),
6301
+ $item['capability'],
6302
+ $item['menu_slug'],
6303
+ $item['render_function']
6304
+ );
6305
+
6306
+ if ( false !== $item['before_render_function'] ) {
6307
+ add_action( "load-$hook", $item['before_render_function'] );
6308
+ }
6309
+ } else {
6310
+ add_submenu_page(
6311
+ $this->get_top_level_menu_slug(),
6312
+ $item['page_title'],
6313
+ sprintf( $item_template, $item['menu_title'] ),
6314
+ $item['capability'],
6315
+ $item['menu_slug'],
6316
+ array( $this, '' )
6317
+ );
6318
+ }
6319
+ }
6320
+ }
6321
+ }
6322
+
6323
+ /**
6324
+ * Re-order the submenu items so all Freemius added new submenu items
6325
+ * are added right after the plugin's settings submenu item.
6326
+ *
6327
+ * @author Vova Feldman (@svovaf)
6328
+ * @since 1.1.4
6329
+ */
6330
+ private function order_sub_submenu_items() {
6331
+ global $submenu;
6332
+
6333
+ $top_level_menu = &$submenu[ $this->_menu->get_top_level_menu_slug() ];
6334
+
6335
+ $all_submenu_items_after = array();
6336
+
6337
+ $found_submenu_item = false;
6338
+
6339
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
6340
+ if ( $found_submenu_item ) {
6341
+ // Remove all submenu items after the plugin's submenu item.
6342
+ $all_submenu_items_after[] = $meta;
6343
+ unset( $top_level_menu[ $submenu_id ] );
6344
+ }
6345
+
6346
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
6347
+ // Found the submenu item, put all below.
6348
+ $found_submenu_item = true;
6349
+ continue;
6350
+ }
6351
+ }
6352
+
6353
+ // Embed all plugin's new submenu items.
6354
+ $this->embed_submenu_items();
6355
+
6356
+ // Start with specially high number to make sure it's appended.
6357
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
6358
+ foreach ( $all_submenu_items_after as $meta ) {
6359
+ $top_level_menu[ $i ] = $meta;
6360
+ $i ++;
6361
+ }
6362
+
6363
+ // Sort submenu items.
6364
+ ksort( $top_level_menu );
6365
+ }
6366
+
6367
+ /**
6368
+ * Displays the Support Forum link when enabled.
6369
+ *
6370
+ * Can be filtered like so:
6371
+ *
6372
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
6373
+ * if ( 'support' === $menu_id ) {
6374
+ * return _fs->is_registered();
6375
+ * }
6376
+ * return $is_visible;
6377
+ * }
6378
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
6379
+ *
6380
+ */
6381
+ function _add_default_submenu_items() {
6382
+ if ( ! $this->is_on() ) {
6383
+ return;
6384
+ }
6385
+
6386
+ if ( ! $this->is_activation_mode() ) {
6387
+ if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
6388
+ $this->add_submenu_link_item(
6389
+ $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
6390
+ $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
6391
+ 'wp-support-forum',
6392
+ 'read',
6393
+ 50
6394
+ );
6395
+ }
6396
+ }
6397
+ }
6398
+
6399
+ /**
6400
+ * @author Vova Feldman (@svovaf)
6401
+ * @since 1.0.1
6402
+ *
6403
+ * @param string $menu_title
6404
+ * @param callable $render_function
6405
+ * @param bool|string $page_title
6406
+ * @param string $capability
6407
+ * @param bool|string $menu_slug
6408
+ * @param bool|callable $before_render_function
6409
+ * @param int $priority
6410
+ * @param bool $show_submenu
6411
+ */
6412
+ function add_submenu_item(
6413
+ $menu_title,
6414
+ $render_function,
6415
+ $page_title = false,
6416
+ $capability = 'manage_options',
6417
+ $menu_slug = false,
6418
+ $before_render_function = false,
6419
+ $priority = WP_FS__DEFAULT_PRIORITY,
6420
+ $show_submenu = true
6421
+ ) {
6422
+ $this->_logger->entrance( 'Title = ' . $menu_title );
6423
+
6424
+ if ( $this->is_addon() ) {
6425
+ $parent_fs = $this->get_parent_instance();
6426
+
6427
+ if ( is_object( $parent_fs ) ) {
6428
+ $parent_fs->add_submenu_item(
6429
+ $menu_title,
6430
+ $render_function,
6431
+ $page_title,
6432
+ $capability,
6433
+ $menu_slug,
6434
+ $before_render_function,
6435
+ $priority,
6436
+ $show_submenu
6437
+ );
6438
+
6439
+ return;
6440
+ }
6441
+ }
6442
+
6443
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6444
+ $this->_menu_items[ $priority ] = array();
6445
+ }
6446
+
6447
+ $this->_menu_items[ $priority ][] = array(
6448
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
6449
+ 'menu_title' => $menu_title,
6450
+ 'capability' => $capability,
6451
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6452
+ 'render_function' => $render_function,
6453
+ 'before_render_function' => $before_render_function,
6454
+ 'show_submenu' => $show_submenu,
6455
+ );
6456
+ }
6457
+
6458
+ /**
6459
+ * @author Vova Feldman (@svovaf)
6460
+ * @since 1.0.1
6461
+ *
6462
+ * @param string $menu_title
6463
+ * @param string $url
6464
+ * @param bool $menu_slug
6465
+ * @param string $capability
6466
+ * @param int $priority
6467
+ *
6468
+ */
6469
+ function add_submenu_link_item(
6470
+ $menu_title,
6471
+ $url,
6472
+ $menu_slug = false,
6473
+ $capability = 'read',
6474
+ $priority = WP_FS__DEFAULT_PRIORITY
6475
+ ) {
6476
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
6477
+
6478
+ if ( $this->is_addon() ) {
6479
+ $parent_fs = $this->get_parent_instance();
6480
+
6481
+ if ( is_object( $parent_fs ) ) {
6482
+ $parent_fs->add_submenu_link_item(
6483
+ $menu_title,
6484
+ $url,
6485
+ $menu_slug,
6486
+ $capability,
6487
+ $priority
6488
+ );
6489
+
6490
+ return;
6491
+ }
6492
+ }
6493
+
6494
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6495
+ $this->_menu_items[ $priority ] = array();
6496
+ }
6497
+
6498
+ $this->_menu_items[ $priority ][] = array(
6499
+ 'menu_title' => $menu_title,
6500
+ 'capability' => $capability,
6501
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6502
+ 'url' => $url,
6503
+ 'page_title' => $menu_title,
6504
+ 'render_function' => 'fs_dummy',
6505
+ 'before_render_function' => '',
6506
+ );
6507
+ }
6508
+
6509
+ #endregion ------------------------------------------------------------------
6510
+
6511
+ /* Actions / Hooks / Filters
6512
+ ------------------------------------------------------------------------------------------------------------------*/
6513
+ /**
6514
+ * @author Vova Feldman (@svovaf)
6515
+ * @since 1.1.7
6516
+ *
6517
+ * @param string $tag
6518
+ *
6519
+ * @return string
6520
+ */
6521
+ private function get_action_tag( $tag ) {
6522
+ return 'fs_' . $tag . '_' . $this->_slug;
6523
+ }
6524
+
6525
+ /**
6526
+ * Do action, specific for the current context plugin.
6527
+ *
6528
+ * @author Vova Feldman (@svovaf)
6529
+ * @since 1.0.1
6530
+ *
6531
+ * @param string $tag The name of the action to be executed.
6532
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
6533
+ * functions hooked to the action. Default empty.
6534
+ *
6535
+ * @uses do_action()
6536
+ */
6537
+ function do_action( $tag, $arg = '' ) {
6538
+ $this->_logger->entrance( $tag );
6539
+
6540
+ $args = func_get_args();
6541
+
6542
+ call_user_func_array( 'do_action', array_merge(
6543
+ array( $this->get_action_tag( $tag ) ),
6544
+ array_slice( $args, 1 ) )
6545
+ );
6546
+ }
6547
+
6548
+ /**
6549
+ * Add action, specific for the current context plugin.
6550
+ *
6551
+ * @author Vova Feldman (@svovaf)
6552
+ * @since 1.0.1
6553
+ *
6554
+ * @param string $tag
6555
+ * @param callable $function_to_add
6556
+ * @param int $priority
6557
+ * @param int $accepted_args
6558
+ *
6559
+ * @uses add_action()
6560
+ */
6561
+ function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6562
+ $this->_logger->entrance( $tag );
6563
+
6564
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6565
+ }
6566
+
6567
+ /**
6568
+ * Apply filter, specific for the current context plugin.
6569
+ *
6570
+ * @author Vova Feldman (@svovaf)
6571
+ * @since 1.0.9
6572
+ *
6573
+ * @param string $tag The name of the filter hook.
6574
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
6575
+ *
6576
+ * @return mixed The filtered value after all hooked functions are applied to it.
6577
+ *
6578
+ * @uses apply_filters()
6579
+ */
6580
+ function apply_filters( $tag, $value ) {
6581
+ $this->_logger->entrance( $tag );
6582
+
6583
+ $args = func_get_args();
6584
+ array_unshift( $args, $this->_slug );
6585
+
6586
+ return call_user_func_array( 'fs_apply_filter', $args );
6587
+ }
6588
+
6589
+ /**
6590
+ * Add filter, specific for the current context plugin.
6591
+ *
6592
+ * @author Vova Feldman (@svovaf)
6593
+ * @since 1.0.9
6594
+ *
6595
+ * @param string $tag
6596
+ * @param callable $function_to_add
6597
+ * @param int $priority
6598
+ * @param int $accepted_args
6599
+ *
6600
+ * @uses add_filter()
6601
+ */
6602
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6603
+ $this->_logger->entrance( $tag );
6604
+
6605
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6606
+ }
6607
+
6608
+ /**
6609
+ * Check if has filter.
6610
+ *
6611
+ * @author Vova Feldman (@svovaf)
6612
+ * @since 1.1.4
6613
+ *
6614
+ * @param string $tag
6615
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
6616
+ *
6617
+ * @return false|int
6618
+ *
6619
+ * @uses has_filter()
6620
+ */
6621
+ function has_filter( $tag, $function_to_check = false ) {
6622
+ $this->_logger->entrance( $tag );
6623
+
6624
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
6625
+ }
6626
+
6627
+ /**
6628
+ * Override default i18n text phrases.
6629
+ *
6630
+ * @author Vova Feldman (@svovaf)
6631
+ * @since 1.1.6
6632
+ *
6633
+ * @param string[] string $key_value
6634
+ *
6635
+ * @uses fs_override_i18n()
6636
+ */
6637
+ function override_i18n( $key_value ) {
6638
+ fs_override_i18n( $key_value, $this->_slug );
6639
+ }
6640
+
6641
+ /* Account Page
6642
+ ------------------------------------------------------------------------------------------------------------------*/
6643
+ /**
6644
+ * Update site information.
6645
+ *
6646
+ * @author Vova Feldman (@svovaf)
6647
+ * @since 1.0.1
6648
+ *
6649
+ * @param bool $store Flush to Database if true.
6650
+ */
6651
+ private function _store_site( $store = true ) {
6652
+ $this->_logger->entrance();
6653
+
6654
+ $encrypted_site = clone $this->_site;
6655
+ $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
6656
+
6657
+ $sites = self::get_all_sites();
6658
+ $sites[ $this->_slug ] = $encrypted_site;
6659
+ self::$_accounts->set_option( 'sites', $sites, $store );
6660
+ }
6661
+
6662
+ /**
6663
+ * Update plugin's plans information.
6664
+ *
6665
+ * @author Vova Feldman (@svovaf)
6666
+ * @since 1.0.2
6667
+ *
6668
+ * @param bool $store Flush to Database if true.
6669
+ */
6670
+ private function _store_plans( $store = true ) {
6671
+ $this->_logger->entrance();
6672
+
6673
+ $plans = self::get_all_plans();
6674
+
6675
+ // Copy plans.
6676
+ $encrypted_plans = array();
6677
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6678
+ $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
6679
+ }
6680
+
6681
+ $plans[ $this->_slug ] = $encrypted_plans;
6682
+ self::$_accounts->set_option( 'plans', $plans, $store );
6683
+ }
6684
+
6685
+ /**
6686
+ * Update user's plugin licenses.
6687
+ *
6688
+ * @author Vova Feldman (@svovaf)
6689
+ * @since 1.0.5
6690
+ *
6691
+ * @param bool $store
6692
+ * @param string|bool $plugin_slug
6693
+ * @param FS_Plugin_License[] $licenses
6694
+ */
6695
+ private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
6696
+ $this->_logger->entrance();
6697
+
6698
+ $all_licenses = self::get_all_licenses();
6699
+
6700
+ if ( ! is_string( $plugin_slug ) ) {
6701
+ $plugin_slug = $this->_slug;
6702
+ $licenses = $this->_licenses;
6703
+ }
6704
+
6705
+ if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
6706
+ $all_licenses[ $plugin_slug ] = array();
6707
+ }
6708
+
6709
+ $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
6710
+
6711
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
6712
+ }
6713
+
6714
+ /**
6715
+ * Update user information.
6716
+ *
6717
+ * @author Vova Feldman (@svovaf)
6718
+ * @since 1.0.1
6719
+ *
6720
+ * @param bool $store Flush to Database if true.
6721
+ */
6722
+ private function _store_user( $store = true ) {
6723
+ $this->_logger->entrance();
6724
+
6725
+ $users = self::get_all_users();
6726
+ $users[ $this->_user->id ] = $this->_user;
6727
+ self::$_accounts->set_option( 'users', $users, $store );
6728
+ }
6729
+
6730
+ /**
6731
+ * Update new updates information.
6732
+ *
6733
+ * @author Vova Feldman (@svovaf)
6734
+ * @since 1.0.4
6735
+ *
6736
+ * @param FS_Plugin_Tag|null $update
6737
+ * @param bool $store Flush to Database if true.
6738
+ * @param bool|number $plugin_id
6739
+ */
6740
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
6741
+ $this->_logger->entrance();
6742
+
6743
+ if ( $update instanceof FS_Plugin_Tag ) {
6744
+ $update->updated = time();
6745
+ }
6746
+
6747
+ if ( ! is_numeric( $plugin_id ) ) {
6748
+ $plugin_id = $this->_plugin->id;
6749
+ }
6750
+
6751
+ $updates = self::get_all_updates();
6752
+ $updates[ $plugin_id ] = $update;
6753
+ self::$_accounts->set_option( 'updates', $updates, $store );
6754
+ }
6755
+
6756
+ /**
6757
+ * Update new updates information.
6758
+ *
6759
+ * @author Vova Feldman (@svovaf)
6760
+ * @since 1.0.6
6761
+ *
6762
+ * @param FS_Plugin[] $plugin_addons
6763
+ * @param bool $store Flush to Database if true.
6764
+ */
6765
+ private function _store_addons( $plugin_addons, $store = true ) {
6766
+ $this->_logger->entrance();
6767
+
6768
+ $addons = self::get_all_addons();
6769
+ $addons[ $this->_plugin->id ] = $plugin_addons;
6770
+ self::$_accounts->set_option( 'addons', $addons, $store );
6771
+ }
6772
+
6773
+ /**
6774
+ * Delete plugin's associated add-ons.
6775
+ *
6776
+ * @author Vova Feldman (@svovaf)
6777
+ * @since 1.0.8
6778
+ *
6779
+ * @param bool $store
6780
+ *
6781
+ * @return bool
6782
+ */
6783
+ private function _delete_account_addons( $store = true ) {
6784
+ $all_addons = self::get_all_account_addons();
6785
+
6786
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
6787
+ return false;
6788
+ }
6789
+
6790
+ unset( $all_addons[ $this->_plugin->id ] );
6791
+
6792
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
6793
+
6794
+ return true;
6795
+ }
6796
+
6797
+ /**
6798
+ * Update account add-ons list.
6799
+ *
6800
+ * @author Vova Feldman (@svovaf)
6801
+ * @since 1.0.6
6802
+ *
6803
+ * @param FS_Plugin[] $addons
6804
+ * @param bool $store Flush to Database if true.
6805
+ */
6806
+ private function _store_account_addons( $addons, $store = true ) {
6807
+ $this->_logger->entrance();
6808
+
6809
+ $all_addons = self::get_all_account_addons();
6810
+ $all_addons[ $this->_plugin->id ] = $addons;
6811
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
6812
+ }
6813
+
6814
+ /**
6815
+ * Store account params in the Database.
6816
+ *
6817
+ * @author Vova Feldman (@svovaf)
6818
+ * @since 1.0.1
6819
+ */
6820
+ private function _store_account() {
6821
+ $this->_logger->entrance();
6822
+
6823
+ $this->_store_site( false );
6824
+ $this->_store_user( false );
6825
+ $this->_store_plans( false );
6826
+ $this->_store_licenses( false );
6827
+
6828
+ self::$_accounts->store();
6829
+ }
6830
+
6831
+ /**
6832
+ * Sync user's information.
6833
+ *
6834
+ * @author Vova Feldman (@svovaf)
6835
+ * @since 1.0.3
6836
+ * @uses FS_Api
6837
+ */
6838
+ private function _handle_account_user_sync() {
6839
+ $this->_logger->entrance();
6840
+
6841
+ $api = $this->get_api_user_scope();
6842
+
6843
+ // Get user's information.
6844
+ $user = $api->get( '/', true );
6845
+
6846
+ if ( isset( $user->id ) ) {
6847
+ $this->_user->first = $user->first;
6848
+ $this->_user->last = $user->last;
6849
+ $this->_user->email = $user->email;
6850
+
6851
+ $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
6852
+
6853
+ if ( $user->is_verified &&
6854
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
6855
+ ) {
6856
+ $this->_user->is_verified = true;
6857
+
6858
+ $this->do_action( 'account_email_verified', $user->email );
6859
+
6860
+ $this->_admin_notices->add(
6861
+ __fs( 'email-verified-message', $this->_slug ),
6862
+ __fs( 'right-on', $this->_slug ) . '!',
6863
+ 'success',
6864
+ // Make admin sticky if account menu item is invisible,
6865
+ // since the page will be auto redirected to the plugin's
6866
+ // main settings page, and the non-sticky message
6867
+ // will disappear.
6868
+ ! $is_menu_item_account_visible,
6869
+ false,
6870
+ 'email_verified'
6871
+ );
6872
+ }
6873
+
6874
+ // Flush user details to DB.
6875
+ $this->_store_user();
6876
+
6877
+ $this->do_action( 'after_account_user_sync', $user );
6878
+
6879
+ /**
6880
+ * If account menu item is hidden, redirect to plugin's main settings page.
6881
+ *
6882
+ * @author Vova Feldman (@svovaf)
6883
+ * @since 1.1.6
6884
+ *
6885
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
6886
+ */
6887
+ if ( ! $is_menu_item_account_visible ) {
6888
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
6889
+ exit();
6890
+ }
6891
+ }
6892
+ }
6893
+ }
6894
+
6895
+ /**
6896
+ * @author Vova Feldman (@svovaf)
6897
+ * @since 1.0.5
6898
+ * @uses FS_Api
6899
+ *
6900
+ * @param bool $flush
6901
+ *
6902
+ * @return object|\FS_Site
6903
+ */
6904
+ private function _fetch_site( $flush = false ) {
6905
+ $this->_logger->entrance();
6906
+ $api = $this->get_api_site_scope();
6907
+
6908
+ $site = $api->get( '/', $flush );
6909
+
6910
+ if ( ! isset( $site->error ) ) {
6911
+ $site = new FS_Site( $site );
6912
+ $site->slug = $this->_slug;
6913
+ $site->version = $this->get_plugin_version();
6914
+ }
6915
+
6916
+ return $site;
6917
+ }
6918
+
6919
+ /**
6920
+ * @param bool $store
6921
+ *
6922
+ * @return FS_Plugin_Plan|object|false
6923
+ */
6924
+ private function _enrich_site_plan( $store = true ) {
6925
+ // Try to load plan from local cache.
6926
+ $plan = $this->_get_plan_by_id( $this->_site->plan->id );
6927
+
6928
+ if ( false === $plan ) {
6929
+ $plan = $this->_fetch_site_plan();
6930
+ }
6931
+
6932
+ if ( $plan instanceof FS_Plugin_Plan ) {
6933
+ $this->_update_plan( $plan, $store );
6934
+ }
6935
+
6936
+ return $plan;
6937
+ }
6938
+
6939
+ /**
6940
+ * @author Vova Feldman (@svovaf)
6941
+ * @since 1.0.9
6942
+ * @uses FS_Api
6943
+ *
6944
+ * @param bool $store
6945
+ *
6946
+ * @return FS_Plugin_Plan|object|false
6947
+ */
6948
+ private function _enrich_site_trial_plan( $store = true ) {
6949
+ // Try to load plan from local cache.
6950
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
6951
+
6952
+ if ( false === $trial_plan ) {
6953
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
6954
+ }
6955
+
6956
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
6957
+ $this->_storage->store( 'trial_plan', $trial_plan, $store );
6958
+ }
6959
+
6960
+ return $trial_plan;
6961
+ }
6962
+
6963
+ /**
6964
+ * @author Vova Feldman (@svovaf)
6965
+ * @since 1.0.9
6966
+ * @uses FS_Api
6967
+ *
6968
+ * @param number|bool $license_id
6969
+ *
6970
+ * @return FS_Subscription|object|bool
6971
+ */
6972
+ private function _fetch_site_license_subscription( $license_id = false ) {
6973
+ $this->_logger->entrance();
6974
+ $api = $this->get_api_site_scope();
6975
+
6976
+ if ( ! is_numeric( $license_id ) ) {
6977
+ $license_id = $this->_license->id;
6978
+ }
6979
+
6980
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
6981
+
6982
+ return ! isset( $result->error ) ?
6983
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
6984
+ new FS_Subscription( $result->subscriptions[0] ) :
6985
+ false
6986
+ ) :
6987
+ $result;
6988
+ }
6989
+
6990
+ /**
6991
+ * @author Vova Feldman (@svovaf)
6992
+ * @since 1.0.4
6993
+ * @uses FS_Api
6994
+ *
6995
+ * @param number|bool $plan_id
6996
+ *
6997
+ * @return FS_Plugin_Plan|object
6998
+ */
6999
+ private function _fetch_site_plan( $plan_id = false ) {
7000
+ $this->_logger->entrance();
7001
+ $api = $this->get_api_site_scope();
7002
+
7003
+ if ( ! is_numeric( $plan_id ) ) {
7004
+ $plan_id = $this->_site->plan->id;
7005
+ }
7006
+
7007
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
7008
+
7009
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
7010
+ }
7011
+
7012
+ /**
7013
+ * @author Vova Feldman (@svovaf)
7014
+ * @since 1.0.5
7015
+ * @uses FS_Api
7016
+ *
7017
+ * @return FS_Plugin_Plan[]|object
7018
+ */
7019
+ private function _fetch_plugin_plans() {
7020
+ $this->_logger->entrance();
7021
+ $api = $this->get_api_site_scope();
7022
+
7023
+ $result = $api->get( '/plans.json', true );
7024
+
7025
+ if ( ! $this->is_api_error( $result ) ) {
7026
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
7027
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
7028
+ }
7029
+
7030
+ $result = $result->plans;
7031
+ }
7032
+
7033
+ return $result;
7034
+ }
7035
+
7036
+ /**
7037
+ * @author Vova Feldman (@svovaf)
7038
+ * @since 1.0.5
7039
+ * @uses FS_Api
7040
+ *
7041
+ * @param number|bool $plugin_id
7042
+ *
7043
+ * @return FS_Plugin_License[]|object
7044
+ */
7045
+ private function _fetch_licenses( $plugin_id = false ) {
7046
+ $this->_logger->entrance();
7047
+
7048
+ $api = $this->get_api_user_scope();
7049
+
7050
+ if ( ! is_numeric( $plugin_id ) ) {
7051
+ $plugin_id = $this->_plugin->id;
7052
+ }
7053
+
7054
+ $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
7055
+
7056
+ if ( ! isset( $result->error ) ) {
7057
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
7058
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
7059
+ }
7060
+
7061
+ $result = $result->licenses;
7062
+ }
7063
+
7064
+ return $result;
7065
+ }
7066
+
7067
+ /**
7068
+ * @author Vova Feldman (@svovaf)
7069
+ * @since 1.0.4
7070
+ *
7071
+ * @param FS_Plugin_Plan $plan
7072
+ * @param bool $store
7073
+ */
7074
+ private function _update_plan( $plan, $store = false ) {
7075
+ $this->_logger->entrance();
7076
+
7077
+ $this->_site->plan = $plan;
7078
+ $this->_store_site( $store );
7079
+ }
7080
+
7081
+ /**
7082
+ * @author Vova Feldman (@svovaf)
7083
+ * @since 1.0.5
7084
+ *
7085
+ * @param FS_Plugin_License[] $licenses
7086
+ * @param string|bool $plugin_slug
7087
+ */
7088
+ private function _update_licenses( $licenses, $plugin_slug = false ) {
7089
+ $this->_logger->entrance();
7090
+
7091
+ if ( is_array( $licenses ) ) {
7092
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
7093
+ $licenses[ $i ]->updated = time();
7094
+ }
7095
+ }
7096
+
7097
+ if ( ! is_string( $plugin_slug ) ) {
7098
+ $this->_licenses = $licenses;
7099
+ }
7100
+
7101
+ $this->_store_licenses( true, $plugin_slug, $licenses );
7102
+ }
7103
+
7104
+ /**
7105
+ * @author Vova Feldman (@svovaf)
7106
+ * @since 1.0.4
7107
+ *
7108
+ * @param bool|number $plugin_id
7109
+ * @param bool $flush Since 1.1.7.3
7110
+ *
7111
+ * @return object|false New plugin tag info if exist.
7112
+ */
7113
+ private function _fetch_newer_version( $plugin_id = false, $flush = true ) {
7114
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush );
7115
+
7116
+ if ( ! is_object( $latest_tag ) ) {
7117
+ return false;
7118
+ }
7119
+
7120
+ // Check if version is actually newer.
7121
+ $has_new_version =
7122
+ // If it's an non-installed add-on then always return latest.
7123
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
7124
+ // Compare versions.
7125
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
7126
+
7127
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
7128
+
7129
+ return $has_new_version ? $latest_tag : false;
7130
+ }
7131
+
7132
+ /**
7133
+ * @author Vova Feldman (@svovaf)
7134
+ * @since 1.0.5
7135
+ *
7136
+ * @param bool|number $plugin_id
7137
+ * @param bool $flush Since 1.1.7.3
7138
+ *
7139
+ * @return bool|FS_Plugin_Tag
7140
+ */
7141
+ function get_update( $plugin_id = false, $flush = true ) {
7142
+ $this->_logger->entrance();
7143
+
7144
+ if ( ! is_numeric( $plugin_id ) ) {
7145
+ $plugin_id = $this->_plugin->id;
7146
+ }
7147
+
7148
+ $this->_check_updates( true, $plugin_id, $flush );
7149
+ $updates = $this->get_all_updates();
7150
+
7151
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
7152
+ }
7153
+
7154
+ /**
7155
+ * Check if site assigned with active license.
7156
+ *
7157
+ * @author Vova Feldman (@svovaf)
7158
+ * @since 1.0.6
7159
+ */
7160
+ function has_active_license() {
7161
+ return (
7162
+ is_object( $this->_license ) &&
7163
+ is_numeric( $this->_license->id ) &&
7164
+ ! $this->_license->is_expired()
7165
+ );
7166
+ }
7167
+
7168
+ /**
7169
+ * Check if site assigned with license with enabled features.
7170
+ *
7171
+ * @author Vova Feldman (@svovaf)
7172
+ * @since 1.0.6
7173
+ *
7174
+ * @return bool
7175
+ */
7176
+ function has_features_enabled_license() {
7177
+ return (
7178
+ is_object( $this->_license ) &&
7179
+ is_numeric( $this->_license->id ) &&
7180
+ $this->_license->is_features_enabled()
7181
+ );
7182
+ }
7183
+
7184
+ /**
7185
+ * Check if user is a trial or have feature enabled license.
7186
+ *
7187
+ * @author Vova Feldman (@svovaf)
7188
+ * @since 1.1.7
7189
+ *
7190
+ * @return bool
7191
+ */
7192
+ function can_use_premium_code() {
7193
+ return $this->is_trial() || $this->has_features_enabled_license();
7194
+ }
7195
+
7196
+ /**
7197
+ * Sync site's plan.
7198
+ *
7199
+ * @author Vova Feldman (@svovaf)
7200
+ * @since 1.0.3
7201
+ *
7202
+ * @uses FS_Api
7203
+ *
7204
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7205
+ * the admin.
7206
+ */
7207
+ private function _sync_license( $background = false ) {
7208
+ $this->_logger->entrance();
7209
+
7210
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
7211
+
7212
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
7213
+
7214
+ if ( $is_addon_sync ) {
7215
+ $this->_sync_addon_license( $plugin_id, $background );
7216
+ } else {
7217
+ $this->_sync_plugin_license( $background );
7218
+ }
7219
+
7220
+ $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
7221
+ }
7222
+
7223
+ /**
7224
+ * Sync plugin's add-on license.
7225
+ *
7226
+ * @author Vova Feldman (@svovaf)
7227
+ * @since 1.0.6
7228
+ * @uses FS_Api
7229
+ *
7230
+ * @param number $addon_id
7231
+ * @param bool $background
7232
+ */
7233
+ private function _sync_addon_license( $addon_id, $background ) {
7234
+ $this->_logger->entrance();
7235
+
7236
+ if ( $this->is_addon_activated( $addon_id ) ) {
7237
+ // If already installed, use add-on sync.
7238
+ $fs_addon = self::get_instance_by_id( $addon_id );
7239
+ $fs_addon->_sync_license( $background );
7240
+
7241
+ return;
7242
+ }
7243
+
7244
+ // Validate add-on exists.
7245
+ $addon = $this->get_addon( $addon_id );
7246
+
7247
+ if ( ! is_object( $addon ) ) {
7248
+ return;
7249
+ }
7250
+
7251
+ // Add add-on into account add-ons.
7252
+ $account_addons = $this->get_account_addons();
7253
+ if ( ! is_array( $account_addons ) ) {
7254
+ $account_addons = array();
7255
+ }
7256
+ $account_addons[] = $addon->id;
7257
+ $account_addons = array_unique( $account_addons );
7258
+ $this->_store_account_addons( $account_addons );
7259
+
7260
+ // Load add-on licenses.
7261
+ $licenses = $this->_fetch_licenses( $addon->id );
7262
+
7263
+ // Sync add-on licenses.
7264
+ if ( ! isset( $licenses->error ) ) {
7265
+ $this->_update_licenses( $licenses, $addon->slug );
7266
+
7267
+ if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
7268
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
7269
+
7270
+ if ( ! isset( $plans_result->error ) ) {
7271
+ $plans = array();
7272
+ foreach ( $plans_result->plans as $plan ) {
7273
+ $plans[] = new FS_Plugin_Plan( $plan );
7274
+ }
7275
+
7276
+ $this->_admin_notices->add_sticky(
7277
+ FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
7278
+ sprintf(
7279
+ __fs( 'addon-successfully-upgraded-message', $this->_slug ),
7280
+ $addon->title
7281
+ ) . ' ' . $this->_get_latest_download_link(
7282
+ __fs( 'download-latest-version', $this->_slug ),
7283
+ $addon_id
7284
+ )
7285
+ :
7286
+ sprintf(
7287
+ __fs( 'addon-successfully-purchased-message', $this->_slug ),
7288
+ $addon->title
7289
+ ) . ' ' . $this->_get_latest_download_link(
7290
+ __fs( 'download-latest-version', $this->_slug ),
7291
+ $addon_id
7292
+ ),
7293
+ 'addon_plan_upgraded_' . $addon->slug,
7294
+ __fs( 'yee-haw', $this->_slug ) . '!'
7295
+ );
7296
+ }
7297
+ }
7298
+ }
7299
+ }
7300
+
7301
+ /**
7302
+ * Sync site's plugin plan.
7303
+ *
7304
+ * @author Vova Feldman (@svovaf)
7305
+ * @since 1.0.6
7306
+ * @uses FS_Api
7307
+ *
7308
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7309
+ * the admin.
7310
+ */
7311
+ private function _sync_plugin_license( $background = false ) {
7312
+ $this->_logger->entrance();
7313
+
7314
+ // Sync site info.
7315
+ $site = $this->send_install_update( array(), true );
7316
+
7317
+ $plan_change = 'none';
7318
+
7319
+ if ( $this->is_api_error( $site ) ) {
7320
+ // Show API messages only if not background sync or if paying customer.
7321
+ if ( ! $background || $this->is_paying() ) {
7322
+ // Try to ping API to see if not blocked.
7323
+ if ( ! FS_Api::test() ) {
7324
+ /**
7325
+ * Failed to ping API - blocked!
7326
+ *
7327
+ * @author Vova Feldman (@svovaf)
7328
+ * @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.
7329
+ */
7330
+ $api = $this->get_api_site_scope();
7331
+
7332
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
7333
+ self::$_global_admin_notices->add(
7334
+ sprintf(
7335
+ __fs( 'server-blocking-access', $this->_slug ),
7336
+ $this->get_plugin_name(),
7337
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
7338
+ ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
7339
+ __fs( 'oops', $this->_slug ) . '...',
7340
+ 'error',
7341
+ $background,
7342
+ false,
7343
+ 'api_blocked'
7344
+ );
7345
+ }
7346
+ } else {
7347
+ // Authentication params are broken.
7348
+ $this->_admin_notices->add(
7349
+ __fs( 'wrong-authentication-param-message', $this->_slug ),
7350
+ __fs( 'oops', $this->_slug ) . '...',
7351
+ 'error'
7352
+ );
7353
+ }
7354
+ }
7355
+
7356
+ // No reason to continue with license sync while there are API issues.
7357
+ return;
7358
+ }
7359
+
7360
+ // Remove sticky API connectivity message.
7361
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
7362
+
7363
+ $site = new FS_Site( $site );
7364
+
7365
+ // Sync plans.
7366
+ $this->_sync_plans();
7367
+
7368
+ if ( ! $this->has_paid_plan() ) {
7369
+ $this->_site = $site;
7370
+ $this->_enrich_site_plan( true );
7371
+ $this->_store_site();
7372
+ } else {
7373
+ // Sync licenses.
7374
+ $this->_sync_licenses();
7375
+
7376
+ // Check if plan / license changed.
7377
+ if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
7378
+ // Check if trial started.
7379
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
7380
+ $site->trial_ends != $this->_site->trial_ends ||
7381
+ // Check if license changed.
7382
+ $site->license_id != $this->_site->license_id
7383
+ ) {
7384
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
7385
+ // New trial started.
7386
+ $this->_site = $site;
7387
+ $plan_change = 'trial_started';
7388
+
7389
+ // Store trial plan information.
7390
+ $this->_enrich_site_trial_plan( true );
7391
+
7392
+ // For trial with subscription use-case.
7393
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7394
+
7395
+ if ( is_object( $new_license ) && ! $new_license->is_expired() ) {
7396
+ $this->_site = $site;
7397
+ $this->_update_site_license( $new_license );
7398
+ $this->_store_licenses();
7399
+ $this->_enrich_site_plan( true );
7400
+
7401
+ $this->_sync_site_subscription( $this->_license );
7402
+ }
7403
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
7404
+ // Was in trial, but now trial expired and no license ID.
7405
+ // New trial started.
7406
+ $this->_site = $site;
7407
+ $plan_change = 'trial_expired';
7408
+
7409
+ // Clear trial plan information.
7410
+ $this->_storage->trial_plan = null;
7411
+
7412
+ } else {
7413
+ $is_free = $this->is_free_plan();
7414
+
7415
+ // Make sure license exist and not expired.
7416
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7417
+
7418
+ if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
7419
+ // The license is expired, so ignore upgrade method.
7420
+ } else {
7421
+ // License changed.
7422
+ $this->_site = $site;
7423
+ $this->_update_site_license( $new_license );
7424
+ $this->_store_licenses();
7425
+ $this->_enrich_site_plan( true );
7426
+
7427
+ $plan_change = $is_free ?
7428
+ 'upgraded' :
7429
+ ( is_object( $new_license ) ?
7430
+ 'changed' :
7431
+ 'downgraded' );
7432
+ }
7433
+ }
7434
+
7435
+ // Store updated site info.
7436
+ $this->_store_site();
7437
+ } else {
7438
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
7439
+ if ( ! $this->has_features_enabled_license() ) {
7440
+ $this->_deactivate_license();
7441
+ $plan_change = 'downgraded';
7442
+ } else {
7443
+ $plan_change = 'expired';
7444
+ }
7445
+ }
7446
+
7447
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
7448
+ $this->_sync_site_subscription( $this->_license );
7449
+ }
7450
+ }
7451
+ }
7452
+
7453
+ if ( $this->has_paid_plan() ) {
7454
+ switch ( $plan_change ) {
7455
+ case 'none':
7456
+ if ( ! $background && is_admin() ) {
7457
+ $plan = $this->is_trial() ?
7458
+ $this->_storage->trial_plan :
7459
+ $this->_site->plan;
7460
+
7461
+ $this->_admin_notices->add(
7462
+ sprintf(
7463
+ __fs( 'plan-did-not-change-message', $this->_slug ) . ' ' .
7464
+ sprintf(
7465
+ '<a href="%s">%s</a>',
7466
+ $this->contact_url(
7467
+ 'bug',
7468
+ sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
7469
+ strtoupper( $plan->name )
7470
+ )
7471
+ ),
7472
+ __fs( 'contact-us-here', $this->_slug )
7473
+ ),
7474
+ '<i>' . $plan->title . ( $this->is_trial() ? ' ' . __fs( 'trial', $this->_slug ) : '' ) . '</i>'
7475
+ ),
7476
+ __fs( 'hmm', $this->_slug ) . '...',
7477
+ 'error'
7478
+ );
7479
+ }
7480
+ break;
7481
+ case 'upgraded':
7482
+ $this->_admin_notices->add_sticky(
7483
+ sprintf(
7484
+ __fs( 'plan-upgraded-message', $this->_slug ),
7485
+ '<i>' . $this->get_plugin_name() . '</i>'
7486
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7487
+ __fs( 'download-latest-x-version', $this->_slug ),
7488
+ $this->_site->plan->title
7489
+ ) )
7490
+ ),
7491
+ 'plan_upgraded',
7492
+ __fs( 'yee-haw', $this->_slug ) . '!'
7493
+ );
7494
+
7495
+ $this->_admin_notices->remove_sticky( array(
7496
+ 'trial_started',
7497
+ 'trial_promotion',
7498
+ 'trial_expired',
7499
+ 'activation_complete',
7500
+ ) );
7501
+ break;
7502
+ case 'changed':
7503
+ $this->_admin_notices->add_sticky(
7504
+ sprintf(
7505
+ __fs( 'plan-changed-to-x-message', $this->_slug ),
7506
+ $this->_site->plan->title
7507
+ ),
7508
+ 'plan_changed'
7509
+ );
7510
+
7511
+ $this->_admin_notices->remove_sticky( array(
7512
+ 'trial_started',
7513
+ 'trial_promotion',
7514
+ 'trial_expired',
7515
+ 'activation_complete',
7516
+ ) );
7517
+ break;
7518
+ case 'downgraded':
7519
+ $this->_admin_notices->add_sticky(
7520
+ sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
7521
+ 'license_expired',
7522
+ __fs( 'hmm', $this->_slug ) . '...'
7523
+ );
7524
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7525
+ break;
7526
+ case 'expired':
7527
+ $this->_admin_notices->add_sticky(
7528
+ sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
7529
+ 'license_expired',
7530
+ __fs( 'hmm', $this->_slug ) . '...'
7531
+ );
7532
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7533
+ break;
7534
+ case 'trial_started':
7535
+ $this->_admin_notices->add_sticky(
7536
+ sprintf(
7537
+ __fs( 'trial-started-message', $this->_slug ),
7538
+ '<i>' . $this->get_plugin_name() . '</i>'
7539
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7540
+ __fs( 'download-latest-x-version', $this->_slug ),
7541
+ $this->_storage->trial_plan->title
7542
+ ) ) ),
7543
+ 'trial_started',
7544
+ __fs( 'yee-haw', $this->_slug ) . '!'
7545
+ );
7546
+
7547
+ $this->_admin_notices->remove_sticky( array(
7548
+ 'trial_promotion',
7549
+ ) );
7550
+ break;
7551
+ case 'trial_expired':
7552
+ $this->_admin_notices->add_sticky(
7553
+ __fs( 'trial-expired-message', $this->_slug ),
7554
+ 'trial_expired',
7555
+ __fs( 'hmm', $this->_slug ) . '...'
7556
+ );
7557
+ $this->_admin_notices->remove_sticky( array(
7558
+ 'trial_started',
7559
+ 'trial_promotion',
7560
+ 'plan_upgraded',
7561
+ ) );
7562
+ break;
7563
+ }
7564
+ }
7565
+
7566
+ if ( 'none' !== $plan_change ) {
7567
+ $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
7568
+ }
7569
+ }
7570
+
7571
+ /**
7572
+ * @author Vova Feldman (@svovaf)
7573
+ * @since 1.0.5
7574
+ *
7575
+ * @param bool $background
7576
+ */
7577
+ protected function _activate_license( $background = false ) {
7578
+ $this->_logger->entrance();
7579
+
7580
+ $license_id = fs_request_get( 'license_id' );
7581
+
7582
+ if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
7583
+ // License is already activated.
7584
+ return;
7585
+ }
7586
+
7587
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
7588
+ $this->_get_license_by_id( $license_id ) :
7589
+ $this->_get_available_premium_license();
7590
+
7591
+ if ( ! is_object( $premium_license ) ) {
7592
+ return;
7593
+ }
7594
+
7595
+ $api = $this->get_api_site_scope();
7596
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put' );
7597
+
7598
+ if ( $this->is_api_error( $license ) ) {
7599
+ if ( ! $background ) {
7600
+ $this->_admin_notices->add(
7601
+ __fs( 'license-activation-failed-message', $this->_slug ) . '<br> ' .
7602
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license, true ),
7603
+ __fs( 'hmm', $this->_slug ) . '...',
7604
+ 'error'
7605
+ );
7606
+ }
7607
+
7608
+ return;
7609
+ }
7610
+
7611
+ $premium_license = new FS_Plugin_License( $license );
7612
+
7613
+ // Updated site plan.
7614
+ $site = $this->get_api_site_scope()->get( '/', true );
7615
+ if ( ! $this->is_api_error( $site ) ) {
7616
+ $this->_site = new FS_Site( $site );
7617
+ }
7618
+ $this->_update_site_license( $premium_license );
7619
+ $this->_enrich_site_plan( false );
7620
+
7621
+ $this->_store_account();
7622
+
7623
+ if ( ! $background ) {
7624
+ $this->_admin_notices->add_sticky(
7625
+ __fs( 'license-activated-message', $this->_slug ) .
7626
+ ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7627
+ __fs( 'download-latest-x-version', $this->_slug ),
7628
+ $this->_site->plan->title
7629
+ ) ) ),
7630
+ 'license_activated',
7631
+ __fs( 'yee-haw', $this->_slug ) . '!'
7632
+ );
7633
+ }
7634
+
7635
+ $this->_admin_notices->remove_sticky( array(
7636
+ 'trial_promotion',
7637
+ 'license_expired',
7638
+ ) );
7639
+ }
7640
+
7641
+ /**
7642
+ * @author Vova Feldman (@svovaf)
7643
+ * @since 1.0.5
7644
+ *
7645
+ * @param bool $show_notice
7646
+ */
7647
+ protected function _deactivate_license( $show_notice = true ) {
7648
+ $this->_logger->entrance();
7649
+
7650
+ if ( ! is_object( $this->_license ) ) {
7651
+ $this->_admin_notices->add(
7652
+ sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
7653
+ __fs( 'hmm', $this->_slug ) . '...'
7654
+ );
7655
+
7656
+ return;
7657
+ }
7658
+
7659
+ $api = $this->get_api_site_scope();
7660
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
7661
+
7662
+ if ( isset( $license->error ) ) {
7663
+ $this->_admin_notices->add(
7664
+ __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
7665
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
7666
+ __fs( 'hmm', $this->_slug ) . '...',
7667
+ 'error'
7668
+ );
7669
+
7670
+ return;
7671
+ }
7672
+
7673
+ // Update license cache.
7674
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
7675
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
7676
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
7677
+ }
7678
+ }
7679
+
7680
+ // Updated site plan to default.
7681
+ $this->_sync_plans();
7682
+ $this->_site->plan->id = $this->_plans[0]->id;
7683
+ // Unlink license from site.
7684
+ $this->_update_site_license( null );
7685
+ $this->_enrich_site_plan( false );
7686
+
7687
+ $this->_store_account();
7688
+
7689
+ if ( $show_notice ) {
7690
+ $this->_admin_notices->add(
7691
+ sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
7692
+ __fs( 'ok', $this->_slug )
7693
+ );
7694
+ }
7695
+
7696
+ $this->_admin_notices->remove_sticky( array(
7697
+ 'plan_upgraded',
7698
+ 'license_activated',
7699
+ ) );
7700
+ }
7701
+
7702
+ /**
7703
+ * Site plan downgrade.
7704
+ *
7705
+ * @author Vova Feldman (@svovaf)
7706
+ * @since 1.0.4
7707
+ *
7708
+ * @uses FS_Api
7709
+ */
7710
+ private function _downgrade_site() {
7711
+ $this->_logger->entrance();
7712
+
7713
+ $api = $this->get_api_site_scope();
7714
+ $site = $api->call( 'downgrade.json', 'put' );
7715
+
7716
+ $plan_downgraded = false;
7717
+ $plan = false;
7718
+ if ( ! isset( $site->error ) ) {
7719
+ $prev_plan_id = $this->_site->plan->id;
7720
+
7721
+ // Update new site plan id.
7722
+ $this->_site->plan->id = $site->plan_id;
7723
+
7724
+ $plan = $this->_enrich_site_plan();
7725
+ $subscription = $this->_sync_site_subscription( $this->_license );
7726
+
7727
+ // Plan downgraded if plan was changed or subscription was cancelled.
7728
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
7729
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
7730
+ } else {
7731
+ // handle different error cases.
7732
+
7733
+ }
7734
+
7735
+ if ( $plan_downgraded ) {
7736
+ // Remove previous sticky message about upgrade (if exist).
7737
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7738
+
7739
+ $this->_admin_notices->add(
7740
+ sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
7741
+ $plan->title,
7742
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
7743
+ )
7744
+ );
7745
+
7746
+ // Store site updates.
7747
+ $this->_store_site();
7748
+ } else {
7749
+ $this->_admin_notices->add(
7750
+ __fs( 'plan-downgraded-failure-message', $this->_slug ),
7751
+ __fs( 'oops', $this->_slug ) . '...',
7752
+ 'error'
7753
+ );
7754
+ }
7755
+ }
7756
+
7757
+ /**
7758
+ * @author Vova Feldman (@svovaf)
7759
+ * @since 1.1.8.1
7760
+ *
7761
+ * @param bool|string $plan_name
7762
+ *
7763
+ * @return bool If trial was successfully started.
7764
+ */
7765
+ function start_trial($plan_name = false) {
7766
+ $this->_logger->entrance();
7767
+
7768
+ if ( $this->is_trial() ) {
7769
+ // Already in trial mode.
7770
+ $this->_admin_notices->add(
7771
+ __fs( 'in-trial-mode', $this->_slug ),
7772
+ __fs( 'oops', $this->_slug ) . '...',
7773
+ 'error'
7774
+ );
7775
+
7776
+ return false;
7777
+ }
7778
+
7779
+ if ( $this->_site->is_trial_utilized() ) {
7780
+ // Trial was already utilized.
7781
+ $this->_admin_notices->add(
7782
+ __fs( 'trial-utilized', $this->_slug ),
7783
+ __fs( 'oops', $this->_slug ) . '...',
7784
+ 'error'
7785
+ );
7786
+
7787
+ return false;
7788
+ }
7789
+
7790
+ if ( false !== $plan_name ) {
7791
+ $plan = $this->get_plan_by_name( $plan_name );
7792
+
7793
+ if ( false === $plan ) {
7794
+ // Plan doesn't exist.
7795
+ $this->_admin_notices->add(
7796
+ sprintf( __fs( 'trial-plan-x-not-exist', $this->_slug ), $plan_name ),
7797
+ __fs( 'oops', $this->_slug ) . '...',
7798
+ 'error'
7799
+ );
7800
+
7801
+ return false;
7802
+ }
7803
+
7804
+ if ( ! $plan->has_trial() ) {
7805
+ // Plan doesn't exist.
7806
+ $this->_admin_notices->add(
7807
+ sprintf( __fs( 'plan-x-no-trial', $this->_slug ), $plan_name ),
7808
+ __fs( 'oops', $this->_slug ) . '...',
7809
+ 'error'
7810
+ );
7811
+
7812
+ return false;
7813
+ }
7814
+ } else {
7815
+ if ( ! $this->has_trial_plan() ) {
7816
+ // None of the plans have a trial.
7817
+ $this->_admin_notices->add(
7818
+ __fs( 'no-trials', $this->_slug ),
7819
+ __fs( 'oops', $this->_slug ) . '...',
7820
+ 'error'
7821
+ );
7822
+
7823
+ return false;
7824
+ }
7825
+
7826
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
7827
+
7828
+ $plan = $plans_with_trial[0];
7829
+ }
7830
+
7831
+ $api = $this->get_api_site_scope();
7832
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
7833
+
7834
+ if ( $this->is_api_error( $plan ) ) {
7835
+ // Some API error while trying to start the trial.
7836
+ $this->_admin_notices->add(
7837
+ __fs( 'unexpected-api-error', $this->_slug ) . ' ' . var_export( $plan, true ),
7838
+ __fs( 'oops', $this->_slug ) . '...',
7839
+ 'error'
7840
+ );
7841
+
7842
+ return false;
7843
+ }
7844
+
7845
+ // Sync license.
7846
+ $this->_sync_license();
7847
+
7848
+ return $this->is_trial();
7849
+ }
7850
+
7851
+ /**
7852
+ * Cancel site trial.
7853
+ *
7854
+ * @author Vova Feldman (@svovaf)
7855
+ * @since 1.0.9
7856
+ *
7857
+ * @uses FS_Api
7858
+ */
7859
+ private function _cancel_trial() {
7860
+ $this->_logger->entrance();
7861
+
7862
+ if ( ! $this->is_trial() ) {
7863
+ $this->_admin_notices->add(
7864
+ __fs( 'trial-cancel-no-trial-message', $this->_slug ),
7865
+ __fs( 'oops', $this->_slug ) . '...',
7866
+ 'error'
7867
+ );
7868
+
7869
+ return;
7870
+ }
7871
+
7872
+ $api = $this->get_api_site_scope();
7873
+ $site = $api->call( 'trials.json', 'delete' );
7874
+
7875
+ $trial_cancelled = false;
7876
+
7877
+ if ( ! $this->is_api_error( $site ) ) {
7878
+ $prev_trial_ends = $this->_site->trial_ends;
7879
+
7880
+ if ( $this->is_paid_trial() ) {
7881
+ $this->_license->expiration = $site->trial_ends;
7882
+ $this->_license->is_cancelled = true;
7883
+ $this->_update_site_license( $this->_license );
7884
+ $this->_store_licenses();
7885
+
7886
+ // Clear subscription reference.
7887
+ $this->_sync_site_subscription( null );
7888
+ }
7889
+
7890
+ // Update site info.
7891
+ $this->_site = new FS_Site( $site );
7892
+ $this->_enrich_site_plan();
7893
+
7894
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
7895
+ } else {
7896
+ // handle different error cases.
7897
+
7898
+ }
7899
+
7900
+ if ( $trial_cancelled ) {
7901
+ // Remove previous sticky messages about upgrade or trial (if exist).
7902
+ $this->_admin_notices->remove_sticky( array(
7903
+ 'trial_started',
7904
+ 'trial_promotion',
7905
+ 'plan_upgraded',
7906
+ ) );
7907
+
7908
+ // Store site updates.
7909
+ $this->_store_site();
7910
+
7911
+ // Clear trial plan information.
7912
+ unset( $this->_storage->trial_plan );
7913
+
7914
+ if ( ! $this->is_addon() ||
7915
+ ! $this->deactivate_premium_only_addon_without_license( true )
7916
+ ) {
7917
+ $this->_admin_notices->add(
7918
+ sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
7919
+ );
7920
+ }
7921
+ } else {
7922
+ $this->_admin_notices->add(
7923
+ __fs( 'trial-cancel-failure-message', $this->_slug ),
7924
+ __fs( 'oops', $this->_slug ) . '...',
7925
+ 'error'
7926
+ );
7927
+ }
7928
+ }
7929
+
7930
+ /**
7931
+ * @author Vova Feldman (@svovaf)
7932
+ * @since 1.0.6
7933
+ *
7934
+ * @param bool|number $plugin_id
7935
+ *
7936
+ * @return bool
7937
+ */
7938
+ private function _is_addon_id( $plugin_id ) {
7939
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
7940
+ }
7941
+
7942
+ /**
7943
+ * Check if user eligible to download premium version updates.
7944
+ *
7945
+ * @author Vova Feldman (@svovaf)
7946
+ * @since 1.0.6
7947
+ *
7948
+ * @return bool
7949
+ */
7950
+ private function _can_download_premium() {
7951
+ return $this->has_active_license() ||
7952
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
7953
+ }
7954
+
7955
+ /**
7956
+ *
7957
+ * @author Vova Feldman (@svovaf)
7958
+ * @since 1.0.6
7959
+ *
7960
+ * @param bool|number $addon_id
7961
+ * @param string $type "json" or "zip"
7962
+ *
7963
+ * @return string
7964
+ */
7965
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
7966
+
7967
+ $is_addon = $this->_is_addon_id( $addon_id );
7968
+
7969
+ $is_premium = null;
7970
+ if ( ! $is_addon ) {
7971
+ $is_premium = $this->_can_download_premium();
7972
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
7973
+ $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
7974
+ }
7975
+
7976
+ return // If add-on, then append add-on ID.
7977
+ ( $is_addon ? "/addons/$addon_id" : '' ) .
7978
+ '/updates/latest.' . $type .
7979
+ // If add-on and not yet activated, try to fetch based on server licensing.
7980
+ ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
7981
+ }
7982
+
7983
+ /**
7984
+ * @author Vova Feldman (@svovaf)
7985
+ * @since 1.0.4
7986
+ *
7987
+ * @param bool|number $addon_id
7988
+ * @param bool $flush Since 1.1.7.3
7989
+ *
7990
+ * @return object|false Plugin latest tag info.
7991
+ */
7992
+ function _fetch_latest_version( $addon_id = false, $flush = true ) {
7993
+ $this->_logger->entrance();
7994
+
7995
+ /**
7996
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
7997
+ * @since 1.1.7.4 Also check updates for add-ons.
7998
+ */
7999
+ if ( ! $this->is_registered() &&
8000
+ ! $this->_is_addon_id( $addon_id )
8001
+ ) {
8002
+ return false;
8003
+ }
8004
+
8005
+ $tag = $this->get_api_site_or_plugin_scope()->get(
8006
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
8007
+ $flush
8008
+ );
8009
+
8010
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
8011
+
8012
+ $this->_logger->departure( 'Latest version ' . $latest_version );
8013
+
8014
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
8015
+ }
8016
+
8017
+ #region Download Plugin ------------------------------------------------------------------
8018
+
8019
+ /**
8020
+ * Download latest plugin version, based on plan.
8021
+ * The download will be fetched via the API first.
8022
+ *
8023
+ * @author Vova Feldman (@svovaf)
8024
+ * @since 1.0.4
8025
+ *
8026
+ * @param bool|number $plugin_id
8027
+ *
8028
+ * @uses FS_Api
8029
+ *
8030
+ * @deprecated
8031
+ */
8032
+ private function _download_latest( $plugin_id = false ) {
8033
+ $this->_logger->entrance();
8034
+
8035
+ $is_addon = $this->_is_addon_id( $plugin_id );
8036
+
8037
+ $is_premium = $this->_can_download_premium();
8038
+
8039
+ $latest = $this->get_api_site_scope()->call(
8040
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8041
+ );
8042
+
8043
+ $slug = $this->_slug;
8044
+ if ( $is_addon ) {
8045
+ $addon = $this->get_addon( $plugin_id );
8046
+ $slug = is_object( $addon ) ? $addon->slug : 'addon';
8047
+ }
8048
+
8049
+ if ( ! is_object( $latest ) ) {
8050
+ header( "Content-Type: application/zip" );
8051
+ header( "Content-Disposition: attachment; filename={$slug}" . ( ! $is_addon && $is_premium ? '-premium' : '' ) . ".zip" );
8052
+ header( "Content-Length: " . strlen( $latest ) );
8053
+ echo $latest;
8054
+
8055
+ exit();
8056
+ }
8057
+ }
8058
+
8059
+ /**
8060
+ * Download latest plugin version, based on plan.
8061
+ *
8062
+ * Not like _download_latest(), this will redirect the page
8063
+ * to secure download url to prevent dual download (from FS to WP server,
8064
+ * and then from WP server to the client / browser).
8065
+ *
8066
+ * @author Vova Feldman (@svovaf)
8067
+ * @since 1.0.9
8068
+ *
8069
+ * @param bool|number $plugin_id
8070
+ *
8071
+ * @uses FS_Api
8072
+ * @uses wp_redirect()
8073
+ */
8074
+ private function _download_latest_directly( $plugin_id = false ) {
8075
+ $this->_logger->entrance();
8076
+
8077
+ wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
8078
+ }
8079
+
8080
+ /**
8081
+ * Get latest plugin FS API download URL.
8082
+ *
8083
+ * @author Vova Feldman (@svovaf)
8084
+ * @since 1.0.9
8085
+ *
8086
+ * @param bool|number $plugin_id
8087
+ *
8088
+ * @return string
8089
+ */
8090
+ private function _get_latest_download_api_url( $plugin_id = false ) {
8091
+ $this->_logger->entrance();
8092
+
8093
+ return $this->get_api_site_scope()->get_signed_url(
8094
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8095
+ );
8096
+ }
8097
+
8098
+ /**
8099
+ * Get latest plugin download link.
8100
+ *
8101
+ * @author Vova Feldman (@svovaf)
8102
+ * @since 1.0.9
8103
+ *
8104
+ * @param string $label
8105
+ * @param bool|number $plugin_id
8106
+ *
8107
+ * @return string
8108
+ */
8109
+ private function _get_latest_download_link( $label, $plugin_id = false ) {
8110
+ return sprintf(
8111
+ '<a target="_blank" href="%s">%s</a>',
8112
+ $this->_get_latest_download_local_url( $plugin_id ),
8113
+ $label
8114
+ );
8115
+ }
8116
+
8117
+ /**
8118
+ * Get latest plugin download local URL.
8119
+ *
8120
+ * @author Vova Feldman (@svovaf)
8121
+ * @since 1.0.9
8122
+ *
8123
+ * @param bool|number $plugin_id
8124
+ *
8125
+ * @return string
8126
+ */
8127
+ function _get_latest_download_local_url( $plugin_id = false ) {
8128
+ // Add timestamp to protect from caching.
8129
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
8130
+
8131
+ if ( ! empty( $plugin_id ) ) {
8132
+ $params['plugin_id'] = $plugin_id;
8133
+ }
8134
+
8135
+ return $this->get_account_url( 'download_latest', $params );
8136
+ }
8137
+
8138
+ #endregion Download Plugin ------------------------------------------------------------------
8139
+
8140
+ /**
8141
+ * @author Vova Feldman (@svovaf)
8142
+ * @since 1.0.4
8143
+ *
8144
+ * @uses FS_Api
8145
+ *
8146
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
8147
+ * was initiated by the admin.
8148
+ * @param bool|number $plugin_id
8149
+ * @param bool $flush Since 1.1.7.3
8150
+ */
8151
+ private function _check_updates( $background = false, $plugin_id = false, $flush = true ) {
8152
+ $this->_logger->entrance();
8153
+
8154
+ // Check if there's a newer version for download.
8155
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush );
8156
+
8157
+ $update = null;
8158
+ if ( is_object( $new_version ) ) {
8159
+ $update = new FS_Plugin_Tag( $new_version );
8160
+
8161
+ if ( ! $background ) {
8162
+ $this->_admin_notices->add(
8163
+ sprintf(
8164
+ __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
8165
+ $update->version,
8166
+ sprintf(
8167
+ '<a href="%s" target="_blank">%s</a>',
8168
+ $this->get_account_url( 'download_latest' ),
8169
+ sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
8170
+ )
8171
+ ),
8172
+ __fs( 'new', $this->_slug ) . '!'
8173
+ );
8174
+ }
8175
+ } else if ( false === $new_version && ! $background ) {
8176
+ $this->_admin_notices->add(
8177
+ __fs( 'you-have-latest', $this->_slug ),
8178
+ __fs( 'you-are-good', $this->_slug )
8179
+ );
8180
+ }
8181
+
8182
+ $this->_store_update( $update, true, $plugin_id );
8183
+ }
8184
+
8185
+ /**
8186
+ * @author Vova Feldman (@svovaf)
8187
+ * @since 1.0.4
8188
+ *
8189
+ * @param bool $flush Since 1.1.7.3 by default add 24 hour cache.
8190
+ *
8191
+ * @return FS_Plugin[]
8192
+ *
8193
+ * @uses FS_Api
8194
+ */
8195
+ private function _sync_addons( $flush = false ) {
8196
+ $this->_logger->entrance();
8197
+
8198
+ $result = $this->get_api_site_or_plugin_scope()->get( '/addons.json?enriched=true', $flush );
8199
+
8200
+ $addons = array();
8201
+ if ( ! $this->is_api_error( $result ) ) {
8202
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
8203
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
8204
+ }
8205
+
8206
+ $this->_store_addons( $addons, true );
8207
+ }
8208
+
8209
+ return $addons;
8210
+ }
8211
+
8212
+ /**
8213
+ * Handle user email update.
8214
+ *
8215
+ * @author Vova Feldman (@svovaf)
8216
+ * @since 1.0.3
8217
+ * @uses FS_Api
8218
+ *
8219
+ * @param string $new_email
8220
+ *
8221
+ * @return object
8222
+ */
8223
+ private function _update_email( $new_email ) {
8224
+ $this->_logger->entrance();
8225
+
8226
+
8227
+ $api = $this->get_api_user_scope();
8228
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
8229
+ 'email' => $new_email,
8230
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
8231
+ 'account',
8232
+ array( 'fs_action' => 'sync_user' )
8233
+ ),
8234
+ ) );
8235
+
8236
+ if ( ! isset( $user->error ) ) {
8237
+ $this->_user->email = $user->email;
8238
+ $this->_user->is_verified = $user->is_verified;
8239
+ $this->_store_user();
8240
+ } else {
8241
+ // handle different error cases.
8242
+
8243
+ }
8244
+
8245
+ return $user;
8246
+ }
8247
+
8248
+ /**
8249
+ * @author Vova Feldman (@svovaf)
8250
+ * @since 1.1.1
8251
+ *
8252
+ * @param mixed $result
8253
+ *
8254
+ * @return bool Is API result contains an error.
8255
+ */
8256
+ private function is_api_error( $result ) {
8257
+ return ( is_object( $result ) && isset( $result->error ) ) ||
8258
+ is_string( $result );
8259
+ }
8260
+
8261
+ /**
8262
+ * Start install ownership change.
8263
+ *
8264
+ * @author Vova Feldman (@svovaf)
8265
+ * @since 1.1.1
8266
+ * @uses FS_Api
8267
+ *
8268
+ * @param string $candidate_email
8269
+ *
8270
+ * @return bool Is ownership change successfully initiated.
8271
+ */
8272
+ private function init_change_owner( $candidate_email ) {
8273
+ $this->_logger->entrance();
8274
+
8275
+ $api = $this->get_api_site_scope();
8276
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
8277
+ 'email' => $candidate_email,
8278
+ 'after_confirm_url' => $this->_get_admin_page_url(
8279
+ 'account',
8280
+ array( 'fs_action' => 'change_owner' )
8281
+ ),
8282
+ ) );
8283
+
8284
+ return ! $this->is_api_error( $result );
8285
+ }
8286
+
8287
+ /**
8288
+ * Handle install ownership change.
8289
+ *
8290
+ * @author Vova Feldman (@svovaf)
8291
+ * @since 1.1.1
8292
+ * @uses FS_Api
8293
+ *
8294
+ * @return bool Was ownership change successfully complete.
8295
+ */
8296
+ private function complete_change_owner() {
8297
+ $this->_logger->entrance();
8298
+
8299
+ $site_result = $this->get_api_site_scope( true )->get();
8300
+ $site = new FS_Site( $site_result );
8301
+ $this->_site = $site;
8302
+
8303
+ $user = new FS_User();
8304
+ $user->id = fs_request_get( 'user_id' );
8305
+
8306
+ // Validate install's user and given user.
8307
+ if ( $user->id != $this->_site->user_id ) {
8308
+ return false;
8309
+ }
8310
+
8311
+ $user->public_key = fs_request_get( 'user_public_key' );
8312
+ $user->secret_key = fs_request_get( 'user_secret_key' );
8313
+
8314
+ // Fetch new user information.
8315
+ $this->_user = $user;
8316
+ $user_result = $this->get_api_user_scope( true )->get();
8317
+ $user = new FS_User( $user_result );
8318
+ $this->_user = $user;
8319
+
8320
+ $this->_set_account( $user, $site );
8321
+
8322
+ return true;
8323
+ }
8324
+
8325
+ /**
8326
+ * Handle user name update.
8327
+ *
8328
+ * @author Vova Feldman (@svovaf)
8329
+ * @since 1.0.9
8330
+ * @uses FS_Api
8331
+ *
8332
+ * @return object
8333
+ */
8334
+ private function update_user_name() {
8335
+ $this->_logger->entrance();
8336
+ $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
8337
+
8338
+ $api = $this->get_api_user_scope();
8339
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
8340
+ 'name' => $name,
8341
+ ) );
8342
+
8343
+ if ( ! isset( $user->error ) ) {
8344
+ $this->_user->first = $user->first;
8345
+ $this->_user->last = $user->last;
8346
+ $this->_store_user();
8347
+ } else {
8348
+ // handle different error cases.
8349
+
8350
+ }
8351
+
8352
+ return $user;
8353
+ }
8354
+
8355
+ /**
8356
+ * Verify user email.
8357
+ *
8358
+ * @author Vova Feldman (@svovaf)
8359
+ * @since 1.0.3
8360
+ * @uses FS_Api
8361
+ */
8362
+ private function verify_email() {
8363
+ $this->_handle_account_user_sync();
8364
+
8365
+ if ( $this->_user->is_verified() ) {
8366
+ return;
8367
+ }
8368
+
8369
+ $api = $this->get_api_site_scope();
8370
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
8371
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
8372
+ 'account',
8373
+ array( 'fs_action' => 'sync_user' )
8374
+ )
8375
+ ) );
8376
+
8377
+ if ( ! isset( $result->error ) ) {
8378
+ $this->_admin_notices->add( sprintf(
8379
+ __fs( 'verification-email-sent-message', $this->_slug ),
8380
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
8381
+ ) );
8382
+ } else {
8383
+ // handle different error cases.
8384
+
8385
+ }
8386
+ }
8387
+
8388
+ /**
8389
+ * @author Vova Feldman (@svovaf)
8390
+ * @since 1.1.2
8391
+ *
8392
+ * @return string
8393
+ */
8394
+ private function get_activation_url() {
8395
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url() );
8396
+ }
8397
+
8398
+ /**
8399
+ * Get the URL of the page that should be loaded after the user connect or skip in the opt-in screen.
8400
+ *
8401
+ * @author Vova Feldman (@svovaf)
8402
+ * @since 1.1.3
8403
+ *
8404
+ * @param string $filter Filter name.
8405
+ *
8406
+ * @return string
8407
+ */
8408
+ private function get_after_activation_url( $filter ) {
8409
+ $first_time_path = $this->_menu->get_first_time_path();
8410
+
8411
+ return $this->apply_filters(
8412
+ $filter,
8413
+ empty( $first_time_path ) ?
8414
+ $this->_get_admin_page_url() :
8415
+ $first_time_path
8416
+ );
8417
+ }
8418
+
8419
+ /**
8420
+ * Handle account page updates / edits / actions.
8421
+ *
8422
+ * @author Vova Feldman (@svovaf)
8423
+ * @since 1.0.2
8424
+ *
8425
+ */
8426
+ private function _handle_account_edits() {
8427
+ if ( ! current_user_can( 'activate_plugins' ) ) {
8428
+ return;
8429
+ }
8430
+
8431
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
8432
+ $action = fs_get_action();
8433
+
8434
+ switch ( $action ) {
8435
+ case 'delete_account':
8436
+ check_admin_referer( $action );
8437
+
8438
+ if ( $plugin_id == $this->get_id() ) {
8439
+ $this->delete_account_event();
8440
+
8441
+ // Clear user and site.
8442
+ $this->_site = null;
8443
+ $this->_user = null;
8444
+
8445
+ if ( fs_redirect( $this->get_activation_url() ) ) {
8446
+ exit();
8447
+ }
8448
+ } else {
8449
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8450
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8451
+ $fs_addon->delete_account_event();
8452
+
8453
+ if ( fs_redirect( $this->_get_admin_page_url( 'account' ) ) ) {
8454
+ exit();
8455
+ }
8456
+ }
8457
+ }
8458
+
8459
+ return;
8460
+
8461
+ case 'downgrade_account':
8462
+ check_admin_referer( $action );
8463
+ $this->_downgrade_site();
8464
+
8465
+ return;
8466
+
8467
+ case 'activate_license':
8468
+ check_admin_referer( $action );
8469
+
8470
+ if ( $plugin_id == $this->get_id() ) {
8471
+ $this->_activate_license();
8472
+ } else {
8473
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8474
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8475
+ $fs_addon->_activate_license();
8476
+ }
8477
+ }
8478
+
8479
+ return;
8480
+
8481
+ case 'deactivate_license':
8482
+ check_admin_referer( $action );
8483
+
8484
+ if ( $plugin_id == $this->get_id() ) {
8485
+ $this->_deactivate_license();
8486
+ } else {
8487
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8488
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8489
+ $fs_addon->_deactivate_license();
8490
+ }
8491
+ }
8492
+
8493
+ return;
8494
+
8495
+ case 'check_updates':
8496
+ check_admin_referer( $action );
8497
+ $this->_check_updates();
8498
+
8499
+ return;
8500
+
8501
+ case 'change_owner':
8502
+ $state = fs_request_get( 'state', 'init' );
8503
+ switch ( $state ) {
8504
+ case 'init':
8505
+ $candidate_email = fs_request_get( 'candidate_email', '' );
8506
+
8507
+ if ( $this->init_change_owner( $candidate_email ) ) {
8508
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
8509
+ }
8510
+ break;
8511
+ case 'owner_confirmed':
8512
+ $candidate_email = fs_request_get( 'candidate_email', '' );
8513
+
8514
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
8515
+ break;
8516
+ case 'candidate_confirmed':
8517
+ if ( $this->complete_change_owner() ) {
8518
+ $this->_admin_notices->add_sticky(
8519
+ sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
8520
+ 'ownership_changed',
8521
+ __fs( 'congrats', $this->_slug ) . '!'
8522
+ );
8523
+ } else {
8524
+ // @todo Handle failed ownership change message.
8525
+ }
8526
+ break;
8527
+ }
8528
+
8529
+ return;
8530
+
8531
+ case 'update_email':
8532
+ check_admin_referer( 'update_email' );
8533
+
8534
+ $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
8535
+ $result = $this->_update_email( $new_email );
8536
+
8537
+ if ( isset( $result->error ) ) {
8538
+ switch ( $result->error->code ) {
8539
+ case 'user_exist':
8540
+ $this->_admin_notices->add(
8541
+ __fs( 'user-exist-message', $this->_slug ) . ' ' .
8542
+ sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
8543
+ sprintf(
8544
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
8545
+ $this->get_account_url( 'change_owner', array(
8546
+ 'state' => 'init',
8547
+ 'candidate_email' => $new_email
8548
+ ) ),
8549
+ __fs( 'change-ownership', $this->_slug )
8550
+ ),
8551
+ __fs( 'oops', $this->_slug ) . '...',
8552
+ 'error'
8553
+ );
8554
+ break;
8555
+ }
8556
+ } else {
8557
+ $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
8558
+ }
8559
+
8560
+ return;
8561
+
8562
+ case 'update_user_name':
8563
+ check_admin_referer( 'update_user_name' );
8564
+
8565
+ $result = $this->update_user_name();
8566
+
8567
+ if ( isset( $result->error ) ) {
8568
+ $this->_admin_notices->add(
8569
+ __fs( 'name-update-failed-message', $this->_slug ),
8570
+ __fs( 'oops', $this->_slug ) . '...',
8571
+ 'error'
8572
+ );
8573
+ } else {
8574
+ $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
8575
+ }
8576
+
8577
+ return;
8578
+
8579
+ #region Actions that might be called from external links (e.g. email)
8580
+
8581
+ case 'cancel_trial':
8582
+ if ( $plugin_id == $this->get_id() ) {
8583
+ $this->_cancel_trial();
8584
+ } else {
8585
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8586
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8587
+ $fs_addon->_cancel_trial();
8588
+ }
8589
+ }
8590
+
8591
+ return;
8592
+
8593
+ case 'verify_email':
8594
+ $this->verify_email();
8595
+
8596
+ return;
8597
+
8598
+ case 'sync_user':
8599
+ $this->_handle_account_user_sync();
8600
+
8601
+ return;
8602
+
8603
+ case $this->_slug . '_sync_license':
8604
+ $this->_sync_license();
8605
+
8606
+ return;
8607
+
8608
+ case 'download_latest':
8609
+ $this->_download_latest_directly( $plugin_id );
8610
+
8611
+ return;
8612
+
8613
+ #endregion
8614
+ }
8615
+
8616
+ if ( WP_FS__IS_POST_REQUEST ) {
8617
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
8618
+ foreach ( $properties as $p ) {
8619
+ if ( 'update_' . $p === $action ) {
8620
+ check_admin_referer( $action );
8621
+
8622
+ $this->_logger->log( $action );
8623
+
8624
+ $site_property = substr( $p, strlen( 'site_' ) );
8625
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
8626
+ $this->get_site()->{$site_property} = $site_property_value;
8627
+
8628
+ // Store account after modification.
8629
+ $this->_store_site();
8630
+
8631
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
8632
+
8633
+ $this->_admin_notices->add( sprintf(
8634
+ __fs( 'x-updated', $this->_slug ),
8635
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
8636
+
8637
+ return;
8638
+ }
8639
+ }
8640
+ }
8641
+ }
8642
+
8643
+ /**
8644
+ * Account page resources load.
8645
+ *
8646
+ * @author Vova Feldman (@svovaf)
8647
+ * @since 1.0.6
8648
+ */
8649
+ function _account_page_load() {
8650
+ $this->_logger->entrance();
8651
+
8652
+ $this->_logger->info( var_export( $_REQUEST, true ) );
8653
+
8654
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
8655
+
8656
+ if ( $this->has_addons() ) {
8657
+ wp_enqueue_script( 'plugin-install' );
8658
+ add_thickbox();
8659
+
8660
+ function fs_addons_body_class( $classes ) {
8661
+ $classes .= ' plugins-php';
8662
+
8663
+ return $classes;
8664
+ }
8665
+
8666
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
8667
+ }
8668
+
8669
+ if ( $this->has_paid_plan() &&
8670
+ ! $this->has_any_license() &&
8671
+ ! $this->is_sync_executed()
8672
+ ) {
8673
+ /**
8674
+ * If no licenses found and no sync job was executed during the last 24 hours,
8675
+ * just execute the sync job right away (blocking execution).
8676
+ *
8677
+ * @since 1.1.7.3
8678
+ */
8679
+ $this->run_manual_sync();
8680
+ }
8681
+
8682
+ $this->_handle_account_edits();
8683
+
8684
+ $this->do_action( 'account_page_load_before_departure' );
8685
+ }
8686
+
8687
+ /**
8688
+ * Render account page.
8689
+ *
8690
+ * @author Vova Feldman (@svovaf)
8691
+ * @since 1.0.0
8692
+ */
8693
+ function _account_page_render() {
8694
+ $this->_logger->entrance();
8695
+
8696
+ $vars = array( 'slug' => $this->_slug );
8697
+ fs_require_once_template( 'account.php', $vars );
8698
+ }
8699
+
8700
+ /**
8701
+ * Render account connect page.
8702
+ *
8703
+ * @author Vova Feldman (@svovaf)
8704
+ * @since 1.0.7
8705
+ */
8706
+ function _connect_page_render() {
8707
+ $this->_logger->entrance();
8708
+
8709
+ $vars = array( 'slug' => $this->_slug );
8710
+ fs_require_once_template( 'connect.php', $vars );
8711
+ }
8712
+
8713
+ /**
8714
+ * Load required resources before add-ons page render.
8715
+ *
8716
+ * @author Vova Feldman (@svovaf)
8717
+ * @since 1.0.6
8718
+ */
8719
+ function _addons_page_load() {
8720
+ $this->_logger->entrance();
8721
+
8722
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
8723
+
8724
+ wp_enqueue_script( 'plugin-install' );
8725
+ add_thickbox();
8726
+
8727
+ function fs_addons_body_class( $classes ) {
8728
+ $classes .= ' plugins-php';
8729
+
8730
+ return $classes;
8731
+ }
8732
+
8733
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
8734
+
8735
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
8736
+ $this->_admin_notices->add(
8737
+ sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
8738
+ __fs( 'heads-up', $this->_slug ),
8739
+ 'update-nag'
8740
+ );
8741
+ }
8742
+ }
8743
+
8744
+ /**
8745
+ * Render add-ons page.
8746
+ *
8747
+ * @author Vova Feldman (@svovaf)
8748
+ * @since 1.0.6
8749
+ */
8750
+ function _addons_page_render() {
8751
+ $this->_logger->entrance();
8752
+
8753
+ $vars = array( 'slug' => $this->_slug );
8754
+ fs_require_once_template( 'add-ons.php', $vars );
8755
+ }
8756
+
8757
+ /* Pricing & Upgrade
8758
+ ------------------------------------------------------------------------------------------------------------------*/
8759
+ /**
8760
+ * Render pricing page.
8761
+ *
8762
+ * @author Vova Feldman (@svovaf)
8763
+ * @since 1.0.0
8764
+ */
8765
+ function _pricing_page_render() {
8766
+ $this->_logger->entrance();
8767
+
8768
+ $vars = array( 'slug' => $this->_slug );
8769
+
8770
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
8771
+ fs_require_once_template( 'checkout.php', $vars );
8772
+ } else {
8773
+ fs_require_once_template( 'pricing.php', $vars );
8774
+ }
8775
+ }
8776
+
8777
+ #region Contact Us ------------------------------------------------------------------
8778
+
8779
+ /**
8780
+ * Render contact-us page.
8781
+ *
8782
+ * @author Vova Feldman (@svovaf)
8783
+ * @since 1.0.3
8784
+ */
8785
+ function _contact_page_render() {
8786
+ $this->_logger->entrance();
8787
+
8788
+ $vars = array( 'slug' => $this->_slug );
8789
+ fs_require_once_template( 'contact.php', $vars );
8790
+ }
8791
+
8792
+ #endregion ------------------------------------------------------------------
8793
+
8794
+ /**
8795
+ * Hide all admin notices to prevent distractions.
8796
+ *
8797
+ * @author Vova Feldman (@svovaf)
8798
+ * @since 1.0.3
8799
+ *
8800
+ * @uses remove_all_actions()
8801
+ */
8802
+ private static function _hide_admin_notices() {
8803
+ remove_all_actions( 'admin_notices' );
8804
+ remove_all_actions( 'network_admin_notices' );
8805
+ remove_all_actions( 'all_admin_notices' );
8806
+ remove_all_actions( 'user_admin_notices' );
8807
+ }
8808
+
8809
+ static function _clean_admin_content_section_hook() {
8810
+ self::_hide_admin_notices();
8811
+
8812
+ // Hide footer.
8813
+ echo '<style>#wpfooter { display: none !important; }</style>';
8814
+ }
8815
+
8816
+ /**
8817
+ * Attach to admin_head hook to hide all admin notices.
8818
+ *
8819
+ * @author Vova Feldman (@svovaf)
8820
+ * @since 1.0.3
8821
+ */
8822
+ static function _clean_admin_content_section() {
8823
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
8824
+ }
8825
+
8826
+ /* CSS & JavaScript
8827
+ ------------------------------------------------------------------------------------------------------------------*/
8828
+ /* function _enqueue_script($handle, $src) {
8829
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
8830
+
8831
+ $this->_logger->entrance( 'script = ' . $url );
8832
+
8833
+ wp_enqueue_script( $handle, $url );
8834
+ }*/
8835
+
8836
+ /* SDK
8837
+ ------------------------------------------------------------------------------------------------------------------*/
8838
+ private $_user_api;
8839
+
8840
+ /**
8841
+ *
8842
+ * @author Vova Feldman (@svovaf)
8843
+ * @since 1.0.2
8844
+ *
8845
+ * @param bool $flush
8846
+ *
8847
+ * @return FS_Api
8848
+ */
8849
+ function get_api_user_scope( $flush = false ) {
8850
+ if ( ! isset( $this->_user_api ) || $flush ) {
8851
+ $this->_user_api = FS_Api::instance(
8852
+ $this->_slug,
8853
+ 'user',
8854
+ $this->_user->id,
8855
+ $this->_user->public_key,
8856
+ ! $this->is_live(),
8857
+ $this->_user->secret_key
8858
+ );
8859
+ }
8860
+
8861
+ return $this->_user_api;
8862
+ }
8863
+
8864
+ private $_site_api;
8865
+
8866
+ /**
8867
+ *
8868
+ * @author Vova Feldman (@svovaf)
8869
+ * @since 1.0.2
8870
+ *
8871
+ * @param bool $flush
8872
+ *
8873
+ * @return FS_Api
8874
+ */
8875
+ function get_api_site_scope( $flush = false ) {
8876
+ if ( ! isset( $this->_site_api ) || $flush ) {
8877
+ $this->_site_api = FS_Api::instance(
8878
+ $this->_slug,
8879
+ 'install',
8880
+ $this->_site->id,
8881
+ $this->_site->public_key,
8882
+ ! $this->is_live(),
8883
+ $this->_site->secret_key
8884
+ );
8885
+ }
8886
+
8887
+ return $this->_site_api;
8888
+ }
8889
+
8890
+ private $_plugin_api;
8891
+
8892
+ /**
8893
+ * Get plugin public API scope.
8894
+ *
8895
+ * @author Vova Feldman (@svovaf)
8896
+ * @since 1.0.7
8897
+ *
8898
+ * @return FS_Api
8899
+ */
8900
+ function get_api_plugin_scope() {
8901
+ if ( ! isset( $this->_plugin_api ) ) {
8902
+ $this->_plugin_api = FS_Api::instance(
8903
+ $this->_slug,
8904
+ 'plugin',
8905
+ $this->_plugin->id,
8906
+ $this->_plugin->public_key,
8907
+ ! $this->is_live()
8908
+ );
8909
+ }
8910
+
8911
+ return $this->_plugin_api;
8912
+ }
8913
+
8914
+ /**
8915
+ * Get site API scope object (fallback to public plugin scope when not registered).
8916
+ *
8917
+ * @author Vova Feldman (@svovaf)
8918
+ * @since 1.0.7
8919
+ *
8920
+ * @return FS_Api
8921
+ */
8922
+ function get_api_site_or_plugin_scope() {
8923
+ return $this->is_registered() ?
8924
+ $this->get_api_site_scope() :
8925
+ $this->get_api_plugin_scope();
8926
+ }
8927
+
8928
+ /**
8929
+ * Show trial promotional notice (if any trial exist).
8930
+ *
8931
+ * @author Vova Feldman (@svovaf)
8932
+ * @since 1.0.9
8933
+ *
8934
+ * @param $plans
8935
+ */
8936
+ function _check_for_trial_plans( $plans ) {
8937
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
8938
+ }
8939
+
8940
+ /**
8941
+ * Show trial promotional notice (if any trial exist).
8942
+ *
8943
+ * @author Vova Feldman (@svovaf)
8944
+ * @since 1.0.9
8945
+ */
8946
+ function _add_trial_notice() {
8947
+ // Check if trial already utilized.
8948
+ if ( $this->_site->is_trial_utilized() ) {
8949
+ return;
8950
+ }
8951
+
8952
+ // Check if already paying.
8953
+ if ( $this->is_paying() ) {
8954
+ return;
8955
+ }
8956
+
8957
+ // Check if trial message is already shown.
8958
+ if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
8959
+ return;
8960
+ }
8961
+
8962
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
8963
+ $trial_plans_count = count( $trial_plans );
8964
+
8965
+ // Check if any of the plans contains trial.
8966
+ if ( 0 === $trial_plans_count ) {
8967
+ return;
8968
+ }
8969
+
8970
+ /**
8971
+ * @var FS_Plugin_Plan $paid_plan
8972
+ */
8973
+ $paid_plan = $trial_plans[0];
8974
+ $require_subscription = $paid_plan->is_require_subscription;
8975
+ $upgrade_url = $this->get_trial_url();
8976
+ $cc_string = $require_subscription ?
8977
+ sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $paid_plan->trial_period ) :
8978
+ __fs( 'no-cc-required', $this->_slug ) . '!';
8979
+
8980
+
8981
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
8982
+
8983
+ if ( $total_paid_plans === $trial_plans_count ) {
8984
+ // All paid plans have trials.
8985
+ $message = sprintf(
8986
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
8987
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
8988
+ strtolower( __fs( 'awesome', $this->_slug ) ),
8989
+ $paid_plan->trial_period
8990
+ );
8991
+ } else {
8992
+ $plans_string = '';
8993
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
8994
+ $plans_string .= sprintf( '<a href="%s">%s</a>', $upgrade_url, $trial_plans[ $i ]->title );
8995
+
8996
+ if ( $i < $trial_plans_count - 2 ) {
8997
+ $plans_string .= ', ';
8998
+ } else if ( $i == $trial_plans_count - 2 ) {
8999
+ $plans_string .= ' and ';
9000
+ }
9001
+ }
9002
+
9003
+ // Not all paid plans have trials.
9004
+ $message = sprintf(
9005
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9006
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9007
+ $plans_string,
9008
+ $paid_plan->trial_period
9009
+ );
9010
+ }
9011
+
9012
+ $message .= ' ' . $cc_string;
9013
+
9014
+ // Add start trial button.
9015
+ $message .= ' ' . sprintf(
9016
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9017
+ $upgrade_url,
9018
+ __fs( 'start-free-trial', $this->_slug )
9019
+ );
9020
+
9021
+ $this->_admin_notices->add_sticky(
9022
+ $this->apply_filters( 'trial_promotion_message', $message ),
9023
+ 'trial_promotion',
9024
+ '',
9025
+ 'promotion'
9026
+ );
9027
+
9028
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
9029
+ }
9030
+
9031
+ /* Action Links
9032
+ ------------------------------------------------------------------------------------------------------------------*/
9033
+ private $_action_links_hooked = false;
9034
+ private $_action_links = array();
9035
+
9036
+ /**
9037
+ * @author Vova Feldman (@svovaf)
9038
+ * @since 1.0.0
9039
+ *
9040
+ * @return bool
9041
+ */
9042
+ private function is_plugin_action_links_hooked() {
9043
+ $this->_logger->entrance( json_encode( $this->_action_links_hooked ) );
9044
+
9045
+ return $this->_action_links_hooked;
9046
+ }
9047
+
9048
+ /**
9049
+ * Hook to plugin action links filter.
9050
+ *
9051
+ * @author Vova Feldman (@svovaf)
9052
+ * @since 1.0.0
9053
+ */
9054
+ private function hook_plugin_action_links() {
9055
+ $this->_logger->entrance();
9056
+
9057
+ $this->_action_links_hooked = true;
9058
+
9059
+ $this->_logger->log( 'Adding action links hooks.' );
9060
+
9061
+ // Add action link to settings page.
9062
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
9063
+ &$this,
9064
+ '_modify_plugin_action_links_hook'
9065
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9066
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
9067
+ &$this,
9068
+ '_modify_plugin_action_links_hook'
9069
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9070
+ }
9071
+
9072
+ /**
9073
+ * Add plugin action link.
9074
+ *
9075
+ * @author Vova Feldman (@svovaf)
9076
+ * @since 1.0.0
9077
+ *
9078
+ * @param $label
9079
+ * @param $url
9080
+ * @param bool $external
9081
+ * @param int $priority
9082
+ * @param bool $key
9083
+ */
9084
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
9085
+ $this->_logger->entrance();
9086
+
9087
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
9088
+ $this->_action_links[ $priority ] = array();
9089
+ }
9090
+
9091
+ if ( false === $key ) {
9092
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
9093
+ }
9094
+
9095
+ $this->_action_links[ $priority ][] = array(
9096
+ 'label' => $label,
9097
+ 'href' => $url,
9098
+ 'key' => $key,
9099
+ 'external' => $external
9100
+ );
9101
+ }
9102
+
9103
+ /**
9104
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
9105
+ *
9106
+ * @author Vova Feldman (@svovaf)
9107
+ * @since 1.0.0
9108
+ */
9109
+ function _add_upgrade_action_link() {
9110
+ $this->_logger->entrance();
9111
+
9112
+ if ( $this->is_registered() ) {
9113
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
9114
+ $this->add_plugin_action_link(
9115
+ __fs( 'upgrade', $this->_slug ),
9116
+ $this->get_upgrade_url(),
9117
+ false,
9118
+ 7,
9119
+ 'upgrade'
9120
+ );
9121
+ }
9122
+
9123
+ if ( $this->has_addons() ) {
9124
+ $this->add_plugin_action_link(
9125
+ __fs( 'add-ons', $this->_slug ),
9126
+ $this->_get_admin_page_url( 'addons' ),
9127
+ false,
9128
+ 9,
9129
+ 'addons'
9130
+ );
9131
+ }
9132
+ }
9133
+ }
9134
+
9135
+ /**
9136
+ * Get the URL of the page that should be loaded right after the plugin activation.
9137
+ *
9138
+ * @author Vova Feldman (@svovaf)
9139
+ * @since 1.1.7.4
9140
+ *
9141
+ * @return string
9142
+ */
9143
+ function get_after_plugin_activation_redirect_url() {
9144
+ $url = false;
9145
+ $plugin_fs = false;
9146
+
9147
+ if ( ! $this->is_addon() ) {
9148
+ $first_time_path = $this->_menu->get_first_time_path();
9149
+ $plugin_fs = $this;
9150
+ $url = $plugin_fs->is_activation_mode() ?
9151
+ $plugin_fs->get_activation_url() :
9152
+ ( empty( $first_time_path ) ?
9153
+ $this->_get_admin_page_url() :
9154
+ $first_time_path );
9155
+ } else {
9156
+ if ( $this->is_parent_plugin_installed() ) {
9157
+ $plugin_fs = self::get_parent_instance();
9158
+ }
9159
+
9160
+ if ( is_object( $plugin_fs ) ) {
9161
+ if ( ! $plugin_fs->is_registered() ) {
9162
+ // Forward to parent plugin connect when parent not registered.
9163
+ $url = $plugin_fs->get_activation_url();
9164
+ } else {
9165
+ // Forward to account page.
9166
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
9167
+ }
9168
+ }
9169
+ }
9170
+
9171
+ return $url;
9172
+ }
9173
+
9174
+ /**
9175
+ * Forward page to activation page.
9176
+ *
9177
+ * @author Vova Feldman (@svovaf)
9178
+ * @since 1.0.3
9179
+ */
9180
+ function _redirect_on_activation_hook() {
9181
+ $url = $this->get_after_plugin_activation_redirect_url();
9182
+
9183
+ if ( is_string( $url ) ) {
9184
+ fs_redirect( $url );
9185
+ exit();
9186
+ }
9187
+ }
9188
+
9189
+ /**
9190
+ * Modify plugin's page action links collection.
9191
+ *
9192
+ * @author Vova Feldman (@svovaf)
9193
+ * @since 1.0.0
9194
+ *
9195
+ * @param array $links
9196
+ * @param $file
9197
+ *
9198
+ * @return array
9199
+ */
9200
+ function _modify_plugin_action_links_hook( $links, $file ) {
9201
+ $this->_logger->entrance();
9202
+
9203
+ $passed_deactivate = false;
9204
+ $deactivate_link = '';
9205
+ $before_deactivate = array();
9206
+ $after_deactivate = array();
9207
+ foreach ( $links as $key => $link ) {
9208
+ if ( 'deactivate' === $key ) {
9209
+ $deactivate_link = $link;
9210
+ $passed_deactivate = true;
9211
+ continue;
9212
+ }
9213
+
9214
+ if ( ! $passed_deactivate ) {
9215
+ $before_deactivate[ $key ] = $link;
9216
+ } else {
9217
+ $after_deactivate[ $key ] = $link;
9218
+ }
9219
+ }
9220
+
9221
+ ksort( $this->_action_links );
9222
+
9223
+ foreach ( $this->_action_links as $new_links ) {
9224
+ foreach ( $new_links as $link ) {
9225
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
9226
+ }
9227
+ }
9228
+
9229
+ if ( ! empty( $deactivate_link ) ) {
9230
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
9231
+ /*
9232
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
9233
+ *
9234
+ * If user is paying or in trial and have the free version installed,
9235
+ * assume that the deactivation is for the upgrade process, so this is not needed.
9236
+ */
9237
+ $deactivate_link .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
9238
+ }
9239
+
9240
+ // Append deactivation link.
9241
+ $before_deactivate['deactivate'] = $deactivate_link;
9242
+ }
9243
+
9244
+ return array_merge( $before_deactivate, $after_deactivate );
9245
+ }
9246
+
9247
+ /**
9248
+ * Adds admin message.
9249
+ *
9250
+ * @author Vova Feldman (@svovaf)
9251
+ * @since 1.0.4
9252
+ *
9253
+ * @param string $message
9254
+ * @param string $title
9255
+ * @param string $type
9256
+ */
9257
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
9258
+ $this->_admin_notices->add( $message, $title, $type );
9259
+ }
9260
+
9261
+ /**
9262
+ * Adds sticky admin message.
9263
+ *
9264
+ * @author Vova Feldman (@svovaf)
9265
+ * @since 1.1.0
9266
+ *
9267
+ * @param string $message
9268
+ * @param string $id
9269
+ * @param string $title
9270
+ * @param string $type
9271
+ */
9272
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
9273
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
9274
+ }
9275
+
9276
+ /* Plugin Auto-Updates (@since 1.0.4)
9277
+ ------------------------------------------------------------------------------------------------------------------*/
9278
+ /**
9279
+ * @var string[]
9280
+ */
9281
+ private static $_auto_updated_plugins;
9282
+
9283
+ /**
9284
+ * @todo TEST IF IT WORKS!!!
9285
+ *
9286
+ * Include plugins for automatic updates based on stored settings.
9287
+ *
9288
+ * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
9289
+ *
9290
+ * @author Vova Feldman (@svovaf)
9291
+ * @since 1.0.4
9292
+ *
9293
+ * @param bool $update Whether to update (not used for plugins)
9294
+ * @param object $item The plugin's info
9295
+ *
9296
+ * @return bool
9297
+ */
9298
+ static function _include_plugins_in_auto_update( $update, $item ) {
9299
+ // Before version 3.8.2 the $item was the file name of the plugin,
9300
+ // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
9301
+ $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
9302
+
9303
+ if ( ! isset( self::$_auto_updated_plugins ) ) {
9304
+ $plugins = self::$_accounts->get_option( 'plugins', array() );
9305
+
9306
+ $identifiers = array();
9307
+ foreach ( $plugins as $p ) {
9308
+ /**
9309
+ * @var FS_Plugin $p
9310
+ */
9311
+ if ( isset( $p->auto_update ) && $p->auto_update ) {
9312
+ $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
9313
+ }
9314
+ }
9315
+
9316
+ self::$_auto_updated_plugins = $identifiers;
9317
+ }
9318
+
9319
+ if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
9320
+ return true;
9321
+ }
9322
+
9323
+ // Pass update decision to next filters
9324
+ return $update;
9325
+ }
9326
+
9327
+ #region Versioning ------------------------------------------------------------------
9328
+
9329
+ /**
9330
+ * Check if Freemius in SDK upgrade mode.
9331
+ *
9332
+ * @author Vova Feldman (@svovaf)
9333
+ * @since 1.0.9
9334
+ *
9335
+ * @return bool
9336
+ */
9337
+ function is_sdk_upgrade_mode() {
9338
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
9339
+ $this->_storage->sdk_upgrade_mode :
9340
+ false;
9341
+ }
9342
+
9343
+ /**
9344
+ * Turn SDK upgrade mode off.
9345
+ *
9346
+ * @author Vova Feldman (@svovaf)
9347
+ * @since 1.0.9
9348
+ *
9349
+ * @return bool
9350
+ */
9351
+ function set_sdk_upgrade_complete() {
9352
+ $this->_storage->sdk_upgrade_mode = false;
9353
+ }
9354
+
9355
+ /**
9356
+ * Check if plugin upgrade mode.
9357
+ *
9358
+ * @author Vova Feldman (@svovaf)
9359
+ * @since 1.0.9
9360
+ *
9361
+ * @return bool
9362
+ */
9363
+ function is_plugin_upgrade_mode() {
9364
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
9365
+ $this->_storage->plugin_upgrade_mode :
9366
+ false;
9367
+ }
9368
+
9369
+ /**
9370
+ * Turn plugin upgrade mode off.
9371
+ *
9372
+ * @author Vova Feldman (@svovaf)
9373
+ * @since 1.0.9
9374
+ *
9375
+ * @return bool
9376
+ */
9377
+ function set_plugin_upgrade_complete() {
9378
+ $this->_storage->plugin_upgrade_mode = false;
9379
+ }
9380
+
9381
+ #endregion ------------------------------------------------------------------
9382
+
9383
+ #region Permissions ------------------------------------------------------------------
9384
+
9385
+ /**
9386
+ * Check if specific permission requested.
9387
+ *
9388
+ * @author Vova Feldman (@svovaf)
9389
+ * @since 1.1.6
9390
+ *
9391
+ * @param string $permission
9392
+ *
9393
+ * @return bool
9394
+ */
9395
+ function is_permission_requested( $permission ) {
9396
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
9397
+ }
9398
+
9399
+ #endregion Permissions ------------------------------------------------------------------
9400
+
9401
+ #region Marketing ------------------------------------------------------------------
9402
+
9403
+ /**
9404
+ * Check if current user purchased any other plugins before.
9405
+ *
9406
+ * @author Vova Feldman (@svovaf)
9407
+ * @since 1.0.9
9408
+ *
9409
+ * @return bool
9410
+ */
9411
+ function has_purchased_before() {
9412
+ // TODO: Implement has_purchased_before() method.
9413
+ }
9414
+
9415
+ /**
9416
+ * Check if current user classified as an agency.
9417
+ *
9418
+ * @author Vova Feldman (@svovaf)
9419
+ * @since 1.0.9
9420
+ *
9421
+ * @return bool
9422
+ */
9423
+ function is_agency() {
9424
+ // TODO: Implement is_agency() method.
9425
+ }
9426
+
9427
+ /**
9428
+ * Check if current user classified as a developer.
9429
+ *
9430
+ * @author Vova Feldman (@svovaf)
9431
+ * @since 1.0.9
9432
+ *
9433
+ * @return bool
9434
+ */
9435
+ function is_developer() {
9436
+ // TODO: Implement is_developer() method.
9437
+ }
9438
+
9439
+ /**
9440
+ * Check if current user classified as a business.
9441
+ *
9442
+ * @author Vova Feldman (@svovaf)
9443
+ * @since 1.0.9
9444
+ *
9445
+ * @return bool
9446
+ */
9447
+ function is_business() {
9448
+ // TODO: Implement is_business() method.
9449
+ }
9450
+
9451
+ #endregion ------------------------------------------------------------------
9452
+ }
freemius/includes/class-fs-api.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.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( $method . ':' . $path );
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( $path );
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, please retry in ' . ( self::$_cache->get_record_expiration( 'ping_test' ) - WP_FS__SCRIPT_START_TIME ) . ' sec.',
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 array $params
354
+ *
355
+ * @return object
356
+ */
357
+ function ping( $unique_anonymous_id = null, $params = array() ) {
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_merge(
367
+ array( 'uid' => $unique_anonymous_id ),
368
+ $params
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_merge(
384
+ array( 'uid' => $unique_anonymous_id ),
385
+ $params
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
+ 'maintenance_mode',
419
+ 'squid_cache_block',
420
+ 'too_many_requests',
421
+ ) ) );
422
+
423
+ }
424
+
425
+ /**
426
+ * Check if valid ping request result.
427
+ *
428
+ * @author Vova Feldman (@svovaf)
429
+ * @since 1.1.1
430
+ *
431
+ * @param mixed $pong
432
+ *
433
+ * @return bool
434
+ */
435
+ function is_valid_ping( $pong ) {
436
+ return Freemius_Api::Test( $pong );
437
+ }
438
+
439
+ function get_url( $path = '' ) {
440
+ return Freemius_Api::GetUrl( $path, $this->_api->IsSandbox() );
441
+ }
442
+
443
+ /**
444
+ * Clear API cache.
445
+ *
446
+ * @author Vova Feldman (@svovaf)
447
+ * @since 1.0.9
448
+ */
449
+ static function clear_cache() {
450
+ self::_init();
451
+
452
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
453
+ self::$_cache->clear( true );
454
+ }
455
+ }
freemius/includes/class-fs-logger.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ function get_id() {
90
+ return $this->_id;
91
+ }
92
+
93
+ function get_file() {
94
+ return $this->_file_start;
95
+ }
96
+
97
+ private function _log( &$message, $type = 'log', $wrapper ) {
98
+ if ( ! $this->is_on() ) {
99
+ return;
100
+ }
101
+
102
+ $bt = debug_backtrace();
103
+ $depth = $wrapper ? 3 : 2;
104
+ while ( $depth < count( $bt ) - 1 && 'eval' === $bt[ $depth ]['function'] ) {
105
+ $depth ++;
106
+ }
107
+
108
+ $caller = $bt[ $depth ];
109
+
110
+ $log = array_merge( $caller, array(
111
+ 'cnt' => self::$CNT ++,
112
+ 'logger' => $this,
113
+ 'timestamp' => microtime(true),
114
+ 'type' => $type,
115
+ 'msg' => $message,
116
+ ) );
117
+
118
+ self::$LOG[] = $log;
119
+
120
+ if ( $this->is_echo_on() ) {
121
+ echo self::format_html( $log ) . "\n";
122
+ }
123
+ }
124
+
125
+ function log( $message, $wrapper = false ) {
126
+ $this->_log( $message, 'log', $wrapper );
127
+ }
128
+
129
+ function info( $message, $wrapper = false ) {
130
+ $this->_log( $message, 'info', $wrapper );
131
+ }
132
+
133
+ function warn( $message, $wrapper = false ) {
134
+ $this->_log( $message, 'warn', $wrapper );
135
+ }
136
+
137
+ function error( $message, $wrapper = false ) {
138
+ $this->_log( $message, 'error', $wrapper );
139
+ }
140
+
141
+ function entrance( $message = '', $wrapper = false ) {
142
+ $msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;
143
+
144
+ $this->_log( $msg, 'log', $wrapper );
145
+ }
146
+
147
+ function departure( $message = '', $wrapper = false ) {
148
+ $msg = 'Departure' . ( empty( $message ) ? '' : ' > ' ) . $message;
149
+
150
+ $this->_log( $msg, 'log', $wrapper );
151
+ }
152
+
153
+ private static function format( $log, $show_type = true ) {
154
+ 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'] . ']';
155
+ }
156
+
157
+ private static function format_html( $log ) {
158
+ 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>';
159
+ }
160
+
161
+ static function dump() {
162
+ ?>
163
+ <!-- BEGIN: Freemius PHP Console Log -->
164
+ <script type="text/javascript">
165
+ <?php
166
+ foreach (self::$LOG as $log)
167
+ {
168
+ echo 'console.' . $log['type'] . '(' . json_encode(self::format($log, false)) . ')' . "\n";
169
+ }
170
+ ?>
171
+ </script>
172
+ <!-- END: Freemius PHP Console Log -->
173
+ <?php
174
+ }
175
+
176
+ static function get_log() {
177
+ return self::$LOG;
178
+ }
179
+ }
freemius/includes/class-fs-plugin-updater.php ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @var object
32
+ * @since 1.1.8.1
33
+ */
34
+ private $_update_details;
35
+
36
+ function __construct( Freemius $freemius ) {
37
+ $this->_fs = $freemius;
38
+
39
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $freemius->get_slug() . '_updater', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
40
+
41
+ $this->_filters();
42
+ }
43
+
44
+ /**
45
+ * Initiate required filters.
46
+ *
47
+ * @author Vova Feldman (@svovaf)
48
+ * @since 1.0.4
49
+ */
50
+ private function _filters() {
51
+ // Override request for plugin information
52
+ add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
53
+
54
+ // WP 3.0+
55
+ add_filter( 'pre_set_site_transient_update_plugins', array(
56
+ &$this,
57
+ 'pre_set_site_transient_update_plugins_filter'
58
+ ) );
59
+
60
+ if ( ! $this->_fs->has_active_license() ) {
61
+ /**
62
+ * If user has the premium plugin's code but do NOT have an active license,
63
+ * encourage him to upgrade by showing that there's a new release, but instead
64
+ * of showing an update link, show upgrade link to the pricing page.
65
+ *
66
+ * @since 1.1.6
67
+ *
68
+ */
69
+ // WP 2.9+
70
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
71
+ &$this,
72
+ 'catch_plugin_update_row'
73
+ ), 9 );
74
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
75
+ &$this,
76
+ 'edit_and_echo_plugin_update_row'
77
+ ), 11, 2 );
78
+ }
79
+
80
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
81
+ add_filter( 'http_request_host_is_external', array(
82
+ $this,
83
+ 'http_request_host_is_external_filter'
84
+ ), 10, 3 );
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Capture plugin update row by turning output buffering.
90
+ *
91
+ * @author Vova Feldman (@svovaf)
92
+ * @since 1.1.6
93
+ */
94
+ function catch_plugin_update_row() {
95
+ ob_start();
96
+ }
97
+
98
+ /**
99
+ * Overrides default update message format with "renew your license" message.
100
+ *
101
+ * @author Vova Feldman (@svovaf)
102
+ * @since 1.1.6
103
+ */
104
+ function edit_and_echo_plugin_update_row( $file, $plugin_data ) {
105
+ $plugin_update_row = ob_get_clean();
106
+
107
+ $current = get_site_transient( 'update_plugins' );
108
+ if ( ! isset( $current->response[ $file ] ) ) {
109
+ echo $plugin_update_row;
110
+
111
+ return false;
112
+ }
113
+
114
+ $r = $current->response[ $file ];
115
+
116
+ $plugin_update_row = preg_replace(
117
+ '/(\<div.+>)(.+)(\<a.+\<a.+)\<\/div\>/is',
118
+ '$1 $2 ' . sprintf(
119
+ __fs( 'renew-license-now' ),
120
+ '<a href="' . $this->_fs->pricing_url() . '">', '</a>',
121
+ $r->new_version ) .
122
+ '$4',
123
+ $plugin_update_row
124
+ );
125
+
126
+ echo $plugin_update_row;
127
+ }
128
+
129
+ /**
130
+ * Since WP version 3.6, a new security feature was added that denies access to repository with a local ip.
131
+ * During development mode we want to be able updating plugin versions via our localhost repository. This
132
+ * filter white-list all domains including "api.freemius".
133
+ *
134
+ * @link http://www.emanueletessore.com/wordpress-download-failed-valid-url-provided/
135
+ *
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.4
138
+ *
139
+ * @param bool $allow
140
+ * @param string $host
141
+ * @param string $url
142
+ *
143
+ * @return bool
144
+ */
145
+ function http_request_host_is_external_filter( $allow, $host, $url ) {
146
+ return ( false !== strpos( $host, 'freemius' ) ) ? true : $allow;
147
+ }
148
+
149
+ /**
150
+ * Check for Updates at the defined API endpoint and modify the update array.
151
+ *
152
+ * This function dives into the update api just when WordPress creates its update array,
153
+ * then adds a custom API call and injects the custom plugin data retrieved from the API.
154
+ * It is reassembled from parts of the native WordPress plugin update code.
155
+ * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
156
+ *
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.0.4
159
+ *
160
+ * @uses FS_Api
161
+ *
162
+ * @param stdClass $transient_data Update array build by WordPress.
163
+ *
164
+ * @return array Modified update array with custom plugin data.
165
+ */
166
+ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
167
+ $this->_logger->entrance();
168
+
169
+ if ( empty( $transient_data ) ||
170
+ defined( 'WP_FS__UNINSTALL_MODE' )
171
+ ) {
172
+ return $transient_data;
173
+ }
174
+
175
+ if ( ! isset( $this->_update_details ) ) {
176
+ // Get plugin's newest update.
177
+ $new_version = $this->_fs->get_update( false, false );
178
+
179
+ $this->_update_details = false;
180
+
181
+ if ( is_object( $new_version ) ) {
182
+ $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
183
+
184
+ $plugin_details = new stdClass();
185
+ $plugin_details->slug = $this->_fs->get_slug();
186
+ $plugin_details->new_version = $new_version->version;
187
+ $plugin_details->url = WP_FS__ADDRESS;
188
+ $plugin_details->package = $new_version->url;
189
+ $plugin_details->plugin = $this->_fs->get_plugin_basename();
190
+
191
+ /**
192
+ * Cache plugin details locally since set_site_transient( 'update_plugins' )
193
+ * called multiple times and the non wp.org plugins are filtered after the
194
+ * call to .org.
195
+ *
196
+ * @since 1.1.8.1
197
+ */
198
+ $this->_update_details = $plugin_details;
199
+ }
200
+ }
201
+
202
+ if ( is_object( $this->_update_details ) ) {
203
+ // Add plugin to transient data.
204
+ $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_update_details;
205
+ }
206
+
207
+ return $transient_data;
208
+ }
209
+
210
+ /**
211
+ * Try to fetch plugin's info from .org repository.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.0.5
215
+ *
216
+ * @param string $action
217
+ * @param object $args
218
+ *
219
+ * @return bool|mixed
220
+ */
221
+ static function _fetch_plugin_info_from_repository( $action, $args ) {
222
+ $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
223
+ if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
224
+ $url = set_url_scheme( $url, 'https' );
225
+ }
226
+
227
+ $args = array(
228
+ 'timeout' => 15,
229
+ 'body' => array(
230
+ 'action' => $action,
231
+ 'request' => serialize( $args )
232
+ )
233
+ );
234
+
235
+ $request = wp_remote_post( $url, $args );
236
+
237
+ if ( is_wp_error( $request ) ) {
238
+ return false;
239
+ }
240
+
241
+ $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
242
+
243
+ if ( ! is_object( $res ) && ! is_array( $res ) ) {
244
+ return false;
245
+ }
246
+
247
+ return $res;
248
+ }
249
+
250
+ /**
251
+ * Updates information on the "View version x.x details" page with custom data.
252
+ *
253
+ * @author Vova Feldman (@svovaf)
254
+ * @since 1.0.4
255
+ *
256
+ * @uses FS_Api
257
+ *
258
+ * @param object $data
259
+ * @param string $action
260
+ * @param mixed $args
261
+ *
262
+ * @return object
263
+ */
264
+ function plugins_api_filter( $data, $action = '', $args = null ) {
265
+ $this->_logger->entrance();
266
+
267
+ if ( ( 'plugin_information' !== $action ) ||
268
+ ! isset( $args->slug )
269
+ ) {
270
+ return $data;
271
+ }
272
+
273
+ $addon = false;
274
+ $is_addon = false;
275
+
276
+ if ( $this->_fs->get_slug() !== $args->slug ) {
277
+ $addon = $this->_fs->get_addon_by_slug( $args->slug );
278
+
279
+ if ( ! is_object( $addon ) ) {
280
+ return $data;
281
+ }
282
+
283
+ $is_addon = true;
284
+ }
285
+
286
+ $plugin_in_repo = false;
287
+ if ( ! $is_addon ) {
288
+ // Try to fetch info from .org repository.
289
+ $data = self::_fetch_plugin_info_from_repository( $action, $args );
290
+
291
+ $plugin_in_repo = ( false !== $data );
292
+ }
293
+
294
+ if ( ! $plugin_in_repo ) {
295
+ $data = $args;
296
+
297
+ // Fetch as much as possible info from local files.
298
+ $plugin_local_data = $this->_fs->get_plugin_data();
299
+ $data->name = $plugin_local_data['Name'];
300
+ $data->author = $plugin_local_data['Author'];
301
+ $data->sections = array(
302
+ 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
303
+ );
304
+
305
+ // @todo Store extra plugin info on Freemius or parse readme.txt markup.
306
+ /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
307
+
308
+ if ( !isset($info->error) ) {
309
+ $data = $info;
310
+ }*/
311
+ }
312
+
313
+ // Get plugin's newest update.
314
+ $new_version = $this->_fs->_fetch_latest_version( $is_addon ? $addon->id : false );
315
+
316
+ if ( $is_addon ) {
317
+ $data->name = $addon->title . ' ' . __fs( 'addon', $this->_fs->get_slug() );
318
+ $data->slug = $addon->slug;
319
+ $data->url = WP_FS__ADDRESS;
320
+ $data->package = $new_version->url;
321
+ }
322
+
323
+ if ( ! $plugin_in_repo ) {
324
+ $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
325
+ $data->requires = $new_version->requires_platform_version;
326
+ $data->tested = $new_version->tested_up_to_version;
327
+ }
328
+
329
+ $data->version = $new_version->version;
330
+ $data->download_link = $new_version->url;
331
+
332
+ return $data;
333
+ }
334
+ }
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/debug/class-fs-debug-bar-panel.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Extends Debug Bar plugin by adding a panel to show all Freemius API requests.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.3
18
+ *
19
+ * Class Freemius_Debug_Bar_Panel
20
+ */
21
+ class Freemius_Debug_Bar_Panel extends Debug_Bar_Panel {
22
+ function init() {
23
+ $this->title( 'Freemius' );
24
+ }
25
+
26
+ static function requests_count() {
27
+ if ( class_exists( 'Freemius_Api' ) ) {
28
+ $logger = Freemius_Api::GetLogger();
29
+ } else {
30
+ $logger = array();
31
+ }
32
+
33
+ return number_format( count( $logger ) );
34
+ }
35
+
36
+ static function total_time() {
37
+ if ( class_exists( 'Freemius_Api' ) ) {
38
+ $logger = Freemius_Api::GetLogger();
39
+ } else {
40
+ $logger = array();
41
+ }
42
+
43
+ $total_time = .0;
44
+ foreach ( $logger as $l ) {
45
+ $total_time += $l['total'];
46
+ }
47
+
48
+ return number_format( 100 * $total_time, 2 ) . ' ' . __fs( 'ms' );
49
+ }
50
+
51
+ function render() {
52
+ ?>
53
+ <div id='debug-bar-php'>
54
+ <?php fs_require_template( '/debug/api-calls.php' ) ?>
55
+ <br>
56
+ <?php fs_require_template( '/debug/scheduled-crons.php' ) ?>
57
+ <br>
58
+ <?php fs_require_template( '/debug/plugins-themes-sync.php' ) ?>
59
+ <br>
60
+ <?php fs_require_template( '/debug/logger.php' ) ?>
61
+ </div>
62
+ <?php
63
+ }
64
+ }
freemius/includes/debug/debug-bar-start.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! WP_FS__DEBUG_SDK ) {
14
+ return;
15
+ }
16
+
17
+ /**
18
+ * Initialize Freemius custom debug panels.
19
+ *
20
+ * @param array $panels Debug bar panels objects
21
+ *
22
+ * @return array Debug bar panels with your custom panels
23
+ */
24
+ function fs_custom_panels_init( $panels ) {
25
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
26
+ if ( FS_API__LOGGER_ON ) {
27
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
28
+ $panels[] = new Freemius_Debug_Bar_Panel();
29
+ }
30
+ }
31
+
32
+ return $panels;
33
+ }
34
+
35
+ function fs_custom_status_init( $statuses ) {
36
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
37
+ if ( FS_API__LOGGER_ON ) {
38
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
39
+ $statuses[] = array(
40
+ 'fs_api_requests',
41
+ __fs( 'Freemius API' ),
42
+ Freemius_Debug_Bar_Panel::requests_count() . ' ' . __fs( 'Requests' ) .
43
+ ' (' . Freemius_Debug_Bar_Panel::total_time() . ')'
44
+ );
45
+ }
46
+ }
47
+
48
+ return $statuses;
49
+ }
50
+
51
+ add_filter( 'debug_bar_panels', 'fs_custom_panels_init' );
52
+ add_filter( 'debug_bar_statuses', 'fs_custom_status_init' );
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,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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|null
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
+ * Check if single site license.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.8.1
98
+ *
99
+ * @return bool
100
+ */
101
+ function is_single_site() {
102
+ return ( is_numeric( $this->quota ) && 1 == $this->quota );
103
+ }
104
+
105
+ /**
106
+ * @author Vova Feldman (@svovaf)
107
+ * @since 1.0.5
108
+ *
109
+ * @return bool
110
+ */
111
+ function is_expired() {
112
+ return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
113
+ }
114
+
115
+ /**
116
+ * @author Vova Feldman (@svovaf)
117
+ * @since 1.0.6
118
+ *
119
+ * @return bool
120
+ */
121
+ function is_lifetime() {
122
+ return is_null( $this->expiration );
123
+ }
124
+
125
+ /**
126
+ * Check if license is fully utilized.
127
+ *
128
+ * @author Vova Feldman (@svovaf)
129
+ * @since 1.0.6
130
+ *
131
+ * @param bool $is_localhost
132
+ *
133
+ * @return bool
134
+ */
135
+ function is_utilized( $is_localhost = null ) {
136
+ if ( is_null( $is_localhost ) ) {
137
+ $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
138
+ }
139
+
140
+ return ! ( $this->is_free_localhost && $is_localhost ) &&
141
+ ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
142
+ }
143
+
144
+ /**
145
+ * Check if license's plan features are enabled.
146
+ *
147
+ * - Either if plan not expired
148
+ * - If expired, based on the configuration to block features or not.
149
+ *
150
+ * @author Vova Feldman (@svovaf)
151
+ * @since 1.0.6
152
+ *
153
+ * @return bool
154
+ */
155
+ function is_features_enabled() {
156
+ return ( ! $this->is_block_features || ! $this->is_expired() );
157
+ }
158
+
159
+ /**
160
+ * Subscription considered to be new without any payments
161
+ * if the license expires in less than 24 hours
162
+ * from the license creation.
163
+ *
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.9
166
+ *
167
+ * @return bool
168
+ */
169
+ function is_first_payment_pending() {
170
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
171
+ }
172
+ }
freemius/includes/entities/class-fs-plugin-plan.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $name;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $title;
29
+ /**
30
+ * @var string
31
+ */
32
+ public $description;
33
+ /**
34
+ * @var bool Defaults to true. If true, allow unlimited localhost installs with the same license.
35
+ */
36
+ public $is_free_localhost;
37
+ /**
38
+ * @var bool Defaults to true. If false, don't block features after license expiry - only block updates and
39
+ * support.
40
+ */
41
+ public $is_block_features;
42
+ /**
43
+ * @var int
44
+ */
45
+ public $license_type;
46
+ /**
47
+ * @var bool
48
+ */
49
+ public $is_https_support;
50
+ /**
51
+ * @var int Trial days.
52
+ */
53
+ public $trial_period;
54
+ /**
55
+ * @var string If true, require payment for trial.
56
+ */
57
+ public $is_require_subscription;
58
+ /**
59
+ * @var string Knowledge Base URL.
60
+ */
61
+ public $support_kb;
62
+ /**
63
+ * @var string Support Forum URL.
64
+ */
65
+ public $support_forum;
66
+ /**
67
+ * @var string Support email address.
68
+ */
69
+ public $support_email;
70
+ /**
71
+ * @var string Support phone.
72
+ */
73
+ public $support_phone;
74
+ /**
75
+ * @var string Support skype username.
76
+ */
77
+ public $support_skype;
78
+ /**
79
+ * @var bool Is personal success manager supported with the plan.
80
+ */
81
+ public $is_success_manager;
82
+ /**
83
+ * @var bool Is featured plan.
84
+ */
85
+ public $is_featured;
86
+
87
+ #endregion Properties
88
+
89
+ /**
90
+ * @param object|bool $plan
91
+ */
92
+ function __construct( $plan = false ) {
93
+ parent::__construct( $plan );
94
+
95
+ if ( is_object( $plan ) ) {
96
+ $this->name = strtolower( $plan->name );
97
+ }
98
+ }
99
+
100
+ static function get_type() {
101
+ return 'plan';
102
+ }
103
+
104
+ /**
105
+ * @author Vova Feldman (@svovaf)
106
+ * @since 1.0.9
107
+ *
108
+ * @return bool
109
+ */
110
+ function is_free() {
111
+ return ( 'free' === $this->name );
112
+ }
113
+
114
+ /**
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.0.9
117
+ *
118
+ * @return bool
119
+ */
120
+ function has_trial() {
121
+ return ! $this->is_free() &&
122
+ is_numeric( $this->trial_period ) && ( $this->trial_period > 0 );
123
+ }
124
+ }
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-pricing.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius for EDD Add-On
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Pricing extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plan_id;
21
+ /**
22
+ * @var int
23
+ */
24
+ public $licenses;
25
+ /**
26
+ * @var null|float
27
+ */
28
+ public $monthly_price;
29
+ /**
30
+ * @var null|float
31
+ */
32
+ public $annual_price;
33
+ /**
34
+ * @var null|float
35
+ */
36
+ public $lifetime_price;
37
+
38
+ #endregion Properties
39
+
40
+ /**
41
+ * @param object|bool $pricing
42
+ */
43
+ function __construct( $pricing = false ) {
44
+ parent::__construct( $pricing );
45
+ }
46
+
47
+ static function get_type() {
48
+ return 'pricing';
49
+ }
50
+
51
+ /**
52
+ * @author Vova Feldman (@svovaf)
53
+ * @since 1.1.8
54
+ *
55
+ * @return bool
56
+ */
57
+ function has_monthly() {
58
+ return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 );
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.8
64
+ *
65
+ * @return bool
66
+ */
67
+ function has_annual() {
68
+ return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 );
69
+ }
70
+
71
+ /**
72
+ * @author Vova Feldman (@svovaf)
73
+ * @since 1.1.8
74
+ *
75
+ * @return bool
76
+ */
77
+ function has_lifetime() {
78
+ return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 );
79
+ }
80
+
81
+ /**
82
+ * Check if unlimited licenses pricing.
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.1.8
86
+ *
87
+ * @return bool
88
+ */
89
+ function is_unlimited() {
90
+ return is_null( $this->licenses );
91
+ }
92
+
93
+
94
+ /**
95
+ * Check if pricing has more than one billing cycle.
96
+ *
97
+ * @author Vova Feldman (@svovaf)
98
+ * @since 1.1.8
99
+ *
100
+ * @return bool
101
+ */
102
+ function is_multi_cycle() {
103
+ $cycles = 0;
104
+ if ( $this->has_monthly() ) {
105
+ $cycles ++;
106
+ }
107
+ if ( $this->has_annual() ) {
108
+ $cycles ++;
109
+ }
110
+ if ( $this->has_lifetime() ) {
111
+ $cycles ++;
112
+ }
113
+
114
+ return $cycles > 1;
115
+ }
116
+
117
+ /**
118
+ * Get annual over monthly discount.
119
+ *
120
+ * @author Vova Feldman (@svovaf)
121
+ * @since 1.1.8
122
+ *
123
+ * @return int
124
+ */
125
+ function annual_discount_percentage() {
126
+ return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
127
+ }
128
+
129
+ /**
130
+ * Get annual over monthly savings.
131
+ *
132
+ * @author Vova Feldman (@svovaf)
133
+ * @since 1.1.8
134
+ *
135
+ * @return float
136
+ */
137
+ function annual_savings() {
138
+ return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses );
139
+ }
140
+
141
+ }
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,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 $site_id;
22
+ /**
23
+ * @var number
24
+ */
25
+ public $plugin_id;
26
+ /**
27
+ * @var number
28
+ */
29
+ public $user_id;
30
+ /**
31
+ * @var string
32
+ */
33
+ public $title;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $url;
38
+ /**
39
+ * @var string
40
+ */
41
+ public $version;
42
+ /**
43
+ * @var string E.g. en-GB
44
+ */
45
+ public $language;
46
+ /**
47
+ * @var string E.g. UTF-8
48
+ */
49
+ public $charset;
50
+ /**
51
+ * @var string Platform version (e.g WordPress version).
52
+ */
53
+ public $platform_version;
54
+ /**
55
+ * @var string Programming language version (e.g PHP version).
56
+ */
57
+ public $programming_language_version;
58
+ /**
59
+ * @var FS_Plugin_Plan $plan
60
+ */
61
+ public $plan;
62
+ /**
63
+ * @var number|null
64
+ */
65
+ public $license_id;
66
+ /**
67
+ * @var number|null
68
+ */
69
+ public $trial_plan_id;
70
+ /**
71
+ * @var string|null
72
+ */
73
+ public $trial_ends;
74
+ /**
75
+ * @since 1.0.9
76
+ *
77
+ * @var bool
78
+ */
79
+ public $is_premium = false;
80
+
81
+ /**
82
+ * @param stdClass|bool $site
83
+ */
84
+ function __construct( $site = false ) {
85
+ $this->plan = new FS_Plugin_Plan();
86
+
87
+ parent::__construct( $site );
88
+
89
+ if ( is_object( $site ) ) {
90
+ $this->plan->id = $site->plan_id;
91
+ }
92
+ }
93
+
94
+ static function get_type() {
95
+ return 'install';
96
+ }
97
+
98
+ function is_localhost() {
99
+ // The server has no way to verify if localhost unless localhost appears in domain.
100
+ return WP_FS__IS_LOCALHOST_FOR_SERVER;
101
+ // return (substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1');
102
+ }
103
+
104
+ /**
105
+ * Check if site in trial.
106
+ *
107
+ * @author Vova Feldman (@svovaf)
108
+ * @since 1.0.9
109
+ *
110
+ * @return bool
111
+ */
112
+ function is_trial() {
113
+ return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME );
114
+ }
115
+
116
+ /**
117
+ * Check if user already utilized the trial with the current install.
118
+ *
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.0.9
121
+ *
122
+ * @return bool
123
+ */
124
+ function is_trial_utilized() {
125
+ return is_numeric( $this->trial_plan_id );
126
+ }
127
+ }
freemius/includes/entities/class-fs-subscription.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
118
+ /**
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.1.7
121
+ */
122
+ function has_trial() {
123
+ return ! is_null( $this->trial_ends );
124
+ }
125
+ }
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,441 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ( ! function_exists( 'fs_dummy' ) ) {
18
+ function fs_dummy() {
19
+ }
20
+ }
21
+
22
+ /* Url.
23
+ --------------------------------------------------------------------------------------------*/
24
+ function fs_get_url_daily_cache_killer() {
25
+ return date( '\YY\Mm\Dd' );
26
+ }
27
+
28
+ /* Templates / Views.
29
+ --------------------------------------------------------------------------------------------*/
30
+ if ( ! function_exists( 'fs_get_template_path' ) ) {
31
+ function fs_get_template_path( $path ) {
32
+ return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
33
+ }
34
+
35
+ function fs_include_template( $path, &$params = null ) {
36
+ $VARS = &$params;
37
+ include( fs_get_template_path( $path ) );
38
+ }
39
+
40
+ function fs_include_once_template( $path, &$params = null ) {
41
+ $VARS = &$params;
42
+ include_once( fs_get_template_path( $path ) );
43
+ }
44
+
45
+ function fs_require_template( $path, &$params = null ) {
46
+ $VARS = &$params;
47
+ require( fs_get_template_path( $path ) );
48
+ }
49
+
50
+ function fs_require_once_template( $path, &$params = null ) {
51
+ $VARS = &$params;
52
+ require_once( fs_get_template_path( $path ) );
53
+ }
54
+
55
+ function fs_get_template( $path, &$params = null ) {
56
+ ob_start();
57
+
58
+ $VARS = &$params;
59
+ require_once( fs_get_template_path( $path ) );
60
+
61
+ return ob_get_clean();
62
+ }
63
+ }
64
+
65
+ /* Scripts and styles including.
66
+ --------------------------------------------------------------------------------------------*/
67
+ function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
68
+ global $fs_core_logger;
69
+ if ( $fs_core_logger->is_on() ) {
70
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
71
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_CSS . trim( $path, '/' ) ) );
72
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ) );
73
+ }
74
+
75
+ wp_enqueue_style( $handle, plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $media );
76
+ }
77
+
78
+ function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
79
+ global $fs_core_logger;
80
+ if ( $fs_core_logger->is_on() ) {
81
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
82
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_JS . trim( $path, '/' ) ) );
83
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ) );
84
+ }
85
+
86
+ wp_enqueue_script( $handle, plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $in_footer );
87
+ }
88
+
89
+ function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
90
+ return plugins_url( plugin_basename( $img_dir . '/' . trim( $path, '/' ) ) );
91
+ }
92
+
93
+ /* Request handlers.
94
+ --------------------------------------------------------------------------------------------*/
95
+ /**
96
+ * @param string $key
97
+ * @param mixed $def
98
+ *
99
+ * @return mixed
100
+ */
101
+ function fs_request_get( $key, $def = false ) {
102
+ return isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
103
+ }
104
+
105
+ function fs_request_has( $key ) {
106
+ return isset( $_REQUEST[ $key ] );
107
+ }
108
+
109
+ function fs_request_get_bool( $key, $def = false ) {
110
+ return ( isset( $_REQUEST[ $key ] ) && ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) ) ? true : $def;
111
+ }
112
+
113
+ function fs_request_is_post() {
114
+ return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
115
+ }
116
+
117
+ function fs_request_is_get() {
118
+ return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
119
+ }
120
+
121
+ function fs_get_action( $action_key = 'action' ) {
122
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
123
+ return strtolower( $_REQUEST[ $action_key ] );
124
+ }
125
+
126
+ if ( 'action' == $action_key ) {
127
+ $action_key = 'fs_action';
128
+
129
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
130
+ return strtolower( $_REQUEST[ $action_key ] );
131
+ }
132
+ }
133
+
134
+ return false;
135
+ }
136
+
137
+ function fs_request_is_action( $action, $action_key = 'action' ) {
138
+ return ( strtolower( $action ) === fs_get_action( $action_key ) );
139
+ }
140
+
141
+ function fs_is_plugin_page( $menu_slug ) {
142
+ return ( is_admin() && $_REQUEST['page'] === $menu_slug );
143
+ }
144
+
145
+ /* Core UI.
146
+ --------------------------------------------------------------------------------------------*/
147
+ /**
148
+ * @param string $slug
149
+ * @param string $page
150
+ * @param string $action
151
+ * @param string $title
152
+ * @param array $params
153
+ * @param bool $is_primary
154
+ * @param string|bool $icon_class Optional class for an icon (since 1.1.7).
155
+ * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
156
+ * @param string $method Since 1.1.7
157
+ *
158
+ * @uses fs_ui_get_action_button()
159
+ */
160
+ function fs_ui_action_button(
161
+ $slug,
162
+ $page,
163
+ $action,
164
+ $title,
165
+ $params = array(),
166
+ $is_primary = true,
167
+ $icon_class = false,
168
+ $confirmation = false,
169
+ $method = 'GET'
170
+ ) {
171
+ echo fs_ui_get_action_button(
172
+ $slug,
173
+ $page,
174
+ $action,
175
+ $title,
176
+ $params,
177
+ $is_primary,
178
+ $icon_class,
179
+ $confirmation,
180
+ $method
181
+ );
182
+ }
183
+
184
+ /**
185
+ * @author Vova Feldman (@svovaf)
186
+ * @since 1.1.7
187
+ *
188
+ * @param string $slug
189
+ * @param string $page
190
+ * @param string $action
191
+ * @param string $title
192
+ * @param array $params
193
+ * @param bool $is_primary
194
+ * @param string|bool $icon_class Optional class for an icon.
195
+ * @param string|bool $confirmation Optional confirmation message before submit.
196
+ * @param string $method
197
+ *
198
+ * @return string
199
+ */
200
+ function fs_ui_get_action_button(
201
+ $slug,
202
+ $page,
203
+ $action,
204
+ $title,
205
+ $params = array(),
206
+ $is_primary = true,
207
+ $icon_class = false,
208
+ $confirmation = false,
209
+ $method = 'GET'
210
+ ) {
211
+ // Prepend icon (if set).
212
+ $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title;
213
+
214
+ if ( is_string( $confirmation ) ) {
215
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>',
216
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
217
+ $method,
218
+ $action,
219
+ wp_nonce_field( $action, '_wpnonce', true, false ),
220
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
221
+ $confirmation,
222
+ $title
223
+ );
224
+ } else if ( 'GET' !== strtoupper( $method ) ) {
225
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>',
226
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
227
+ $method,
228
+ $action,
229
+ wp_nonce_field( $action, '_wpnonce', true, false ),
230
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
231
+ $title
232
+ );
233
+ } else {
234
+ return sprintf( '<a href="%s" class="%s">%s</a></form>',
235
+ wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ),
236
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
237
+ $title
238
+ );
239
+ }
240
+ }
241
+
242
+ function fs_ui_action_link( $slug, $page, $action, $title, $params = array() ) {
243
+ ?><a class=""
244
+ 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
245
+ }
246
+
247
+ /*function fs_error_handler($errno, $errstr, $errfile, $errline)
248
+ {
249
+ if (false === strpos($errfile, 'freemius/'))
250
+ {
251
+ // @todo Dump Freemius errors to local log.
252
+ }
253
+
254
+ // switch ($errno) {
255
+ // case E_USER_ERROR:
256
+ // break;
257
+ // case E_WARNING:
258
+ // case E_USER_WARNING:
259
+ // break;
260
+ // case E_NOTICE:
261
+ // case E_USER_NOTICE:
262
+ // break;
263
+ // default:
264
+ // break;
265
+ // }
266
+ }
267
+
268
+ set_error_handler('fs_error_handler');*/
269
+
270
+ function fs_nonce_url( $actionurl, $action = - 1, $name = '_wpnonce' ) {
271
+ // $actionurl = str_replace( '&amp;', '&', $actionurl );
272
+ return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
273
+ }
274
+
275
+ if ( ! function_exists( 'fs_starts_with' ) ) {
276
+ /**
277
+ * Check if string starts with.
278
+ *
279
+ * @author Vova Feldman (@svovaf)
280
+ * @since 1.1.3
281
+ *
282
+ * @param string $haystack
283
+ * @param string $needle
284
+ *
285
+ * @return bool
286
+ */
287
+ function fs_starts_with( $haystack, $needle ) {
288
+ $length = strlen( $needle );
289
+
290
+ return ( substr( $haystack, 0, $length ) === $needle );
291
+ }
292
+ }
293
+
294
+ #region Url Canonization ------------------------------------------------------------------
295
+
296
+ if ( ! function_exists( 'fs_canonize_url' ) ) {
297
+ /**
298
+ * @author Vova Feldman (@svovaf)
299
+ * @since 1.1.3
300
+ *
301
+ * @param string $url
302
+ * @param bool $omit_host
303
+ * @param array $ignore_params
304
+ *
305
+ * @return string
306
+ */
307
+ function fs_canonize_url( $url, $omit_host = false, $ignore_params = array() ) {
308
+ $parsed_url = parse_url( strtolower( $url ) );
309
+
310
+ // if ( ! isset( $parsed_url['host'] ) ) {
311
+ // return $url;
312
+ // }
313
+
314
+ $canonical = ( ( $omit_host || ! isset( $parsed_url['host'] ) ) ? '' : $parsed_url['host'] ) . $parsed_url['path'];
315
+
316
+ if ( isset( $parsed_url['query'] ) ) {
317
+ parse_str( $parsed_url['query'], $queryString );
318
+ $canonical .= '?' . fs_canonize_query_string( $queryString, $ignore_params );
319
+ }
320
+
321
+ return $canonical;
322
+ }
323
+ }
324
+
325
+ if ( ! function_exists( 'fs_canonize_query_string' ) ) {
326
+ /**
327
+ * @author Vova Feldman (@svovaf)
328
+ * @since 1.1.3
329
+ *
330
+ * @param array $params
331
+ * @param array $ignore_params
332
+ * @param bool $params_prefix
333
+ *
334
+ * @return string
335
+ */
336
+ function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) {
337
+ if ( ! is_array( $params ) || 0 === count( $params ) ) {
338
+ return '';
339
+ }
340
+
341
+ // Urlencode both keys and values
342
+ $keys = fs_urlencode_rfc3986( array_keys( $params ) );
343
+ $values = fs_urlencode_rfc3986( array_values( $params ) );
344
+ $params = array_combine( $keys, $values );
345
+
346
+ // Parameters are sorted by name, using lexicographical byte value ordering.
347
+ // Ref: Spec: 9.1.1 (1)
348
+ uksort( $params, 'strcmp' );
349
+
350
+ $pairs = array();
351
+ foreach ( $params as $parameter => $value ) {
352
+ $lower_param = strtolower( $parameter );
353
+
354
+ // Skip ignore params.
355
+ if ( in_array( $lower_param, $ignore_params ) || ( false !== $params_prefix && startsWith( $lower_param, $params_prefix ) ) ) {
356
+ continue;
357
+ }
358
+
359
+ if ( is_array( $value ) ) {
360
+ // If two or more parameters share the same name, they are sorted by their value
361
+ // Ref: Spec: 9.1.1 (1)
362
+ natsort( $value );
363
+ foreach ( $value as $duplicate_value ) {
364
+ $pairs[] = $lower_param . '=' . $duplicate_value;
365
+ }
366
+ } else {
367
+ $pairs[] = $lower_param . '=' . $value;
368
+ }
369
+ }
370
+
371
+ if ( 0 === count( $pairs ) ) {
372
+ return '';
373
+ }
374
+
375
+ return implode( "&", $pairs );
376
+ }
377
+ }
378
+
379
+ if ( ! function_exists( 'fs_urlencode_rfc3986' ) ) {
380
+ /**
381
+ * @author Vova Feldman (@svovaf)
382
+ * @since 1.1.3
383
+ *
384
+ * @param string|string[] $input
385
+ *
386
+ * @return array|mixed|string
387
+ */
388
+ function fs_urlencode_rfc3986( $input ) {
389
+ if ( is_array( $input ) ) {
390
+ return array_map( 'fs_urlencode_rfc3986', $input );
391
+ } else if ( is_scalar( $input ) ) {
392
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) );
393
+ }
394
+
395
+ return '';
396
+ }
397
+ }
398
+
399
+ #endregion Url Canonization ------------------------------------------------------------------
400
+
401
+ function fs_download_image( $from, $to ) {
402
+ $ch = curl_init( $from );
403
+ $fp = fopen( fs_normalize_path( $to ), 'wb' );
404
+ curl_setopt( $ch, CURLOPT_FILE, $fp );
405
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
406
+ curl_exec( $ch );
407
+ curl_close( $ch );
408
+ fclose( $fp );
409
+ }
410
+
411
+ /* General Utilities
412
+ --------------------------------------------------------------------------------------------*/
413
+
414
+ /**
415
+ * Sorts an array by the value of the priority key.
416
+ *
417
+ * @author Daniel Iser (@danieliser)
418
+ * @since 1.1.7
419
+ *
420
+ * @param $a
421
+ * @param $b
422
+ *
423
+ * @return int
424
+ */
425
+ function fs_sort_by_priority( $a, $b ) {
426
+
427
+ // If b has a priority and a does not, b wins.
428
+ if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) {
429
+ return 1;
430
+ } // If b has a priority and a does not, b wins.
431
+ elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) {
432
+ return - 1;
433
+ } // If neither has a priority or both priorities are equal its a tie.
434
+ elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) {
435
+ return 0;
436
+ }
437
+
438
+ // If both have priority return the winner.
439
+ return ( $a['priority'] < $b['priority'] ) ? - 1 : 1;
440
+ }
441
+
freemius/includes/fs-essential-functions.php ADDED
@@ -0,0 +1,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ( ! function_exists( 'fs_sanitize_redirect' ) ) {
76
+ /**
77
+ * Sanitizes a URL for use in a redirect.
78
+ *
79
+ * @since 2.3
80
+ *
81
+ * @param string $location
82
+ *
83
+ * @return string redirect-sanitized URL
84
+ */
85
+ function fs_sanitize_redirect( $location ) {
86
+ $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
87
+ $location = fs_kses_no_null( $location );
88
+
89
+ // remove %0d and %0a from location
90
+ $strip = array( '%0d', '%0a' );
91
+ $found = true;
92
+ while ( $found ) {
93
+ $found = false;
94
+ foreach ( (array) $strip as $val ) {
95
+ while ( strpos( $location, $val ) !== false ) {
96
+ $found = true;
97
+ $location = str_replace( $val, '', $location );
98
+ }
99
+ }
100
+ }
101
+
102
+ return $location;
103
+ }
104
+ }
105
+
106
+ if ( ! function_exists( 'fs_kses_no_null' ) ) {
107
+ /**
108
+ * Removes any NULL characters in $string.
109
+ *
110
+ * @since 1.0.0
111
+ *
112
+ * @param string $string
113
+ *
114
+ * @return string
115
+ */
116
+ function fs_kses_no_null( $string ) {
117
+ $string = preg_replace( '/\0+/', '', $string );
118
+ $string = preg_replace( '/(\\\\0)+/', '', $string );
119
+
120
+ return $string;
121
+ }
122
+ }
123
+ }
124
+
125
+ #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
126
+
127
+ if ( ! function_exists( '__fs' ) ) {
128
+ global $fs_text_overrides;
129
+
130
+ if ( ! isset( $fs_text_overrides ) ) {
131
+ $fs_text_overrides = array();
132
+ }
133
+
134
+ /**
135
+ * Retrieve a translated text by key.
136
+ *
137
+ * @author Vova Feldman (@svovaf)
138
+ * @since 1.1.4
139
+ *
140
+ * @param string $key
141
+ * @param string $slug
142
+ *
143
+ * @return string
144
+ *
145
+ * @global $fs_text , $fs_text_overrides
146
+ */
147
+ function __fs( $key, $slug = 'freemius' ) {
148
+ global $fs_text, $fs_text_overrides;
149
+
150
+ if ( ! isset( $fs_text ) ) {
151
+ require_once( ( defined( 'WP_FS__DIR_INCLUDES' ) ? WP_FS__DIR_INCLUDES : dirname( __FILE__ ) ) . '/i18n.php' );
152
+ }
153
+
154
+ if ( isset( $fs_text_overrides[ $slug ] ) ) {
155
+ if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) {
156
+ return $fs_text_overrides[ $slug ][ $key ];
157
+ }
158
+
159
+ $lower_key = strtolower( $key );
160
+ if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) {
161
+ return $fs_text_overrides[ $slug ][ $lower_key ];
162
+ }
163
+ }
164
+
165
+ return isset( $fs_text[ $key ] ) ?
166
+ $fs_text[ $key ] :
167
+ $key;
168
+ }
169
+
170
+ /**
171
+ * Display a translated text by key.
172
+ *
173
+ * @author Vova Feldman (@svovaf)
174
+ * @since 1.1.4
175
+ *
176
+ * @param string $key
177
+ * @param string $slug
178
+ */
179
+ function _efs( $key, $slug = 'freemius' ) {
180
+ echo __fs( $key, $slug );
181
+ }
182
+
183
+ /**
184
+ * Override default i18n text phrases.
185
+ *
186
+ * @author Vova Feldman (@svovaf)
187
+ * @since 1.1.6
188
+ *
189
+ * @param string[] $key_value
190
+ * @param string $slug
191
+ *
192
+ * @global $fs_text_overrides
193
+ */
194
+ function fs_override_i18n( array $key_value, $slug = 'freemius' ) {
195
+ global $fs_text_overrides;
196
+
197
+ if ( ! isset( $fs_text_overrides[ $slug ] ) ) {
198
+ $fs_text_overrides[ $slug ] = array();
199
+ }
200
+
201
+ foreach ( $key_value as $key => $value ) {
202
+ $fs_text_overrides[ $slug ][ $key ] = $value;
203
+ }
204
+ }
205
+ }
206
+
207
+ if ( ! function_exists( 'fs_get_ip' ) ) {
208
+ /**
209
+ * Get client IP.
210
+ *
211
+ * @author Vova Feldman (@svovaf)
212
+ * @since 1.1.2
213
+ *
214
+ * @return string|null
215
+ */
216
+ function fs_get_ip() {
217
+ $fields = array(
218
+ 'HTTP_CF_CONNECTING_IP',
219
+ 'HTTP_CLIENT_IP',
220
+ 'HTTP_X_FORWARDED_FOR',
221
+ 'HTTP_X_FORWARDED',
222
+ 'HTTP_FORWARDED_FOR',
223
+ 'HTTP_FORWARDED',
224
+ 'REMOTE_ADDR',
225
+ );
226
+
227
+ foreach ( $fields as $ip_field ) {
228
+ if ( ! empty( $_SERVER[ $ip_field ] ) ) {
229
+ return $_SERVER[ $ip_field ];
230
+ }
231
+ }
232
+
233
+ return null;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Leverage backtrace to find caller plugin main file path.
239
+ *
240
+ * @author Vova Feldman (@svovaf)
241
+ * @since 1.0.6
242
+ *
243
+ * @return string
244
+ */
245
+ function fs_find_caller_plugin_file() {
246
+ /**
247
+ * All the code below will be executed once on activation.
248
+ * If the user changes the main plugin's file name, the file_exists()
249
+ * will catch it.
250
+ */
251
+ if ( ! function_exists( 'get_plugins' ) ) {
252
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
253
+ }
254
+
255
+ $all_plugins = get_plugins();
256
+ $all_plugins_paths = array();
257
+
258
+ // Get active plugin's main files real full names (might be symlinks).
259
+ foreach ( $all_plugins as $relative_path => &$data ) {
260
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
261
+ }
262
+
263
+ $plugin_file = null;
264
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
265
+ if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
266
+ $plugin_file = $bt[ $i ]['file'];
267
+ break;
268
+ }
269
+ }
270
+
271
+ if ( is_null( $plugin_file ) ) {
272
+ // Throw an error to the developer in case of some edge case dev environment.
273
+ wp_die( __fs( 'failed-finding-main-path' ), __fs( 'error' ), array( 'back_link' => true ) );
274
+ }
275
+
276
+ return $plugin_file;
277
+ }
278
+
279
+ require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
280
+
281
+ /**
282
+ * Update SDK newest version reference.
283
+ *
284
+ * @author Vova Feldman (@svovaf)
285
+ * @since 1.1.6
286
+ *
287
+ * @param string $sdk_relative_path
288
+ * @param string|bool $plugin_file
289
+ *
290
+ * @global $fs_active_plugins
291
+ */
292
+ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
293
+ global $fs_active_plugins;
294
+
295
+ if ( ! is_string( $plugin_file ) ) {
296
+ $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
297
+ }
298
+
299
+ $fs_active_plugins->newest = (object) array(
300
+ 'plugin_path' => $plugin_file,
301
+ 'sdk_path' => $sdk_relative_path,
302
+ 'version' => $fs_active_plugins->plugins[ $sdk_relative_path ]->version,
303
+ 'in_activation' => ! is_plugin_active( $plugin_file ),
304
+ 'timestamp' => time(),
305
+ );
306
+
307
+ // Update DB with latest SDK version and path.
308
+ update_option( 'fs_active_plugins', $fs_active_plugins );
309
+ }
310
+
311
+ /**
312
+ * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
313
+ *
314
+ * @author Vova Feldman (@svovaf)
315
+ * @since 1.1.6
316
+ *
317
+ * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
318
+ *
319
+ * @global $fs_active_plugins
320
+ */
321
+ function fs_newest_sdk_plugin_first() {
322
+ global $fs_active_plugins;
323
+
324
+ /**
325
+ * @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).
326
+ *
327
+ * @link https://github.com/Freemius/wordpress-sdk/issues/26
328
+ */
329
+ // $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
330
+
331
+ $active_plugins = get_option( 'active_plugins' );
332
+ $newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins );
333
+ if ( 0 == $newest_sdk_plugin_key ) {
334
+ // if it's 0 it's the first plugin already, no need to continue
335
+ return false;
336
+ }
337
+
338
+ array_splice( $active_plugins, $newest_sdk_plugin_key, 1 );
339
+ array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path );
340
+ update_option( 'active_plugins', $active_plugins );
341
+
342
+ return true;
343
+ }
344
+
345
+ /**
346
+ * Go over all Freemius SDKs in the system and find and "remember"
347
+ * the newest SDK which is associated with an active plugin.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.1.6
351
+ *
352
+ * @global $fs_active_plugins
353
+ */
354
+ function fs_fallback_to_newest_active_sdk() {
355
+ global $fs_active_plugins;
356
+
357
+ $newest_sdk_data = null;
358
+ $newest_sdk_path = null;
359
+
360
+ foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
361
+ if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
362
+ ) {
363
+ // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
364
+ if ( ! is_plugin_active( $data->plugin_path ) ||
365
+ ! file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) )
366
+ ) {
367
+ unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
368
+
369
+ // No need to store the data since it will be stored in fs_update_sdk_newest_version()
370
+ // or explicitly with update_option().
371
+ } else {
372
+ $newest_sdk_data = $data;
373
+ $newest_sdk_path = $sdk_relative_path;
374
+ }
375
+ }
376
+ }
377
+
378
+ if ( is_null( $newest_sdk_data ) ) {
379
+ // Couldn't find any SDK reference.
380
+ $fs_active_plugins = new stdClass();
381
+ update_option( 'fs_active_plugins', $fs_active_plugins );
382
+ } else {
383
+ fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
384
+ }
385
+ }
386
+
387
+ #region Actions / Filters -----------------------------------------
388
+
389
+ /**
390
+ * Apply filter for specific plugin.
391
+ *
392
+ * @author Vova Feldman (@svovaf)
393
+ * @since 1.0.9
394
+ *
395
+ * @param string $slug Plugin slug
396
+ * @param string $tag The name of the filter hook.
397
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
398
+ *
399
+ * @return mixed The filtered value after all hooked functions are applied to it.
400
+ *
401
+ * @uses apply_filters()
402
+ */
403
+ function fs_apply_filter( $slug, $tag, $value ) {
404
+ $args = func_get_args();
405
+
406
+ return call_user_func_array( 'apply_filters', array_merge(
407
+ array( 'fs_' . $tag . '_' . $slug ),
408
+ array_slice( $args, 2 ) )
409
+ );
410
+ }
411
+
412
+ #endregion Actions / Filters -----------------------------------------
freemius/includes/fs-plugin-info-dialog.php ADDED
@@ -0,0 +1,936 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Class FS_Plugin_Info_Dialog
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7
18
+ */
19
+ class FS_Plugin_Info_Dialog {
20
+ /**
21
+ * @since 1.1.7
22
+ *
23
+ * @var FS_Logger
24
+ */
25
+ private $_logger;
26
+
27
+ /**
28
+ * @since 1.1.7
29
+ *
30
+ * @var Freemius
31
+ */
32
+ private $_fs;
33
+
34
+ function __construct( Freemius $fs ) {
35
+ $this->_fs = $fs;
36
+
37
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $fs->get_slug() . '_info', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
38
+
39
+ // Remove default plugin information action.
40
+ remove_all_actions( 'install_plugins_pre_plugin-information' );
41
+
42
+ // Override action with custom plugins function for add-ons.
43
+ add_action( 'install_plugins_pre_plugin-information', array( &$this, 'install_plugin_information' ) );
44
+
45
+ // Override request for plugin information for Add-ons.
46
+ add_filter(
47
+ 'fs_plugins_api',
48
+ array( &$this, '_get_addon_info_filter' ),
49
+ WP_FS__DEFAULT_PRIORITY, 3 );
50
+ }
51
+
52
+ /**
53
+ * Generate add-on plugin information.
54
+ *
55
+ * @author Vova Feldman (@svovaf)
56
+ * @since 1.0.6
57
+ *
58
+ * @param array $data
59
+ * @param string $action
60
+ * @param object|null $args
61
+ *
62
+ * @return array|null
63
+ */
64
+ function _get_addon_info_filter( $data, $action = '', $args = null ) {
65
+ $this->_logger->entrance();
66
+
67
+ $parent_plugin_id = fs_request_get( 'parent_plugin_id', false );
68
+
69
+ if ( $this->_fs->get_id() != $parent_plugin_id ||
70
+ ( 'plugin_information' !== $action ) ||
71
+ ! isset( $args->slug )
72
+ ) {
73
+ return $data;
74
+ }
75
+
76
+ // Find add-on by slug.
77
+ $addons = $this->_fs->get_addons();
78
+ $selected_addon = false;
79
+ foreach ( $addons as $addon ) {
80
+ if ( $addon->slug == $args->slug ) {
81
+ $selected_addon = $addon;
82
+ break;
83
+ }
84
+ }
85
+
86
+ if ( false === $selected_addon ) {
87
+ return $data;
88
+ }
89
+
90
+ if ( ! isset( $selected_addon->info ) ) {
91
+ // Setup some default info.
92
+ $selected_addon->info = new stdClass();
93
+ $selected_addon->info->selling_point_0 = 'Selling Point 1';
94
+ $selected_addon->info->selling_point_1 = 'Selling Point 2';
95
+ $selected_addon->info->selling_point_2 = 'Selling Point 3';
96
+ $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
97
+ }
98
+
99
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
100
+
101
+ $data = $args;
102
+
103
+ $is_free = true;
104
+
105
+ // Load add-on pricing.
106
+ $has_pricing = false;
107
+ $has_features = false;
108
+ $plans = false;
109
+ $plans_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans.json" );
110
+ if ( ! isset( $plans_result->error ) ) {
111
+ $plans = $plans_result->plans;
112
+ if ( is_array( $plans ) ) {
113
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
114
+ $plans[ $i ] = new FS_Plugin_Plan( $plans[ $i ] );
115
+ $plan = $plans[ $i ];
116
+
117
+ $pricing_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/pricing.json" );
118
+ if ( ! isset( $pricing_result->error ) ) {
119
+ // Update plan's pricing.
120
+ $plan->pricing = $pricing_result->pricing;
121
+
122
+ if ( is_array( $plan->pricing ) && ! empty( $plan->pricing ) ) {
123
+ $is_free = false;
124
+
125
+ foreach ( $plan->pricing as &$pricing ) {
126
+ $pricing = new FS_Pricing( $pricing );
127
+ }
128
+ }
129
+
130
+ $has_pricing = true;
131
+ }
132
+
133
+ $features_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/features.json" );
134
+ if ( ! isset( $features_result->error ) &&
135
+ is_array( $features_result->features ) &&
136
+ 0 < count( $features_result->features )
137
+ ) {
138
+ // Update plan's pricing.
139
+ $plan->features = $features_result->features;
140
+
141
+ $has_features = true;
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ // Fetch latest version from Freemius.
148
+ $latest = $this->_fs->_fetch_latest_version( $selected_addon->id );
149
+
150
+ if ( ! $is_free ) {
151
+ // If paid add-on, then it's not on wordpress.org
152
+ $is_wordpress_org = false;
153
+ } else {
154
+ // If no versions found, then assume it's a .org plugin.
155
+ $is_wordpress_org = ( false === $latest );
156
+ }
157
+
158
+ if ( $is_wordpress_org ) {
159
+ $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository(
160
+ 'plugin_information', (object) array(
161
+ 'slug' => $selected_addon->slug,
162
+ 'is_ssl' => is_ssl(),
163
+ 'fields' => array(
164
+ 'banners' => true,
165
+ 'reviews' => true,
166
+ 'downloaded' => false,
167
+ 'active_installs' => true
168
+ )
169
+ ) );
170
+
171
+ if ( ! empty( $repo_data ) ) {
172
+ $data = $repo_data;
173
+ $data->wp_org_missing = false;
174
+ } else {
175
+ // Couldn't find plugin on .org.
176
+ $is_wordpress_org = false;
177
+
178
+ // Plugin is missing, not on Freemius nor WP.org.
179
+ $data->wp_org_missing = true;
180
+ }
181
+ }
182
+
183
+ if ( ! $is_wordpress_org ) {
184
+ $data->checkout_link = $this->_fs->checkout_url();
185
+ $data->fs_missing = ( false === $latest );
186
+
187
+ if ( $is_free ) {
188
+ $data->download_link = $this->_fs->_get_latest_download_local_url( $selected_addon->id );
189
+ }
190
+ }
191
+
192
+ if ( ! $is_wordpress_org ) {
193
+ // Fetch as much as possible info from local files.
194
+ $plugin_local_data = $this->_fs->get_plugin_data();
195
+ $data->name = $selected_addon->title;
196
+ $data->author = $plugin_local_data['Author'];
197
+ $view_vars = array( 'plugin' => $selected_addon );
198
+ $data->sections = array(
199
+ 'description' => fs_get_template( '/plugin-info/description.php', $view_vars ),
200
+ );
201
+
202
+ if ( ! empty( $selected_addon->info->banner_url ) ) {
203
+ $data->banners = array(
204
+ 'low' => $selected_addon->info->banner_url,
205
+ );
206
+ }
207
+
208
+ if ( ! empty( $selected_addon->info->screenshots ) ) {
209
+ $view_vars = array(
210
+ 'screenshots' => $selected_addon->info->screenshots,
211
+ 'plugin' => $selected_addon,
212
+ );
213
+ $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
214
+ }
215
+
216
+ if ( is_object( $latest ) ) {
217
+ $data->version = $latest->version;
218
+ $data->last_updated = ! is_null( $latest->updated ) ? $latest->updated : $latest->created;
219
+ $data->requires = $latest->requires_platform_version;
220
+ $data->tested = $latest->tested_up_to_version;
221
+ } else {
222
+ // Add dummy version.
223
+ $data->version = '1.0.0';
224
+
225
+ // Add message to developer to deploy the plugin through Freemius.
226
+ }
227
+ }
228
+
229
+ if ( $has_pricing ) {
230
+ // Add plans to data.
231
+ $data->plans = $plans;
232
+
233
+ if ( $has_features ) {
234
+ $view_vars = array(
235
+ 'plans' => $plans,
236
+ 'plugin' => $selected_addon,
237
+ );
238
+ $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
239
+ }
240
+ }
241
+
242
+ $data->is_paid = ! $is_free;
243
+ $data->external = ! $is_wordpress_org;
244
+
245
+ return $data;
246
+ }
247
+
248
+ /**
249
+ * @author Vova Feldman (@svovaf)
250
+ * @since 1.1.7
251
+ *
252
+ * @param FS_Plugin_Plan $plan
253
+ *
254
+ * @return string
255
+ */
256
+ private function get_billing_cycle( FS_Plugin_Plan $plan ) {
257
+ $billing_cycle = null;
258
+
259
+ if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) {
260
+ $pricing = $plan->pricing[0];
261
+ if ( isset( $pricing->annual_price ) ) {
262
+ $billing_cycle = 'annual';
263
+ } else if ( isset( $pricing->monthly_price ) ) {
264
+ $billing_cycle = 'monthly';
265
+ } else if ( isset( $pricing->lifetime_price ) ) {
266
+ $billing_cycle = 'lifetime';
267
+ }
268
+ } else {
269
+ foreach ( $plan->pricing as $pricing ) {
270
+ if ( isset( $pricing->annual_price ) ) {
271
+ $billing_cycle = 'annual';
272
+ } else if ( isset( $pricing->monthly_price ) ) {
273
+ $billing_cycle = 'monthly';
274
+ } else if ( isset( $pricing->lifetime_price ) ) {
275
+ $billing_cycle = 'lifetime';
276
+ }
277
+
278
+ if ( ! is_null( $billing_cycle ) ) {
279
+ break;
280
+ }
281
+ }
282
+ }
283
+
284
+ return $billing_cycle;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.7
290
+ *
291
+ * @param FS_Plugin_Plan $plan
292
+ * @param FS_Pricing $pricing
293
+ *
294
+ * @return float|null|string
295
+ */
296
+ private function get_price_tag( FS_Plugin_Plan $plan, FS_Pricing $pricing ) {
297
+ $price_tag = '';
298
+ if ( isset( $pricing->annual_price ) ) {
299
+ $price_tag = $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
300
+ } else if ( isset( $pricing->monthly_price ) ) {
301
+ $price_tag = $pricing->monthly_price . ' / mo';
302
+ } else if ( isset( $pricing->lifetime_price ) ) {
303
+ $price_tag = $pricing->lifetime_price;
304
+ }
305
+
306
+ return '$' . $price_tag;
307
+ }
308
+
309
+ /**
310
+ * @author Vova Feldman (@svovaf)
311
+ * @since 1.1.7
312
+ *
313
+ * @param object $api
314
+ * @param FS_Plugin_Plan|null $plan
315
+ *
316
+ * @return string
317
+ */
318
+ private function get_plugin_cta( $api, $plan = null ) {
319
+ if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
320
+
321
+ if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) {
322
+ if ( is_null( $plan ) ) {
323
+ $plan = $api->plans[0];
324
+ }
325
+
326
+ return ' <a class="button button-primary right" href="' . $this->_fs->addon_checkout_url(
327
+ $plan->plugin_id,
328
+ $plan->pricing[0]->id,
329
+ $this->get_billing_cycle( $plan ),
330
+ $plan->has_trial()
331
+ ) . '" target="_parent">' .
332
+ ( ! $plan->has_trial() ?
333
+ __fs( 'purchase', $api->slug ) :
334
+ sprintf( __fs( 'start-free-x', $api->slug ), $this->get_trial_period( $plan ) )
335
+ ) .
336
+ '</a>';
337
+
338
+ // @todo Add Cart concept.
339
+ // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>';
340
+
341
+ } else if ( ! empty( $api->download_link ) ) {
342
+ $status = install_plugin_install_status( $api );
343
+
344
+
345
+ // Hosted on WordPress.org.
346
+ switch ( $status['status'] ) {
347
+ case 'install':
348
+ if ( $api->external &&
349
+ $this->_fs->is_org_repo_compliant() ||
350
+ ! $this->_fs->is_premium()
351
+ ) {
352
+ /**
353
+ * Add-on hosted on Freemius, not yet installed, and core
354
+ * plugin is wordpress.org compliant. Therefore, require a download
355
+ * since installing external plugins is not allowed by the wp.org guidelines.
356
+ */
357
+ return ' <a class="button button-primary right" href="' . esc_url( $api->download_link ) . '" target="_blank">' . __fs( 'download-latest', $api->slug ) . '</a>';
358
+ } else {
359
+ if ( $status['url'] ) {
360
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
361
+ }
362
+ }
363
+ break;
364
+ case 'update_available':
365
+ if ( $status['url'] ) {
366
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
367
+ }
368
+ break;
369
+ case 'newer_installed':
370
+ return '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
371
+ break;
372
+ case 'latest_installed':
373
+ return '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
374
+ break;
375
+ }
376
+
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * @author Vova Feldman (@svovaf)
383
+ * @since 1.1.7
384
+ *
385
+ * @param FS_Plugin_Plan $plan
386
+ *
387
+ * @return string
388
+ */
389
+ private function get_trial_period( $plan ) {
390
+ $trial_period = (int) $plan->trial_period;
391
+
392
+ switch ( $trial_period ) {
393
+ case 30:
394
+ return 'month';
395
+ case 60:
396
+ return '2 months';
397
+ default:
398
+ return "{$plan->trial_period} days";
399
+ }
400
+ }
401
+
402
+ /**
403
+ * Display plugin information in dialog box form.
404
+ *
405
+ * Based on core install_plugin_information() function.
406
+ *
407
+ * @author Vova Feldman (@svovaf)
408
+ * @since 1.0.6
409
+ */
410
+ function install_plugin_information() {
411
+ global $tab;
412
+
413
+ if ( empty( $_REQUEST['plugin'] ) ) {
414
+ return;
415
+ }
416
+
417
+ $args = array(
418
+ 'slug' => wp_unslash( $_REQUEST['plugin'] ),
419
+ 'is_ssl' => is_ssl(),
420
+ 'fields' => array(
421
+ 'banners' => true,
422
+ 'reviews' => true,
423
+ 'downloaded' => false,
424
+ 'active_installs' => true
425
+ )
426
+ );
427
+
428
+ if ( is_array( $args ) ) {
429
+ $args = (object) $args;
430
+ }
431
+
432
+ if ( ! isset( $args->per_page ) ) {
433
+ $args->per_page = 24;
434
+ }
435
+
436
+ if ( ! isset( $args->locale ) ) {
437
+ $args->locale = get_locale();
438
+ }
439
+
440
+ $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args );
441
+
442
+ if ( is_wp_error( $api ) ) {
443
+ wp_die( $api );
444
+ }
445
+
446
+ $plugins_allowedtags = array(
447
+ 'a' => array(
448
+ 'href' => array(),
449
+ 'title' => array(),
450
+ 'target' => array(),
451
+ // Add image style for screenshots.
452
+ 'class' => array()
453
+ ),
454
+ 'style' => array(),
455
+ 'abbr' => array( 'title' => array() ),
456
+ 'acronym' => array( 'title' => array() ),
457
+ 'code' => array(),
458
+ 'pre' => array(),
459
+ 'em' => array(),
460
+ 'strong' => array(),
461
+ 'div' => array( 'class' => array() ),
462
+ 'span' => array( 'class' => array() ),
463
+ 'p' => array(),
464
+ 'ul' => array(),
465
+ 'ol' => array(),
466
+ 'li' => array( 'class' => array() ),
467
+ 'i' => array( 'class' => array() ),
468
+ 'h1' => array(),
469
+ 'h2' => array(),
470
+ 'h3' => array(),
471
+ 'h4' => array(),
472
+ 'h5' => array(),
473
+ 'h6' => array(),
474
+ 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
475
+ // 'table' => array(),
476
+ // 'td' => array(),
477
+ // 'tr' => array(),
478
+ // 'th' => array(),
479
+ // 'thead' => array(),
480
+ // 'tbody' => array(),
481
+ );
482
+
483
+ $plugins_section_titles = array(
484
+ 'description' => _x( 'Description', 'Plugin installer section title' ),
485
+ 'installation' => _x( 'Installation', 'Plugin installer section title' ),
486
+ 'faq' => _x( 'FAQ', 'Plugin installer section title' ),
487
+ 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
488
+ 'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
489
+ 'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
490
+ 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
491
+ );
492
+
493
+ // Sanitize HTML
494
+ // foreach ( (array) $api->sections as $section_name => $content ) {
495
+ // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
496
+ // }
497
+
498
+ foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
499
+ if ( isset( $api->$key ) ) {
500
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
501
+ }
502
+ }
503
+
504
+ // Add after $api->slug is ready.
505
+ $plugins_section_titles['features'] = __fs( 'features-and-pricing', $api->slug );
506
+
507
+ $_tab = esc_attr( $tab );
508
+
509
+ $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
510
+ if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
511
+ $section_titles = array_keys( (array) $api->sections );
512
+ $section = array_shift( $section_titles );
513
+ }
514
+
515
+ iframe_header( __( 'Plugin Install' ) );
516
+
517
+ $_with_banner = '';
518
+
519
+ // var_dump($api->banners);
520
+ if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
521
+ $_with_banner = 'with-banner';
522
+ $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
523
+ $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
524
+ ?>
525
+ <style type="text/css">
526
+ #plugin-information-title.with-banner
527
+ {
528
+ background-image: url( <?php echo esc_url( $low ); ?> );
529
+ }
530
+
531
+ @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 )
532
+ {
533
+ #plugin-information-title.with-banner
534
+ {
535
+ background-image: url( <?php echo esc_url( $high ); ?> );
536
+ }
537
+ }
538
+ </style>
539
+ <?php
540
+ }
541
+
542
+ echo '<div id="plugin-information-scrollable">';
543
+ echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
544
+ echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
545
+
546
+ foreach ( (array) $api->sections as $section_name => $content ) {
547
+ if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
548
+ continue;
549
+ }
550
+
551
+ if ( isset( $plugins_section_titles[ $section_name ] ) ) {
552
+ $title = $plugins_section_titles[ $section_name ];
553
+ } else {
554
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
555
+ }
556
+
557
+ $class = ( $section_name === $section ) ? ' class="current"' : '';
558
+ $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) );
559
+ $href = esc_url( $href );
560
+ $san_section = esc_attr( $section_name );
561
+ echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
562
+ }
563
+
564
+ echo "</div>\n";
565
+
566
+ ?>
567
+ <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
568
+ <div class="fyi">
569
+ <?php if ( $api->is_paid ) : ?>
570
+ <?php if ( isset( $api->plans ) ) : ?>
571
+ <div class="plugin-information-pricing">
572
+ <?php foreach ( $api->plans as $plan ) : ?>
573
+ <?php
574
+ /**
575
+ * @var FS_Plugin_Plan $plan
576
+ */
577
+ ?>
578
+ <?php $first_pricing = $plan->pricing[0] ?>
579
+ <?php $is_multi_cycle = $first_pricing->is_multi_cycle() ?>
580
+ <div class="fs-plan<?php if ( ! $is_multi_cycle ) {
581
+ echo ' fs-single-cycle';
582
+ } ?>" data-plan-id="<?php echo $plan->id ?>">
583
+ <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan', $api->slug ), $plan->title ) ?></h3>
584
+ <?php $has_annual = $first_pricing->has_annual() ?>
585
+ <?php $has_monthly = $first_pricing->has_monthly() ?>
586
+ <div class="nav-tab-wrapper">
587
+ <?php $billing_cycles = array( 'monthly', 'annual', 'lifetime' ) ?>
588
+ <?php $i = 0;
589
+ foreach ( $billing_cycles as $cycle ) : ?>
590
+ <?php $prop = "{$cycle}_price";
591
+ if ( isset( $first_pricing->{$prop} ) ) : ?>
592
+ <?php $is_featured = ( 'annual' === $cycle && $is_multi_cycle ) ?>
593
+ <?php
594
+ $prices = array();
595
+ foreach ( $plan->pricing as $pricing ) {
596
+ if ( isset( $pricing->{$prop} ) ) {
597
+ $prices[] = array(
598
+ 'id' => $pricing->id,
599
+ 'licenses' => $pricing->licenses,
600
+ 'price' => $pricing->{$prop}
601
+ );
602
+ }
603
+ }
604
+ ?>
605
+ <a class="nav-tab" data-billing-cycle="<?php echo $cycle ?>"
606
+ data-pricing="<?php esc_attr_e( json_encode( $prices ) ) ?>">
607
+ <?php if ( $is_featured ) : ?>
608
+ <label>&#9733; <?php _efs( 'best', $api->slug ) ?> &#9733;</label>
609
+ <?php endif ?>
610
+ <?php _efs( $cycle, $api->slug ) ?>
611
+ </a>
612
+ <?php endif ?>
613
+ <?php $i ++; endforeach ?>
614
+ <?php wp_enqueue_script( 'jquery' ) ?>
615
+ <script type="text/javascript">
616
+ (function ($, undef) {
617
+ var
618
+ _formatBillingFrequency = function (cycle) {
619
+ switch (cycle) {
620
+ case 'monthly':
621
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('monthly', $api->slug)) ?>';
622
+ case 'annual':
623
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('annually', $api->slug)) ?>';
624
+ case 'lifetime':
625
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('once', $api->slug)) ?>';
626
+ }
627
+ },
628
+ _formatLicensesTitle = function (pricing) {
629
+ switch (pricing.licenses) {
630
+ case 1:
631
+ return '<?php _efs( 'license-single-site', $api->slug ) ?>';
632
+ case null:
633
+ return '<?php _efs( 'license-unlimited', $api->slug ) ?>';
634
+ default:
635
+ return '<?php _efs( 'license-x-sites', $api->slug ) ?>'.replace('%s', pricing.licenses);
636
+ }
637
+ },
638
+ _formatPrice = function (pricing, cycle, multipleLicenses) {
639
+ if (undef === multipleLicenses)
640
+ multipleLicenses = true;
641
+
642
+ var priceCycle;
643
+ switch (cycle) {
644
+ case 'monthly':
645
+ priceCycle = ' / <?php _efs('mo', $api->slug) ?>';
646
+ break;
647
+ case 'lifetime':
648
+ priceCycle = '';
649
+ break;
650
+ case 'annual':
651
+ default:
652
+ priceCycle = ' / <?php _efs('year', $api->slug) ?>';
653
+ break;
654
+ }
655
+
656
+ if (!multipleLicenses && 1 == pricing.licenses) {
657
+ return '$' + pricing.price + priceCycle;
658
+ }
659
+
660
+ return _formatLicensesTitle(pricing) + ' - <var class="fs-price">$' + pricing.price + priceCycle + '</var>';
661
+ },
662
+ _checkoutUrl = function (plan, pricing, cycle) {
663
+ return '<?php echo esc_url_raw(remove_query_arg('billing_cycle', add_query_arg(array('plugin_id' => $plan->plugin_id), $api->checkout_link))) ?>' +
664
+ '&plan_id=' + plan +
665
+ '&pricing_id=' + pricing +
666
+ '&billing_cycle=' + cycle<?php if ($plan->has_trial()) { echo " + '&trial=true'"; }?>;
667
+ },
668
+ _updateCtaUrl = function (plan, pricing, cycle) {
669
+ $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', _checkoutUrl(plan, pricing, cycle));
670
+ };
671
+
672
+ $(document).ready(function () {
673
+ var $plan = $('.plugin-information-pricing .fs-plan[data-plan-id=<?php echo $plan->id ?>]');
674
+ $plan.find('input[type=radio]').live('click', function () {
675
+ _updateCtaUrl(
676
+ $plan.attr('data-plan-id'),
677
+ $(this).val(),
678
+ $plan.find('.nav-tab-active').attr('data-billing-cycle')
679
+ );
680
+
681
+ $plan.find('.fs-trial-terms .fs-price').html(
682
+ $(this).parents('label').find('.fs-price').html()
683
+ );
684
+ });
685
+
686
+ $plan.find('.nav-tab').click(function () {
687
+ if ($(this).hasClass('nav-tab-active'))
688
+ return;
689
+
690
+ var $this = $(this),
691
+ billingCycle = $this.attr('data-billing-cycle'),
692
+ pricing = JSON.parse($this.attr('data-pricing')),
693
+ $pricesList = $this.parents('.fs-plan').find('.fs-pricing-body .fs-licenses'),
694
+ html = '';
695
+
696
+ // Un-select previously selected tab.
697
+ $plan.find('.nav-tab').removeClass('nav-tab-active');
698
+
699
+ // Select current tab.
700
+ $this.addClass('nav-tab-active');
701
+
702
+ // Render licenses prices.
703
+ if (1 == pricing.length) {
704
+ html = '<li><label><?php _efs( 'price', $api->slug ) ?>: ' + _formatPrice(pricing[0], billingCycle, false) + '</label></li>';
705
+ } else {
706
+ for (var i = 0; i < pricing.length; i++) {
707
+ html += '<li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" value="' + pricing[i].id + '">' + _formatPrice(pricing[i], billingCycle) + '</label></li>';
708
+ }
709
+ }
710
+ $pricesList.html(html);
711
+
712
+ if (1 < pricing.length) {
713
+ // Select first license option.
714
+ $pricesList.find('li:first input').click();
715
+ }
716
+ else {
717
+ _updateCtaUrl(
718
+ $plan.attr('data-plan-id'),
719
+ pricing[0].id,
720
+ billingCycle
721
+ );
722
+ }
723
+
724
+ // Update billing frequency.
725
+ $plan.find('.fs-billing-frequency').html(_formatBillingFrequency(billingCycle));
726
+
727
+ if ('annual' === billingCycle) {
728
+ $plan.find('.fs-annual-discount').show();
729
+ } else {
730
+ $plan.find('.fs-annual-discount').hide();
731
+ }
732
+ });
733
+
734
+ <?php if ( $has_annual ) : ?>
735
+ // Select annual by default.
736
+ $plan.find('.nav-tab[data-billing-cycle=annual]').click();
737
+ <?php else : ?>
738
+ // Select first tab.
739
+ $plan.find('.nav-tab:first').click();
740
+ <?php endif ?>
741
+ });
742
+ }(jQuery));
743
+ </script>
744
+ </div>
745
+ <div class="fs-pricing-body">
746
+ <span class="fs-billing-frequency"></span>
747
+ <?php $annual_discount = ( $has_annual && $has_monthly ) ? $plan->pricing[0]->annual_discount_percentage() : 0 ?>
748
+ <?php if ( $annual_discount > 0 ) : ?>
749
+ <span
750
+ class="fs-annual-discount"><?php printf( __fs( 'save-x', $api->slug ), $annual_discount . '%' ) ?></span>
751
+ <?php endif ?>
752
+ <ul class="fs-licenses">
753
+ </ul>
754
+ <?php echo $this->get_plugin_cta( $api, $plan ) ?>
755
+ <div style="clear:both"></div>
756
+ <?php if ( $plan->has_trial() ) : ?>
757
+ <?php $trial_period = $this->get_trial_period( $plan ) ?>
758
+ <ul class="fs-trial-terms">
759
+ <li>
760
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'no-commitment-x', $api->slug ), $trial_period ) ?>
761
+ </li>
762
+ <li>
763
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'after-x-pay-as-little-y', $api->slug ), $trial_period, '<var class="fs-price">' . $this->get_price_tag( $plan, $plan->pricing[0] ) . '</var>' ) ?>
764
+ </li>
765
+ </ul>
766
+ <?php endif ?>
767
+ </div>
768
+ </div>
769
+ </div>
770
+ <?php endforeach ?>
771
+ <?php endif ?>
772
+ <?php endif ?>
773
+ <div>
774
+ <h3><?php _efs( 'details', $api->slug ) ?></h3>
775
+ <ul>
776
+ <?php if ( ! empty( $api->version ) ) { ?>
777
+ <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
778
+ <?php
779
+ }
780
+ if ( ! empty( $api->author ) ) {
781
+ ?>
782
+ <li>
783
+ <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?>
784
+ </li>
785
+ <?php
786
+ }
787
+ if ( ! empty( $api->last_updated ) ) {
788
+ ?>
789
+ <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span
790
+ title="<?php echo $api->last_updated; ?>">
791
+ <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
792
+ </span></li>
793
+ <?php
794
+ }
795
+ if ( ! empty( $api->requires ) ) {
796
+ ?>
797
+ <li>
798
+ <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?>
799
+ </li>
800
+ <?php
801
+ }
802
+ if ( ! empty( $api->tested ) ) {
803
+ ?>
804
+ <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?>
805
+ </li>
806
+ <?php
807
+ }
808
+ if ( ! empty( $api->downloaded ) ) {
809
+ ?>
810
+ <li>
811
+ <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?>
812
+ </li>
813
+ <?php
814
+ }
815
+ if ( ! empty( $api->slug ) && empty( $api->external ) ) {
816
+ ?>
817
+ <li><a target="_blank"
818
+ href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a>
819
+ </li>
820
+ <?php
821
+ }
822
+ if ( ! empty( $api->homepage ) ) {
823
+ ?>
824
+ <li><a target="_blank"
825
+ href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a>
826
+ </li>
827
+ <?php
828
+ }
829
+ if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) {
830
+ ?>
831
+ <li><a target="_blank"
832
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
833
+ </li>
834
+ <?php } ?>
835
+ </ul>
836
+ </div>
837
+ <?php if ( ! empty( $api->rating ) ) { ?>
838
+ <h3><?php _e( 'Average Rating' ); ?></h3>
839
+ <?php wp_star_rating( array(
840
+ 'rating' => $api->rating,
841
+ 'type' => 'percent',
842
+ 'number' => $api->num_ratings
843
+ ) ); ?>
844
+ <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
845
+ <?php
846
+ }
847
+
848
+ if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
849
+ foreach ( $api->ratings as $key => $ratecount ) {
850
+ // Avoid div-by-zero.
851
+ $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
852
+ ?>
853
+ <div class="counter-container">
854
+ <span class="counter-label"><a
855
+ href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
856
+ target="_blank"
857
+ 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>
858
+ <span class="counter-back">
859
+ <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
860
+ </span>
861
+ <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
862
+ </div>
863
+ <?php
864
+ }
865
+ }
866
+ if ( ! empty( $api->contributors ) ) {
867
+ ?>
868
+ <h3><?php _e( 'Contributors' ); ?></h3>
869
+ <ul class="contributors">
870
+ <?php
871
+ foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
872
+ if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
873
+ continue;
874
+ }
875
+ if ( empty( $contrib_username ) ) {
876
+ $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
877
+ }
878
+ $contrib_username = sanitize_user( $contrib_username );
879
+ if ( empty( $contrib_profile ) ) {
880
+ echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
881
+ } else {
882
+ 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>";
883
+ }
884
+ }
885
+ ?>
886
+ </ul>
887
+ <?php if ( ! empty( $api->donate_link ) ) { ?>
888
+ <a target="_blank"
889
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
890
+ <?php } ?>
891
+ <?php } ?>
892
+ </div>
893
+ <div id="section-holder" class="wrap">
894
+ <?php
895
+ if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
896
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>';
897
+ } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
898
+ 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>';
899
+ }
900
+
901
+ foreach ( (array) $api->sections as $section_name => $content ) {
902
+ $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
903
+ $content = links_add_target( $content, '_blank' );
904
+
905
+ $san_section = esc_attr( $section_name );
906
+
907
+ $display = ( $section_name === $section ) ? 'block' : 'none';
908
+
909
+ if ( 'description' === $section_name &&
910
+ ( ( ! $api->external && $api->wp_org_missing ) ||
911
+ ( $api->external && $api->fs_missing ) )
912
+ ) {
913
+ $missing_notice = array(
914
+ 'type' => 'error',
915
+ 'id' => md5( microtime() ),
916
+ 'message' => __fs( ( $api->is_paid ? 'paid-addon-not-deployed' : 'free-addon-not-deployed' ), $api->slug ),
917
+ );
918
+ fs_require_template( 'admin-notice.php', $missing_notice );
919
+ }
920
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
921
+ echo $content;
922
+ echo "\t</div>\n";
923
+ }
924
+ echo "</div>\n";
925
+ echo "</div>\n";
926
+ echo "</div>\n"; // #plugin-information-scrollable
927
+ echo "<div id='$tab-footer'>\n";
928
+
929
+ echo $this->get_plugin_cta( $api );
930
+
931
+ echo "</div>\n";
932
+
933
+ iframe_footer();
934
+ exit;
935
+ }
936
+ }
freemius/includes/i18n.php ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 'cancel-trial' => __( 'Cancel Trial', 'freemius' ),
49
+ 'free-trial' => __( 'Free Trial', 'freemius' ),
50
+ 'start-free-x' => __( 'Start my free %s', 'freemius' ),
51
+ 'no-commitment-x' => __( 'No commitment for %s - cancel anytime', 'freemius' ),
52
+ 'after-x-pay-as-little-y' => __( 'After your free %s, pay as little as %s', 'freemius' ),
53
+ 'details' => __( 'Details', 'freemius' ),
54
+ 'account-details' => __( 'Account Details', 'freemius' ),
55
+ 'delete' => _x( 'Delete', 'verb', 'freemius' ),
56
+ 'delete-account' => __( 'Delete Account', 'freemius' ),
57
+ 'dismiss' => _x( 'Dismiss', 'as close a window', 'freemius' ),
58
+ 'plan' => _x( 'Plan', 'as product pricing plan', 'freemius' ),
59
+ 'change-plan' => __( 'Change Plan', 'freemius' ),
60
+ 'download-x-version' => _x( 'Download %s Version', 'as download professional version', 'freemius' ),
61
+ 'download-x-version-now' => _x( 'Download %s version now', 'as download professional version now', 'freemius' ),
62
+ 'download-latest' => _x( 'Download Latest', 'as download latest version', 'freemius' ),
63
+ 'you-have-x-license' => _x( 'You have a %s license.', 'E.g. you have a professional license.', 'freemius' ),
64
+ 'new' => __( 'New', 'freemius' ),
65
+ 'free' => __( 'Free', 'freemius' ),
66
+ 'trial' => _x( 'Trial', 'as trial plan', 'freemius' ),
67
+ 'purchase' => _x( 'Purchase', 'verb', 'freemius' ),
68
+ 'purchase-license' => __( 'Purchase License', 'freemius' ),
69
+ 'buy' => _x( 'Buy', 'verb', 'freemius' ),
70
+ 'buy-license' => __( 'Buy License', 'freemius' ),
71
+ 'license-single-site' => __( 'Single Site License', 'freemius' ),
72
+ 'license-unlimited' => __( 'Unlimited Licenses', 'freemius' ),
73
+ 'license-x-sites' => __( 'Up to %s Sites', 'freemius' ),
74
+ 'renew-license-now' => __( '%sRenew your license now%s to access version %s features and support.', 'freemius' ),
75
+ 'x-plan' => _x( '%s Plan', 'e.g. Professional Plan', 'freemius' ),
76
+ 'you-are-step-away' => __( 'You are just one step away - %s', 'freemius' ),
77
+ 'activate-x-now' => _x( 'Complete "%s" Activation Now', '%s - plugin name. As complete "Jetpack" activation now', 'freemius' ),
78
+ 'few-plugin-tweaks' => __( 'We made a few tweaks to the plugin, %s', 'freemius' ),
79
+ 'optin-x-now' => __( 'Opt-in to make "%s" Better!', 'freemius' ),
80
+ 'error' => __( 'Error', 'freemius' ),
81
+ 'failed-finding-main-path' => __( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'freemius' ),
82
+ #region Account
83
+
84
+ 'expiration' => _x( 'Expiration', 'as expiration date', 'freemius' ),
85
+ 'license' => _x( 'License', 'as software license', 'freemius' ),
86
+ 'not-verified' => __( 'not verified', 'freemius' ),
87
+ 'verify-email' => __( 'Verify Email', 'freemius' ),
88
+ 'expires-in' => _x( 'Expires in %s', 'e.g. expires in 2 months', 'freemius' ),
89
+ 'renews-in' => _x( 'Auto renews in %s', 'e.g. auto renews in 2 months', 'freemius' ),
90
+ 'no-expiration' => __( 'No expiration', 'freemius' ),
91
+ 'expired' => __( 'Expired', 'freemius' ),
92
+ 'cancelled' => __( 'Cancelled', 'freemius' ),
93
+ 'in-x' => _x( 'In %s', 'e.g. In 2 hours', 'freemius' ),
94
+ 'x-ago' => _x( '%s ago', 'e.g. 2 min ago', 'freemius' ),
95
+ 'version' => _x( 'Version', 'as plugin version', 'freemius' ),
96
+ 'name' => __( 'Name', 'freemius' ),
97
+ 'email' => __( 'Email', 'freemius' ),
98
+ 'verified' => __( 'Verified', 'freemius' ),
99
+ 'plugin' => __( 'Plugin', 'freemius' ),
100
+ 'plugins' => __( 'Plugins', 'freemius' ),
101
+ 'themes' => __( 'Themes', 'freemius' ),
102
+ 'path' => _x( 'Path', 'as file/folder path', 'freemius' ),
103
+ 'title' => __( 'Title', 'freemius' ),
104
+ 'free-version' => __( 'Free version', 'freemius' ),
105
+ 'premium-version' => __( 'Premium version', 'freemius' ),
106
+ 'slug' => _x( 'Slug', 'as WP plugin slug', 'freemius' ),
107
+ 'id' => __( 'ID', 'freemius' ),
108
+ 'users' => __( 'Users', 'freemius' ),
109
+ 'plugin-installs' => __( 'Plugin Installs', 'freemius' ),
110
+ 'sites' => _x( 'Sites', 'like websites', 'freemius' ),
111
+ 'user-id' => __( 'User ID', 'freemius' ),
112
+ 'site-id' => __( 'Site ID', 'freemius' ),
113
+ 'public-key' => __( 'Public Key', 'freemius' ),
114
+ 'secret-key' => __( 'Secret Key', 'freemius' ),
115
+ 'no-secret' => _x( 'No Secret', 'as secret encryption key missing', 'freemius' ),
116
+ 'no-id' => __( 'No ID', 'freemius' ),
117
+ 'sync-license' => _x( 'Sync License', 'as synchronize license', 'freemius' ),
118
+ 'sync' => _x( 'Sync', 'as synchronize', 'freemius' ),
119
+ 'deactivate-license' => __( 'Deactivate License', 'freemius' ),
120
+ 'activate' => __( 'Activate', 'freemius' ),
121
+ 'deactivate' => __( 'Deactivate', 'freemius' ),
122
+ 'skip-deactivate' => __( 'Skip & Deactivate', 'freemius' ),
123
+ 'no-deactivate' => __( 'No - just deactivate', 'freemius' ),
124
+ 'yes-do-your-thing' => __( 'Yes - do your thing', 'freemius' ),
125
+ 'active' => _x( 'Active', 'active mode', 'freemius' ),
126
+ 'is-active' => _x( 'Is Active', 'is active mode?', 'freemius' ),
127
+ 'install-now' => __( 'Install Now', 'freemius' ),
128
+ 'install-update-now' => __( 'Install Update Now', 'freemius' ),
129
+ 'more-information-about-x' => __( 'More information about %s', 'freemius' ),
130
+ 'localhost' => __( 'Localhost', 'freemius' ),
131
+ 'activate-x-plan' => _x( 'Activate %s Plan', 'as activate Professional plan', 'freemius' ),
132
+ 'x-left' => _x( '%s left', 'as 5 licenses left', 'freemius' ),
133
+ 'last-license' => __( 'Last license', 'freemius' ),
134
+ 'what-is-your-x' => __( 'What is your %s?', 'freemius' ),
135
+ 'activate-this-addon' => __( 'Activate this add-on', 'freemius' ),
136
+ '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' ),
137
+ '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' ),
138
+ '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' ),
139
+ 'downgrade-x-confirm' => __( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'freemius' ),
140
+ 'cancel-trial-confirm' => __( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'freemius' ),
141
+ 'after-downgrade-non-blocking' => __( 'You can still enjoy all %s features but you will not have access to plugin updates and support.', 'freemius' ),
142
+ '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' ),
143
+ 'proceed-confirmation' => __( 'Are you sure you want to proceed?', 'freemius' ),
144
+ #endregion Account
145
+
146
+ 'add-ons-for-x' => __( 'Add Ons for %s', 'freemius' ),
147
+ 'add-ons-missing' => __( 'We could\'nt load the add-ons list. It\'s probably an issue on our side, please try to come back in few minutes.', 'freemius' ),
148
+ #region Plugin Deactivation
149
+ 'deactivation-share-reason' => __( 'If you have a moment, please let us know why you are deactivating', 'freemius' ),
150
+ 'deactivation-modal-button-confirm' => __( 'Yes - Deactivate', 'freemius' ),
151
+ 'deactivation-modal-button-submit' => __( 'Submit & Deactivate', 'freemius' ),
152
+ 'deactivation-modal-button-cancel' => _x( 'Cancel', 'the text of the cancel button of the plugin deactivation dialog box.', 'freemius' ),
153
+ 'reason-no-longer-needed' => __( 'I no longer need the plugin', 'freemius' ),
154
+ 'reason-found-a-better-plugin' => __( 'I found a better plugin', 'freemius' ),
155
+ 'reason-needed-for-a-short-period' => __( 'I only needed the plugin for a short period', 'freemius' ),
156
+ 'reason-broke-my-site' => __( 'The plugin broke my site', 'freemius' ),
157
+ 'reason-suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'freemius' ),
158
+ 'reason-cant-pay-anymore' => __( "I can't pay for it anymore", 'freemius' ),
159
+ 'reason-temporary-deactivation' => __( "It's a temporary deactivation. I'm just debugging an issue.", 'freemius' ),
160
+ 'reason-other' => _x( 'Other', 'the text of the "other" reason for deactivating the plugin that is shown in the modal box.', 'freemius' ),
161
+ 'ask-for-reason-message' => __( 'Kindly tell us the reason so we can improve.', 'freemius' ),
162
+ 'placeholder-plugin-name' => __( "What's the plugin's name?", 'freemius' ),
163
+ 'placeholder-comfortable-price' => __( 'What price would you feel comfortable paying?', 'freemius' ),
164
+ 'reason-couldnt-make-it-work' => __( "I couldn't understand how to make it work", 'freemius' ),
165
+ 'reason-great-but-need-specific-feature' => __( "The plugin is great, but I need specific feature that you don't support", 'freemius' ),
166
+ 'reason-not-working' => __( 'The plugin is not working', 'freemius' ),
167
+ 'reason-not-what-i-was-looking-for' => __( "It's not what I was looking for", 'freemius' ),
168
+ 'reason-didnt-work-as-expected' => __( "The plugin didn't work as expected", 'freemius' ),
169
+ 'placeholder-feature' => __( 'What feature?', 'freemius' ),
170
+ 'placeholder-share-what-didnt-work' => __( "Kindly share what didn't work so we can fix it for future users...", 'freemius' ),
171
+ 'placeholder-what-youve-been-looking-for' => __( "What you've been looking for?", 'freemius' ),
172
+ 'placeholder-what-did-you-expect' => __( "What did you expect?", 'freemius' ),
173
+ 'reason-didnt-work' => __( "The plugin didn't work", 'freemius' ),
174
+ 'reason-dont-like-to-share-my-information' => __( "I don't like to share my information with you", 'freemius' ),
175
+ #endregion Plugin Deactivation
176
+
177
+ #region Connect
178
+ 'hey-x' => _x( 'Hey %s,', 'greeting', 'freemius' ),
179
+ 'thanks-x' => _x( 'Thanks %s!', 'a greeting. E.g. Thanks John!', 'freemius' ),
180
+ 'connect-message' => __( 'In order to enjoy all our features and functionality, %s needs to connect your user, %s at %s, to %s', 'freemius' ),
181
+ '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' ),
182
+ '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' ),
183
+ 'what-permissions' => __( 'What permissions are being granted?', 'freemius' ),
184
+ 'permissions-profile' => __( 'Your Profile Overview', 'freemius' ),
185
+ 'permissions-profile_desc' => __( 'Name and email address', 'freemius' ),
186
+ 'permissions-site' => __( 'Your Site Overview', 'freemius' ),
187
+ 'permissions-site_desc' => __( 'Site URL, WP version, PHP info, plugins & themes', 'freemius' ),
188
+ 'permissions-events' => __( 'Current Plugin Events', 'freemius' ),
189
+ 'permissions-events_desc' => __( 'Activation, deactivation and uninstall', 'freemius' ),
190
+ 'permissions-plugins_themes' => __( 'Plugins & Themes', 'freemius' ),
191
+ 'permissions-plugins_themes_desc' => __( 'Titles, versions and state.', 'freemius' ),
192
+ 'permissions-newsletter' => __( 'Newsletter', 'freemius' ),
193
+ 'permissions-newsletter_desc' => __( 'Updates, announcements, marketing, no spam', 'freemius' ),
194
+ 'privacy-policy' => __( 'Privacy Policy', 'freemius' ),
195
+ 'tos' => __( 'Terms of Service', 'freemius' ),
196
+ 'activating' => _x( 'Activating', 'as activating plugin', 'freemius' ),
197
+ 'sending-email' => _x( 'Sending email', 'as in the process of sending an email', 'freemius' ),
198
+ 'opt-in-connect' => _x( 'Allow & Continue', 'button label', 'freemius' ),
199
+ 'skip' => _x( 'Skip', 'verb', 'freemius' ),
200
+ 'resend-activation-email' => __( 'Re-send activation email', 'freemius' ),
201
+ #endregion Connect
202
+
203
+ #region Screenshots
204
+ 'screenshots' => __( 'Screenshots', 'freemius' ),
205
+ 'view-full-size-x' => __( 'Click to view full-size screenshot %d', 'freemius' ),
206
+ #endregion Screenshots
207
+
208
+ #region Debug
209
+ 'freemius-debug' => __( 'Freemius Debug', 'freemius' ),
210
+ 'on' => _x( 'On', 'as turned on', 'freemius' ),
211
+ 'off' => _x( 'Off', 'as turned off', 'freemius' ),
212
+ 'debugging' => _x( 'Debugging', 'as code debugging', 'freemius' ),
213
+ 'freemius-state' => __( 'Freemius State', 'freemius' ),
214
+ 'connected' => _x( 'Connected', 'as connection was successful', 'freemius' ),
215
+ 'blocked' => _x( 'Blocked', 'as connection blocked', 'freemius' ),
216
+ 'api' => _x( 'API', 'as application program interface', 'freemius' ),
217
+ 'sdk' => _x( 'SDK', 'as software development kit versions', 'freemius' ),
218
+ 'sdk-versions' => _x( 'SDK Versions', 'as software development kit versions', 'freemius' ),
219
+ 'plugin-path' => _x( 'Plugin Path', 'as plugin folder path', 'freemius' ),
220
+ 'sdk-path' => _x( 'SDK Path', 'as sdk path', 'freemius' ),
221
+ 'addons-of-x' => __( 'Add Ons of Plugin %s', 'freemius' ),
222
+ 'delete-all-confirm' => __( 'Are you sure you want to delete all Freemius data?', 'freemius' ),
223
+ 'actions' => __( 'Actions', 'freemius' ),
224
+ 'delete-all-accounts' => __( 'Delete All Accounts', 'freemius' ),
225
+ 'start-fresh' => __( 'Start Fresh', 'freemius' ),
226
+ 'clear-api-cache' => __( 'Clear API Cache', 'freemius' ),
227
+ 'sync-data-from-server' => __( 'Sync Data From Server', 'freemius' ),
228
+ 'scheduled-crons' => __( 'Scheduled Crons', 'freemius' ),
229
+ 'plugins-themes-sync' => __( 'Plugins & Themes Sync', 'freemius' ),
230
+ #endregion Debug
231
+
232
+ #region Expressions
233
+ 'congrats' => _x( 'Congrats', 'as congratulations', 'freemius' ),
234
+ 'oops' => _x( 'Oops', 'exclamation', 'freemius' ),
235
+ 'yee-haw' => _x( 'Yee-haw', 'interjection expressing joy or exuberance', 'freemius' ),
236
+ 'woot' => _x( 'W00t', '(especially in electronic communication) used to express elation, enthusiasm, or triumph.', 'freemius' ),
237
+ 'right-on' => _x( 'Right on', 'a positive response', 'freemius' ),
238
+ 'hmm' => _x( 'Hmm', 'something somebody says when they are thinking about what you have just said. ', 'freemius' ),
239
+ 'ok' => __( 'O.K', 'freemius' ),
240
+ 'hey' => _x( 'Hey', 'exclamation', 'freemius' ),
241
+ 'heads-up' => _x( 'Heads up', 'advance notice of something that will need attention.', 'freemius' ),
242
+ #endregion Expressions
243
+
244
+ #region Admin Notices
245
+ 'you-have-latest' => __( 'Seems like you got the latest release.', 'freemius' ),
246
+ 'you-are-good' => __( 'You are all good!', 'freemius' ),
247
+ 'user-exist-message' => __( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'freemius' ),
248
+ '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' ),
249
+ 'email-updated-message' => __( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'freemius' ),
250
+ 'name-updated-message' => __( 'Your name was successfully updated.', 'freemius' ),
251
+ 'x-updated' => __( 'You have successfully updated your %s.', 'freemius' ),
252
+ 'name-update-failed-message' => __( 'Please provide your full name.', 'freemius' ),
253
+ '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' ),
254
+ 'addons-info-external-message' => __( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'freemius' ),
255
+ 'no-cc-required' => __( 'No credit card required', 'freemius' ),
256
+ 'premium-activated-message' => __( 'Premium plugin version was successfully activated.', 'freemius' ),
257
+ 'successful-version-upgrade-message' => __( 'The upgrade of %s was successfully completed.', 'freemius' ),
258
+ 'activation-with-plan-x-message' => __( 'Your account was successfully activated with the %s plan.', 'freemius' ),
259
+ 'download-latest-x-version' => __( 'Download the latest %s version now', 'freemius' ),
260
+ 'download-latest-version' => __( 'Download the latest version now', 'freemius' ),
261
+ 'addon-successfully-purchased-message' => _x( '%s Add-on was successfully purchased.', '%s - product name, e.g. Facebook add-on was successfully...', 'freemius' ),
262
+ 'addon-successfully-upgraded-message' => __( 'Your %s Add-on plan was successfully upgraded.', 'freemius' ),
263
+ 'email-verified-message' => __( 'Your email has been successfully verified - you are AWESOME!', 'freemius' ),
264
+ 'plan-upgraded-message' => __( 'Your plan was successfully upgraded.', 'freemius' ),
265
+ 'plan-changed-to-x-message' => __( 'Your plan was successfully changed to %s.', 'freemius' ),
266
+ 'license-expired-blocking-message' => __( 'Your license has expired. You can still continue using the free plugin forever.', 'freemius' ),
267
+ 'trial-started-message' => __( 'Your trial has been successfully started.', 'freemius' ),
268
+ 'license-activated-message' => __( 'Your license was successfully activated.', 'freemius' ),
269
+ 'no-active-license-message' => __( 'It looks like your site currently doesn\'t have an active license.', 'freemius' ),
270
+ 'license-deactivation-message' => __( 'Your license was successfully deactivated, you are back to the %s plan.', 'freemius' ),
271
+ 'license-deactivation-failed-message' => __( 'It looks like the license deactivation failed.', 'freemius' ),
272
+ 'license-activation-failed-message' => __( 'It looks like the license could not be activated.', 'freemius' ),
273
+ 'server-error-message' => __( 'Error received from the server:', 'freemius' ),
274
+ 'trial-expired-message' => __( 'Your trial has expired. You can still continue using all our free features.', 'freemius' ),
275
+ 'plan-x-downgraded-message' => __( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'freemius' ),
276
+ 'plan-downgraded-failure-message' => __( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'freemius' ),
277
+ 'trial-cancel-no-trial-message' => __( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'freemius' ),
278
+ 'trial-cancel-message' => __( 'Your %s free trial was successfully cancelled.', 'freemius' ),
279
+ 'version-x-released' => _x( 'Version %s was released.', '%s - numeric version number', 'freemius' ),
280
+ 'please-download-x' => __( 'Please download %s.', 'freemius' ),
281
+ 'latest-x-version' => _x( 'the latest %s version here', '%s - plan name, as the latest professional version here', 'freemius' ),
282
+ 'trial-x-promotion-message' => __( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'freemius' ),
283
+ 'start-free-trial' => _x( 'Start free trial', 'call to action', 'freemius' ),
284
+ 'trial-cancel-failure-message' => __( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'freemius' ),
285
+ 'trial-utilized' => __( 'You already utilized a trial before.', 'freemius' ),
286
+ 'in-trial-mode' => __( 'You are already running the plugin in a trial mode.', 'freemius' ),
287
+ 'trial-plan-x-not-exist' => __( 'Plan %s do not exist, therefore, can\'t start a trial.', 'freemius' ),
288
+ 'plan-x-no-trial' => __( 'Plan %s does not support a trial period.', 'freemius' ),
289
+ 'no-trials' => __( 'None of the plugin\'s plans supports a trial period.', 'freemius' ),
290
+ 'unexpected-api-error' => __( 'Unexpected API error. Please contact the plugin\'s author with the following error.', 'freemius' ),
291
+ 'no-commitment-for-x-days' => __( 'No commitment for %s days - cancel anytime!', 'freemius' ),
292
+ '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' ),
293
+ 'could-not-activate-x' => __( 'Couldn\'t activate %s.', 'freemius' ),
294
+ 'contact-us-with-error-message' => __( 'Please contact us with the following message:', 'freemius' ),
295
+ 'plan-did-not-change-message' => __( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'freemius' ),
296
+ 'contact-us-here' => __( 'Please contact us here', 'freemius' ),
297
+ 'plan-did-not-change-email-message' => __( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'freemius' ),
298
+ #endregion Admin Notices
299
+ #region Connectivity Issues
300
+ 'connectivity-test-fails-message' => __( 'From unknown reason, the API connectivity test failed.', 'freemius' ),
301
+ 'connectivity-test-maybe-temporary' => __( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'freemius' ),
302
+ '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' ),
303
+ 'cloudflare-blocks-connection-message' => __( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'freemius' ),
304
+ 'x-requires-access-to-api' => _x( '%s requires an access to our API.', 'as pluginX requires an access to our API', 'freemius' ),
305
+ 'squid-blocks-connection-message' => __( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'freemius' ),
306
+ 'squid-no-clue-title' => __( 'I don\'t know what is Squid or ACL, help me!', 'freemius' ),
307
+ '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' ),
308
+ 'sysadmin-title' => __( 'I\'m a system administrator', 'freemius' ),
309
+ 'squid-sysadmin-desc' => __( 'Great, please whitelist the following domains: %s. Once you done, deactivate the plugin and activate it again.', 'freemius' ),
310
+ 'curl-missing-no-clue-title' => __( 'I don\'t know what is cURL or how to install it, help me!', 'freemius' ),
311
+ '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' ),
312
+ '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' ),
313
+ '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' ),
314
+ 'fix-issue-title' => __( 'Yes - I\'m giving you a chance to fix it', 'freemius' ),
315
+ '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' ),
316
+ 'install-previous-title' => __( 'Let\'s try your previous version', 'freemius' ),
317
+ 'install-previous-desc' => __( 'Uninstall this version and install the previous one.', 'freemius' ),
318
+ 'deactivate-plugin-title' => __( 'That\'s exhausting, please deactivate', 'freemius' ),
319
+ 'deactivate-plugin-desc' => __( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'freemius' ),
320
+ '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' ),
321
+ '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' ),
322
+ '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' ),
323
+ #endregion Connectivity Issues
324
+ #region Change Owner
325
+ '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' ),
326
+ 'change-owner-request_owner-confirmed' => __( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'freemius' ),
327
+ 'change-owner-request_candidate-confirmed' => __( '%s is the new owner of the account.', 'freemius' ),
328
+ #endregion Change Owner
329
+ 'addon-x-cannot-run-without-y' => _x( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'freemius' ),
330
+ 'addon-x-cannot-run-without-parent' => _x( '%s cannot run without the plugin.', 'addonX cannot run...', 'freemius' ),
331
+ 'plugin-x-activation-message' => _x( '%s activation was successfully completed.', 'pluginX activation was successfully...', 'freemius' ),
332
+ 'features-and-pricing' => _x( 'Features & Pricing', 'Plugin installer section title', 'freemius' ),
333
+ 'free-addon-not-deployed' => __( 'Add-on must be deployed to WordPress.org or Freemius.', 'freemius' ),
334
+ 'paid-addon-not-deployed' => __( 'Paid add-on must be deployed to Freemius.', 'freemius' ),
335
+ #region Add-On Licensing
336
+ 'addon-no-license-message' => __( '%s is a premium only add-on. You have to purchase a license first before activating the plugin.', 'freemius' ),
337
+ 'addon-trial-cancelled-message' => __( '%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.', 'freemius' ),
338
+ #endregion Add-On Licensing
339
+ #region Billing Cycles
340
+ 'monthly' => _x( 'Monthly', 'as every month', 'freemius' ),
341
+ 'mo' => _x( 'mo', 'as monthly period', 'freemius' ),
342
+ 'annual' => _x( 'Annual', 'as once a year', 'freemius' ),
343
+ 'annually' => _x( 'Annually', 'as once a year', 'freemius' ),
344
+ 'once' => _x( 'Once', 'as once a year', 'freemius' ),
345
+ 'year' => _x( 'year', 'as annual period', 'freemius' ),
346
+ 'lifetime' => __( 'Lifetime', 'freemius' ),
347
+ 'best' => _x( 'Best', 'e.g. the best product', 'freemius' ),
348
+ 'billed-x' => _x( 'Billed %s', 'e.g. billed monthly', 'freemius' ),
349
+ 'save-x' => _x( 'Save %s', 'as a discount of $5 or 10%', 'freemius' ),
350
+ #endregion Billing Cycles
351
+ 'view-details' => __( 'View details', 'freemius' ),
352
+ );
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,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ( function_exists( 'current_user_can' ) &&
133
+ ! current_user_can( 'manage_options' )
134
+ ) {
135
+ // Only show messages to admins.
136
+ return;
137
+ }
138
+
139
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
140
+ return;
141
+ }
142
+
143
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
144
+ fs_require_template( 'admin-notice.php', $msg );
145
+
146
+ if ( $msg['sticky'] ) {
147
+ self::has_sticky_messages();
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Handle all_admin_notices by printing the admin messages stacked in the queue.
154
+ *
155
+ * @author Vova Feldman (@svovaf)
156
+ * @since 1.0.4
157
+ *
158
+ */
159
+ function _all_admin_notices_hook() {
160
+ $notice_type = 'all_admin_notices';
161
+
162
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
163
+ return;
164
+ }
165
+
166
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
167
+ fs_require_template( 'all-admin-notice.php', $msg );
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Enqueue common stylesheet to style admin notice.
173
+ *
174
+ * @author Vova Feldman (@svovaf)
175
+ * @since 1.0.7
176
+ */
177
+ function _enqueue_styles() {
178
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
179
+ }
180
+
181
+ /**
182
+ * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @param string $message
188
+ * @param string $title
189
+ * @param string $type
190
+ * @param bool $is_sticky
191
+ * @param bool $all_admin
192
+ * @param string $id Message ID
193
+ * @param bool $store_if_sticky
194
+ *
195
+ * @uses add_action()
196
+ */
197
+ function add( $message, $title = '', $type = 'success', $is_sticky = false, $all_admin = false, $id = '', $store_if_sticky = true ) {
198
+ $key = ( $all_admin ? 'all_admin_notices' : 'admin_notices' );
199
+
200
+ if ( ! isset( $this->_admin_messages[ $key ] ) ) {
201
+ $this->_admin_messages[ $key ] = array();
202
+
203
+ add_action( $key, array( &$this, "_{$key}_hook" ) );
204
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_styles' ) );
205
+
206
+ }
207
+
208
+ if ( '' === $id ) {
209
+ $id = md5( $title . ' ' . $message . ' ' . $type );
210
+ }
211
+
212
+ $message_object = array(
213
+ 'message' => $message,
214
+ 'title' => $title,
215
+ 'type' => $type,
216
+ 'sticky' => $is_sticky,
217
+ 'id' => $id,
218
+ 'all' => $all_admin,
219
+ 'slug' => $this->_slug,
220
+ 'plugin' => $this->_title,
221
+ );
222
+
223
+ if ( $is_sticky && $store_if_sticky ) {
224
+ $this->_sticky_storage->{$id} = $message_object;
225
+ }
226
+
227
+ $this->_admin_messages[ $key ][ $id ] = $message_object;
228
+ }
229
+
230
+ /**
231
+ * @author Vova Feldman (@svovaf)
232
+ * @since 1.0.7
233
+ *
234
+ * @param string $ids
235
+ */
236
+ function remove_sticky( $ids ) {
237
+ if ( ! is_array( $ids ) ) {
238
+ $ids = array( $ids );
239
+ }
240
+
241
+ foreach ( $ids as $id ) {
242
+ // Remove from sticky storage.
243
+ $this->_sticky_storage->remove( $id );
244
+
245
+ // Remove from current admin messages.
246
+ if ( isset( $this->_admin_messages['all_admin_notices'] ) && isset( $this->_admin_messages['all_admin_notices'][ $id ] ) ) {
247
+ unset( $this->_admin_messages['all_admin_notices'][ $id ] );
248
+ }
249
+ if ( isset( $this->_admin_messages['admin_notices'] ) && isset( $this->_admin_messages['admin_notices'][ $id ] ) ) {
250
+ unset( $this->_admin_messages['admin_notices'][ $id ] );
251
+ }
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Check if sticky message exists by id.
257
+ *
258
+ * @author Vova Feldman (@svovaf)
259
+ * @since 1.0.9
260
+ *
261
+ * @param $id
262
+ *
263
+ * @return bool
264
+ */
265
+ function has_sticky( $id ) {
266
+ return isset( $this->_sticky_storage[ $id ] );
267
+ }
268
+
269
+ /**
270
+ * Adds sticky admin notification.
271
+ *
272
+ * @author Vova Feldman (@svovaf)
273
+ * @since 1.0.7
274
+ *
275
+ * @param string $message
276
+ * @param string $id Message ID
277
+ * @param string $title
278
+ * @param string $type
279
+ * @param bool $all_admin
280
+ */
281
+ function add_sticky( $message, $id, $title = '', $type = 'success', $all_admin = false ) {
282
+ $this->add( $message, $title, $type, true, $all_admin, $id );
283
+ }
284
+
285
+ /**
286
+ * Clear all sticky messages.
287
+ *
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.0.8
290
+ */
291
+ function clear_all_sticky() {
292
+ $this->_sticky_storage->clear_all();
293
+ }
294
+
295
+ /**
296
+ * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
297
+ *
298
+ * @author Vova Feldman (@svovaf)
299
+ * @since 1.0.4
300
+ *
301
+ * @param string $message
302
+ * @param string $title
303
+ * @param string $type
304
+ * @param bool $is_sticky
305
+ * @param string $id Message ID
306
+ */
307
+ function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
308
+ $this->add( $message, $title, $type, $is_sticky, true, $id );
309
+ }
310
+ }
freemius/includes/managers/class-fs-cache-manager.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Get cached record expiration, or false if not cached or expired.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.7.3
203
+ *
204
+ * @param string $key
205
+ *
206
+ * @return bool|int
207
+ */
208
+ function get_record_expiration( $key ) {
209
+ $this->_logger->entrance( 'key = ' . $key );
210
+
211
+ $cache_entry = $this->_options->get_option( $key, false );
212
+
213
+ if ( is_object( $cache_entry ) &&
214
+ isset( $cache_entry->timestamp ) &&
215
+ is_numeric( $cache_entry->timestamp ) &&
216
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
217
+ ) {
218
+ return $cache_entry->timestamp;
219
+ }
220
+
221
+ return false;
222
+ }
223
+
224
+ /**
225
+ * Purge cached item.
226
+ *
227
+ * @author Vova Feldman (@svovaf)
228
+ * @since 1.1.6
229
+ *
230
+ * @param string $key
231
+ */
232
+ function purge( $key ) {
233
+ $this->_logger->entrance( 'key = ' . $key );
234
+
235
+ $this->_options->unset_option( $key, true );
236
+ }
237
+ }
freemius/includes/managers/class-fs-key-value-storage.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ( $this->_logger->is_on() ) {
90
+ $this->_logger->entrance( $key . ' = ' . var_export( $value, true ) );
91
+ }
92
+
93
+ if ( array_key_exists( $key, $this->_data ) && $value === $this->_data[ $key ] ) {
94
+ // No need to store data if the value wasn't changed.
95
+ return;
96
+ }
97
+
98
+ $all_data = $this->get_all_data();
99
+
100
+ $this->_data[ $key ] = $value;
101
+
102
+ $all_data[ $this->_slug ] = $this->_data;
103
+
104
+ $options_manager = $this->get_option_manager();
105
+ $options_manager->set_option( $this->_id, $all_data, $flush );
106
+ }
107
+
108
+ /**
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.7
111
+ *
112
+ * @param bool $store
113
+ * @param string[] $exceptions Set of keys to keep and not clear.
114
+ */
115
+ function clear_all( $store = true, $exceptions = array() ) {
116
+ $new_data = array();
117
+ foreach ( $exceptions as $key ) {
118
+ if ( isset( $this->_data[ $key ] ) ) {
119
+ $new_data[ $key ] = $this->_data[ $key ];
120
+ }
121
+ }
122
+
123
+ $this->_data = $new_data;
124
+
125
+ if ( $store ) {
126
+ $all_data = $this->get_all_data();
127
+ $all_data[ $this->_slug ] = $this->_data;
128
+ $options_manager = $this->get_option_manager();
129
+ $options_manager->set_option( $this->_id, $all_data, true );
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Delete key-value storage.
135
+ *
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.9
138
+ */
139
+ function delete() {
140
+ $this->_data = array();
141
+
142
+ $all_data = $this->get_all_data();
143
+ unset( $all_data[ $this->_slug ] );
144
+ $options_manager = $this->get_option_manager();
145
+ $options_manager->set_option( $this->_id, $all_data, true );
146
+ }
147
+
148
+ /**
149
+ * @author Vova Feldman (@svovaf)
150
+ * @since 1.0.7
151
+ *
152
+ * @param string $key
153
+ * @param bool $store
154
+ */
155
+ function remove( $key, $store = true ) {
156
+ if ( ! array_key_exists( $key, $this->_data ) ) {
157
+ return;
158
+ }
159
+
160
+ unset( $this->_data[ $key ] );
161
+
162
+ if ( $store ) {
163
+ $all_data = $this->get_all_data();
164
+ $all_data[ $this->_slug ] = $this->_data;
165
+ $options_manager = $this->get_option_manager();
166
+ $options_manager->set_option( $this->_id, $all_data, true );
167
+ }
168
+ }
169
+
170
+ /**
171
+ * @author Vova Feldman (@svovaf)
172
+ * @since 1.0.7
173
+ *
174
+ * @param string $key
175
+ * @param mixed $default
176
+ *
177
+ * @return bool|\FS_Plugin
178
+ */
179
+ function get( $key, $default = false ) {
180
+ return array_key_exists( $key, $this->_data ) ?
181
+ $this->_data[ $key ] :
182
+ $default;
183
+ }
184
+
185
+
186
+ /* ArrayAccess + Magic Access (better for refactoring)
187
+ -----------------------------------------------------------------------------------*/
188
+ function __set( $k, $v ) {
189
+ $this->store( $k, $v );
190
+ }
191
+
192
+ function __isset( $k ) {
193
+ return array_key_exists( $k, $this->_data );
194
+ }
195
+
196
+ function __unset( $k ) {
197
+ $this->remove( $k );
198
+ }
199
+
200
+ function __get( $k ) {
201
+ return $this->get( $k, null );
202
+ }
203
+
204
+ function offsetSet( $k, $v ) {
205
+ if ( is_null( $k ) ) {
206
+ throw new Exception( 'Can\'t append value to request params.' );
207
+ } else {
208
+ $this->{$k} = $v;
209
+ }
210
+ }
211
+
212
+ function offsetExists( $k ) {
213
+ return array_key_exists( $k, $this->_data );
214
+ }
215
+
216
+ function offsetUnset( $k ) {
217
+ unset( $this->$k );
218
+ }
219
+
220
+ function offsetGet( $k ) {
221
+ return $this->get( $k, null );
222
+ }
223
+
224
+ /**
225
+ * (PHP 5 &gt;= 5.0.0)<br/>
226
+ * Return the current element
227
+ *
228
+ * @link http://php.net/manual/en/iterator.current.php
229
+ * @return mixed Can return any type.
230
+ */
231
+ public function current() {
232
+ return current( $this->_data );
233
+ }
234
+
235
+ /**
236
+ * (PHP 5 &gt;= 5.0.0)<br/>
237
+ * Move forward to next element
238
+ *
239
+ * @link http://php.net/manual/en/iterator.next.php
240
+ * @return void Any returned value is ignored.
241
+ */
242
+ public function next() {
243
+ next( $this->_data );
244
+ }
245
+
246
+ /**
247
+ * (PHP 5 &gt;= 5.0.0)<br/>
248
+ * Return the key of the current element
249
+ *
250
+ * @link http://php.net/manual/en/iterator.key.php
251
+ * @return mixed scalar on success, or null on failure.
252
+ */
253
+ public function key() {
254
+ return key( $this->_data );
255
+ }
256
+
257
+ /**
258
+ * (PHP 5 &gt;= 5.0.0)<br/>
259
+ * Checks if current position is valid
260
+ *
261
+ * @link http://php.net/manual/en/iterator.valid.php
262
+ * @return boolean The return value will be casted to boolean and then evaluated.
263
+ * Returns true on success or false on failure.
264
+ */
265
+ public function valid() {
266
+ $key = key( $this->_data );
267
+
268
+ return ( $key !== null && $key !== false );
269
+ }
270
+
271
+ /**
272
+ * (PHP 5 &gt;= 5.0.0)<br/>
273
+ * Rewind the Iterator to the first element
274
+ *
275
+ * @link http://php.net/manual/en/iterator.rewind.php
276
+ * @return void Any returned value is ignored.
277
+ */
278
+ public function rewind() {
279
+ reset( $this->_data );
280
+ }
281
+
282
+ /**
283
+ * (PHP 5 &gt;= 5.1.0)<br/>
284
+ * Count elements of an object
285
+ *
286
+ * @link http://php.net/manual/en/countable.count.php
287
+ * @return int The custom count as an integer.
288
+ * </p>
289
+ * <p>
290
+ * The return value is cast to an integer.
291
+ */
292
+ public function count() {
293
+ return count( $this->_data );
294
+ }
295
+ }
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,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ( isset( $this->_options ) ) {
104
+ // Clear prev options.
105
+ $this->clear();
106
+ }
107
+
108
+ if ( ! WP_FS__DEBUG_SDK ) {
109
+ $this->_options = wp_cache_get( $option_name, WP_FS__SLUG );
110
+ }
111
+
112
+ // $this->_logger->info('wp_cache_get = ' . var_export($this->_options, true));
113
+
114
+ // if ( is_array( $this->_options ) ) {
115
+ // $this->clear();
116
+ // }
117
+
118
+ $cached = true;
119
+
120
+ if ( empty( $this->_options ) ) {
121
+ $this->_options = get_option( $option_name );
122
+
123
+ if ( is_string( $this->_options ) ) {
124
+ $this->_options = json_decode( $this->_options );
125
+ }
126
+
127
+ // $this->_logger->info('get_option = ' . var_export($this->_options, true));
128
+
129
+ if ( false === $this->_options ) {
130
+ $this->clear();
131
+ }
132
+
133
+ $cached = false;
134
+ }
135
+
136
+ if ( ! WP_FS__DEBUG_SDK && ! $cached ) // Set non encoded cache.
137
+ {
138
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
139
+ }
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @author Vova Feldman (@svovaf)
145
+ * @since 1.0.3
146
+ *
147
+ * @return bool
148
+ */
149
+ function is_loaded() {
150
+ return isset( $this->_options );
151
+ }
152
+
153
+ /**
154
+ * @author Vova Feldman (@svovaf)
155
+ * @since 1.0.3
156
+ *
157
+ * @return bool
158
+ */
159
+ function is_empty() {
160
+ return ( $this->is_loaded() && false === $this->_options );
161
+ }
162
+
163
+ /**
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.6
166
+ *
167
+ * @param bool $flush
168
+ */
169
+ function clear( $flush = false ) {
170
+ $this->_logger->entrance();
171
+
172
+ $this->_options = array();
173
+
174
+ if ( $flush ) {
175
+ $this->store();
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Delete options manager from DB.
181
+ *
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.0.9
184
+ */
185
+ function delete() {
186
+ delete_option( $this->_get_option_manager_name() );
187
+ }
188
+
189
+ /**
190
+ * @author Vova Feldman (@svovaf)
191
+ * @since 1.0.6
192
+ *
193
+ * @param string $option
194
+ *
195
+ * @return bool
196
+ */
197
+ function has_option( $option ) {
198
+ return array_key_exists( $option, $this->_options );
199
+ }
200
+
201
+ /**
202
+ * @author Vova Feldman (@svovaf)
203
+ * @since 1.0.3
204
+ *
205
+ * @param string $option
206
+ * @param mixed $default
207
+ *
208
+ * @return mixed
209
+ */
210
+ function get_option( $option, $default = null ) {
211
+ $this->_logger->entrance( 'option = ' . $option );
212
+
213
+ if ( is_array( $this->_options ) ) {
214
+ return isset( $this->_options[ $option ] ) ? $this->_options[ $option ] : $default;
215
+ } else if ( is_object( $this->_options ) ) {
216
+ return isset( $this->_options->{$option} ) ? $this->_options->{$option} : $default;
217
+ }
218
+
219
+ return $default;
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.0.3
225
+ *
226
+ * @param string $option
227
+ * @param mixed $value
228
+ * @param bool $flush
229
+ */
230
+ function set_option( $option, $value, $flush = false ) {
231
+ $this->_logger->entrance( 'option = ' . $option );
232
+
233
+ if ( ! $this->is_loaded() ) {
234
+ $this->clear();
235
+ }
236
+
237
+ if ( is_array( $this->_options ) ) {
238
+ $this->_options[ $option ] = $value;
239
+ } else if ( is_object( $this->_options ) ) {
240
+ $this->_options->{$option} = $value;
241
+ }
242
+
243
+ if ( $flush ) {
244
+ $this->store();
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Unset option.
250
+ *
251
+ * @author Vova Feldman (@svovaf)
252
+ * @since 1.0.3
253
+ *
254
+ * @param string $option
255
+ * @param bool $flush
256
+ */
257
+ function unset_option( $option, $flush = false ) {
258
+ $this->_logger->entrance( 'option = ' . $option );
259
+
260
+ if ( is_array( $this->_options ) ) {
261
+ if ( ! isset( $this->_options[ $option ] ) ) {
262
+ return;
263
+ }
264
+
265
+ unset( $this->_options[ $option ] );
266
+
267
+ } else if ( is_object( $this->_options ) ) {
268
+ if ( ! isset( $this->_options->{$option} ) ) {
269
+ return;
270
+ }
271
+
272
+ unset( $this->_options->{$option} );
273
+ }
274
+
275
+ if ( $flush ) {
276
+ $this->store();
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Dump options to database.
282
+ *
283
+ * @author Vova Feldman (@svovaf)
284
+ * @since 1.0.3
285
+ */
286
+ function store() {
287
+ $this->_logger->entrance();
288
+
289
+ $option_name = $this->_get_option_manager_name();
290
+
291
+ if ( $this->_logger->is_on() ) {
292
+ $this->_logger->info( $option_name . ' = ' . var_export( $this->_options, true ) );
293
+ }
294
+
295
+ // Update DB.
296
+ update_option( $option_name, $this->_options );
297
+
298
+ if ( ! WP_FS__DEBUG_SDK ) {
299
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
300
+ }
301
+ }
302
+ }
freemius/includes/managers/class-fs-plan-manager.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
41
+ * @var FS_Plugin_License[] $licenses
42
+ */
43
+ foreach ( $licenses as $license ) {
44
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
45
+ return true;
46
+ }
47
+ }
48
+ }
49
+
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * Check if plugin has any paid plans.
55
+ *
56
+ * @author Vova Feldman (@svovaf)
57
+ * @since 1.0.7
58
+ *
59
+ * @param FS_Plugin_Plan[] $plans
60
+ *
61
+ * @return bool
62
+ */
63
+ function has_paid_plan( $plans ) {
64
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
65
+ return false;
66
+ }
67
+
68
+ /**
69
+ * @var FS_Plugin_Plan[] $plans
70
+ */
71
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
72
+ if ( ! $plans[ $i ]->is_free() ) {
73
+ return true;
74
+ }
75
+ }
76
+
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Check if plugin has any free plan, or is it premium only.
82
+ *
83
+ * Note: If no plans configured, assume plugin is free.
84
+ *
85
+ * @author Vova Feldman (@svovaf)
86
+ * @since 1.0.7
87
+ *
88
+ * @param FS_Plugin_Plan[] $plans
89
+ *
90
+ * @return bool
91
+ */
92
+ function has_free_plan( $plans ) {
93
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
94
+ return true;
95
+ }
96
+
97
+ /**
98
+ * @var FS_Plugin_Plan[] $plans
99
+ */
100
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
101
+ if ( $plans[ $i ]->is_free() ) {
102
+ return true;
103
+ }
104
+ }
105
+
106
+ return false;
107
+ }
108
+
109
+ /**
110
+ * Find all plans that have trial.
111
+ *
112
+ * @author Vova Feldman (@svovaf)
113
+ * @since 1.0.9
114
+ *
115
+ * @param FS_Plugin_Plan[] $plans
116
+ *
117
+ * @return FS_Plugin_Plan[]
118
+ */
119
+ function get_trial_plans( $plans ) {
120
+ $trial_plans = array();
121
+
122
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
123
+ /**
124
+ * @var FS_Plugin_Plan[] $plans
125
+ */
126
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
127
+ if ( $plans[ $i ]->has_trial() ) {
128
+ $trial_plans[] = $plans[ $i ];
129
+ }
130
+ }
131
+ }
132
+
133
+ return $trial_plans;
134
+ }
135
+
136
+ /**
137
+ * Check if plugin has any trial plan.
138
+ *
139
+ * @author Vova Feldman (@svovaf)
140
+ * @since 1.0.9
141
+ *
142
+ * @param FS_Plugin_Plan[] $plans
143
+ *
144
+ * @return bool
145
+ */
146
+ function has_trial_plan( $plans ) {
147
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
148
+ return true;
149
+ }
150
+
151
+ /**
152
+ * @var FS_Plugin_Plan[] $plans
153
+ */
154
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
155
+ if ( $plans[ $i ]->has_trial() ) {
156
+ return true;
157
+ }
158
+ }
159
+
160
+ return false;
161
+ }
162
+ }
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,574 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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__LOGGER_ON' ) ) {
45
+ define( 'FS_API__LOGGER_ON', false );
46
+ }
47
+
48
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
49
+ define( 'FS_API__ADDRESS', '://api.freemius.com' );
50
+ }
51
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
52
+ define( 'FS_API__SANDBOX_ADDRESS', '://sandbox-api.freemius.com' );
53
+ }
54
+
55
+ class Freemius_Api extends Freemius_Api_Base {
56
+ private static $_logger = array();
57
+
58
+ /**
59
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
60
+ * @param number $pID Element's id.
61
+ * @param string $pPublic Public key.
62
+ * @param string|bool $pSecret Element's secret key.
63
+ * @param bool $pSandbox Whether or not to run API in sandbox mode.
64
+ */
65
+ public function __construct( $pScope, $pID, $pPublic, $pSecret = false, $pSandbox = false ) {
66
+ // If secret key not provided, use public key encryption.
67
+ if ( is_bool( $pSecret ) ) {
68
+ $pSecret = $pPublic;
69
+ }
70
+
71
+ parent::Init( $pScope, $pID, $pPublic, $pSecret, $pSandbox );
72
+ }
73
+
74
+ public static function GetUrl( $pCanonizedPath = '', $pIsSandbox = false ) {
75
+ $address = ( $pIsSandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS );
76
+
77
+ if ( ':' === $address[0] ) {
78
+ $address = self::$_protocol . $address;
79
+ }
80
+
81
+ return $address . $pCanonizedPath;
82
+ }
83
+
84
+ #region Servers Clock Diff ------------------------------------------------------
85
+
86
+ /**
87
+ * @var int Clock diff in seconds between current server to API server.
88
+ */
89
+ private static $_clock_diff = 0;
90
+
91
+ /**
92
+ * Set clock diff for all API calls.
93
+ *
94
+ * @since 1.0.3
95
+ *
96
+ * @param $pSeconds
97
+ */
98
+ public static function SetClockDiff( $pSeconds ) {
99
+ self::$_clock_diff = $pSeconds;
100
+ }
101
+
102
+ /**
103
+ * Find clock diff between current server to API server.
104
+ *
105
+ * @since 1.0.2
106
+ * @return int Clock diff in seconds.
107
+ */
108
+ public static function FindClockDiff() {
109
+ $time = time();
110
+ $pong = self::Ping();
111
+
112
+ return ( $time - strtotime( $pong->timestamp ) );
113
+ }
114
+
115
+ #endregion Servers Clock Diff ------------------------------------------------------
116
+
117
+ /**
118
+ * @var string http or https
119
+ */
120
+ private static $_protocol = FS_API__PROTOCOL;
121
+
122
+ /**
123
+ * Set API connection protocol.
124
+ *
125
+ * @since 1.0.4
126
+ */
127
+ public static function SetHttp() {
128
+ self::$_protocol = 'http';
129
+ }
130
+
131
+ /**
132
+ * @since 1.0.4
133
+ *
134
+ * @return bool
135
+ */
136
+ public static function IsHttps() {
137
+ return ( 'https' === self::$_protocol );
138
+ }
139
+
140
+ /**
141
+ * Sign request with the following HTTP headers:
142
+ * Content-MD5: MD5(HTTP Request body)
143
+ * Date: Current date (i.e Sat, 14 Feb 2015 20:24:46 +0000)
144
+ * Authorization: FS {scope_entity_id}:{scope_entity_public_key}:base64encode(sha256(string_to_sign,
145
+ * {scope_entity_secret_key}))
146
+ *
147
+ * @param string $pResourceUrl
148
+ * @param array $pCurlOptions
149
+ *
150
+ * @return array
151
+ */
152
+ function SignRequest( $pResourceUrl, $pCurlOptions ) {
153
+ $eol = "\n";
154
+ $content_md5 = '';
155
+ $now = ( time() - self::$_clock_diff );
156
+ $date = date( 'r', $now );
157
+ $content_type = '';
158
+
159
+ if ( isset( $pCurlOptions[ CURLOPT_POST ] ) && 0 < $pCurlOptions[ CURLOPT_POST ] ) {
160
+ $content_md5 = md5( $pCurlOptions[ CURLOPT_POSTFIELDS ] );
161
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Content-MD5: ' . $content_md5;
162
+ $content_type = 'application/json';
163
+ }
164
+
165
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Date: ' . $date;
166
+
167
+ $string_to_sign = implode( $eol, array(
168
+ $pCurlOptions[ CURLOPT_CUSTOMREQUEST ],
169
+ $content_md5,
170
+ $content_type,
171
+ $date,
172
+ $pResourceUrl
173
+ ) );
174
+
175
+ // If secret and public keys are identical, it means that
176
+ // the signature uses public key hash encoding.
177
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
178
+
179
+ // Add authorization header.
180
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Authorization: ' .
181
+ $auth_type . ' ' .
182
+ $this->_id . ':' .
183
+ $this->_public . ':' .
184
+ self::Base64UrlEncode(
185
+ hash_hmac( 'sha256', $string_to_sign, $this->_secret )
186
+ );
187
+
188
+ return $pCurlOptions;
189
+ }
190
+
191
+ /**
192
+ * Get API request URL signed via query string.
193
+ *
194
+ * @param string $pPath
195
+ *
196
+ * @throws Freemius_Exception
197
+ *
198
+ * @return string
199
+ */
200
+ function GetSignedUrl( $pPath ) {
201
+ $resource = explode( '?', $this->CanonizePath( $pPath ) );
202
+ $pResourceUrl = $resource[0];
203
+
204
+ $eol = "\n";
205
+ $content_md5 = '';
206
+ $content_type = '';
207
+ $now = ( time() - self::$_clock_diff );
208
+ $date = date( 'r', $now );
209
+
210
+ $string_to_sign = implode( $eol, array(
211
+ 'GET',
212
+ $content_md5,
213
+ $content_type,
214
+ $date,
215
+ $pResourceUrl
216
+ ) );
217
+
218
+ // If secret and public keys are identical, it means that
219
+ // the signature uses public key hash encoding.
220
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
221
+
222
+ return Freemius_Api::GetUrl(
223
+ $pResourceUrl . '?' .
224
+ ( 1 < count( $resource ) && ! empty( $resource[1] ) ? $resource[1] . '&' : '' ) .
225
+ http_build_query( array(
226
+ 'auth_date' => $date,
227
+ 'authorization' => $auth_type . ' ' . $this->_id . ':' .
228
+ $this->_public . ':' .
229
+ self::Base64UrlEncode( hash_hmac(
230
+ 'sha256', $string_to_sign, $this->_secret
231
+ ) )
232
+ ) ), $this->_isSandbox );
233
+ }
234
+
235
+ /**
236
+ * @param resource $pCurlHandler
237
+ * @param array $pCurlOptions
238
+ *
239
+ * @return mixed
240
+ */
241
+ private static function ExecuteRequest( &$pCurlHandler, &$pCurlOptions ) {
242
+ $start = microtime( true );
243
+
244
+ $result = curl_exec( $pCurlHandler );
245
+
246
+ if ( FS_API__LOGGER_ON ) {
247
+ $end = microtime( true );
248
+
249
+ $has_body = ( isset( $pCurlOptions[ CURLOPT_POST ] ) && 0 < $pCurlOptions[ CURLOPT_POST ] );
250
+
251
+ self::$_logger[] = array(
252
+ 'id' => count( self::$_logger ),
253
+ 'start' => $start,
254
+ 'end' => $end,
255
+ 'total' => ( $end - $start ),
256
+ 'method' => $pCurlOptions[ CURLOPT_CUSTOMREQUEST ],
257
+ 'path' => $pCurlOptions[ CURLOPT_URL ],
258
+ 'body' => $has_body ? $pCurlOptions[ CURLOPT_POSTFIELDS ] : null,
259
+ 'result' => $result,
260
+ 'code' => curl_getinfo( $pCurlHandler, CURLINFO_HTTP_CODE ),
261
+ 'backtrace' => debug_backtrace(),
262
+ );
263
+ }
264
+
265
+ return $result;
266
+ }
267
+
268
+ /**
269
+ * @return array
270
+ */
271
+ static function GetLogger() {
272
+ return self::$_logger;
273
+ }
274
+
275
+ /**
276
+ * @param string $pCanonizedPath
277
+ * @param string $pMethod
278
+ * @param array $pParams
279
+ * @param null|resource $pCurlHandler
280
+ * @param bool $pIsSandbox
281
+ * @param null|callable $pBeforeExecutionFunction
282
+ *
283
+ * @return object[]|object|null
284
+ *
285
+ * @throws \Freemius_Exception
286
+ */
287
+ private static function MakeStaticRequest(
288
+ $pCanonizedPath,
289
+ $pMethod = 'GET',
290
+ $pParams = array(),
291
+ $pCurlHandler = null,
292
+ $pIsSandbox = false,
293
+ $pBeforeExecutionFunction = null
294
+ ) {
295
+ if ( ! FS_SDK__HAS_CURL ) {
296
+ self::ThrowNoCurlException();
297
+ }
298
+
299
+ // Connectivity errors simulation.
300
+ if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
301
+ self::ThrowCloudFlareDDoSException();
302
+ } else if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
303
+ self::ThrowSquidAclException();
304
+ }
305
+
306
+ if ( ! $pCurlHandler ) {
307
+ $pCurlHandler = curl_init();
308
+ }
309
+
310
+ $opts = array(
311
+ CURLOPT_CONNECTTIMEOUT => 10,
312
+ CURLOPT_RETURNTRANSFER => true,
313
+ CURLOPT_TIMEOUT => 60,
314
+ CURLOPT_USERAGENT => FS_SDK__USER_AGENT,
315
+ );
316
+
317
+ if ( ! isset( $opts[ CURLOPT_HTTPHEADER ] ) || ! is_array( $opts[ CURLOPT_HTTPHEADER ] ) ) {
318
+ $opts[ CURLOPT_HTTPHEADER ] = array();
319
+ }
320
+
321
+ if ( 'POST' === $pMethod || 'PUT' === $pMethod ) {
322
+ if ( is_array( $pParams ) && 0 < count( $pParams ) ) {
323
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Content-Type: application/json';
324
+ $opts[ CURLOPT_POST ] = count( $pParams );
325
+ $opts[ CURLOPT_POSTFIELDS ] = json_encode( $pParams );
326
+ }
327
+
328
+ $opts[ CURLOPT_RETURNTRANSFER ] = true;
329
+ }
330
+
331
+ $opts[ CURLOPT_URL ] = Freemius_Api::GetUrl( $pCanonizedPath, $pIsSandbox );
332
+ $opts[ CURLOPT_CUSTOMREQUEST ] = $pMethod;
333
+
334
+ $resource = explode( '?', $pCanonizedPath );
335
+
336
+ // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
337
+ // for 2 seconds if the server does not support this header.
338
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Expect:';
339
+
340
+ if ( 'https' === substr( strtolower( $pCanonizedPath ), 0, 5 ) ) {
341
+ $opts[ CURLOPT_SSL_VERIFYHOST ] = false;
342
+ $opts[ CURLOPT_SSL_VERIFYPEER ] = false;
343
+ }
344
+
345
+ if ( false !== $pBeforeExecutionFunction &&
346
+ is_callable( $pBeforeExecutionFunction )
347
+ ) {
348
+ $opts = call_user_func( $pBeforeExecutionFunction, $resource[0], $opts );
349
+ }
350
+
351
+ curl_setopt_array( $pCurlHandler, $opts );
352
+ $result = self::ExecuteRequest( $pCurlHandler, $opts );
353
+
354
+ /*if (curl_errno($ch) == 60) // CURLE_SSL_CACERT
355
+ {
356
+ self::errorLog('Invalid or no certificate authority found, using bundled information');
357
+ curl_setopt($ch, CURLOPT_CAINFO,
358
+ dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
359
+ $result = curl_exec($ch);
360
+ }*/
361
+
362
+ // With dual stacked DNS responses, it's possible for a server to
363
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
364
+ // the case, curl will try IPv4 first and if that fails, then it will
365
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
366
+ // operating system.
367
+ if ( false === $result && empty( $opts[ CURLOPT_IPRESOLVE ] ) ) {
368
+ $matches = array();
369
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
370
+ if ( preg_match( $regex, curl_error( $pCurlHandler ), $matches ) ) {
371
+ if ( strlen( @inet_pton( $matches[1] ) ) === 16 ) {
372
+ // self::errorLog('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
373
+ $opts[ CURLOPT_IPRESOLVE ] = CURL_IPRESOLVE_V4;
374
+ curl_setopt( $pCurlHandler, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
375
+ $result = self::ExecuteRequest( $pCurlHandler, $opts );
376
+ }
377
+ }
378
+ }
379
+
380
+ if ( $result === false ) {
381
+ self::ThrowCurlException( $pCurlHandler );
382
+ }
383
+
384
+ curl_close( $pCurlHandler );
385
+
386
+ if ( empty( $result ) ) {
387
+ return null;
388
+ }
389
+
390
+ $decoded = json_decode( $result );
391
+
392
+ if ( is_null( $decoded ) ) {
393
+ if ( preg_match( '/Please turn JavaScript on/i', $result ) &&
394
+ preg_match( '/text\/javascript/', $result )
395
+ ) {
396
+ self::ThrowCloudFlareDDoSException( $result );
397
+ } 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 ) &&
398
+ preg_match( '/squid/', $result )
399
+ ) {
400
+ self::ThrowSquidAclException( $result );
401
+ } else {
402
+ $decoded = (object) array(
403
+ 'error' => (object) array(
404
+ 'type' => 'Unknown',
405
+ 'message' => $result,
406
+ 'code' => 'unknown',
407
+ 'http' => 402
408
+ )
409
+ );
410
+ }
411
+ }
412
+
413
+ return $decoded;
414
+ }
415
+
416
+
417
+ /**
418
+ * Makes an HTTP request. This method can be overridden by subclasses if
419
+ * developers want to do fancier things or use something other than curl to
420
+ * make the request.
421
+ *
422
+ * @param string $pCanonizedPath The URL to make the request to
423
+ * @param string $pMethod HTTP method
424
+ * @param array $pParams The parameters to use for the POST body
425
+ * @param null|resource $pCurlHandler Initialized curl handle
426
+ *
427
+ * @return object[]|object|null
428
+ *
429
+ * @throws Freemius_Exception
430
+ */
431
+ public function MakeRequest(
432
+ $pCanonizedPath,
433
+ $pMethod = 'GET',
434
+ $pParams = array(),
435
+ $pCurlHandler = null
436
+ ) {
437
+ $resource = explode( '?', $pCanonizedPath );
438
+
439
+ // Only sign request if not ping.json connectivity test.
440
+ $sign_request = ( '/v1/ping.json' !== strtolower( substr( $resource[0], - strlen( '/v1/ping.json' ) ) ) );
441
+
442
+ return self::MakeStaticRequest(
443
+ $pCanonizedPath,
444
+ $pMethod,
445
+ $pParams,
446
+ $pCurlHandler,
447
+ $this->_isSandbox,
448
+ $sign_request ? array( &$this, 'SignRequest' ) : null
449
+ );
450
+ }
451
+
452
+ #region Connectivity Test ------------------------------------------------------
453
+
454
+ /**
455
+ * If successful connectivity to the API endpoint using ping.json endpoint.
456
+ *
457
+ * - OR -
458
+ *
459
+ * Validate if ping result object is valid.
460
+ *
461
+ * @param mixed $pPong
462
+ *
463
+ * @return bool
464
+ */
465
+ public static function Test( $pPong = null ) {
466
+ $pong = is_null( $pPong ) ?
467
+ self::Ping() :
468
+ $pPong;
469
+
470
+ return (
471
+ is_object( $pong ) &&
472
+ isset( $pong->api ) &&
473
+ 'pong' === $pong->api
474
+ );
475
+ }
476
+
477
+ /**
478
+ * Ping API to test connectivity.
479
+ *
480
+ * @return object
481
+ */
482
+ public static function Ping() {
483
+ try {
484
+ $result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
485
+ } catch ( Freemius_Exception $e ) {
486
+ // Map to error object.
487
+ $result = (object) $e->getResult();
488
+ } catch ( Exception $e ) {
489
+ // Map to error object.
490
+ $result = (object) array(
491
+ 'error' => array(
492
+ 'type' => 'Unknown',
493
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
494
+ 'code' => 'unknown',
495
+ 'http' => 402
496
+ )
497
+ );
498
+ }
499
+
500
+ return $result;
501
+ }
502
+
503
+ #endregion Connectivity Test ------------------------------------------------------
504
+
505
+ #region Connectivity Exceptions ------------------------------------------------------
506
+
507
+ /**
508
+ * @param resource $pCurlHandler
509
+ *
510
+ * @throws Freemius_Exception
511
+ */
512
+ private static function ThrowCurlException( $pCurlHandler ) {
513
+ $e = new Freemius_Exception( array(
514
+ 'error' => array(
515
+ 'code' => curl_errno( $pCurlHandler ),
516
+ 'message' => curl_error( $pCurlHandler ),
517
+ 'type' => 'CurlException',
518
+ ),
519
+ ) );
520
+
521
+ curl_close( $pCurlHandler );
522
+ throw $e;
523
+ }
524
+
525
+ /**
526
+ * @param string $pResult
527
+ *
528
+ * @throws Freemius_Exception
529
+ */
530
+ private static function ThrowNoCurlException( $pResult = '' ) {
531
+ throw new Freemius_Exception( array(
532
+ 'error' => (object) array(
533
+ 'type' => 'cUrlMissing',
534
+ 'message' => $pResult,
535
+ 'code' => 'curl_missing',
536
+ 'http' => 402
537
+ )
538
+ ) );
539
+ }
540
+
541
+ /**
542
+ * @param string $pResult
543
+ *
544
+ * @throws Freemius_Exception
545
+ */
546
+ private static function ThrowCloudFlareDDoSException( $pResult = '' ) {
547
+ throw new Freemius_Exception( array(
548
+ 'error' => (object) array(
549
+ 'type' => 'CloudFlareDDoSProtection',
550
+ 'message' => $pResult,
551
+ 'code' => 'cloudflare_ddos_protection',
552
+ 'http' => 402
553
+ )
554
+ ) );
555
+ }
556
+
557
+ /**
558
+ * @param string $pResult
559
+ *
560
+ * @throws Freemius_Exception
561
+ */
562
+ private static function ThrowSquidAclException( $pResult = '' ) {
563
+ throw new Freemius_Exception( array(
564
+ 'error' => (object) array(
565
+ 'type' => 'SquidCacheBlock',
566
+ 'message' => $pResult,
567
+ 'code' => 'squid_cache_block',
568
+ 'http' => 402
569
+ )
570
+ ) );
571
+ }
572
+
573
+ #endregion Connectivity Exceptions ------------------------------------------------------
574
+ }
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,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Freemius SDK Version.
15
+ *
16
+ * @var string
17
+ */
18
+ $this_sdk_version = '1.1.8.1';
19
+
20
+ #region SDK Selection Logic --------------------------------------------------------------------
21
+
22
+ /**
23
+ * Special logic added on 1.1.6 to make sure that every Freemius powered plugin
24
+ * will ALWAYS be loaded with the newest SDK from the active Freemius powered plugins.
25
+ *
26
+ * Since Freemius SDK is backward compatible, this will make sure that all Freemius powered
27
+ * plugins will run correctly.
28
+ *
29
+ * @since 1.1.6
30
+ */
31
+
32
+ global $fs_active_plugins;
33
+
34
+ $this_sdk_relative_path = plugin_basename( dirname( __FILE__ ) );
35
+
36
+ if ( ! isset( $fs_active_plugins ) ) {
37
+ // Require SDK essentials.
38
+ require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php';
39
+
40
+ // Load all Freemius powered active plugins.
41
+ $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() );
42
+
43
+ if ( ! isset( $fs_active_plugins->plugins ) ) {
44
+ $fs_active_plugins->plugins = array();
45
+ }
46
+ }
47
+
48
+ if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
49
+ require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
50
+ }
51
+
52
+ // Update current SDK info based on the SDK path.
53
+ if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) ||
54
+ $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version
55
+ ) {
56
+ $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
57
+ 'version' => $this_sdk_version,
58
+ 'timestamp' => time(),
59
+ 'plugin_path' => plugin_basename( fs_find_direct_caller_plugin_file( __FILE__ ) ),
60
+ );
61
+ }
62
+
63
+ $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path );
64
+
65
+ if ( ! isset( $fs_active_plugins->newest ) ) {
66
+ /**
67
+ * This will be executed only once, for the first time a Freemius powered plugin is activated.
68
+ */
69
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
70
+
71
+ $is_current_sdk_newest = true;
72
+ } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) {
73
+ /**
74
+ * Current SDK is newer than the newest stored SDK.
75
+ */
76
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
77
+
78
+ if ( class_exists( 'Freemius' ) ) {
79
+ // Older SDK version was already loaded.
80
+
81
+ if ( ! $fs_active_plugins->newest->in_activation ) {
82
+ // Re-order plugins to load this plugin first.
83
+ fs_newest_sdk_plugin_first();
84
+ }
85
+
86
+ // Refresh page.
87
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
88
+ exit();
89
+ }
90
+ }
91
+ } else {
92
+ if ( ! function_exists( 'get_plugins' ) ) {
93
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
94
+ }
95
+
96
+ $is_newest_sdk_plugin_activate = is_plugin_active( $fs_active_plugins->newest->plugin_path );
97
+
98
+ if ( $is_current_sdk_newest &&
99
+ ! $is_newest_sdk_plugin_activate &&
100
+ ! $fs_active_plugins->newest->in_activation
101
+ ) {
102
+ // If current SDK is the newest and the plugin is NOT active, it means
103
+ // that the current plugin in activation mode.
104
+ $fs_active_plugins->newest->in_activation = true;
105
+ update_option( 'fs_active_plugins', $fs_active_plugins );
106
+ }
107
+
108
+ $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' ) );
109
+
110
+ if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
111
+ // Plugin with newest SDK is no longer active, or SDK was moved to a different location.
112
+ unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
113
+ }
114
+
115
+ if ( ! ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) ||
116
+ ! $is_newest_sdk_path_valid ||
117
+ // Is newest SDK downgraded.
118
+ ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
119
+ version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
120
+ ) {
121
+ /**
122
+ * Plugin with newest SDK is no longer active.
123
+ * OR
124
+ * The newest SDK was in the current plugin. BUT, seems like the version of
125
+ * the SDK was downgraded to a lower SDK.
126
+ */
127
+ // Find the active plugin with the newest SDK version and update the newest reference.
128
+ fs_fallback_to_newest_active_sdk();
129
+ } else {
130
+ if ( $is_newest_sdk_plugin_activate &&
131
+ $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
132
+ ( $fs_active_plugins->newest->in_activation ||
133
+ ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
134
+ )
135
+
136
+ ) {
137
+ if ( $fs_active_plugins->newest->in_activation ) {
138
+ // Plugin no more in activation.
139
+ $fs_active_plugins->newest->in_activation = false;
140
+ update_option( 'fs_active_plugins', $fs_active_plugins );
141
+ }
142
+
143
+ // Reorder plugins to load plugin with newest SDK first.
144
+ if ( fs_newest_sdk_plugin_first() ) {
145
+ // Refresh page after re-order to make sure activated plugin loads newest SDK.
146
+ if ( class_exists( 'Freemius' ) ) {
147
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
148
+ exit();
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ if ( class_exists( 'Freemius' ) ) {
157
+ // SDK was already loaded.
158
+ return;
159
+ }
160
+
161
+ if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
162
+ $newest_sdk_starter = fs_normalize_path( WP_PLUGIN_DIR . '/' . $fs_active_plugins->newest->sdk_path . '/start.php' );
163
+
164
+ if ( file_exists( $newest_sdk_starter ) ) {
165
+ // Reorder plugins to load plugin with newest SDK first.
166
+ fs_newest_sdk_plugin_first();
167
+
168
+ // There's a newer SDK version, load it instead of the current one!
169
+ require_once $newest_sdk_starter;
170
+
171
+ return;
172
+ }
173
+ }
174
+
175
+ #endregion SDK Selection Logic --------------------------------------------------------------------
176
+
177
+ #region Hooks & Filters Collection --------------------------------------------------------------------
178
+
179
+ /**
180
+ * Freemius hooks (actions & filters) tags structure:
181
+ *
182
+ * fs_{filter/action_name}_{plugin_slug}
183
+ *
184
+ * --------------------------------------------------------
185
+ *
186
+ * Usage with WordPress' add_action() / add_filter():
187
+ *
188
+ * add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
189
+ *
190
+ * --------------------------------------------------------
191
+ *
192
+ * Usage with Freemius' instance add_action() / add_filter():
193
+ *
194
+ * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
195
+ * my_freemius()->add_action('{action_name}', $callable);
196
+ *
197
+ * --------------------------------------------------------
198
+ *
199
+ * Freemius filters collection:
200
+ *
201
+ * fs_connect_url_{plugin_slug}
202
+ * fs_trial_promotion_message_{plugin_slug}
203
+ * fs_is_long_term_user_{plugin_slug}
204
+ * fs_uninstall_reasons_{plugin_slug}
205
+ * fs_is_plugin_update_{plugin_slug}
206
+ * fs_api_domains_{plugin_slug}
207
+ * fs_email_template_sections_{plugin_slug}
208
+ * fs_support_forum_submenu_{plugin_slug}
209
+ * fs_support_forum_url_{plugin_slug}
210
+ * fs_connect_message_{plugin_slug}
211
+ * fs_connect_message_on_update_{plugin_slug}
212
+ * fs_uninstall_confirmation_message_{plugin_slug}
213
+ * fs_pending_activation_message_{plugin_slug}
214
+ * fs_is_submenu_visible_{plugin_slug}
215
+ * fs_plugin_icon_{plugin_slug}
216
+ * fs_show_trial_{plugin_slug}
217
+ *
218
+ * --------------------------------------------------------
219
+ *
220
+ * Freemius actions collection:
221
+ *
222
+ * fs_after_license_loaded_{plugin_slug}
223
+ * fs_after_license_change_{plugin_slug}
224
+ * fs_after_plans_sync_{plugin_slug}
225
+ *
226
+ * fs_after_account_details_{plugin_slug}
227
+ * fs_after_account_user_sync_{plugin_slug}
228
+ * fs_after_account_plan_sync_{plugin_slug}
229
+ * fs_before_account_load_{plugin_slug}
230
+ * fs_after_account_connection_{plugin_slug}
231
+ * fs_account_property_edit_{plugin_slug}
232
+ * fs_account_email_verified_{plugin_slug}
233
+ * fs_account_page_load_before_departure_{plugin_slug}
234
+ * fs_before_account_delete_{plugin_slug}
235
+ * fs_after_account_delete_{plugin_slug}
236
+ *
237
+ * fs_sdk_version_update_{plugin_slug}
238
+ * fs_plugin_version_update_{plugin_slug}
239
+ *
240
+ * fs_initiated_{plugin_slug}
241
+ * fs_after_init_plugin_registered_{plugin_slug}
242
+ * fs_after_init_plugin_anonymous_{plugin_slug}
243
+ * fs_after_init_plugin_pending_activations_{plugin_slug}
244
+ * fs_after_init_addon_registered_{plugin_slug}
245
+ * fs_after_init_addon_anonymous_{plugin_slug}
246
+ * fs_after_init_addon_pending_activations_{plugin_slug}
247
+ *
248
+ * fs_after_premium_version_activation_{plugin_slug}
249
+ * fs_after_free_version_reactivation_{plugin_slug}
250
+ *
251
+ * fs_after_uninstall_{plugin_slug}
252
+ * fs_before_admin_menu_init_{plugin_slug}
253
+ */
254
+
255
+ #endregion Hooks & Filters Collection --------------------------------------------------------------------
256
+
257
+ if ( ! class_exists( 'Freemius' ) ) {
258
+
259
+ if ( ! defined( 'WP_FS__SDK_VERSION' ) ) {
260
+ define( 'WP_FS__SDK_VERSION', $this_sdk_version );
261
+ }
262
+
263
+ // Configuration should be loaded first.
264
+ require_once dirname( __FILE__ ) . '/config.php';
265
+
266
+ // Logger must be loaded before any other.
267
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-logger.php';
268
+ require_once WP_FS__DIR_INCLUDES . '/debug/debug-bar-start.php';
269
+
270
+ require_once WP_FS__DIR_INCLUDES . '/fs-core-functions.php';
271
+ // require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-abstract-manager.php';
272
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-option-manager.php';
273
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-cache-manager.php';
274
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-notice-manager.php';
275
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-menu-manager.php';
276
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-key-value-storage.php';
277
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-license-manager.php';
278
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plan-manager.php';
279
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plugin-manager.php';
280
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-entity.php';
281
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-scope-entity.php';
282
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-user.php';
283
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-site.php';
284
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin.php';
285
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-info.php';
286
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-tag.php';
287
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-plan.php';
288
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-pricing.php';
289
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-license.php';
290
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-subscription.php';
291
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-api.php';
292
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-plugin-updater.php';
293
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-security.php';
294
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius-abstract.php';
295
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';
296
+
297
+ /**
298
+ * Quick shortcut to get Freemius for specified plugin.
299
+ * Used by various templates.
300
+ *
301
+ * @param string $slug
302
+ *
303
+ * @return Freemius
304
+ */
305
+ function freemius( $slug ) {
306
+ return Freemius::instance( $slug );
307
+ }
308
+
309
+ /**
310
+ * @param string $slug
311
+ * @param number $plugin_id
312
+ * @param string $public_key
313
+ * @param bool $is_live Is live or test plugin.
314
+ * @param bool $is_premium Hints freemius if running the premium plugin or not.
315
+ *
316
+ * @return Freemius
317
+ */
318
+ function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) {
319
+ $fs = Freemius::instance( $slug );
320
+ $fs->init( $plugin_id, $public_key, $is_live, $is_premium );
321
+
322
+ return $fs;
323
+ }
324
+
325
+ /**
326
+ * @param array [string]string $plugin
327
+ *
328
+ * @return Freemius
329
+ * @throws Freemius_Exception
330
+ */
331
+ function fs_dynamic_init( $plugin ) {
332
+ $fs = Freemius::instance( $plugin['slug'] );
333
+ $fs->dynamic_init( $plugin );
334
+
335
+ return $fs;
336
+ }
337
+
338
+ function fs_dump_log() {
339
+ FS_Logger::dump();
340
+ }
341
+ }
freemius/templates/account.php ADDED
@@ -0,0 +1,625 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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( false, false );
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
+ $is_paid_trial = $fs->is_paid_trial();
33
+ $show_upgrade = ( ! $is_paying && ! $is_paid_trial );
34
+ ?>
35
+
36
+ <div class="wrap">
37
+ <h2 class="nav-tab-wrapper">
38
+ <a href="<?php $fs->get_account_url() ?>" class="nav-tab nav-tab-active"><?php _efs( 'account', $slug ) ?></a>
39
+ <?php if ( $fs->has_addons() ) : ?>
40
+ <a href="<?php echo $fs->_get_admin_page_url( 'addons' ) ?>"
41
+ class="nav-tab"><?php _efs( 'add-ons', $slug ) ?></a>
42
+ <?php endif ?>
43
+ <?php if ( $fs->is_not_paying() && $fs->has_paid_plan() ) : ?>
44
+ <a href="<?php echo $fs->get_upgrade_url() ?>" class="nav-tab"><?php _efs( 'upgrade', $slug ) ?></a>
45
+ <?php if ( $fs->apply_filters( 'show_trial', true ) && ! $fs->is_trial_utilized() && $fs->has_trial_plan() ) : ?>
46
+ <a href="<?php echo $fs->get_trial_url() ?>" class="nav-tab"><?php _efs( 'free-trial', $slug ) ?></a>
47
+ <?php endif ?>
48
+ <?php endif ?>
49
+ </h2>
50
+
51
+ <div id="poststuff">
52
+ <div id="fs_account">
53
+ <div class="has-sidebar has-right-sidebar">
54
+ <div class="has-sidebar-content">
55
+ <div class="postbox">
56
+ <h3><?php _efs('account-details', $slug) ?></h3>
57
+
58
+ <div class="fs-header-actions">
59
+ <ul>
60
+ <li>
61
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
62
+ <input type="hidden" name="fs_action" value="delete_account">
63
+ <?php wp_nonce_field('delete_account') ?>
64
+ <a href="#" onclick="if (confirm('<?php
65
+ if ($is_active_subscription) {
66
+ echo esc_attr(sprintf(__fs('delete-account-x-confirm', $slug), $plan->title));
67
+ } else {
68
+ _efs('delete-account-confirm', $slug);
69
+ }
70
+ ?>')) this.parentNode.submit(); return false;"><i
71
+ class="dashicons dashicons-no"></i> <?php _efs('delete-account', $slug) ?></a>
72
+ </form>
73
+ </li>
74
+ <?php if ($is_paying) : ?>
75
+ <li>
76
+ &nbsp;•&nbsp;
77
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
78
+ <input type="hidden" name="fs_action" value="deactivate_license">
79
+ <?php wp_nonce_field('deactivate_license') ?>
80
+ <a href="#"
81
+ onclick="if (confirm('<?php _efs('deactivate-license-confirm', $slug) ?>')) this.parentNode.submit(); return false;"><i
82
+ class="dashicons dashicons-admin-network"></i> <?php _efs('deactivate-license', $slug) ?>
83
+ </a>
84
+ </form>
85
+ </li>
86
+ <?php if (! $license->is_lifetime() &&
87
+ $is_active_subscription
88
+ ) : ?>
89
+ <li>
90
+ &nbsp;•&nbsp;
91
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
92
+ <input type="hidden" name="fs_action" value="downgrade_account">
93
+ <?php wp_nonce_field('downgrade_account') ?>
94
+ <a href="#"
95
+ 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) {
96
+ printf(__fs('after-downgrade-non-blocking', $slug), $plan->title);
97
+ } else {
98
+ printf(__fs('after-downgrade-blocking', $slug), $plan->title);
99
+ }?> <?php _efs('proceed-confirmation', $slug) ?>')) this.parentNode.submit(); return false;"><i
100
+ class="dashicons dashicons-download"></i> <?php _efs('downgrade', $slug) ?></a>
101
+ </form>
102
+ </li>
103
+ <?php endif ?>
104
+ <li>
105
+ &nbsp;•&nbsp;
106
+ <a href="<?php echo $fs->get_upgrade_url() ?>"><i
107
+ class="dashicons dashicons-grid-view"></i> <?php _efs('change-plan', $slug) ?></a>
108
+ </li>
109
+ <?php elseif ($is_paid_trial) : ?>
110
+ <li>
111
+ &nbsp;•&nbsp;
112
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
113
+ <input type="hidden" name="fs_action" value="cancel_trial">
114
+ <?php wp_nonce_field('cancel_trial') ?>
115
+ <a href="#"
116
+ onclick="if (confirm('<?php _efs('cancel-trial-confirm') ?>')) this.parentNode.submit(); return false;"><i
117
+ class="dashicons dashicons-download"></i> <?php _efs('cancel-trial', $slug) ?></a>
118
+ </form>
119
+ </li>
120
+ <?php endif ?>
121
+ <li>
122
+ &nbsp;•&nbsp;
123
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
124
+ <input type="hidden" name="fs_action" value="<?php echo $slug ?>_sync_license">
125
+ <?php wp_nonce_field($slug . '_sync_license') ?>
126
+ <a href="#" onclick="this.parentNode.submit(); return false;"><i
127
+ class="dashicons dashicons-image-rotate"></i> <?php _efs('sync', $slug) ?></a>
128
+ </form>
129
+ </li>
130
+
131
+ </ul>
132
+ </div>
133
+ <div class="inside">
134
+ <table id="fs_account_details" cellspacing="0" class="fs-key-value-table">
135
+ <?php
136
+ $profile = array();
137
+ $profile[] = array(
138
+ 'id' => 'user_name',
139
+ 'title' => __fs('name', $slug),
140
+ 'value' => $name
141
+ );
142
+ // if (isset($user->email) && false !== strpos($user->email, '@'))
143
+ $profile[] = array(
144
+ 'id' => 'email',
145
+ 'title' => __fs('email', $slug),
146
+ 'value' => $user->email
147
+ );
148
+ if (is_numeric($user->id)) {
149
+ $profile[] = array(
150
+ 'id' => 'user_id',
151
+ 'title' => __fs('user-id', $slug),
152
+ 'value' => $user->id
153
+ );
154
+ }
155
+
156
+ $profile[] = array(
157
+ 'id' => 'site_id',
158
+ 'title' => __fs('site-id', $slug),
159
+ 'value' => is_string($site->id) ?
160
+ $site->id :
161
+ __fs('no-id', $slug)
162
+ );
163
+
164
+ $profile[] = array(
165
+ 'id' => 'site_public_key',
166
+ 'title' => __fs('public-key', $slug),
167
+ 'value' => $site->public_key
168
+ );
169
+
170
+ $profile[] = array(
171
+ 'id' => 'site_secret_key',
172
+ 'title' => __fs('secret-key', $slug),
173
+ 'value' => ((is_string($site->secret_key)) ?
174
+ $site->secret_key :
175
+ __fs('no-secret', $slug)
176
+ )
177
+ );
178
+
179
+ if ($fs->has_paid_plan()) {
180
+ if ($fs->is_trial()) {
181
+ $trial_plan = $fs->get_trial_plan();
182
+
183
+ $profile[] = array(
184
+ 'id' => 'plan',
185
+ 'title' => __fs('plan', $slug),
186
+ 'value' => (is_string($trial_plan->name) ?
187
+ strtoupper($trial_plan->title) :
188
+ __fs('trial', $slug))
189
+ );
190
+ } else {
191
+ $profile[] = array(
192
+ 'id' => 'plan',
193
+ 'title' => __fs('plan', $slug),
194
+ 'value' => is_string($site->plan->name) ?
195
+ strtoupper($site->plan->title) :
196
+ strtoupper(__fs('free', $slug))
197
+ );
198
+ }
199
+ }
200
+
201
+ $profile[] = array(
202
+ 'id' => 'version',
203
+ 'title' => __fs('version', $slug),
204
+ 'value' => $fs->get_plugin_version()
205
+ );
206
+ ?>
207
+ <?php $odd = true;
208
+ foreach ($profile as $p) : ?>
209
+ <?php
210
+ if ('plan' === $p['id'] && ! $fs->has_paid_plan()) {
211
+ // If plugin don't have any paid plans, there's no reason
212
+ // to show current plan.
213
+ continue;
214
+ }
215
+ ?>
216
+ <tr class="fs-field-<?php echo $p['id'] ?><?php if ($odd) : ?> alternate<?php endif ?>">
217
+ <td>
218
+ <nobr><?php echo $p['title'] ?>:</nobr>
219
+ </td>
220
+ <td>
221
+ <code><?php echo htmlspecialchars($p['value']) ?></code>
222
+ <?php if ('email' === $p['id'] && ! $user->is_verified()) : ?>
223
+ <label class="fs-tag fs-warn"><?php _efs('not-verified', $slug) ?></label>
224
+ <?php endif ?>
225
+ <?php if ('plan' === $p['id']) : ?>
226
+ <?php if ($fs->is_trial()) : ?>
227
+ <label class="fs-tag fs-success"><?php _efs('trial', $slug) ?></label>
228
+ <?php endif ?>
229
+ <?php if (is_object($license) && ! $license->is_lifetime()) : ?>
230
+ <?php if (! $is_active_subscription && ! $license->is_first_payment_pending()) : ?>
231
+ <label
232
+ class="fs-tag fs-warn"><?php printf(__fs('expires-in', $slug), human_time_diff(time(), strtotime($license->expiration))) ?></label>
233
+ <?php elseif ($is_active_subscription && ! $subscription->is_first_payment_pending()) : ?>
234
+ <label
235
+ class="fs-tag fs-success"><?php printf(__fs('renews-in', $slug), human_time_diff(time(), strtotime($subscription->next_payment))) ?></label>
236
+ <?php endif ?>
237
+ <?php elseif ($fs->is_trial()) : ?>
238
+ <label
239
+ class="fs-tag fs-warn"><?php printf(__fs('expires-in', $slug), human_time_diff(time(), strtotime($site->trial_ends))) ?></label>
240
+ <?php endif ?>
241
+ <?php endif ?>
242
+ <?php if ('version' === $p['id'] && $fs->has_paid_plan()) : ?>
243
+ <?php if ($fs->is_premium()) : ?>
244
+ <label
245
+ class="fs-tag fs-<?php echo $fs->can_use_premium_code() ? 'success' : 'warn' ?>"><?php _efs('premium-version') ?></label>
246
+ <?php elseif ($fs->can_use_premium_code()) : ?>
247
+ <label class="fs-tag fs-warn"><?php _efs('free-version') ?></label>
248
+ <?php endif ?>
249
+ <?php endif ?>
250
+ </td>
251
+ <td class="fs-right">
252
+ <?php if ('email' === $p['id'] && ! $user->is_verified()) : ?>
253
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
254
+ <input type="hidden" name="fs_action" value="verify_email">
255
+ <?php wp_nonce_field('verify_email') ?>
256
+ <input type="submit" class="button button-small"
257
+ value="<?php _efs('verify-email', $slug) ?>">
258
+ </form>
259
+ <?php endif ?>
260
+ <?php if ('plan' === $p['id']) : ?>
261
+ <div class="button-group">
262
+ <?php $license = $fs->is_free_plan() ? $fs->_get_available_premium_license() : false ?>
263
+ <?php if (false !== $license && ($license->left() > 0 || ($site->is_localhost() && $license->is_free_localhost))) : ?>
264
+ <?php $premium_plan = $fs->_get_plan_by_id($license->plan_id) ?>
265
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>"
266
+ method="POST">
267
+ <input type="hidden" name="fs_action" value="activate_license">
268
+ <input type="hidden" name="license_id" value="<?php echo $license->id ?>">
269
+ <?php wp_nonce_field('activate_license') ?>
270
+ <input type="submit" class="button button-primary"
271
+ value="<?php printf(
272
+ __fs( 'activate-x-plan', $slug ) . '%s',
273
+ $premium_plan->title,
274
+ ( $site->is_localhost() && $license->is_free_localhost ) ?
275
+ ' [' . __fs( 'localhost', $slug ) . ']' :
276
+ ( $license->is_single_site() ?
277
+ '' :
278
+ ' [' . ( 1 < $license->left() ?
279
+ sprintf( __fs( 'x-left', $slug ), $license->left() ) :
280
+ strtolower( __fs( 'last-license', $slug ) ) ) . ']'
281
+ )
282
+ ) ?> ">
283
+ </form>
284
+ <?php else : ?>
285
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>"
286
+ method="POST" class="button-group">
287
+ <input type="submit" class="button"
288
+ value="<?php _efs('sync-license', $slug) ?>">
289
+ <input type="hidden" name="fs_action"
290
+ value="<?php echo $slug ?>_sync_license">
291
+ <?php wp_nonce_field($slug . '_sync_license') ?>
292
+ <a href="<?php echo $fs->get_upgrade_url() ?>"
293
+ class="button<?php if ($show_upgrade) {
294
+ echo ' button-primary';
295
+ } ?> button-upgrade"><i
296
+ class="dashicons dashicons-cart"></i> <?php ($show_upgrade) ?
297
+ _efs('upgrade', $slug) :
298
+ _efs('change-plan', $slug)
299
+ ?></a>
300
+ </form>
301
+ <?php endif ?>
302
+ </div>
303
+ <?php elseif ('version' === $p['id']) : ?>
304
+ <div class="button-group">
305
+ <?php if ($is_paying || $fs->is_trial()) : ?>
306
+ <?php if (! $fs->is_allowed_to_install()) : ?>
307
+ <a target="_blank" class="button button-primary"
308
+ 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>
309
+ <?php elseif (is_object($update)) : ?>
310
+ <a class="button button-primary"
311
+ 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>
312
+ <?php endif ?>
313
+ <?php endif; ?>
314
+ </div>
315
+ <?php
316
+ elseif (/*in_array($p['id'], array('site_secret_key', 'site_id', 'site_public_key')) ||*/
317
+ (is_string($user->secret_key) && in_array($p['id'], array(
318
+ 'email',
319
+ 'user_name'
320
+ )))
321
+ ) : ?>
322
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST"
323
+ 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;">
324
+ <input type="hidden" name="fs_action" value="update_<?php echo $p['id'] ?>">
325
+ <input type="hidden" name="fs_<?php echo $p['id'] ?>_<?php echo $slug ?>"
326
+ value="">
327
+ <?php wp_nonce_field('update_' . $p['id']) ?>
328
+ <input type="submit" class="button button-small"
329
+ value="<?php _ex('Edit', 'verb', 'freemius') ?>">
330
+ </form>
331
+ <?php endif ?>
332
+ </td>
333
+ </tr>
334
+ <?php $odd = ! $odd;
335
+ endforeach ?>
336
+ </table>
337
+ </div>
338
+ </div>
339
+ <?php
340
+ $account_addons = $fs->get_account_addons();
341
+ if (! is_array($account_addons)) {
342
+ $account_addons = array();
343
+ }
344
+
345
+ $installed_addons = $fs->get_installed_addons();
346
+ $installed_addons_ids = array();
347
+ foreach ($installed_addons as $fs_addon) {
348
+ $installed_addons_ids[] = $fs_addon->get_id();
349
+ }
350
+
351
+ $addons_to_show = array_unique(array_merge($installed_addons_ids, $account_addons));
352
+ ?>
353
+ <?php if (0 < count($addons_to_show)) : ?>
354
+ <div class="postbox">
355
+ <div class="">
356
+ <!-- <div class="inside">-->
357
+ <table id="fs_addons" class="widefat">
358
+ <thead>
359
+ <tr>
360
+ <th><h3><?php _efs('add-ons', $slug) ?></h3></th>
361
+ <th><?php _efs('id', $slug) ?></th>
362
+ <th><?php _efs('version', $slug) ?></th>
363
+ <th><?php _efs('plan', $slug) ?></th>
364
+ <th><?php _efs('license', $slug) ?></th>
365
+ <th></th>
366
+ <?php if (defined('WP_FS__DEV_MODE') && WP_FS__DEV_MODE) : ?>
367
+ <th></th>
368
+ <?php endif ?>
369
+ </tr>
370
+ </thead>
371
+ <tbody>
372
+ <?php $odd = true;
373
+ foreach ($addons_to_show as $addon_id) : ?>
374
+ <?php
375
+ $addon = $fs->get_addon($addon_id);
376
+ $is_addon_activated = $fs->is_addon_activated($addon->slug);
377
+ $is_addon_connected = $fs->is_addon_connected($addon->slug);
378
+
379
+ $fs_addon = $is_addon_connected ? freemius($addon->slug) : false;
380
+ if (is_object($fs_addon)) {
381
+ $is_paying = $fs_addon->is_paying();
382
+ $user = $fs_addon->get_user();
383
+ $site = $fs_addon->get_site();
384
+ $license = $fs_addon->_get_license();
385
+ $subscription = $fs_addon->_get_subscription();
386
+ $plan = $fs_addon->get_plan();
387
+ $is_active_subscription = (is_object($subscription) && $subscription->is_active());
388
+ $is_paid_trial = $fs_addon->is_paid_trial();
389
+ $show_upgrade = (! $is_paying && ! $is_paid_trial && ! $fs_addon->_has_premium_license());
390
+ $is_current_license_expired = is_object($license) && $license->is_expired();
391
+ }
392
+
393
+ // var_dump( $is_paid_trial, $license, $site, $subscription );
394
+
395
+ ?>
396
+ <tr<?php if ($odd) {
397
+ echo ' class="alternate"';
398
+ } ?>>
399
+ <td>
400
+ <!-- Title -->
401
+ <?php echo $addon->title ?>
402
+ </td>
403
+ <?php if ($is_addon_connected) : ?>
404
+ <?php // Add-on Installed ?>
405
+ <?php $addon_site = $fs_addon->get_site(); ?>
406
+ <td>
407
+ <!-- ID -->
408
+ <?php echo $addon_site->id ?>
409
+ </td>
410
+ <td>
411
+ <!-- Version -->
412
+ <?php echo $fs_addon->get_plugin_version() ?>
413
+ </td>
414
+ <td>
415
+ <!-- Plan Title -->
416
+ <?php echo is_string($addon_site->plan->name) ? strtoupper($addon_site->plan->title) : 'FREE' ?>
417
+ </td>
418
+ <td>
419
+ <!-- Expiration -->
420
+ <?php
421
+ $tags = array();
422
+
423
+ if ($fs_addon->is_trial()) {
424
+ $tags[] = array('label' => __fs('trial', $slug), 'type' => 'success');
425
+
426
+ $tags[] = array(
427
+ 'label' => sprintf(__fs(($is_paid_trial ? 'renews-in' : 'expires-in'), $slug), human_time_diff(time(), strtotime($site->trial_ends))),
428
+ 'type' => ($is_paid_trial ? 'success' : 'warn')
429
+ );
430
+ } else {
431
+ if (is_object($license)) {
432
+ if ($license->is_cancelled) {
433
+ $tags[] = array(
434
+ 'label' => __fs('cancelled', $slug),
435
+ 'type' => 'error'
436
+ );
437
+ } else if ($license->is_expired()) {
438
+ $tags[] = array(
439
+ 'label' => __fs('expired', $slug),
440
+ 'type' => 'error'
441
+ );
442
+ } else if ($license->is_lifetime()) {
443
+ $tags[] = array(
444
+ 'label' => __fs('no-expiration', $slug),
445
+ 'type' => 'success'
446
+ );
447
+ } else if (! $is_active_subscription && ! $license->is_first_payment_pending()) {
448
+ $tags[] = array(
449
+ 'label' => sprintf(__fs('expires-in', $slug), human_time_diff(time(), strtotime($license->expiration))),
450
+ 'type' => 'warn'
451
+ );
452
+ } else if ($is_active_subscription && ! $subscription->is_first_payment_pending()) {
453
+ $tags[] = array(
454
+ 'label' => sprintf(__fs('renews-in', $slug), human_time_diff(time(), strtotime($subscription->next_payment))),
455
+ 'type' => 'success'
456
+ );
457
+ }
458
+ }
459
+ }
460
+
461
+ foreach ($tags as $t) {
462
+ printf('<label class="fs-tag fs-%s">%s</label>' . "\n", $t['type'], $t['label']);
463
+ }
464
+ ?>
465
+ </td>
466
+ <?php
467
+ $buttons = array();
468
+ if ($is_addon_activated) {
469
+ if ($is_paying) {
470
+ $buttons[] = fs_ui_get_action_button(
471
+ $slug,
472
+ 'account',
473
+ 'deactivate_license',
474
+ __fs('deactivate-license', $slug),
475
+ array('plugin_id' => $addon_id),
476
+ false
477
+ );
478
+ } else if ($is_paid_trial) {
479
+ $buttons[] = fs_ui_get_action_button(
480
+ $slug,
481
+ 'account',
482
+ 'cancel_trial',
483
+ __fs('cancel-trial', $slug),
484
+ array('plugin_id' => $addon_id),
485
+ false,
486
+ 'dashicons dashicons-download',
487
+ __fs('cancel-trial-confirm', $slug),
488
+ 'POST'
489
+ );
490
+ } else {
491
+ $premium_license = $fs_addon->_get_available_premium_license();
492
+
493
+ if (is_object($premium_license)) {
494
+ $site = $fs_addon->get_site();
495
+
496
+ $buttons[] = fs_ui_get_action_button(
497
+ $slug,
498
+ 'account',
499
+ 'activate_license',
500
+ 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' : '')),
501
+ array(
502
+ 'plugin_id' => $addon_id,
503
+ 'license_id' => $premium_license->id,
504
+ )
505
+ );
506
+ }
507
+ }
508
+
509
+ if (0 == count($buttons)) {
510
+ // Add sync license only if non of the other CTAs are visible.
511
+ $buttons[] = fs_ui_get_action_button(
512
+ $slug,
513
+ 'account',
514
+ $slug . '_sync_license',
515
+ __fs('sync-license', $slug),
516
+ array('plugin_id' => $addon_id),
517
+ false
518
+ );
519
+
520
+ }
521
+ } else if (! $show_upgrade) {
522
+ if ($fs->is_addon_installed($addon->slug)) {
523
+ $addon_file = $fs->get_addon_basename($addon->slug);
524
+ $buttons[] = sprintf(
525
+ '<a class="button button-primary" href="%s" title="%s" class="edit">%s</a>',
526
+ wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file),
527
+ esc_attr(__fs('activate-this-addon', $slug)),
528
+ __fs('activate', $slug)
529
+ );
530
+ } else {
531
+ if ($fs->is_allowed_to_install()) {
532
+ $buttons[] = sprintf(
533
+ '<a class="button button-primary" href="%s" class="edit">%s</a>',
534
+ wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $addon->slug), 'install-plugin_' . $addon->slug),
535
+ __fs('install-now', $slug)
536
+ );
537
+ } else {
538
+ $buttons[] = sprintf(
539
+ '<a target="_blank" class="button button-primary" href="%s" class="edit">%s</a>',
540
+ $fs->_get_latest_download_local_url($addon_id),
541
+ __fs('download-latest', $slug)
542
+ );
543
+ }
544
+ }
545
+ }
546
+
547
+ if ($show_upgrade) {
548
+ $buttons[] = sprintf('<a href="%s" class="thickbox button button-primary" aria-label="%s" data-title="%s"><i class="dashicons dashicons-cart"></i> %s</a>',
549
+ esc_url(network_admin_url('plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
550
+ '&TB_iframe=true&width=600&height=550')),
551
+ esc_attr(sprintf(__fs('more-information-about-x', $slug), $addon->title)),
552
+ esc_attr($addon->title),
553
+ __fs(($fs_addon->has_free_plan() ? 'upgrade' : 'purchase'), $slug)
554
+ );
555
+ }
556
+
557
+ $buttons_count = count($buttons);
558
+ ?>
559
+
560
+ <td>
561
+ <!-- Actions -->
562
+ <?php if ($buttons_count > 1) : ?>
563
+ <div class="button-group">
564
+ <?php endif ?>
565
+ <?php foreach ($buttons as $button) : ?>
566
+ <?php echo $button ?>
567
+ <?php endforeach ?>
568
+ <?php if ($buttons_count > 1) : ?>
569
+ </div>
570
+ <?php endif ?>
571
+ </td>
572
+ <?php else : ?>
573
+ <?php // Add-on NOT Installed or was never connected.
574
+ ?>
575
+ <td colspan="4">
576
+ <!-- Action -->
577
+ <?php if ($fs->is_addon_installed($addon->slug)) : ?>
578
+ <?php $addon_file = $fs->get_addon_basename($addon->slug) ?>
579
+ <a class="button button-primary"
580
+ href="<?php echo wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file) ?>"
581
+ title="<?php esc_attr(__fs('activate-this-addon', $slug)) ?>"
582
+ class="edit"><?php _efs('activate', $slug) ?></a>
583
+ <?php else : ?>
584
+ <?php if ($fs->is_allowed_to_install()) : ?>
585
+ <a class="button button-primary"
586
+ 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>
587
+ <?php else : ?>
588
+ <a target="_blank" class="button button-primary"
589
+ href="<?php echo $fs->_get_latest_download_local_url($addon_id) ?>"><?php _efs('download-latest', $slug) ?></a>
590
+ <?php endif ?>
591
+ <?php endif ?>
592
+ </td>
593
+ <?php endif ?>
594
+ <?php if (defined('WP_FS__DEV_MODE') && WP_FS__DEV_MODE) : ?>
595
+ <td>
596
+ <!-- Optional Delete Action -->
597
+ <?php
598
+ if ($is_addon_activated) {
599
+ fs_ui_action_button(
600
+ $slug, 'account',
601
+ 'delete_account',
602
+ __fs('delete', $slug),
603
+ array('plugin_id' => $addon_id),
604
+ false
605
+ );
606
+ }
607
+ ?>
608
+ </td>
609
+ <?php endif ?>
610
+ </tr>
611
+ <?php $odd = ! $odd;
612
+ endforeach ?>
613
+ </tbody>
614
+ </table>
615
+ </div>
616
+ </div>
617
+ <?php endif ?>
618
+
619
+ <?php $fs->do_action('after_account_details') ?>
620
+ </div>
621
+ </div>
622
+ </div>
623
+ </div>
624
+ </div>
625
+ <?php fs_require_template('powered-by.php') ?>
freemius/templates/add-ons.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $has_addons = ( is_array( $addons ) && 0 < count( $addons ) );
29
+ ?>
30
+ <div id="fs_addons" class="wrap">
31
+ <h2><?php printf( __fs( 'add-ons-for-x', $slug ), $fs->get_plugin_name() ) ?></h2>
32
+
33
+ <div id="poststuff">
34
+ <?php if ( ! $has_addons ) : ?>
35
+ <h3><?php printf(
36
+ '%s... %s',
37
+ __fs( 'oops', $slug ),
38
+ __fs( 'add-ons-missing', $slug )
39
+ ) ?></h3>
40
+ <?php endif ?>
41
+ <ul class="fs-cards-list">
42
+ <?php if ( $has_addons ) : ?>
43
+ <?php foreach ( $addons as $addon ) : ?>
44
+ <?php
45
+ $open_addon = ( $open_addon || ( $open_addon_slug === $addon->slug ) );
46
+
47
+ $price = 0;
48
+ $plan = null;
49
+ $plans_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans.json" );
50
+ if ( ! isset( $plans_result->error ) ) {
51
+ $plans = $plans_result->plans;
52
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
53
+ $plan = new FS_Plugin_Plan( $plans[0] );
54
+ $pricing_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans/{$plan->id}/pricing.json" );
55
+ if ( ! isset( $pricing_result->error ) ) {
56
+ // Update plan's pricing.
57
+ $plan->pricing = $pricing_result->pricing;
58
+
59
+ if ( is_array( $plan->pricing ) && 0 < count( $plan->pricing ) ) {
60
+ $min_price = 999999;
61
+ foreach ( $plan->pricing as $pricing ) {
62
+ if ( ! is_null( $pricing->annual_price ) && $pricing->annual_price > 0 ) {
63
+ $min_price = min( $min_price, $pricing->annual_price );
64
+ } else if ( ! is_null( $pricing->monthly_price ) && $pricing->monthly_price > 0 ) {
65
+ $min_price = min( $min_price, 12 * $pricing->monthly_price );
66
+ }
67
+ }
68
+
69
+ if ( $min_price < 999999 ) {
70
+ $price = $min_price;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ ?>
77
+ <li class="fs-card fs-addon" data-slug="<?php echo $addon->slug ?>">
78
+ <?php
79
+ echo sprintf( '<a href="%s" class="thickbox fs-overlay" aria-label="%s" data-title="%s"></a>',
80
+ esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
81
+ '&TB_iframe=true&width=600&height=550' ) ),
82
+ esc_attr( sprintf( __fs( 'more-information-about-x', $slug ), $addon->title ) ),
83
+ esc_attr( $addon->title )
84
+ );
85
+ ?>
86
+ <?php
87
+ if ( is_null( $addon->info ) ) {
88
+ $addon->info = new stdClass();
89
+ }
90
+ if ( ! isset( $addon->info->card_banner_url ) ) {
91
+ $addon->info->card_banner_url = '//dashboard.freemius.com/assets/img/marketing/blueprint-300x100.jpg';
92
+ }
93
+ if ( ! isset( $addon->info->short_description ) ) {
94
+ $addon->info->short_description = 'What\'s the one thing your add-on does really, really well?';
95
+ }
96
+ ?>
97
+ <div class="fs-inner">
98
+ <ul>
99
+ <li class="fs-card-banner"
100
+ style="background-image: url('<?php echo $addon->info->card_banner_url ?>');"></li>
101
+ <!-- <li class="fs-tag"></li>-->
102
+ <li class="fs-title"><?php echo $addon->title ?></li>
103
+ <li class="fs-offer">
104
+ <span
105
+ class="fs-price"><?php echo ( 0 == $price ) ? __fs( 'free', $slug ) : ('$' . number_format( $price, 2 ) . ($plan->has_trial() ? ' - ' . __fs('trial', $slug) : '')) ?></span>
106
+ </li>
107
+ <li class="fs-description"><?php echo ! empty( $addon->info->short_description ) ? $addon->info->short_description : 'SHORT DESCRIPTION' ?></li>
108
+ <li class="fs-cta"><a class="button"><?php _efs( 'view-details', $slug ) ?></a></li>
109
+ </ul>
110
+ </div>
111
+ </li>
112
+ <?php endforeach ?>
113
+ <?php endif ?>
114
+ </ul>
115
+ </div>
116
+ </div>
117
+ <script type="text/javascript">
118
+ (function ($) {
119
+ <?php if ( $open_addon ) : ?>
120
+
121
+ var interval = setInterval(function () {
122
+ // Open add-on information page.
123
+ $('.fs-card[data-slug=<?php echo $open_addon_slug ?>] a').click();
124
+ if ($('#TB_iframeContent').length > 0) {
125
+ clearInterval(interval);
126
+ interval = null;
127
+ }
128
+ }, 200);
129
+
130
+ <?php else : ?>
131
+
132
+
133
+ $('.fs-card.fs-addon').mouseover(function(){
134
+ $(this).find('.fs-cta .button').addClass('button-primary');
135
+ });
136
+
137
+ $('.fs-card.fs-addon').mouseout(function(){
138
+ $(this).find('.fs-cta .button').removeClass('button-primary');
139
+ });
140
+
141
+ <?php endif ?>
142
+ })(jQuery);
143
+ </script>
144
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/admin-notice.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.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+ <div<?php if ( ! empty( $VARS['id'] ) ) : ?> data-id="<?php echo $VARS['id'] ?>"<?php endif ?><?php if ( ! empty( $VARS['slug'] ) ) : ?> data-slug="<?php echo $VARS['slug'] ?>"<?php endif ?>
14
+ class="<?php
15
+ switch ( $VARS['type'] ) {
16
+ case 'error':
17
+ echo 'error form-invalid';
18
+ break;
19
+ case 'promotion':
20
+ echo 'updated promotion';
21
+ break;
22
+ case 'update':
23
+ // echo 'update-nag update';
24
+ // break;
25
+ case 'success':
26
+ default:
27
+ echo 'updated success';
28
+ break;
29
+ }
30
+ ?> fs-notice<?php if ( ! empty( $VARS['sticky'] ) ) {
31
+ echo ' fs-sticky';
32
+ } ?><?php if ( ! empty( $VARS['plugin'] ) ) {
33
+ echo ' fs-has-title';
34
+ } ?>"><?php if ( ! empty( $VARS['plugin'] ) ) : ?>
35
+ <label class="fs-plugin-title"><?php echo $VARS['plugin'] ?></label>
36
+ <?php endif ?>
37
+ <?php if ( ! empty( $VARS['sticky'] ) ) : ?>
38
+ <div class="fs-close"><i class="dashicons dashicons-no"
39
+ title="<?php _efs( 'dismiss' ) ?>"></i> <span><?php _efs( 'dismiss' ) ?></span>
40
+ </div>
41
+ <?php endif ?>
42
+ <div class="fs-notice-body">
43
+ <?php if ( ! empty( $VARS['title'] ) ) : ?><b><?php echo $VARS['title'] ?></b> <?php endif ?>
44
+ <?php echo $VARS['message'] ?>
45
+ </div>
46
+ </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,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $site = $fs->get_site();
33
+ $plugin_id = fs_request_get( 'plugin_id', $fs->get_id() );
34
+
35
+ if ($plugin_id != $fs->get_id()) {
36
+ if ( $fs->is_addon_activated( $plugin_id ) ) {
37
+ $fs_addon = Freemius::get_instance_by_id( $plugin_id );
38
+ $site = $fs_addon->get_site();
39
+ }
40
+ }
41
+
42
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
43
+ $site,
44
+ $timestamp,
45
+ 'checkout'
46
+ ) );
47
+ } else {
48
+ $current_user = Freemius::_get_current_wp_user();
49
+
50
+ // Add site and user info to the request, this information
51
+ // is NOT being stored unless the user complete the purchase
52
+ // and agrees to the TOS.
53
+ $context_params = array_merge( $context_params, array(
54
+ 'user_firstname' => $current_user->user_firstname,
55
+ 'user_lastname' => $current_user->user_lastname,
56
+ 'user_email' => $current_user->user_email,
57
+ // 'user_nickname' => $current_user->user_nicename,
58
+ // 'plugin_slug' => $slug,
59
+ // 'site_url' => get_site_url(),
60
+ // 'site_name' => get_bloginfo( 'name' ),
61
+ // 'platform_version' => get_bloginfo( 'version' ),
62
+ // 'language' => get_bloginfo( 'language' ),
63
+ // 'charset' => get_bloginfo( 'charset' ),
64
+ // 'account_url' => fs_nonce_url( $fs->_get_admin_page_url(
65
+ // 'account',
66
+ // array( 'fs_action' => 'sync_user' )
67
+ // ), 'sync_user' ),
68
+ ) );
69
+
70
+ $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
71
+
72
+ if ( is_object( $fs_user ) ) {
73
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
74
+ $fs_user,
75
+ $timestamp,
76
+ 'checkout'
77
+ ) );
78
+ }
79
+ }
80
+
81
+ if ( $fs->is_payments_sandbox() )
82
+ {
83
+ // Append plugin secure token for sandbox mode authentication.
84
+ $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
85
+ $fs->get_plugin(),
86
+ $timestamp,
87
+ 'checkout'
88
+ );
89
+
90
+ /**
91
+ * @since 1.1.7.3 Add security timestamp for sandbox even for anonymous user.
92
+ */
93
+ if ( empty( $context_params['s_ctx_ts'] ) ) {
94
+ $context_params['s_ctx_ts'] = $timestamp;
95
+ }
96
+ }
97
+
98
+ $return_url = fs_nonce_url( $fs->_get_admin_page_url(
99
+ 'account',
100
+ array(
101
+ 'fs_action' => $slug . '_sync_license',
102
+ 'plugin_id' => isset( $_GET['plugin_id'] ) ? $_GET['plugin_id'] : $fs->get_id()
103
+ )
104
+ ), $slug . '_sync_license' );
105
+
106
+ $query_params = array_merge( $context_params, $_GET, array(
107
+ // Current plugin version.
108
+ 'plugin_version' => $fs->get_plugin_version(),
109
+ 'return_url' => $return_url,
110
+ // Admin CSS URL for style/design competability.
111
+ // 'wp_admin_css' => get_bloginfo('wpurl') . "/wp-admin/load-styles.php?c=1&load=buttons,wp-admin,dashicons",
112
+ ) );
113
+ ?>
114
+ <div class="fs-secure-notice">
115
+ <i class="dashicons dashicons-lock"></i>
116
+ <span><b>Secure HTTPS Checkout</b> - PCI compliant, running via iframe from external domain</span>
117
+ </div>
118
+ <div id="fs_contact" class="wrap" style="margin: 40px 0 -65px -20px;">
119
+ <div id="iframe"></div>
120
+ <script type="text/javascript">
121
+ // http://stackoverflow.com/questions/4583703/jquery-post-request-not-ajax
122
+ jQuery(function ($) {
123
+ $.extend({
124
+ form: function (url, data, method) {
125
+ if (method == null) method = 'POST';
126
+ if (data == null) data = {};
127
+
128
+ var form = $('<form>').attr({
129
+ method: method,
130
+ action: url
131
+ }).css({
132
+ display: 'none'
133
+ });
134
+
135
+ var addData = function (name, data) {
136
+ if ($.isArray(data)) {
137
+ for (var i = 0; i < data.length; i++) {
138
+ var value = data[i];
139
+ addData(name + '[]', value);
140
+ }
141
+ } else if (typeof data === 'object') {
142
+ for (var key in data) {
143
+ if (data.hasOwnProperty(key)) {
144
+ addData(name + '[' + key + ']', data[key]);
145
+ }
146
+ }
147
+ } else if (data != null) {
148
+ form.append($('<input>').attr({
149
+ type : 'hidden',
150
+ name : String(name),
151
+ value: String(data)
152
+ }));
153
+ }
154
+ };
155
+
156
+ for (var key in data) {
157
+ if (data.hasOwnProperty(key)) {
158
+ addData(key, data[key]);
159
+ }
160
+ }
161
+
162
+ return form.appendTo('body');
163
+ }
164
+ });
165
+ });
166
+
167
+ (function ($) {
168
+ $(function () {
169
+
170
+ var
171
+ // Keep track of the iframe height.
172
+ iframe_height = 800,
173
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
174
+ // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
175
+ // passed via query string or hard coded into the child page, it depends on your needs).
176
+ src = base_url + '/checkout/?<?php echo (isset($_REQUEST['XDEBUG_SESSION']) ? 'XDEBUG_SESSION=' . $_REQUEST['XDEBUG_SESSION'] . '&' : '') . http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
177
+
178
+ // Append the Iframe into the DOM.
179
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
180
+ .appendTo('#iframe');
181
+
182
+ FS.PostMessage.init(base_url);
183
+ FS.PostMessage.receiveOnce('height', function (data) {
184
+ var h = data.height;
185
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
186
+ iframe_height = h;
187
+ $("#iframe iframe").height(iframe_height + 'px');
188
+ }
189
+ });
190
+
191
+ FS.PostMessage.receiveOnce('install', function (data) {
192
+ // Post data to activation URL.
193
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
194
+ 'fs_action' => $slug . '_activate_new',
195
+ 'plugin_id' => isset($_GET['plugin_id']) ? $_GET['plugin_id'] : $fs->get_id()
196
+ )), $slug . '_activate_new') ?>', {
197
+ user_id : data.user.id,
198
+ user_secret_key : data.user.secret_key,
199
+ user_public_key : data.user.public_key,
200
+ install_id : data.install.id,
201
+ install_secret_key: data.install.secret_key,
202
+ install_public_key: data.install.public_key
203
+ }).submit();
204
+ });
205
+
206
+ FS.PostMessage.receiveOnce('pending_activation', function (data) {
207
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
208
+ 'fs_action' => $slug . '_activate_new',
209
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
210
+ 'pending_activation' => true,
211
+ )), $slug . '_activate_new') ?>', {
212
+ user_email: data.user_email
213
+ }).submit();
214
+ });
215
+
216
+ FS.PostMessage.receiveOnce('get_context', function () {
217
+ console.debug('receiveOnce', 'get_context');
218
+
219
+ // If the user didn't connect his account with Freemius,
220
+ // once he accepts the Terms of Service and Privacy Policy,
221
+ // and then click the purchase button, the context information
222
+ // of the user will be shared with Freemius in order to complete the
223
+ // purchase workflow and activate the license for the right user.
224
+ FS.PostMessage.post('context', {
225
+ plugin_id : '<?php echo $fs->get_id() ?>',
226
+ plugin_public_key: '<?php echo $fs->get_public_key() ?>',
227
+ plugin_version : '<?php echo $fs->get_plugin_version() ?>',
228
+ plugin_slug : '<?php echo $slug ?>',
229
+ site_name : '<?php echo get_bloginfo('name') ?>',
230
+ platform_version : '<?php echo get_bloginfo('version') ?>',
231
+ language : '<?php echo get_bloginfo('language') ?>',
232
+ charset : '<?php echo get_bloginfo('charset') ?>',
233
+ return_url : '<?php echo $return_url ?>',
234
+ account_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url(
235
+ 'account',
236
+ array('fs_action' => 'sync_user')
237
+ ), 'sync_user') ?>',
238
+ activation_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url('',
239
+ array(
240
+ 'fs_action' => $slug . '_activate_new',
241
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
242
+
243
+ )),
244
+ $slug . '_activate_new') ?>'
245
+ }, iframe[0]);
246
+ });
247
+
248
+ FS.PostMessage.receiveOnce('get_dimensions', function (data) {
249
+ console.debug('receiveOnce', 'get_dimensions');
250
+
251
+ FS.PostMessage.post('dimensions', {
252
+ height : $(document.body).height(),
253
+ scrollTop: $(document).scrollTop()
254
+ }, iframe[0]);
255
+ });
256
+ });
257
+ })(jQuery);
258
+ </script>
259
+ </div>
260
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/connect.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = Freemius::_get_current_wp_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/usage-tracking/';
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 $params = $fs->get_opt_in_params() ?>
113
+ <?php foreach ( $params as $name => $value ) : ?>
114
+ <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
115
+ <?php endforeach ?>
116
+ <button class="button button-primary" tabindex="1"
117
+ type="submit"><?php _efs( $is_pending_activation ? 'resend-activation-email' : 'opt-in-connect', $slug ) ?></button>
118
+ </form>
119
+ <?php endif ?>
120
+ </div><?php
121
+
122
+ // Set core permission list items.
123
+ $permissions = array(
124
+ 'profile' => array(
125
+ 'icon-class' => 'dashicons dashicons-admin-users',
126
+ 'label' => __fs( 'permissions-profile' ),
127
+ 'desc' => __fs( 'permissions-profile_desc' ),
128
+ 'priority' => 5,
129
+ ),
130
+ 'site' => array(
131
+ 'icon-class' => 'dashicons dashicons-admin-settings',
132
+ 'label' => __fs( 'permissions-site' ),
133
+ 'desc' => __fs( 'permissions-site_desc' ),
134
+ 'priority' => 10,
135
+ ),
136
+ 'events' => array(
137
+ 'icon-class' => 'dashicons dashicons-admin-plugins',
138
+ 'label' => __fs( 'permissions-events' ),
139
+ 'desc' => __fs( 'permissions-events_desc' ),
140
+ 'priority' => 20,
141
+ ),
142
+ );
143
+
144
+ // Add newsletter permissions if enabled.
145
+ if ( $fs->is_permission_requested( 'newsletter' ) ) {
146
+ $permissions['newsletter'] = array(
147
+ 'icon-class' => 'dashicons dashicons-email-alt',
148
+ 'label' => __fs( 'permissions-newsletter' ),
149
+ 'desc' => __fs( 'permissions-newsletter_desc' ),
150
+ 'priority' => 15,
151
+ );
152
+ }
153
+
154
+ // Allow filtering of the permissions list.
155
+ $permissions = $fs->apply_filters( 'permission_list', $permissions );
156
+
157
+ // Sort by priority.
158
+ uasort( $permissions, 'fs_sort_by_priority' );
159
+
160
+ if ( ! empty( $permissions ) ) : ?>
161
+ <div class="fs-permissions">
162
+ <a class="fs-trigger" href="#"><?php _efs( 'what-permissions', $slug ) ?></a>
163
+ <ul><?php
164
+ foreach ( $permissions as $id => $permission ) : ?>
165
+ <li id="fs-permission-<?php esc_attr_e( $id ); ?>"
166
+ class="fs-permission fs-<?php esc_attr_e( $id ); ?>">
167
+ <i class="<?php esc_attr_e( $permission['icon-class'] ); ?>"></i>
168
+
169
+ <div>
170
+ <span><?php esc_html_e( $permission['label'] ); ?></span>
171
+
172
+ <p><?php esc_html_e( $permission['desc'] ); ?></p>
173
+ </div>
174
+ </li>
175
+ <?php endforeach; ?>
176
+ </ul>
177
+ </div>
178
+ <?php endif; ?>
179
+
180
+ <div class="fs-terms">
181
+ <a href="https://freemius.com/privacy/" target="_blank"><?php _efs( 'privacy-policy', $slug ) ?></a>
182
+ &nbsp;&nbsp;-&nbsp;&nbsp;
183
+ <a href="https://freemius.com/terms/" target="_blank"><?php _efs( 'tos', $slug ) ?></a>
184
+ </div>
185
+ </div>
186
+ <script type="text/javascript">
187
+ (function ($) {
188
+ $('.button').on('click', function () {
189
+ // Set loading mode.
190
+ $(document.body).css({'cursor': 'wait'});
191
+ });
192
+ $('.button.button-primary').on('click', function () {
193
+ $(this).addClass('fs-loading');
194
+ $(this).html('<?php _efs( $is_pending_activation ? 'sending-email' : 'activating' , $slug ) ?>...').css({'cursor': 'wait'});
195
+ });
196
+ $('.fs-permissions .fs-trigger').on('click', function () {
197
+ $('.fs-permissions').toggleClass('fs-open');
198
+ });
199
+ })(jQuery);
200
+ </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,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ selectedReasonID = false;
46
+
47
+ $modal.appendTo($('body'));
48
+
49
+ registerEventHandlers();
50
+
51
+ function registerEventHandlers() {
52
+ $deactivateLink.click(function (evt) {
53
+ evt.preventDefault();
54
+
55
+ showModal();
56
+ });
57
+
58
+ $modal.on('input propertychange', '.reason-input input', function () {
59
+ if (!isOtherReasonSelected()) {
60
+ return;
61
+ }
62
+
63
+ var reason = $(this).val().trim();
64
+
65
+ /**
66
+ * If reason is not empty, remove the error-message class of the message container
67
+ * to change the message color back to default.
68
+ */
69
+ if (reason.length > 0) {
70
+ $('.message').removeClass('error-message');
71
+ enableDeactivateButton();
72
+ }
73
+ });
74
+
75
+ $modal.on('blur', '.reason-input input', function () {
76
+ var $userReason = $(this);
77
+
78
+ setTimeout(function () {
79
+ if (!isOtherReasonSelected()) {
80
+ return;
81
+ }
82
+
83
+ /**
84
+ * If reason is empty, add the error-message class to the message container
85
+ * to change the message color to red.
86
+ */
87
+ if (0 === $userReason.val().trim().length) {
88
+ $('.message').addClass('error-message');
89
+ disableDeactivateButton();
90
+ }
91
+ }, 150);
92
+ });
93
+
94
+ $modal.on('click', '.button', function (evt) {
95
+ evt.preventDefault();
96
+
97
+ if ($(this).hasClass('disabled')) {
98
+ return;
99
+ }
100
+
101
+ var _parent = $(this).parents('.fs-modal:first');
102
+ var _this = $(this);
103
+
104
+ if (_this.hasClass('allow-deactivate')) {
105
+ var $radio = $('input[type="radio"]:checked');
106
+
107
+ if (0 === $radio.length) {
108
+ // If no selected reason, just deactivate the plugin.
109
+ window.location.href = $deactivateLink.attr('href');
110
+ return;
111
+ }
112
+
113
+ var $selected_reason = $radio.parents('li:first'),
114
+ $input = $selected_reason.find('textarea, input[type="text"]'),
115
+ userReason = ( 0 !== $input.length ) ? $input.val().trim() : '';
116
+
117
+ if (isOtherReasonSelected() && ( '' === userReason )) {
118
+ return;
119
+ }
120
+
121
+ $.ajax({
122
+ url : ajaxurl,
123
+ method : 'POST',
124
+ data : {
125
+ 'action' : 'submit-uninstall-reason',
126
+ 'reason_id' : $radio.val(),
127
+ 'reason_info': userReason
128
+ },
129
+ beforeSend: function () {
130
+ _parent.find('.button').addClass('disabled');
131
+ _parent.find('.button-secondary').text('Processing...');
132
+ },
133
+ complete : function () {
134
+ // Do not show the dialog box, deactivate the plugin.
135
+ window.location.href = $deactivateLink.attr('href');
136
+ }
137
+ });
138
+ } else if (_this.hasClass('button-deactivate')) {
139
+ // Change the Deactivate button's text and show the reasons panel.
140
+ _parent.find('.button-deactivate').addClass('allow-deactivate');
141
+
142
+ showPanel('reasons');
143
+ }
144
+ });
145
+
146
+ $modal.on('click', 'input[type="radio"]', function () {
147
+ var $selectedReasonOption = $(this);
148
+
149
+ // If the selection has not changed, do not proceed.
150
+ if (selectedReasonID === $selectedReasonOption.val())
151
+ return;
152
+
153
+ selectedReasonID = $selectedReasonOption.val();
154
+
155
+ var _parent = $(this).parents('li:first');
156
+
157
+ $modal.find('.reason-input').remove();
158
+ $modal.find('.button-deactivate').text('<?php printf( __fs( 'deactivation-modal-button-submit' , $slug ) ); ?>');
159
+
160
+ enableDeactivateButton();
161
+
162
+ if (_parent.hasClass('has-input')) {
163
+ var inputType = _parent.data('input-type'),
164
+ inputPlaceholder = _parent.data('input-placeholder'),
165
+ reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>';
166
+
167
+ _parent.append($(reasonInputHtml));
168
+ _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
169
+
170
+ if (isOtherReasonSelected()) {
171
+ showMessage('<?php printf( __fs( 'ask-for-reason-message' , $slug ) ); ?>');
172
+ disableDeactivateButton();
173
+ }
174
+ }
175
+ });
176
+
177
+ // If the user has clicked outside the window, cancel it.
178
+ $modal.on('click', function (evt) {
179
+ var $target = $(evt.target);
180
+
181
+ // If the user has clicked anywhere in the modal dialog, just return.
182
+ if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) {
183
+ return;
184
+ }
185
+
186
+ // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
187
+ if (!$target.hasClass('button-close') && ( $target.parents('.fs-modal-body').length > 0 || $target.parents('.fs-modal-footer').length > 0 )) {
188
+ return;
189
+ }
190
+
191
+ closeModal();
192
+ });
193
+ }
194
+
195
+ function isOtherReasonSelected() {
196
+ // Get the selected radio input element.
197
+ var $selectedReasonOption = $modal.find('input[type="radio"]:checked'),
198
+ selectedReason = $selectedReasonOption.parent().next().text().trim();
199
+
200
+ return ( 'Other' === selectedReason );
201
+ }
202
+
203
+ function showModal() {
204
+ resetModal();
205
+
206
+ // Display the dialog box.
207
+ $modal.addClass('active');
208
+
209
+ $('body').addClass('has-fs-modal');
210
+ }
211
+
212
+ function closeModal() {
213
+ $modal.removeClass('active');
214
+
215
+ $('body').removeClass('has-fs-modal');
216
+ }
217
+
218
+ function resetModal() {
219
+ selectedReasonID = false;
220
+
221
+ enableDeactivateButton();
222
+
223
+ // Uncheck all radio buttons.
224
+ $modal.find('input[type="radio"]').prop('checked', false);
225
+
226
+ // Remove all input fields ( textfield, textarea ).
227
+ $modal.find('.reason-input').remove();
228
+
229
+ $modal.find('.message').hide();
230
+
231
+ var $deactivateButton = $modal.find('.button-deactivate');
232
+
233
+ /*
234
+ * If the modal dialog has no confirmation message, that is, it has only one panel, then ensure
235
+ * that clicking the deactivate button will actually deactivate the plugin.
236
+ */
237
+ if ($modal.hasClass('no-confirmation-message')) {
238
+ $deactivateButton.addClass('allow-deactivate');
239
+
240
+ showPanel('reasons');
241
+ } else {
242
+ $deactivateButton.removeClass('allow-deactivate');
243
+
244
+ showPanel('confirm');
245
+ }
246
+ }
247
+
248
+ function showMessage(message) {
249
+ $modal.find('.message').text(message).show();
250
+ }
251
+
252
+ function enableDeactivateButton() {
253
+ $modal.find('.button-deactivate').removeClass('disabled');
254
+ }
255
+
256
+ function disableDeactivateButton() {
257
+ $modal.find('.button-deactivate').addClass('disabled');
258
+ }
259
+
260
+ function showPanel(panelType) {
261
+ $modal.find('.fs-modal-panel').removeClass('active ');
262
+ $modal.find('[data-panel-id="' + panelType + '"]').addClass('active');
263
+
264
+ updateButtonLabels();
265
+ }
266
+
267
+ function updateButtonLabels() {
268
+ var $deactivateButton = $modal.find('.button-deactivate');
269
+
270
+ // Reset the deactivate button's text.
271
+ if ('confirm' === getCurrentPanel()) {
272
+ $deactivateButton.text('<?php printf( __fs( 'deactivation-modal-button-confirm' , $slug ) ); ?>');
273
+ } else {
274
+ $deactivateButton.text('<?php printf( __fs( 'skip-deactivate' , $slug ) ); ?>');
275
+ }
276
+ }
277
+
278
+ function getCurrentPanel() {
279
+ return $modal.find('.fs-modal-panel.active').attr('data-panel-id');
280
+ }
281
+ })(jQuery);
282
+ </script>
freemius/templates/debug.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <div>
19
+ <!-- Debugging Switch -->
20
+ <?php //$debug_mode = get_option( 'fs_debug_mode', null ) ?>
21
+ <span class="switch-label"><?php _efs( 'debugging' ) ?></span>
22
+
23
+ <div class="switch <?php echo WP_FS__DEBUG_SDK ? 'off' : 'on' ?>">
24
+ <div class="toggle"></div>
25
+ <span class="on"><?php _efs( 'on' ) ?></span>
26
+ <span class="off"><?php _efs( 'off' ) ?></span>
27
+ </div>
28
+ <script type="text/javascript">
29
+ (function ($) {
30
+ $(document).ready(function () {
31
+ // Switch toggle
32
+ $('.switch').click(function () {
33
+ $(this)
34
+ .toggleClass('on')
35
+ .toggleClass('off');
36
+
37
+ $.post(ajaxurl, {
38
+ action: 'fs_toggle_debug_mode',
39
+ is_on : ($(this).hasClass('off') ? 1 : 0)
40
+ }, function (response) {
41
+ if (1 == response) {
42
+ // Refresh page on success.
43
+ location.reload();
44
+ }
45
+ });
46
+ });
47
+ });
48
+ }(jQuery));
49
+ </script>
50
+ </div>
51
+ <h2><?php _efs( 'actions' ) ?></h2>
52
+ <table>
53
+ <tbody>
54
+ <tr>
55
+ <td>
56
+ <!-- Delete All Accounts -->
57
+ <form action="" method="POST">
58
+ <input type="hidden" name="fs_action" value="restart_freemius">
59
+ <?php wp_nonce_field( 'restart_freemius' ) ?>
60
+ <button class="button button-primary"
61
+ onclick="if (confirm('<?php _efs( 'delete-all-confirm' ) ?>')) this.parentNode.submit(); return false;"><?php _efs( 'delete-all-accounts' ) ?></button>
62
+ </form>
63
+ </td>
64
+ <td>
65
+ <!-- Clear API Cache -->
66
+ <form action="" method="POST">
67
+ <input type="hidden" name="fs_clear_api_cache" value="true">
68
+ <button class="button button-primary"><?php _efs( 'clear-api-cache' ) ?></button>
69
+ </form>
70
+ </td>
71
+ <td>
72
+ <!-- Sync Data with Server -->
73
+ <form action="" method="POST">
74
+ <input type="hidden" name="background_sync" value="true">
75
+ <button class="button button-primary"><?php _efs( 'sync-data-from-server' ) ?></button>
76
+ </form>
77
+ </td>
78
+ </tr>
79
+ </tbody>
80
+ </table>
81
+ <h2><?php _efs( 'sdk-versions' ) ?></h2>
82
+ <table id="fs_sdks" class="widefat">
83
+ <thead>
84
+ <tr>
85
+ <th><?php _efs( 'version' ) ?></th>
86
+ <th><?php _efs( 'sdk-path' ) ?></th>
87
+ <th><?php _efs( 'plugin-path' ) ?></th>
88
+ <th><?php _efs( 'is-active' ) ?></th>
89
+ </tr>
90
+ </thead>
91
+ <tbody>
92
+ <?php foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) : ?>
93
+ <?php $is_active = ( WP_FS__SDK_VERSION == $data->version ) ?>
94
+ <tr<?php if ( $is_active ) {
95
+ echo ' style="background: #E6FFE6; font-weight: bold"';
96
+ } ?>>
97
+ <td><?php echo $data->version ?></td>
98
+ <td><?php echo $sdk_path ?></td>
99
+ <td><?php echo $data->plugin_path ?></td>
100
+ <td><?php echo ( $is_active ) ? 'Active' : 'Inactive' ?></td>
101
+ </tr>
102
+ <?php endforeach ?>
103
+ </tbody>
104
+ </table>
105
+ <?php $plugins = $fs_options->get_option( 'plugins' ) ?>
106
+ <?php if ( is_array( $plugins ) && 0 < count( $plugins ) ) : ?>
107
+ <h2><?php _efs( 'plugins' ) ?></h2>
108
+ <table id="fs_plugins" class="widefat">
109
+ <thead>
110
+ <tr>
111
+ <th><?php _efs( 'id' ) ?></th>
112
+ <th><?php _efs( 'slug' ) ?></th>
113
+ <th><?php _efs( 'version' ) ?></th>
114
+ <th><?php _efs( 'title' ) ?></th>
115
+ <th><?php _efs( 'api' ) ?></th>
116
+ <th><?php _efs( 'freemius-state' ) ?></th>
117
+ <th><?php _efs( 'plugin-path' ) ?></th>
118
+ <th><?php _efs( 'public-key' ) ?></th>
119
+ </tr>
120
+ </thead>
121
+ <tbody>
122
+ <?php foreach ( $plugins as $slug => $data ) : ?>
123
+ <?php $is_active = is_plugin_active( $data->file ) ?>
124
+ <?php $fs = $is_active ? freemius( $slug ) : null ?>
125
+ <tr<?php if ( $is_active ) {
126
+ echo ' style="background: #E6FFE6; font-weight: bold"';
127
+ } ?>>
128
+ <td><?php echo $data->id ?></td>
129
+ <td><?php echo $slug ?></td>
130
+ <td><?php echo $data->version ?></td>
131
+ <td><?php echo $data->title ?></td>
132
+ <td><?php if ( $is_active ) {
133
+ echo $fs->has_api_connectivity() ?
134
+ __fs( 'connected' ) :
135
+ __fs( 'blocked' );
136
+ } ?></td>
137
+ <td><?php if ( $is_active ) {
138
+ echo $fs->is_on() ?
139
+ __fs( 'on' ) :
140
+ __fs( 'off' );
141
+ } ?></td>
142
+ <td><?php echo $data->file ?></td>
143
+ <td><?php echo $data->public_key ?></td>
144
+ </tr>
145
+ <?php endforeach ?>
146
+ </tbody>
147
+ </table>
148
+ <?php endif ?>
149
+ <?php
150
+ /**
151
+ * @var FS_Site[] $sites
152
+ */
153
+ $sites = $VARS['sites'];
154
+ ?>
155
+ <?php if ( is_array( $sites ) && 0 < count( $sites ) ) : ?>
156
+ <h2><?php _efs( 'plugin-installs' ) ?> / <?php _efs( 'sites' ) ?></h2>
157
+ <table id="fs_installs" class="widefat">
158
+ <thead>
159
+ <tr>
160
+ <th><?php _efs( 'id' ) ?></th>
161
+ <th><?php _efs( 'slug' ) ?></th>
162
+ <th><?php _efs( 'plan' ) ?></th>
163
+ <th><?php _efs( 'public-key' ) ?></th>
164
+ <th><?php _efs( 'secret-key' ) ?></th>
165
+ </tr>
166
+ </thead>
167
+ <tbody>
168
+ <?php foreach ( $sites as $slug => $site ) : ?>
169
+ <tr>
170
+ <td><?php echo $site->id ?></td>
171
+ <td><?php echo $slug ?></td>
172
+ <td><?php
173
+ echo is_object( $site->plan ) ?
174
+ base64_decode( $site->plan->name ) :
175
+ ''
176
+ ?></td>
177
+ <td><?php echo $site->public_key ?></td>
178
+ <td><?php echo $site->secret_key ?></td>
179
+ </tr>
180
+ <?php endforeach ?>
181
+ </tbody>
182
+ </table>
183
+ <?php endif ?>
184
+ <?php
185
+ $addons = $VARS['addons'];
186
+ ?>
187
+ <?php foreach ( $addons as $plugin_id => $plugin_addons ) : ?>
188
+ <h2><?php printf( __fs( 'addons-of-x' ), $plugin_id ) ?></h2>
189
+ <table id="fs_addons" class="widefat">
190
+ <thead>
191
+ <tr>
192
+ <th><?php _efs( 'id' ) ?></th>
193
+ <th><?php _efs( 'title' ) ?></th>
194
+ <th><?php _efs( 'slug' ) ?></th>
195
+ <th><?php _efs( 'version' ) ?></th>
196
+ <th><?php _efs( 'public-key' ) ?></th>
197
+ <th><?php _efs( 'secret-key' ) ?></th>
198
+ </tr>
199
+ </thead>
200
+ <tbody>
201
+ <?php
202
+ /**
203
+ * @var FS_Plugin[] $plugin_addons
204
+ */
205
+ foreach ( $plugin_addons as $addon ) : ?>
206
+ <tr>
207
+ <td><?php echo $addon->id ?></td>
208
+ <td><?php echo $addon->title ?></td>
209
+ <td><?php echo $addon->slug ?></td>
210
+ <td><?php echo $addon->version ?></td>
211
+ <td><?php echo $addon->public_key ?></td>
212
+ <td><?php echo $addon->secret_key ?></td>
213
+ </tr>
214
+ <?php endforeach ?>
215
+ </tbody>
216
+ </table>
217
+ <?php endforeach ?>
218
+ <?php
219
+ /**
220
+ * @var FS_User[] $users
221
+ */
222
+ $users = $VARS['users'];
223
+ ?>
224
+ <?php if ( is_array( $users ) && 0 < count( $users ) ) : ?>
225
+ <h2><?php _efs( 'users' ) ?></h2>
226
+ <table id="fs_users" class="widefat">
227
+ <thead>
228
+ <tr>
229
+ <th><?php _efs( 'id' ) ?></th>
230
+ <th><?php _efs( 'name' ) ?></th>
231
+ <th><?php _efs( 'email' ) ?></th>
232
+ <th><?php _efs( 'verified' ) ?></th>
233
+ <th><?php _efs( 'public-key' ) ?></th>
234
+ <th><?php _efs( 'secret-key' ) ?></th>
235
+ </tr>
236
+ </thead>
237
+ <tbody>
238
+ <?php foreach ( $users as $user_id => $user ) : ?>
239
+ <tr>
240
+ <td><?php echo $user->id ?></td>
241
+ <td><?php echo $user->get_name() ?></td>
242
+ <td><a href="mailto:<?php esc_attr_e($user->email) ?>"><?php echo $user->email ?></a></td>
243
+ <td><?php echo json_encode( $user->is_verified ) ?></td>
244
+ <td><?php echo $user->public_key ?></td>
245
+ <td><?php echo $user->secret_key ?></td>
246
+ </tr>
247
+ <?php endforeach ?>
248
+ </tbody>
249
+ </table>
250
+ <?php endif ?>
freemius/templates/debug/api-calls.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( class_exists( 'Freemius_Api' ) ) {
14
+ $logger = Freemius_Api::GetLogger();
15
+ } else {
16
+ $logger = array();
17
+ }
18
+
19
+ $counters = array(
20
+ 'GET' => 0,
21
+ 'POST' => 0,
22
+ 'PUT' => 0,
23
+ 'DELETE' => 0
24
+ );
25
+
26
+ $show_body = false;
27
+ foreach ( $logger as $log ) {
28
+ $counters[ $log['method'] ] ++;
29
+
30
+ if ( ! is_null( $log['body'] ) ) {
31
+ $show_body = true;
32
+ }
33
+ }
34
+
35
+ $pretty_print = $show_body && defined( 'JSON_PRETTY_PRINT' ) && version_compare( phpversion(), '5.3', '>=' );
36
+
37
+ $root_path_len = strlen( ABSPATH );
38
+ ?>
39
+ <h1><?php _efs( 'API' ) ?></h1>
40
+
41
+ <h2><span>Total Time:</span><?php echo Freemius_Debug_Bar_Panel::total_time() ?></h2>
42
+
43
+ <h2><span>Total Requests:</span><?php echo Freemius_Debug_Bar_Panel::requests_count() ?></h2>
44
+ <?php foreach ( $counters as $method => $count ) : ?>
45
+ <h2><span><?php echo $method ?>:</span><?php echo number_format( $count ) ?></h2>
46
+ <?php endforeach ?>
47
+ <table class="widefat">
48
+ <thead>
49
+ <tr>
50
+ <th>#</th>
51
+ <th><?php _efs( 'Method' ) ?></th>
52
+ <th><?php _efs( 'Code' ) ?></th>
53
+ <th><?php _efs( 'Length' ) ?></th>
54
+ <th><?php _efs( 'Path' ) ?></th>
55
+ <?php if ( $show_body ) : ?>
56
+ <th><?php _efs( 'Body' ) ?></th>
57
+ <?php endif ?>
58
+ <th><?php _efs( 'Result' ) ?></th>
59
+ <th><?php _efs( 'Start' ) ?></th>
60
+ <th><?php _efs( 'End' ) ?></th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <?php foreach ( $logger as $log ) : ?>
65
+ <tr>
66
+ <td><?php echo $log['id'] ?>.</td>
67
+ <td><?php echo $log['method'] ?></td>
68
+ <td><?php echo $log['code'] ?></td>
69
+ <td><?php echo number_format( 100 * $log['total'], 2 ) . ' ' . __fs( 'ms' ) ?></td>
70
+ <td>
71
+ <?php
72
+ printf( '<a href="#" onclick="jQuery(this).parent().find(\'table\').toggle(); return false;">%s</a>',
73
+ $log['path']
74
+ );
75
+ ?>
76
+ <table class="widefat" style="display: none">
77
+ <tbody>
78
+ <?php for ( $i = 0, $bt = $log['backtrace'], $len = count( $bt ); $i < $len; $i ++ ) : ?>
79
+ <tr>
80
+ <td><?php echo( $len - $i ) ?></td>
81
+ <td><?php if ( isset( $bt[ $i ]['function'] ) ) {
82
+ echo ( isset( $bt[ $i ]['class'] ) ? $bt[ $i ]['class'] . $bt[ $i ]['type'] : '' ) . $bt[ $i ]['function'];
83
+ } ?></td>
84
+ <td><?php if ( isset( $bt[ $i ]['file'] ) ) {
85
+ echo substr( $bt[ $i ]['file'], $root_path_len ) . ':' . $bt[ $i ]['line'];
86
+ } ?></td>
87
+ </tr>
88
+ <?php endfor ?>
89
+ </tbody>
90
+ </table>
91
+ </td>
92
+ <?php if ( $show_body ) : ?>
93
+ <td>
94
+ <?php if ( 'GET' !== $log['method'] ) : ?>
95
+ <?php
96
+ $body = $log['body'];
97
+ printf(
98
+ '<a href="#" onclick="jQuery(this).parent().find(\'pre\').toggle(); return false;">%s</a>',
99
+ substr( $body, 0, 32 ) . ( 32 < strlen( $body ) ? '...' : '' )
100
+ );
101
+ if ( $pretty_print ) {
102
+ $body = json_encode( json_decode( $log['body'] ), JSON_PRETTY_PRINT );
103
+ }
104
+ ?>
105
+ <pre style="display: none"><code><?php echo esc_html( $body ) ?></code></pre>
106
+ <?php endif ?>
107
+ </td>
108
+ <?php endif ?>
109
+ <td>
110
+ <?php
111
+ $result = $log['result'];
112
+
113
+ $is_not_empty_result = ( is_string( $result ) && ! empty( $result ) );
114
+
115
+ if ( $is_not_empty_result ) {
116
+ printf(
117
+ '<a href="#" onclick="jQuery(this).parent().find(\'pre\').toggle(); return false;">%s</a>',
118
+ substr( $result, 0, 32 ) . ( 32 < strlen( $result ) ? '...' : '' )
119
+ );
120
+ }
121
+
122
+ if ( $is_not_empty_result && $pretty_print ) {
123
+ $decoded = json_decode( $result );
124
+ if ( ! is_null( $decoded ) ) {
125
+ $result = json_encode( $decoded, JSON_PRETTY_PRINT );
126
+ }
127
+ } else {
128
+ $result = is_string( $result ) ? $result : json_encode( $result );
129
+ }
130
+ ?>
131
+ <pre<?php if ( $is_not_empty_result ) : ?> style="display: none"<?php endif ?>><code><?php echo esc_html( $result ) ?></code></pre>
132
+ </td>
133
+ <td><?php echo number_format( 100 * ( $log['start'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
134
+ <td><?php echo number_format( 100 * ( $log['end'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
135
+ </tr>
136
+ <?php endforeach ?>
137
+ </tbody>
138
+ </table>
freemius/templates/debug/logger.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $log_book = FS_Logger::get_log();
14
+ ?>
15
+ <h1><?php _efs( 'Log' ) ?></h1>
16
+
17
+ <table class="widefat" style="font-size: 11px;">
18
+ <thead>
19
+ <tr>
20
+ <th>#</th>
21
+ <th><?php _efs( 'id' ) ?></th>
22
+ <th><?php _efs( 'type' ) ?></th>
23
+ <th><?php _efs( 'function' ) ?></th>
24
+ <th><?php _efs( 'message' ) ?></th>
25
+ <th><?php _efs( 'file' ) ?></th>
26
+ <th><?php _efs( 'timestamp' ) ?></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+
31
+ <?php $i = 0;
32
+ foreach ( $log_book as $log ) : ?>
33
+ <tr<?php if ( $i % 2 ) {
34
+ echo ' class="alternate"';
35
+ } ?>>
36
+ <td><?php echo $log['cnt'] ?>.</td>
37
+ <td><?php echo $log['logger']->get_id() ?></td>
38
+ <td><?php echo $log['type'] ?></td>
39
+ <td><b><code style="color: blue;"><?php echo $log['function'] ?></code></b></td>
40
+ <td>
41
+ <?php
42
+ printf(
43
+ '<a href="#" style="color: darkorange !important;" onclick="jQuery(this).parent().find(\'div\').toggle(); return false;"><nobr>%s</nobr></a>',
44
+ substr( $log['msg'], 0, 32 ) . ( 32 < strlen( $log['msg'] ) ? '...' : '' )
45
+ );
46
+ ?>
47
+ <div style="display: none;">
48
+ <b style="color: darkorange;"><?php echo $log['msg'] ?></b>
49
+ </div>
50
+ </td>
51
+ <td><?php
52
+ if ( isset( $log['file'] ) ) {
53
+ echo substr( $log['file'], $log['logger']->get_file() ) . ':' . $log['line'] . ')';
54
+ }
55
+ ?></td>
56
+ <td><?php echo number_format( 100 * ( $log['timestamp'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
57
+ </tr>
58
+ <?php $i ++; endforeach ?>
59
+ </tbody>
60
+ </table>
freemius/templates/debug/plugins-themes-sync.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
14
+ $all_plugins = $fs_options->get_option( 'all_plugins' );
15
+ $all_themes = $fs_options->get_option( 'all_themes' );
16
+ ?>
17
+ <h1><?php _efs( 'plugins-themes-sync' ) ?></h1>
18
+ <table class="widefat">
19
+ <thead>
20
+ <tr>
21
+ <th></th>
22
+ <th><?php _efs( 'total' ) ?></th>
23
+ <th><?php _efs( 'Last' ) ?></th>
24
+ </tr>
25
+ </thead>
26
+ <tbody>
27
+ <?php if ( is_object( $all_plugins ) ) : ?>
28
+ <tr>
29
+ <td><?php _efs( 'plugins' ) ?></td>
30
+ <td><?php echo count( $all_plugins->plugins ) ?></td>
31
+ <td><?php
32
+ if ( isset( $all_plugins->timestamp ) && is_numeric( $all_plugins->timestamp ) ) {
33
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $all_plugins->timestamp );
34
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
35
+ $diff . ' ' . __fs( 'sec' ) :
36
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $all_plugins->timestamp );
37
+
38
+ if ( WP_FS__SCRIPT_START_TIME < $all_plugins->timestamp ) {
39
+ printf( __fs( 'in-x' ), $human_diff );
40
+ } else {
41
+ printf( __fs( 'x-ago' ), $human_diff );
42
+ }
43
+ }
44
+ ?></td>
45
+ </tr>
46
+ <?php endif ?>
47
+ <?php if ( is_object( $all_themes ) ) : ?>
48
+ <tr>
49
+ <td><?php _efs( 'themes' ) ?></td>
50
+ <td><?php echo count( $all_themes->themes ) ?></td>
51
+ <td><?php
52
+ if ( isset( $all_themes->timestamp ) && is_numeric( $all_themes->timestamp ) ) {
53
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $all_themes->timestamp );
54
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
55
+ $diff . ' ' . __fs( 'sec' ) :
56
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $all_themes->timestamp );
57
+
58
+ if ( WP_FS__SCRIPT_START_TIME < $all_themes->timestamp ) {
59
+ printf( __fs( 'in-x' ), $human_diff );
60
+ } else {
61
+ printf( __fs( 'x-ago' ), $human_diff );
62
+ }
63
+ }
64
+ ?></td>
65
+ </tr>
66
+ <?php endif ?>
67
+ </tbody>
68
+ </table>
freemius/templates/debug/scheduled-crons.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.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
14
+ $plugins = $fs_options->get_option( 'plugins' );
15
+ $scheduled_crons = array();
16
+ if ( is_array( $plugins ) && 0 < count( $plugins ) ) {
17
+ foreach ( $plugins as $slug => $data ) {
18
+ $fs = freemius( $slug );
19
+
20
+ $next_execution = $fs->next_sync_cron();
21
+ $last_execution = $fs->last_sync_cron();
22
+
23
+ if ( false !== $next_execution ) {
24
+ $scheduled_crons[ $slug ][] = array(
25
+ 'name' => $fs->get_plugin_name(),
26
+ 'slug' => $slug,
27
+ 'type' => 'sync_cron',
28
+ 'last' => $last_execution,
29
+ 'next' => $next_execution,
30
+ );
31
+ }
32
+
33
+ $next_install_execution = $fs->next_install_sync();
34
+ $last_install_execution = $fs->last_install_sync();
35
+
36
+ if ( false !== $next_install_execution || false !== $last_install_execution ) {
37
+ $scheduled_crons[ $slug ][] = array(
38
+ 'name' => $fs->get_plugin_name(),
39
+ 'slug' => $slug,
40
+ 'type' => 'install_sync',
41
+ 'last' => $last_install_execution,
42
+ 'next' => $next_install_execution,
43
+ );
44
+ }
45
+ }
46
+ }
47
+ ?>
48
+ <h1><?php _efs( 'scheduled-crons' ) ?></h1>
49
+ <table class="widefat">
50
+ <thead>
51
+ <tr>
52
+ <th><?php _efs( 'slug' ) ?></th>
53
+ <th><?php _efs( 'plugin' ) ?></th>
54
+ <th><?php _efs( 'type' ) ?></th>
55
+ <th><?php _efs( 'Last' ) ?></th>
56
+ <th><?php _efs( 'Next' ) ?></th>
57
+ </tr>
58
+ </thead>
59
+ <tbody>
60
+ <?php foreach ( $scheduled_crons as $slug => $crons ) : ?>
61
+ <?php foreach ( $crons as $cron ) : ?>
62
+ <tr>
63
+ <td><?php echo $slug ?></td>
64
+ <td><?php echo $cron['name'] ?></td>
65
+ <td><?php echo $cron['type'] ?></td>
66
+ <td><?php
67
+ if (is_numeric($cron['last'])) {
68
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $cron['last'] );
69
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
70
+ $diff . ' ' . __fs( 'sec' ) :
71
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $cron['last'] );
72
+
73
+ if ( WP_FS__SCRIPT_START_TIME < $cron['last'] ) {
74
+ printf( __fs( 'in-x' ), $human_diff );
75
+ } else {
76
+ printf( __fs( 'x-ago' ), $human_diff );
77
+ }
78
+
79
+ // echo ' ' . $cron['last'];
80
+ }
81
+ ?></td>
82
+ <td><?php
83
+ if (is_numeric($cron['next'])) {
84
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $cron['next'] );
85
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
86
+ $diff . ' ' . __fs( 'sec' ) :
87
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $cron['next'] );
88
+
89
+ if ( WP_FS__SCRIPT_START_TIME < $cron['next'] ) {
90
+ printf( __fs( 'in-x' ), $human_diff );
91
+ } else {
92
+ printf( __fs( 'x-ago' ), $human_diff );
93
+ }
94
+ }
95
+ ?></td>
96
+ </tr>
97
+ <?php endforeach ?>
98
+ <?php endforeach ?>
99
+ </tbody>
100
+ </table>
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,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ('retry_ping' === error_type) {
43
+ data.action = slug + '_retry_connectivity_test';
44
+ }
45
+
46
+ $(this).css({'cursor': 'wait'});
47
+
48
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
49
+ $.post(ajaxurl, data, function (response) {
50
+ if (1 == response) {
51
+ // Refresh page on success.
52
+ location.reload();
53
+ } else if ('http' === response.substr(0, 4)) {
54
+ // Ping actually worked, redirect.
55
+ window.location = response;
56
+ }
57
+ });
58
+ });
59
+ });
60
+ </script>
freemius/templates/plugin-icon.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /**
17
+ * @since 1.1.7.5
18
+ */
19
+ $local_path = $fs->apply_filters( 'plugin_icon', false );
20
+
21
+ if ( is_string( $local_path ) ) {
22
+ $icons = array( $local_path );
23
+ } else {
24
+ global $fs_active_plugins;
25
+
26
+ $img_dir = WP_FS__DIR_IMG;
27
+
28
+ if ( 1 < count( $fs_active_plugins->plugins ) ) {
29
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
30
+ if ( $data->plugin_path == $fs->get_plugin_basename() ) {
31
+ $img_dir = WP_PLUGIN_DIR . '/' . $sdk_path . '/assets/img';
32
+ break;
33
+ }
34
+ }
35
+ }
36
+
37
+ $icons = glob( fs_normalize_path( $img_dir . '/' . $slug . '.*' ) );
38
+ if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
39
+ $icon_found = false;
40
+ $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.png' );
41
+ $have_write_permissions = is_writable( fs_normalize_path( $img_dir ) );
42
+
43
+ if ( WP_FS__IS_LOCALHOST && $fs->is_org_repo_compliant() && $have_write_permissions ) {
44
+ /**
45
+ * IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
46
+ *
47
+ * This code will only be executed once during the testing
48
+ * of the plugin in a local environment. The plugin icon file WILL
49
+ * already exist in the assets folder when the plugin is deployed to
50
+ * the repository.
51
+ */
52
+ $suffixes = array(
53
+ '-128x128.png',
54
+ '-128x128.jpg',
55
+ '-256x256.png',
56
+ '-256x256.jpg',
57
+ '.svg',
58
+ );
59
+
60
+ $base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';
61
+
62
+ foreach ( $suffixes as $s ) {
63
+ $headers = get_headers( $base_url . $s );
64
+ if ( strpos( $headers[0], '200' ) ) {
65
+ $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.' . substr( $s, strpos( $s, '.' ) + 1 ) );
66
+ fs_download_image( $base_url . $s, $local_path );
67
+ $icon_found = true;
68
+ break;
69
+ }
70
+ }
71
+ }
72
+
73
+ if ( ! $icon_found ) {
74
+ // No icons found, fallback to default icon.
75
+ if ( $have_write_permissions ) {
76
+ // If have write permissions, copy default icon.
77
+ copy( fs_normalize_path( $img_dir . '/plugin-icon.png' ), $local_path );
78
+ } else {
79
+ // If doesn't have write permissions, use default icon path.
80
+ $local_path = fs_normalize_path( $img_dir . '/plugin-icon.png' );
81
+ }
82
+ }
83
+
84
+ $icons = array( $local_path );
85
+ }
86
+ }
87
+
88
+ $icon_dir = dirname( $icons[0] );
89
+ $relative_url = fs_img_url( substr( $icons[0], strlen( $icon_dir ) ), $icon_dir );
90
+ ?>
91
+ <div class="fs-plugin-icon">
92
+ <img src="<?php echo $relative_url ?>"/>
93
+ </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>
js/meta-tag-manager-settings.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($){
2
+ //Meta Box Options
3
+ //$(".postbox > h2").click(function(){ $(this).parent().toggleClass('closed'); });
4
+ //$(".postbox").addClass('closed');
5
+ //Navigation Tabs
6
+ $('.tabs-active .nav-tab-wrapper .nav-tab').click(function(){
7
+ el = $(this);
8
+ elid = el.attr('id');
9
+ $('.mtm-menu-group').hide();
10
+ $('.'+elid).show();
11
+ //$(".postbox").addClass('closed');
12
+ //open_close.text(EM.open_text);
13
+ });
14
+ $('.nav-tab-wrapper .nav-tab').click(function(){
15
+ $('.nav-tab-wrapper .nav-tab').removeClass('nav-tab-active');
16
+ $(this).addClass('nav-tab-active').blur();
17
+ });
18
+ var navUrl = document.location.toString();
19
+ if (navUrl.match('#')) { //anchor-based navigation
20
+ var nav_tab = navUrl.split('#');
21
+ var current_tab = 'a#mtm-menu-' + nav_tab[1];
22
+ $(current_tab).trigger('click');
23
+ if( nav_tab.length > 2 ){
24
+ section = $("#mtm-opt-"+nav_tab[2]);
25
+ if( section.length > 0 ){
26
+ section.children('h2').trigger('click');
27
+ $('html, body').animate({ scrollTop: section.offset().top - 30 }); //sends user back to current section
28
+ }
29
+ }
30
+ }else{
31
+ //set to general tab by default, so we can also add clicked subsections
32
+ document.location = navUrl+"#builder";
33
+ }
34
+ $('.nav-tab-link').click(function(){ $($(this).attr('rel')).trigger('click'); }); //links to mimick tabs
35
+ $('input[type="submit"]').click(function(){
36
+ var el = $(this).parents('.postbox').first();
37
+ var docloc = document.location.toString().split('#');
38
+ var newloc = docloc[0];
39
+ if( docloc.length > 1 ){
40
+ var nav_tab = docloc[1].split('#');
41
+ newloc = newloc + "#" + nav_tab[0];
42
+ if( el.attr('id') ){
43
+ newloc = newloc + "#" + el.attr('id').replace('mtm-opt-','');
44
+ }
45
+ }
46
+ document.location = newloc;
47
+ });
48
+ });
js/meta-tag-manager.js ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready( function($) {
2
+ //initialize one or many meta tag field forms
3
+ var init_fields = function( container ){
4
+ //add selectize for the type selector
5
+ container.find('.mtm-field-input-tag-type').each( function(e){
6
+ if( this.value == 'charset' ){
7
+ $(this).closest('.mtm-field').find('.mtm-field-type-content').show();
8
+ }
9
+ });
10
+ container.find('.mtm-field-input-tag-type').selectize().on('change', function(e){
11
+ var parent = $(this).closest('.mtm-field');
12
+ parent.find('.mtm-field-type-content').hide();
13
+ if( this.value != 'charset' ){
14
+ parent.find('.mtm-field-type-content').show();
15
+ }
16
+ //get value input from template and selectize
17
+ var value_template = $(this).closest('.mtm-builder').find('.mtm-field-type-templates .mtm-field-input-tag-'+this.value).first().clone();
18
+ if( value_template.length > 0 ){
19
+ //clone, rename, selectize
20
+ value_template = value_template.clone();
21
+ var current_value = parent.find('select.mtm-field-input-tag-value, input.mtm-field-input-tag-value');
22
+ var current_value_name = current_value.attr('name');
23
+ current_value.each(function(){ if( typeof this.selectize != 'undefined' ) this.selectize.destroy(); }).replaceWith(value_template);
24
+ parent.find('.mtm-field-input.mtm-field-type-value label em').text(this.value);
25
+ value_template.attr('name', current_value_name).trigger('change');
26
+ if( value_template.is('select') ) value_template.selectize({ create: true });
27
+ }
28
+ });
29
+ //add selectize for contexts, which is a tag-style selection
30
+ container.find('.mtm-field-input-tag-context').selectize({
31
+ plugins: ['remove_button'],
32
+ maxItems: 100,
33
+ closeAfterSelect: true,
34
+ //add some extra functions in case 'all' is selected, hence no need to select other things
35
+ onItemAdd: function(value, item){
36
+ if( this.items.length > 1 ){
37
+ if( value == 'all' ){
38
+ this.clear(true);
39
+ this.addItem('all', true);
40
+ //this.settings.maxItems = 1;
41
+ }else if( this.getItem('all').length ){
42
+ this.removeItem('all', true);
43
+ }
44
+ }
45
+ },
46
+ //update display values on header of field card
47
+ onChange: function(items){
48
+ var values = [];
49
+ if( typeof items == 'object' && items ){
50
+ items.forEach(function(item){
51
+ values.push(this.getItem(item).text().replace(/×$/i, ''));
52
+ }, this);
53
+ }
54
+ this.$control.closest('.mtm-field').find('.mtm-meta-context-values').text(values.join(', '));
55
+ }
56
+ }).on('click', function(){ this.selectize.open(); });
57
+ //general selectize for other selectizable dropdowns
58
+ container.find('.mtm-field-input-selectize').selectize({
59
+ create: true,
60
+ });
61
+ container.find('.mtm-field-input-tag-reference').hide();
62
+ }
63
+ //init displayed fields on page load
64
+ $('.mtm-builder .mtm-fields .mtm-field').addClass('closed')
65
+ init_fields($('.mtm-builder .mtm-fields'));
66
+
67
+ //build meta tag dynamically
68
+ var build_meta_tag = function( container ){
69
+ var meta_type = container.find('.mtm-field-input-tag-type option:selected').val();
70
+ if( meta_type ){
71
+ container.find('.mtm-field-title code').show();
72
+ var meta_value = container.find('select.mtm-field-input-tag-'+ meta_type +' option:selected').val();
73
+ container.find('.mtm-field-title code .mtm-meta-type-att').text(meta_type).css('opacity','0.1').animate({'opacity':'1'});
74
+ container.find('.mtm-field-title code .mtm-meta-type-val').text(meta_value).css('opacity','0.1').animate({'opacity':'1'});
75
+ if( meta_type == 'charset' ){
76
+ container.find('.mtm-field-title code .mtm-meta-content').hide();
77
+ }else{
78
+ container.find('.mtm-field-title code .mtm-meta-content').fadeIn().children('.mtm-meta-content-value').text(container.find('.mtm-field-input-tag-content').val()).css('opacity','0.1').animate({'opacity':'1'});
79
+ }
80
+ }
81
+ }
82
+ $('.mtm-builder').on('change', '.mtm-field-input-tag-type', function(){
83
+ build_meta_tag( $(this).closest('.mtm-field') );
84
+ });
85
+ $('.mtm-builder').on('keyup change', '.mtm-field-input-tag-content', function(){
86
+ $(this).closest('.mtm-field').find('.mtm-field-title code .mtm-meta-content-value').css('opacity','0.1').animate({'opacity':'1'}).text(this.value);
87
+ });
88
+ $('.mtm-builder').on('change keyup', '.mtm-field-input-tag-value', function(){
89
+ $(this).closest('.mtm-field').find('.mtm-field-title code .mtm-meta-type-val').css('opacity','0.1').animate({'opacity':'1'}).text(this.value);
90
+ });
91
+ $('.mtm-builder').on('keyup change', '.mtm-field-input-tag-reference', function(){
92
+ $(this).closest('.mtm-field').find('.mtm-field-title .mtm-meta-reference .mtm-meta-reference-value').text(this.value);
93
+ });
94
+ $('.mtm-builder').on('blur', '.mtm-field-input-tag-reference', function(e){
95
+ e.preventDefault();
96
+ });
97
+
98
+ //make sortable
99
+ $(".mtm-builder .mtm-fields" ).sortable({
100
+ placeholder: "mtm-field-placeholder",
101
+ handle: '.mtm-field-header',
102
+ start: function( event, ui ){
103
+ ui.item.addClass('closed').data('openField', false);
104
+ ui.item.css('height', 'auto');
105
+ }
106
+ });
107
+ //actions for field cards
108
+ $('.mtm-builder').on('mousedown mouseup', '.mtm-field-header, button.mtm-field-close', function(e){
109
+ //open/close functionality for fields
110
+ if( $(e.target).hasClass('mtm-field-input-tag-reference') ) return;
111
+ var field = $(this).closest('.mtm-field');
112
+ if( e.type == 'mousedown' ){
113
+ field.data('openField', field.hasClass('closed')); //allow sortable overriding
114
+ field.addClass('closed');
115
+ field.find('.mtm-meta-reference .mtm-meta-reference-value').show();
116
+ field.find('.mtm-meta-reference .mtm-field-input-tag-reference').hide();
117
+ }else if( field.data('openField') ){
118
+ field.siblings('.mtm-field').addClass('closed');
119
+ field.removeClass('closed');
120
+ field.find('.mtm-meta-reference .mtm-meta-reference-value').hide();
121
+ field.find('.mtm-meta-reference .mtm-field-input-tag-reference').show();
122
+ }
123
+ }).on('click', '.mtm-field-remove', function(){
124
+ //removing a card
125
+ if( $(this).closest('.mtm-fields').children('.mtm-field').length <= 1 ){
126
+ $(this).closest('.mtm-builder').find('.mtm-field-placeholder').show();
127
+ }
128
+ $(this).closest('.mtm-field').remove();
129
+ }).on('click', '.mtm-add-field', function(e){
130
+ //adding a field
131
+ e.preventDefault();
132
+ var container = $(this).closest('.mtm-builder');
133
+ container.find('.mtm-field-placeholder').hide();
134
+ container.find('.mtm-field').addClass('closed');
135
+ var index = container.data('nextIndex');
136
+ container.data('nextIndex', index + 1);
137
+ var new_field = $('.mtm-field-template .mtm-field').clone().data('thisIndex', index);
138
+ new_field.find("[name*='[t]']").each( function( i ){
139
+ var new_attribute = $(this).attr('name').replace('mtm-fields[t]', 'mtm-fields['+ index +']');
140
+ $(this).attr('name', new_attribute);
141
+ });
142
+ $('.mtm-builder .mtm-fields').append(new_field);
143
+ init_fields(new_field);
144
+ new_field.removeClass('closed');
145
+ new_field.find('.mtm-meta-reference .mtm-meta-reference-value').hide();
146
+ new_field.find('.mtm-meta-reference .mtm-field-input-tag-reference').show();
147
+ $(this).blur();
148
+ }).data('nextIndex', $('.mtm-builder .mtm-fields .mtm-field').length); //set index counter
149
+
150
+ $('.mtm-settings .mtm-post-types .mtm-post-types-select').selectize({
151
+ plugins: ['remove_button'],
152
+ maxItems: 100,
153
+ closeAfterSelect: false
154
+ }).on('click', function(){ this.selectize.open(); });
155
+ });
js/selectize.js ADDED
@@ -0,0 +1,3667 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * sifter.js
3
+ * Copyright (c) 2013 Brian Reavis & contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ * ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ *
14
+ * @author Brian Reavis <brian@thirdroute.com>
15
+ */
16
+
17
+ (function(root, factory) {
18
+ if (typeof define === 'function' && define.amd) {
19
+ define('sifter', factory);
20
+ } else if (typeof exports === 'object') {
21
+ module.exports = factory();
22
+ } else {
23
+ root.Sifter = factory();
24
+ }
25
+ }(this, function() {
26
+
27
+ /**
28
+ * Textually searches arrays and hashes of objects
29
+ * by property (or multiple properties). Designed
30
+ * specifically for autocomplete.
31
+ *
32
+ * @constructor
33
+ * @param {array|object} items
34
+ * @param {object} items
35
+ */
36
+ var Sifter = function(items, settings) {
37
+ this.items = items;
38
+ this.settings = settings || {diacritics: true};
39
+ };
40
+
41
+ /**
42
+ * Splits a search string into an array of individual
43
+ * regexps to be used to match results.
44
+ *
45
+ * @param {string} query
46
+ * @returns {array}
47
+ */
48
+ Sifter.prototype.tokenize = function(query) {
49
+ query = trim(String(query || '').toLowerCase());
50
+ if (!query || !query.length) return [];
51
+
52
+ var i, n, regex, letter;
53
+ var tokens = [];
54
+ var words = query.split(/ +/);
55
+
56
+ for (i = 0, n = words.length; i < n; i++) {
57
+ regex = escape_regex(words[i]);
58
+ if (this.settings.diacritics) {
59
+ for (letter in DIACRITICS) {
60
+ if (DIACRITICS.hasOwnProperty(letter)) {
61
+ regex = regex.replace(new RegExp(letter, 'g'), DIACRITICS[letter]);
62
+ }
63
+ }
64
+ }
65
+ tokens.push({
66
+ string : words[i],
67
+ regex : new RegExp(regex, 'i')
68
+ });
69
+ }
70
+
71
+ return tokens;
72
+ };
73
+
74
+ /**
75
+ * Iterates over arrays and hashes.
76
+ *
77
+ * ```
78
+ * this.iterator(this.items, function(item, id) {
79
+ * // invoked for each item
80
+ * });
81
+ * ```
82
+ *
83
+ * @param {array|object} object
84
+ */
85
+ Sifter.prototype.iterator = function(object, callback) {
86
+ var iterator;
87
+ if (is_array(object)) {
88
+ iterator = Array.prototype.forEach || function(callback) {
89
+ for (var i = 0, n = this.length; i < n; i++) {
90
+ callback(this[i], i, this);
91
+ }
92
+ };
93
+ } else {
94
+ iterator = function(callback) {
95
+ for (var key in this) {
96
+ if (this.hasOwnProperty(key)) {
97
+ callback(this[key], key, this);
98
+ }
99
+ }
100
+ };
101
+ }
102
+
103
+ iterator.apply(object, [callback]);
104
+ };
105
+
106
+ /**
107
+ * Returns a function to be used to score individual results.
108
+ *
109
+ * Good matches will have a higher score than poor matches.
110
+ * If an item is not a match, 0 will be returned by the function.
111
+ *
112
+ * @param {object|string} search
113
+ * @param {object} options (optional)
114
+ * @returns {function}
115
+ */
116
+ Sifter.prototype.getScoreFunction = function(search, options) {
117
+ var self, fields, tokens, token_count;
118
+
119
+ self = this;
120
+ search = self.prepareSearch(search, options);
121
+ tokens = search.tokens;
122
+ fields = search.options.fields;
123
+ token_count = tokens.length;
124
+
125
+ /**
126
+ * Calculates how close of a match the
127
+ * given value is against a search token.
128
+ *
129
+ * @param {mixed} value
130
+ * @param {object} token
131
+ * @return {number}
132
+ */
133
+ var scoreValue = function(value, token) {
134
+ var score, pos;
135
+
136
+ if (!value) return 0;
137
+ value = String(value || '');
138
+ pos = value.search(token.regex);
139
+ if (pos === -1) return 0;
140
+ score = token.string.length / value.length;
141
+ if (pos === 0) score += 0.5;
142
+ return score;
143
+ };
144
+
145
+ /**
146
+ * Calculates the score of an object
147
+ * against the search query.
148
+ *
149
+ * @param {object} token
150
+ * @param {object} data
151
+ * @return {number}
152
+ */
153
+ var scoreObject = (function() {
154
+ var field_count = fields.length;
155
+ if (!field_count) {
156
+ return function() { return 0; };
157
+ }
158
+ if (field_count === 1) {
159
+ return function(token, data) {
160
+ return scoreValue(data[fields[0]], token);
161
+ };
162
+ }
163
+ return function(token, data) {
164
+ for (var i = 0, sum = 0; i < field_count; i++) {
165
+ sum += scoreValue(data[fields[i]], token);
166
+ }
167
+ return sum / field_count;
168
+ };
169
+ })();
170
+
171
+ if (!token_count) {
172
+ return function() { return 0; };
173
+ }
174
+ if (token_count === 1) {
175
+ return function(data) {
176
+ return scoreObject(tokens[0], data);
177
+ };
178
+ }
179
+
180
+ if (search.options.conjunction === 'and') {
181
+ return function(data) {
182
+ var score;
183
+ for (var i = 0, sum = 0; i < token_count; i++) {
184
+ score = scoreObject(tokens[i], data);
185
+ if (score <= 0) return 0;
186
+ sum += score;
187
+ }
188
+ return sum / token_count;
189
+ };
190
+ } else {
191
+ return function(data) {
192
+ for (var i = 0, sum = 0; i < token_count; i++) {
193
+ sum += scoreObject(tokens[i], data);
194
+ }
195
+ return sum / token_count;
196
+ };
197
+ }
198
+ };
199
+
200
+ /**
201
+ * Returns a function that can be used to compare two
202
+ * results, for sorting purposes. If no sorting should
203
+ * be performed, `null` will be returned.
204
+ *
205
+ * @param {string|object} search
206
+ * @param {object} options
207
+ * @return function(a,b)
208
+ */
209
+ Sifter.prototype.getSortFunction = function(search, options) {
210
+ var i, n, self, field, fields, fields_count, multiplier, multipliers, get_field, implicit_score, sort;
211
+
212
+ self = this;
213
+ search = self.prepareSearch(search, options);
214
+ sort = (!search.query && options.sort_empty) || options.sort;
215
+
216
+ /**
217
+ * Fetches the specified sort field value
218
+ * from a search result item.
219
+ *
220
+ * @param {string} name
221
+ * @param {object} result
222
+ * @return {mixed}
223
+ */
224
+ get_field = function(name, result) {
225
+ if (name === '$score') return result.score;
226
+ return self.items[result.id][name];
227
+ };
228
+
229
+ // parse options
230
+ fields = [];
231
+ if (sort) {
232
+ for (i = 0, n = sort.length; i < n; i++) {
233
+ if (search.query || sort[i].field !== '$score') {
234
+ fields.push(sort[i]);
235
+ }
236
+ }
237
+ }
238
+
239
+ // the "$score" field is implied to be the primary
240
+ // sort field, unless it's manually specified
241
+ if (search.query) {
242
+ implicit_score = true;
243
+ for (i = 0, n = fields.length; i < n; i++) {
244
+ if (fields[i].field === '$score') {
245
+ implicit_score = false;
246
+ break;
247
+ }
248
+ }
249
+ if (implicit_score) {
250
+ fields.unshift({field: '$score', direction: 'desc'});
251
+ }
252
+ } else {
253
+ for (i = 0, n = fields.length; i < n; i++) {
254
+ if (fields[i].field === '$score') {
255
+ fields.splice(i, 1);
256
+ break;
257
+ }
258
+ }
259
+ }
260
+
261
+ multipliers = [];
262
+ for (i = 0, n = fields.length; i < n; i++) {
263
+ multipliers.push(fields[i].direction === 'desc' ? -1 : 1);
264
+ }
265
+
266
+ // build function
267
+ fields_count = fields.length;
268
+ if (!fields_count) {
269
+ return null;
270
+ } else if (fields_count === 1) {
271
+ field = fields[0].field;
272
+ multiplier = multipliers[0];
273
+ return function(a, b) {
274
+ return multiplier * cmp(
275
+ get_field(field, a),
276
+ get_field(field, b)
277
+ );
278
+ };
279
+ } else {
280
+ return function(a, b) {
281
+ var i, result, a_value, b_value, field;
282
+ for (i = 0; i < fields_count; i++) {
283
+ field = fields[i].field;
284
+ result = multipliers[i] * cmp(
285
+ get_field(field, a),
286
+ get_field(field, b)
287
+ );
288
+ if (result) return result;
289
+ }
290
+ return 0;
291
+ };
292
+ }
293
+ };
294
+
295
+ /**
296
+ * Parses a search query and returns an object
297
+ * with tokens and fields ready to be populated
298
+ * with results.
299
+ *
300
+ * @param {string} query
301
+ * @param {object} options
302
+ * @returns {object}
303
+ */
304
+ Sifter.prototype.prepareSearch = function(query, options) {
305
+ if (typeof query === 'object') return query;
306
+
307
+ options = extend({}, options);
308
+
309
+ var option_fields = options.fields;
310
+ var option_sort = options.sort;
311
+ var option_sort_empty = options.sort_empty;
312
+
313
+ if (option_fields && !is_array(option_fields)) options.fields = [option_fields];
314
+ if (option_sort && !is_array(option_sort)) options.sort = [option_sort];
315
+ if (option_sort_empty && !is_array(option_sort_empty)) options.sort_empty = [option_sort_empty];
316
+
317
+ return {
318
+ options : options,
319
+ query : String(query || '').toLowerCase(),
320
+ tokens : this.tokenize(query),
321
+ total : 0,
322
+ items : []
323
+ };
324
+ };
325
+
326
+ /**
327
+ * Searches through all items and returns a sorted array of matches.
328
+ *
329
+ * The `options` parameter can contain:
330
+ *
331
+ * - fields {string|array}
332
+ * - sort {array}
333
+ * - score {function}
334
+ * - filter {bool}
335
+ * - limit {integer}
336
+ *
337
+ * Returns an object containing:
338
+ *
339
+ * - options {object}
340
+ * - query {string}
341
+ * - tokens {array}
342
+ * - total {int}
343
+ * - items {array}
344
+ *
345
+ * @param {string} query
346
+ * @param {object} options
347
+ * @returns {object}
348
+ */
349
+ Sifter.prototype.search = function(query, options) {
350
+ var self = this, value, score, search, calculateScore;
351
+ var fn_sort;
352
+ var fn_score;
353
+
354
+ search = this.prepareSearch(query, options);
355
+ options = search.options;
356
+ query = search.query;
357
+
358
+ // generate result scoring function
359
+ fn_score = options.score || self.getScoreFunction(search);
360
+
361
+ // perform search and sort
362
+ if (query.length) {
363
+ self.iterator(self.items, function(item, id) {
364
+ score = fn_score(item);
365
+ if (options.filter === false || score > 0) {
366
+ search.items.push({'score': score, 'id': id});
367
+ }
368
+ });
369
+ } else {
370
+ self.iterator(self.items, function(item, id) {
371
+ search.items.push({'score': 1, 'id': id});
372
+ });
373
+ }
374
+
375
+ fn_sort = self.getSortFunction(search, options);
376
+ if (fn_sort) search.items.sort(fn_sort);
377
+
378
+ // apply limits
379
+ search.total = search.items.length;
380
+ if (typeof options.limit === 'number') {
381
+ search.items = search.items.slice(0, options.limit);
382
+ }
383
+
384
+ return search;
385
+ };
386
+
387
+ // utilities
388
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
389
+
390
+ var cmp = function(a, b) {
391
+ if (typeof a === 'number' && typeof b === 'number') {
392
+ return a > b ? 1 : (a < b ? -1 : 0);
393
+ }
394
+ a = asciifold(String(a || ''));
395
+ b = asciifold(String(b || ''));
396
+ if (a > b) return 1;
397
+ if (b > a) return -1;
398
+ return 0;
399
+ };
400
+
401
+ var extend = function(a, b) {
402
+ var i, n, k, object;
403
+ for (i = 1, n = arguments.length; i < n; i++) {
404
+ object = arguments[i];
405
+ if (!object) continue;
406
+ for (k in object) {
407
+ if (object.hasOwnProperty(k)) {
408
+ a[k] = object[k];
409
+ }
410
+ }
411
+ }
412
+ return a;
413
+ };
414
+
415
+ var trim = function(str) {
416
+ return (str + '').replace(/^\s+|\s+$|/g, '');
417
+ };
418
+
419
+ var escape_regex = function(str) {
420
+ return (str + '').replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
421
+ };
422
+
423
+ var is_array = Array.isArray || ($ && $.isArray) || function(object) {
424
+ return Object.prototype.toString.call(object) === '[object Array]';
425
+ };
426
+
427
+ var DIACRITICS = {
428
+ 'a': '[aÀÁÂÃÄÅàáâãäåĀāąĄ]',
429
+ 'c': '[cÇçćĆčČ]',
430
+ 'd': '[dđĐďĎ]',
431
+ 'e': '[eÈÉÊËèéêëěĚĒēęĘ]',
432
+ 'i': '[iÌÍÎÏìíîïĪī]',
433
+ 'l': '[lłŁ]',
434
+ 'n': '[nÑñňŇńŃ]',
435
+ 'o': '[oÒÓÔÕÕÖØòóôõöøŌō]',
436
+ 'r': '[rřŘ]',
437
+ 's': '[sŠšśŚ]',
438
+ 't': '[tťŤ]',
439
+ 'u': '[uÙÚÛÜùúûüůŮŪū]',
440
+ 'y': '[yŸÿýÝ]',
441
+ 'z': '[zŽžżŻźŹ]'
442
+ };
443
+
444
+ var asciifold = (function() {
445
+ var i, n, k, chunk;
446
+ var foreignletters = '';
447
+ var lookup = {};
448
+ for (k in DIACRITICS) {
449
+ if (DIACRITICS.hasOwnProperty(k)) {
450
+ chunk = DIACRITICS[k].substring(2, DIACRITICS[k].length - 1);
451
+ foreignletters += chunk;
452
+ for (i = 0, n = chunk.length; i < n; i++) {
453
+ lookup[chunk.charAt(i)] = k;
454
+ }
455
+ }
456
+ }
457
+ var regexp = new RegExp('[' + foreignletters + ']', 'g');
458
+ return function(str) {
459
+ return str.replace(regexp, function(foreignletter) {
460
+ return lookup[foreignletter];
461
+ }).toLowerCase();
462
+ };
463
+ })();
464
+
465
+
466
+ // export
467
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
468
+
469
+ return Sifter;
470
+ }));
471
+
472
+
473
+
474
+ /**
475
+ * microplugin.js
476
+ * Copyright (c) 2013 Brian Reavis & contributors
477
+ *
478
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
479
+ * file except in compliance with the License. You may obtain a copy of the License at:
480
+ * http://www.apache.org/licenses/LICENSE-2.0
481
+ *
482
+ * Unless required by applicable law or agreed to in writing, software distributed under
483
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
484
+ * ANY KIND, either express or implied. See the License for the specific language
485
+ * governing permissions and limitations under the License.
486
+ *
487
+ * @author Brian Reavis <brian@thirdroute.com>
488
+ */
489
+
490
+ (function(root, factory) {
491
+ if (typeof define === 'function' && define.amd) {
492
+ define('microplugin', factory);
493
+ } else if (typeof exports === 'object') {
494
+ module.exports = factory();
495
+ } else {
496
+ root.MicroPlugin = factory();
497
+ }
498
+ }(this, function() {
499
+ var MicroPlugin = {};
500
+
501
+ MicroPlugin.mixin = function(Interface) {
502
+ Interface.plugins = {};
503
+
504
+ /**
505
+ * Initializes the listed plugins (with options).
506
+ * Acceptable formats:
507
+ *
508
+ * List (without options):
509
+ * ['a', 'b', 'c']
510
+ *
511
+ * List (with options):
512
+ * [{'name': 'a', options: {}}, {'name': 'b', options: {}}]
513
+ *
514
+ * Hash (with options):
515
+ * {'a': { ... }, 'b': { ... }, 'c': { ... }}
516
+ *
517
+ * @param {mixed} plugins
518
+ */
519
+ Interface.prototype.initializePlugins = function(plugins) {
520
+ var i, n, key;
521
+ var self = this;
522
+ var queue = [];
523
+
524
+ self.plugins = {
525
+ names : [],
526
+ settings : {},
527
+ requested : {},
528
+ loaded : {}
529
+ };
530
+
531
+ if (utils.isArray(plugins)) {
532
+ for (i = 0, n = plugins.length; i < n; i++) {
533
+ if (typeof plugins[i] === 'string') {
534
+ queue.push(plugins[i]);
535
+ } else {
536
+ self.plugins.settings[plugins[i].name] = plugins[i].options;
537
+ queue.push(plugins[i].name);
538
+ }
539
+ }
540
+ } else if (plugins) {
541
+ for (key in plugins) {
542
+ if (plugins.hasOwnProperty(key)) {
543
+ self.plugins.settings[key] = plugins[key];
544
+ queue.push(key);
545
+ }
546
+ }
547
+ }
548
+
549
+ while (queue.length) {
550
+ self.require(queue.shift());
551
+ }
552
+ };
553
+
554
+ Interface.prototype.loadPlugin = function(name) {
555
+ var self = this;
556
+ var plugins = self.plugins;
557
+ var plugin = Interface.plugins[name];
558
+
559
+ if (!Interface.plugins.hasOwnProperty(name)) {
560
+ throw new Error('Unable to find "' + name + '" plugin');
561
+ }
562
+
563
+ plugins.requested[name] = true;
564
+ plugins.loaded[name] = plugin.fn.apply(self, [self.plugins.settings[name] || {}]);
565
+ plugins.names.push(name);
566
+ };
567
+
568
+ /**
569
+ * Initializes a plugin.
570
+ *
571
+ * @param {string} name
572
+ */
573
+ Interface.prototype.require = function(name) {
574
+ var self = this;
575
+ var plugins = self.plugins;
576
+
577
+ if (!self.plugins.loaded.hasOwnProperty(name)) {
578
+ if (plugins.requested[name]) {
579
+ throw new Error('Plugin has circular dependency ("' + name + '")');
580
+ }
581
+ self.loadPlugin(name);
582
+ }
583
+
584
+ return plugins.loaded[name];
585
+ };
586
+
587
+ /**
588
+ * Registers a plugin.
589
+ *
590
+ * @param {string} name
591
+ * @param {function} fn
592
+ */
593
+ Interface.define = function(name, fn) {
594
+ Interface.plugins[name] = {
595
+ 'name' : name,
596
+ 'fn' : fn
597
+ };
598
+ };
599
+ };
600
+
601
+ var utils = {
602
+ isArray: Array.isArray || function(vArg) {
603
+ return Object.prototype.toString.call(vArg) === '[object Array]';
604
+ }
605
+ };
606
+
607
+ return MicroPlugin;
608
+ }));
609
+
610
+ /**
611
+ * selectize.js (v0.12.1)
612
+ * Copyright (c) 2013–2015 Brian Reavis & contributors
613
+ *
614
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
615
+ * file except in compliance with the License. You may obtain a copy of the License at:
616
+ * http://www.apache.org/licenses/LICENSE-2.0
617
+ *
618
+ * Unless required by applicable law or agreed to in writing, software distributed under
619
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
620
+ * ANY KIND, either express or implied. See the License for the specific language
621
+ * governing permissions and limitations under the License.
622
+ *
623
+ * @author Brian Reavis <brian@thirdroute.com>
624
+ */
625
+
626
+ /*jshint curly:false */
627
+ /*jshint browser:true */
628
+
629
+ (function(root, factory) {
630
+ if (typeof define === 'function' && define.amd) {
631
+ define('selectize', ['jquery','sifter','microplugin'], factory);
632
+ } else if (typeof exports === 'object') {
633
+ module.exports = factory(require('jquery'), require('sifter'), require('microplugin'));
634
+ } else {
635
+ root.Selectize = factory(root.jQuery, root.Sifter, root.MicroPlugin);
636
+ }
637
+ }(this, function($, Sifter, MicroPlugin) {
638
+ 'use strict';
639
+
640
+ var highlight = function($element, pattern) {
641
+ if (typeof pattern === 'string' && !pattern.length) return;
642
+ var regex = (typeof pattern === 'string') ? new RegExp(pattern, 'i') : pattern;
643
+
644
+ var highlight = function(node) {
645
+ var skip = 0;
646
+ if (node.nodeType === 3) {
647
+ var pos = node.data.search(regex);
648
+ if (pos >= 0 && node.data.length > 0) {
649
+ var match = node.data.match(regex);
650
+ var spannode = document.createElement('span');
651
+ spannode.className = 'highlight';
652
+ var middlebit = node.splitText(pos);
653
+ var endbit = middlebit.splitText(match[0].length);
654
+ var middleclone = middlebit.cloneNode(true);
655
+ spannode.appendChild(middleclone);
656
+ middlebit.parentNode.replaceChild(spannode, middlebit);
657
+ skip = 1;
658
+ }
659
+ } else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
660
+ for (var i = 0; i < node.childNodes.length; ++i) {
661
+ i += highlight(node.childNodes[i]);
662
+ }
663
+ }
664
+ return skip;
665
+ };
666
+
667
+ return $element.each(function() {
668
+ highlight(this);
669
+ });
670
+ };
671
+
672
+ var MicroEvent = function() {};
673
+ MicroEvent.prototype = {
674
+ on: function(event, fct){
675
+ this._events = this._events || {};
676
+ this._events[event] = this._events[event] || [];
677
+ this._events[event].push(fct);
678
+ },
679
+ off: function(event, fct){
680
+ var n = arguments.length;
681
+ if (n === 0) return delete this._events;
682
+ if (n === 1) return delete this._events[event];
683
+
684
+ this._events = this._events || {};
685
+ if (event in this._events === false) return;
686
+ this._events[event].splice(this._events[event].indexOf(fct), 1);
687
+ },
688
+ trigger: function(event /* , args... */){
689
+ this._events = this._events || {};
690
+ if (event in this._events === false) return;
691
+ for (var i = 0; i < this._events[event].length; i++){
692
+ this._events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
693
+ }
694
+ }
695
+ };
696
+
697
+ /**
698
+ * Mixin will delegate all MicroEvent.js function in the destination object.
699
+ *
700
+ * - MicroEvent.mixin(Foobar) will make Foobar able to use MicroEvent
701
+ *
702
+ * @param {object} the object which will support MicroEvent
703
+ */
704
+ MicroEvent.mixin = function(destObject){
705
+ var props = ['on', 'off', 'trigger'];
706
+ for (var i = 0; i < props.length; i++){
707
+ destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
708
+ }
709
+ };
710
+
711
+ var IS_MAC = /Mac/.test(navigator.userAgent);
712
+
713
+ var KEY_A = 65;
714
+ var KEY_COMMA = 188;
715
+ var KEY_RETURN = 13;
716
+ var KEY_ESC = 27;
717
+ var KEY_LEFT = 37;
718
+ var KEY_UP = 38;
719
+ var KEY_P = 80;
720
+ var KEY_RIGHT = 39;
721
+ var KEY_DOWN = 40;
722
+ var KEY_N = 78;
723
+ var KEY_BACKSPACE = 8;
724
+ var KEY_DELETE = 46;
725
+ var KEY_SHIFT = 16;
726
+ var KEY_CMD = IS_MAC ? 91 : 17;
727
+ var KEY_CTRL = IS_MAC ? 18 : 17;
728
+ var KEY_TAB = 9;
729
+
730
+ var TAG_SELECT = 1;
731
+ var TAG_INPUT = 2;
732
+
733
+ // for now, android support in general is too spotty to support validity
734
+ var SUPPORTS_VALIDITY_API = !/android/i.test(window.navigator.userAgent) && !!document.createElement('form').validity;
735
+
736
+ var isset = function(object) {
737
+ return typeof object !== 'undefined';
738
+ };
739
+
740
+ /**
741
+ * Converts a scalar to its best string representation
742
+ * for hash keys and HTML attribute values.
743
+ *
744
+ * Transformations:
745
+ * 'str' -> 'str'
746
+ * null -> ''
747
+ * undefined -> ''
748
+ * true -> '1'
749
+ * false -> '0'
750
+ * 0 -> '0'
751
+ * 1 -> '1'
752
+ *
753
+ * @param {string} value
754
+ * @returns {string|null}
755
+ */
756
+ var hash_key = function(value) {
757
+ if (typeof value === 'undefined' || value === null) return null;
758
+ if (typeof value === 'boolean') return value ? '1' : '0';
759
+ return value + '';
760
+ };
761
+
762
+ /**
763
+ * Escapes a string for use within HTML.
764
+ *
765
+ * @param {string} str
766
+ * @returns {string}
767
+ */
768
+ var escape_html = function(str) {
769
+ return (str + '')
770
+ .replace(/&/g, '&amp;')
771
+ .replace(/</g, '&lt;')
772
+ .replace(/>/g, '&gt;')
773
+ .replace(/"/g, '&quot;');
774
+ };
775
+
776
+ /**
777
+ * Escapes "$" characters in replacement strings.
778
+ *
779
+ * @param {string} str
780
+ * @returns {string}
781
+ */
782
+ var escape_replace = function(str) {
783
+ return (str + '').replace(/\$/g, '$$$$');
784
+ };
785
+
786
+ var hook = {};
787
+
788
+ /**
789
+ * Wraps `method` on `self` so that `fn`
790
+ * is invoked before the original method.
791
+ *
792
+ * @param {object} self
793
+ * @param {string} method
794
+ * @param {function} fn
795
+ */
796
+ hook.before = function(self, method, fn) {
797
+ var original = self[method];
798
+ self[method] = function() {
799
+ fn.apply(self, arguments);
800
+ return original.apply(self, arguments);
801
+ };
802
+ };
803
+
804
+ /**
805
+ * Wraps `method` on `self` so that `fn`
806
+ * is invoked after the original method.
807
+ *
808
+ * @param {object} self
809
+ * @param {string} method
810
+ * @param {function} fn
811
+ */
812
+ hook.after = function(self, method, fn) {
813
+ var original = self[method];
814
+ self[method] = function() {
815
+ var result = original.apply(self, arguments);
816
+ fn.apply(self, arguments);
817
+ return result;
818
+ };
819
+ };
820
+
821
+ /**
822
+ * Wraps `fn` so that it can only be invoked once.
823
+ *
824
+ * @param {function} fn
825
+ * @returns {function}
826
+ */
827
+ var once = function(fn) {
828
+ var called = false;
829
+ return function() {
830
+ if (called) return;
831
+ called = true;
832
+ fn.apply(this, arguments);
833
+ };
834
+ };
835
+
836
+ /**
837
+ * Wraps `fn` so that it can only be called once
838
+ * every `delay` milliseconds (invoked on the falling edge).
839
+ *
840
+ * @param {function} fn
841
+ * @param {int} delay
842
+ * @returns {function}
843
+ */
844
+ var debounce = function(fn, delay) {
845
+ var timeout;
846
+ return function() {
847
+ var self = this;
848
+ var args = arguments;
849
+ window.clearTimeout(timeout);
850
+ timeout = window.setTimeout(function() {
851
+ fn.apply(self, args);
852
+ }, delay);
853
+ };
854
+ };
855
+
856
+ /**
857
+ * Debounce all fired events types listed in `types`
858
+ * while executing the provided `fn`.
859
+ *
860
+ * @param {object} self
861
+ * @param {array} types
862
+ * @param {function} fn
863
+ */
864
+ var debounce_events = function(self, types, fn) {
865
+ var type;
866
+ var trigger = self.trigger;
867
+ var event_args = {};
868
+
869
+ // override trigger method
870
+ self.trigger = function() {
871
+ var type = arguments[0];
872
+ if (types.indexOf(type) !== -1) {
873
+ event_args[type] = arguments;
874
+ } else {
875
+ return trigger.apply(self, arguments);
876
+ }
877
+ };
878
+
879
+ // invoke provided function
880
+ fn.apply(self, []);
881
+ self.trigger = trigger;
882
+
883
+ // trigger queued events
884
+ for (type in event_args) {
885
+ if (event_args.hasOwnProperty(type)) {
886
+ trigger.apply(self, event_args[type]);
887
+ }
888
+ }
889
+ };
890
+
891
+ /**
892
+ * A workaround for http://bugs.jquery.com/ticket/6696
893
+ *
894
+ * @param {object} $parent - Parent element to listen on.
895
+ * @param {string} event - Event name.
896
+ * @param {string} selector - Descendant selector to filter by.
897
+ * @param {function} fn - Event handler.
898
+ */
899
+ var watchChildEvent = function($parent, event, selector, fn) {
900
+ $parent.on(event, selector, function(e) {
901
+ var child = e.target;
902
+ while (child && child.parentNode !== $parent[0]) {
903
+ child = child.parentNode;
904
+ }
905
+ e.currentTarget = child;
906
+ return fn.apply(this, [e]);
907
+ });
908
+ };
909
+
910
+ /**
911
+ * Determines the current selection within a text input control.
912
+ * Returns an object containing:
913
+ * - start
914
+ * - length
915
+ *
916
+ * @param {object} input
917
+ * @returns {object}
918
+ */
919
+ var getSelection = function(input) {
920
+ var result = {};
921
+ if ('selectionStart' in input) {
922
+ result.start = input.selectionStart;
923
+ result.length = input.selectionEnd - result.start;
924
+ } else if (document.selection) {
925
+ input.focus();
926
+ var sel = document.selection.createRange();
927
+ var selLen = document.selection.createRange().text.length;
928
+ sel.moveStart('character', -input.value.length);
929
+ result.start = sel.text.length - selLen;
930
+ result.length = selLen;
931
+ }
932
+ return result;
933
+ };
934
+
935
+ /**
936
+ * Copies CSS properties from one element to another.
937
+ *
938
+ * @param {object} $from
939
+ * @param {object} $to
940
+ * @param {array} properties
941
+ */
942
+ var transferStyles = function($from, $to, properties) {
943
+ var i, n, styles = {};
944
+ if (properties) {
945
+ for (i = 0, n = properties.length; i < n; i++) {
946
+ styles[properties[i]] = $from.css(properties[i]);
947
+ }
948
+ } else {
949
+ styles = $from.css();
950
+ }
951
+ $to.css(styles);
952
+ };
953
+
954
+ /**
955
+ * Measures the width of a string within a
956
+ * parent element (in pixels).
957
+ *
958
+ * @param {string} str
959
+ * @param {object} $parent
960
+ * @returns {int}
961
+ */
962
+ var measureString = function(str, $parent) {
963
+ if (!str) {
964
+ return 0;
965
+ }
966
+
967
+ var $test = $('<test>').css({
968
+ position: 'absolute',
969
+ top: -99999,
970
+ left: -99999,
971
+ width: 'auto',
972
+ padding: 0,
973
+ whiteSpace: 'pre'
974
+ }).text(str).appendTo('body');
975
+
976
+ transferStyles($parent, $test, [
977
+ 'letterSpacing',
978
+ 'fontSize',
979
+ 'fontFamily',
980
+ 'fontWeight',
981
+ 'textTransform'
982
+ ]);
983
+
984
+ var width = $test.width();
985
+ $test.remove();
986
+
987
+ return width;
988
+ };
989
+
990
+ /**
991
+ * Sets up an input to grow horizontally as the user
992
+ * types. If the value is changed manually, you can
993
+ * trigger the "update" handler to resize:
994
+ *
995
+ * $input.trigger('update');
996
+ *
997
+ * @param {object} $input
998
+ */
999
+ var autoGrow = function($input) {
1000
+ var currentWidth = null;
1001
+
1002
+ var update = function(e, options) {
1003
+ var value, keyCode, printable, placeholder, width;
1004
+ var shift, character, selection;
1005
+ e = e || window.event || {};
1006
+ options = options || {};
1007
+
1008
+ if (e.metaKey || e.altKey) return;
1009
+ if (!options.force && $input.data('grow') === false) return;
1010
+
1011
+ value = $input.val();
1012
+ if (e.type && e.type.toLowerCase() === 'keydown') {
1013
+ keyCode = e.keyCode;
1014
+ printable = (
1015
+ (keyCode >= 97 && keyCode <= 122) || // a-z
1016
+ (keyCode >= 65 && keyCode <= 90) || // A-Z
1017
+ (keyCode >= 48 && keyCode <= 57) || // 0-9
1018
+ keyCode === 32 // space
1019
+ );
1020
+
1021
+ if (keyCode === KEY_DELETE || keyCode === KEY_BACKSPACE) {
1022
+ selection = getSelection($input[0]);
1023
+ if (selection.length) {
1024
+ value = value.substring(0, selection.start) + value.substring(selection.start + selection.length);
1025
+ } else if (keyCode === KEY_BACKSPACE && selection.start) {
1026
+ value = value.substring(0, selection.start - 1) + value.substring(selection.start + 1);
1027
+ } else if (keyCode === KEY_DELETE && typeof selection.start !== 'undefined') {
1028
+ value = value.substring(0, selection.start) + value.substring(selection.start + 1);
1029
+ }
1030
+ } else if (printable) {
1031
+ shift = e.shiftKey;
1032
+ character = String.fromCharCode(e.keyCode);
1033
+ if (shift) character = character.toUpperCase();
1034
+ else character = character.toLowerCase();
1035
+ value += character;
1036
+ }
1037
+ }
1038
+
1039
+ placeholder = $input.attr('placeholder');
1040
+ if (!value && placeholder) {
1041
+ value = placeholder;
1042
+ }
1043
+
1044
+ width = measureString(value, $input) + 4;
1045
+ if (width !== currentWidth) {
1046
+ currentWidth = width;
1047
+ $input.width(width);
1048
+ $input.triggerHandler('resize');
1049
+ }
1050
+ };
1051
+
1052
+ $input.on('keydown keyup update blur', update);
1053
+ update();
1054
+ };
1055
+
1056
+ var Selectize = function($input, settings) {
1057
+ var key, i, n, dir, input, self = this;
1058
+ input = $input[0];
1059
+ input.selectize = self;
1060
+
1061
+ // detect rtl environment
1062
+ var computedStyle = window.getComputedStyle && window.getComputedStyle(input, null);
1063
+ dir = computedStyle ? computedStyle.getPropertyValue('direction') : input.currentStyle && input.currentStyle.direction;
1064
+ dir = dir || $input.parents('[dir]:first').attr('dir') || '';
1065
+
1066
+ // setup default state
1067
+ $.extend(self, {
1068
+ order : 0,
1069
+ settings : settings,
1070
+ $input : $input,
1071
+ tabIndex : $input.attr('tabindex') || '',
1072
+ tagType : input.tagName.toLowerCase() === 'select' ? TAG_SELECT : TAG_INPUT,
1073
+ rtl : /rtl/i.test(dir),
1074
+
1075
+ eventNS : '.selectize' + (++Selectize.count),
1076
+ highlightedValue : null,
1077
+ isOpen : false,
1078
+ isDisabled : false,
1079
+ isRequired : $input.is('[required]'),
1080
+ isInvalid : false,
1081
+ isLocked : false,
1082
+ isFocused : false,
1083
+ isInputHidden : false,
1084
+ isSetup : false,
1085
+ isShiftDown : false,
1086
+ isCmdDown : false,
1087
+ isCtrlDown : false,
1088
+ ignoreFocus : false,
1089
+ ignoreBlur : false,
1090
+ ignoreHover : false,
1091
+ hasOptions : false,
1092
+ currentResults : null,
1093
+ lastValue : '',
1094
+ caretPos : 0,
1095
+ loading : 0,
1096
+ loadedSearches : {},
1097
+
1098
+ $activeOption : null,
1099
+ $activeItems : [],
1100
+
1101
+ optgroups : {},
1102
+ options : {},
1103
+ userOptions : {},
1104
+ items : [],
1105
+ renderCache : {},
1106
+ onSearchChange : settings.loadThrottle === null ? self.onSearchChange : debounce(self.onSearchChange, settings.loadThrottle)
1107
+ });
1108
+
1109
+ // search system
1110
+ self.sifter = new Sifter(this.options, {diacritics: settings.diacritics});
1111
+
1112
+ // build options table
1113
+ if (self.settings.options) {
1114
+ for (i = 0, n = self.settings.options.length; i < n; i++) {
1115
+ self.registerOption(self.settings.options[i]);
1116
+ }
1117
+ delete self.settings.options;
1118
+ }
1119
+
1120
+ // build optgroup table
1121
+ if (self.settings.optgroups) {
1122
+ for (i = 0, n = self.settings.optgroups.length; i < n; i++) {
1123
+ self.registerOptionGroup(self.settings.optgroups[i]);
1124
+ }
1125
+ delete self.settings.optgroups;
1126
+ }
1127
+
1128
+ // option-dependent defaults
1129
+ self.settings.mode = self.settings.mode || (self.settings.maxItems === 1 ? 'single' : 'multi');
1130
+ if (typeof self.settings.hideSelected !== 'boolean') {
1131
+ self.settings.hideSelected = self.settings.mode === 'multi';
1132
+ }
1133
+
1134
+ self.initializePlugins(self.settings.plugins);
1135
+ self.setupCallbacks();
1136
+ self.setupTemplates();
1137
+ self.setup();
1138
+ };
1139
+
1140
+ // mixins
1141
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1142
+
1143
+ MicroEvent.mixin(Selectize);
1144
+ MicroPlugin.mixin(Selectize);
1145
+
1146
+ // methods
1147
+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1148
+
1149
+ $.extend(Selectize.prototype, {
1150
+
1151
+ /**
1152
+ * Creates all elements and sets up event bindings.
1153
+ */
1154
+ setup: function() {
1155
+ var self = this;
1156
+ var settings = self.settings;
1157
+ var eventNS = self.eventNS;
1158
+ var $window = $(window);
1159
+ var $document = $(document);
1160
+ var $input = self.$input;
1161
+
1162
+ var $wrapper;
1163
+ var $control;
1164
+ var $control_input;
1165
+ var $dropdown;
1166
+ var $dropdown_content;
1167
+ var $dropdown_parent;
1168
+ var inputMode;
1169
+ var timeout_blur;
1170
+ var timeout_focus;
1171
+ var classes;
1172
+ var classes_plugins;
1173
+
1174
+ inputMode = self.settings.mode;
1175
+ classes = $input.attr('class') || '';
1176
+
1177
+ $wrapper = $('<div>').addClass(settings.wrapperClass).addClass(classes).addClass(inputMode);
1178
+ $control = $('<div>').addClass(settings.inputClass).addClass('items').appendTo($wrapper);
1179
+ $control_input = $('<input type="text" autocomplete="off" />').appendTo($control).attr('tabindex', $input.is(':disabled') ? '-1' : self.tabIndex);
1180
+ $dropdown_parent = $(settings.dropdownParent || $wrapper);
1181
+ $dropdown = $('<div>').addClass(settings.dropdownClass).addClass(inputMode).hide().appendTo($dropdown_parent);
1182
+ $dropdown_content = $('<div>').addClass(settings.dropdownContentClass).appendTo($dropdown);
1183
+
1184
+ if(self.settings.copyClassesToDropdown) {
1185
+ $dropdown.addClass(classes);
1186
+ }
1187
+
1188
+ $wrapper.css({
1189
+ width: $input[0].style.width
1190
+ });
1191
+
1192
+ if (self.plugins.names.length) {
1193
+ classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-');
1194
+ $wrapper.addClass(classes_plugins);
1195
+ $dropdown.addClass(classes_plugins);
1196
+ }
1197
+
1198
+ if ((settings.maxItems === null || settings.maxItems > 1) && self.tagType === TAG_SELECT) {
1199
+ $input.attr('multiple', 'multiple');
1200
+ }
1201
+
1202
+ if (self.settings.placeholder) {
1203
+ $control_input.attr('placeholder', settings.placeholder);
1204
+ }
1205
+
1206
+ // if splitOn was not passed in, construct it from the delimiter to allow pasting universally
1207
+ if (!self.settings.splitOn && self.settings.delimiter) {
1208
+ var delimiterEscaped = self.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
1209
+ self.settings.splitOn = new RegExp('\\s*' + delimiterEscaped + '+\\s*');
1210
+ }
1211
+
1212
+ if ($input.attr('autocorrect')) {
1213
+ $control_input.attr('autocorrect', $input.attr('autocorrect'));
1214
+ }
1215
+
1216
+ if ($input.attr('autocapitalize')) {
1217
+ $control_input.attr('autocapitalize', $input.attr('autocapitalize'));
1218
+ }
1219
+
1220
+ self.$wrapper = $wrapper;
1221
+ self.$control = $control;
1222
+ self.$control_input = $control_input;
1223
+ self.$dropdown = $dropdown;
1224
+ self.$dropdown_content = $dropdown_content;
1225
+
1226
+ $dropdown.on('mouseenter', '[data-selectable]', function() { return self.onOptionHover.apply(self, arguments); });
1227
+ $dropdown.on('mousedown click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
1228
+ watchChildEvent($control, 'mousedown', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); });
1229
+ autoGrow($control_input);
1230
+
1231
+ $control.on({
1232
+ mousedown : function() { return self.onMouseDown.apply(self, arguments); },
1233
+ click : function() { return self.onClick.apply(self, arguments); }
1234
+ });
1235
+
1236
+ $control_input.on({
1237
+ mousedown : function(e) { e.stopPropagation(); },
1238
+ keydown : function() { return self.onKeyDown.apply(self, arguments); },
1239
+ keyup : function() { return self.onKeyUp.apply(self, arguments); },
1240
+ keypress : function() { return self.onKeyPress.apply(self, arguments); },
1241
+ resize : function() { self.positionDropdown.apply(self, []); },
1242
+ blur : function() { return self.onBlur.apply(self, arguments); },
1243
+ focus : function() { self.ignoreBlur = false; return self.onFocus.apply(self, arguments); },
1244
+ paste : function() { return self.onPaste.apply(self, arguments); }
1245
+ });
1246
+
1247
+ $document.on('keydown' + eventNS, function(e) {
1248
+ self.isCmdDown = e[IS_MAC ? 'metaKey' : 'ctrlKey'];
1249
+ self.isCtrlDown = e[IS_MAC ? 'altKey' : 'ctrlKey'];
1250
+ self.isShiftDown = e.shiftKey;
1251
+ });
1252
+
1253
+ $document.on('keyup' + eventNS, function(e) {
1254
+ if (e.keyCode === KEY_CTRL) self.isCtrlDown = false;
1255
+ if (e.keyCode === KEY_SHIFT) self.isShiftDown = false;
1256
+ if (e.keyCode === KEY_CMD) self.isCmdDown = false;
1257
+ });
1258
+
1259
+ $document.on('mousedown' + eventNS, function(e) {
1260
+ if (self.isFocused) {
1261
+ // prevent events on the dropdown scrollbar from causing the control to blur
1262
+ if (e.target === self.$dropdown[0] || e.target.parentNode === self.$dropdown[0]) {
1263
+ return false;
1264
+ }
1265
+ // blur on click outside
1266
+ if (!self.$control.has(e.target).length && e.target !== self.$control[0]) {
1267
+ self.blur(e.target);
1268
+ }
1269
+ }
1270
+ });
1271
+
1272
+ $window.on(['scroll' + eventNS, 'resize' + eventNS].join(' '), function() {
1273
+ if (self.isOpen) {
1274
+ self.positionDropdown.apply(self, arguments);
1275
+ }
1276
+ });
1277
+ $window.on('mousemove' + eventNS, function() {
1278
+ self.ignoreHover = false;
1279
+ });
1280
+
1281
+ // store original children and tab index so that they can be
1282
+ // restored when the destroy() method is called.
1283
+ this.revertSettings = {
1284
+ $children : $input.children().detach(),
1285
+ tabindex : $input.attr('tabindex')
1286
+ };
1287
+
1288
+ $input.attr('tabindex', -1).hide().after(self.$wrapper);
1289
+
1290
+ if ($.isArray(settings.items)) {
1291
+ self.setValue(settings.items);
1292
+ delete settings.items;
1293
+ }
1294
+
1295
+ // feature detect for the validation API
1296
+ if (SUPPORTS_VALIDITY_API) {
1297
+ $input.on('invalid' + eventNS, function(e) {
1298
+ e.preventDefault();
1299
+ self.isInvalid = true;
1300
+ self.refreshState();
1301
+ });
1302
+ }
1303
+
1304
+ self.updateOriginalInput();
1305
+ self.refreshItems();
1306
+ self.refreshState();
1307
+ self.updatePlaceholder();
1308
+ self.isSetup = true;
1309
+
1310
+ if ($input.is(':disabled')) {
1311
+ self.disable();
1312
+ }
1313
+
1314
+ self.on('change', this.onChange);
1315
+
1316
+ $input.data('selectize', self);
1317
+ $input.addClass('selectized');
1318
+ self.trigger('initialize');
1319
+
1320
+ // preload options
1321
+ if (settings.preload === true) {
1322
+ self.onSearchChange('');
1323
+ }
1324
+
1325
+ },
1326
+
1327
+ /**
1328
+ * Sets up default rendering functions.
1329
+ */
1330
+ setupTemplates: function() {
1331
+ var self = this;
1332
+ var field_label = self.settings.labelField;
1333
+ var field_optgroup = self.settings.optgroupLabelField;
1334
+
1335
+ var templates = {
1336
+ 'optgroup': function(data) {
1337
+ return '<div class="optgroup">' + data.html + '</div>';
1338
+ },
1339
+ 'optgroup_header': function(data, escape) {
1340
+ return '<div class="optgroup-header">' + escape(data[field_optgroup]) + '</div>';
1341
+ },
1342
+ 'option': function(data, escape) {
1343
+ return '<div class="option">' + escape(data[field_label]) + '</div>';
1344
+ },
1345
+ 'item': function(data, escape) {
1346
+ return '<div class="item">' + escape(data[field_label]) + '</div>';
1347
+ },
1348
+ 'option_create': function(data, escape) {
1349
+ return '<div class="create">Add <strong>' + escape(data.input) + '</strong>&hellip;</div>';
1350
+ }
1351
+ };
1352
+
1353
+ self.settings.render = $.extend({}, templates, self.settings.render);
1354
+ },
1355
+
1356
+ /**
1357
+ * Maps fired events to callbacks provided
1358
+ * in the settings used when creating the control.
1359
+ */
1360
+ setupCallbacks: function() {
1361
+ var key, fn, callbacks = {
1362
+ 'initialize' : 'onInitialize',
1363
+ 'change' : 'onChange',
1364
+ 'item_add' : 'onItemAdd',
1365
+ 'item_remove' : 'onItemRemove',
1366
+ 'clear' : 'onClear',
1367
+ 'option_add' : 'onOptionAdd',
1368
+ 'option_remove' : 'onOptionRemove',
1369
+ 'option_clear' : 'onOptionClear',
1370
+ 'optgroup_add' : 'onOptionGroupAdd',
1371
+ 'optgroup_remove' : 'onOptionGroupRemove',
1372
+ 'optgroup_clear' : 'onOptionGroupClear',
1373
+ 'dropdown_open' : 'onDropdownOpen',
1374
+ 'dropdown_close' : 'onDropdownClose',
1375
+ 'type' : 'onType',
1376
+ 'load' : 'onLoad',
1377
+ 'focus' : 'onFocus',
1378
+ 'blur' : 'onBlur'
1379
+ };
1380
+
1381
+ for (key in callbacks) {
1382
+ if (callbacks.hasOwnProperty(key)) {
1383
+ fn = this.settings[callbacks[key]];
1384
+ if (fn) this.on(key, fn);
1385
+ }
1386
+ }
1387
+ },
1388
+
1389
+ /**
1390
+ * Triggered when the main control element
1391
+ * has a click event.
1392
+ *
1393
+ * @param {object} e
1394
+ * @return {boolean}
1395
+ */
1396
+ onClick: function(e) {
1397
+ var self = this;
1398
+
1399
+ // necessary for mobile webkit devices (manual focus triggering
1400
+ // is ignored unless invoked within a click event)
1401
+ if (!self.isFocused) {
1402
+ self.focus();
1403
+ e.preventDefault();
1404
+ }
1405
+ },
1406
+
1407
+ /**
1408
+ * Triggered when the main control element
1409
+ * has a mouse down event.
1410
+ *
1411
+ * @param {object} e
1412
+ * @return {boolean}
1413
+ */
1414
+ onMouseDown: function(e) {
1415
+ var self = this;
1416
+ var defaultPrevented = e.isDefaultPrevented();
1417
+ var $target = $(e.target);
1418
+
1419
+ if (self.isFocused) {
1420
+ // retain focus by preventing native handling. if the
1421
+ // event target is the input it should not be modified.
1422
+ // otherwise, text selection within the input won't work.
1423
+ if (e.target !== self.$control_input[0]) {
1424
+ if (self.settings.mode === 'single') {
1425
+ // toggle dropdown
1426
+ self.isOpen ? self.close() : self.open();
1427
+ } else if (!defaultPrevented) {
1428
+ self.setActiveItem(null);
1429
+ }
1430
+ return false;
1431
+ }
1432
+ } else {
1433
+ // give control focus
1434
+ if (!defaultPrevented) {
1435
+ window.setTimeout(function() {
1436
+ self.focus();
1437
+ }, 0);
1438
+ }
1439
+ }
1440
+ },
1441
+
1442
+ /**
1443
+ * Triggered when the value of the control has been changed.
1444
+ * This should propagate the event to the original DOM
1445
+ * input / select element.
1446
+ */
1447
+ onChange: function() {
1448
+ this.$input.trigger('change');
1449
+ },
1450
+
1451
+ /**
1452
+ * Triggered on <input> paste.
1453
+ *
1454
+ * @param {object} e
1455
+ * @returns {boolean}
1456
+ */
1457
+ onPaste: function(e) {
1458
+ var self = this;
1459
+ if (self.isFull() || self.isInputHidden || self.isLocked) {
1460
+ e.preventDefault();
1461
+ } else {
1462
+ // If a regex or string is included, this will split the pasted
1463
+ // input and create Items for each separate value
1464
+ if (self.settings.splitOn) {
1465
+ setTimeout(function() {
1466
+ var splitInput = $.trim(self.$control_input.val() || '').split(self.settings.splitOn);
1467
+ for (var i = 0, n = splitInput.length; i < n; i++) {
1468
+ self.createItem(splitInput[i]);
1469
+ }
1470
+ }, 0);
1471
+ }
1472
+ }
1473
+ },
1474
+
1475
+ /**
1476
+ * Triggered on <input> keypress.
1477
+ *
1478
+ * @param {object} e
1479
+ * @returns {boolean}
1480
+ */
1481
+ onKeyPress: function(e) {
1482
+ if (this.isLocked) return e && e.preventDefault();
1483
+ var character = String.fromCharCode(e.keyCode || e.which);
1484
+ if (this.settings.create && this.settings.mode === 'multi' && character === this.settings.delimiter) {
1485
+ this.createItem();
1486
+ e.preventDefault();
1487
+ return false;
1488
+ }
1489
+ },
1490
+
1491
+ /**
1492
+ * Triggered on <input> keydown.
1493
+ *
1494
+ * @param {object} e
1495
+ * @returns {boolean}
1496
+ */
1497
+ onKeyDown: function(e) {
1498
+ var isInput = e.target === this.$control_input[0];
1499
+ var self = this;
1500
+
1501
+ if (self.isLocked) {
1502
+ if (e.keyCode !== KEY_TAB) {
1503
+ e.preventDefault();
1504
+ }
1505
+ return;
1506
+ }
1507
+
1508
+ switch (e.keyCode) {
1509
+ case KEY_A:
1510
+ if (self.isCmdDown) {
1511
+ self.selectAll();
1512
+ return;
1513
+ }
1514
+ break;
1515
+ case KEY_ESC:
1516
+ if (self.isOpen) {
1517
+ e.preventDefault();
1518
+ e.stopPropagation();
1519
+ self.close();
1520
+ }
1521
+ return;
1522
+ case KEY_N:
1523
+ if (!e.ctrlKey || e.altKey) break;
1524
+ case KEY_DOWN:
1525
+ if (!self.isOpen && self.hasOptions) {
1526
+ self.open();
1527
+ } else if (self.$activeOption) {
1528
+ self.ignoreHover = true;
1529
+ var $next = self.getAdjacentOption(self.$activeOption, 1);
1530
+ if ($next.length) self.setActiveOption($next, true, true);
1531
+ }
1532
+ e.preventDefault();
1533
+ return;
1534
+ case KEY_P:
1535
+ if (!e.ctrlKey || e.altKey) break;
1536
+ case KEY_UP:
1537
+ if (self.$activeOption) {
1538
+ self.ignoreHover = true;
1539
+ var $prev = self.getAdjacentOption(self.$activeOption, -1);
1540
+ if ($prev.length) self.setActiveOption($prev, true, true);
1541
+ }
1542
+ e.preventDefault();
1543
+ return;
1544
+ case KEY_RETURN:
1545
+ if (self.isOpen && self.$activeOption) {
1546
+ self.onOptionSelect({currentTarget: self.$activeOption});
1547
+ e.preventDefault();
1548
+ }
1549
+ return;
1550
+ case KEY_LEFT:
1551
+ self.advanceSelection(-1, e);
1552
+ return;
1553
+ case KEY_RIGHT:
1554
+ self.advanceSelection(1, e);
1555
+ return;
1556
+ case KEY_TAB:
1557
+ if (self.settings.selectOnTab && self.isOpen && self.$activeOption) {
1558
+ self.onOptionSelect({currentTarget: self.$activeOption});
1559
+
1560
+ // Default behaviour is to jump to the next field, we only want this
1561
+ // if the current field doesn't accept any more entries
1562
+ if (!self.isFull()) {
1563
+ e.preventDefault();
1564
+ }
1565
+ }
1566
+ if (self.settings.create && self.createItem()) {
1567
+ e.preventDefault();
1568
+ }
1569
+ return;
1570
+ case KEY_BACKSPACE:
1571
+ case KEY_DELETE:
1572
+ self.deleteSelection(e);
1573
+ return;
1574
+ }
1575
+
1576
+ if ((self.isFull() || self.isInputHidden) && !(IS_MAC ? e.metaKey : e.ctrlKey)) {
1577
+ e.preventDefault();
1578
+ return;
1579
+ }
1580
+ },
1581
+
1582
+ /**
1583
+ * Triggered on <input> keyup.
1584
+ *
1585
+ * @param {object} e
1586
+ * @returns {boolean}
1587
+ */
1588
+ onKeyUp: function(e) {
1589
+ var self = this;
1590
+
1591
+ if (self.isLocked) return e && e.preventDefault();
1592
+ var value = self.$control_input.val() || '';
1593
+ if (self.lastValue !== value) {
1594
+ self.lastValue = value;
1595
+ self.onSearchChange(value);
1596
+ self.refreshOptions();
1597
+ self.trigger('type', value);
1598
+ }
1599
+ },
1600
+
1601
+ /**
1602
+ * Invokes the user-provide option provider / loader.
1603
+ *
1604
+ * Note: this function is debounced in the Selectize
1605
+ * constructor (by `settings.loadDelay` milliseconds)
1606
+ *
1607
+ * @param {string} value
1608
+ */
1609
+ onSearchChange: function(value) {
1610
+ var self = this;
1611
+ var fn = self.settings.load;
1612
+ if (!fn) return;
1613
+ if (self.loadedSearches.hasOwnProperty(value)) return;
1614
+ self.loadedSearches[value] = true;
1615
+ self.load(function(callback) {
1616
+ fn.apply(self, [value, callback]);
1617
+ });
1618
+ },
1619
+
1620
+ /**
1621
+ * Triggered on <input> focus.
1622
+ *
1623
+ * @param {object} e (optional)
1624
+ * @returns {boolean}
1625
+ */
1626
+ onFocus: function(e) {
1627
+ var self = this;
1628
+ var wasFocused = self.isFocused;
1629
+
1630
+ if (self.isDisabled) {
1631
+ self.blur();
1632
+ e && e.preventDefault();
1633
+ return false;
1634
+ }
1635
+
1636
+ if (self.ignoreFocus) return;
1637
+ self.isFocused = true;
1638
+ if (self.settings.preload === 'focus') self.onSearchChange('');
1639
+
1640
+ if (!wasFocused) self.trigger('focus');
1641
+
1642
+ if (!self.$activeItems.length) {
1643
+ self.showInput();
1644
+ self.setActiveItem(null);
1645
+ self.refreshOptions(!!self.settings.openOnFocus);
1646
+ }
1647
+
1648
+ self.refreshState();
1649
+ },
1650
+
1651
+ /**
1652
+ * Triggered on <input> blur.
1653
+ *
1654
+ * @param {object} e
1655
+ * @param {Element} dest
1656
+ */
1657
+ onBlur: function(e, dest) {
1658
+ var self = this;
1659
+ if (!self.isFocused) return;
1660
+ self.isFocused = false;
1661
+
1662
+ if (self.ignoreFocus) {
1663
+ return;
1664
+ } else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) {
1665
+ // necessary to prevent IE closing the dropdown when the scrollbar is clicked
1666
+ self.ignoreBlur = true;
1667
+ self.onFocus(e);
1668
+ return;
1669
+ }
1670
+
1671
+ var deactivate = function() {
1672
+ self.close();
1673
+ self.setTextboxValue('');
1674
+ self.setActiveItem(null);
1675
+ self.setActiveOption(null);
1676
+ self.setCaret(self.items.length);
1677
+ self.refreshState();
1678
+
1679
+ // IE11 bug: element still marked as active
1680
+ (dest || document.body).focus();
1681
+
1682
+ self.ignoreFocus = false;
1683
+ self.trigger('blur');
1684
+ };
1685
+
1686
+ self.ignoreFocus = true;
1687
+ if (self.settings.create && self.settings.createOnBlur) {
1688
+ self.createItem(null, false, deactivate);
1689
+ } else {
1690
+ deactivate();
1691
+ }
1692
+ },
1693
+
1694
+ /**
1695
+ * Triggered when the user rolls over
1696
+ * an option in the autocomplete dropdown menu.
1697
+ *
1698
+ * @param {object} e
1699
+ * @returns {boolean}
1700
+ */
1701
+ onOptionHover: function(e) {
1702
+ if (this.ignoreHover) return;
1703
+ this.setActiveOption(e.currentTarget, false);
1704
+ },
1705
+
1706
+ /**
1707
+ * Triggered when the user clicks on an option
1708
+ * in the autocomplete dropdown menu.
1709
+ *
1710
+ * @param {object} e
1711
+ * @returns {boolean}
1712
+ */
1713
+ onOptionSelect: function(e) {
1714
+ var value, $target, $option, self = this;
1715
+
1716
+ if (e.preventDefault) {
1717
+ e.preventDefault();
1718
+ e.stopPropagation();
1719
+ }
1720
+
1721
+ $target = $(e.currentTarget);
1722
+ if ($target.hasClass('create')) {
1723
+ self.createItem(null, function() {
1724
+ if (self.settings.closeAfterSelect) {
1725
+ self.close();
1726
+ }
1727
+ });
1728
+ } else {
1729
+ value = $target.attr('data-value');
1730
+ if (typeof value !== 'undefined') {
1731
+ self.lastQuery = null;
1732
+ self.setTextboxValue('');
1733
+ self.addItem(value);
1734
+ if (self.settings.closeAfterSelect) {
1735
+ self.close();
1736
+ } else if (!self.settings.hideSelected && e.type && /mouse/.test(e.type)) {
1737
+ self.setActiveOption(self.getOption(value));
1738
+ }
1739
+ }
1740
+ }
1741
+ },
1742
+
1743
+ /**
1744
+ * Triggered when the user clicks on an item
1745
+ * that has been selected.
1746
+ *
1747
+ * @param {object} e
1748
+ * @returns {boolean}
1749
+ */
1750
+ onItemSelect: function(e) {
1751
+ var self = this;
1752
+
1753
+ if (self.isLocked) return;
1754
+ if (self.settings.mode === 'multi') {
1755
+ e.preventDefault();
1756
+ self.setActiveItem(e.currentTarget, e);
1757
+ }
1758
+ },
1759
+
1760
+ /**
1761
+ * Invokes the provided method that provides
1762
+ * results to a callback---which are then added
1763
+ * as options to the control.
1764
+ *
1765
+ * @param {function} fn
1766
+ */
1767
+ load: function(fn) {
1768
+ var self = this;
1769
+ var $wrapper = self.$wrapper.addClass(self.settings.loadingClass);
1770
+
1771
+ self.loading++;
1772
+ fn.apply(self, [function(results) {
1773
+ self.loading = Math.max(self.loading - 1, 0);
1774
+ if (results && results.length) {
1775
+ self.addOption(results);
1776
+ self.refreshOptions(self.isFocused && !self.isInputHidden);
1777
+ }
1778
+ if (!self.loading) {
1779
+ $wrapper.removeClass(self.settings.loadingClass);
1780
+ }
1781
+ self.trigger('load', results);
1782
+ }]);
1783
+ },
1784
+
1785
+ /**
1786
+ * Sets the input field of the control to the specified value.
1787
+ *
1788
+ * @param {string} value
1789
+ */
1790
+ setTextboxValue: function(value) {
1791
+ var $input = this.$control_input;
1792
+ var changed = $input.val() !== value;
1793
+ if (changed) {
1794
+ $input.val(value).triggerHandler('update');
1795
+ this.lastValue = value;
1796
+ }
1797
+ },
1798
+
1799
+ /**
1800
+ * Returns the value of the control. If multiple items
1801
+ * can be selected (e.g. <select multiple>), this returns
1802
+ * an array. If only one item can be selected, this
1803
+ * returns a string.
1804
+ *
1805
+ * @returns {mixed}
1806
+ */
1807
+ getValue: function() {
1808
+ if (this.tagType === TAG_SELECT && this.$input.attr('multiple')) {
1809
+ return this.items;
1810
+ } else {
1811
+ return this.items.join(this.settings.delimiter);
1812
+ }
1813
+ },
1814
+
1815
+ /**
1816
+ * Resets the selected items to the given value.
1817
+ *
1818
+ * @param {mixed} value
1819
+ */
1820
+ setValue: function(value, silent) {
1821
+ var events = silent ? [] : ['change'];
1822
+
1823
+ debounce_events(this, events, function() {
1824
+ this.clear(silent);
1825
+ this.addItems(value, silent);
1826
+ });
1827
+ },
1828
+
1829
+ /**
1830
+ * Sets the selected item.
1831
+ *
1832
+ * @param {object} $item
1833
+ * @param {object} e (optional)
1834
+ */
1835
+ setActiveItem: function($item, e) {
1836
+ var self = this;
1837
+ var eventName;
1838
+ var i, idx, begin, end, item, swap;
1839
+ var $last;
1840
+
1841
+ if (self.settings.mode === 'single') return;
1842
+ $item = $($item);
1843
+
1844
+ // clear the active selection
1845
+ if (!$item.length) {
1846
+ $(self.$activeItems).removeClass('active');
1847
+ self.$activeItems = [];
1848
+ if (self.isFocused) {
1849
+ self.showInput();
1850
+ }
1851
+ return;
1852
+ }
1853
+
1854
+ // modify selection
1855
+ eventName = e && e.type.toLowerCase();
1856
+
1857
+ if (eventName === 'mousedown' && self.isShiftDown && self.$activeItems.length) {
1858
+ $last = self.$control.children('.active:last');
1859
+ begin = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$last[0]]);
1860
+ end = Array.prototype.indexOf.apply(self.$control[0].childNodes, [$item[0]]);
1861
+ if (begin > end) {
1862
+ swap = begin;
1863
+ begin = end;
1864
+ end = swap;
1865
+ }
1866
+ for (i = begin; i <= end; i++) {
1867
+ item = self.$control[0].childNodes[i];
1868
+ if (self.$activeItems.indexOf(item) === -1) {
1869
+ $(item).addClass('active');
1870
+ self.$activeItems.push(item);
1871
+ }
1872
+ }
1873
+ e.preventDefault();
1874
+ } else if ((eventName === 'mousedown' && self.isCtrlDown) || (eventName === 'keydown' && this.isShiftDown)) {
1875
+ if ($item.hasClass('active')) {
1876
+ idx = self.$activeItems.indexOf($item[0]);
1877
+ self.$activeItems.splice(idx, 1);
1878
+ $item.removeClass('active');
1879
+ } else {
1880
+ self.$activeItems.push($item.addClass('active')[0]);
1881
+ }
1882
+ } else {
1883
+ $(self.$activeItems).removeClass('active');
1884
+ self.$activeItems = [$item.addClass('active')[0]];
1885
+ }
1886
+
1887
+ // ensure control has focus
1888
+ self.hideInput();
1889
+ if (!this.isFocused) {
1890
+ self.focus();
1891
+ }
1892
+ },
1893
+
1894
+ /**
1895
+ * Sets the selected item in the dropdown menu
1896
+ * of available options.
1897
+ *
1898
+ * @param {object} $object
1899
+ * @param {boolean} scroll
1900
+ * @param {boolean} animate
1901
+ */
1902
+ setActiveOption: function($option, scroll, animate) {
1903
+ var height_menu, height_item, y;
1904
+ var scroll_top, scroll_bottom;
1905
+ var self = this;
1906
+
1907
+ if (self.$activeOption) self.$activeOption.removeClass('active');
1908
+ self.$activeOption = null;
1909
+
1910
+ $option = $($option);
1911
+ if (!$option.length) return;
1912
+
1913
+ self.$activeOption = $option.addClass('active');
1914
+
1915
+ if (scroll || !isset(scroll)) {
1916
+
1917
+ height_menu = self.$dropdown_content.height();
1918
+ height_item = self.$activeOption.outerHeight(true);
1919
+ scroll = self.$dropdown_content.scrollTop() || 0;
1920
+ y = self.$activeOption.offset().top - self.$dropdown_content.offset().top + scroll;
1921
+ scroll_top = y;
1922
+ scroll_bottom = y - height_menu + height_item;
1923
+
1924
+ if (y + height_item > height_menu + scroll) {
1925
+ self.$dropdown_content.stop().animate({scrollTop: scroll_bottom}, animate ? self.settings.scrollDuration : 0);
1926
+ } else if (y < scroll) {
1927
+ self.$dropdown_content.stop().animate({scrollTop: scroll_top}, animate ? self.settings.scrollDuration : 0);
1928
+ }
1929
+
1930
+ }
1931
+ },
1932
+
1933
+ /**
1934
+ * Selects all items (CTRL + A).
1935
+ */
1936
+ selectAll: function() {
1937
+ var self = this;
1938
+ if (self.settings.mode === 'single') return;
1939
+
1940
+ self.$activeItems = Array.prototype.slice.apply(self.$control.children(':not(input)').addClass('active'));
1941
+ if (self.$activeItems.length) {
1942
+ self.hideInput();
1943
+ self.close();
1944
+ }
1945
+ self.focus();
1946
+ },
1947
+
1948
+ /**
1949
+ * Hides the input element out of view, while
1950
+ * retaining its focus.
1951
+ */
1952
+ hideInput: function() {
1953
+ var self = this;
1954
+
1955
+ self.setTextboxValue('');
1956
+ self.$control_input.css({opacity: 0, position: 'absolute', left: self.rtl ? 10000 : -10000});
1957
+ self.isInputHidden = true;
1958
+ },
1959
+
1960
+ /**
1961
+ * Restores input visibility.
1962
+ */
1963
+ showInput: function() {
1964
+ this.$control_input.css({opacity: 1, position: 'relative', left: 0});
1965
+ this.isInputHidden = false;
1966
+ },
1967
+
1968
+ /**
1969
+ * Gives the control focus.
1970
+ */
1971
+ focus: function() {
1972
+ var self = this;
1973
+ if (self.isDisabled) return;
1974
+
1975
+ self.ignoreFocus = true;
1976
+ self.$control_input[0].focus();
1977
+ window.setTimeout(function() {
1978
+ self.ignoreFocus = false;
1979
+ self.onFocus();
1980
+ }, 0);
1981
+ },
1982
+
1983
+ /**
1984
+ * Forces the control out of focus.
1985
+ *
1986
+ * @param {Element} dest
1987
+ */
1988
+ blur: function(dest) {
1989
+ this.$control_input[0].blur();
1990
+ this.onBlur(null, dest);
1991
+ },
1992
+
1993
+ /**
1994
+ * Returns a function that scores an object
1995
+ * to show how good of a match it is to the
1996
+ * provided query.
1997
+ *
1998
+ * @param {string} query
1999
+ * @param {object} options
2000
+ * @return {function}
2001
+ */
2002
+ getScoreFunction: function(query) {
2003
+ return this.sifter.getScoreFunction(query, this.getSearchOptions());
2004
+ },
2005
+
2006
+ /**
2007
+ * Returns search options for sifter (the system
2008
+ * for scoring and sorting results).
2009
+ *
2010
+ * @see https://github.com/brianreavis/sifter.js
2011
+ * @return {object}
2012
+ */
2013
+ getSearchOptions: function() {
2014
+ var settings = this.settings;
2015
+ var sort = settings.sortField;
2016
+ if (typeof sort === 'string') {
2017
+ sort = [{field: sort}];
2018
+ }
2019
+
2020
+ return {
2021
+ fields : settings.searchField,
2022
+ conjunction : settings.searchConjunction,
2023
+ sort : sort
2024
+ };
2025
+ },
2026
+
2027
+ /**
2028
+ * Searches through available options and returns
2029
+ * a sorted array of matches.
2030
+ *
2031
+ * Returns an object containing:
2032
+ *
2033
+ * - query {string}
2034
+ * - tokens {array}
2035
+ * - total {int}
2036
+ * - items {array}
2037
+ *
2038
+ * @param {string} query
2039
+ * @returns {object}
2040
+ */
2041
+ search: function(query) {
2042
+ var i, value, score, result, calculateScore;
2043
+ var self = this;
2044
+ var settings = self.settings;
2045
+ var options = this.getSearchOptions();
2046
+
2047
+ // validate user-provided result scoring function
2048
+ if (settings.score) {
2049
+ calculateScore = self.settings.score.apply(this, [query]);
2050
+ if (typeof calculateScore !== 'function') {
2051
+ throw new Error('Selectize "score" setting must be a function that returns a function');
2052
+ }
2053
+ }
2054
+
2055
+ // perform search
2056
+ if (query !== self.lastQuery) {
2057
+ self.lastQuery = query;
2058
+ result = self.sifter.search(query, $.extend(options, {score: calculateScore}));
2059
+ self.currentResults = result;
2060
+ } else {
2061
+ result = $.extend(true, {}, self.currentResults);
2062
+ }
2063
+
2064
+ // filter out selected items
2065
+ if (settings.hideSelected) {
2066
+ for (i = result.items.length - 1; i >= 0; i--) {
2067
+ if (self.items.indexOf(hash_key(result.items[i].id)) !== -1) {
2068
+ result.items.splice(i, 1);
2069
+ }
2070
+ }
2071
+ }
2072
+
2073
+ return result;
2074
+ },
2075
+
2076
+ /**
2077
+ * Refreshes the list of available options shown
2078
+ * in the autocomplete dropdown menu.
2079
+ *
2080
+ * @param {boolean} triggerDropdown
2081
+ */
2082
+ refreshOptions: function(triggerDropdown) {
2083
+ var i, j, k, n, groups, groups_order, option, option_html, optgroup, optgroups, html, html_children, has_create_option;
2084
+ var $active, $active_before, $create;
2085
+
2086
+ if (typeof triggerDropdown === 'undefined') {
2087
+ triggerDropdown = true;
2088
+ }
2089
+
2090
+ var self = this;
2091
+ var query = $.trim(self.$control_input.val());
2092
+ var results = self.search(query);
2093
+ var $dropdown_content = self.$dropdown_content;
2094
+ var active_before = self.$activeOption && hash_key(self.$activeOption.attr('data-value'));
2095
+
2096
+ // build markup
2097
+ n = results.items.length;
2098
+ if (typeof self.settings.maxOptions === 'number') {
2099
+ n = Math.min(n, self.settings.maxOptions);
2100
+ }
2101
+
2102
+ // render and group available options individually
2103
+ groups = {};
2104
+ groups_order = [];
2105
+
2106
+ for (i = 0; i < n; i++) {
2107
+ option = self.options[results.items[i].id];
2108
+ option_html = self.render('option', option);
2109
+ optgroup = option[self.settings.optgroupField] || '';
2110
+ optgroups = $.isArray(optgroup) ? optgroup : [optgroup];
2111
+
2112
+ for (j = 0, k = optgroups && optgroups.length; j < k; j++) {
2113
+ optgroup = optgroups[j];
2114
+ if (!self.optgroups.hasOwnProperty(optgroup)) {
2115
+ optgroup = '';
2116
+ }
2117
+ if (!groups.hasOwnProperty(optgroup)) {
2118
+ groups[optgroup] = [];
2119
+ groups_order.push(optgroup);
2120
+ }
2121
+ groups[optgroup].push(option_html);
2122
+ }
2123
+ }
2124
+
2125
+ // sort optgroups
2126
+ if (this.settings.lockOptgroupOrder) {
2127
+ groups_order.sort(function(a, b) {
2128
+ var a_order = self.optgroups[a].$order || 0;
2129
+ var b_order = self.optgroups[b].$order || 0;
2130
+ return a_order - b_order;
2131
+ });
2132
+ }
2133
+
2134
+ // render optgroup headers & join groups
2135
+ html = [];
2136
+ for (i = 0, n = groups_order.length; i < n; i++) {
2137
+ optgroup = groups_order[i];
2138
+ if (self.optgroups.hasOwnProperty(optgroup) && groups[optgroup].length) {
2139
+ // render the optgroup header and options within it,
2140
+ // then pass it to the wrapper template
2141
+ html_children = self.render('optgroup_header', self.optgroups[optgroup]) || '';
2142
+ html_children += groups[optgroup].join('');
2143
+ html.push(self.render('optgroup', $.extend({}, self.optgroups[optgroup], {
2144
+ html: html_children
2145
+ })));
2146
+ } else {
2147
+ html.push(groups[optgroup].join(''));
2148
+ }
2149
+ }
2150
+
2151
+ $dropdown_content.html(html.join(''));
2152
+
2153
+ // highlight matching terms inline
2154
+ if (self.settings.highlight && results.query.length && results.tokens.length) {
2155
+ for (i = 0, n = results.tokens.length; i < n; i++) {
2156
+ highlight($dropdown_content, results.tokens[i].regex);
2157
+ }
2158
+ }
2159
+
2160
+ // add "selected" class to selected options
2161
+ if (!self.settings.hideSelected) {
2162
+ for (i = 0, n = self.items.length; i < n; i++) {
2163
+ self.getOption(self.items[i]).addClass('selected');
2164
+ }
2165
+ }
2166
+
2167
+ // add create option
2168
+ has_create_option = self.canCreate(query);
2169
+ if (has_create_option) {
2170
+ $dropdown_content.prepend(self.render('option_create', {input: query}));
2171
+ $create = $($dropdown_content[0].childNodes[0]);
2172
+ }
2173
+
2174
+ // activate
2175
+ self.hasOptions = results.items.length > 0 || has_create_option;
2176
+ if (self.hasOptions) {
2177
+ if (results.items.length > 0) {
2178
+ $active_before = active_before && self.getOption(active_before);
2179
+ if ($active_before && $active_before.length) {
2180
+ $active = $active_before;
2181
+ } else if (self.settings.mode === 'single' && self.items.length) {
2182
+ $active = self.getOption(self.items[0]);
2183
+ }
2184
+ if (!$active || !$active.length) {
2185
+ if ($create && !self.settings.addPrecedence) {
2186
+ $active = self.getAdjacentOption($create, 1);
2187
+ } else {
2188
+ $active = $dropdown_content.find('[data-selectable]:first');
2189
+ }
2190
+ }
2191
+ } else {
2192
+ $active = $create;
2193
+ }
2194
+ self.setActiveOption($active);
2195
+ if (triggerDropdown && !self.isOpen) { self.open(); }
2196
+ } else {
2197
+ self.setActiveOption(null);
2198
+ if (triggerDropdown && self.isOpen) { self.close(); }
2199
+ }
2200
+ },
2201
+
2202
+ /**
2203
+ * Adds an available option. If it already exists,
2204
+ * nothing will happen. Note: this does not refresh
2205
+ * the options list dropdown (use `refreshOptions`
2206
+ * for that).
2207
+ *
2208
+ * Usage:
2209
+ *
2210
+ * this.addOption(data)
2211
+ *
2212
+ * @param {object|array} data
2213
+ */
2214
+ addOption: function(data) {
2215
+ var i, n, value, self = this;
2216
+
2217
+ if ($.isArray(data)) {
2218
+ for (i = 0, n = data.length; i < n; i++) {
2219
+ self.addOption(data[i]);
2220
+ }
2221
+ return;
2222
+ }
2223
+
2224
+ if (value = self.registerOption(data)) {
2225
+ self.userOptions[value] = true;
2226
+ self.lastQuery = null;
2227
+ self.trigger('option_add', value, data);
2228
+ }
2229
+ },
2230
+
2231
+ /**
2232
+ * Registers an option to the pool of options.
2233
+ *
2234
+ * @param {object} data
2235
+ * @return {boolean|string}
2236
+ */
2237
+ registerOption: function(data) {
2238
+ var key = hash_key(data[this.settings.valueField]);
2239
+ if (!key || this.options.hasOwnProperty(key)) return false;
2240
+ data.$order = data.$order || ++this.order;
2241
+ this.options[key] = data;
2242
+ return key;
2243
+ },
2244
+
2245
+ /**
2246
+ * Registers an option group to the pool of option groups.
2247
+ *
2248
+ * @param {object} data
2249
+ * @return {boolean|string}
2250
+ */
2251
+ registerOptionGroup: function(data) {
2252
+ var key = hash_key(data[this.settings.optgroupValueField]);
2253
+ if (!key) return false;
2254
+
2255
+ data.$order = data.$order || ++this.order;
2256
+ this.optgroups[key] = data;
2257
+ return key;
2258
+ },
2259
+
2260
+ /**
2261
+ * Registers a new optgroup for options
2262
+ * to be bucketed into.
2263
+ *
2264
+ * @param {string} id
2265
+ * @param {object} data
2266
+ */
2267
+ addOptionGroup: function(id, data) {
2268
+ data[this.settings.optgroupValueField] = id;
2269
+ if (id = this.registerOptionGroup(data)) {
2270
+ this.trigger('optgroup_add', id, data);
2271
+ }
2272
+ },
2273
+
2274
+ /**
2275
+ * Removes an existing option group.
2276
+ *
2277
+ * @param {string} id
2278
+ */
2279
+ removeOptionGroup: function(id) {
2280
+ if (this.optgroups.hasOwnProperty(id)) {
2281
+ delete this.optgroups[id];
2282
+ this.renderCache = {};
2283
+ this.trigger('optgroup_remove', id);
2284
+ }
2285
+ },
2286
+
2287
+ /**
2288
+ * Clears all existing option groups.
2289
+ */
2290
+ clearOptionGroups: function() {
2291
+ this.optgroups = {};
2292
+ this.renderCache = {};
2293
+ this.trigger('optgroup_clear');
2294
+ },
2295
+
2296
+ /**
2297
+ * Updates an option available for selection. If
2298
+ * it is visible in the selected items or options
2299
+ * dropdown, it will be re-rendered automatically.
2300
+ *
2301
+ * @param {string} value
2302
+ * @param {object} data
2303
+ */
2304
+ updateOption: function(value, data) {
2305
+ var self = this;
2306
+ var $item, $item_new;
2307
+ var value_new, index_item, cache_items, cache_options, order_old;
2308
+
2309
+ value = hash_key(value);
2310
+ value_new = hash_key(data[self.settings.valueField]);
2311
+
2312
+ // sanity checks
2313
+ if (value === null) return;
2314
+ if (!self.options.hasOwnProperty(value)) return;
2315
+ if (typeof value_new !== 'string') throw new Error('Value must be set in option data');
2316
+
2317
+ order_old = self.options[value].$order;
2318
+
2319
+ // update references
2320
+ if (value_new !== value) {
2321
+ delete self.options[value];
2322
+ index_item = self.items.indexOf(value);
2323
+ if (index_item !== -1) {
2324
+ self.items.splice(index_item, 1, value_new);
2325
+ }
2326
+ }
2327
+ data.$order = data.$order || order_old;
2328
+ self.options[value_new] = data;
2329
+
2330
+ // invalidate render cache
2331
+ cache_items = self.renderCache['item'];
2332
+ cache_options = self.renderCache['option'];
2333
+
2334
+ if (cache_items) {
2335
+ delete cache_items[value];
2336
+ delete cache_items[value_new];
2337
+ }
2338
+ if (cache_options) {
2339
+ delete cache_options[value];
2340
+ delete cache_options[value_new];
2341
+ }
2342
+
2343
+ // update the item if it's selected
2344
+ if (self.items.indexOf(value_new) !== -1) {
2345
+ $item = self.getItem(value);
2346
+ $item_new = $(self.render('item', data));
2347
+ if ($item.hasClass('active')) $item_new.addClass('active');
2348
+ $item.replaceWith($item_new);
2349
+ }
2350
+
2351
+ // invalidate last query because we might have updated the sortField
2352
+ self.lastQuery = null;
2353
+
2354
+ // update dropdown contents
2355
+ if (self.isOpen) {
2356
+ self.refreshOptions(false);
2357
+ }
2358
+ },
2359
+
2360
+ /**
2361
+ * Removes a single option.
2362
+ *
2363
+ * @param {string} value
2364
+ * @param {boolean} silent
2365
+ */
2366
+ removeOption: function(value, silent) {
2367
+ var self = this;
2368
+ value = hash_key(value);
2369
+
2370
+ var cache_items = self.renderCache['item'];
2371
+ var cache_options = self.renderCache['option'];
2372
+ if (cache_items) delete cache_items[value];
2373
+ if (cache_options) delete cache_options[value];
2374
+
2375
+ delete self.userOptions[value];
2376
+ delete self.options[value];
2377
+ self.lastQuery = null;
2378
+ self.trigger('option_remove', value);
2379
+ self.removeItem(value, silent);
2380
+ },
2381
+
2382
+ /**
2383
+ * Clears all options.
2384
+ */
2385
+ clearOptions: function() {
2386
+ var self = this;
2387
+
2388
+ self.loadedSearches = {};
2389
+ self.userOptions = {};
2390
+ self.renderCache = {};
2391
+ self.options = self.sifter.items = {};
2392
+ self.lastQuery = null;
2393
+ self.trigger('option_clear');
2394
+ self.clear();
2395
+ },
2396
+
2397
+ /**
2398
+ * Returns the jQuery element of the option
2399
+ * matching the given value.
2400
+ *
2401
+ * @param {string} value
2402
+ * @returns {object}
2403
+ */
2404
+ getOption: function(value) {
2405
+ return this.getElementWithValue(value, this.$dropdown_content.find('[data-selectable]'));
2406
+ },
2407
+
2408
+ /**
2409
+ * Returns the jQuery element of the next or
2410
+ * previous selectable option.
2411
+ *
2412
+ * @param {object} $option
2413
+ * @param {int} direction can be 1 for next or -1 for previous
2414
+ * @return {object}
2415
+ */
2416
+ getAdjacentOption: function($option, direction) {
2417
+ var $options = this.$dropdown.find('[data-selectable]');
2418
+ var index = $options.index($option) + direction;
2419
+
2420
+ return index >= 0 && index < $options.length ? $options.eq(index) : $();
2421
+ },
2422
+
2423
+ /**
2424
+ * Finds the first element with a "data-value" attribute
2425
+ * that matches the given value.
2426
+ *
2427
+ * @param {mixed} value
2428
+ * @param {object} $els
2429
+ * @return {object}
2430
+ */
2431
+ getElementWithValue: function(value, $els) {
2432
+ value = hash_key(value);
2433
+
2434
+ if (typeof value !== 'undefined' && value !== null) {
2435
+ for (var i = 0, n = $els.length; i < n; i++) {
2436
+ if ($els[i].getAttribute('data-value') === value) {
2437
+ return $($els[i]);
2438
+ }
2439
+ }
2440
+ }
2441
+
2442
+ return $();
2443
+ },
2444
+
2445
+ /**
2446
+ * Returns the jQuery element of the item
2447
+ * matching the given value.
2448
+ *
2449
+ * @param {string} value
2450
+ * @returns {object}
2451
+ */
2452
+ getItem: function(value) {
2453
+ return this.getElementWithValue(value, this.$control.children());
2454
+ },
2455
+
2456
+ /**
2457
+ * "Selects" multiple items at once. Adds them to the list
2458
+ * at the current caret position.
2459
+ *
2460
+ * @param {string} value
2461
+ * @param {boolean} silent
2462
+ */
2463
+ addItems: function(values, silent) {
2464
+ var items = $.isArray(values) ? values : [values];
2465
+ for (var i = 0, n = items.length; i < n; i++) {
2466
+ this.isPending = (i < n - 1);
2467
+ this.addItem(items[i], silent);
2468
+ }
2469
+ },
2470
+
2471
+ /**
2472
+ * "Selects" an item. Adds it to the list
2473
+ * at the current caret position.
2474
+ *
2475
+ * @param {string} value
2476
+ * @param {boolean} silent
2477
+ */
2478
+ addItem: function(value, silent) {
2479
+ var events = silent ? [] : ['change'];
2480
+
2481
+ debounce_events(this, events, function() {
2482
+ var $item, $option, $options;
2483
+ var self = this;
2484
+ var inputMode = self.settings.mode;
2485
+ var i, active, value_next, wasFull;
2486
+ value = hash_key(value);
2487
+
2488
+ if (self.items.indexOf(value) !== -1) {
2489
+ if (inputMode === 'single') self.close();
2490
+ return;
2491
+ }
2492
+
2493
+ if (!self.options.hasOwnProperty(value)) return;
2494
+ if (inputMode === 'single') self.clear(silent);
2495
+ if (inputMode === 'multi' && self.isFull()) return;
2496
+
2497
+ $item = $(self.render('item', self.options[value]));
2498
+ wasFull = self.isFull();
2499
+ self.items.splice(self.caretPos, 0, value);
2500
+ self.insertAtCaret($item);
2501
+ if (!self.isPending || (!wasFull && self.isFull())) {
2502
+ self.refreshState();
2503
+ }
2504
+
2505
+ if (self.isSetup) {
2506
+ $options = self.$dropdown_content.find('[data-selectable]');
2507
+
2508
+ // update menu / remove the option (if this is not one item being added as part of series)
2509
+ if (!self.isPending) {
2510
+ $option = self.getOption(value);
2511
+ value_next = self.getAdjacentOption($option, 1).attr('data-value');
2512
+ self.refreshOptions(self.isFocused && inputMode !== 'single');
2513
+ if (value_next) {
2514
+ self.setActiveOption(self.getOption(value_next));
2515
+ }
2516
+ }
2517
+
2518
+ // hide the menu if the maximum number of items have been selected or no options are left
2519
+ if (!$options.length || self.isFull()) {
2520
+ self.close();
2521
+ } else {
2522
+ self.positionDropdown();
2523
+ }
2524
+
2525
+ self.updatePlaceholder();
2526
+ self.trigger('item_add', value, $item);
2527
+ self.updateOriginalInput({silent: silent});
2528
+ }
2529
+ });
2530
+ },
2531
+
2532
+ /**
2533
+ * Removes the selected item matching
2534
+ * the provided value.
2535
+ *
2536
+ * @param {string} value
2537
+ */
2538
+ removeItem: function(value, silent) {
2539
+ var self = this;
2540
+ var $item, i, idx;
2541
+
2542
+ $item = (typeof value === 'object') ? value : self.getItem(value);
2543
+ value = hash_key($item.attr('data-value'));
2544
+ i = self.items.indexOf(value);
2545
+
2546
+ if (i !== -1) {
2547
+ $item.remove();
2548
+ if ($item.hasClass('active')) {
2549
+ idx = self.$activeItems.indexOf($item[0]);
2550
+ self.$activeItems.splice(idx, 1);
2551
+ }
2552
+
2553
+ self.items.splice(i, 1);
2554
+ self.lastQuery = null;
2555
+ if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) {
2556
+ self.removeOption(value, silent);
2557
+ }
2558
+
2559
+ if (i < self.caretPos) {
2560
+ self.setCaret(self.caretPos - 1);
2561
+ }
2562
+
2563
+ self.refreshState();
2564
+ self.updatePlaceholder();
2565
+ self.updateOriginalInput({silent: silent});
2566
+ self.positionDropdown();
2567
+ self.trigger('item_remove', value, $item);
2568
+ }
2569
+ },
2570
+
2571
+ /**
2572
+ * Invokes the `create` method provided in the
2573
+ * selectize options that should provide the data
2574
+ * for the new item, given the user input.
2575
+ *
2576
+ * Once this completes, it will be added
2577
+ * to the item list.
2578
+ *
2579
+ * @param {string} value
2580
+ * @param {boolean} [triggerDropdown]
2581
+ * @param {function} [callback]
2582
+ * @return {boolean}
2583
+ */
2584
+ createItem: function(input, triggerDropdown) {
2585
+ var self = this;
2586
+ var caret = self.caretPos;
2587
+ input = input || $.trim(self.$control_input.val() || '');
2588
+
2589
+ var callback = arguments[arguments.length - 1];
2590
+ if (typeof callback !== 'function') callback = function() {};
2591
+
2592
+ if (typeof triggerDropdown !== 'boolean') {
2593
+ triggerDropdown = true;
2594
+ }
2595
+
2596
+ if (!self.canCreate(input)) {
2597
+ callback();
2598
+ return false;
2599
+ }
2600
+
2601
+ self.lock();
2602
+
2603
+ var setup = (typeof self.settings.create === 'function') ? this.settings.create : function(input) {
2604
+ var data = {};
2605
+ data[self.settings.labelField] = input;
2606
+ data[self.settings.valueField] = input;
2607
+ return data;
2608
+ };
2609
+
2610
+ var create = once(function(data) {
2611
+ self.unlock();
2612
+
2613
+ if (!data || typeof data !== 'object') return callback();
2614
+ var value = hash_key(data[self.settings.valueField]);
2615
+ if (typeof value !== 'string') return callback();
2616
+
2617
+ self.setTextboxValue('');
2618
+ self.addOption(data);
2619
+ self.setCaret(caret);
2620
+ self.addItem(value);
2621
+ self.refreshOptions(triggerDropdown && self.settings.mode !== 'single');
2622
+ callback(data);
2623
+ });
2624
+
2625
+ var output = setup.apply(this, [input, create]);
2626
+ if (typeof output !== 'undefined') {
2627
+ create(output);
2628
+ }
2629
+
2630
+ return true;
2631
+ },
2632
+
2633
+ /**
2634
+ * Re-renders the selected item lists.
2635
+ */
2636
+ refreshItems: function() {
2637
+ this.lastQuery = null;
2638
+
2639
+ if (this.isSetup) {
2640
+ this.addItem(this.items);
2641
+ }
2642
+
2643
+ this.refreshState();
2644
+ this.updateOriginalInput();
2645
+ },
2646
+
2647
+ /**
2648
+ * Updates all state-dependent attributes
2649
+ * and CSS classes.
2650
+ */
2651
+ refreshState: function() {
2652
+ var invalid, self = this;
2653
+ if (self.isRequired) {
2654
+ if (self.items.length) self.isInvalid = false;
2655
+ self.$control_input.prop('required', invalid);
2656
+ }
2657
+ self.refreshClasses();
2658
+ },
2659
+
2660
+ /**
2661
+ * Updates all state-dependent CSS classes.
2662
+ */
2663
+ refreshClasses: function() {
2664
+ var self = this;
2665
+ var isFull = self.isFull();
2666
+ var isLocked = self.isLocked;
2667
+
2668
+ self.$wrapper
2669
+ .toggleClass('rtl', self.rtl);
2670
+
2671
+ self.$control
2672
+ .toggleClass('focus', self.isFocused)
2673
+ .toggleClass('disabled', self.isDisabled)
2674
+ .toggleClass('required', self.isRequired)
2675
+ .toggleClass('invalid', self.isInvalid)
2676
+ .toggleClass('locked', isLocked)
2677
+ .toggleClass('full', isFull).toggleClass('not-full', !isFull)
2678
+ .toggleClass('input-active', self.isFocused && !self.isInputHidden)
2679
+ .toggleClass('dropdown-active', self.isOpen)
2680
+ .toggleClass('has-options', !$.isEmptyObject(self.options))
2681
+ .toggleClass('has-items', self.items.length > 0);
2682
+
2683
+ self.$control_input.data('grow', !isFull && !isLocked);
2684
+ },
2685
+
2686
+ /**
2687
+ * Determines whether or not more items can be added
2688
+ * to the control without exceeding the user-defined maximum.
2689
+ *
2690
+ * @returns {boolean}
2691
+ */
2692
+ isFull: function() {
2693
+ return this.settings.maxItems !== null && this.items.length >= this.settings.maxItems;
2694
+ },
2695
+
2696
+ /**
2697
+ * Refreshes the original <select> or <input>
2698
+ * element to reflect the current state.
2699
+ */
2700
+ updateOriginalInput: function(opts) {
2701
+ var i, n, options, label, self = this;
2702
+ opts = opts || {};
2703
+
2704
+ if (self.tagType === TAG_SELECT) {
2705
+ options = [];
2706
+ for (i = 0, n = self.items.length; i < n; i++) {
2707
+ label = self.options[self.items[i]][self.settings.labelField] || '';
2708
+ options.push('<option value="' + escape_html(self.items[i]) + '" selected="selected">' + escape_html(label) + '</option>');
2709
+ }
2710
+ if (!options.length && !this.$input.attr('multiple')) {
2711
+ options.push('<option value="" selected="selected"></option>');
2712
+ }
2713
+ self.$input.html(options.join(''));
2714
+ } else {
2715
+ self.$input.val(self.getValue());
2716
+ self.$input.attr('value',self.$input.val());
2717
+ }
2718
+
2719
+ if (self.isSetup) {
2720
+ if (!opts.silent) {
2721
+ self.trigger('change', self.$input.val());
2722
+ }
2723
+ }
2724
+ },
2725
+
2726
+ /**
2727
+ * Shows/hide the input placeholder depending
2728
+ * on if there items in the list already.
2729
+ */
2730
+ updatePlaceholder: function() {
2731
+ if (!this.settings.placeholder) return;
2732
+ var $input = this.$control_input;
2733
+
2734
+ if (this.items.length) {
2735
+ $input.removeAttr('placeholder');
2736
+ } else {
2737
+ $input.attr('placeholder', this.settings.placeholder);
2738
+ }
2739
+ $input.triggerHandler('update', {force: true});
2740
+ },
2741
+
2742
+ /**
2743
+ * Shows the autocomplete dropdown containing
2744
+ * the available options.
2745
+ */
2746
+ open: function() {
2747
+ var self = this;
2748
+
2749
+ if (self.isLocked || self.isOpen || (self.settings.mode === 'multi' && self.isFull())) return;
2750
+ self.focus();
2751
+ self.isOpen = true;
2752
+ self.refreshState();
2753
+ self.$dropdown.css({visibility: 'hidden', display: 'block'});
2754
+ self.positionDropdown();
2755
+ self.$dropdown.css({visibility: 'visible'});
2756
+ self.trigger('dropdown_open', self.$dropdown);
2757
+ },
2758
+
2759
+ /**
2760
+ * Closes the autocomplete dropdown menu.
2761
+ */
2762
+ close: function() {
2763
+ var self = this;
2764
+ var trigger = self.isOpen;
2765
+
2766
+ if (self.settings.mode === 'single' && self.items.length) {
2767
+ self.hideInput();
2768
+ }
2769
+
2770
+ self.isOpen = false;
2771
+ self.$dropdown.hide();
2772
+ self.setActiveOption(null);
2773
+ self.refreshState();
2774
+
2775
+ if (trigger) self.trigger('dropdown_close', self.$dropdown);
2776
+ },
2777
+
2778
+ /**
2779
+ * Calculates and applies the appropriate
2780
+ * position of the dropdown.
2781
+ */
2782
+ positionDropdown: function() {
2783
+ var $control = this.$control;
2784
+ var offset = this.settings.dropdownParent === 'body' ? $control.offset() : $control.position();
2785
+ offset.top += $control.outerHeight(true);
2786
+
2787
+ this.$dropdown.css({
2788
+ width : $control.outerWidth(),
2789
+ top : offset.top,
2790
+ left : offset.left
2791
+ });
2792
+ },
2793
+
2794
+ /**
2795
+ * Resets / clears all selected items
2796
+ * from the control.
2797
+ *
2798
+ * @param {boolean} silent
2799
+ */
2800
+ clear: function(silent) {
2801
+ var self = this;
2802
+
2803
+ if (!self.items.length) return;
2804
+ self.$control.children(':not(input)').remove();
2805
+ self.items = [];
2806
+ self.lastQuery = null;
2807
+ self.setCaret(0);
2808
+ self.setActiveItem(null);
2809
+ self.updatePlaceholder();
2810
+ self.updateOriginalInput({silent: silent});
2811
+ self.refreshState();
2812
+ self.showInput();
2813
+ self.trigger('clear');
2814
+ },
2815
+
2816
+ /**
2817
+ * A helper method for inserting an element
2818
+ * at the current caret position.
2819
+ *
2820
+ * @param {object} $el
2821
+ */
2822
+ insertAtCaret: function($el) {
2823
+ var caret = Math.min(this.caretPos, this.items.length);
2824
+ if (caret === 0) {
2825
+ this.$control.prepend($el);
2826
+ } else {
2827
+ $(this.$control[0].childNodes[caret]).before($el);
2828
+ }
2829
+ this.setCaret(caret + 1);
2830
+ },
2831
+
2832
+ /**
2833
+ * Removes the current selected item(s).
2834
+ *
2835
+ * @param {object} e (optional)
2836
+ * @returns {boolean}
2837
+ */
2838
+ deleteSelection: function(e) {
2839
+ var i, n, direction, selection, values, caret, option_select, $option_select, $tail;
2840
+ var self = this;
2841
+
2842
+ direction = (e && e.keyCode === KEY_BACKSPACE) ? -1 : 1;
2843
+ selection = getSelection(self.$control_input[0]);
2844
+
2845
+ if (self.$activeOption && !self.settings.hideSelected) {
2846
+ option_select = self.getAdjacentOption(self.$activeOption, -1).attr('data-value');
2847
+ }
2848
+
2849
+ // determine items that will be removed
2850
+ values = [];
2851
+
2852
+ if (self.$activeItems.length) {
2853
+ $tail = self.$control.children('.active:' + (direction > 0 ? 'last' : 'first'));
2854
+ caret = self.$control.children(':not(input)').index($tail);
2855
+ if (direction > 0) { caret++; }
2856
+
2857
+ for (i = 0, n = self.$activeItems.length; i < n; i++) {
2858
+ values.push($(self.$activeItems[i]).attr('data-value'));
2859
+ }
2860
+ if (e) {
2861
+ e.preventDefault();
2862
+ e.stopPropagation();
2863
+ }
2864
+ } else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) {
2865
+ if (direction < 0 && selection.start === 0 && selection.length === 0) {
2866
+ values.push(self.items[self.caretPos - 1]);
2867
+ } else if (direction > 0 && selection.start === self.$control_input.val().length) {
2868
+ values.push(self.items[self.caretPos]);
2869
+ }
2870
+ }
2871
+
2872
+ // allow the callback to abort
2873
+ if (!values.length || (typeof self.settings.onDelete === 'function' && self.settings.onDelete.apply(self, [values]) === false)) {
2874
+ return false;
2875
+ }
2876
+
2877
+ // perform removal
2878
+ if (typeof caret !== 'undefined') {
2879
+ self.setCaret(caret);
2880
+ }
2881
+ while (values.length) {
2882
+ self.removeItem(values.pop());
2883
+ }
2884
+
2885
+ self.showInput();
2886
+ self.positionDropdown();
2887
+ self.refreshOptions(true);
2888
+
2889
+ // select previous option
2890
+ if (option_select) {
2891
+ $option_select = self.getOption(option_select);
2892
+ if ($option_select.length) {
2893
+ self.setActiveOption($option_select);
2894
+ }
2895
+ }
2896
+
2897
+ return true;
2898
+ },
2899
+
2900
+ /**
2901
+ * Selects the previous / next item (depending
2902
+ * on the `direction` argument).
2903
+ *
2904
+ * > 0 - right
2905
+ * < 0 - left
2906
+ *
2907
+ * @param {int} direction
2908
+ * @param {object} e (optional)
2909
+ */
2910
+ advanceSelection: function(direction, e) {
2911
+ var tail, selection, idx, valueLength, cursorAtEdge, $tail;
2912
+ var self = this;
2913
+
2914
+ if (direction === 0) return;
2915
+ if (self.rtl) direction *= -1;
2916
+
2917
+ tail = direction > 0 ? 'last' : 'first';
2918
+ selection = getSelection(self.$control_input[0]);
2919
+
2920
+ if (self.isFocused && !self.isInputHidden) {
2921
+ valueLength = self.$control_input.val().length;
2922
+ cursorAtEdge = direction < 0
2923
+ ? selection.start === 0 && selection.length === 0
2924
+ : selection.start === valueLength;
2925
+
2926
+ if (cursorAtEdge && !valueLength) {
2927
+ self.advanceCaret(direction, e);
2928
+ }
2929
+ } else {
2930
+ $tail = self.$control.children('.active:' + tail);
2931
+ if ($tail.length) {
2932
+ idx = self.$control.children(':not(input)').index($tail);
2933
+ self.setActiveItem(null);
2934
+ self.setCaret(direction > 0 ? idx + 1 : idx);
2935
+ }
2936
+ }
2937
+ },
2938
+
2939
+ /**
2940
+ * Moves the caret left / right.
2941
+ *
2942
+ * @param {int} direction
2943
+ * @param {object} e (optional)
2944
+ */
2945
+ advanceCaret: function(direction, e) {
2946
+ var self = this, fn, $adj;
2947
+
2948
+ if (direction === 0) return;
2949
+
2950
+ fn = direction > 0 ? 'next' : 'prev';
2951
+ if (self.isShiftDown) {
2952
+ $adj = self.$control_input[fn]();
2953
+ if ($adj.length) {
2954
+ self.hideInput();
2955
+ self.setActiveItem($adj);
2956
+ e && e.preventDefault();
2957
+ }
2958
+ } else {
2959
+ self.setCaret(self.caretPos + direction);
2960
+ }
2961
+ },
2962
+
2963
+ /**
2964
+ * Moves the caret to the specified index.
2965
+ *
2966
+ * @param {int} i
2967
+ */
2968
+ setCaret: function(i) {
2969
+ var self = this;
2970
+
2971
+ if (self.settings.mode === 'single') {
2972
+ i = self.items.length;
2973
+ } else {
2974
+ i = Math.max(0, Math.min(self.items.length, i));
2975
+ }
2976
+
2977
+ if(!self.isPending) {
2978
+ // the input must be moved by leaving it in place and moving the
2979
+ // siblings, due to the fact that focus cannot be restored once lost
2980
+ // on mobile webkit devices
2981
+ var j, n, fn, $children, $child;
2982
+ $children = self.$control.children(':not(input)');
2983
+ for (j = 0, n = $children.length; j < n; j++) {
2984
+ $child = $($children[j]).detach();
2985
+ if (j < i) {
2986
+ self.$control_input.before($child);
2987
+ } else {
2988
+ self.$control.append($child);
2989
+ }
2990
+ }
2991
+ }
2992
+
2993
+ self.caretPos = i;
2994
+ },
2995
+
2996
+ /**
2997
+ * Disables user input on the control. Used while
2998
+ * items are being asynchronously created.
2999
+ */
3000
+ lock: function() {
3001
+ this.close();
3002
+ this.isLocked = true;
3003
+ this.refreshState();
3004
+ },
3005
+
3006
+ /**
3007
+ * Re-enables user input on the control.
3008
+ */
3009
+ unlock: function() {
3010
+ this.isLocked = false;
3011
+ this.refreshState();
3012
+ },
3013
+
3014
+ /**
3015
+ * Disables user input on the control completely.
3016
+ * While disabled, it cannot receive focus.
3017
+ */
3018
+ disable: function() {
3019
+ var self = this;
3020
+ self.$input.prop('disabled', true);
3021
+ self.$control_input.prop('disabled', true).prop('tabindex', -1);
3022
+ self.isDisabled = true;
3023
+ self.lock();
3024
+ },
3025
+
3026
+ /**
3027
+ * Enables the control so that it can respond
3028
+ * to focus and user input.
3029
+ */
3030
+ enable: function() {
3031
+ var self = this;
3032
+ self.$input.prop('disabled', false);
3033
+ self.$control_input.prop('disabled', false).prop('tabindex', self.tabIndex);
3034
+ self.isDisabled = false;
3035
+ self.unlock();
3036
+ },
3037
+
3038
+ /**
3039
+ * Completely destroys the control and
3040
+ * unbinds all event listeners so that it can
3041
+ * be garbage collected.
3042
+ */
3043
+ destroy: function() {
3044
+ var self = this;
3045
+ var eventNS = self.eventNS;
3046
+ var revertSettings = self.revertSettings;
3047
+
3048
+ self.trigger('destroy');
3049
+ self.off();
3050
+ self.$wrapper.remove();
3051
+ self.$dropdown.remove();
3052
+
3053
+ self.$input
3054
+ .html('')
3055
+ .append(revertSettings.$children)
3056
+ .removeAttr('tabindex')
3057
+ .removeClass('selectized')
3058
+ .attr({tabindex: revertSettings.tabindex})
3059
+ .show();
3060
+
3061
+ self.$control_input.removeData('grow');
3062
+ self.$input.removeData('selectize');
3063
+
3064
+ $(window).off(eventNS);
3065
+ $(document).off(eventNS);
3066
+ $(document.body).off(eventNS);
3067
+
3068
+ delete self.$input[0].selectize;
3069
+ },
3070
+
3071
+ /**
3072
+ * A helper method for rendering "item" and
3073
+ * "option" templates, given the data.
3074
+ *
3075
+ * @param {string} templateName
3076
+ * @param {object} data
3077
+ * @returns {string}
3078
+ */
3079
+ render: function(templateName, data) {
3080
+ var value, id, label;
3081
+ var html = '';
3082
+ var cache = false;
3083
+ var self = this;
3084
+ var regex_tag = /^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;
3085
+
3086
+ if (templateName === 'option' || templateName === 'item') {
3087
+ value = hash_key(data[self.settings.valueField]);
3088
+ cache = !!value;
3089
+ }
3090
+
3091
+ // pull markup from cache if it exists
3092
+ if (cache) {
3093
+ if (!isset(self.renderCache[templateName])) {
3094
+ self.renderCache[templateName] = {};
3095
+ }
3096
+ if (self.renderCache[templateName].hasOwnProperty(value)) {
3097
+ return self.renderCache[templateName][value];
3098
+ }
3099
+ }
3100
+
3101
+ // render markup
3102
+ html = self.settings.render[templateName].apply(this, [data, escape_html]);
3103
+
3104
+ // add mandatory attributes
3105
+ if (templateName === 'option' || templateName === 'option_create') {
3106
+ html = html.replace(regex_tag, '<$1 data-selectable');
3107
+ }
3108
+ if (templateName === 'optgroup') {
3109
+ id = data[self.settings.optgroupValueField] || '';
3110
+ html = html.replace(regex_tag, '<$1 data-group="' + escape_replace(escape_html(id)) + '"');
3111
+ }
3112
+ if (templateName === 'option' || templateName === 'item') {
3113
+ html = html.replace(regex_tag, '<$1 data-value="' + escape_replace(escape_html(value || '')) + '"');
3114
+ }
3115
+
3116
+ // update cache
3117
+ if (cache) {
3118
+ self.renderCache[templateName][value] = html;
3119
+ }
3120
+
3121
+ return html;
3122
+ },
3123
+
3124
+ /**
3125
+ * Clears the render cache for a template. If
3126
+ * no template is given, clears all render
3127
+ * caches.
3128
+ *
3129
+ * @param {string} templateName
3130
+ */
3131
+ clearCache: function(templateName) {
3132
+ var self = this;
3133
+ if (typeof templateName === 'undefined') {
3134
+ self.renderCache = {};
3135
+ } else {
3136
+ delete self.renderCache[templateName];
3137
+ }
3138
+ },
3139
+
3140
+ /**
3141
+ * Determines whether or not to display the
3142
+ * create item prompt, given a user input.
3143
+ *
3144
+ * @param {string} input
3145
+ * @return {boolean}
3146
+ */
3147
+ canCreate: function(input) {
3148
+ var self = this;
3149
+ if (!self.settings.create) return false;
3150
+ var filter = self.settings.createFilter;
3151
+ return input.length
3152
+ && (typeof filter !== 'function' || filter.apply(self, [input]))
3153
+ && (typeof filter !== 'string' || new RegExp(filter).test(input))
3154
+ && (!(filter instanceof RegExp) || filter.test(input));
3155
+ }
3156
+
3157
+ });
3158
+
3159
+
3160
+ Selectize.count = 0;
3161
+ Selectize.defaults = {
3162
+ options: [],
3163
+ optgroups: [],
3164
+
3165
+ plugins: [],
3166
+ delimiter: ',',
3167
+ splitOn: null, // regexp or string for splitting up values from a paste command
3168
+ persist: true,
3169
+ diacritics: true,
3170
+ create: false,
3171
+ createOnBlur: false,
3172
+ createFilter: null,
3173
+ highlight: true,
3174
+ openOnFocus: true,
3175
+ maxOptions: 1000,
3176
+ maxItems: null,
3177
+ hideSelected: null,
3178
+ addPrecedence: false,
3179
+ selectOnTab: false,
3180
+ preload: false,
3181
+ allowEmptyOption: false,
3182
+ closeAfterSelect: false,
3183
+
3184
+ scrollDuration: 60,
3185
+ loadThrottle: 300,
3186
+ loadingClass: 'loading',
3187
+
3188
+ dataAttr: 'data-data',
3189
+ optgroupField: 'optgroup',
3190
+ valueField: 'value',
3191
+ labelField: 'text',
3192
+ optgroupLabelField: 'label',
3193
+ optgroupValueField: 'value',
3194
+ lockOptgroupOrder: false,
3195
+
3196
+ sortField: '$order',
3197
+ searchField: ['text'],
3198
+ searchConjunction: 'and',
3199
+
3200
+ mode: null,
3201
+ wrapperClass: 'selectize-control',
3202
+ inputClass: 'selectize-input',
3203
+ dropdownClass: 'selectize-dropdown',
3204
+ dropdownContentClass: 'selectize-dropdown-content',
3205
+
3206
+ dropdownParent: null,
3207
+
3208
+ copyClassesToDropdown: true,
3209
+
3210
+ /*
3211
+ load : null, // function(query, callback) { ... }
3212
+ score : null, // function(search) { ... }
3213
+ onInitialize : null, // function() { ... }
3214
+ onChange : null, // function(value) { ... }
3215
+ onItemAdd : null, // function(value, $item) { ... }
3216
+ onItemRemove : null, // function(value) { ... }
3217
+ onClear : null, // function() { ... }
3218
+ onOptionAdd : null, // function(value, data) { ... }
3219
+ onOptionRemove : null, // function(value) { ... }
3220
+ onOptionClear : null, // function() { ... }
3221
+ onOptionGroupAdd : null, // function(id, data) { ... }
3222
+ onOptionGroupRemove : null, // function(id) { ... }
3223
+ onOptionGroupClear : null, // function() { ... }
3224
+ onDropdownOpen : null, // function($dropdown) { ... }
3225
+ onDropdownClose : null, // function($dropdown) { ... }
3226
+ onType : null, // function(str) { ... }
3227
+ onDelete : null, // function(values) { ... }
3228
+ */
3229
+
3230
+ render: {
3231
+ /*
3232
+ item: null,
3233
+ optgroup: null,
3234
+ optgroup_header: null,
3235
+ option: null,
3236
+ option_create: null
3237
+ */
3238
+ }
3239
+ };
3240
+
3241
+
3242
+ $.fn.selectize = function(settings_user) {
3243
+ var defaults = $.fn.selectize.defaults;
3244
+ var settings = $.extend({}, defaults, settings_user);
3245
+ var attr_data = settings.dataAttr;
3246
+ var field_label = settings.labelField;
3247
+ var field_value = settings.valueField;
3248
+ var field_optgroup = settings.optgroupField;
3249
+ var field_optgroup_label = settings.optgroupLabelField;
3250
+ var field_optgroup_value = settings.optgroupValueField;
3251
+
3252
+ /**
3253
+ * Initializes selectize from a <input type="text"> element.
3254
+ *
3255
+ * @param {object} $input
3256
+ * @param {object} settings_element
3257
+ */
3258
+ var init_textbox = function($input, settings_element) {
3259
+ var i, n, values, option;
3260
+
3261
+ var data_raw = $input.attr(attr_data);
3262
+
3263
+ if (!data_raw) {
3264
+ var value = $.trim($input.val() || '');
3265
+ if (!settings.allowEmptyOption && !value.length) return;
3266
+ values = value.split(settings.delimiter);
3267
+ for (i = 0, n = values.length; i < n; i++) {
3268
+ option = {};
3269
+ option[field_label] = values[i];
3270
+ option[field_value] = values[i];
3271
+ settings_element.options.push(option);
3272
+ }
3273
+ settings_element.items = values;
3274
+ } else {
3275
+ settings_element.options = JSON.parse(data_raw);
3276
+ for (i = 0, n = settings_element.options.length; i < n; i++) {
3277
+ settings_element.items.push(settings_element.options[i][field_value]);
3278
+ }
3279
+ }
3280
+ };
3281
+
3282
+ /**
3283
+ * Initializes selectize from a <select> element.
3284
+ *
3285
+ * @param {object} $input
3286
+ * @param {object} settings_element
3287
+ */
3288
+ var init_select = function($input, settings_element) {
3289
+ var i, n, tagName, $children, order = 0;
3290
+ var options = settings_element.options;
3291
+ var optionsMap = {};
3292
+
3293
+ var readData = function($el) {
3294
+ var data = attr_data && $el.attr(attr_data);
3295
+ if (typeof data === 'string' && data.length) {
3296
+ return JSON.parse(data);
3297
+ }
3298
+ return null;
3299
+ };
3300
+
3301
+ var addOption = function($option, group) {
3302
+ $option = $($option);
3303
+
3304
+ var value = hash_key($option.attr('value'));
3305
+ if (!value && !settings.allowEmptyOption) return;
3306
+
3307
+ // if the option already exists, it's probably been
3308
+ // duplicated in another optgroup. in this case, push
3309
+ // the current group to the "optgroup" property on the
3310
+ // existing option so that it's rendered in both places.
3311
+ if (optionsMap.hasOwnProperty(value)) {
3312
+ if (group) {
3313
+ var arr = optionsMap[value][field_optgroup];
3314
+ if (!arr) {
3315
+ optionsMap[value][field_optgroup] = group;
3316
+ } else if (!$.isArray(arr)) {
3317
+ optionsMap[value][field_optgroup] = [arr, group];
3318
+ } else {
3319
+ arr.push(group);
3320
+ }
3321
+ }
3322
+ return;
3323
+ }
3324
+
3325
+ var option = readData($option) || {};
3326
+ option[field_label] = option[field_label] || $option.text();
3327
+ option[field_value] = option[field_value] || value;
3328
+ option[field_optgroup] = option[field_optgroup] || group;
3329
+
3330
+ optionsMap[value] = option;
3331
+ options.push(option);
3332
+
3333
+ if ($option.is(':selected')) {
3334
+ settings_element.items.push(value);
3335
+ }
3336
+ };
3337
+
3338
+ var addGroup = function($optgroup) {
3339
+ var i, n, id, optgroup, $options;
3340
+
3341
+ $optgroup = $($optgroup);
3342
+ id = $optgroup.attr('label');
3343
+
3344
+ if (id) {
3345
+ optgroup = readData($optgroup) || {};
3346
+ optgroup[field_optgroup_label] = id;
3347
+ optgroup[field_optgroup_value] = id;
3348
+ settings_element.optgroups.push(optgroup);
3349
+ }
3350
+
3351
+ $options = $('option', $optgroup);
3352
+ for (i = 0, n = $options.length; i < n; i++) {
3353
+ addOption($options[i], id);
3354
+ }
3355
+ };
3356
+
3357
+ settings_element.maxItems = $input.attr('multiple') ? null : 1;
3358
+
3359
+ $children = $input.children();
3360
+ for (i = 0, n = $children.length; i < n; i++) {
3361
+ tagName = $children[i].tagName.toLowerCase();
3362
+ if (tagName === 'optgroup') {
3363
+ addGroup($children[i]);
3364
+ } else if (tagName === 'option') {
3365
+ addOption($children[i]);
3366
+ }
3367
+ }
3368
+ };
3369
+
3370
+ return this.each(function() {
3371
+ if (this.selectize) return;
3372
+
3373
+ var instance;
3374
+ var $input = $(this);
3375
+ var tag_name = this.tagName.toLowerCase();
3376
+ var placeholder = $input.attr('placeholder') || $input.attr('data-placeholder');
3377
+ if (!placeholder && !settings.allowEmptyOption) {
3378
+ placeholder = $input.children('option[value=""]').text();
3379
+ }
3380
+
3381
+ var settings_element = {
3382
+ 'placeholder' : placeholder,
3383
+ 'options' : [],
3384
+ 'optgroups' : [],
3385
+ 'items' : []
3386
+ };
3387
+
3388
+ if (tag_name === 'select') {
3389
+ init_select($input, settings_element);
3390
+ } else {
3391
+ init_textbox($input, settings_element);
3392
+ }
3393
+
3394
+ instance = new Selectize($input, $.extend(true, {}, defaults, settings_element, settings_user));
3395
+ });
3396
+ };
3397
+
3398
+ $.fn.selectize.defaults = Selectize.defaults;
3399
+ $.fn.selectize.support = {
3400
+ validity: SUPPORTS_VALIDITY_API
3401
+ };
3402
+
3403
+
3404
+ Selectize.define('drag_drop', function(options) {
3405
+ if (!$.fn.sortable) throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');
3406
+ if (this.settings.mode !== 'multi') return;
3407
+ var self = this;
3408
+
3409
+ self.lock = (function() {
3410
+ var original = self.lock;
3411
+ return function() {
3412
+ var sortable = self.$control.data('sortable');
3413
+ if (sortable) sortable.disable();
3414
+ return original.apply(self, arguments);
3415
+ };
3416
+ })();
3417
+
3418
+ self.unlock = (function() {
3419
+ var original = self.unlock;
3420
+ return function() {
3421
+ var sortable = self.$control.data('sortable');
3422
+ if (sortable) sortable.enable();
3423
+ return original.apply(self, arguments);
3424
+ };
3425
+ })();
3426
+
3427
+ self.setup = (function() {
3428
+ var original = self.setup;
3429
+ return function() {
3430
+ original.apply(this, arguments);
3431
+
3432
+ var $control = self.$control.sortable({
3433
+ items: '[data-value]',
3434
+ forcePlaceholderSize: true,
3435
+ disabled: self.isLocked,
3436
+ start: function(e, ui) {
3437
+ ui.placeholder.css('width', ui.helper.css('width'));
3438
+ $control.css({overflow: 'visible'});
3439
+ },
3440
+ stop: function() {
3441
+ $control.css({overflow: 'hidden'});
3442
+ var active = self.$activeItems ? self.$activeItems.slice() : null;
3443
+ var values = [];
3444
+ $control.children('[data-value]').each(function() {
3445
+ values.push($(this).attr('data-value'));
3446
+ });
3447
+ self.setValue(values);
3448
+ self.setActiveItem(active);
3449
+ }
3450
+ });
3451
+ };
3452
+ })();
3453
+
3454
+ });
3455
+
3456
+ Selectize.define('dropdown_header', function(options) {
3457
+ var self = this;
3458
+
3459
+ options = $.extend({
3460
+ title : 'Untitled',
3461
+ headerClass : 'selectize-dropdown-header',
3462
+ titleRowClass : 'selectize-dropdown-header-title',
3463
+ labelClass : 'selectize-dropdown-header-label',
3464
+ closeClass : 'selectize-dropdown-header-close',
3465
+
3466
+ html: function(data) {
3467
+ return (
3468
+ '<div class="' + data.headerClass + '">' +
3469
+ '<div class="' + data.titleRowClass + '">' +
3470
+ '<span class="' + data.labelClass + '">' + data.title + '</span>' +
3471
+ '<a href="javascript:void(0)" class="' + data.closeClass + '">&times;</a>' +
3472
+ '</div>' +
3473
+ '</div>'
3474
+ );
3475
+ }
3476
+ }, options);
3477
+
3478
+ self.setup = (function() {
3479
+ var original = self.setup;
3480
+ return function() {
3481
+ original.apply(self, arguments);
3482
+ self.$dropdown_header = $(options.html(options));
3483
+ self.$dropdown.prepend(self.$dropdown_header);
3484
+ };
3485
+ })();
3486
+
3487
+ });
3488
+
3489
+ Selectize.define('optgroup_columns', function(options) {
3490
+ var self = this;
3491
+
3492
+ options = $.extend({
3493
+ equalizeWidth : true,
3494
+ equalizeHeight : true
3495
+ }, options);
3496
+
3497
+ this.getAdjacentOption = function($option, direction) {
3498
+ var $options = $option.closest('[data-group]').find('[data-selectable]');
3499
+ var index = $options.index($option) + direction;
3500
+
3501
+ return index >= 0 && index < $options.length ? $options.eq(index) : $();
3502
+ };
3503
+
3504
+ this.onKeyDown = (function() {
3505
+ var original = self.onKeyDown;
3506
+ return function(e) {
3507
+ var index, $option, $options, $optgroup;
3508
+
3509
+ if (this.isOpen && (e.keyCode === KEY_LEFT || e.keyCode === KEY_RIGHT)) {
3510
+ self.ignoreHover = true;
3511
+ $optgroup = this.$activeOption.closest('[data-group]');
3512
+ index = $optgroup.find('[data-selectable]').index(this.$activeOption);
3513
+
3514
+ if(e.keyCode === KEY_LEFT) {
3515
+ $optgroup = $optgroup.prev('[data-group]');
3516
+ } else {
3517
+ $optgroup = $optgroup.next('[data-group]');
3518
+ }
3519
+
3520
+ $options = $optgroup.find('[data-selectable]');
3521
+ $option = $options.eq(Math.min($options.length - 1, index));
3522
+ if ($option.length) {
3523
+ this.setActiveOption($option);
3524
+ }
3525
+ return;
3526
+ }
3527
+
3528
+ return original.apply(this, arguments);
3529
+ };
3530
+ })();
3531
+
3532
+ var getScrollbarWidth = function() {
3533
+ var div;
3534
+ var width = getScrollbarWidth.width;
3535
+ var doc = document;
3536
+
3537
+ if (typeof width === 'undefined') {
3538
+ div = doc.createElement('div');
3539
+ div.innerHTML = '<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>';
3540
+ div = div.firstChild;
3541
+ doc.body.appendChild(div);
3542
+ width = getScrollbarWidth.width = div.offsetWidth - div.clientWidth;
3543
+ doc.body.removeChild(div);
3544
+ }
3545
+ return width;
3546
+ };
3547
+
3548
+ var equalizeSizes = function() {
3549
+ var i, n, height_max, width, width_last, width_parent, $optgroups;
3550
+
3551
+ $optgroups = $('[data-group]', self.$dropdown_content);
3552
+ n = $optgroups.length;
3553
+ if (!n || !self.$dropdown_content.width()) return;
3554
+
3555
+ if (options.equalizeHeight) {
3556
+ height_max = 0;
3557
+ for (i = 0; i < n; i++) {
3558
+ height_max = Math.max(height_max, $optgroups.eq(i).height());
3559
+ }
3560
+ $optgroups.css({height: height_max});
3561
+ }
3562
+
3563
+ if (options.equalizeWidth) {
3564
+ width_parent = self.$dropdown_content.innerWidth() - getScrollbarWidth();
3565
+ width = Math.round(width_parent / n);
3566
+ $optgroups.css({width: width});
3567
+ if (n > 1) {
3568
+ width_last = width_parent - width * (n - 1);
3569
+ $optgroups.eq(n - 1).css({width: width_last});
3570
+ }
3571
+ }
3572
+ };
3573
+
3574
+ if (options.equalizeHeight || options.equalizeWidth) {
3575
+ hook.after(this, 'positionDropdown', equalizeSizes);
3576
+ hook.after(this, 'refreshOptions', equalizeSizes);
3577
+ }
3578
+
3579
+
3580
+ });
3581
+
3582
+ Selectize.define('remove_button', function(options) {
3583
+ if (this.settings.mode === 'single') return;
3584
+
3585
+ options = $.extend({
3586
+ label : '&times;',
3587
+ title : 'Remove',
3588
+ className : 'remove',
3589
+ append : true
3590
+ }, options);
3591
+
3592
+ var self = this;
3593
+ var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>';
3594
+
3595
+ /**
3596
+ * Appends an element as a child (with raw HTML).
3597
+ *
3598
+ * @param {string} html_container
3599
+ * @param {string} html_element
3600
+ * @return {string}
3601
+ */
3602
+ var append = function(html_container, html_element) {
3603
+ var pos = html_container.search(/(<\/[^>]+>\s*)$/);
3604
+ return html_container.substring(0, pos) + html_element + html_container.substring(pos);
3605
+ };
3606
+
3607
+ this.setup = (function() {
3608
+ var original = self.setup;
3609
+ return function() {
3610
+ // override the item rendering method to add the button to each
3611
+ if (options.append) {
3612
+ var render_item = self.settings.render.item;
3613
+ self.settings.render.item = function(data) {
3614
+ return append(render_item.apply(this, arguments), html);
3615
+ };
3616
+ }
3617
+
3618
+ original.apply(this, arguments);
3619
+
3620
+ // add event listener
3621
+ this.$control.on('click', '.' + options.className, function(e) {
3622
+ e.preventDefault();
3623
+ if (self.isLocked) return;
3624
+
3625
+ var $item = $(e.currentTarget).parent();
3626
+ self.setActiveItem($item);
3627
+ if (self.deleteSelection()) {
3628
+ self.setCaret(self.items.length);
3629
+ }
3630
+ });
3631
+
3632
+ };
3633
+ })();
3634
+
3635
+ });
3636
+
3637
+ Selectize.define('restore_on_backspace', function(options) {
3638
+ var self = this;
3639
+
3640
+ options.text = options.text || function(option) {
3641
+ return option[this.settings.labelField];
3642
+ };
3643
+
3644
+ this.onKeyDown = (function() {
3645
+ var original = self.onKeyDown;
3646
+ return function(e) {
3647
+ var index, option;
3648
+ if (e.keyCode === KEY_BACKSPACE && this.$control_input.val() === '' && !this.$activeItems.length) {
3649
+ index = this.caretPos - 1;
3650
+ if (index >= 0 && index < this.items.length) {
3651
+ option = this.options[this.items[index]];
3652
+ if (this.deleteSelection(e)) {
3653
+ this.setTextboxValue(options.text.apply(this, [option]));
3654
+ this.refreshOptions(true);
3655
+ }
3656
+ e.preventDefault();
3657
+ return;
3658
+ }
3659
+ }
3660
+ return original.apply(this, arguments);
3661
+ };
3662
+ })();
3663
+ });
3664
+
3665
+
3666
+ return Selectize;
3667
+ }));
js/selectize.min.js ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ /*! selectize.js - v0.12.1 | https://github.com/brianreavis/selectize.js | Apache License (v2) */
2
+ !function(a,b){"function"==typeof define&&define.amd?define("sifter",b):"object"==typeof exports?module.exports=b():a.Sifter=b()}(this,function(){var a=function(a,b){this.items=a,this.settings=b||{diacritics:!0}};a.prototype.tokenize=function(a){if(a=d(String(a||"").toLowerCase()),!a||!a.length)return[];var b,c,f,h,i=[],j=a.split(/ +/);for(b=0,c=j.length;c>b;b++){if(f=e(j[b]),this.settings.diacritics)for(h in g)g.hasOwnProperty(h)&&(f=f.replace(new RegExp(h,"g"),g[h]));i.push({string:j[b],regex:new RegExp(f,"i")})}return i},a.prototype.iterator=function(a,b){var c;c=f(a)?Array.prototype.forEach||function(a){for(var b=0,c=this.length;c>b;b++)a(this[b],b,this)}:function(a){for(var b in this)this.hasOwnProperty(b)&&a(this[b],b,this)},c.apply(a,[b])},a.prototype.getScoreFunction=function(a,b){var c,d,e,f;c=this,a=c.prepareSearch(a,b),e=a.tokens,d=a.options.fields,f=e.length;var g=function(a,b){var c,d;return a?(a=String(a||""),d=a.search(b.regex),-1===d?0:(c=b.string.length/a.length,0===d&&(c+=.5),c)):0},h=function(){var a=d.length;return a?1===a?function(a,b){return g(b[d[0]],a)}:function(b,c){for(var e=0,f=0;a>e;e++)f+=g(c[d[e]],b);return f/a}:function(){return 0}}();return f?1===f?function(a){return h(e[0],a)}:"and"===a.options.conjunction?function(a){for(var b,c=0,d=0;f>c;c++){if(b=h(e[c],a),0>=b)return 0;d+=b}return d/f}:function(a){for(var b=0,c=0;f>b;b++)c+=h(e[b],a);return c/f}:function(){return 0}},a.prototype.getSortFunction=function(a,c){var d,e,f,g,h,i,j,k,l,m,n;if(f=this,a=f.prepareSearch(a,c),n=!a.query&&c.sort_empty||c.sort,l=function(a,b){return"$score"===a?b.score:f.items[b.id][a]},h=[],n)for(d=0,e=n.length;e>d;d++)(a.query||"$score"!==n[d].field)&&h.push(n[d]);if(a.query){for(m=!0,d=0,e=h.length;e>d;d++)if("$score"===h[d].field){m=!1;break}m&&h.unshift({field:"$score",direction:"desc"})}else for(d=0,e=h.length;e>d;d++)if("$score"===h[d].field){h.splice(d,1);break}for(k=[],d=0,e=h.length;e>d;d++)k.push("desc"===h[d].direction?-1:1);return i=h.length,i?1===i?(g=h[0].field,j=k[0],function(a,c){return j*b(l(g,a),l(g,c))}):function(a,c){var d,e,f;for(d=0;i>d;d++)if(f=h[d].field,e=k[d]*b(l(f,a),l(f,c)))return e;return 0}:null},a.prototype.prepareSearch=function(a,b){if("object"==typeof a)return a;b=c({},b);var d=b.fields,e=b.sort,g=b.sort_empty;return d&&!f(d)&&(b.fields=[d]),e&&!f(e)&&(b.sort=[e]),g&&!f(g)&&(b.sort_empty=[g]),{options:b,query:String(a||"").toLowerCase(),tokens:this.tokenize(a),total:0,items:[]}},a.prototype.search=function(a,b){var c,d,e,f,g=this;return d=this.prepareSearch(a,b),b=d.options,a=d.query,f=b.score||g.getScoreFunction(d),a.length?g.iterator(g.items,function(a,e){c=f(a),(b.filter===!1||c>0)&&d.items.push({score:c,id:e})}):g.iterator(g.items,function(a,b){d.items.push({score:1,id:b})}),e=g.getSortFunction(d,b),e&&d.items.sort(e),d.total=d.items.length,"number"==typeof b.limit&&(d.items=d.items.slice(0,b.limit)),d};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:b>a?-1:0:(a=h(String(a||"")),b=h(String(b||"")),a>b?1:b>a?-1:0)},c=function(a){var b,c,d,e;for(b=1,c=arguments.length;c>b;b++)if(e=arguments[b])for(d in e)e.hasOwnProperty(d)&&(a[d]=e[d]);return a},d=function(a){return(a+"").replace(/^\s+|\s+$|/g,"")},e=function(a){return(a+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},f=Array.isArray||$&&$.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},g={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎ]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},h=function(){var a,b,c,d,e="",f={};for(c in g)if(g.hasOwnProperty(c))for(d=g[c].substring(2,g[c].length-1),e+=d,a=0,b=d.length;b>a;a++)f[d.charAt(a)]=c;var h=new RegExp("["+e+"]","g");return function(a){return a.replace(h,function(a){return f[a]}).toLowerCase()}}();return a}),function(a,b){"function"==typeof define&&define.amd?define("microplugin",b):"object"==typeof exports?module.exports=b():a.MicroPlugin=b()}(this,function(){var a={};a.mixin=function(a){a.plugins={},a.prototype.initializePlugins=function(a){var c,d,e,f=this,g=[];if(f.plugins={names:[],settings:{},requested:{},loaded:{}},b.isArray(a))for(c=0,d=a.length;d>c;c++)"string"==typeof a[c]?g.push(a[c]):(f.plugins.settings[a[c].name]=a[c].options,g.push(a[c].name));else if(a)for(e in a)a.hasOwnProperty(e)&&(f.plugins.settings[e]=a[e],g.push(e));for(;g.length;)f.require(g.shift())},a.prototype.loadPlugin=function(b){var c=this,d=c.plugins,e=a.plugins[b];if(!a.plugins.hasOwnProperty(b))throw new Error('Unable to find "'+b+'" plugin');d.requested[b]=!0,d.loaded[b]=e.fn.apply(c,[c.plugins.settings[b]||{}]),d.names.push(b)},a.prototype.require=function(a){var b=this,c=b.plugins;if(!b.plugins.loaded.hasOwnProperty(a)){if(c.requested[a])throw new Error('Plugin has circular dependency ("'+a+'")');b.loadPlugin(a)}return c.loaded[a]},a.define=function(b,c){a.plugins[b]={name:b,fn:c}}};var b={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}};return a}),function(a,b){"function"==typeof define&&define.amd?define("selectize",["jquery","sifter","microplugin"],b):"object"==typeof exports?module.exports=b(require("jquery"),require("sifter"),require("microplugin")):a.Selectize=b(a.jQuery,a.Sifter,a.MicroPlugin)}(this,function(a,b,c){"use strict";var d=function(a,b){if("string"!=typeof b||b.length){var c="string"==typeof b?new RegExp(b,"i"):b,d=function(a){var b=0;if(3===a.nodeType){var e=a.data.search(c);if(e>=0&&a.data.length>0){var f=a.data.match(c),g=document.createElement("span");g.className="highlight";var h=a.splitText(e),i=(h.splitText(f[0].length),h.cloneNode(!0));g.appendChild(i),h.parentNode.replaceChild(g,h),b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName))for(var j=0;j<a.childNodes.length;++j)j+=d(a.childNodes[j]);return b};return a.each(function(){d(this)})}},e=function(){};e.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){var c=arguments.length;return 0===c?delete this._events:1===c?delete this._events[a]:(this._events=this._events||{},void(a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)))},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}},e.mixin=function(a){for(var b=["on","off","trigger"],c=0;c<b.length;c++)a.prototype[b[c]]=e.prototype[b[c]]};var f=/Mac/.test(navigator.userAgent),g=65,h=13,i=27,j=37,k=38,l=80,m=39,n=40,o=78,p=8,q=46,r=16,s=f?91:17,t=f?18:17,u=9,v=1,w=2,x=!/android/i.test(window.navigator.userAgent)&&!!document.createElement("form").validity,y=function(a){return"undefined"!=typeof a},z=function(a){return"undefined"==typeof a||null===a?null:"boolean"==typeof a?a?"1":"0":a+""},A=function(a){return(a+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},B=function(a){return(a+"").replace(/\$/g,"$$$$")},C={};C.before=function(a,b,c){var d=a[b];a[b]=function(){return c.apply(a,arguments),d.apply(a,arguments)}},C.after=function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);return c.apply(a,arguments),b}};var D=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},E=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c),c=window.setTimeout(function(){a.apply(d,e)},b)}},F=function(a,b,c){var d,e=a.trigger,f={};a.trigger=function(){var c=arguments[0];return-1===b.indexOf(c)?e.apply(a,arguments):void(f[c]=arguments)},c.apply(a,[]),a.trigger=e;for(d in f)f.hasOwnProperty(d)&&e.apply(a,f[d])},G=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;return b.currentTarget=c,d.apply(this,[b])})},H=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length),b.start=c.text.length-d,b.length=d}return b},I=function(a,b,c){var d,e,f={};if(c)for(d=0,e=c.length;e>d;d++)f[c[d]]=a.css(c[d]);else f=a.css();b.css(f)},J=function(b,c){if(!b)return 0;var d=a("<test>").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).text(b).appendTo("body");I(c,d,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]);var e=d.width();return d.remove(),e},K=function(a){var b=null,c=function(c,d){var e,f,g,h,i,j,k,l;c=c||window.event||{},d=d||{},c.metaKey||c.altKey||(d.force||a.data("grow")!==!1)&&(e=a.val(),c.type&&"keydown"===c.type.toLowerCase()&&(f=c.keyCode,g=f>=97&&122>=f||f>=65&&90>=f||f>=48&&57>=f||32===f,f===q||f===p?(l=H(a[0]),l.length?e=e.substring(0,l.start)+e.substring(l.start+l.length):f===p&&l.start?e=e.substring(0,l.start-1)+e.substring(l.start+1):f===q&&"undefined"!=typeof l.start&&(e=e.substring(0,l.start)+e.substring(l.start+1))):g&&(j=c.shiftKey,k=String.fromCharCode(c.keyCode),k=j?k.toUpperCase():k.toLowerCase(),e+=k)),h=a.attr("placeholder"),!e&&h&&(e=h),i=J(e,a)+4,i!==b&&(b=i,a.width(i),a.triggerHandler("resize")))};a.on("keydown keyup update blur",c),c()},L=function(c,d){var e,f,g,h,i=this;h=c[0],h.selectize=i;var j=window.getComputedStyle&&window.getComputedStyle(h,null);if(g=j?j.getPropertyValue("direction"):h.currentStyle&&h.currentStyle.direction,g=g||c.parents("[dir]:first").attr("dir")||"",a.extend(i,{order:0,settings:d,$input:c,tabIndex:c.attr("tabindex")||"",tagType:"select"===h.tagName.toLowerCase()?v:w,rtl:/rtl/i.test(g),eventNS:".selectize"+ ++L.count,highlightedValue:null,isOpen:!1,isDisabled:!1,isRequired:c.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:null===d.loadThrottle?i.onSearchChange:E(i.onSearchChange,d.loadThrottle)}),i.sifter=new b(this.options,{diacritics:d.diacritics}),i.settings.options){for(e=0,f=i.settings.options.length;f>e;e++)i.registerOption(i.settings.options[e]);delete i.settings.options}if(i.settings.optgroups){for(e=0,f=i.settings.optgroups.length;f>e;e++)i.registerOptionGroup(i.settings.optgroups[e]);delete i.settings.optgroups}i.settings.mode=i.settings.mode||(1===i.settings.maxItems?"single":"multi"),"boolean"!=typeof i.settings.hideSelected&&(i.settings.hideSelected="multi"===i.settings.mode),i.initializePlugins(i.settings.plugins),i.setupCallbacks(),i.setupTemplates(),i.setup()};return e.mixin(L),c.mixin(L),a.extend(L.prototype,{setup:function(){var b,c,d,e,g,h,i,j,k,l=this,m=l.settings,n=l.eventNS,o=a(window),p=a(document),q=l.$input;if(i=l.settings.mode,j=q.attr("class")||"",b=a("<div>").addClass(m.wrapperClass).addClass(j).addClass(i),c=a("<div>").addClass(m.inputClass).addClass("items").appendTo(b),d=a('<input type="text" autocomplete="off" />').appendTo(c).attr("tabindex",q.is(":disabled")?"-1":l.tabIndex),h=a(m.dropdownParent||b),e=a("<div>").addClass(m.dropdownClass).addClass(i).hide().appendTo(h),g=a("<div>").addClass(m.dropdownContentClass).appendTo(e),l.settings.copyClassesToDropdown&&e.addClass(j),b.css({width:q[0].style.width}),l.plugins.names.length&&(k="plugin-"+l.plugins.names.join(" plugin-"),b.addClass(k),e.addClass(k)),(null===m.maxItems||m.maxItems>1)&&l.tagType===v&&q.attr("multiple","multiple"),l.settings.placeholder&&d.attr("placeholder",m.placeholder),!l.settings.splitOn&&l.settings.delimiter){var u=l.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");l.settings.splitOn=new RegExp("\\s*"+u+"+\\s*")}q.attr("autocorrect")&&d.attr("autocorrect",q.attr("autocorrect")),q.attr("autocapitalize")&&d.attr("autocapitalize",q.attr("autocapitalize")),l.$wrapper=b,l.$control=c,l.$control_input=d,l.$dropdown=e,l.$dropdown_content=g,e.on("mouseenter","[data-selectable]",function(){return l.onOptionHover.apply(l,arguments)}),e.on("mousedown click","[data-selectable]",function(){return l.onOptionSelect.apply(l,arguments)}),G(c,"mousedown","*:not(input)",function(){return l.onItemSelect.apply(l,arguments)}),K(d),c.on({mousedown:function(){return l.onMouseDown.apply(l,arguments)},click:function(){return l.onClick.apply(l,arguments)}}),d.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return l.onKeyDown.apply(l,arguments)},keyup:function(){return l.onKeyUp.apply(l,arguments)},keypress:function(){return l.onKeyPress.apply(l,arguments)},resize:function(){l.positionDropdown.apply(l,[])},blur:function(){return l.onBlur.apply(l,arguments)},focus:function(){return l.ignoreBlur=!1,l.onFocus.apply(l,arguments)},paste:function(){return l.onPaste.apply(l,arguments)}}),p.on("keydown"+n,function(a){l.isCmdDown=a[f?"metaKey":"ctrlKey"],l.isCtrlDown=a[f?"altKey":"ctrlKey"],l.isShiftDown=a.shiftKey}),p.on("keyup"+n,function(a){a.keyCode===t&&(l.isCtrlDown=!1),a.keyCode===r&&(l.isShiftDown=!1),a.keyCode===s&&(l.isCmdDown=!1)}),p.on("mousedown"+n,function(a){if(l.isFocused){if(a.target===l.$dropdown[0]||a.target.parentNode===l.$dropdown[0])return!1;l.$control.has(a.target).length||a.target===l.$control[0]||l.blur(a.target)}}),o.on(["scroll"+n,"resize"+n].join(" "),function(){l.isOpen&&l.positionDropdown.apply(l,arguments)}),o.on("mousemove"+n,function(){l.ignoreHover=!1}),this.revertSettings={$children:q.children().detach(),tabindex:q.attr("tabindex")},q.attr("tabindex",-1).hide().after(l.$wrapper),a.isArray(m.items)&&(l.setValue(m.items),delete m.items),x&&q.on("invalid"+n,function(a){a.preventDefault(),l.isInvalid=!0,l.refreshState()}),l.updateOriginalInput(),l.refreshItems(),l.refreshState(),l.updatePlaceholder(),l.isSetup=!0,q.is(":disabled")&&l.disable(),l.on("change",this.onChange),q.data("selectize",l),q.addClass("selectized"),l.trigger("initialize"),m.preload===!0&&l.onSearchChange("")},setupTemplates:function(){var b=this,c=b.settings.labelField,d=b.settings.optgroupLabelField,e={optgroup:function(a){return'<div class="optgroup">'+a.html+"</div>"},optgroup_header:function(a,b){return'<div class="optgroup-header">'+b(a[d])+"</div>"},option:function(a,b){return'<div class="option">'+b(a[c])+"</div>"},item:function(a,b){return'<div class="item">'+b(a[c])+"</div>"},option_create:function(a,b){return'<div class="create">Add <strong>'+b(a.input)+"</strong>&hellip;</div>"}};b.settings.render=a.extend({},e,b.settings.render)},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(a in c)c.hasOwnProperty(a)&&(b=this.settings[c[a]],b&&this.on(a,b))},onClick:function(a){var b=this;b.isFocused||(b.focus(),a.preventDefault())},onMouseDown:function(b){{var c=this,d=b.isDefaultPrevented();a(b.target)}if(c.isFocused){if(b.target!==c.$control_input[0])return"single"===c.settings.mode?c.isOpen?c.close():c.open():d||c.setActiveItem(null),!1}else d||window.setTimeout(function(){c.focus()},0)},onChange:function(){this.$input.trigger("change")},onPaste:function(b){var c=this;c.isFull()||c.isInputHidden||c.isLocked?b.preventDefault():c.settings.splitOn&&setTimeout(function(){for(var b=a.trim(c.$control_input.val()||"").split(c.settings.splitOn),d=0,e=b.length;e>d;d++)c.createItem(b[d])},0)},onKeyPress:function(a){if(this.isLocked)return a&&a.preventDefault();var b=String.fromCharCode(a.keyCode||a.which);return this.settings.create&&"multi"===this.settings.mode&&b===this.settings.delimiter?(this.createItem(),a.preventDefault(),!1):void 0},onKeyDown:function(a){var b=(a.target===this.$control_input[0],this);if(b.isLocked)return void(a.keyCode!==u&&a.preventDefault());switch(a.keyCode){case g:if(b.isCmdDown)return void b.selectAll();break;case i:return void(b.isOpen&&(a.preventDefault(),a.stopPropagation(),b.close()));case o:if(!a.ctrlKey||a.altKey)break;case n:if(!b.isOpen&&b.hasOptions)b.open();else if(b.$activeOption){b.ignoreHover=!0;var c=b.getAdjacentOption(b.$activeOption,1);c.length&&b.setActiveOption(c,!0,!0)}return void a.preventDefault();case l:if(!a.ctrlKey||a.altKey)break;case k:if(b.$activeOption){b.ignoreHover=!0;var d=b.getAdjacentOption(b.$activeOption,-1);d.length&&b.setActiveOption(d,!0,!0)}return void a.preventDefault();case h:return void(b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),a.preventDefault()));case j:return void b.advanceSelection(-1,a);case m:return void b.advanceSelection(1,a);case u:return b.settings.selectOnTab&&b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),b.isFull()||a.preventDefault()),void(b.settings.create&&b.createItem()&&a.preventDefault());case p:case q:return void b.deleteSelection(a)}return!b.isFull()&&!b.isInputHidden||(f?a.metaKey:a.ctrlKey)?void 0:void a.preventDefault()},onKeyUp:function(a){var b=this;if(b.isLocked)return a&&a.preventDefault();var c=b.$control_input.val()||"";b.lastValue!==c&&(b.lastValue=c,b.onSearchChange(c),b.refreshOptions(),b.trigger("type",c))},onSearchChange:function(a){var b=this,c=b.settings.load;c&&(b.loadedSearches.hasOwnProperty(a)||(b.loadedSearches[a]=!0,b.load(function(d){c.apply(b,[a,d])})))},onFocus:function(a){var b=this,c=b.isFocused;return b.isDisabled?(b.blur(),a&&a.preventDefault(),!1):void(b.ignoreFocus||(b.isFocused=!0,"focus"===b.settings.preload&&b.onSearchChange(""),c||b.trigger("focus"),b.$activeItems.length||(b.showInput(),b.setActiveItem(null),b.refreshOptions(!!b.settings.openOnFocus)),b.refreshState()))},onBlur:function(a,b){var c=this;if(c.isFocused&&(c.isFocused=!1,!c.ignoreFocus)){if(!c.ignoreBlur&&document.activeElement===c.$dropdown_content[0])return c.ignoreBlur=!0,void c.onFocus(a);var d=function(){c.close(),c.setTextboxValue(""),c.setActiveItem(null),c.setActiveOption(null),c.setCaret(c.items.length),c.refreshState(),(b||document.body).focus(),c.ignoreFocus=!1,c.trigger("blur")};c.ignoreFocus=!0,c.settings.create&&c.settings.createOnBlur?c.createItem(null,!1,d):d()}},onOptionHover:function(a){this.ignoreHover||this.setActiveOption(a.currentTarget,!1)},onOptionSelect:function(b){var c,d,e=this;b.preventDefault&&(b.preventDefault(),b.stopPropagation()),d=a(b.currentTarget),d.hasClass("create")?e.createItem(null,function(){e.settings.closeAfterSelect&&e.close()}):(c=d.attr("data-value"),"undefined"!=typeof c&&(e.lastQuery=null,e.setTextboxValue(""),e.addItem(c),e.settings.closeAfterSelect?e.close():!e.settings.hideSelected&&b.type&&/mouse/.test(b.type)&&e.setActiveOption(e.getOption(c))))},onItemSelect:function(a){var b=this;b.isLocked||"multi"===b.settings.mode&&(a.preventDefault(),b.setActiveItem(a.currentTarget,a))},load:function(a){var b=this,c=b.$wrapper.addClass(b.settings.loadingClass);b.loading++,a.apply(b,[function(a){b.loading=Math.max(b.loading-1,0),a&&a.length&&(b.addOption(a),b.refreshOptions(b.isFocused&&!b.isInputHidden)),b.loading||c.removeClass(b.settings.loadingClass),b.trigger("load",a)}])},setTextboxValue:function(a){var b=this.$control_input,c=b.val()!==a;c&&(b.val(a).triggerHandler("update"),this.lastValue=a)},getValue:function(){return this.tagType===v&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(a,b){var c=b?[]:["change"];F(this,c,function(){this.clear(b),this.addItems(a,b)})},setActiveItem:function(b,c){var d,e,f,g,h,i,j,k,l=this;if("single"!==l.settings.mode){if(b=a(b),!b.length)return a(l.$activeItems).removeClass("active"),l.$activeItems=[],void(l.isFocused&&l.showInput());if(d=c&&c.type.toLowerCase(),"mousedown"===d&&l.isShiftDown&&l.$activeItems.length){for(k=l.$control.children(".active:last"),g=Array.prototype.indexOf.apply(l.$control[0].childNodes,[k[0]]),h=Array.prototype.indexOf.apply(l.$control[0].childNodes,[b[0]]),g>h&&(j=g,g=h,h=j),e=g;h>=e;e++)i=l.$control[0].childNodes[e],-1===l.$activeItems.indexOf(i)&&(a(i).addClass("active"),l.$activeItems.push(i));c.preventDefault()}else"mousedown"===d&&l.isCtrlDown||"keydown"===d&&this.isShiftDown?b.hasClass("active")?(f=l.$activeItems.indexOf(b[0]),l.$activeItems.splice(f,1),b.removeClass("active")):l.$activeItems.push(b.addClass("active")[0]):(a(l.$activeItems).removeClass("active"),l.$activeItems=[b.addClass("active")[0]]);l.hideInput(),this.isFocused||l.focus()}},setActiveOption:function(b,c,d){var e,f,g,h,i,j=this;j.$activeOption&&j.$activeOption.removeClass("active"),j.$activeOption=null,b=a(b),b.length&&(j.$activeOption=b.addClass("active"),(c||!y(c))&&(e=j.$dropdown_content.height(),f=j.$activeOption.outerHeight(!0),c=j.$dropdown_content.scrollTop()||0,g=j.$activeOption.offset().top-j.$dropdown_content.offset().top+c,h=g,i=g-e+f,g+f>e+c?j.$dropdown_content.stop().animate({scrollTop:i},d?j.settings.scrollDuration:0):c>g&&j.$dropdown_content.stop().animate({scrollTop:h},d?j.settings.scrollDuration:0)))},selectAll:function(){var a=this;"single"!==a.settings.mode&&(a.$activeItems=Array.prototype.slice.apply(a.$control.children(":not(input)").addClass("active")),a.$activeItems.length&&(a.hideInput(),a.close()),a.focus())},hideInput:function(){var a=this;a.setTextboxValue(""),a.$control_input.css({opacity:0,position:"absolute",left:a.rtl?1e4:-1e4}),a.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0}),this.isInputHidden=!1},focus:function(){var a=this;a.isDisabled||(a.ignoreFocus=!0,a.$control_input[0].focus(),window.setTimeout(function(){a.ignoreFocus=!1,a.onFocus()},0))},blur:function(a){this.$control_input[0].blur(),this.onBlur(null,a)},getScoreFunction:function(a){return this.sifter.getScoreFunction(a,this.getSearchOptions())},getSearchOptions:function(){var a=this.settings,b=a.sortField;return"string"==typeof b&&(b=[{field:b}]),{fields:a.searchField,conjunction:a.searchConjunction,sort:b}},search:function(b){var c,d,e,f=this,g=f.settings,h=this.getSearchOptions();if(g.score&&(e=f.settings.score.apply(this,[b]),"function"!=typeof e))throw new Error('Selectize "score" setting must be a function that returns a function');if(b!==f.lastQuery?(f.lastQuery=b,d=f.sifter.search(b,a.extend(h,{score:e})),f.currentResults=d):d=a.extend(!0,{},f.currentResults),g.hideSelected)for(c=d.items.length-1;c>=0;c--)-1!==f.items.indexOf(z(d.items[c].id))&&d.items.splice(c,1);return d},refreshOptions:function(b){var c,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;"undefined"==typeof b&&(b=!0);var t=this,u=a.trim(t.$control_input.val()),v=t.search(u),w=t.$dropdown_content,x=t.$activeOption&&z(t.$activeOption.attr("data-value"));for(g=v.items.length,"number"==typeof t.settings.maxOptions&&(g=Math.min(g,t.settings.maxOptions)),h={},i=[],c=0;g>c;c++)for(j=t.options[v.items[c].id],k=t.render("option",j),l=j[t.settings.optgroupField]||"",m=a.isArray(l)?l:[l],e=0,f=m&&m.length;f>e;e++)l=m[e],t.optgroups.hasOwnProperty(l)||(l=""),h.hasOwnProperty(l)||(h[l]=[],i.push(l)),h[l].push(k);for(this.settings.lockOptgroupOrder&&i.sort(function(a,b){var c=t.optgroups[a].$order||0,d=t.optgroups[b].$order||0;return c-d}),n=[],c=0,g=i.length;g>c;c++)l=i[c],t.optgroups.hasOwnProperty(l)&&h[l].length?(o=t.render("optgroup_header",t.optgroups[l])||"",o+=h[l].join(""),n.push(t.render("optgroup",a.extend({},t.optgroups[l],{html:o})))):n.push(h[l].join(""));if(w.html(n.join("")),t.settings.highlight&&v.query.length&&v.tokens.length)for(c=0,g=v.tokens.length;g>c;c++)d(w,v.tokens[c].regex);if(!t.settings.hideSelected)for(c=0,g=t.items.length;g>c;c++)t.getOption(t.items[c]).addClass("selected");p=t.canCreate(u),p&&(w.prepend(t.render("option_create",{input:u})),s=a(w[0].childNodes[0])),t.hasOptions=v.items.length>0||p,t.hasOptions?(v.items.length>0?(r=x&&t.getOption(x),r&&r.length?q=r:"single"===t.settings.mode&&t.items.length&&(q=t.getOption(t.items[0])),q&&q.length||(q=s&&!t.settings.addPrecedence?t.getAdjacentOption(s,1):w.find("[data-selectable]:first"))):q=s,t.setActiveOption(q),b&&!t.isOpen&&t.open()):(t.setActiveOption(null),b&&t.isOpen&&t.close())},addOption:function(b){var c,d,e,f=this;if(a.isArray(b))for(c=0,d=b.length;d>c;c++)f.addOption(b[c]);else(e=f.registerOption(b))&&(f.userOptions[e]=!0,f.lastQuery=null,f.trigger("option_add",e,b))},registerOption:function(a){var b=z(a[this.settings.valueField]);return!b||this.options.hasOwnProperty(b)?!1:(a.$order=a.$order||++this.order,this.options[b]=a,b)},registerOptionGroup:function(a){var b=z(a[this.settings.optgroupValueField]);return b?(a.$order=a.$order||++this.order,this.optgroups[b]=a,b):!1},addOptionGroup:function(a,b){b[this.settings.optgroupValueField]=a,(a=this.registerOptionGroup(b))&&this.trigger("optgroup_add",a,b)},removeOptionGroup:function(a){this.optgroups.hasOwnProperty(a)&&(delete this.optgroups[a],this.renderCache={},this.trigger("optgroup_remove",a))},clearOptionGroups:function(){this.optgroups={},this.renderCache={},this.trigger("optgroup_clear")},updateOption:function(b,c){var d,e,f,g,h,i,j,k=this;if(b=z(b),f=z(c[k.settings.valueField]),null!==b&&k.options.hasOwnProperty(b)){if("string"!=typeof f)throw new Error("Value must be set in option data");j=k.options[b].$order,f!==b&&(delete k.options[b],g=k.items.indexOf(b),-1!==g&&k.items.splice(g,1,f)),c.$order=c.$order||j,k.options[f]=c,h=k.renderCache.item,i=k.renderCache.option,h&&(delete h[b],delete h[f]),i&&(delete i[b],delete i[f]),-1!==k.items.indexOf(f)&&(d=k.getItem(b),e=a(k.render("item",c)),d.hasClass("active")&&e.addClass("active"),d.replaceWith(e)),k.lastQuery=null,k.isOpen&&k.refreshOptions(!1)}},removeOption:function(a,b){var c=this;a=z(a);var d=c.renderCache.item,e=c.renderCache.option;d&&delete d[a],e&&delete e[a],delete c.userOptions[a],delete c.options[a],c.lastQuery=null,c.trigger("option_remove",a),c.removeItem(a,b)},clearOptions:function(){var a=this;a.loadedSearches={},a.userOptions={},a.renderCache={},a.options=a.sifter.items={},a.lastQuery=null,a.trigger("option_clear"),a.clear()},getOption:function(a){return this.getElementWithValue(a,this.$dropdown_content.find("[data-selectable]"))},getAdjacentOption:function(b,c){var d=this.$dropdown.find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},getElementWithValue:function(b,c){if(b=z(b),"undefined"!=typeof b&&null!==b)for(var d=0,e=c.length;e>d;d++)if(c[d].getAttribute("data-value")===b)return a(c[d]);return a()},getItem:function(a){return this.getElementWithValue(a,this.$control.children())},addItems:function(b,c){for(var d=a.isArray(b)?b:[b],e=0,f=d.length;f>e;e++)this.isPending=f-1>e,this.addItem(d[e],c)},addItem:function(b,c){var d=c?[]:["change"];F(this,d,function(){var d,e,f,g,h,i=this,j=i.settings.mode;return b=z(b),-1!==i.items.indexOf(b)?void("single"===j&&i.close()):void(i.options.hasOwnProperty(b)&&("single"===j&&i.clear(c),"multi"===j&&i.isFull()||(d=a(i.render("item",i.options[b])),h=i.isFull(),i.items.splice(i.caretPos,0,b),i.insertAtCaret(d),(!i.isPending||!h&&i.isFull())&&i.refreshState(),i.isSetup&&(f=i.$dropdown_content.find("[data-selectable]"),i.isPending||(e=i.getOption(b),g=i.getAdjacentOption(e,1).attr("data-value"),i.refreshOptions(i.isFocused&&"single"!==j),g&&i.setActiveOption(i.getOption(g))),!f.length||i.isFull()?i.close():i.positionDropdown(),i.updatePlaceholder(),i.trigger("item_add",b,d),i.updateOriginalInput({silent:c})))))})},removeItem:function(a,b){var c,d,e,f=this;c="object"==typeof a?a:f.getItem(a),a=z(c.attr("data-value")),d=f.items.indexOf(a),-1!==d&&(c.remove(),c.hasClass("active")&&(e=f.$activeItems.indexOf(c[0]),f.$activeItems.splice(e,1)),f.items.splice(d,1),f.lastQuery=null,!f.settings.persist&&f.userOptions.hasOwnProperty(a)&&f.removeOption(a,b),d<f.caretPos&&f.setCaret(f.caretPos-1),f.refreshState(),f.updatePlaceholder(),f.updateOriginalInput({silent:b}),f.positionDropdown(),f.trigger("item_remove",a,c))},createItem:function(b,c){var d=this,e=d.caretPos;b=b||a.trim(d.$control_input.val()||"");var f=arguments[arguments.length-1];if("function"!=typeof f&&(f=function(){}),"boolean"!=typeof c&&(c=!0),!d.canCreate(b))return f(),!1;d.lock();var g="function"==typeof d.settings.create?this.settings.create:function(a){var b={};return b[d.settings.labelField]=a,b[d.settings.valueField]=a,b},h=D(function(a){if(d.unlock(),!a||"object"!=typeof a)return f();var b=z(a[d.settings.valueField]);return"string"!=typeof b?f():(d.setTextboxValue(""),d.addOption(a),d.setCaret(e),d.addItem(b),d.refreshOptions(c&&"single"!==d.settings.mode),void f(a))}),i=g.apply(this,[b,h]);return"undefined"!=typeof i&&h(i),!0},refreshItems:function(){this.lastQuery=null,this.isSetup&&this.addItem(this.items),this.refreshState(),this.updateOriginalInput()},refreshState:function(){var a,b=this;b.isRequired&&(b.items.length&&(b.isInvalid=!1),b.$control_input.prop("required",a)),b.refreshClasses()},refreshClasses:function(){var b=this,c=b.isFull(),d=b.isLocked;b.$wrapper.toggleClass("rtl",b.rtl),b.$control.toggleClass("focus",b.isFocused).toggleClass("disabled",b.isDisabled).toggleClass("required",b.isRequired).toggleClass("invalid",b.isInvalid).toggleClass("locked",d).toggleClass("full",c).toggleClass("not-full",!c).toggleClass("input-active",b.isFocused&&!b.isInputHidden).toggleClass("dropdown-active",b.isOpen).toggleClass("has-options",!a.isEmptyObject(b.options)).toggleClass("has-items",b.items.length>0),b.$control_input.data("grow",!c&&!d)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(a){var b,c,d,e,f=this;if(a=a||{},f.tagType===v){for(d=[],b=0,c=f.items.length;c>b;b++)e=f.options[f.items[b]][f.settings.labelField]||"",d.push('<option value="'+A(f.items[b])+'" selected="selected">'+A(e)+"</option>");d.length||this.$input.attr("multiple")||d.push('<option value="" selected="selected"></option>'),f.$input.html(d.join(""))}else f.$input.val(f.getValue()),f.$input.attr("value",f.$input.val());f.isSetup&&(a.silent||f.trigger("change",f.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update",{force:!0})}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(),a.isOpen=!0,a.refreshState(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",a.$dropdown))},close:function(){var a=this,b=a.isOpen;"single"===a.settings.mode&&a.items.length&&a.hideInput(),a.isOpen=!1,a.$dropdown.hide(),a.setActiveOption(null),a.refreshState(),b&&a.trigger("dropdown_close",a.$dropdown)},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(a){var b=this;b.items.length&&(b.$control.children(":not(input)").remove(),b.items=[],b.lastQuery=null,b.setCaret(0),b.setActiveItem(null),b.updatePlaceholder(),b.updateOriginalInput({silent:a}),b.refreshState(),b.showInput(),b.trigger("clear"))},insertAtCaret:function(b){var c=Math.min(this.caretPos,this.items.length);0===c?this.$control.prepend(b):a(this.$control[0].childNodes[c]).before(b),this.setCaret(c+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&b.keyCode===p?-1:1,f=H(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;d>c;c++)g.push(a(l.$activeItems[c]).attr("data-value"));
3
+ b&&(b.preventDefault(),b.stopPropagation())}else(l.isFocused||"single"===l.settings.mode)&&l.items.length&&(0>e&&0===f.start&&0===f.length?g.push(l.items[l.caretPos-1]):e>0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&l.settings.onDelete.apply(l,[g])===!1)return!1;for("undefined"!=typeof h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h,i=this;0!==a&&(i.rtl&&(a*=-1),c=a>0?"last":"first",d=H(i.$control_input[0]),i.isFocused&&!i.isInputHidden?(f=i.$control_input.val().length,g=0>a?0===d.start&&0===d.length:d.start===f,g&&!f&&i.advanceCaret(a,b)):(h=i.$control.children(".active:"+c),h.length&&(e=i.$control.children(":not(input)").index(h),i.setActiveItem(null),i.setCaret(a>0?e+1:e))))},advanceCaret:function(a,b){var c,d,e=this;0!==a&&(c=a>0?"next":"prev",e.isShiftDown?(d=e.$control_input[c](),d.length&&(e.hideInput(),e.setActiveItem(d),b&&b.preventDefault())):e.setCaret(e.caretPos+a))},setCaret:function(b){var c=this;if(b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b)),!c.isPending){var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;e>d;d++)g=a(f[d]).detach(),b>d?c.$control_input.before(g):c.$control.append(g)}c.caretPos=b},lock:function(){this.close(),this.isLocked=!0,this.refreshState()},unlock:function(){this.isLocked=!1,this.refreshState()},disable:function(){var a=this;a.$input.prop("disabled",!0),a.$control_input.prop("disabled",!0).prop("tabindex",-1),a.isDisabled=!0,a.lock()},enable:function(){var a=this;a.$input.prop("disabled",!1),a.$control_input.prop("disabled",!1).prop("tabindex",a.tabIndex),a.isDisabled=!1,a.unlock()},destroy:function(){var b=this,c=b.eventNS,d=b.revertSettings;b.trigger("destroy"),b.off(),b.$wrapper.remove(),b.$dropdown.remove(),b.$input.html("").append(d.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:d.tabindex}).show(),b.$control_input.removeData("grow"),b.$input.removeData("selectize"),a(window).off(c),a(document).off(c),a(document.body).off(c),delete b.$input[0].selectize},render:function(a,b){var c,d,e="",f=!1,g=this,h=/^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;return("option"===a||"item"===a)&&(c=z(b[g.settings.valueField]),f=!!c),f&&(y(g.renderCache[a])||(g.renderCache[a]={}),g.renderCache[a].hasOwnProperty(c))?g.renderCache[a][c]:(e=g.settings.render[a].apply(this,[b,A]),("option"===a||"option_create"===a)&&(e=e.replace(h,"<$1 data-selectable")),"optgroup"===a&&(d=b[g.settings.optgroupValueField]||"",e=e.replace(h,'<$1 data-group="'+B(A(d))+'"')),("option"===a||"item"===a)&&(e=e.replace(h,'<$1 data-value="'+B(A(c||""))+'"')),f&&(g.renderCache[a][c]=e),e)},clearCache:function(a){var b=this;"undefined"==typeof a?b.renderCache={}:delete b.renderCache[a]},canCreate:function(a){var b=this;if(!b.settings.create)return!1;var c=b.settings.createFilter;return!(!a.length||"function"==typeof c&&!c.apply(b,[a])||"string"==typeof c&&!new RegExp(c).test(a)||c instanceof RegExp&&!c.test(a))}}),L.count=0,L.defaults={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:1e3,maxItems:null,hideSelected:null,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,loadThrottle:300,loadingClass:"loading",dataAttr:"data-data",optgroupField:"optgroup",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"selectize-control",inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,copyClassesToDropdown:!0,render:{}},a.fn.selectize=function(b){var c=a.fn.selectize.defaults,d=a.extend({},c,b),e=d.dataAttr,f=d.labelField,g=d.valueField,h=d.optgroupField,i=d.optgroupLabelField,j=d.optgroupValueField,k=function(b,c){var h,i,j,k,l=b.attr(e);if(l)for(c.options=JSON.parse(l),h=0,i=c.options.length;i>h;h++)c.items.push(c.options[h][g]);else{var m=a.trim(b.val()||"");if(!d.allowEmptyOption&&!m.length)return;for(j=m.split(d.delimiter),h=0,i=j.length;i>h;h++)k={},k[f]=j[h],k[g]=j[h],c.options.push(k);c.items=j}},l=function(b,c){var k,l,m,n,o=c.options,p={},q=function(a){var b=e&&a.attr(e);return"string"==typeof b&&b.length?JSON.parse(b):null},r=function(b,e){b=a(b);var i=z(b.attr("value"));if(i||d.allowEmptyOption)if(p.hasOwnProperty(i)){if(e){var j=p[i][h];j?a.isArray(j)?j.push(e):p[i][h]=[j,e]:p[i][h]=e}}else{var k=q(b)||{};k[f]=k[f]||b.text(),k[g]=k[g]||i,k[h]=k[h]||e,p[i]=k,o.push(k),b.is(":selected")&&c.items.push(i)}},s=function(b){var d,e,f,g,h;for(b=a(b),f=b.attr("label"),f&&(g=q(b)||{},g[i]=f,g[j]=f,c.optgroups.push(g)),h=a("option",b),d=0,e=h.length;e>d;d++)r(h[d],f)};for(c.maxItems=b.attr("multiple")?null:1,n=b.children(),k=0,l=n.length;l>k;k++)m=n[k].tagName.toLowerCase(),"optgroup"===m?s(n[k]):"option"===m&&r(n[k])};return this.each(function(){if(!this.selectize){var e,f=a(this),g=this.tagName.toLowerCase(),h=f.attr("placeholder")||f.attr("data-placeholder");h||d.allowEmptyOption||(h=f.children('option[value=""]').text());var i={placeholder:h,options:[],optgroups:[],items:[]};"select"===g?l(f,i):k(f,i),e=new L(f,a.extend(!0,{},c,i,b))}})},a.fn.selectize.defaults=L.defaults,a.fn.selectize.support={validity:x},L.define("drag_drop",function(){if(!a.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var b=this;b.lock=function(){var a=b.lock;return function(){var c=b.$control.data("sortable");return c&&c.disable(),a.apply(b,arguments)}}(),b.unlock=function(){var a=b.unlock;return function(){var c=b.$control.data("sortable");return c&&c.enable(),a.apply(b,arguments)}}(),b.setup=function(){var c=b.setup;return function(){c.apply(this,arguments);var d=b.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:b.isLocked,start:function(a,b){b.placeholder.css("width",b.helper.css("width")),d.css({overflow:"visible"})},stop:function(){d.css({overflow:"hidden"});var c=b.$activeItems?b.$activeItems.slice():null,e=[];d.children("[data-value]").each(function(){e.push(a(this).attr("data-value"))}),b.setValue(e),b.setActiveItem(c)}})}}()}}),L.define("dropdown_header",function(b){var c=this;b=a.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(a){return'<div class="'+a.headerClass+'"><div class="'+a.titleRowClass+'"><span class="'+a.labelClass+'">'+a.title+'</span><a href="javascript:void(0)" class="'+a.closeClass+'">&times;</a></div></div>'}},b),c.setup=function(){var d=c.setup;return function(){d.apply(c,arguments),c.$dropdown_header=a(b.html(b)),c.$dropdown.prepend(c.$dropdown_header)}}()}),L.define("optgroup_columns",function(b){var c=this;b=a.extend({equalizeWidth:!0,equalizeHeight:!0},b),this.getAdjacentOption=function(b,c){var d=b.closest("[data-group]").find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},this.onKeyDown=function(){var a=c.onKeyDown;return function(b){var d,e,f,g;return!this.isOpen||b.keyCode!==j&&b.keyCode!==m?a.apply(this,arguments):(c.ignoreHover=!0,g=this.$activeOption.closest("[data-group]"),d=g.find("[data-selectable]").index(this.$activeOption),g=b.keyCode===j?g.prev("[data-group]"):g.next("[data-group]"),f=g.find("[data-selectable]"),e=f.eq(Math.min(f.length-1,d)),void(e.length&&this.setActiveOption(e)))}}();var d=function(){var a,b=d.width,c=document;return"undefined"==typeof b&&(a=c.createElement("div"),a.innerHTML='<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>',a=a.firstChild,c.body.appendChild(a),b=d.width=a.offsetWidth-a.clientWidth,c.body.removeChild(a)),b},e=function(){var e,f,g,h,i,j,k;if(k=a("[data-group]",c.$dropdown_content),f=k.length,f&&c.$dropdown_content.width()){if(b.equalizeHeight){for(g=0,e=0;f>e;e++)g=Math.max(g,k.eq(e).height());k.css({height:g})}b.equalizeWidth&&(j=c.$dropdown_content.innerWidth()-d(),h=Math.round(j/f),k.css({width:h}),f>1&&(i=j-h*(f-1),k.eq(f-1).css({width:i})))}};(b.equalizeHeight||b.equalizeWidth)&&(C.after(this,"positionDropdown",e),C.after(this,"refreshOptions",e))}),L.define("remove_button",function(b){if("single"!==this.settings.mode){b=a.extend({label:"&times;",title:"Remove",className:"remove",append:!0},b);var c=this,d='<a href="javascript:void(0)" class="'+b.className+'" tabindex="-1" title="'+A(b.title)+'">'+b.label+"</a>",e=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)};this.setup=function(){var f=c.setup;return function(){if(b.append){var g=c.settings.render.item;c.settings.render.item=function(){return e(g.apply(this,arguments),d)}}f.apply(this,arguments),this.$control.on("click","."+b.className,function(b){if(b.preventDefault(),!c.isLocked){var d=a(b.currentTarget).parent();c.setActiveItem(d),c.deleteSelection()&&c.setCaret(c.items.length)}})}}()}}),L.define("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]},this.onKeyDown=function(){var c=b.onKeyDown;return function(b){var d,e;return b.keyCode===p&&""===this.$control_input.val()&&!this.$activeItems.length&&(d=this.caretPos-1,d>=0&&d<this.items.length)?(e=this.options[this.items[d]],this.deleteSelection(b)&&(this.setTextboxValue(a.text.apply(this,[e])),this.refreshOptions(!0)),void b.preventDefault()):c.apply(this,arguments)}}()}),L});
meta-tag-manager-da_DK.mo → languages/meta-tag-manager-da_DK.mo RENAMED
File without changes
meta-tag-manager-da_DK.po → languages/meta-tag-manager-da_DK.po RENAMED
File without changes
meta-tag-manager-de_DE.mo → languages/meta-tag-manager-de_DE.mo RENAMED
File without changes
meta-tag-manager-de_DE.po → languages/meta-tag-manager-de_DE.po RENAMED
File without changes
meta-tag-manager-es_ES.mo → languages/meta-tag-manager-es_ES.mo RENAMED
File without changes
meta-tag-manager-es_ES.po → languages/meta-tag-manager-es_ES.po RENAMED
File without changes
meta-tag-manager-nl_NL.mo → languages/meta-tag-manager-nl_NL.mo RENAMED
File without changes
meta-tag-manager-nl_NL.po → languages/meta-tag-manager-nl_NL.po RENAMED
File without changes
meta-tag-manager-admin.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
  /*
3
- Copyright (C) 2009 NetWebLogic LLC
4
- Copyright (C) 2009 Martin Lormes
5
 
6
  This program is free software; you can redistribute it and/or modify
7
  it under the terms of the GNU General Public License as published by
@@ -16,133 +15,93 @@ GNU General Public License for more details.
16
  You should have received a copy of the GNU General Public License
17
  along with this program. If not, see <http://www.gnu.org/licenses/>.
18
  */
 
19
 
20
- class MetaTagManagerAdmin {
21
 
22
  /** loads the plugin */
23
- function init() {
24
- // i18n
25
- load_plugin_textdomain ( 'meta-tag-manager', '', basename ( dirname ( __FILE__ ) ) );
26
  // add plugin page to admin menu
27
  add_action ( 'admin_menu', array ( __CLASS__, 'menus' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
  /** adds plugin page to admin menu; put it under 'Settings' */
31
- function menus() {
32
- $page = add_options_page ( __ ( 'Meta Tag Manager', 'meta-tag-manager' ), __ ( 'Meta Tag Manager', 'meta-tag-manager' ), 8, 'mtmverification', array ( __CLASS__, 'options' ) );
33
  // add javascript
34
- add_action ( "admin_print_scripts-$page", array ( __CLASS__, 'scripts' ) );
35
  }
36
 
37
  /** loads javascript on plugin admin page */
38
- function scripts() {
39
- wp_enqueue_script ( 'meta-tag-manager', path_join ( WP_PLUGIN_URL, basename ( dirname ( __FILE__ ) ) . '/mtm_script.js' ), array ('jquery' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  }
41
 
42
- /** the plugin page and all the admin code � old php style spaghetti code */
43
- function options() {
44
- add_option ( 'mtm_data' );
45
- $mtm_data = array ();
46
- if (is_admin () and 1 == $_POST ['mtm_submitted']) {
47
- check_admin_referer ( 'mtmverification' );
48
- for($i = 1; isset ( $_POST ["mtm_{$i}_ref"] ); $i ++) {
49
- $name = trim ( $_POST ["mtm_{$i}_name"] );
50
- $content = trim ( $_POST ["mtm_{$i}_content"] );
51
- $ref = trim ( $_POST ["mtm_{$i}_ref"] );
52
-
53
- if ( get_magic_quotes_gpc() ) {
54
- $name = stripslashes ( $name );
55
- $content = stripslashes ( $content );
56
- $ref = stripslashes ( $ref );
57
- }
58
-
59
- if ('' != $name and '' != $content) {
60
- $meta = array ($name, $content, $ref );
61
- if (isset ( $_POST ["mtm_{$i}_homepageonly"] ))
62
- $meta [3] = 1;
63
- $mtm_data [] = $meta;
64
- }
65
- }
66
- update_option ( 'mtm_data', $mtm_data );
67
- echo '<div id="message" class="updated fade"><p><strong>' . __ ( 'Settings saved.' ) . '</strong></p></div>'; // No textdomain: phrase used in core, too
68
- } else {
69
- $mtm_data = get_option ( 'mtm_data' );
70
  }
71
- ?>
72
- <div class="wrap nwl-plugin">
73
- <h2><?php _e ( 'Meta Tag Manager', 'meta-tag-manager' ); ?></h2>
74
- <div id="poststuff" class="metabox-holder has-right-sidebar">
75
- <div id="side-info-column" class="inner-sidebar">
76
- <div id="categorydiv" class="postbox ">
77
- <div class="handlediv" title="Click to toggle"></div>
78
- <h3 class="hndle">Plugin Information</h3>
79
- <div class="inside">
80
- <p>This plugin was developed by <a href="http://twitter.com/marcussykes">Marcus Sykes</a> @ <a href="http://netweblogic.com">NetWebLogic</a></p>
81
- <p>Please visit <a href="http://netweblogic.com/forums/">our forum</a> for plugin support.</p>
82
- </div>
83
- </div>
84
- <div id="categorydiv" class="postbox ">
85
- <div class="handlediv" title="Click to toggle"></div>
86
- <h3 class="hndle">Special Thanks</h3>
87
- <div class="inside">
88
- <p><a href="http://ten-fingers-and-a-brain.com">Martin Lormes</a> for his contribution.</p>
89
- </div>
90
- </div>
91
- </div>
92
- <div id="post-body">
93
- <div id="post-body-content">
94
- <p><?php _e ( 'Enter a reference name (something to help you remember the meta tag) and then enter the values that you want the meta tag to hold.', 'meta-tag-manager' ); ?></p>
95
- <form method="post" action="">
96
- <?php wp_nonce_field ( 'mtmverification' ); ?>
97
- <table class="form-table">
98
- <thead>
99
- <tr valign="top">
100
- <td><strong><?php _e ( 'Reference Name', 'meta-tag-manager' ); ?></strong></td>
101
- <td><strong><?php _e ( 'Meta Tag', 'meta-tag-manager' ); ?></strong></td>
102
- <td><strong><?php _e ( 'Homepage only', 'meta-tag-manager' ); ?></strong></td>
103
- </tr>
104
- </thead>
105
- <tbody id="mtm_body">
106
- <?php if ( is_array ( $mtm_data ) AND count ( $mtm_data ) > 0 ) : ?>
107
- <?php foreach ( $mtm_data as $name => $meta ) : $count++; ?>
108
- <tr valign="top" id="mtm_<?php echo $count; ?>">
109
- <td scope="row">
110
- <input type="text" name="mtm_<?php echo $count; ?>_ref" value="<?php echo ( isset ( $meta[2] ) ) ? htmlspecialchars ( $meta[2] ) : $name; // $name is for backward compatibility of mtm_data ?>" />
111
- <a href="#" rel="<?php echo $count; ?>"><?php _e ( 'Remove', 'meta-tag-manager' ); ?></a></td>
112
- <td>&lt;meta name="<input type="text" name="mtm_<?php echo $count; ?>_name" value="<?php echo htmlspecialchars ( $meta[0] ); ?>" />" content="<input type="text" name="mtm_<?php echo $count; ?>_content" value="<?php echo htmlspecialchars ( $meta[1] ); ?>" class="regular-text" />" /&gt;</td>
113
- <td><input type="checkbox" name="mtm_<?php echo $count; ?>_homepageonly" value="1"<?php echo ( isset ( $meta[3] ) ) ? ' checked="checked"' : ''; ?> /></td>
114
- </tr>
115
- <?php endforeach; ?>
116
- <?php else : ?>
117
- <tr valign="top" id="mtm_1">
118
- <td scope="row">
119
- <input type="text" name="mtm_1_ref" value="" />
120
- <a href="#" rel="1"><?php _e ( 'Remove', 'meta-tag-manager' ); ?></a></td>
121
- <td>&lt;meta name="<input type="text" name="mtm_1_name" value="" />" content="<input type="text" name="mtm_1_content" value="" class="regular-text" />" /&gt;</td>
122
- <td><input type="checkbox" name="mtm_1_homepageonly" value="1" /></td>
123
- </tr>
124
- <?php endif; ?>
125
- </tbody>
126
- <tfoot>
127
- <tr valign="top">
128
- <td colspan="2"><a href="#" id="mtm_add_tag"><?php _e ( 'Add new tag', 'meta-tag-manager' ); ?></a></td>
129
- </tr>
130
- </tfoot>
131
- </table>
132
- <input type="hidden" name="mtm_submitted" value="1" />
133
- <p class="submit">
134
- <input type="submit" class="button-primary" value="<?php _e('Save Changes'); // No textdomain: phrase used in core, too ?>" />
135
- </p>
136
- </form>
137
- </div>
138
- </div>
139
- </div>
140
- </div>
141
- </div>
142
- <?php
143
  }
144
-
145
  }
146
 
147
  // Start this plugin once all other plugins are fully loaded
148
- add_action( 'init', array('MetaTagManagerAdmin', 'init') );
 
1
  <?php
2
  /*
3
+ Copyright (C) 2016 Marcus Sykes
 
4
 
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
15
  You should have received a copy of the GNU General Public License
16
  along with this program. If not, see <http://www.gnu.org/licenses/>.
17
  */
18
+ if( !defined('ABSPATH') ) exit;
19
 
20
+ class Meta_Tag_Manager_Admin {
21
 
22
  /** loads the plugin */
23
+ public static function init() {
24
+ global $pagenow;
 
25
  // add plugin page to admin menu
26
  add_action ( 'admin_menu', array ( __CLASS__, 'menus' ) );
27
+ if( version_compare(MTM_VERSION, get_option('mtm_version', 0)) ){
28
+ include_once('mtm-update.php');
29
+ }
30
+ if($pagenow == 'post.php' || $pagenow == 'post-new.php' ){ //only needed if editing post
31
+ //meta boxes
32
+ add_action('add_meta_boxes', 'Meta_Tag_Manager_Admin::meta_boxes');
33
+ //Save/Edit actions
34
+ add_filter('wp_insert_post_data', 'Meta_Tag_Manager_Admin::wp_insert_post_data', 100, 2); //validate post meta before saving is done
35
+ }
36
+ }
37
+
38
+ public static function load_plugin_textdomain(){
39
+ load_plugin_textdomain('meta-tag-manager', false, dirname( plugin_basename( __FILE__ ) ).'/languages');
40
  }
41
 
42
  /** adds plugin page to admin menu; put it under 'Settings' */
43
+ public static function menus() {
44
+ $page = add_options_page ( __ ( 'Meta Tag Manager', 'meta-tag-manager' ), __ ( 'Meta Tag Manager', 'meta-tag-manager' ), 'list_users', 'meta-tag-manager', 'Meta_Tag_Manager_Admin::options' );
45
  // add javascript
46
+ add_action ( "admin_enqueue_scripts", 'Meta_Tag_Manager_Admin::scripts', 10, 1 );
47
  }
48
 
49
  /** loads javascript on plugin admin page */
50
+ public static function scripts( $hook ) {
51
+ if( in_array($hook, array('post.php', 'post-new.php', 'settings_page_meta-tag-manager')) ){
52
+ if($hook == 'post.php' || $hook == 'post-new.php' ){
53
+ global $post;
54
+ $mtm_custom = get_option('mtm_custom');
55
+ if( !in_array($post->post_type, $mtm_custom['post-types']) ) return;
56
+ }
57
+ $jquery_deps = array('jquery','jquery-ui-core','jquery-ui-widget','jquery-ui-mouse','jquery-ui-sortable');
58
+ if( defined('WP_DEBUG') && WP_DEBUG ){
59
+ wp_enqueue_script('mtm-selectize', plugins_url('js/selectize.js',__FILE__), $jquery_deps, MTM_VERSION);
60
+ wp_enqueue_script('meta-tag-manager', plugins_url('js/meta-tag-manager.js',__FILE__), $jquery_deps, MTM_VERSION);
61
+ wp_enqueue_style('mtm-selectize', plugins_url('css/selectize.css',__FILE__), array(), MTM_VERSION);
62
+ wp_enqueue_style('meta-tag-manager', plugins_url('css/meta-tag-manager.css',__FILE__), array(), MTM_VERSION);
63
+ }else{
64
+ wp_enqueue_script('mtm-selectize', plugins_url('js/selectize.min.js',__FILE__), $jquery_deps, MTM_VERSION);
65
+ wp_enqueue_script('meta-tag-manager', plugins_url('js/meta-tag-manager.js',__FILE__), $jquery_deps, MTM_VERSION);
66
+ wp_enqueue_style('meta-tag-manager', plugins_url('css/meta-tag-manager.min.css',__FILE__), array(), MTM_VERSION);
67
+ }
68
+ }
69
+ }
70
+
71
+ public static function meta_boxes(){
72
+ global $post;
73
+ //no need to proceed if we're not dealing with posts we're set to add meta
74
+ $mtm_custom = get_option('mtm_custom');
75
+ add_meta_box('meta-tag-manager', __('Meta Tag Manager','meta-tag-manager'), 'Meta_Tag_Manager_Admin::post_meta_box', $mtm_custom['post-types'], 'normal','low');
76
  }
77
 
78
+ public static function post_meta_box(){
79
+ global $post;
80
+ //output builder
81
+ include('mtm-builder.php');
82
+ echo MTM_Builder::output(Meta_Tag_Manager::get_post_data($post->ID), array('context'=>false));
83
+ }
84
+
85
+ public static function wp_insert_post_data($data, $postarr){
86
+ $post_type = $data['post_type'];
87
+ $post_ID = !empty($postarr['ID']) ? $postarr['ID'] : false;
88
+ $mtm_custom = get_option('mtm_custom');
89
+ //get posted meta tag data and save it to CPT meta
90
+ if( $post_ID && !empty($mtm_custom['post-types']) && in_array($post_type, $mtm_custom['post-types']) ){
91
+ include_once('mtm-builder.php');
92
+ $mtm_data = MTM_Builder::get_post(array('context'=>false));
93
+ if( !empty($mtm_data) ) update_post_meta($post_ID, 'mtm_data', $mtm_data);
 
 
 
 
 
 
 
 
 
 
 
 
94
  }
95
+ return $data;
96
+ }
97
+
98
+ /** the plugin options page */
99
+ public static function options() {
100
+ include_once('mtm-builder.php');
101
+ include('mtm-admin-settings.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
 
103
  }
104
 
105
  // Start this plugin once all other plugins are fully loaded
106
+ add_action( 'init', array('Meta_Tag_Manager_Admin', 'init') );
107
+ add_action('plugins_loaded', 'Meta_Tag_Manager_Admin::load_plugin_textdomain');
meta-tag-manager.php CHANGED
@@ -1,15 +1,15 @@
1
  <?php
2
  /*
3
  Plugin Name: Meta Tag Manager
4
- Plugin URI: http://netweblogic.com/wordpress/plugins/meta-tag-manager/
5
- Description: A simple plugin to manage meta tags that appear on all your pages. This can be used for verifiying google, yahoo, and more.
6
- Author: NetWebLogic LLC
7
- Version: 1.2
8
- Author URI: http://netweblogic.com/
9
  Text Domain: meta-tag-manager
10
  */
11
  /*
12
- Copyright (C) 2010 NetWebLogic LLC
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
@@ -24,39 +24,143 @@ GNU General Public License for more details.
24
  You should have received a copy of the GNU General Public License
25
  along with this program. If not, see <http://www.gnu.org/licenses/>.
26
  */
 
27
 
28
- class MetaTagManager {
 
 
29
  /** loads the plugin */
30
- function init() {
31
- add_action ( 'wp_head', array ( __CLASS__, 'head' ) );
 
 
 
 
 
 
32
  }
33
 
34
  /** puts the meta tags in the head */
35
- function head() {
36
  //If options form has been submitted, create a $_POST value that will be saved on databse
37
- $mtm_data = get_option('mtm_data');
38
- ?>
39
- <!-- Meta Manager Start -->
40
- <?php
41
- if(is_array($mtm_data)){
42
- foreach( $mtm_data as $meta){
43
- if (! isset ( $meta [3] ) or (1 != $meta [3]) or (is_home () and 'posts' == get_option ( 'show_on_front' )) or is_front_page ()) {
44
- $name = wp_specialchars ( $meta [0], 1 );
45
- $content = wp_specialchars ( $meta [1], 1 );
46
- echo "<meta name=\"$name\" content=\"$content\" />\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
 
 
48
  }
49
  }
50
- ?>
51
- <!-- Meta Manager End -->
52
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
  }
 
 
55
 
56
- // Include admin backend if needed
57
- if ( is_admin() ) {
58
- require_once ( 'meta-tag-manager-admin.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
-
61
- // Start this plugin once all other plugins are fully loaded
62
- add_action( 'init', array('MetaTagManager', 'init') );
 
 
 
 
 
 
 
 
1
  <?php
2
  /*
3
  Plugin Name: Meta Tag Manager
4
+ Plugin URI: https://wordpress.org/plugins/meta-tag-manager/
5
+ Description: A simple plugin to manage meta tags that appear on aread of your site or individual posts. This can be used for verifiying google, yahoo, and more.
6
+ Author: Marcus Sykes
7
+ Version: 2.0
8
+ Author URI: http://msyk.es/
9
  Text Domain: meta-tag-manager
10
  */
11
  /*
12
+ Copyright (C) 2016 Marcus Sykes
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
24
  You should have received a copy of the GNU General Public License
25
  along with this program. If not, see <http://www.gnu.org/licenses/>.
26
  */
27
+ if( !defined('ABSPATH') ) exit;
28
 
29
+ define('MTM_VERSION', '2.0');
30
+
31
+ class Meta_Tag_Manager {
32
  /** loads the plugin */
33
+ public static function init() {
34
+ //include MTM_Tag class
35
+ include('mtm-tag.php');
36
+ // Include admin backend if needed
37
+ if ( is_admin() ) {
38
+ require_once ( 'meta-tag-manager-admin.php' );
39
+ }
40
+ add_action ('wp_head', 'Meta_Tag_Manager::head', 1);
41
  }
42
 
43
  /** puts the meta tags in the head */
44
+ public static function head() {
45
  //If options form has been submitted, create a $_POST value that will be saved on databse
46
+ $meta_tags = array();
47
+ //check global tags and filter out ones we'll show for this page
48
+ foreach( self::get_data() as $tag ){
49
+ if( !empty($tag->context) ){ //if empty, we assume it's meant to be output everywhere
50
+ foreach( $tag->context as $context ){
51
+ if( $context == 'home' && is_home() ){
52
+ $meta_tags[] = $tag;
53
+ continue; //match found, quit the loop
54
+ }else{
55
+ //check post types and taxonomies
56
+ if( preg_match('/^post-type_/', $context) ){
57
+ $post_type = str_replace('post-type_', '', $context);
58
+ if( is_single() && get_post_type() == $post_type ){
59
+ $meta_tags[] = $tag;
60
+ }
61
+ continue; //match found, quit the loop
62
+ }elseif( preg_match('/^taxonomy_/', $context) ){
63
+ $taxonomy = str_replace('taxonomy_', '', $context);
64
+ if( is_tax( $taxonomy ) || ($taxonomy == 'category' && is_category()) || ($taxonomy == 'post_tag' && is_tag()) ){
65
+ $meta_tags[] = $tag;
66
+ }
67
+ continue; //match found, quit the loop
68
+ }
69
+ }
70
+ }
71
+ }else{
72
+ $meta_tags[] = $tag;
73
+ }
74
+ }
75
+ //check individual post in case we have specific post meta tags to show
76
+ if( is_single() || is_page() ){
77
+ $mtm_custom = get_option('mtm_custom');
78
+ if( !empty($mtm_custom['post-types']) && in_array(get_post_type(), $mtm_custom['post-types']) ){
79
+ $meta_tags = array_merge($meta_tags, self::get_post_data());
80
+ }
81
+ }
82
+ //output the filtered out tags that pass validation
83
+ if( !empty($meta_tags) ){
84
+ //add as keys to prevent duplicates
85
+ $meta_tag_strings = array();
86
+ foreach( $meta_tags as $tag ){
87
+ //only output valid keys
88
+ if( $tag->is_valid() ){
89
+ $meta_tag_strings[$tag->output()] = 1;
90
+ }
91
+ }
92
+ //output tags if there are any
93
+ if( !empty($meta_tag_strings) ){
94
+ echo "\r\n\t".'<!-- Meta Tag Manager -->';
95
+ foreach( $meta_tag_strings as $tag_string => $v ){
96
+ echo "\r\n\t".$tag_string;
97
  }
98
+ echo "\r\n\t".'<!-- / Meta Tag Manager -->';
99
+ echo "\r\n";
100
  }
101
  }
102
+ }
103
+
104
+ public static function get_data(){
105
+ $mtm_data = get_option('mtm_data');
106
+ $meta_tags = array();
107
+ if( is_array($mtm_data) ){
108
+ foreach( $mtm_data as $meta_tag_data ){
109
+ $meta_tags[] = new MTM_Tag($meta_tag_data);
110
+ }
111
+ }
112
+ return $meta_tags;
113
+ }
114
+
115
+ public static function get_post_data( $post_id = false ){
116
+ if( empty($post_id) ) $post_id = get_the_ID();
117
+ $meta_tag_data = maybe_unserialize(get_post_meta($post_id, 'mtm_data', true));
118
+ $meta_tags = array();
119
+ if( is_array($meta_tag_data) ){
120
+ foreach( $meta_tag_data as $tag_data ){
121
+ $meta_tags[] = new MTM_Tag($tag_data);
122
+ }
123
+ }
124
+ return $meta_tags;
125
  }
126
  }
127
+ // Start this plugin once all other plugins are fully loaded
128
+ add_action( 'plugins_loaded', array('Meta_Tag_Manager', 'init'), 100 );
129
 
130
+ // FREEMIUS INSIGHTS integration
131
+ function meta_tag_manager_freemius() {
132
+ global $meta_tag_manager_freemius;
133
+ if ( ! isset( $meta_tag_manager_freemius ) ) {
134
+ // Include Freemius SDK.
135
+ require_once dirname(__FILE__) . '/freemius/start.php';
136
+ $meta_tag_manager_freemius = fs_dynamic_init( array(
137
+ 'id' => '264',
138
+ 'slug' => 'meta-tag-manager',
139
+ 'public_key' => 'pk_07d443985f85078e1d30b59ac31b3',
140
+ 'is_premium' => false,
141
+ 'has_addons' => false,
142
+ 'has_paid_plans' => false,
143
+ 'menu' => array(
144
+ 'slug' => 'meta-tag-manager',
145
+ 'account' => false,
146
+ 'contact' => false,
147
+ 'support' => false,
148
+ 'parent' => array(
149
+ 'slug' => 'options-general.php',
150
+ ),
151
+ ),
152
+ ));
153
+ }
154
+ return $meta_tag_manager_freemius;
155
  }
156
+ // Init Freemius.
157
+ $mtm_freemius_strings = array(
158
+ 'you-are-step-away' => __( 'Welcome to the new and improved Meta Tag Manager 2. %s', 'meta-tag-manager' ),
159
+ 'activate-x-now' => __('Start setting it up!', 'meta-tag-manager'),
160
+ 'optin-x-now' => __( 'Check it out!', 'meta-tag-manager' ),
161
+ 'connect-message' => '<br />'. sprintf(__( 'Please help us improve %s by allowing us to collect some information about your site, which is sent to %s.', 'meta-tag-manager' ), '<b>'.__('Meta Tag Manager','meta-tag-manager').'</b>', '<a href="http://freemius.com" target="_blank">freemius.com</a>').
162
+ '<br /><br /><b>' . __('This is totally optional and you can skip this step below!', 'meta-tag-manager').'</b>'
163
+ );
164
+ $mtm_freemius_strings['connect-message_on-update'] = $mtm_freemius_strings['connect-message'];
165
+ $mtm_freemius_strings['few-plugin-tweaks'] = $mtm_freemius_strings['you-are-step-away'];
166
+ meta_tag_manager_freemius()->override_i18n($mtm_freemius_strings);
meta-tag-manager.pot DELETED
@@ -1,64 +0,0 @@
1
- # Language File for 'Meta Tag Manager' (Wordpress Plugin).
2
- # Copyright (C) 2008 NetWebLogic LLC
3
- # Copyright (c) 2009 Martin Lormes <martinhh@gmail.com>
4
- # This file is distributed under the same license as the meta-tag-manager package.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: meta-tag-manager 0.5.2\n"
10
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/meta-tag-manager\n"
11
- "POT-Creation-Date: 2009-09-21 15:06+0000\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "MIME-Version: 1.0\n"
16
- "Content-Type: text/plain; charset=CHARSET\n"
17
- "Content-Transfer-Encoding: 8bit\n"
18
-
19
- #. #-#-#-#-# plugin.pot (meta-tag-manager 0.5.1) #-#-#-#-#
20
- #. Plugin Name of an extension
21
- #: meta-tag-manager-admin.php:11 meta-tag-manager-admin.php:49
22
- msgid "Meta Tag Manager"
23
- msgstr ""
24
-
25
- #: meta-tag-manager-admin.php:50
26
- msgid "Enter a reference name (something to help you remember the meta tag) and then enter the values that you want the meta tag to hold."
27
- msgstr ""
28
-
29
- #: meta-tag-manager-admin.php:56
30
- msgid "Reference Name"
31
- msgstr ""
32
-
33
- #: meta-tag-manager-admin.php:57
34
- msgid "Meta Tag"
35
- msgstr ""
36
-
37
- #: meta-tag-manager-admin.php:58
38
- msgid "Homepage only"
39
- msgstr ""
40
-
41
- #: meta-tag-manager-admin.php:67 meta-tag-manager-admin.php:76
42
- msgid "Remove"
43
- msgstr ""
44
-
45
- #: meta-tag-manager-admin.php:84
46
- msgid "Add new tag"
47
- msgstr ""
48
-
49
- #. Plugin URI of an extension
50
- msgid "http://netweblogic.com/wordpress/plugins/meta-tag-manager/"
51
- msgstr ""
52
-
53
- #. Description of an extension
54
- msgid ""
55
- "A simple plugin to manage meta tags that appear on all your pages. This can be used for verifiying google, yahoo, and more."
56
- msgstr ""
57
-
58
- #. Author of an extension
59
- msgid "NetWebLogic LLC"
60
- msgstr ""
61
-
62
- #. Author URI of an extension
63
- msgid "http://netweblogic.com/"
64
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
mtm-admin-settings.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( !defined('ABSPATH') ) exit;
3
+
4
+ $count = 0;
5
+ if (is_admin () and !empty($_REQUEST['mtm_nonce']) && wp_verify_nonce($_REQUEST['mtm_nonce'], 'mtm_options_submitted') ) {
6
+ $mtm_data = MTM_Builder::get_post();
7
+ update_option ( 'mtm_data', $mtm_data );
8
+ //quickly sanitize the post type custom data and save
9
+ $mtm_custom = array('post-types'=>array());
10
+ if( !empty($_REQUEST['mtm-post-types']) ){
11
+ $post_types = get_post_types(array('public'=>true), 'names');
12
+ foreach( $_REQUEST['mtm-post-types'] as $post_type ){
13
+ if( in_array($post_type, $post_types) ){
14
+ $mtm_custom['post-types'][] = $post_type;
15
+ }
16
+ }
17
+ }
18
+ update_option('mtm_custom', $mtm_custom);
19
+ echo '<div id="message" class="updated fade"><p><strong>' . __ ( 'Settings saved.' ) . '</strong></p></div>'; // No textdomain: phrase used in core, too
20
+ } else {
21
+ $mtm_custom = get_option('mtm_custom', array('post-type'=>array()));
22
+ }
23
+ ?>
24
+ <script type="text/javascript" charset="utf-8"><?php include('js/meta-tag-manager-settings.js'); ?></script>
25
+ <div class="wrap tabs-active">
26
+ <h1><?php esc_html_e( 'Meta Tag Manager', 'meta-tag-manager' ); ?></h1>
27
+ <h2 class="nav-tab-wrapper">
28
+ <a href="#builder" id="mtm-menu-builder" class="nav-tab nav-tab-active"><?php esc_html_e('Custom Meta Tags','meta-tag-manager'); ?></a>
29
+ <a href="#general" id="mtm-menu-general" class="nav-tab"><?php esc_html_e('General Options','meta-tag-manager'); ?></a>
30
+ </h2>
31
+ <div id="poststuff">
32
+ <div id="post-body" class="metabox-holder columns-2 mtm-settings">
33
+ <div id="postbox-container-2" class="postbox-container">
34
+ <form action="" method="post">
35
+ <?php wp_nonce_field('mtm_options_submitted', 'mtm_nonce'); ?>
36
+ <div class="mtm-menu-general mtm-menu-group" style="display:none;">
37
+ <div id="mtm-post-types" class="postbox mtm-post-types">
38
+ <h2 class="hndle"><?php esc_html_e('Post Type Support', 'meta-tag-manager'); ?></h2>
39
+ <div class="inside">
40
+ <p><?php esc_html_e('Enable the meta tag builder on the edit pages of your selected post types below. This will allow you to create specific post types for specific posts on your site.', 'meta-tag-manager'); ?></p>
41
+ <?php
42
+ //Post Types
43
+ $post_type_options = array();
44
+ foreach( get_post_types(array('public'=>true), 'objects') as $post_type){
45
+ $post_type_options[$post_type->labels->name] = $post_type->name;
46
+ }
47
+ ?>
48
+ <select name="mtm-post-types[]" class="mtm-post-types-select" multiple>
49
+ <option value=""><?php esc_html_e('choose one or more post types', 'meta-tag-manager'); ?></option>
50
+ <?php
51
+ echo MTM_Builder::output_select_options($post_type_options, $mtm_custom['post-types']);
52
+ ?>
53
+ </select>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ <div class="mtm-menu-builder mtm-menu-group">
58
+ <p><?php esc_html_e('Use the meta tag builder to create meta tags which will be used on your site. You can choose what kind of meta tag to display, as well as where to display them such as on all your pages, just the home page or specific post types and taxonomies.', 'meta-tag-manager'); ?></p>
59
+ <p><?php esc_html_e('You can also enter a reference name at the top of each field card (something to help you remember the meta tag) and then enter the values below it that you want the meta tag to hold.', 'meta-tag-manager'); ?></p>
60
+ <p><?php esc_html_e('For adding meta tags to specific post types, please click on the \'General Options\' tab above.', 'meta-tag-manager'); ?></p>
61
+ <?php MTM_Builder::output(Meta_Tag_Manager::get_data(), array('context'=>true, 'reference'=>true)); ?>
62
+ </div>
63
+ <div class="mtm-actions">
64
+ <button type="submit" class="button-primary"><?php esc_html_e('Save Changes','meta-tag-manager'); ?></button>
65
+ </div>
66
+ </form>
67
+ </div>
68
+ <div id="postbox-container-1" class="postbox-container">
69
+ <div id="mtm-plugin-info" class="postbox ">
70
+ <button type="button" class="handlediv button-link"
71
+ aria-expanded="true">
72
+ <span class="screen-reader-text"><?php echo sprintf(esc_html__('Toggle panel: %s'), esc_html__('About This Plugin','meta-tag-manager')); ?></span>
73
+ <span class="toggle-indicator" aria-hidden="true"></span>
74
+ </button>
75
+ <h2 class="hndle ui-sortable-handle">
76
+ <span><?php esc_html_e('About This Plugin','meta-tag-manager'); ?></span>
77
+ </h2>
78
+ <div class="inside">
79
+ <p>
80
+ <?php echo sprintf(esc_html__('This plugin was developed by %s.', 'meta-tag-manager'), '<a href="http://msyk.es">Marcus Sykes</a>'); ?>
81
+ </p>
82
+ <p style="color:green; font-weight:bold;">
83
+ <?php
84
+ echo sprintf(esc_html__('Please leave us a %s review on %s to show your support and help us keep making this plugin better!','meta-tag-manager'),
85
+ '<a href="http://wordpress.org/support/view/plugin-reviews/meta-tag-manager?filter=5">★★★★★</a>',
86
+ '<a href="https://wordpress.org/plugins/meta-tag-manager/">WordPress.org</a>'
87
+ );
88
+ ?>
89
+ </p>
90
+ </div>
91
+ </div>
92
+ <div id="mtm-plugin-support" class="postbox ">
93
+ <button type="button" class="handlediv button-link"
94
+ aria-expanded="true">
95
+ <span class="screen-reader-text"><?php echo sprintf(esc_html__('Toggle panel: %s'), esc_html__('Need Help?','meta-tag-manager')); ?></span>
96
+ <span class="toggle-indicator" aria-hidden="true"></span>
97
+ </button>
98
+ <h2 class="hndle ui-sortable-handle">
99
+ <span><?php esc_html_e('Need Help?','meta-tag-manager'); ?></span>
100
+ </h2>
101
+ <div class="inside">
102
+ <p>
103
+ <?php echo sprintf(esc_html__('Please visit our %s if you have any questions.', 'meta-tag-manager'),
104
+ '<a href="http://wordpress.org/support/plugin/meta-tag-manager/">'.esc_html__('Support Forum','meta-tag-manager').'</a>'); ?>
105
+ </p>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ </div><!-- #post-body -->
110
+ </div><!-- #poststuff -->
111
+ </div>
mtm-builder.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( !defined('ABSPATH') ) exit;
3
+
4
+ include_once('mtm-tag-admin.php'); //extend MTM_Tag for admin purposes
5
+ class MTM_Builder {
6
+
7
+ public static $context_options = array();
8
+
9
+ public static function get_post( $args = array() ){
10
+ $mtm_data = array();
11
+ if( !empty($_REQUEST['mtm-fields']) ){
12
+ foreach( $_REQUEST['mtm-fields'] as $k => $posted_tag ){
13
+ if( $k === 't' ) continue; //skip the template
14
+ $tag = new MTM_Tag_Admin($posted_tag);
15
+ $mtm_data[] = $tag->to_array();
16
+ }
17
+ }
18
+ return $mtm_data;
19
+ }
20
+
21
+ public static function output($meta_tags, $args = array() ){
22
+ ?>
23
+ <div class="mtm-builder">
24
+ <div class="mtm-fields<?php if( empty($args['context']) ): ?> no-context<?php endif; ?><?php if( empty($args['reference']) ): ?> no-reference<?php endif; ?>">
25
+ <?php
26
+ $i = 0;
27
+ foreach( $meta_tags as $tag ){
28
+ self::output_field($i, $tag, $args);
29
+ $i++;
30
+ }
31
+ $placeholder_style = ($i != 0) ? ' style="display:none;"':'';
32
+ echo '<div class="mtm-field-placeholder mtm-add-field"'.$placeholder_style.'>'.esc_html__('No tags added yet, click here or on the button below to add one!','meta-tag-manager').'</div>';
33
+ ?>
34
+ </div>
35
+ <div class="mtm-field-template">
36
+ <?php self::output_field('t', new MTM_Tag(array()), $args); ?>
37
+ </div>
38
+ <div class="mtm-field-type-templates" style="display:none; visibility:hidden;">
39
+ <?php foreach( MTM_Tag::get_types() as $type ): $type_values = MTM_Tag_Admin::get_type_values($type); ?>
40
+ <?php if( !empty($type_values) ): ?>
41
+ <select name="mtm-field-type-template" class="mtm-field-input-tag-<?php echo esc_attr($type); ?> mtm-field-input-tag-value">
42
+ <option value=""><?php esc_html_e('choose a value or type in a custom one...', 'meta-tag-manager'); ?></option>
43
+ <?php echo self::output_select_options($type_values); ?>
44
+ </select>
45
+ <?php elseif( $type == 'charset' ): ?>
46
+ <input name="mtm-field-type-template" type="text" value="<?php bloginfo( 'charset' ); ?>" class="mtm-field-input-tag-<?php echo esc_attr($type); ?> mtm-field-input-tag-value" />
47
+ <?php else: ?>
48
+ <input name="mtm-field-type-template" type="text" class="mtm-field-input-tag-<?php echo esc_attr($type); ?> mtm-field-input-tag-value" />
49
+ <?php endif; ?>
50
+ <?php endforeach; ?>
51
+ </div>
52
+ <button type="button" class="button-secondary mtm-add-field"><span class="dashicons dashicons-plus"></span> <?php esc_html_e('Add Meta Tag','meta-tag-manager'); ?></button>
53
+ </div>
54
+ <?php
55
+ }
56
+
57
+ public static function output_field( $i = '', $tag, $args = array() ){
58
+ ?>
59
+ <div class="mtm-field">
60
+ <div class="mtm-field-header">
61
+ <div class="mtm-field-header-toggle"></div>
62
+ <div class="mtm-col-sort"><span class="dashicons dashicons-sort"></span></div>
63
+ <div class="mtm-field-title">
64
+ <?php if( !empty($args['reference']) ): ?>
65
+ <div class="mtm-meta-reference">
66
+ <?php $reference = empty($tag->reference) ? __('Custom Meta Tag','meta-tag-manager') : $tag->reference; ?>
67
+ <span class="mtm-meta-reference-value" title="<?php esc_attr_e('Custom Meta Tag Reference','meta-tag-manager'); ?>"><?php echo esc_html($reference); ?></span>
68
+ <label class="mtm-field-input-reference">
69
+ <span class="screen-reader-text" ><?php esc_html_e('Reference Name','meta-tag-manager'); ?></span>
70
+ <input type="text" name="mtm-fields[<?php echo esc_attr($i); ?>][reference]" value="<?php echo esc_attr($tag->reference); ?>" placeholder="<?php esc_html_e('optional reference name', 'meta-tag-manager'); ?>" class="mtm-field-input-tag-reference" />
71
+ </label>
72
+ <?php if( !empty($args['context']) ): ?>
73
+ <span class="mtm-meta-context">
74
+ <span class="dashicons dashicons-admin-page"></span>
75
+ <span class="mtm-meta-context-values">
76
+ <?php
77
+ $context_value = empty($tag->context) ? array('all') : $tag->context;
78
+ $display_contexts = array();
79
+ foreach( self::get_context_options() as $context_label => $context_option ){
80
+ if( is_array($context_option) ){
81
+ foreach( $context_option as $context_option_label => $context_option_value )
82
+ if( in_array($context_option_value, $context_value) ){
83
+ $display_contexts[] = $context_option_label;
84
+ }
85
+ }else{
86
+ if( in_array($context_option, $context_value) ){
87
+ $display_contexts[] = $context_label;
88
+ }
89
+ }
90
+ }
91
+ echo implode(', ', $display_contexts);
92
+ ?>
93
+ </span>
94
+ </span>
95
+ <?php endif; ?>
96
+ </div>
97
+ <?php endif; ?>
98
+ <code>
99
+ <span class="mtm-meta-closing-tag">&lt;meta</span>
100
+ <span class="mtm-meta-type">
101
+ <?php
102
+ $type_val = !empty($tag->value) ? $tag->value:'...';
103
+ ?>
104
+ <span class="mtm-meta-type-att"><?php echo esc_html($tag->type); ?></span>="<span class="mtm-meta-type-val"><?php echo esc_html($type_val); ?></span>"
105
+ </span>
106
+ <span class="mtm-meta-content<?php if($tag->type == 'charset') echo ' hidden'; ?>">
107
+ <?php $content_val = !empty($tag->content) ? $tag->content:'...' ?>
108
+ content="<span class="mtm-meta-content-value"><?php echo esc_html($content_val); ?></span>"
109
+ </span>
110
+ <span class="mtm-meta-closing-tag">/&gt;</span>
111
+ </code>
112
+ <a class="mtm-field-remove" title="<?php esc_attr_e('Remove Meta Tag','meta-tag-manager'); ?>"><span class="dashicons dashicons-trash"></span></a>
113
+ </div>
114
+ </div>
115
+ <div class="mtm-field-data">
116
+ <div class="mtm-field-input mtm-field-type-type">
117
+ <label>
118
+ <span class="mtm-field-input-label"><?php esc_html_e('Tag Type','meta-tag-manager'); ?></span>
119
+ <select name="mtm-fields[<?php echo esc_attr($i); ?>][type]" class="mtm-field-input-tag-type">
120
+ <option value=""><?php esc_html_e('choose a tag type', 'meta-tag-manager'); ?></option>
121
+ <?php
122
+ $type_options = MTM_Tag::get_types();
123
+ echo self::output_select_options($type_options, $tag->type);
124
+ ?>
125
+ </select>
126
+ </label>
127
+ </div>
128
+ <div class="mtm-field-input mtm-field-type-value">
129
+ <label>
130
+ <span class="mtm-field-input-label"><?php echo sprintf(esc_html__('%s Value','meta-tag-manager'), '<em>'.esc_html($tag->type).'</em>'); ?></span>
131
+ <?php $type_values = MTM_Tag_Admin::get_type_values($tag->type); ?>
132
+ <?php if( !empty($type_values) ): ?>
133
+ <select name="mtm-fields[<?php echo esc_attr($i); ?>][value]" class="mtm-field-input-tag-<?php echo esc_attr($tag->type); ?> mtm-field-input-tag-value mtm-field-input-selectize">
134
+ <option value=""><?php esc_html_e('choose a value or type in a custom one...', 'meta-tag-manager'); ?></option>
135
+ <?php echo self::output_select_options($type_values, $tag->value); ?>
136
+ </select>
137
+ <?php else: ?>
138
+ <input name="mtm-fields[<?php echo esc_attr($i); ?>][value]" type="text" class="mtm-field-input-<?php echo esc_attr($type); ?> mtm-field-input-tag-value" value="<?php echo esc_attr($tag->value); ?>" />
139
+ <?php endif; ?>
140
+ </label>
141
+ </div>
142
+ <div class="mtm-field-input mtm-field-type-content mtm-field-attr">
143
+ <label>
144
+ <span class="mtm-field-input-label"><?php echo sprintf(esc_html__('%s Attribute','meta-tag-manager'), '<em>content</em>'); ?></span>
145
+ <input type="text" name="mtm-fields[<?php echo esc_attr($i); ?>][content]" value="<?php echo esc_attr($tag->content); ?>" placeholder="<?php esc_attr_e('add content corresponding to the chosen tag type', 'meta-tag-manager'); ?>" class="mtm-field-input-tag-content" />
146
+ </label>
147
+ </div>
148
+ <?php if( !empty($args['context']) ): ?>
149
+ <div class="mtm-field-input mtm-field-input-context">
150
+ <label>
151
+ <span class="mtm-field-input-label"><?php echo esc_html_e('Where to display this tag','meta-tag-manager'); ?></span>
152
+ <select name="mtm-fields[<?php echo esc_attr($i); ?>][context][]" class="mtm-field-input-tag-context" multiple>
153
+ <option value=""><?php esc_html_e('choose one or more contexts', 'meta-tag-manager'); ?></option>
154
+ <?php
155
+ $context_options = self::get_context_options();
156
+ echo self::output_select_options($context_options, $context_value);
157
+ ?>
158
+ </select>
159
+ </label>
160
+ </div>
161
+ <?php endif; ?>
162
+ <?php
163
+ /*
164
+ This is currently shelved as a feature unless there's demand, due to the extra work involved.
165
+ The intention of the bit below is to allow for extra custom attributes since the meta tag does allow for various global attributes.
166
+ https://www.w3.org/TR/html5/document-metadata.html#the-meta-element
167
+ If you're reading this and you want to see this functionality, drop us a line on the support forums (and maybe a little context as for why)
168
+ so we know there's demand for it!
169
+ */
170
+ /*
171
+ <div class="mtm-field-section">
172
+ <div class="mtm-field-section-header">
173
+ <div class="mtm-field-section-toggle"></div>
174
+ <div class="mtm-field-section-title"><?php esc_html_e('Additional Attributes (Advanced)','meta-tag-manager'); ?></div>
175
+ </div>
176
+ <div class="mtm-field-section-data">
177
+ <div class="mtm-field-type-custom">
178
+ <div class="mtm-field-input mtm-field-type-custom-name">
179
+ <label>
180
+ <span class="screen-reader-text"><?php sprintf(esc_html_x('Custom %s', 'label for custom attribute name/value fields', 'meta-tag-manager'),esc_html__('attribute name','meta-tag-manager')); ?></span>
181
+ <input type="text" name="mtm-fields[<?php echo esc_attr($i); ?>][][label]" value="" placeholder="<?php esc_attr_e('attribute name','meta-tag-manager'); ?>" />
182
+ </label>
183
+ </div>
184
+ <div class="mtm-field-input mtm-field-type-custom-value">
185
+ <label>
186
+ <span class="screen-reader-text"><?php sprintf(esc_html_x('Custom %s', 'label for custom attribute name/value fields', 'meta-tag-manager'),esc_html__('attribute value','meta-tag-manager')); ?></span>
187
+ <input type="text" name="mtm-fields[<?php echo esc_attr($i); ?>][][label]" value="" placeholder="<?php esc_attr_e('attribute value','meta-tag-manager'); ?>" />
188
+ </label>
189
+ </div>
190
+ </div>
191
+ <br class="clear" />
192
+ </div>
193
+ </div>
194
+ */ ?>
195
+ <div class="mtm-field-actions">
196
+ <button type="button" class="button-secondary mtm-field-close"><?php esc_html_e('Close Meta Tag Options','meta-tag-manager'); ?></button>
197
+ </div>
198
+ </div>
199
+ </div>
200
+ <?php
201
+ }
202
+
203
+ public static function output_select_options( $options, $selected='', $add_selected_option = true ){
204
+ $html = '';
205
+ foreach( $options as $key => $option ){
206
+ $selected_attr = ( (is_array($selected) && in_array($option, $selected)) || $selected == $option ) ? ' selected="selected"':'';
207
+ if( is_array($option) ){
208
+ $html .= '<optgroup label="'.esc_attr($key).'">';
209
+ $html .= self::output_select_options($option, $selected, false);
210
+ $html .= '</optgroup>';
211
+ }else{
212
+ //single option, output value no key
213
+ if( is_numeric($key) ){
214
+ $html .= '<option'.$selected_attr.'>'.esc_html($option).'</option>';
215
+ }else{
216
+ $html .= '<option value="'.esc_attr($option).'"'.$selected_attr.'>'.esc_html($key).'</option>';
217
+ }
218
+ }
219
+ }
220
+ if( !preg_match('/selected="selected"/', $html) && $selected != '' && $add_selected_option ){
221
+ //value not existing, so we add it as an option
222
+ $html = '<option selected="selected">'.esc_html($selected).'</option>' . $html;
223
+ }
224
+ return $html;
225
+ }
226
+
227
+ public static function get_context_options(){
228
+ if( !empty(self::$context_options) ) return self::$context_options;
229
+ $context_options = array(
230
+ __('All Pages', 'meta-tag-manager') => 'all',
231
+ __('Front Page', 'meta-tag-manager') => 'home'
232
+ );
233
+ //Post Types
234
+ $post_types_label = __('Post Types', 'meta-tag-manager');
235
+ foreach( get_post_types(array('public'=>true), 'objects') as $post_type){
236
+ $context_options[$post_types_label][$post_type->labels->name] = 'post-type_' . $post_type->name;
237
+ }
238
+ //Taxonomies
239
+ $taxonomies_label = __('Taxonomies', 'meta-tag-manager');
240
+ foreach( get_taxonomies(array('public'=>true), 'objects') as $taxonomy ){
241
+ $context_options[$taxonomies_label][$taxonomy->labels->name] = 'taxonomy_' . $taxonomy->name;
242
+ }
243
+ self::$context_options = $context_options;
244
+ return $context_options;
245
+ }
246
+ }
mtm-tag-admin.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MTM_Tag_Admin extends MTM_Tag {
3
+
4
+ public static $type_options = array();
5
+
6
+ /**
7
+ * Constructs a meta tag object but assumes $values is dirty and sanitizes it before passing onto parent constructor
8
+ * @param array $values
9
+ */
10
+ public function __construct($values){
11
+ //context may be passed as an array, if so we implode it first
12
+ if( !empty($values['context']) && is_array($values['context']) ){
13
+ if( in_array('all',$values['context']) ){
14
+ //all pages equates to no context, since when we're outputting global meta tags no context implies outputting it everywhere
15
+ $values['context'] = false;
16
+ }else{
17
+ //implode the context values
18
+ $values['context'] = wp_unslash(implode(',', $values['context']));
19
+ }
20
+ }
21
+ //go through all non-empty values and wp_kses it
22
+ foreach( $values as $k => $v ){
23
+ $values[$k] = wp_kses(wp_unslash($v), array());
24
+ }
25
+ //now pass cleaned values to parent constructor
26
+ parent::__construct($values);
27
+ }
28
+
29
+ public static function get_type_values($type = false){
30
+ if( empty(self::$type_options) ){
31
+ $options = array(
32
+ 'name' => array(
33
+ __('Common values','meta-tag-manager') => array( 'application-name', 'author', 'description', 'generator', 'keywords', 'referrer' ),
34
+ __('Other possible values','meta-tag-manager') => array( 'creator', 'googlebot', 'publisher', 'robots', 'slurp', 'viewport')
35
+ ),
36
+ 'http-equiv' => array( 'Content-Security-Policy', 'default-style', 'refresh' ),
37
+ 'property' => array(
38
+ 'OpenGraph Properties' => array( 'og:url', 'og:type', 'og:title', 'og:locale', 'og:image', 'og:image:secure_url', 'og:image:type', 'og:image:width', 'og:image:height', 'og:video', 'og:video:secure_url', 'og:video:type', 'og:video:width', 'og:video:height', 'og:audio', 'og:audio:secure_url', 'og:audio:type', 'og:description', 'og:site_name', 'og:determiner' ),
39
+ 'Twitter Card Properties' => array( 'twitter:card', 'twitter:site', 'twitter:site:id', 'twitter:creator', 'twitter:creator:id', 'twitter:description', 'twitter:title', 'twitter:image', 'twitter:image:alt', 'twitter:player', 'twitter:player:width', 'twitter:player:height', 'twitter:player:stream', 'twitter:app:name:iphone', 'twitter:app:id:iphone', 'twitter:app:url:iphone', 'twitter:app:name:ipad', 'twitter:app:id:ipad', 'twitter:app:url:ipad', 'twitter:app:name:googleplay', 'twitter:app:id:googleplay', 'twitter:app:url:googleplay' )
40
+ )
41
+ );
42
+ self::$type_options = apply_filters('mtm_tag_type_options', $options);
43
+ }
44
+ if( !empty($type) ){
45
+ return array_key_exists($type, self::$type_options) ? self::$type_options[$type] : array();
46
+ }
47
+ return apply_filters('mtm_tag_type_options', self::$type_options);
48
+ }
49
+
50
+ }
mtm-tag.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class MTM_Tag {
3
+ public $reference;
4
+ public $type;
5
+ public $value;
6
+ public $content;
7
+ public $context = false;
8
+
9
+ public static $types = array();
10
+ public static $types_with_content = array();
11
+
12
+ public function __construct($values){
13
+ $this->reference = !empty($values['reference']) ? $values['reference']:'';
14
+ $this->type = !empty($values['type']) ? $values['type']:'';
15
+ $this->value = !empty($values['value']) ? $values['value']:'';
16
+ $this->content = !empty($values['content']) ? $values['content']:'';
17
+ if( !empty($values['context']) ){
18
+ $this->context = explode(',', $values['context']);
19
+ }
20
+ }
21
+
22
+ public function output(){
23
+ $tag_string = '<meta '.esc_attr($this->type).'="'.esc_attr($this->value).'"';
24
+ if( $this->has_content() ){
25
+ $tag_string .= ' content="'.esc_attr($this->content).'"';
26
+ }
27
+ $tag_string .= ' />';
28
+ return $tag_string;
29
+ }
30
+
31
+ public function to_array(){
32
+ $array = array(
33
+ 'reference' => $this->reference,
34
+ 'type' => $this->type,
35
+ 'value' => $this->value
36
+ );
37
+ if( $this->has_content() ){
38
+ $array['content'] = $this->content;
39
+ }
40
+ if( $this->context !== false && is_array($this->context) ){
41
+ $array['context'] = implode(',', $this->context);
42
+ }
43
+ return $array;
44
+ }
45
+
46
+ public function is_valid(){
47
+ if( in_array($this->type, $this->get_types()) ){ //pass
48
+ if( !empty($this->value) ){ //pass
49
+ if( $this->has_content() && empty($this->content) ){ //fail
50
+ return false; //empty content, no point in outputting
51
+ }
52
+ return true; //if we get here, we're good
53
+ }
54
+ }
55
+ return false;
56
+ }
57
+
58
+ public static function get_types(){
59
+ if( empty(self::$types) ){
60
+ self::$types = apply_filters('mtm_tag_get_types', array('name','http-equiv','charset','itemprop','property'));
61
+ }
62
+ return self::$types;
63
+ }
64
+
65
+ public function has_content(){
66
+ if( empty(self::$types_with_content) ){
67
+ self::$types_with_content = apply_filters('mtm_types_with_content', array('name','http-equiv','itemprop','property'));
68
+ }
69
+ return in_array($this->type, self::$types_with_content);
70
+ }
71
+ }
mtm-update.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if( defined('MTM_VERSION') ){
3
+ //coming in from MTM 1.x we change the values to something else
4
+ if( !get_option('mtm_version') ){
5
+ $mtm_data = get_option('mtm_data');
6
+ $new_mtm_data = array();
7
+ foreach($mtm_data as $mtm_tag){
8
+ $new_tag = array(
9
+ 'value' => $mtm_tag[0],
10
+ 'content' => $mtm_tag[1],
11
+ 'reference' => $mtm_tag[2],
12
+ 'type' => 'name'
13
+ );
14
+ if( !empty($mtm_tag[3]) ){
15
+ $new_tag['location'] = 'home';
16
+ }else{
17
+ $new_tag['location'] = 'all';
18
+ }
19
+ $new_mtm_data[] = $new_tag;
20
+ }
21
+ update_option('mtm_data', $new_mtm_data);
22
+ update_option('mtm_custom', array('post-types'=>array('post','page')));
23
+ update_option('mtm_shiny_update_notice', 1);
24
+ }
25
+ update_option('mtm_version', MTM_VERSION);
26
+ }
mtm_script.js DELETED
@@ -1,68 +0,0 @@
1
- /*
2
- Plugin Name: Meta Tag Manager
3
- Plugin URI: http://netweblogic.com/wordpress/plugins/meta-tag-manager/
4
- Description: A simple plugin to manage meta tags that appear on all your pages. This can be used for verifiying google, yahoo, and more.
5
- Author: Marcus Sykes
6
- Version: 0.5.2
7
- Author URI: http://netweblogic.com/
8
- License : GNU General Public License
9
- Copyright (C) 2008 NetWebLogic LLC
10
- Copyright (C) 2009 Martin Lormes
11
- */
12
- jQuery(document).ready( function($) {
13
- jQuery('#mtm_add_tag').click( function() {
14
- // Get All meta rows
15
- var metas = jQuery('#mtm_body').children();
16
- // Copy first row and change values
17
- var metaCopy = jQuery(metas[0]).clone(true);
18
- newId = metas.length + 1;
19
- metaCopy.attr('id', 'mtm_'+newId);
20
- metaCopy.find('a').attr('rel', newId);
21
- metaCopy.find('[name=mtm_1_ref]').attr({
22
- name:'mtm_'+newId+'_ref' ,
23
- value:''
24
- });
25
- metaCopy.find('[name=mtm_1_content]').attr( {
26
- name:'mtm_'+newId+'_content' ,
27
- value:''
28
- });
29
- metaCopy.find('[name=mtm_1_name]').attr( {
30
- name:'mtm_'+newId+'_name' ,
31
- value:''
32
- });
33
- metaCopy.find('[name=mtm_1_homepageonly]').attr( {
34
- name:'mtm_'+newId+'_homepageonly' ,
35
- checked:false
36
- });
37
- // Insert into end of file
38
- jQuery('#mtm_body').append(metaCopy);
39
- // Duplicate the last entry, remove values and rename id
40
- });
41
-
42
- jQuery('#mtm_body a').click( function() {
43
- // Only remove if there's more than 1 meta tag
44
- if(jQuery('#mtm_body').children().length > 1) {
45
- // Remove the item
46
- jQuery(jQuery(this).parent().parent().get(0)).remove();
47
- //Renumber all the items
48
- jQuery('#mtm_body').children().each( function(i) {
49
- metaCopy = jQuery(this);
50
- oldId = metaCopy.attr('id').replace('mtm_','');
51
- newId = i+1;
52
- metaCopy.attr('id', 'mtm_'+newId);
53
- metaCopy.find('a').attr('rel', newId);
54
- metaCopy.find('[name=mtm_'+ oldId +'_ref]').attr('name', 'mtm_'+newId+'_ref');
55
- metaCopy.find('[name=mtm_'+ oldId +'_content]').attr('name', 'mtm_'+newId+'_content');
56
- metaCopy.find('[name=mtm_'+ oldId +'_name]').attr( 'name', 'mtm_'+newId+'_name');
57
- metaCopy.find('[name=mtm_'+ oldId +'_homepageonly]').attr( 'name', 'mtm_'+newId+'_homepageonly');
58
- });
59
- } else {
60
- metaCopy = jQuery(jQuery(this).parent().parent().get(0));
61
- metaCopy.find('[name=mtm_1_ref]').attr( 'value', '' );
62
- metaCopy.find('[name=mtm_1_content]').attr( 'value', '' );
63
- metaCopy.find('[name=mtm_1_name]').attr( 'value', '' );
64
- metaCopy.find('[name=mtm_1_homepageonly]').attr( 'checked', false );
65
- alert("If you don't want any meta tags, just leave the text boxes blank and submit");
66
- }
67
- });
68
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,54 +1,56 @@
1
  === Meta Tag Manager ===
2
- Contributors: netweblogic
3
- Tags: Google, SEO, Yahoo, Webmaster Tools, Meta, Meta Tags
 
4
  Requires at least: 2.5
5
- Tested up to: 3.3.1
6
- Stable tag: 1.2
7
 
8
- This plugin will allow you to easily add and manage special meta tags to your whole site, such as Yahoo and Google verification tags.
9
 
10
  == Description ==
11
 
12
- Simple plugin which allows you to add custom meta tags that will show across all pages on your blog or on the homepage only.
13
 
14
- Just upload, activate, and immediately start adding meta tags.
15
 
16
- This can be used for adding Google and Yahoo site verification tags along with any other meta tags you may want to add.
17
 
18
- If you have any problems with the plugins, please visit our [http://netweblogic.com/forums/](support forums) for further information and provide some feedback first, we may be able to help. It's considered rude to just give low ratings and nothing reason for doing so.
 
 
19
 
20
- If you find this plugin useful and would like to say thanks, a link, digg, or some other form of recognition to the plugin page on our blog would be appreciated.
21
 
22
- Special thanks to Martin Lormes for help during some crucial updates.
23
-
24
- = Translated Languages Available =
25
-
26
- Here's a list of currently translated languages. Translations that have been submitted are greatly appreciated and hopefully make this plugin a better one. If you'd like to contribute, please have a look at the POT file in the langs folder and send us your translations.
27
-
28
- * Danish - Christian B.
29
- * German - Martin Lormes
30
- * Spanish - Jose Manuel
31
- * Dutch - Marnix van der Heide
32
 
33
  == Installation ==
34
 
35
- 1. Download and unzip the plugin, then upload the entire `meta-tag-manager` directory to the `/wp-content/plugins` directory; or simply upload the zip file if you use WordPress 2.7 or newer
36
  1. Activate the plugin through the 'Plugins' menu in WordPress
37
  1. Go to *Settings > Meta Tag Manager*
38
- 1. Enter the values in the text boxes. The first text box is so you can give your meta tag a memorable name and is not displayed on the website
39
- 1. Add tags by clicking on the add tag link under the meta rows, and remove tags by clicking on the links next to the meta in question
40
- 1. Save your changes
41
 
42
  == Frequently Asked Questions ==
43
 
44
- Please see our [http://netweblogic.com/forums/](support forums).
45
 
46
  == Screenshots ==
47
 
48
  1. Once the plugin is activated you can add/edit/delete tags from the menu in *Settings > Meta Tag Manager*
49
 
 
 
 
 
50
  == Changelog ==
51
 
 
 
 
 
 
52
  = 1.2 =
53
  * fixed stripslashes bug
54
  * added languages
1
  === Meta Tag Manager ===
2
+ Contributors: netweblogic, freemius
3
+ Tags: google, SEO, yahoo, tags, webmaster tools, meta, meta tags, ogp, open graph, twitter cards
4
+ Text Domain: meta-tag-manager
5
  Requires at least: 2.5
6
+ Tested up to: 4.5.2
7
+ Stable tag: 2.0
8
 
9
+ Easily add and manage custom meta tags to various parts of your site or on individual posts, such as Yahoo and Google verification tags.
10
 
11
  == Description ==
12
 
13
+ <blockquote>Meta Tag Manager 2.0 is a complete rewrite with many improvments on the first versions. Whilst there are many improvements, this first rewrite isn't a great departure from the original plugin, although it adds some fundemental improvements.
14
 
15
+ We have plenty of ideas of what to add to the plugin, we'd love to hear your suggestions too, please let us know on our <a href="https://wordpress.org/support/plugin/meta-tag-manager">support forums</a>.<br/><br/></blockquote>
16
 
17
+ Meta Tags Manager is a simple, lightweight plugin which allows you to add custom meta tags to your site. Features include:
18
 
19
+ * Supports meta tags including the name, property, http-equiv, charset and itemprop attributes.
20
+ * Add meta tags to specific posts, choose what Custom Post Types to support from our settings page.
21
+ * Add global meta tags that will display on specific CPTs, Taxonomies, your front page or your whole site.
22
 
23
+ Use cases include:
24
 
25
+ * Adding Google and Yahoo site verification tags
26
+ * Adding additional open graph, twitter card or other social media meta info not supported by other SEO/Meta plugins
 
 
 
 
 
 
 
 
27
 
28
  == Installation ==
29
 
30
+ 1. Upload the entire `meta-tag-manager` directory to the `/wp-content/plugins/` directory
31
  1. Activate the plugin through the 'Plugins' menu in WordPress
32
  1. Go to *Settings > Meta Tag Manager*
33
+ 1. Start adding Meta Tags!
 
 
34
 
35
  == Frequently Asked Questions ==
36
 
37
+ Please visit our <a href="https://wordpress.org/support/plugin/meta-tag-manager">support forums</a> if you have any questions.
38
 
39
  == Screenshots ==
40
 
41
  1. Once the plugin is activated you can add/edit/delete tags from the menu in *Settings > Meta Tag Manager*
42
 
43
+ 2. You can also choose what post types to manage specific meta tags
44
+
45
+ 3. If enabled you can add meta tags to a specific post in it's own meta box
46
+
47
  == Changelog ==
48
 
49
+ = 2.0 =
50
+ * complete rewrite of plugin using up-to-date WP best practices
51
+ * improved interface for adding meta tags including support for creating tags using either the property, charset, http-equiv or itemprop attributes
52
+ * added ability to add individual meta tags to specific individual CPTs which can be chosen in settings page
53
+
54
  = 1.2 =
55
  * fixed stripslashes bug
56
  * added languages
screenshot-1.jpg DELETED
Binary file