Coming Soon Page and Maintenance Mode for WordPress Block Editor - Version 1.0.0

Version Description

Download this release

Release Info

Developer heldervilela
Plugin Icon 128x128 Coming Soon Page and Maintenance Mode for WordPress Block Editor
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

Files changed (87) hide show
  1. LICENSE +674 -0
  2. admin/Toolbar.php +59 -0
  3. admin/api/UnlockPage.php +116 -0
  4. admin/blocks/Init.php +311 -0
  5. admin/blocks/_available/temp-01/attributes.php +84 -0
  6. admin/blocks/_available/temp-01/media/thumb.jpg +0 -0
  7. admin/blocks/_available/temp-01/render.php +70 -0
  8. admin/blocks/available-blocks.json +12 -0
  9. admin/blocks/sidebar/look-and-feel/editor.scss +11 -0
  10. admin/blocks/sidebar/look-and-feel/media/icon.svg +5 -0
  11. admin/blocks/sidebar/seo/editor.scss +11 -0
  12. admin/blocks/sidebar/seo/media/icon.svg +5 -0
  13. admin/blocks/sidebar/settings/editor.scss +11 -0
  14. admin/blocks/sidebar/settings/media/icon.svg +5 -0
  15. admin/blocks/sidebar/templates/editor.scss +66 -0
  16. admin/blocks/sidebar/templates/media/add.svg +3 -0
  17. admin/config.settings.php +142 -0
  18. admin/dashboard/Init.php +153 -0
  19. coming-soon-blocks.php +213 -0
  20. frontend/components/block-background-overlayer.php +16 -0
  21. frontend/components/block-background.php +83 -0
  22. frontend/components/cookie-notice.php +21 -0
  23. frontend/components/social-icons.php +20 -0
  24. frontend/components/unlock-page.php +29 -0
  25. frontend/init.php +198 -0
  26. frontend/template.php +140 -0
  27. languages/coming-soon-blocks.pot +134 -0
  28. lib/Footer_Text.php +56 -0
  29. lib/Gutenberg_Checker.php +180 -0
  30. lib/Plugin.php +343 -0
  31. lib/Utils.php +271 -0
  32. lib/freemius.php +56 -0
  33. lib/freemius/assets/css/admin/account.css +1 -0
  34. lib/freemius/assets/css/admin/add-ons.css +2 -0
  35. lib/freemius/assets/css/admin/affiliation.css +1 -0
  36. lib/freemius/assets/css/admin/checkout.css +1 -0
  37. lib/freemius/assets/css/admin/common.css +2 -0
  38. lib/freemius/assets/css/admin/connect.css +1 -0
  39. lib/freemius/assets/css/admin/deactivation-feedback.css +1 -0
  40. lib/freemius/assets/css/admin/debug.css +1 -0
  41. lib/freemius/assets/css/admin/dialog-boxes.css +2 -0
  42. lib/freemius/assets/css/admin/gdpr-optin-notice.css +1 -0
  43. lib/freemius/assets/css/admin/index.php +3 -0
  44. lib/freemius/assets/css/admin/license-activation.css +1 -0
  45. lib/freemius/assets/css/customizer.css +1 -0
  46. lib/freemius/assets/css/index.php +3 -0
  47. lib/freemius/assets/img/coming-soon-blocks.png +0 -0
  48. lib/freemius/assets/img/index.php +3 -0
  49. lib/freemius/assets/img/mobile-menu.png +0 -0
  50. lib/freemius/assets/img/plugin-icon.png +0 -0
  51. lib/freemius/assets/img/theme-icon.png +0 -0
  52. lib/freemius/assets/index.php +3 -0
  53. lib/freemius/assets/js/index.php +3 -0
  54. lib/freemius/assets/js/nojquery.ba-postmessage.js +140 -0
  55. lib/freemius/assets/js/nojquery.ba-postmessage.min.js +12 -0
  56. lib/freemius/assets/js/postmessage.js +135 -0
  57. lib/freemius/assets/scss/_colors.scss +68 -0
  58. lib/freemius/assets/scss/_functions.scss +0 -0
  59. lib/freemius/assets/scss/_load.scss +4 -0
  60. lib/freemius/assets/scss/_mixins.scss +270 -0
  61. lib/freemius/assets/scss/_start.scss +4 -0
  62. lib/freemius/assets/scss/_vars.scss +6 -0
  63. lib/freemius/assets/scss/admin/_ajax-loader.scss +49 -0
  64. lib/freemius/assets/scss/admin/_auto-install.scss +33 -0
  65. lib/freemius/assets/scss/admin/_deactivation-feedback.scss +55 -0
  66. lib/freemius/assets/scss/admin/_gdpr-consent.scss +81 -0
  67. lib/freemius/assets/scss/admin/_license-activation.scss +47 -0
  68. lib/freemius/assets/scss/admin/_license-key-resend.scss +68 -0
  69. lib/freemius/assets/scss/admin/_modal-common.scss +194 -0
  70. lib/freemius/assets/scss/admin/_multisite-options.scss +40 -0
  71. lib/freemius/assets/scss/admin/_themes.scss +21 -0
  72. lib/freemius/assets/scss/admin/_tooltip.scss +66 -0
  73. lib/freemius/assets/scss/admin/account.scss +302 -0
  74. lib/freemius/assets/scss/admin/add-ons.scss +449 -0
  75. lib/freemius/assets/scss/admin/affiliation.scss +97 -0
  76. lib/freemius/assets/scss/admin/checkout.scss +5 -0
  77. lib/freemius/assets/scss/admin/common.scss +218 -0
  78. lib/freemius/assets/scss/admin/connect.scss +548 -0
  79. lib/freemius/assets/scss/admin/debug.scss +135 -0
  80. lib/freemius/assets/scss/admin/dialog-boxes.scss +8 -0
  81. lib/freemius/assets/scss/admin/gdpr-optin-notice.scss +17 -0
  82. lib/freemius/assets/scss/admin/index.php +3 -0
  83. lib/freemius/assets/scss/customizer.scss +125 -0
  84. lib/freemius/assets/scss/index.php +3 -0
  85. lib/freemius/config.php +388 -0
  86. lib/freemius/includes/class-freemius-abstract.php +597 -0
  87. lib/freemius/includes/class-freemius.php +20143 -0
LICENSE ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ {one line to give the program's name and a brief idea of what it does.}
635
+ Copyright (C) {year} {name of author}
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ {project} Copyright (C) {year} {fullname}
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
admin/Toolbar.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class to add menu to toolbar.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ namespace Pixelthrone\ComingSoon_Blocks\Toolbar;
12
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
13
+
14
+ // Exit if accessed directly.
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit;
17
+ }
18
+
19
+ /**
20
+ * Toolbar Class
21
+ *
22
+ * @since 1.0.0
23
+ */
24
+ class Toolbar {
25
+
26
+ /**
27
+ * Class constructor.
28
+ */
29
+ public function __construct() {
30
+ add_action( 'admin_bar_menu', [$this, 'admin_bar_menu'] , 50 );
31
+ }
32
+
33
+ /**
34
+ * Build menu.
35
+ *
36
+ * @since 1.0.0
37
+ * @access public
38
+ *
39
+ * @param string $footer_text The content that will be printed.
40
+ *
41
+ * @return string The content that will be printed.
42
+ */
43
+ function admin_bar_menu( $wp_admin_bar ) {
44
+
45
+ foreach (Plugin::get_settings('toolbar') as $menu) {
46
+
47
+ if( Plugin::is_active() ) {
48
+ if( $menu['id'] === 'pt_comingsoonblocks_toolbar_group' ) {
49
+ $menu['meta'] = ['class' => '-coming-soon-enabled'];
50
+ }
51
+ }
52
+ $wp_admin_bar->add_node( $menu );
53
+
54
+ }
55
+ }
56
+
57
+ }
58
+
59
+ new Toolbar();
admin/api/UnlockPage.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Unlock Coming Soon Page
4
+ *
5
+ * @package coming-soon-blocks
6
+ * @version 1.0.0
7
+ * @author Helder Vilela from Pixelthrone
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ namespace Pixelthrone\ComingSoon_Blocks\Api\UnlockPage;
12
+
13
+ use Pixelthrone\ComingSoon_Blocks\Utils;
14
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
15
+ use WP_REST_Request;
16
+ use WP_REST_Response;
17
+ use WP_REST_Server;
18
+ use WP_Error;
19
+
20
+ class UnlockPage {
21
+
22
+ /**
23
+ * Endpoint namespace.
24
+ *
25
+ * @var string
26
+ */
27
+ protected $namespace = 'v1';
28
+
29
+ /**
30
+ * Route base.
31
+ *
32
+ * @var string
33
+ */
34
+ protected $rest_endpoint = 'unlockpage';
35
+
36
+ public
37
+ function __construct() {
38
+
39
+ add_action( 'rest_api_init', function () {
40
+
41
+ /**
42
+ * Filter feed
43
+ *
44
+ * @since 1.0.0
45
+ * @access public
46
+ * @endpoint /wp-json/v1/unlockpage (GET)
47
+ *
48
+ * @return object
49
+ */
50
+ register_rest_route( $this->namespace, '/' . $this->rest_endpoint, [
51
+ 'methods' => WP_REST_Server::READABLE,
52
+ 'callback' => [ $this, 'callback' ],
53
+ ] );
54
+
55
+
56
+ } );
57
+
58
+ }
59
+
60
+ /**
61
+ * Get cart.
62
+ *
63
+ * @access public
64
+ * @since 1.0.0
65
+ *
66
+ * @param array $data
67
+ *
68
+ * @return WP_REST_Response
69
+ */
70
+ public
71
+ function callback( WP_REST_Request $request ) {
72
+ $nonce = check_ajax_referer('wp_rest', '_wpnonce', false);
73
+ $pwd = $request->get_param( 'pwd' );
74
+
75
+ # Check the nonce
76
+ if ( ! $nonce ) {
77
+ return new WP_Error( 'invalid-nonce', esc_html__( 'No naughty business please!', 'coming-soon-blocks' ), [ 'status' => 403 ] );
78
+ }
79
+
80
+ $pageConfig = Plugin::get_frontend_settings();
81
+
82
+ if( $pageConfig->settings->passwordProtected ) {
83
+
84
+ // Confirm password
85
+ if( $pageConfig->settings->password === $pwd ) {
86
+ $response = [
87
+ 'code' => 'refreshing',
88
+ 'data' => [
89
+ 'status' => 200,
90
+ ],
91
+ 'message' => esc_html__( 'The page will be updated.', 'coming-soon-blocks' )
92
+ ];
93
+
94
+ $pwd = Utils\encrypt($pwd);
95
+ setcookie( 'comingsoonblocks__unlock_page', $pwd, strtotime( '+10 days' ), '/' );
96
+
97
+ return new WP_REST_Response( $response, 200 );
98
+ }
99
+ // Invalid password
100
+ else {
101
+ return new WP_Error( 'invalid-password', esc_html__( 'The password is not correct.', 'coming-soon-blocks' ), [ 'status' => 403 ] );
102
+ }
103
+
104
+
105
+ } else {
106
+ return new WP_Error( 'option-is-not-enabled', esc_html__( 'No naughty business please!', 'coming-soon-blocks' ), [ 'status' => 403 ] );
107
+ }
108
+
109
+ }
110
+
111
+ }
112
+
113
+ new UnlockPage();
114
+
115
+
116
+
admin/blocks/Init.php ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Init gutenberg blocks.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ namespace Pixelthrone\ComingSoon_Blocks\Blocks;
12
+
13
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
14
+ use Pixelthrone\ComingSoon_Blocks\Utils;
15
+
16
+ // Exit if accessed directly.
17
+ if ( ! defined( 'ABSPATH' ) ) {
18
+ exit;
19
+ }
20
+
21
+ /**
22
+ * Main blocks class
23
+ *
24
+ * @since 1.0.0
25
+ */
26
+ class Init {
27
+ /**
28
+ * Plugin url.
29
+ *
30
+ * @var string $plugin_url
31
+ */
32
+ private $url;
33
+
34
+ /**
35
+ * Plugin slug.
36
+ *
37
+ * @var string $slug
38
+ */
39
+ private $slug;
40
+
41
+ /**
42
+ * Plugin slug.
43
+ *
44
+ * @var string $slug
45
+ */
46
+ private $version;
47
+
48
+ /**
49
+ * Blocks manifest.
50
+ *
51
+ * @var array
52
+ */
53
+ private $blocks;
54
+
55
+ /**
56
+ * Constructor.
57
+ *
58
+ * @since 1.0.0
59
+ * @return void
60
+ */
61
+ public
62
+ function __construct() {
63
+ // No run in ajax
64
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
65
+ return;
66
+ }
67
+
68
+ add_action( 'rest_insert_' . Plugin::get_slug(), [ $this, 'post_updated_on_rest' ], 10, 2 );
69
+ add_action( 'post_updated', [ $this, 'post_updated_on_admin' ], 10, 3 );
70
+
71
+ // Only on my pages
72
+ if ( ! Utils\is_post_type_page( Plugin::get_slug() ) && is_admin() ) {
73
+ return;
74
+ }
75
+
76
+ $this->slug = Plugin::get_slug();
77
+ $this->url = Plugin::get_plugin_url();
78
+ $this->version = Plugin::get_version();
79
+ $this->blocks = wp_remote_get( $this->url . '/admin/blocks/available-blocks.json' );
80
+ $this->blocks = json_decode( wp_remote_retrieve_body( $this->blocks ) );
81
+
82
+ // Only run on my page
83
+ if ( Utils\is_post_type_page( Plugin::get_slug() ) ) {
84
+ add_action( 'admin_init', [ $this, 'admin_init' ] );
85
+ add_action( 'after_setup_theme', [ $this, 'after_setup_theme' ], 99 );
86
+ add_action( 'enqueue_block_editor_assets', [ $this, 'localization' ] );
87
+ add_action( 'admin_footer', [ $this, 'admin_footer' ] );
88
+ }
89
+ add_action( 'init', [ $this, 'init' ] );
90
+ }
91
+
92
+ /**
93
+ * Update post meta on rest call.
94
+ *
95
+ * @access public
96
+ *
97
+ * @param $post
98
+ * @param $WP_REST_Request | WP_REST_Request
99
+ */
100
+ public
101
+ function post_updated_on_rest( $post, $WP_REST_Request ) {
102
+
103
+ $status = $WP_REST_Request->get_param( 'status' );
104
+ $seo_content = $WP_REST_Request->get_param( 'comingsoonblocks_seo' );
105
+ $lookandfeel_content = $WP_REST_Request->get_param( 'comingsoonblocks_lookandfeel' );
106
+ $settings_content = $WP_REST_Request->get_param( 'comingsoonblocks_settings' );
107
+
108
+ if ( ! $seo_content && ! $lookandfeel_content && ! $settings_content ) {
109
+ return;
110
+ }
111
+
112
+ $posted_id = $WP_REST_Request->get_param( 'id' );
113
+ $actual_selected_page_id = Plugin::get_option( 'selected_page_id' );
114
+
115
+ if ( $seo_content ) {
116
+ Plugin::update_option( 'seo', $posted_id, $seo_content );
117
+ }
118
+
119
+ if ( $lookandfeel_content ) {
120
+ Plugin::update_option( 'lookandfeel', $posted_id, $lookandfeel_content );
121
+ }
122
+
123
+ if ( $settings_content ) {
124
+ Plugin::update_option( 'settings', $posted_id, $settings_content );
125
+
126
+ $settings_content = json_decode( $settings_content );
127
+
128
+ // Same Page
129
+ if ( intval( $actual_selected_page_id ) === intval( $posted_id ) ) {
130
+ $new_page_id = $settings_content->status ? $posted_id : null;
131
+ Plugin::update_option( 'selected_page_id', null, $new_page_id );
132
+ }
133
+ // Different page
134
+ else {
135
+ if ( $settings_content ) {
136
+ Plugin::update_option( 'selected_page_id', null, $posted_id );
137
+ }
138
+ }
139
+
140
+
141
+ }
142
+
143
+ }
144
+
145
+ /**
146
+ * Update post meta on normal call.
147
+ *
148
+ * @access public
149
+ */
150
+ public
151
+ function post_updated_on_admin( $post_ID, $post_after, $post_before ) {
152
+ $actual_selected_page_id = Plugin::get_option( 'selected_page_id' );
153
+
154
+ if( $post_after->post_status !== 'publish' ) {
155
+ if ( intval( $actual_selected_page_id ) === intval( $post_ID ) ) {
156
+ Plugin::update_option( 'selected_page_id', null, null );
157
+ }
158
+ }
159
+
160
+ }
161
+
162
+ /**
163
+ * Registers theme support for a given feature.
164
+ *
165
+ * @access public
166
+ */
167
+ public
168
+ function after_setup_theme() {
169
+ remove_theme_support( 'editor-styles' );
170
+ remove_theme_support( 'dark-editor-style' );
171
+ remove_theme_support( 'responsive-embeds' );
172
+ add_theme_support( 'align-full' );
173
+ remove_theme_support( 'disable-custom-colors' );
174
+ add_theme_support( 'editor-font-sizes' );
175
+ }
176
+
177
+ /**
178
+ * Init on frontend.
179
+ *
180
+ * @access public
181
+ */
182
+ public
183
+ function init() {
184
+ $this->register_blocks();
185
+ }
186
+
187
+ /**
188
+ * Init on admin.
189
+ *
190
+ * @access public
191
+ */
192
+ public
193
+ function admin_init() {
194
+ $this->register_blocks();
195
+ $this->editor_assets();
196
+ }
197
+
198
+ /**
199
+ * Add actions to enqueue assets.
200
+ *
201
+ * @access public
202
+ */
203
+ public
204
+ function register_blocks() {
205
+
206
+ // Return early if this function does not exist.
207
+ if ( ! function_exists( 'register_block_type' ) || ! is_array( $this->blocks ) ) {
208
+ return;
209
+ }
210
+
211
+ /**
212
+ * Register Block.
213
+ */
214
+ foreach ( $this->blocks as $block ) {
215
+
216
+ $args = [
217
+ 'editor_script' => $this->slug . '-editor',
218
+ 'editor_style' => $this->slug . '-editor',
219
+ 'style' => $this->slug . '-frontend',
220
+ ];
221
+
222
+ if ( ! empty( $block->script ) ) {
223
+ $args['script'] = $this->slug . '-' . $args['script'];
224
+ }
225
+
226
+ if ( $block->render_callback ) {
227
+ $args['attributes'] = include( Plugin::get_plugin_dir( '/admin/blocks/_available/' . $block->slug . '/attributes.php' ) );
228
+ $args['render_callback'] = include( Plugin::get_plugin_dir( '/admin/blocks/_available/' . $block->slug . '/render.php' ) );
229
+ }
230
+
231
+ register_block_type( $block->name, $args );
232
+ }
233
+
234
+ }
235
+
236
+ /**
237
+ * Enqueue block assets for use within Gutenberg.
238
+ *
239
+ * @access public
240
+ */
241
+ public
242
+ function editor_assets() {
243
+
244
+ // Styles
245
+ wp_register_style( $this->slug . '-frontend', $this->url . '/public/dist/blocks.editor.bundle.css', [], $this->version );
246
+ wp_register_style( $this->slug . '-editor', $this->url . '/public/dist/blocks.style.bundle.css', [], $this->version );
247
+
248
+ // Scripts
249
+ wp_register_script( $this->slug . '-editor', $this->url . '/public/dist/blocks.bundle.js', [
250
+ 'wp-blocks',
251
+ 'wp-i18n',
252
+ 'wp-element',
253
+ 'wp-plugins',
254
+ 'wp-components',
255
+ 'wp-edit-post',
256
+ 'wp-api',
257
+ 'wp-editor'
258
+ ], $this->version, true );
259
+
260
+ }
261
+
262
+ /**
263
+ * Enqueue Jed-formatted localization data.
264
+ *
265
+ * @access public
266
+ */
267
+ public
268
+ function localization() {
269
+
270
+ /**
271
+ * Share page data with javascript.
272
+ *
273
+ * @since 1.0.0
274
+ */
275
+ $ptPlugin = Plugin::get_script_data();
276
+ $ptPlugin['license'] = [
277
+ 'plan' => csblocks_fs()->get_plan_name(),
278
+ 'can_use_premium_code' => csblocks_fs()->can_use_premium_code(),
279
+ 'is_trial' => csblocks_fs()->is_trial(),
280
+ 'is_free' => csblocks_fs()->is_not_paying(),
281
+ ];
282
+
283
+ $ptPlugin = wp_json_encode( $ptPlugin );
284
+ $content = [
285
+ 'const csblocks=' . $ptPlugin . ';'
286
+ ];
287
+
288
+ wp_script_add_data( $this->slug . '-editor', 'data', implode( $content, ' ' ) );
289
+
290
+
291
+ // Check if this function exists.
292
+ if ( ! function_exists( 'wp_set_script_translations' ) ) {
293
+ return;
294
+ }
295
+
296
+ wp_set_script_translations( $this->slug . '-editor', 'coming-soon-blocks' );
297
+ }
298
+
299
+ /**
300
+ * Add extra markup.
301
+ *
302
+ * @access public
303
+ */
304
+ public
305
+ function admin_footer() {}
306
+ }
307
+
308
+ if ( Plugin::has_gutenberg() ) {
309
+ new Init();
310
+ }
311
+
admin/blocks/_available/temp-01/attributes.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
4
+
5
+ return [
6
+ 'titleText' => [
7
+ 'type' => 'string',
8
+ 'default' => 'If you do it right, it will last forever.'
9
+ ],
10
+ 'subTitleText' => [
11
+ 'type' => 'string',
12
+ 'default' => 'WE ARE WORKING ON OUR WEBSITE'
13
+ ],
14
+ 'descriptionText' => [
15
+ 'type' => 'string',
16
+ 'default' => 'Curabitur blandit tempus porttitor. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Maecenas sed diam eget risus varius blandit sit amet non magna risus, porta ac consectetur ac.'
17
+ ],
18
+ 'copyrightText' => [
19
+ 'type' => 'string',
20
+ 'default' => '© 2018 — Made with ♥︎ by <a href="#">Pixelthrone</a>"'
21
+ ],
22
+ 'align' => [
23
+ 'type' => 'string',
24
+ 'default' => 'full'
25
+ ],
26
+ 'logoID' => [
27
+ 'type' => 'number',
28
+ 'default' => '',
29
+ ],
30
+ 'logoAlign' => [
31
+ 'type' => 'string',
32
+ 'default' => 'center',
33
+ ],
34
+ 'logoMaxWidth' => [
35
+ 'type' => 'number',
36
+ 'default' => 150,
37
+ ],
38
+ 'logoURL' => [
39
+ 'type' => 'string',
40
+ 'default' => Plugin::get_cdn_url('logo--01.png'),
41
+ ],
42
+ 'overlayColor' => [
43
+ 'type' => 'string',
44
+ 'default' => '#000000'
45
+ ],
46
+ 'overlayOpacity' => [
47
+ 'type' => 'number',
48
+ 'default' => 40
49
+ ],
50
+ 'textColor' => [
51
+ 'type' => 'string',
52
+ 'default' => '#fff'
53
+ ],
54
+ 'networks' => [
55
+ 'type' => 'string',
56
+ 'default' => '[]',
57
+ ],
58
+ 'titleTypo' => [
59
+ 'type' => 'string',
60
+ 'default' => '{"fontfamily":"Vollkorn","variants":["regular","italic","600","600italic","700","700italic","900","900italic"],"desktop":{"fontweight":"italic","fontsize":30,"lineheight":130,"letterspacing":0},"mobile":{"fontweight":"regular","fontsize":16,"lineheight":100,"letterspacing":0}}',
61
+ ],
62
+ 'subtitleTypo' => [
63
+ 'type' => 'string',
64
+ 'default' => '{"fontfamily":"Montserrat","variants":["100","100italic","200","200italic","300","300italic","regular","italic","500","500italic","600","600italic","700","700italic","800","800italic","900","900italic"],"desktop":{"fontweight":"600","fontsize":13,"lineheight":100,"letterspacing":0},"mobile":{"fontweight":"100","fontsize":16,"lineheight":100,"letterspacing":0}}',
65
+ ],
66
+ 'bodyTypo' => [
67
+ 'type' => 'string',
68
+ 'default' => '{"fontfamily":"Montserrat","variants":["100","100italic","200","200italic","300","300italic","regular","italic","500","500italic","600","600italic","700","700italic","800","800italic","900","900italic"],"desktop":{"fontweight":"300","fontsize":14,"lineheight":145,"letterspacing":0},"mobile":{"fontweight":"100","fontsize":16,"lineheight":100,"letterspacing":0}}',
69
+ ],
70
+ 'background' => [
71
+ 'type' => 'string',
72
+ 'default' => json_encode( [
73
+ 'type' => 'image',
74
+ 'image' => [
75
+ 'id' => '',
76
+ 'full' => Plugin::get_cdn_url('temp-01--bg.jpg'),
77
+ 'thumb' => '',
78
+ ],
79
+ 'gallery' => [],
80
+ 'video' => [],
81
+ 'color' => '#0D1215'
82
+ ] ),
83
+ ]
84
+ ];
admin/blocks/_available/temp-01/media/thumb.jpg ADDED
Binary file
admin/blocks/_available/temp-01/render.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ use Pixelthrone\ComingSoon_Blocks\Utils;
3
+
4
+ /**
5
+ * @param $attributes
6
+ * @param $content
7
+ *
8
+ * @return false|string
9
+ */
10
+ return function( $attributes, $content ) {
11
+ $blockID = uniqid('block__');
12
+
13
+ /**
14
+ * Typography
15
+ */
16
+ $bodyTypo = json_decode($attributes['bodyTypo']);
17
+ Utils\page_css( 'add', Utils\compile_block_css( $blockID, $bodyTypo, 'body__typography' ) );
18
+ Utils\page_fonts( 'add', $bodyTypo );
19
+
20
+ $titleTypo = json_decode( $attributes['titleTypo'] );
21
+ Utils\page_css( 'add', Utils\compile_block_css( $blockID, $titleTypo, 'title__typography' ) );
22
+ Utils\page_fonts( 'add', $titleTypo );
23
+
24
+ $subtitleTypo = json_decode( $attributes['subtitleTypo'] );
25
+ Utils\page_css( 'add', Utils\compile_block_css( $blockID, $subtitleTypo, 'subtitle__typography' ) );
26
+ Utils\page_fonts( 'add', $subtitleTypo );
27
+
28
+ /**
29
+ * Output
30
+ */
31
+ ob_start();
32
+ // var_dump($attributes);
33
+ ?>
34
+ <main data-blockid="<?php echo $blockID; ?>" data-block="pixelthrone/comingsoon--temp-01">
35
+
36
+ <div class="content__container" style="color:<?php echo esc_attr($attributes['textColor']); ?> ">
37
+ <div class="brand__wrapper">
38
+ <img style="max-width: <?php echo esc_attr($attributes['logoMaxWidth']) ?>px"
39
+ class="-<?php echo esc_attr($attributes['logoAlign']) ?>-align"
40
+ src="<?php echo esc_url($attributes['logoURL']) ?>"
41
+ >
42
+ </div>
43
+
44
+ <div class="title__wrapper">
45
+ <?php echo ! empty($attributes['titleText']) ? '<h1 class="-title__typography">'.$attributes['titleText'].'<h1>' : ''; ?>
46
+ </div>
47
+
48
+ <div class="subtitle__wrapper">
49
+ <?php echo ! empty($attributes['subTitleText']) ? '<h2 class="-subtitle__typography">'.Utils\esc_allowed_html($attributes['subTitleText']).'</h2>' : ''; ?>
50
+ </div>
51
+
52
+ <div class="description__wrapper -body__typography">
53
+ <?php echo ! empty($attributes['descriptionText']) ? '<p>'.Utils\esc_allowed_html($attributes['descriptionText']).'</p>' : ''; ?>
54
+ <p class="copyright"><?php echo Utils\esc_allowed_html( $attributes['copyrightText'] ) ?></p>
55
+ </div>
56
+
57
+ <?php if( ! empty($attributes['networks']) && $attributes['networks'] !== '[]' ): ?>
58
+ <div class="social__wrapper">
59
+ <?php Utils\component('social-icons', ['networks'=> $attributes['networks']]) ?>
60
+ </div>
61
+ <?php endif; ?>
62
+
63
+ </div>
64
+
65
+ <?php Utils\component('block-background-overlayer', ['overlayColor'=> $attributes['overlayColor'], 'overlayOpacity' => $attributes['overlayOpacity'] ]) ?>
66
+ <?php Utils\component('block-background', ['background'=> $attributes['background'] ]) ?>
67
+ </main>
68
+ <?php
69
+ return ob_get_clean();
70
+ };
admin/blocks/available-blocks.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "name" : "pixelthrone/comingsoon--temp-01",
4
+ "slug" : "temp-01",
5
+ "thumb" : {
6
+ "name" : "01",
7
+ "img" : "/admin/blocks/_available/temp-01/media/thumb.jpg"
8
+ },
9
+ "script" : "",
10
+ "render_callback" : true
11
+ }
12
+ ]
admin/blocks/sidebar/look-and-feel/editor.scss ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ // Header
3
+ .edit-post-header {
4
+ .edit-post-pinned-plugins button .look-and-feel-button {
5
+ stroke: none !important;
6
+ > * {
7
+ stroke: none !important;
8
+ }
9
+ }
10
+ }
11
+ }
admin/blocks/sidebar/look-and-feel/media/icon.svg ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <svg width="78px" height="17px" viewBox="0 0 78 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
3
+ <path d="M0,13.4262695 L0,4.14599609 L2.48605219,4.14599609 L2.48605219,11.4013672 L6.0294633,11.4013672 L6.0294633,13.4262695 L0,13.4262695 Z M15.5778818,8.7734375 C15.5778818,10.3349687 15.1981595,11.5219686 14.4387034,12.3344727 C13.6792474,13.1469767 12.5673533,13.5532227 11.1029878,13.5532227 C9.65960178,13.5532227 8.55295248,13.1448609 7.78300673,12.328125 C7.01306098,11.5113891 6.62809388,10.3222734 6.62809388,8.76074219 C6.62809388,7.21613811 7.01096307,6.03654379 7.77671293,5.22192383 C8.54246279,4.40730387 9.65540583,4 11.1155754,4 C12.5799409,4 13.6897371,4.40413007 14.4449972,5.21240234 C15.2002574,6.02067461 15.5778818,7.20767446 15.5778818,8.7734375 Z M9.24631593,8.7734375 C9.24631593,10.5677173 9.86520038,11.4648438 11.1029878,11.4648438 C11.7323713,11.4648438 12.199157,11.2469097 12.503359,10.8110352 C12.807561,10.3751606 12.9596597,9.69596815 12.9596597,8.7734375 C12.9596597,7.84667505 12.8054631,7.16219297 12.4970652,6.7199707 C12.1886673,6.27774844 11.7281753,6.05664062 11.1155754,6.05664062 C9.8693962,6.05664062 9.24631593,6.96223053 9.24631593,8.7734375 Z M25.5731603,8.7734375 C25.5731603,10.3349687 25.193438,11.5219686 24.4339819,12.3344727 C23.6745259,13.1469767 22.5626318,13.5532227 21.0982663,13.5532227 C19.6548803,13.5532227 18.548231,13.1448609 17.7782852,12.328125 C17.0083395,11.5113891 16.6233724,10.3222734 16.6233724,8.76074219 C16.6233724,7.21613811 17.0062416,6.03654379 17.7719914,5.22192383 C18.5377413,4.40730387 19.6506843,4 21.1108539,4 C22.5752194,4 23.6850156,4.40413007 24.4402757,5.21240234 C25.1955359,6.02067461 25.5731603,7.20767446 25.5731603,8.7734375 Z M19.2415944,8.7734375 C19.2415944,10.5677173 19.8604789,11.4648438 21.0982663,11.4648438 C21.7276498,11.4648438 22.1944355,11.2469097 22.4986375,10.8110352 C22.8028395,10.3751606 22.9549382,9.69596815 22.9549382,8.7734375 C22.9549382,7.84667505 22.8007416,7.16219297 22.4923437,6.7199707 C22.1839458,6.27774844 21.7234538,6.05664062 21.1108539,6.05664062 C19.8646747,6.05664062 19.2415944,6.96223053 19.2415944,8.7734375 Z M34.8194762,13.4262695 L32.0124401,13.4262695 L30.193531,9.87792969 L29.457156,10.3222656 L29.457156,13.4262695 L26.9585162,13.4262695 L26.9585162,4.14599609 L29.457156,4.14599609 L29.457156,8.17675781 C29.5830327,7.92708208 29.8368802,7.53141547 30.2187062,6.98974609 L32.1509037,4.14599609 L34.8698266,4.14599609 L31.9683834,8.30371094 L34.8194762,13.4262695 Z M44.7965926,13.4262695 L44.1735061,12.7788086 C43.795876,13.0200207 43.4864338,13.1861161 43.2451701,13.2770996 C43.0039065,13.3680831 42.7332757,13.4368487 42.4332695,13.4833984 C42.1332634,13.5299481 41.7902546,13.5532227 41.4042328,13.5532227 C40.7412822,13.5532227 40.1549154,13.438966 39.6451148,13.2104492 C39.1353142,12.9819325 38.7451023,12.6624369 38.4744674,12.2519531 C38.2038326,11.8414693 38.0685172,11.3738633 38.0685172,10.8491211 C38.0685172,9.74039159 38.6391496,8.89193002 39.7804316,8.30371094 C39.5202864,8.0074855 39.3178378,7.69327966 39.1730796,7.36108398 C39.0283214,7.02888831 38.9559434,6.65332241 38.9559434,6.234375 C38.9559434,5.55728828 39.2150357,5.01985876 39.7332281,4.62207031 C40.2514204,4.22428187 40.963662,4.02539062 41.8699742,4.02539062 C42.7553069,4.02539062 43.4444714,4.22322393 43.9374885,4.61889648 C44.4305055,5.01456904 44.6770103,5.55305649 44.6770103,6.234375 C44.6770103,6.70410391 44.5437928,7.13891402 44.2773538,7.53881836 C44.0109148,7.9387227 43.5902832,8.31428861 43.0154463,8.66552734 L44.2679131,9.86523438 C44.5826049,9.3785783 44.8007878,8.82845359 44.9224686,8.21484375 L47.4777527,8.21484375 C47.351876,8.79883104 47.1536232,9.38386751 46.8829883,9.9699707 C46.6123534,10.5560739 46.307107,11.0585917 45.9672399,11.4775391 L47.9812569,13.4262695 L44.7965926,13.4262695 Z M40.6049198,10.6713867 C40.6049198,10.9379896 40.6993259,11.1559236 40.8881409,11.3251953 C41.0769559,11.494467 41.3266076,11.5791016 41.6371035,11.5791016 C41.8762692,11.5791016 42.0860605,11.5473636 42.2664838,11.4838867 C42.446907,11.4204098 42.5853693,11.3484705 42.6818748,11.2680664 L41.1210116,9.66845703 C40.7769487,9.92659634 40.6049198,10.2609029 40.6049198,10.6713867 Z M42.4615917,6.234375 C42.4615917,6.02701719 42.4018011,5.87784876 42.2822183,5.78686523 C42.1626354,5.69588171 42.0126346,5.65039062 41.8322114,5.65039062 C41.655984,5.65039062 41.5017874,5.70328723 41.3696168,5.80908203 C41.2374463,5.91487683 41.171362,6.08414597 41.171362,6.31689453 C41.171362,6.63427893 41.3559784,6.96223789 41.7252167,7.30078125 C41.9643824,7.16536391 42.1469009,7.00350029 42.2727776,6.81518555 C42.3986543,6.6268708 42.4615917,6.43326922 42.4615917,6.234375 Z M54.1506225,13.4262695 L51.7023331,13.4262695 L51.7023331,4.14599609 L57.1401789,4.14599609 L57.1401789,6.15820312 L54.1506225,6.15820312 L54.1506225,7.92919922 L56.9073082,7.92919922 L56.9073082,9.94140625 L54.1506225,9.94140625 L54.1506225,13.4262695 Z M63.8375046,13.4262695 L58.3744836,13.4262695 L58.3744836,4.14599609 L63.8375046,4.14599609 L63.8375046,6.15820312 L60.8605358,6.15820312 L60.8605358,7.61816406 L63.6172215,7.61816406 L63.6172215,9.63037109 L60.8605358,9.63037109 L60.8605358,11.3823242 L63.8375046,11.3823242 L63.8375046,13.4262695 Z M70.6355312,13.4262695 L65.1725101,13.4262695 L65.1725101,4.14599609 L70.6355312,4.14599609 L70.6355312,6.15820312 L67.6585623,6.15820312 L67.6585623,7.61816406 L70.4152481,7.61816406 L70.4152481,9.63037109 L67.6585623,9.63037109 L67.6585623,11.3823242 L70.6355312,11.3823242 L70.6355312,13.4262695 Z M71.9705367,13.4262695 L71.9705367,4.14599609 L74.4565889,4.14599609 L74.4565889,11.4013672 L78,11.4013672 L78,13.4262695 L71.9705367,13.4262695 Z" fill="#555D67"></path>
4
+ </g>
5
+ </svg>
admin/blocks/sidebar/seo/editor.scss ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ // Header
3
+ .edit-post-header {
4
+ .edit-post-pinned-plugins button .seo-button {
5
+ stroke: none !important;
6
+ > * {
7
+ stroke: none !important;
8
+ }
9
+ }
10
+ }
11
+ }
admin/blocks/sidebar/seo/media/icon.svg ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <svg width="24px" height="17px" viewBox="0 0 24 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
+ <g id="Artboard Copy 3--Artboard-Copy-3" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
3
+ <path d="M6.72535927,10.9169435 C6.72535927,11.5193829 6.57430291,12.0542612 6.27218565,12.5215947 C5.97006839,12.9889281 5.53441308,13.3521582 4.96520665,13.6112957 C4.39600022,13.8704332 3.72828731,14 2.96204788,14 C2.32278528,14 1.78642572,13.9545962 1.35295313,13.8637874 C0.919480545,13.7729785 0.468500677,13.6146191 0,13.3887043 L0,11.0498339 C0.494771743,11.3067565 1.00923907,11.5071975 1.54341741,11.6511628 C2.07759575,11.7951281 2.56798163,11.8671096 3.01458975,11.8671096 C3.39989872,11.8671096 3.68230844,11.7995577 3.86182739,11.6644518 C4.04134634,11.5293459 4.13110447,11.3554828 4.13110447,11.1428571 C4.13110447,11.0099661 4.0949823,10.8936882 4.02273687,10.7940199 C3.95049144,10.6943517 3.83446264,10.5935775 3.67464698,10.4916944 C3.51483133,10.3898112 3.08902752,10.1816184 2.39722279,9.86710963 C1.77109571,9.57917907 1.30150745,9.30011209 0.988443916,9.02990033 C0.67538038,8.75968857 0.443322777,8.44961415 0.292264148,8.09966777 C0.141205518,7.7497214 0.0656773366,7.33555056 0.0656773366,6.85714286 C0.0656773366,5.96234326 0.387493068,5.26467581 1.03113418,4.7641196 C1.6747753,4.26356339 2.55922126,4.01328904 3.68449858,4.01328904 C4.67842058,4.01328904 5.69203067,4.24584485 6.72535927,4.71096346 L5.9306635,6.73754153 C5.03306874,6.32114963 4.25808392,6.11295681 3.60568578,6.11295681 C3.26854043,6.11295681 3.0233475,6.17275688 2.87009961,6.2923588 C2.71685173,6.41196073 2.64022893,6.56035349 2.64022893,6.73754153 C2.64022893,6.92801867 2.73764934,7.0985596 2.93249308,7.24916944 C3.12733682,7.39977927 3.65603409,7.67441661 4.51860076,8.0730897 C5.34613934,8.44961429 5.92081029,8.85381844 6.24263085,9.28571429 C6.5644514,9.71761013 6.72535927,10.2613478 6.72535927,10.9169435 Z M13.6222302,13.8671096 L7.9214374,13.8671096 L7.9214374,4.15282392 L13.6222302,4.15282392 L13.6222302,6.25913621 L10.5156922,6.25913621 L10.5156922,7.78737542 L13.3923595,7.78737542 L13.3923595,9.89368771 L10.5156922,9.89368771 L10.5156922,11.7275748 L13.6222302,11.7275748 L13.6222302,13.8671096 Z M24,8.99667774 C24,10.6312374 23.6037507,11.8737499 22.8112402,12.7242525 C22.0187297,13.5747551 20.8584417,14 19.3303414,14 C17.8241336,14 16.6693186,13.5725403 15.8658619,12.717608 C15.0624051,11.8626757 14.6606827,10.6179484 14.6606827,8.9833887 C14.6606827,7.36654784 15.0602159,6.13178721 15.8592941,5.27906977 C16.6583724,4.42635233 17.819755,4 19.3434768,4 C20.8715772,4 22.029676,4.4230301 22.8178079,5.26910299 C23.6059399,6.11517588 24,7.35768837 24,8.99667774 Z M17.3928599,8.99667774 C17.3928599,10.874871 18.0386806,11.8139535 19.3303414,11.8139535 C19.987118,11.8139535 20.4742201,11.5858273 20.7916621,11.1295681 C21.1091042,10.6733089 21.2678228,9.96235256 21.2678228,8.99667774 C21.2678228,8.02657322 21.1069149,7.31007983 20.7850944,6.84717608 C20.4632738,6.38427233 19.9827394,6.15282392 19.3434768,6.15282392 C18.0430591,6.15282392 17.3928599,7.10076571 17.3928599,8.99667774 Z" id="Artboard Copy 3--SEO" fill="#555D67"></path>
4
+ </g>
5
+ </svg>
admin/blocks/sidebar/settings/editor.scss ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ // Header
3
+ .edit-post-header {
4
+ .edit-post-pinned-plugins button .settings-button {
5
+ stroke: none !important;
6
+ > * {
7
+ stroke: none !important;
8
+ }
9
+ }
10
+ }
11
+ }
admin/blocks/sidebar/settings/media/icon.svg ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <svg width="62px" height="17px" viewBox="0 0 62 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
+ <g id="Artboard Copy 4--Artboard-Copy-4" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
3
+ <path d="M6.73913043,10.912841 C6.73913043,11.516082 6.58776476,12.0516721 6.28502887,12.5196274 C5.98229298,12.9875827 5.5457456,13.3512961 4.97537364,13.6107784 C4.40500168,13.8702608 3.73592152,14 2.96811311,14 C2.32754152,14 1.79008369,13.9545358 1.35572351,13.8636061 C0.921363317,13.7726764 0.469460001,13.6141063 0,13.3878909 L0,11.0459082 C0.495784861,11.3031727 1.01130563,11.5038804 1.54657779,11.6480373 C2.08184994,11.7921941 2.57323995,11.8642715 3.02076257,11.8642715 C3.40686051,11.8642715 3.68984851,11.7966296 3.86973505,11.661344 C4.0496216,11.5260583 4.13956352,11.3519638 4.13956352,11.1390552 C4.13956352,11.0059874 4.10336738,10.8895547 4.03097401,10.7897538 C3.95858065,10.6899529 3.84231426,10.5890446 3.68217136,10.4870259 C3.52202847,10.3850073 3.09535276,10.1765374 2.40213145,9.86161011 C1.77472229,9.57329641 1.30417248,9.29385808 0.990467901,9.02328676 C0.67676332,8.75271544 0.444230546,8.44222841 0.292862602,8.09181637 C0.141494658,7.74140432 0.0658118206,7.32668237 0.0658118206,6.84763806 C0.0658118206,5.95164777 0.388286517,5.25305196 1.03324558,4.75182967 C1.67820465,4.25060739 2.56446164,4 3.69204314,4 C4.68800034,4 5.70368594,4.23286527 6.73913043,4.69860279 L5.9428074,6.72787758 C5.04337469,6.3109316 4.26680297,6.10246174 3.61306895,6.10246174 C3.27523325,6.10246174 3.02953824,6.16234138 2.87597656,6.28210246 C2.72241488,6.40186354 2.64563519,6.55045376 2.64563519,6.72787758 C2.64563519,6.91860818 2.74325508,7.08937605 2.93849779,7.24018629 C3.1337405,7.39099654 3.66352036,7.66599933 4.52785326,8.06520293 C5.35708635,8.44222854 5.93293402,8.84697056 6.25541355,9.27944112 C6.57789309,9.71191168 6.73913043,10.2563729 6.73913043,10.912841 Z M13.6501237,13.8669328 L7.93765771,13.8669328 L7.93765771,4.13972056 L13.6501237,4.13972056 L13.6501237,6.24883566 L10.5372246,6.24883566 L10.5372246,7.77910845 L13.4197824,7.77910845 L13.4197824,9.88822355 L10.5372246,9.88822355 L10.5372246,11.7245509 L13.6501237,11.7245509 L13.6501237,13.8669328 Z M19.2909489,13.8669328 L16.691382,13.8669328 L16.691382,6.28875582 L14.3419,6.28875582 L14.3419,4.13972056 L21.6338497,4.13972056 L21.6338497,6.28875582 L19.2909489,6.28875582 L19.2909489,13.8669328 Z M27.2351878,13.8669328 L24.6356209,13.8669328 L24.6356209,6.28875582 L22.2861389,6.28875582 L22.2861389,4.13972056 L29.5780886,4.13972056 L29.5780886,6.28875582 L27.2351878,6.28875582 L27.2351878,13.8669328 Z M30.6647358,13.8669328 L30.6647358,4.13972056 L33.2774651,4.13972056 L33.2774651,13.8669328 L30.6647358,13.8669328 Z M44.2293042,13.8669328 L40.8202518,13.8669328 L37.3059006,7.01397206 L37.24667,7.01397206 C37.330032,8.09182176 37.3717124,8.91461238 37.3717124,9.4823686 L37.3717124,13.8669328 L35.0682987,13.8669328 L35.0682987,4.13972056 L38.4641887,4.13972056 L41.9653775,10.8995343 L42.0048646,10.8995343 C41.9434399,9.91926766 41.9127281,9.13196128 41.9127281,8.53759148 L41.9127281,4.13972056 L44.2293042,4.13972056 L44.2293042,13.8669328 Z M49.8832917,8.17165669 L54.0360176,8.17165669 L54.0360176,13.4145043 C52.9084361,13.8048367 51.6689925,14 50.3176497,14 C48.8346826,14 47.6884715,13.5653182 46.8789821,12.6959415 C46.0694926,11.8265647 45.664754,10.5868344 45.664754,8.97671324 C45.664754,7.40651244 46.1078825,6.18452422 46.9941528,5.31071191 C47.880423,4.4368996 49.1220603,4 50.7191018,4 C51.3245736,4 51.8960338,4.05766188 52.4334997,4.17298736 C52.9709656,4.28831284 53.4393217,4.4346853 53.8385821,4.61210912 L53.0159343,6.6746507 C52.322713,6.32867425 51.5614973,6.15568862 50.7322642,6.15568862 C49.9732307,6.15568862 49.3864145,6.40518713 48.971798,6.90419162 C48.5571814,7.40319611 48.3498763,8.11620739 48.3498763,9.04324684 C48.3498763,9.95254391 48.5374381,10.6455953 48.9125673,11.1224218 C49.2876966,11.5992483 49.828445,11.837658 50.5348287,11.837658 C50.9209267,11.837658 51.2763069,11.799956 51.6009802,11.7245509 L51.6009802,10.2009315 L49.8832917,10.2009315 L49.8832917,8.17165669 Z M62,10.912841 C62,11.516082 61.8486343,12.0516721 61.5458984,12.5196274 C61.2431625,12.9875827 60.8066152,13.3512961 60.2362432,13.6107784 C59.6658712,13.8702608 58.9967911,14 58.2289827,14 C57.5884111,14 57.0509533,13.9545358 56.6165931,13.8636061 C56.1822329,13.7726764 55.7303296,13.6141063 55.2608696,13.3878909 L55.2608696,11.0459082 C55.7566544,11.3031727 56.2721752,11.5038804 56.8074474,11.6480373 C57.3427195,11.7921941 57.8341095,11.8642715 58.2816321,11.8642715 C58.6677301,11.8642715 58.9507181,11.7966296 59.1306046,11.661344 C59.3104912,11.5260583 59.4004331,11.3519638 59.4004331,11.1390552 C59.4004331,11.0059874 59.3642369,10.8895547 59.2918436,10.7897538 C59.2194502,10.6899529 59.1031838,10.5890446 58.9430409,10.4870259 C58.782898,10.3850073 58.3562223,10.1765374 57.663001,9.86161011 C57.0355919,9.57329641 56.565042,9.29385808 56.2513375,9.02328676 C55.9376329,8.75271544 55.7051001,8.44222841 55.5537322,8.09181637 C55.4023642,7.74140432 55.3266814,7.32668237 55.3266814,6.84763806 C55.3266814,5.95164777 55.6491561,5.25305196 56.2941152,4.75182967 C56.9390742,4.25060739 57.8253312,4 58.9529127,4 C59.9488699,4 60.9645555,4.23286527 62,4.69860279 L61.203677,6.72787758 C60.3042443,6.3109316 59.5276725,6.10246174 58.8739385,6.10246174 C58.5361028,6.10246174 58.2904078,6.16234138 58.1368461,6.28210246 C57.9832844,6.40186354 57.9065048,6.55045376 57.9065048,6.72787758 C57.9065048,6.91860818 58.0041246,7.08937605 58.1993674,7.24018629 C58.3946101,7.39099654 58.9243899,7.66599933 59.7887228,8.06520293 C60.6179559,8.44222854 61.1938036,8.84697056 61.5162831,9.27944112 C61.8387627,9.71191168 62,10.2563729 62,10.912841 Z" id="Artboard Copy 4--SETTINGS" fill="#555D67"></path>
4
+ </g>
5
+ </svg>
admin/blocks/sidebar/templates/editor.scss ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Header
2
+ .edit-post-header {
3
+ button[aria-label="Page Templates"] {
4
+ position: absolute;
5
+ left: 4px;
6
+ top: 10px;
7
+
8
+ &.is-toggled svg *,
9
+ svg * {
10
+ stroke: none !important;
11
+ path { stroke: none !important; }
12
+ }
13
+
14
+ &:hover {
15
+ &.is-toggled svg *,
16
+ svg * {
17
+ stroke: none !important;
18
+ path { stroke: none !important; }
19
+ }
20
+ }
21
+ }
22
+
23
+ .layout--header--show-template-button {
24
+ svg {
25
+ display: inherit;
26
+ stroke: none !important;
27
+ path {
28
+ stroke: none !important;
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ // Sidebar
35
+ .edit-post-sidebar {
36
+
37
+ .components-panel {
38
+
39
+ div[data-component="sidebar--available-blocks"] {
40
+ .template-thumb-button {
41
+ position: relative;
42
+ display: block;
43
+ margin: 10px 0;
44
+ text-decoration: none;
45
+ button {
46
+ transition: all 0.6s $easeOutQuart;
47
+ position: absolute;
48
+ bottom: 10px;
49
+ right: 20px;
50
+ opacity: 0;
51
+ }
52
+ img {
53
+ margin: 0 auto;
54
+ display: inherit;
55
+ }
56
+ /* ---- hover ---- */
57
+ &:hover {
58
+ button {
59
+ opacity: 1;
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ }
admin/blocks/sidebar/templates/media/add.svg ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <svg focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
2
+ <path d="M10 1c-5 0-9 4-9 9s4 9 9 9 9-4 9-9-4-9-9-9zm0 16c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm1-11H9v3H6v2h3v3h2v-3h3V9h-3V6z"></path>
3
+ </svg>
admin/config.settings.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * plugin config file.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
17
+
18
+ $icon = Plugin::is_active() ? 'dashicons-lock' : 'dashicons-unlock';
19
+ $cdnURL = 'https://cdn.pixelthrone.com/';
20
+
21
+ return [
22
+ /**
23
+ * Plugin.
24
+ */
25
+ 'plugin' => [
26
+ 'slug' => 'coming-soon-blocks',
27
+ 'name' => 'Coming Soon Blocks for Gutenberg',
28
+ 'version' => '1.0.0',
29
+ 'PluginURI' => 'https://pixelthrone.com/coming-soon-blocks',
30
+ 'WP.OrgURI' => '#plugin-wp-org-url',
31
+ ],
32
+ /**
33
+ * Meta keys.
34
+ */
35
+ 'meta_keys' => [
36
+ 'seo' => 'comingsoonblocks_seo',
37
+ 'settings' => 'comingsoonblocks_settings',
38
+ 'lookandfeel' => 'comingsoonblocks_lookandfeel',
39
+ 'selected_page_id' => 'comingsoonblocks_selected_page_id',
40
+ ],
41
+ /**
42
+ * Cdn.
43
+ */
44
+ 'cdn' => [
45
+ 'media' => $cdnURL.'media/coming-soon-blocks/',
46
+ 'notices' => $cdnURL.'notices/coming-soon-blocks/',
47
+ ],
48
+ /**
49
+ * 3rd-Party plugins.
50
+ */
51
+ '3party' => [
52
+ 'gutenberg' => [
53
+ 'slug' => 'gutenberg',
54
+ 'name' => 'gutenberg',
55
+ 'base' => 'gutenberg/gutenberg.php',
56
+ ]
57
+ ],
58
+ /**
59
+ * Post Type.
60
+ */
61
+ 'post_type' => [
62
+ 'menu_icon' => $icon,
63
+ 'label' => esc_html__( 'Coming Soon', 'coming-soon-blocks' ),
64
+ 'labels' => [
65
+ 'name' => esc_html__( 'Coming Soon', 'coming-soon-blocks' ),
66
+ 'singular_name' => esc_html__( 'Page', 'coming-soon-blocks' ),
67
+ 'menu_name' => esc_html__( 'Coming Soon', 'coming-soon-blocks' ),
68
+ 'parent_item_colon' => esc_html__( 'Page', 'coming-soon-blocks' ),
69
+ 'all_items' => esc_html__( 'All Pages', 'coming-soon-blocks' ),
70
+ 'view_item' => esc_html__( 'View Pages', 'coming-soon-blocks' ),
71
+ 'add_new_item' => esc_html__( 'Add new', 'coming-soon-blocks' ),
72
+ 'add_new' => esc_html__( 'Add new', 'coming-soon-blocks' ),
73
+ 'edit_item' => esc_html__( 'Edit Pages', 'coming-soon-blocks' ),
74
+ 'update_item' => esc_html__( 'Update', 'coming-soon-blocks' ),
75
+ 'search_items' => esc_html__( 'Search pages', 'coming-soon-blocks' ),
76
+ 'not_found' => esc_html__( 'No pages found', 'coming-soon-blocks' ),
77
+ 'not_found_in_trash' => esc_html__( 'No pages found in Trash', 'coming-soon-blocks' ),
78
+ ],
79
+ 'supports' => [ 'title', 'revisions', 'editor' ],
80
+ 'hierarchical' => true,
81
+ 'public' => true,
82
+ 'show_ui' => true,
83
+ 'show_in_nav_menus' => false,
84
+ 'show_in_admin_bar' => true,
85
+ 'menu_position' => 20,
86
+ 'can_export' => true,
87
+ 'has_archive' => true,
88
+ 'show_in_rest' => true,
89
+ 'exclude_from_search' => true,
90
+ 'publicly_queryable' => true,
91
+ 'capability_type' => 'page',
92
+ ],
93
+ /**
94
+ * toolbar.
95
+ */
96
+ 'toolbar' => [
97
+ [
98
+ 'id' => 'pt_comingsoonblocks_toolbar_group',
99
+ 'title' => '<i class="dashicons-before '.$icon.'"></i>',
100
+ 'href' => get_admin_url( null, 'edit.php?post_type=coming-soon-blocks' ),
101
+ 'meta' => [ 'class' => '' ]
102
+ ],
103
+ [
104
+ 'id' => 'pt_comingsoonblocks_toolbar_status',
105
+ 'title' => esc_html__( 'Coming is active', 'coming-soon-blocks' ),
106
+ 'href' => get_admin_url( null, 'edit.php?post_type=coming-soon-blocks' ),
107
+ 'parent' => 'pt_comingsoonblocks_toolbar_group'
108
+ ],
109
+ [
110
+ 'id' => 'pt_comingsoonblocks_toolbar_add-new',
111
+ 'title' => sprintf( esc_html__( '%s Add Coming soon', 'coming-soon-blocks' ), '<i class="dashicons-before dashicons-plus"></i>' ),
112
+ 'href' => get_admin_url( null, 'post-new.php?post_type=coming-soon-blocks' ),
113
+ 'parent' => 'pt_comingsoonblocks_toolbar_group'
114
+ ],
115
+ [
116
+ 'id' => 'pt_comingsoonblocks_toolbar_settings',
117
+ 'title' => sprintf( esc_html__( '%s Settings', 'coming-soon-blocks' ), '<i class="dashicons-before dashicons-admin-generic"></i>' ),
118
+ 'href' => get_admin_url( null, 'edit.php?post_type=coming-soon-blocks' ),
119
+ 'parent' => 'pt_comingsoonblocks_toolbar_group'
120
+ ],
121
+ [
122
+ 'id' => 'pt_comingsoonblocks_toolbar_contact-us',
123
+ 'title' => esc_html__( 'Contact Us', 'coming-soon-blocks' ),
124
+ 'href' => csblocks_fs()->contact_url(),
125
+ 'parent' => 'pt_comingsoonblocks_toolbar_group',
126
+ 'meta' => [ 'target' => '_blank' ]
127
+ ],
128
+ [
129
+ 'id' => 'pt_comingsoonblocks_toolbar_support-forum',
130
+ 'title' => esc_html__( 'Support Forum', 'coming-soon-blocks' ),
131
+ 'href' => csblocks_fs()->get_support_forum_url(),
132
+ 'parent' => 'pt_comingsoonblocks_toolbar_group',
133
+ 'meta' => [ 'target' => '_blank' ]
134
+ ],
135
+ [
136
+ 'id' => 'pt_comingsoonblocks_toolbar_upgrade',
137
+ 'title' => csblocks_fs()->is_free_plan() ? esc_html__( 'Upgrade', 'coming-soon-blocks' ) : esc_html__( 'Pricing', 'coming-soon-blocks' ),
138
+ 'href' => csblocks_fs()->pricing_url(),
139
+ 'parent' => 'pt_comingsoonblocks_toolbar_group',
140
+ ],
141
+ ]
142
+ ];
admin/dashboard/Init.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Init gutenberg blocks.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ namespace Pixelthrone\ComingSoon_Blocks\Dashboard;
12
+
13
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
14
+ use Pixelthrone\ComingSoon_Blocks\Utils;
15
+
16
+ // Exit if accessed directly.
17
+ if ( ! defined( 'ABSPATH' ) ) {
18
+ exit;
19
+ }
20
+
21
+ /**
22
+ * Main dashboard class
23
+ *
24
+ * @since 1.0.0
25
+ */
26
+ class Init {
27
+ /**
28
+ * Plugin url.
29
+ *
30
+ * @var string $plugin_url
31
+ */
32
+ private $url;
33
+
34
+ /**
35
+ * Plugin slug.
36
+ *
37
+ * @var string $slug
38
+ */
39
+ private $slug;
40
+
41
+ /**
42
+ * Plugin slug.
43
+ *
44
+ * @var string $slug
45
+ */
46
+ private $version;
47
+
48
+ /**
49
+ * Plugin settings.
50
+ *
51
+ * @var string $settings
52
+ */
53
+ private $settings;
54
+
55
+ /**
56
+ * Blocks manifest.
57
+ *
58
+ * @var array
59
+ */
60
+ private $blocks;
61
+
62
+ /**
63
+ * Constructor.
64
+ *
65
+ * @since 1.0.0
66
+ * @return void
67
+ */
68
+ public
69
+ function __construct() {
70
+ global $pagenow;
71
+
72
+ $this->slug = Plugin::get_slug();
73
+ $this->url = Plugin::get_plugin_url();
74
+ $this->version = Plugin::get_version();
75
+ $this->settings = Plugin::get_settings();
76
+
77
+ if ( Plugin::has_gutenberg() && Utils\is_post_type_page( Plugin::get_slug() ) && $pagenow === 'edit.php' ) {
78
+
79
+
80
+ add_action( 'admin_footer', function () {
81
+ // echo '<div id="plugin-dashboard"></div>';
82
+ } );
83
+
84
+ add_action( 'enqueue_block_editor_assets', [ $this, 'localization' ] );
85
+ add_action( 'admin_init', [ $this, 'load_dashboard_assets' ] );
86
+ }
87
+
88
+ add_action( 'init', [ $this, 'init' ], 100 );
89
+ //add_action( 'admin_menu', [ $this, 'admin_menu' ] );
90
+ }
91
+
92
+ /**
93
+ * Init backend & frontend code.
94
+ *
95
+ * @access public
96
+ */
97
+ public
98
+ function init() {
99
+ /**
100
+ * Register post type.
101
+ */
102
+ register_post_type( $this->slug, $this->settings['post_type'] );
103
+ /**
104
+ * Enqueue global assets.
105
+ */
106
+ wp_enqueue_style( $this->slug . '-global', $this->url . '/public/dist/global.bundle.css', [], $this->version );
107
+ }
108
+
109
+ /**
110
+ * Register a custom menu page.
111
+ *
112
+ * @access public
113
+ */
114
+ public
115
+ function admin_menu() {}
116
+
117
+ /**
118
+ * Enqueue dashboard assets.
119
+ *
120
+ * @access public
121
+ */
122
+ public
123
+ function load_dashboard_assets() {
124
+ wp_enqueue_style( 'wp-components' );
125
+ wp_enqueue_style( 'wp-editor' );
126
+ wp_enqueue_style( $this->slug . '-dashboard', $this->url . '/public/dist/dashboard.bundle.css', [
127
+ 'wp-components',
128
+ 'wp-editor'
129
+ ], $this->version );
130
+
131
+ wp_enqueue_script( 'wp-components' );
132
+ wp_enqueue_script( 'wp-editor' );
133
+ wp_enqueue_script( 'wp-i18n' );
134
+ wp_enqueue_script( 'wp-api' );
135
+ wp_enqueue_script( $this->slug . '-dashboard', $this->url . '/public/dist/dashboard.bundle.js', [
136
+ 'wp-i18n',
137
+ 'wp-components',
138
+ 'wp-editor',
139
+ 'wp-api',
140
+ ], $this->version, true );
141
+ }
142
+
143
+ /**
144
+ * Enqueue Jed-formatted localization data.
145
+ *
146
+ * @access public
147
+ */
148
+ public
149
+ function localization() {}
150
+ }
151
+
152
+ new Init();
153
+
coming-soon-blocks.php ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Coming Soon Blocks
4
+ * Plugin URI: https://pixelthrone.com/coming-soon-blocks
5
+ * Description: Coming Soon Page, Under Construction & Maintenance Mode plugin for WordPress + Gutenberg
6
+ * Author: Helder Vilela from Pixelthrone
7
+ * Author URI: https://heldervilela.com
8
+ * Tags: gutenberg, editor, block, layout, coming Soon, under Construction, maintenance
9
+ * Version: 1.0.0
10
+ * Stable tag: 1.0.0
11
+ * Text Domain: coming-soon-blocks
12
+ * Domain Path: languages
13
+ * Tested up to: 5.0.0
14
+ *
15
+ * Coming Soon Blocks is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License
21
+ * along with Coming Soon Blocks. If not, see <http://www.gnu.org/licenses/>.
22
+ *
23
+ * @package @@pkg.package
24
+ * @author Helder Vilela from Pixelthrone
25
+ * @license GPL-3.0
26
+ */
27
+
28
+ namespace Pixelthrone\ComingSoon_Blocks;
29
+
30
+ // Exit if accessed directly.
31
+ if ( ! defined( 'ABSPATH' ) ) {
32
+ exit;
33
+ }
34
+
35
+ /**
36
+ * Load freemius.
37
+ *
38
+ * @since 1.0.0
39
+ */
40
+ if ( function_exists( 'csblocks_fs' ) ) {
41
+ csblocks_fs()->set_basename( true, __FILE__ );
42
+ return;
43
+ }
44
+
45
+ require_once( plugin_dir_path( __FILE__ ) . '/lib/freemius.php' );
46
+
47
+ /**
48
+ * Initialize Class.
49
+ *
50
+ * @since 1.0.0
51
+ */
52
+ final
53
+ class Initialize {
54
+ /**
55
+ * Global Files to include.
56
+ *
57
+ * @since 1.0.0
58
+ * @return array
59
+ */
60
+ private $global_files = [
61
+ 'lib/Plugin.php',
62
+ 'lib/Utils.php',
63
+ 'lib/Gutenberg_Checker.php',
64
+ 'admin/dashboard/Init.php',
65
+ 'admin/Toolbar.php',
66
+ 'admin/blocks/Init.php',
67
+ 'admin/api/UnlockPage.php',
68
+ 'frontend/init.php',
69
+ ];
70
+
71
+ /**
72
+ * Admin Files to include.
73
+ *
74
+ * @since 1.0.0
75
+ * @return array
76
+ */
77
+ private $admin_files = [];
78
+
79
+ /**
80
+ * Constructor.
81
+ *
82
+ * @since 1.0.0
83
+ * @return void
84
+ */
85
+ public
86
+ function __construct() {
87
+
88
+ /**
89
+ * Add a check for our plugin before redirecting
90
+ */
91
+ register_activation_hook( __FILE__, function () {
92
+ add_option( 'pt_comingsoonblocks_do_activation_redirect', true );
93
+ } );
94
+ /**
95
+ * Initialize after plugins loaded
96
+ */
97
+ add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
98
+ /**
99
+ * Admin Initialize
100
+ */
101
+ //add_action( 'admin_init', [ $this, 'admin_init' ] );
102
+ /**
103
+ * Global Initialize
104
+ */
105
+ add_action( 'init', [ $this, 'init' ] );
106
+ add_action( 'after_setup_theme', [ $this, 'after_setup_theme' ] );
107
+
108
+ }
109
+
110
+ /**
111
+ * Called once any activated plugins have been loaded
112
+ *
113
+ * @return void
114
+ */
115
+ public
116
+ function plugins_loaded() {
117
+ $this->autoload();
118
+ }
119
+
120
+ /**
121
+ * Fires after WordPress has finished loading
122
+ *
123
+ * @return void
124
+ */
125
+ public
126
+ function init() {
127
+ /**
128
+ * Loads the plugin language files
129
+ */
130
+ load_plugin_textdomain( 'coming-soon-blocks', false, dirname( plugin_basename( plugin_dir_path( __FILE__ ) ) ) . '/languages/' );
131
+ }
132
+
133
+ /**
134
+ * This hook is called during each page load, after the theme is initialized
135
+ *
136
+ * @return void
137
+ */
138
+ public
139
+ function after_setup_theme() {
140
+ /**
141
+ * Loads the plugin language files
142
+ */
143
+ add_image_size( 'csblocks_bg_image', 1920, 1280 );
144
+ }
145
+
146
+ /**
147
+ * Triggered before any other hook when a user accesses the admin area
148
+ *
149
+ * @return void
150
+ */
151
+ public
152
+ function admin_init() {}
153
+
154
+ /**
155
+ * Include required files.
156
+ *
157
+ * @access private
158
+ * @since 1.0.0
159
+ * @return void
160
+ */
161
+ private
162
+ function autoload() {
163
+
164
+ // Global
165
+ foreach ( $this->global_files as $file ) {
166
+ require_once( plugin_dir_path( __FILE__ ) . $file );
167
+ }
168
+
169
+ // Admin only
170
+ if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
171
+ foreach ( $this->admin_files as $file ) {
172
+ require_once( plugin_dir_path( __FILE__ ) . $file );
173
+ }
174
+ }
175
+
176
+ }
177
+
178
+ /**
179
+ * Throw error on object clone.
180
+ *
181
+ * The whole idea of the singleton design pattern is that there is a single
182
+ * object therefore, we don't want the object to be cloned.
183
+ *
184
+ * @since 1.0.0
185
+ * @access protected
186
+ * @return void
187
+ */
188
+ public
189
+ function __clone() {
190
+ // Cloning instances of the class is forbidden.
191
+ _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'coming-soon-blocks' ), '1.0' );
192
+ }
193
+
194
+ /**
195
+ * Disable unserializing of the class.
196
+ *
197
+ * @since 1.0.0
198
+ * @access protected
199
+ * @return void
200
+ */
201
+ public
202
+ function __wakeup() {
203
+ // Unserializing instances of the class is forbidden.
204
+ _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'coming-soon-blocks' ), '1.0' );
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Init plugin.
210
+ *
211
+ * @since 1.0.0
212
+ */
213
+ new Initialize();
frontend/components/block-background-overlayer.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Block background overlayer.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ if( $overlayOpacity !== 0 ):;
12
+ ?>
13
+ <div data-component="block-background-overlayer"
14
+ style="background-color: <?php echo esc_attr($overlayColor) ?>; opacity: <?php echo esc_attr($overlayOpacity/100) ?>;"
15
+ ></div>
16
+ <?php endif; ?>
frontend/components/block-background.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Block background.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+ use Pixelthrone\ComingSoon_Blocks\Utils;
11
+
12
+ $background = json_decode($background);
13
+ //var_dump($image);
14
+ //var_dump($background);
15
+ ?>
16
+ <div data-component="block-background">
17
+ <?php
18
+ switch ($background->type) {
19
+ /**
20
+ * Color.
21
+ *
22
+ * @since 1.0.0
23
+ */
24
+ case 'color':
25
+ ?>
26
+ <div class="color-element" style="background-color: <?php echo $background->color ?>"></div>
27
+ <?php
28
+ echo '';
29
+ break;
30
+ /**
31
+ * Image.
32
+ *
33
+ * @since 1.0.0
34
+ */
35
+ case 'image':
36
+ if( ! empty($background->image) ):
37
+ $image = $background->image->id ? wp_get_attachment_image_src( $background->image->id, 'csblocks_bg_image')[0] : $background->image->full;
38
+ ?>
39
+ <div class="image-element">
40
+ <span style="background-image: url('<?php echo esc_url($image); ?>')"></span>
41
+ </div>
42
+ <?php
43
+ endif;
44
+ break;
45
+ /**
46
+ * Gallery.
47
+ *
48
+ * @since 1.0.0
49
+ */
50
+ case 'gallery':
51
+ ?>
52
+ <div class="gallery-element" data-component="slideshow-background">
53
+ <div>
54
+ <?php
55
+ foreach ($background->gallery as $img ):
56
+ $image = wp_get_attachment_image_src( $img->id, 'csblocks_bg_image');
57
+ ?>
58
+ <span><img src="<?php echo esc_url($image[0]) ?>"/></span>
59
+ <?php endforeach; ?>
60
+ </div>
61
+ </div>
62
+ <?php
63
+ break;
64
+ /**
65
+ * Video.
66
+ *
67
+ * @since 1.0.0
68
+ */
69
+ case 'video':
70
+ if( ! empty($background->video) ):
71
+ $image = $background->image->id ? wp_get_attachment_image_src( $background->image->id, 'csblocks_bg_image')[0] : '';
72
+ ?>
73
+ <div class="video-element">
74
+ <video playsinline autoPlay loop muted poster="<?php echo esc_url($image); ?>">
75
+ <source src="<?php echo esc_url($background->video->url); ?>" type="video/mp4">
76
+ </video>
77
+ </div>
78
+ <?php
79
+ endif;
80
+ break;
81
+ }
82
+ ?>
83
+ </div>
frontend/components/cookie-notice.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Cookie notice component.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ use Pixelthrone\ComingSoon_Blocks\Utils;
12
+
13
+ if( isset($_COOKIE['comingsoonblocks__cookie_notice']) && $_COOKIE['comingsoonblocks__cookie_notice'] === 'true') {
14
+ return true;
15
+ }
16
+
17
+ ?>
18
+ <div data-component="cookie-notice" class="<?php echo $notalone ? '-not-alone' : ''; ?>">
19
+ <p><?php echo Utils\esc_allowed_html( '<b>We use <u>cookies</u></b> to ensure that we give you the best experience on our website.<br> If you continue to use this page we will assume that you are happy with it.', 'coming-soon-blocks' ); ?></p>
20
+ <button><?php esc_html_e( 'Got it, Thanks!', 'coming-soon-blocks' );?></button>
21
+ </div>
frontend/components/social-icons.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Social widget component.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+ if( empty($networks)) {
11
+ return;
12
+ }
13
+
14
+ $networks = json_decode( $networks );
15
+ ?>
16
+ <div data-component="social-icons">
17
+ <?php foreach( $networks as $network ):?>
18
+ <a href="<?php echo esc_url($network->url); ?>" target="_blank" class="-icon -<?php echo esc_attr($network->icon); ?>"><i class="socicon-<?php echo esc_attr($network->icon); ?>"></i></a>
19
+ <?php endforeach; ?>
20
+ </div>
frontend/components/unlock-page.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Unlock page button component.
4
+ *
5
+ * @since 1.0.0
6
+ *
7
+ * @package Coming Soon Blocks
8
+ * @author Helder Vilela from Pixelthrone
9
+ * @link Helder Vilela from Pixelthrone_uri
10
+ * @license GPL-3.0
11
+ */
12
+ use Pixelthrone\ComingSoon_Blocks\Utils;
13
+ $button_bg = ( isset($button_bg) && ! empty($button_bg) ) ? "style='background-color:{$button_bg};'" : '';
14
+ ?>
15
+ <div data-component="unlock-page" data-mode="close" data-message="false" data-loading="false">
16
+ <a href="#" class="button">
17
+ <?php Utils\loadSVG('icon--password-protected'); ?>
18
+ <i></i>
19
+ <span <?php echo $button_bg; ?>></span>
20
+ </a>
21
+ <div class="content__wrapper">
22
+ <span><p></p></span>
23
+ <p><?php esc_html_e( 'This site is password protected, view by typing the password.', 'coming-soon-blocks' ); ?></p>
24
+ <input type="password" name="password" placeholder="∙∙∙∙∙∙">
25
+ <i></i>
26
+ </div>
27
+
28
+ <span class="page-overlayer"></span>
29
+ </div>
frontend/init.php ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Main class to manage frontend view.
5
+ *
6
+ * @package Coming Soon Blocks
7
+ * @author Helder Vilela from Pixelthrone
8
+ * @link Helder Vilela from Pixelthrone_uri
9
+ * @license GPL-3.0
10
+ */
11
+ namespace Pixelthrone\ComingSoon_Blocks\Frontend;
12
+
13
+ use Pixelthrone\ComingSoon_Blocks\Utils ;
14
+ use Pixelthrone\ComingSoon_Blocks\Plugin ;
15
+ use WP_Error ;
16
+ // Exit if accessed directly.
17
+ if ( !defined( 'ABSPATH' ) ) {
18
+ exit;
19
+ }
20
+ /**
21
+ * Frontend Class
22
+ *
23
+ * @since 1.0.0
24
+ */
25
+ class Init
26
+ {
27
+ /**
28
+ * Coming soon status.
29
+ *
30
+ * @var string $status
31
+ */
32
+ private $status ;
33
+ /**
34
+ * Class constructor.
35
+ */
36
+ public function __construct()
37
+ {
38
+ // Only run on frontend
39
+ if ( is_admin() ) {
40
+ return;
41
+ }
42
+ // Check if plugin is active
43
+
44
+ if ( Plugin::is_active() ) {
45
+ add_action( 'template_redirect', [ $this, 'template_redirect' ] );
46
+ // Disable the rest api in coming soon mode
47
+
48
+ if ( apply_filters( 'pixelthrone/coming-soon-blocks/only_allow_logged_in_rest_access', false ) ) {
49
+ $current_WP_version = get_bloginfo( 'version' );
50
+ if ( version_compare( $current_WP_version, '4.7', '>=' ) ) {
51
+ add_filter( 'rest_authentication_errors', array( &$this, 'only_allow_logged_in_rest_access' ) );
52
+ }
53
+ }
54
+
55
+ }
56
+
57
+ }
58
+
59
+ /**
60
+ * Build page.
61
+ *
62
+ * @since 1.0.0
63
+ * @access public
64
+ *
65
+ * @return string.
66
+ */
67
+ public function template_redirect()
68
+ {
69
+ $pageSettings = Plugin::get_frontend_settings();
70
+ // Check if page exist
71
+ $post = get_post( $pageSettings->selected_page_id );
72
+ // print_r( "<pre>" );
73
+ // print_r( $pageSettings );
74
+ // print_r( "</pre>" );
75
+ /**
76
+ * Verify if the page has the correct status.
77
+ *
78
+ * @since 1.0.0
79
+ */
80
+ if ( !$post || $post->post_status !== 'publish' ) {
81
+ return false;
82
+ }
83
+ /**
84
+ * Exit if a custom login page.
85
+ *
86
+ * @since 1.0.0
87
+ */
88
+ if ( preg_match( "/login|admin|dashboard|account/i", $_SERVER['REQUEST_URI'] ) > 0 ) {
89
+ return false;
90
+ }
91
+ /**
92
+ * Check if user is logged in and roles.
93
+ *
94
+ * @since 1.0.0
95
+ */
96
+ if ( $pageSettings->settings->loginBypass && is_user_logged_in() ) {
97
+ if ( current_user_can( 'activate_plugins' ) ) {
98
+ return false;
99
+ }
100
+ }
101
+ /**
102
+ * Redirect Mode.
103
+ *
104
+ * @since 1.0.0
105
+ */
106
+ if ( $pageSettings->settings->redirectMode ) {
107
+ if ( !empty($pageSettings->settings->redirectUrl) ) {
108
+ wp_redirect( $pageSettings->settings->redirectUrl, 301 );
109
+ }
110
+ }
111
+ /**
112
+ * Change the page header.
113
+ *
114
+ * @since 1.0.0
115
+ */
116
+ if ( $pageSettings->seo->serviceUnavailable ) {
117
+ $this->set_maintenance_headers();
118
+ }
119
+ /**
120
+ * Page plugins cache.
121
+ *
122
+ * @since 1.0.0
123
+ */
124
+ if ( $pageSettings->seo->noCache ) {
125
+ $this->disable_caching();
126
+ }
127
+ include_once Plugin::get_plugin_dir() . '/frontend/template.php';
128
+ exit;
129
+ }
130
+
131
+ /**
132
+ * Add maintenance headers.
133
+ *
134
+ * @since 1.0.0
135
+ * @access public
136
+ *
137
+ * @return void.
138
+ */
139
+ public function set_maintenance_headers()
140
+ {
141
+ header( 'HTTP/1.1 503 Service Temporarily Unavailable' );
142
+ header( 'Status: 503 Service Temporarily Unavailable' );
143
+ header( 'Retry-After: 86400' );
144
+ // retry in a day
145
+ }
146
+
147
+ /**
148
+ * Disable caching plugins.
149
+ * - W3 Total Cache
150
+ * - WP Super Cache
151
+ * - ZenCache (Previously QuickCache)
152
+ *
153
+ * @since 1.0.0
154
+ * @access public
155
+ *
156
+ * @return string.
157
+ */
158
+ public function disable_caching()
159
+ {
160
+
161
+ if ( apply_filters( 'pixelthrone/coming-soon-blocks/disable_caching', true ) ) {
162
+ $define = function ( $name, $value ) {
163
+ if ( !defined( $name ) ) {
164
+ define( $name, $value );
165
+ }
166
+ };
167
+ $define( 'DONOTCACHEPAGE', true );
168
+ $define( 'DONOTCDN', true );
169
+ $define( 'DONOTCACHEDB', true );
170
+ $define( 'DONOTMINIFY', true );
171
+ $define( 'DONOTCACHEOBJECT', true );
172
+ nocache_headers();
173
+ }
174
+
175
+ }
176
+
177
+ /**
178
+ * Add maintenance headers.
179
+ *
180
+ * @since 1.0.0
181
+ * @access public
182
+ *
183
+ * @return void.
184
+ */
185
+ public function only_allow_logged_in_rest_access( $access )
186
+ {
187
+ if ( !is_user_logged_in() ) {
188
+ return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'coming-soon-blocks' ), [
189
+ 'status' => rest_authorization_required_code(),
190
+ ] );
191
+ }
192
+ return $access;
193
+ }
194
+
195
+ }
196
+ if ( Plugin::has_gutenberg() && !is_admin() ) {
197
+ new Init();
198
+ }
frontend/template.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Pixelthrone\ComingSoon_Blocks\Plugin ;
4
+ use Pixelthrone\ComingSoon_Blocks\Utils ;
5
+ // Exit if accessed directly.
6
+ if ( !defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+ $pageConfig = Plugin::get_frontend_settings();
10
+ $page = get_post( $pageConfig->selected_page_id );
11
+ ?>
12
+ <!doctype html>
13
+ <html>
14
+ <head>
15
+ <meta charset="utf-8">
16
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
17
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
18
+ <meta name="apple-mobile-web-app-capable" content="yes">
19
+ <!-- Site info -->
20
+ <?php
21
+ $tile = ( !empty($pageConfig->seo->title) ? esc_html( $pageConfig->seo->title ) : $page->post_title );
22
+ echo '<title>' . $tile . '</title>' ;
23
+ echo ( !empty($pageConfig->seo->description) ? "\r\n\t" . '<meta name="description" content="' . esc_attr( $pageConfig->seo->description ) . '">' : '' ) ;
24
+ echo ( !empty($pageConfig->seo->keywords) ? "\r\n\t" . '<meta name="keywords" content="' . esc_attr( $pageConfig->seo->keywords ) . '">' : '' ) ;
25
+ echo ( !empty($pageConfig->seo->author) ? "\r\n\t" . '<meta name="author" content="' . esc_attr( $pageConfig->seo->author ) . '">' : '' ) ;
26
+ echo ( !empty($pageConfig->seo->copyright) ? "\r\n\t" . '<meta name="copyright" content="' . esc_attr( $pageConfig->seo->copyright ) . '">' : '' ) ;
27
+ echo ( !empty($pageConfig->seo->serviceUnavailable) ? "\r\n\t" . '<meta name="robots" content="noindex,nofollow" />' : "\r\n\t" . '<meta name="robots" content="index, follow" />' ) ;
28
+ echo ( !empty($pageConfig->seo->noCache) ? "\r\n\t" . '<meta http-equiv="cache-control" content="no-cache"/>' : '' ) ;
29
+ ?>
30
+
31
+ <!-- Facebook -->
32
+ <?php
33
+ echo ( !empty($pageConfig->seo->facebook->title) ? '<meta property="og:title" content="' . esc_attr( $pageConfig->seo->facebook->title ) . '">' : '' ) ;
34
+ echo ( !empty($pageConfig->seo->facebook->description) ? "\r\n\t" . '<meta property="og:description" content="' . esc_attr( $pageConfig->seo->facebook->title ) . '">' : '' ) ;
35
+ echo ( !empty($pageConfig->seo->facebook->cover->url) ? "\r\n\t" . '<meta property="og:image" content="' . esc_url( $pageConfig->seo->facebook->cover->url ) . '">' : '' ) ;
36
+ ?>
37
+
38
+ <!-- Twitter -->
39
+ <?php
40
+ echo ( !empty($pageConfig->seo->twitter->title) ? '<meta property="twitter:title" content="' . esc_attr( $pageConfig->seo->twitter->title ) . '">' : '' ) ;
41
+ echo ( !empty($pageConfig->seo->twitter->description) ? "\r\n\t" . '<meta property="twitter:description" content="' . esc_attr( $pageConfig->seo->twitter->title ) . '">' : '' ) ;
42
+ echo ( !empty($pageConfig->seo->twitter->cover->url) ? "\r\n\t" . '<meta property="twitter:image" content="' . esc_url( $pageConfig->seo->twitter->cover->url ) . '">' : '' ) ;
43
+ ?>
44
+
45
+ <!-- Icons -->
46
+ <?php
47
+ echo ( !empty($pageConfig->lookandfeel->favicon->url) ? '<link rel="icon" href="' . esc_url( $pageConfig->lookandfeel->favicon->url ) . '">' : '' ) ;
48
+ ?>
49
+
50
+ <!-- LOAD MAIN STYLE -->
51
+ <link rel="stylesheet" href="<?php
52
+ echo Plugin::get_plugin_url( '/public/dist/blocks.style.bundle.css' ) ;
53
+ ?>">
54
+ <link rel="stylesheet" href="<?php
55
+ echo Plugin::get_plugin_url( '/public/dist/frontend.bundle.css' ) ;
56
+ ?>">
57
+
58
+ </head>
59
+
60
+ <body data-nonce="<?php
61
+ echo wp_create_nonce( 'wp_rest' ) ;
62
+ ?>"
63
+ data-restURL="<?php
64
+ echo esc_url_raw( rest_url() ) ;
65
+ ?>"
66
+ >
67
+
68
+ <?php
69
+ /**
70
+ * Page Content
71
+ *
72
+ * @since 1.0.0
73
+ */
74
+ echo do_blocks( $page->post_content ) ;
75
+ /**
76
+ * Cookie Notice
77
+ *
78
+ * @since 1.0.0
79
+ */
80
+
81
+ if ( $pageConfig->settings->cookieNotice ) {
82
+ $notalone = false;
83
+ Utils\component( 'cookie-notice', [
84
+ 'notalone' => $notalone,
85
+ ] );
86
+ }
87
+
88
+ /**
89
+ * Global site tag (gtag.js) - Google Analytics
90
+ *
91
+ * @since 1.0.0
92
+ */
93
+
94
+ if ( !empty($pageConfig->settings->googleAnalytics) ) {
95
+ ?>
96
+ <script async src="https://www.googletagmanager.com/gtag/js?id=UA-54038527-1"></script>
97
+ <script>
98
+ window.dataLayer = window.dataLayer || [];
99
+ function gtag(){dataLayer.push(arguments);}
100
+ gtag('js', new Date());
101
+ gtag('config', '<?php
102
+ echo esc_html( $pageConfig->settings->googleAnalytics ) ;
103
+ ?>');
104
+ </script>
105
+ <?php
106
+ }
107
+
108
+ /**
109
+ * Print blocks CSS
110
+ *
111
+ * @since 1.0.0
112
+ */
113
+
114
+ if ( !empty(Utils\page_css( 'get' )) ) {
115
+ $pageCSS = implode( Utils\page_css( 'get' ), '' );
116
+ echo "<style id='blocks-css-compiled'>{$pageCSS}</style>" ;
117
+ }
118
+
119
+ /**
120
+ * Load google fonts
121
+ *
122
+ * @since 1.0.0
123
+ */
124
+ $pageFonts = Utils\page_fonts( 'get' );
125
+ if ( !empty($pageFonts) ) {
126
+ foreach ( $pageFonts as $font => $variants ) {
127
+ $font = str_replace( " ", "+", $font );
128
+ $variants = implode( $variants, ',' );
129
+ echo "<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family={$font}:{$variants}\" id=\"font-preview-acme\">" ;
130
+ }
131
+ }
132
+ ?>
133
+
134
+ <!-- Scripts -->
135
+ <script src="<?php
136
+ echo Plugin::get_plugin_url( '/public/dist/frontend.bundle.js' ) ;
137
+ ?>"></script>
138
+
139
+ </body>
140
+ </html>
languages/coming-soon-blocks.pot ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2018 coming-soon-blocks
2
+ # This file is distributed under the same license as the coming-soon-blocks package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: coming-soon-blocks\n"
6
+ "MIME-Version: 1.0\n"
7
+ "Content-Type: text/plain; charset=UTF-8\n"
8
+ "Content-Transfer-Encoding: 8bit\n"
9
+ "Language-Team: PixelThrone\n"
10
+ "Last-Translator: Helder Vilela from Pixelthrone\n"
11
+ "Report-Msgid-Bugs-To: support@pixelthrone.com\n"
12
+ "X-Poedit-Basepath: ..\n"
13
+ "X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
14
+ "X-Poedit-SearchPath-0: .\n"
15
+ "X-Poedit-SearchPathExcluded-0: *.js\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
18
+
19
+ #: coming-soon-blocks.php:178, coming-soon-blocks.php:191
20
+ msgid "Cheatin&#8217; huh?"
21
+ msgstr ""
22
+
23
+ #: admin/config.settings.php:63, admin/config.settings.php:65, admin/config.settings.php:67
24
+ msgid "Coming Soon"
25
+ msgstr ""
26
+
27
+ #: admin/config.settings.php:66, admin/config.settings.php:68
28
+ msgid "Page"
29
+ msgstr ""
30
+
31
+ #: admin/config.settings.php:69
32
+ msgid "All Pages"
33
+ msgstr ""
34
+
35
+ #: admin/config.settings.php:70
36
+ msgid "View Pages"
37
+ msgstr ""
38
+
39
+ #: admin/config.settings.php:71, admin/config.settings.php:72
40
+ msgid "Add new"
41
+ msgstr ""
42
+
43
+ #: admin/config.settings.php:73
44
+ msgid "Edit Pages"
45
+ msgstr ""
46
+
47
+ #: admin/config.settings.php:74
48
+ msgid "Update"
49
+ msgstr ""
50
+
51
+ #: admin/config.settings.php:75
52
+ msgid "Search pages"
53
+ msgstr ""
54
+
55
+ #: admin/config.settings.php:76
56
+ msgid "No pages found"
57
+ msgstr ""
58
+
59
+ #: admin/config.settings.php:77
60
+ msgid "No pages found in Trash"
61
+ msgstr ""
62
+
63
+ #: admin/config.settings.php:105
64
+ msgid "Coming is active"
65
+ msgstr ""
66
+
67
+ #: admin/config.settings.php:111
68
+ msgid "%s Add Coming soon"
69
+ msgstr ""
70
+
71
+ #: admin/config.settings.php:117
72
+ msgid "%s Settings"
73
+ msgstr ""
74
+
75
+ #: admin/config.settings.php:123
76
+ msgid "Contact Us"
77
+ msgstr ""
78
+
79
+ #: admin/config.settings.php:130
80
+ msgid "Support Forum"
81
+ msgstr ""
82
+
83
+ #: admin/config.settings.php:137
84
+ msgid "Upgrade"
85
+ msgstr ""
86
+
87
+ #: admin/config.settings.php:137
88
+ msgid "Pricing"
89
+ msgstr ""
90
+
91
+ #: frontend/init.php:236
92
+ msgid "Only authenticated users can access the REST API."
93
+ msgstr ""
94
+
95
+ #. translators: Name of this pluign
96
+ #: lib/Gutenberg_Checker.php:135
97
+ msgid "deactivate %1$s"
98
+ msgstr ""
99
+
100
+ #. translators: 1: Required plugin 2: Name of this plugin 3: Activate or Install, from $link above
101
+ #. translators: 1: Required plugin 2: Name of this pluign 3: Activate or Install, from $link above
102
+ #: lib/Gutenberg_Checker.php:140, lib/Gutenberg_Checker.php:173
103
+ msgid "%1$s requires the %2$s block editor. %4$s Please %3$s to continue."
104
+ msgstr ""
105
+
106
+ #. translators: Name of this pluign
107
+ #: lib/Gutenberg_Checker.php:162
108
+ msgid "activate %1$s"
109
+ msgstr ""
110
+
111
+ #. translators: Name of this pluign
112
+ #: lib/Gutenberg_Checker.php:166
113
+ msgid "install %1$s"
114
+ msgstr ""
115
+
116
+ #: admin/api/UnlockPage.php:77, admin/api/UnlockPage.php:106
117
+ msgid "No naughty business please!"
118
+ msgstr ""
119
+
120
+ #: admin/api/UnlockPage.php:91
121
+ msgid "The page will be updated."
122
+ msgstr ""
123
+
124
+ #: admin/api/UnlockPage.php:101
125
+ msgid "The password is not correct."
126
+ msgstr ""
127
+
128
+ #: frontend/components/cookie-notice.php:20
129
+ msgid "Got it, Thanks!"
130
+ msgstr ""
131
+
132
+ #: frontend/components/unlock-page.php:23
133
+ msgid "This site is password protected, view by typing the password."
134
+ msgstr ""
lib/Footer_Text.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Modifies the "Thank you" text displayed in the admin footer
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ // Exit if accessed directly.
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Generates a link.
18
+ */
19
+ class Footer_Text {
20
+
21
+ /**
22
+ * Constructor
23
+ */
24
+ public function __construct() {
25
+ add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
26
+ }
27
+
28
+ /**
29
+ * Admin footer text.
30
+ *
31
+ * @since 1.0.0
32
+ * @access public
33
+ *
34
+ * @param string $footer_text The content that will be printed.
35
+ *
36
+ * @return string The content that will be printed.
37
+ */
38
+ public function admin_footer_text( $footer_text ) {
39
+ global $pagenow, $post_type;
40
+
41
+ if ( ! in_array( $pagenow, array( 'edit.php' ), true ) ) {
42
+ return $footer_text;
43
+ }
44
+
45
+ $footer_text = sprintf(
46
+ /* translators: 1: Block Architect, 2: Link to plugin review */
47
+ __( 'Enjoying %1$s? Please leave a %2$s rating — we appreciate your support!', 'block-gallery' ),
48
+ 'Block Gallery',
49
+ '<a href="' . esc_url( BLOCKGALLERY_REVIEW_URL ) . '" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
50
+ );
51
+
52
+ return $footer_text;
53
+ }
54
+ }
55
+
56
+ new Block_Gallery_Footer_Text();
lib/Gutenberg_Checker.php ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Check for Gutenberg.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ namespace Pixelthrone\ComingSoon_Blocks\Lib\Gutenberg_Checker;
12
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
13
+
14
+ // Exit if accessed directly.
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit;
17
+ }
18
+
19
+ /**
20
+ * Notice Class
21
+ *
22
+ * @since 1.0.0
23
+ */
24
+ class Gutenberg_Checker {
25
+
26
+ /**
27
+ * Gutenberg check.
28
+ *
29
+ * @var string $has_gutenberg
30
+ */
31
+ public $has_gutenberg = false;
32
+
33
+ /**
34
+ * Gutenberg base.
35
+ *
36
+ * @var string $gutenberg_base
37
+ */
38
+ public $gutenberg_base;
39
+
40
+ /**
41
+ * Gutenberg slug.
42
+ *
43
+ * @var string $gutenberg_slug
44
+ */
45
+ public $gutenberg_slug = 'gutenberg';
46
+
47
+ /**
48
+ * Classic Editor check.
49
+ *
50
+ * @var string $has_classic_editor
51
+ */
52
+ public $has_classic_editor;
53
+
54
+ /**
55
+ * Classic Editor slug.
56
+ *
57
+ * @var string $classic_editor_slug
58
+ */
59
+ public $classic_editor_slug = 'classic-editor';
60
+
61
+ /**
62
+ * Classic Editor base.
63
+ *
64
+ * @var string $classic_editor_base
65
+ */
66
+ public $classic_editor_base;
67
+
68
+ /**
69
+ * Setup the activation class.
70
+ *
71
+ * @access public
72
+ * @since 1.0.0
73
+ * @return void
74
+ */
75
+ public
76
+ function __construct() {
77
+ add_action( 'admin_init', array( $this, 'admin_init' ));
78
+ }
79
+
80
+ /**
81
+ * Check if plugins are installed.
82
+ *
83
+ * @access public
84
+ * @since 1.0.0
85
+ * @return void
86
+ */
87
+ public
88
+ function admin_init() {
89
+ $plugins = get_plugins();
90
+
91
+ // Check if Gutenberg is installed.
92
+ foreach( $plugins as $plugin_path => $plugin ) {
93
+ if( $plugin['TextDomain'] === $this->gutenberg_slug ) {
94
+ $this->has_gutenberg = true;
95
+ $this->gutenberg_base = $this->gutenberg_slug;
96
+ }
97
+ }
98
+
99
+ // Check if Classic Editor is installed.
100
+ foreach ( $plugins as $plugin_path => $plugin ) {
101
+ if( $plugin['TextDomain'] === $this->classic_editor_slug ) {
102
+ $this->has_classic_editor = true;
103
+ $this->classic_editor_base = $plugin_path;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Fire notices where needed
109
+ */
110
+ // Check if the Gutenberg plugin exists.
111
+ if ( ! function_exists( 'register_block_type' ) ) {
112
+ if(version_compare(get_bloginfo('version'),'5', '>=') ){
113
+ add_action( 'admin_notices', array( $this, 'wp5_notice' ) );
114
+ } else {
115
+ add_action( 'admin_notices', array( $this, 'wp4_notice' ) );
116
+ }
117
+ }
118
+
119
+ // Check if the Classic Editor plugin exists.
120
+ if ( function_exists( 'classic_editor_init_actions' ) && $this->has_classic_editor ) {
121
+ add_action( 'admin_notices', array( $this, 'classic_editor_notice' ) );
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Display notice if Gutenberg is not installed or activated.
127
+ *
128
+ * @access public
129
+ */
130
+ public function classic_editor_notice() {
131
+
132
+ $url = wp_nonce_url( admin_url( 'plugins.php?action=deactivate&plugin=' . Plugin::get_settings('3party', 'gutenberg', 'slug') ), 'deactivate-plugin_' . Plugin::get_settings('3party', 'gutenberg', 'name') );
133
+
134
+ /* translators: Name of this pluign */
135
+ $link = '<a class="button" href="' . esc_url( $url ) . '">' . sprintf( __( 'deactivate %1$s', 'coming-soon-blocks' ), 'Classic Editor' ) . '</a>';
136
+
137
+ $plugin = '<a href="http://wordpress.org/gutenberg" target="_blank">Gutenberg</a>';
138
+
139
+ /* translators: 1: Required plugin 2: Name of this plugin 3: Activate or Install, from $link above */
140
+ echo '<div class="notice notice-error"><p>' . sprintf( esc_html__( '%1$s requires the %2$s block editor. %4$s Please %3$s to continue.', 'coming-soon-blocks' ), '<strong>' . Plugin::get_settings('3party', 'gutenberg', 'name') . '</strong>', $plugin, $link, '<br>' ) . '</p></div>';
141
+ }
142
+
143
+ /**
144
+ * Display notice if Gutenberg is not installed or activated for wordpress 5
145
+ *
146
+ * @access public
147
+ */
148
+ public
149
+ function wp5_notice() {
150
+ }
151
+
152
+ /**
153
+ * Display notice if Gutenberg is not installed or activated.
154
+ *
155
+ * @access public
156
+ */
157
+ public
158
+ function wp4_notice() {
159
+ if ( $this->has_gutenberg ) {
160
+ $url = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . Plugin::get_settings('3party', 'gutenberg', 'base') ).'&plugin_status=all&paged=1', 'activate-plugin_' . Plugin::get_settings('3party', 'gutenberg', 'base') );
161
+ /* translators: Name of this pluign */
162
+ $link = '<a class="button" href="' . esc_url( $url ) . '">' . sprintf( __( 'activate %1$s', 'coming-soon-blocks' ), Plugin::get_settings('3party', 'gutenberg', 'name') ) . '</a>';
163
+ } else {
164
+ $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . Plugin::get_settings('3party', 'gutenberg', 'slug') ), 'install-plugin_' . Plugin::get_settings('3party', 'gutenberg', 'slug') );
165
+ /* translators: Name of this pluign */
166
+ $link = '<a class="button" href="' . esc_url( $url ) . '">' . sprintf( __( 'install %1$s', 'coming-soon-blocks' ), Plugin::get_settings('3party', 'gutenberg', 'name') ) . '</a>';
167
+ }
168
+
169
+ $plugin = '<a href="http://wordpress.org/gutenberg" target="_blank">'.Plugin::get_settings('3party', 'gutenberg', 'name').'</a>';
170
+
171
+ /* translators: 1: Required plugin 2: Name of this pluign 3: Activate or Install, from $link above */
172
+
173
+ echo '<div class="notice notice-error"><p>' . sprintf( esc_html__( '%1$s requires the %2$s block editor. %4$s Please %3$s to continue.', 'coming-soon-blocks' ), '<strong>' . Plugin::get_settings('plugin', 'name') . '</strong>', $plugin, $link, '<br>' ) . '</p></div>';
174
+ }
175
+ }
176
+
177
+ new Gutenberg_Checker();
178
+
179
+
180
+
lib/Plugin.php ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Core class.
4
+ *
5
+ * @package Coming Soon Blocks
6
+ * @author Helder Vilela from Pixelthrone
7
+ * @link Helder Vilela from Pixelthrone_uri
8
+ * @license GPL-3.0
9
+ */
10
+
11
+ namespace Pixelthrone\ComingSoon_Blocks;
12
+
13
+ // Exit if accessed directly.
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit;
16
+ }
17
+
18
+ /**
19
+ * Core class
20
+ *
21
+ * @since 1.0.0
22
+ */
23
+ class Plugin {
24
+
25
+ /**
26
+ * Plugin Path.
27
+ *
28
+ * @var array $settings
29
+ */
30
+ private static $settings;
31
+
32
+ /**
33
+ * Plugin Dir.
34
+ *
35
+ * @var string $PLUGIN_DIR
36
+ */
37
+ private static $PLUGIN_DIR;
38
+
39
+ /**
40
+ * Plugin URL.
41
+ *
42
+ * @var string $PLUGIN_URL
43
+ */
44
+ private static $PLUGIN_URL;
45
+
46
+ /**
47
+ * Plugin File.
48
+ *
49
+ * @var string $PLUGIN_FILE
50
+ */
51
+ private static $PLUGIN_FILE;
52
+
53
+ /**
54
+ * Plugin Base.
55
+ *
56
+ * @var string $PLUGIN_BASE
57
+ */
58
+ private static $PLUGIN_BASE;
59
+
60
+ /**
61
+ * Plugin slug.
62
+ *
63
+ * @var string $PLUGIN_SLUG
64
+ */
65
+ private static $PLUGIN_SLUG;
66
+
67
+ /**
68
+ * Plugin version.
69
+ *
70
+ * @var string $PLUGIN_VERSION
71
+ */
72
+ private static $PLUGIN_VERSION;
73
+
74
+ /**
75
+ * Gutenberg check.
76
+ *
77
+ * @var boolean $has_gutenberg
78
+ */
79
+ private static $has_gutenberg = true;
80
+
81
+ /**
82
+ * Classic Editor check.
83
+ *
84
+ * @var boolean $has_classic_editor
85
+ */
86
+ private static $has_classic_editor = false;
87
+
88
+ /**
89
+ * Meta key names.
90
+ *
91
+ * @var array $meta_key
92
+ */
93
+ private static $meta_key;
94
+
95
+ /**
96
+ * Page css style.
97
+ *
98
+ * @var array $page_CSS
99
+ */
100
+ public static $page_CSS;
101
+
102
+ /**
103
+ * Google fonts to load.
104
+ *
105
+ * @var array $google_fonts
106
+ */
107
+ public static $google_fonts;
108
+
109
+ /**
110
+ * Constructor.
111
+ */
112
+ public
113
+ function __construct() {
114
+ static::$PLUGIN_DIR = str_replace( "/lib", "", untrailingslashit( plugin_dir_path( __FILE__ ) ) );
115
+ static::$PLUGIN_URL = str_replace( "/lib", "", untrailingslashit( plugin_dir_url( __FILE__ ) ) );
116
+ static::$settings = include( static::$PLUGIN_DIR . '/admin/config.settings.php' );
117
+
118
+ static::$PLUGIN_FILE = plugin_dir_url( __FILE__ );
119
+ static::$PLUGIN_BASE = plugin_basename( __FILE__ );
120
+ static::$PLUGIN_SLUG = static::$settings['plugin']['slug'];
121
+ static::$PLUGIN_VERSION = static::$settings['plugin']['version'];
122
+ static::$meta_key = static::$settings['meta_keys'];
123
+
124
+ // Check if the Gutenberg plugin exists and is got to use
125
+ if ( ! function_exists( 'register_block_type' ) || function_exists( 'classic_editor_init_actions' ) ) {
126
+ static::$has_gutenberg = false;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Get plugin directory.
132
+ *
133
+ * @return string.
134
+ */
135
+ public static
136
+ function get_plugin_dir( $dir = '' ) {
137
+ return static::$PLUGIN_DIR . $dir;
138
+ }
139
+
140
+ /**
141
+ * Get plugin url.
142
+ *
143
+ * @return string.
144
+ */
145
+ public static
146
+ function get_plugin_url( $dir = '' ) {
147
+ return static::$PLUGIN_URL . $dir;
148
+ }
149
+
150
+ /**
151
+ * Get CDN url.
152
+ *
153
+ * @param string $file
154
+ * @param string $folder
155
+ *
156
+ * @return string.
157
+ */
158
+ public static
159
+ function get_cdn_url( $file, $folder='media' ) {
160
+ return static::$settings['cdn'][$folder] . $file;
161
+ }
162
+
163
+ /**
164
+ * Get plugin settings.
165
+ *
166
+ * @param string $first
167
+ * @param string $second
168
+ * @param string $third
169
+ *
170
+ * @return array.
171
+ */
172
+ public static
173
+ function get_settings( $first = null, $second = null, $third = null ) {
174
+ if ( $first ) {
175
+ if ( ! empty( $first ) && ! empty( $second ) && ! empty( $third ) ) {
176
+ return static::$settings[ $first ][ $second ][ $third ];
177
+ }
178
+ if ( ! empty( $first ) && ! empty( $second ) ) {
179
+ return static::$settings[ $first ][ $second ];
180
+ }
181
+ if ( ! empty( $first ) ) {
182
+ return static::$settings[ $first ];
183
+ }
184
+ } else {
185
+ return static::$settings;
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Get plugin slug
191
+ *
192
+ * @return string
193
+ */
194
+ public static
195
+ function get_slug() {
196
+ return static::$PLUGIN_SLUG;
197
+ }
198
+
199
+ /**
200
+ * Get plugin version
201
+ *
202
+ * @return string
203
+ */
204
+ public static
205
+ function get_version() {
206
+ return static::$PLUGIN_VERSION;
207
+ }
208
+
209
+ /**
210
+ * Check if gutenberg exist
211
+ *
212
+ * @return string
213
+ */
214
+ public static
215
+ function has_gutenberg() {
216
+ return static::$has_gutenberg;
217
+ }
218
+
219
+ /**
220
+ * Check if plugin is pro version
221
+ *
222
+ * @return string
223
+ */
224
+ public static
225
+ function is_pro() {
226
+ return static::$is_pro;
227
+ }
228
+
229
+ /**
230
+ * Get Meta Keys
231
+ *
232
+ * @return string
233
+ */
234
+ public static
235
+ function get_meta_key_name( $name ) {
236
+ return isset( static::$meta_key[ $name ] ) ? static::$meta_key[ $name ] : null;
237
+ }
238
+
239
+ /**
240
+ * Get site options & post meta
241
+ *
242
+ * @return string
243
+ */
244
+ public static
245
+ function get_option( $name, $post_id = null, $decode = false ) {
246
+ switch ( $name ) {
247
+ case 'selected_page_id':
248
+ return get_option( static::$meta_key['selected_page_id'], null );
249
+ break;
250
+ case 'settings':
251
+ $r = get_post_meta( $post_id, static::$meta_key['settings'], true );
252
+
253
+ return ! $decode ? $r : json_decode( $r );
254
+ break;
255
+ case 'seo':
256
+ $r = get_post_meta( $post_id, static::$meta_key['seo'], true );
257
+
258
+ return ! $decode ? $r : json_decode( $r );
259
+ break;
260
+ case 'lookandfeel':
261
+ $r = get_post_meta( $post_id, static::$meta_key['lookandfeel'], true );
262
+
263
+ return ! $decode ? $r : json_decode( $r );
264
+ break;
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Get site options & post meta
270
+ *
271
+ * @return void
272
+ */
273
+ public static
274
+ function update_option( $name, $post_id, $value ) {
275
+ switch ( $name ) {
276
+ case 'selected_page_id':
277
+ update_option( static::$meta_key['selected_page_id'], $value );
278
+ break;
279
+ case 'settings':
280
+ $value = json_decode( $value );
281
+ update_post_meta( $post_id, static::$meta_key['settings'], $value );
282
+ break;
283
+ case 'seo':
284
+ $value = json_decode( $value );
285
+ update_post_meta( $post_id, static::$meta_key['seo'], $value );
286
+ break;
287
+ case 'lookandfeel':
288
+ $value = json_decode( $value );
289
+ update_post_meta( $post_id, static::$meta_key['lookandfeel'], $value );
290
+ break;
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Check if coming soon is activated
296
+ *
297
+ * @return int
298
+ */
299
+ public static
300
+ function is_active() {
301
+ return get_option( 'comingsoonblocks_selected_page_id', null ) ? true : false;
302
+ }
303
+
304
+ /**
305
+ * Get frontend settings
306
+ *
307
+ * @return object
308
+ */
309
+ public static
310
+ function get_frontend_settings() {
311
+ $selected_page_id = static::get_option( 'selected_page_id' );
312
+
313
+ return (object) [
314
+ 'baseURL' => static::get_plugin_url(),
315
+ 'selected_page_id' => $selected_page_id,
316
+ 'settings' => static::get_option( 'settings', $selected_page_id, false ),
317
+ 'seo' => static::get_option( 'seo', $selected_page_id, false ),
318
+ 'lookandfeel' => static::get_option( 'lookandfeel', $selected_page_id, false ),
319
+ ];
320
+ }
321
+
322
+ /**
323
+ * Get script data.
324
+ *
325
+ * @return array
326
+ */
327
+ public static
328
+ function get_script_data() {
329
+ $settings = static::get_option( 'settings', get_the_ID() );
330
+ $seo = static::get_option( 'seo', get_the_ID() );
331
+ $lookandfeel = static::get_option( 'lookandfeel', get_the_ID() );
332
+
333
+ return [
334
+ 'baseURL' => static::get_plugin_url(),
335
+ 'time_format' => get_option( 'time_format' ),
336
+ 'settings' => $settings,
337
+ 'seo' => $seo,
338
+ 'lookandfeel' => $lookandfeel
339
+ ];
340
+ }
341
+ }
342
+
343
+ new Plugin();
lib/Utils.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin utilities functions.
4
+ *
5
+ * @package coming-soon-blocks
6
+ * @version 1.0.0
7
+ * @author Helder Vilela from Pixelthrone
8
+ * @license GPL-3.0
9
+ */
10
+ namespace Pixelthrone\ComingSoon_Blocks\Utils;
11
+ use Pixelthrone\ComingSoon_Blocks\Plugin;
12
+
13
+ /**
14
+ * Retrieve post meta field for a post.
15
+ *
16
+ * @since 1.5.0
17
+ *
18
+ * @param int $post_id Post ID.
19
+ * @param string $key Optional. The meta key to retrieve. By default, returns
20
+ * data for all keys. Default empty.
21
+ * @param bool $single Optional. Whether to return a single value. Default false.
22
+ * @return mixed Will be an array if $single is false. Will be value of meta data
23
+ * field if $single is true.
24
+ */
25
+ function get_admin_field( $ID, $key, $single = true ) {
26
+ return get_post_meta( $ID, $key, $single);
27
+ }
28
+
29
+ /**
30
+ * Check if the admin bar is showing and return a class
31
+ *
32
+ * @since 1.0.0
33
+ * @version 1.0
34
+ *
35
+ * @return string
36
+ */
37
+ function ui_admin_bar( $return = 'echo' ) {
38
+ $var = ( is_admin_bar_showing() ) ? '-admin-bar' : '';
39
+
40
+ if ( $return == 'echo' ) {
41
+ echo $var;
42
+ } else {
43
+ return $var;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Check current post type
49
+ *
50
+ * @since 1.0.0
51
+ * @version 1.0
52
+ *
53
+ * @return string
54
+ */
55
+ function is_post_type_page( $check=false ) {
56
+ global $pagenow;
57
+
58
+ if( isset($_GET['post_type']) && $_GET['post_type'] === $check ) {
59
+ return true;
60
+ }
61
+
62
+ if( isset($_GET['post']) && $pagenow === 'post.php' ) {
63
+ $post = get_post( $_GET['post'] );
64
+ if( $post->post_type === 'coming-soon-blocks') {
65
+ return true;
66
+ }
67
+ }
68
+
69
+ return false;
70
+ }
71
+ /**
72
+ * Get current post type
73
+ *
74
+ * @since 1.0.0
75
+ * @version 1.0
76
+ *
77
+ * @return string
78
+ */
79
+ function get_post_type() {
80
+ global $pagenow;
81
+
82
+ if ('post.php' == $pagenow && isset($_GET['post']) ) {
83
+ $post_type = get_post_type($_GET['post']);
84
+ return $post_type;
85
+ }
86
+
87
+ if ( 'post-new.php' == $pagenow && isset($_GET['post_type']) ) {
88
+ return $_GET['post_type'];
89
+ }
90
+
91
+ return null;
92
+ }
93
+
94
+ /**
95
+ * Get html component
96
+ *
97
+ * @since 1.0.0
98
+ * @access public
99
+ *
100
+ * @param $name
101
+ * @param $args
102
+ *
103
+ * @return string
104
+ */
105
+ function component( $name, $args = [] ) {
106
+ if( ! empty($args) && is_array( $args ) ) {
107
+ extract( $args ); // @codingStandardsIgnoreLine
108
+ }
109
+ include Plugin::get_plugin_dir( '/frontend/components/' . $name . '.php' );
110
+ }
111
+
112
+ /**
113
+ * Esc string with allowed html
114
+ *
115
+ * @since 1.0.0
116
+ * @access public
117
+ *
118
+ * @param $name
119
+ * @param $args
120
+ *
121
+ * @return string
122
+ */
123
+ function esc_allowed_html( $string ) {
124
+ $allowed_html = [
125
+ 'a' => [
126
+ 'href' => [],
127
+ 'title' => [],
128
+ 'target' => [],
129
+ 'class' => [],
130
+ ],
131
+ 'p' => [
132
+ 'class' => [],
133
+ ],
134
+ 'strong' => [],
135
+ 'em' =>[],
136
+ 'u' =>[],
137
+ 'b' =>[],
138
+ 'br' =>[]
139
+ ];
140
+
141
+ return wp_kses($string, $allowed_html);
142
+ }
143
+
144
+ /**
145
+ * Load SVG Icon
146
+ *
147
+ * @since 1.0.0
148
+ * @version 1.0
149
+ *
150
+ * @param $svg_name
151
+ *
152
+ * @return string
153
+ */
154
+ function loadSVG( $svg_name, $return = false, $path = '/public/svg/' ) {
155
+ if ( $return ) {
156
+ ob_start();
157
+ include Plugin::get_plugin_dir($path . $svg_name . '.svg');
158
+ $contents = ob_get_contents();
159
+ ob_end_clean();
160
+
161
+ return $contents;
162
+ } else {
163
+ include Plugin::get_plugin_dir($path . $svg_name . '.svg');
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Encrypt string
169
+ *
170
+ * @since 1.0.0
171
+ * @version 1.0
172
+ *
173
+ * @param $string
174
+ *
175
+ * @return string
176
+ */
177
+ function encrypt( $string ) {
178
+ return md5($string.AUTH_KEY);
179
+ }
180
+
181
+ /**
182
+ * Encrypt string
183
+ *
184
+ * @since 1.0.0
185
+ * @version 1.0
186
+ *
187
+ * @param $string
188
+ *
189
+ * @return string
190
+ */
191
+ function check_encrypt( $plain_string, $encrypted_string ) {
192
+ return md5($plain_string.AUTH_KEY) === $encrypted_string;
193
+ }
194
+
195
+ /**
196
+ * Build block css
197
+ *
198
+ * @since 1.0.0
199
+ * @version 1.0
200
+ *
201
+ * @param $typo
202
+ * @param $className
203
+ *
204
+ * @return string
205
+ */
206
+ function compile_block_css( $blockID, $typo, $className ) {
207
+
208
+ $fontStyle = 'normal';
209
+ $fontweight = $typo->desktop->fontweight;
210
+
211
+ if (strpos($fontweight, 'italic') !== false) {
212
+ $fontweight = str_replace("italic", "", $fontweight); // Remove italic
213
+ $fontweight = $fontweight ? $fontweight : 'normal'; // Check if is empty
214
+ $fontStyle = 'italic';
215
+ }
216
+ if (strpos($fontweight, 'regular') !== false) {
217
+ $fontweight = 'normal';
218
+ }
219
+
220
+ return "main[data-blockid=\"{$blockID}\"] .-{$className} {
221
+ font-family: {$typo->fontfamily};
222
+ font-size: {$typo->desktop->fontsize}px;
223
+ font-weight: {$fontweight};
224
+ font-style: {$fontStyle};
225
+ line-height: {$typo->desktop->lineheight}%;
226
+ letter-spacing: {$typo->desktop->letterspacing}px;
227
+ }";
228
+ }
229
+
230
+ /**
231
+ * Add page CSS
232
+ *
233
+ * @since 1.0.0
234
+ * @version 1.0
235
+ *
236
+ * @param $action
237
+ * @param $CSS
238
+ *
239
+ * @return array
240
+ */
241
+ function page_css( $action, $CSS=null) {
242
+ if( $action === 'add' ) {
243
+ Plugin::$page_CSS[] = $CSS;
244
+ } else {
245
+ return Plugin::$page_CSS;
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Add page CSS
251
+ *
252
+ * @since 1.0.0
253
+ * @version 1.0
254
+ *
255
+ * @param $font
256
+ * @param $action
257
+ *
258
+ * @return array
259
+ */
260
+ function page_fonts( $action, $font=null ) {
261
+ if( $action === 'add' ) {
262
+ if( ! isset( Plugin::$google_fonts[$font->fontfamily][$font->desktop->fontweight] ) ) {
263
+ Plugin::$google_fonts[$font->fontfamily][$font->desktop->fontweight] = $font->desktop->fontweight;
264
+ }
265
+ if( ! isset( Plugin::$google_fonts[$font->fontfamily][$font->mobile->fontweight] ) ) {
266
+ Plugin::$google_fonts[$font->fontfamily][$font->mobile->fontweight] = $font->mobile->fontweight;
267
+ }
268
+ } else {
269
+ return Plugin::$google_fonts;
270
+ }
271
+ }
lib/freemius.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper function for easy freemius access.
5
+ *
6
+ * @package Coming Soon Blocks
7
+ * @author Helder Vilela from Pixelthrone
8
+ * @link Helder Vilela from Pixelthrone_uri
9
+ * @license GPL-3.0
10
+ */
11
+ // Create a helper function for easy SDK access.
12
+ if ( !function_exists( 'csblocks_fs' ) ) {
13
+ // Create a helper function for easy SDK access.
14
+ function csblocks_fs()
15
+ {
16
+ global $csblocks_fs ;
17
+
18
+ if ( !isset( $csblocks_fs ) ) {
19
+ // Activate multisite network integration.
20
+ if ( !defined( 'WP_FS__PRODUCT_2893_MULTISITE' ) ) {
21
+ define( 'WP_FS__PRODUCT_2893_MULTISITE', true );
22
+ }
23
+ // Include Freemius SDK.
24
+ require_once dirname( __FILE__ ) . '/freemius/start.php';
25
+ $csblocks_fs = fs_dynamic_init( array(
26
+ 'id' => '2893',
27
+ 'slug' => 'coming-soon-blocks',
28
+ 'type' => 'plugin',
29
+ 'public_key' => 'pk_b43d7d97999bfe621ba14d6a8647c',
30
+ 'is_premium' => false,
31
+ 'has_addons' => false,
32
+ 'has_paid_plans' => true,
33
+ 'trial' => array(
34
+ 'days' => 7,
35
+ 'is_require_payment' => true,
36
+ ),
37
+ 'menu' => array(
38
+ 'slug' => 'edit.php?post_type=coming-soon-blocks',
39
+ ),
40
+ 'is_live' => true,
41
+ ) );
42
+ }
43
+
44
+ return $csblocks_fs;
45
+ }
46
+
47
+ }
48
+ // Init Freemius.
49
+ csblocks_fs();
50
+ // Signal that SDK was initiated.
51
+ do_action( 'csblocks_fs_loaded' );
52
+ // Core overrides.
53
+ csblocks_fs()->override_i18n( array(
54
+ 'symbol_arrow-left' => '',
55
+ 'symbol_arrow-right' => '',
56
+ ) );
lib/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 h3 .dashicons{width:26px;height:26px;font-size:1.3em}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .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}#fs_account_details .button-group{float:right}.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 code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}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_sites .fs-scrollable-table .fs-table-body{max-height:200px;overflow:auto;border:1px solid #e5e5e5}#fs_sites .fs-scrollable-table .fs-table-body>table.widefat{border:none !important}#fs_sites .fs-scrollable-table .fs-main-column{width:100%}#fs_sites .fs-scrollable-table .fs-site-details td:first-of-type{text-align:right;color:grey;width:1px}#fs_sites .fs-scrollable-table .fs-site-details td:last-of-type{text-align:right}#fs_sites .fs-scrollable-table .fs-install-details table tr td{width:1px;white-space:nowrap}#fs_sites .fs-scrollable-table .fs-install-details table tr td:last-of-type{width:auto}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#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}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}
lib/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}}
lib/freemius/assets/css/admin/affiliation.css ADDED
@@ -0,0 +1 @@
 
1
+ @charset "UTF-8";#fs_affiliation_content_wrapper #messages{margin-top:25px}#fs_affiliation_content_wrapper h3{font-size:24px;padding:0;margin-left:0}#fs_affiliation_content_wrapper ul li{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;list-style-type:none}#fs_affiliation_content_wrapper ul li:before{content:'✓';margin-right:10px;font-weight:bold}#fs_affiliation_content_wrapper p:not(.description),#fs_affiliation_content_wrapper li,#fs_affiliation_content_wrapper label{font-size:16px !important;line-height:26px !important}#fs_affiliation_content_wrapper .button{margin-top:20px;margin-bottom:7px;line-height:35px;height:40px;font-size:16px}#fs_affiliation_content_wrapper .button#cancel_button{margin-right:5px}#fs_affiliation_content_wrapper form .input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form .input-container .input-label{font-weight:bold;display:block;width:100%}#fs_affiliation_content_wrapper form .input-container.input-container-text label,#fs_affiliation_content_wrapper form .input-container.input-container-text input,#fs_affiliation_content_wrapper form .input-container.input-container-text textarea{display:block}#fs_affiliation_content_wrapper form .input-container #add_domain,#fs_affiliation_content_wrapper form .input-container .remove-domain{text-decoration:none;display:inline-block;margin-top:3px}#fs_affiliation_content_wrapper form .input-container #add_domain:focus,#fs_affiliation_content_wrapper form .input-container .remove-domain:focus{box-shadow:none}#fs_affiliation_content_wrapper form .input-container #add_domain.disabled,#fs_affiliation_content_wrapper form .input-container .remove-domain.disabled{color:#aaa;cursor:default}#fs_affiliation_content_wrapper form #extra_domains_container .description{margin-top:0;position:relative;top:-4px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container{margin-bottom:15px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain{display:inline-block;margin-right:5px}#fs_affiliation_content_wrapper form #extra_domains_container .extra-domain-input-container .domain:last-of-type{margin-bottom:0}
lib/freemius/assets/css/admin/checkout.css ADDED
@@ -0,0 +1 @@
 
1
+ @media screen and (max-width: 782px){#wpbody-content{padding-bottom:0 !important}}
lib/freemius/assets/css/admin/common.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .theme-browser .theme .fs-premium-theme-badge{position:absolute;top:10px;right:0;background:#71ae00;color:#fff;text-transform:uppercase;padding:5px 10px;-moz-border-radius:3px 0 0 3px;-webkit-border-radius:3px 0 0 3px;border-radius:3px 0 0 3px;font-weight:bold;border-right:0;-moz-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);-webkit-box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);box-shadow:0 2px 1px -1px rgba(0,0,0,0.3);font-size:1.1em}#iframe{line-height:0;font-size:0}.fs-full-size-wrapper{margin:40px 0 -65px -20px}@media (max-width: 600px){.fs-full-size-wrapper{margin:0 0 -65px -10px}}
2
+ .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}div.fs-notice.updated,div.fs-notice.success,div.fs-notice.promotion{display:block !important}.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;-moz-box-shadow:0 2px 2px rgba(6,113,6,0.3);-webkit-box-shadow:0 2px 2px rgba(6,113,6,0.3);box-shadow:0 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)}.fs-secure-notice a.fs-security-proof{color:green;text-decoration:none}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 600px){.fs-secure-notice{display:none}}@media screen and (max-width: 500px){#fs_promo_tab{display:none}}@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'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}.fs-ajax-spinner{border:0;width:20px;height:20px;margin-right:5px;vertical-align:sub;display:inline-block;background:url("/wp-admin/images/wpspin_light-2x.gif");background-size:contain}.wrap.fs-section h2{text-align:left}
lib/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 .fs-error{background:snow;color:#d3135a;border:1px solid #d3135a;-moz-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);-webkit-box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);box-shadow:0 1px 1px 0 rgba(0,0,0,0.1);text-align:center;padding:5px;margin-bottom:10px}#fs_connect .fs-content p{margin:0;padding:0;font-size:1.2em}#fs_connect .fs-license-key-container{position:relative;width:280px;margin:10px auto 0 auto}#fs_connect .fs-license-key-container input{width:100%}#fs_connect .fs-license-key-container .dashicons{position:absolute;top:5px;right:5px}#fs_connect.require-license-key #sites_list_container td{cursor:pointer}#fs_connect #delegate_to_site_admins{margin-right:15px;float:right;height:26px;vertical-align:middle;line-height:37px;font-weight:bold;border-bottom:1px dashed;text-decoration:none}#fs_connect #delegate_to_site_admins.rtl{margin-left:15px;margin-right:0}#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-license-sync-disclaimer{text-align:center;margin-top:0}#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-freemium-licensing{padding:8px;background:#777;color:#fff}#fs_connect .fs-freemium-licensing p{text-align:center;display:block;margin:0;padding:0}#fs_connect .fs-freemium-licensing a{color:#C2EEFF;text-decoration:underline}#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}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #sites_list_container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-tooltip-trigger{position:relative}.fs-tooltip-trigger:not(a){cursor:help}.fs-tooltip-trigger .fs-tooltip{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:rgba(0,0,0,0.8);color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-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);line-height:1.3em;font-weight:bold;text-align:left}.rtl .fs-tooltip-trigger .fs-tooltip{text-align:right}.fs-tooltip-trigger .fs-tooltip::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:rgba(0,0,0,0.8) transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl .fs-tooltip-trigger .fs-tooltip::after{right:21px;left:auto}.fs-tooltip-trigger:hover .fs-tooltip{visibility:visible;opacity:1}#fs_marketing_optin{display:none;margin-top:10px;border:1px solid #ccc;padding:10px;line-height:1.5em}#fs_marketing_optin .fs-message{display:block;margin-bottom:5px;font-size:1.05em;font-weight:600}#fs_marketing_optin.error{border:1px solid #d3135a;background:#fee}#fs_marketing_optin.error .fs-message{color:#d3135a}#fs_marketing_optin .fs-input-container{margin-top:5px}#fs_marketing_optin .fs-input-container label{margin-top:5px;display:block}#fs_marketing_optin .fs-input-container label input{float:left;margin:1px 0 0 0}#fs_marketing_optin .fs-input-container label:first-child{display:block;margin-bottom:2px}#fs_marketing_optin .fs-input-label{display:block;margin-left:20px}#fs_marketing_optin .fs-input-label .underlined{text-decoration:underline}.rtl #fs_marketing_optin .fs-input-container label input{float:right}.rtl #fs_marketing_optin .fs-input-label{margin-left:0;margin-right:20px}.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}#fs_theme_connect_wrapper{position:fixed;top:0;height:100%;width:100%;z-index:99990;background:rgba(0,0,0,0.75);text-align:center;overflow-y:auto}#fs_theme_connect_wrapper:before{content:"";display:inline-block;vertical-align:middle;height:100%}#fs_theme_connect_wrapper>button.close{color:white;cursor:pointer;height:40px;width:40px;position:absolute;right:0;border:0;background-color:transparent;top:32px}#fs_theme_connect_wrapper #fs_connect{top:0;text-align:left;display:inline-block;vertical-align:middle;margin-top:52px;margin-bottom:20px}#fs_theme_connect_wrapper #fs_connect .fs-terms{background:rgba(140,140,140,0.64)}#fs_theme_connect_wrapper #fs_connect .fs-terms,#fs_theme_connect_wrapper #fs_connect .fs-terms a{color:#c5c5c5}.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}
lib/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,.fs-modal .fs-modal-dialog li.reason .internal-message{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,.fs-modal .internal-message{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea,.fs-modal .internal-message input,.fs-modal .internal-message textarea{width:100%}.fs-modal li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
lib/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}#fs_log_book table{font-family:Consolas,Monaco,monospace;font-size:12px}#fs_log_book table th{color:#ccc}#fs_log_book table tr{background:#232525}#fs_log_book table tr.alternate{background:#2b2b2b}#fs_log_book table tr td.fs-col--logger{color:#5a7435}#fs_log_book table tr td.fs-col--type{color:#ffc861}#fs_log_book table tr td.fs-col--function{color:#a7b7b1;font-weight:bold}#fs_log_book table tr td.fs-col--message,#fs_log_book table tr td.fs-col--message a{color:#9a73ac !important}#fs_log_book table tr td.fs-col--file{color:#d07922}#fs_log_book table tr td.fs-col--timestamp{color:#6596be}
lib/freemius/assets/css/admin/dialog-boxes.css ADDED
@@ -0,0 +1,2 @@
 
 
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.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal.fs-success .fs-modal-header{border-bottom-color:#46b450}.fs-modal.fs-success .fs-modal-body{background-color:#f7fff7}.fs-modal.fs-warn .fs-modal-header{border-bottom-color:#ffb900}.fs-modal.fs-warn .fs-modal-body{background-color:#fff8e5}.fs-modal.fs-error .fs-modal-header{border-bottom-color:#dc3232}.fs-modal.fs-error .fs-modal-body{background-color:#ffeaea}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-header .fs-close .dashicons,.fs-modal .fs-modal-header .fs-close:hover .dashicons{text-decoration:none}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.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>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media (max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label{float:left}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-license-activation .fs-modal-body input.license_key{width:100%}#license_options_container table,#license_options_container table select,#license_options_container table #available_license_key{width:100%}#license_options_container table td:first-child{width:1%}#license_options_container table #other_license_key_container label{position:relative;top:6px;float:left;margin-right:5px}#license_options_container table #other_license_key_container div{overflow:hidden;width:auto;height:30px;display:block;top:2px;position:relative}#license_options_container table #other_license_key_container div input{margin:0}#sites_list_container td{cursor:pointer}#multisite_options_container{margin-top:10px;border:1px solid #ccc;padding:5px}#multisite_options_container a{text-decoration:none}#multisite_options_container a:focus{box-shadow:none}#multisite_options_container a.selected{font-weight:bold}#multisite_options_container.apply-on-all-sites{border:0 none;padding:0}#multisite_options_container.apply-on-all-sites #all_sites_options{border-spacing:0}#multisite_options_container.apply-on-all-sites #all_sites_options td:not(:first-child){display:none}#multisite_options_container #sites_list_container{display:none;overflow:auto}#multisite_options_container #sites_list_container table td{border-top:1px solid #ccc;padding:4px 2px}.fs-modal.fs-modal-license-key-resend .email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend.fs-freemium input.email-address{width:300px}.fs-modal.fs-modal-license-key-resend.fs-freemium label{display:block;margin-bottom:10px}.fs-modal.fs-modal-license-key-resend.fs-premium input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend.fs-premium .button-container{margin-top:2px}}
2
+ .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}.fs-ajax-loader{position:relative;width:170px;height:20px;margin:auto}.fs-ajax-loader .fs-ajax-loader-bar{position:absolute;top:0;background-color:#0074a3;width:20px;height:20px;-webkit-animation-name:bounce_ajaxLoader;-moz-animation-name:bounce_ajaxLoader;-ms-animation-name:bounce_ajaxLoader;-o-animation-name:bounce_ajaxLoader;animation-name:bounce_ajaxLoader;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;-ms-animation-duration:1.5s;-o-animation-duration:1.5s;animation-duration:1.5s;animation-iteration-count:infinite;-o-animation-iteration-count:infinite;-ms-animation-iteration-count:infinite;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;-webkit-animation-direction:normal;-moz-animation-direction:normal;-ms-animation-direction:normal;-o-animation-direction:normal;animation-direction:normal;-moz-transform:0.3;-o-transform:0.3;-ms-transform:0.3;-webkit-transform:0.3;transform:0.3}.fs-ajax-loader .fs-ajax-loader-bar-1{left:0px;animation-delay:0.6s;-o-animation-delay:0.6s;-ms-animation-delay:0.6s;-webkit-animation-delay:0.6s;-moz-animation-delay:0.6s}.fs-ajax-loader .fs-ajax-loader-bar-2{left:19px;animation-delay:0.75s;-o-animation-delay:0.75s;-ms-animation-delay:0.75s;-webkit-animation-delay:0.75s;-moz-animation-delay:0.75s}.fs-ajax-loader .fs-ajax-loader-bar-3{left:38px;animation-delay:0.9s;-o-animation-delay:0.9s;-ms-animation-delay:0.9s;-webkit-animation-delay:0.9s;-moz-animation-delay:0.9s}.fs-ajax-loader .fs-ajax-loader-bar-4{left:57px;animation-delay:1.05s;-o-animation-delay:1.05s;-ms-animation-delay:1.05s;-webkit-animation-delay:1.05s;-moz-animation-delay:1.05s}.fs-ajax-loader .fs-ajax-loader-bar-5{left:76px;animation-delay:1.2s;-o-animation-delay:1.2s;-ms-animation-delay:1.2s;-webkit-animation-delay:1.2s;-moz-animation-delay:1.2s}.fs-ajax-loader .fs-ajax-loader-bar-6{left:95px;animation-delay:1.35s;-o-animation-delay:1.35s;-ms-animation-delay:1.35s;-webkit-animation-delay:1.35s;-moz-animation-delay:1.35s}.fs-ajax-loader .fs-ajax-loader-bar-7{left:114px;animation-delay:1.5s;-o-animation-delay:1.5s;-ms-animation-delay:1.5s;-webkit-animation-delay:1.5s;-moz-animation-delay:1.5s}.fs-ajax-loader .fs-ajax-loader-bar-8{left:133px;animation-delay:1.65s;-o-animation-delay:1.65s;-ms-animation-delay:1.65s;-webkit-animation-delay:1.65s;-moz-animation-delay:1.65s}@-moz-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-ms-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-o-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@-webkit-keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}@keyframes bounce_ajaxLoader{0%{-moz-transform:scale(1);-o-transform:scale(1);-ms-transform:scale(1);-webkit-transform:scale(1);transform:scale(1);background-color:#0074a3}100%{-moz-transform:scale(0.3);-o-transform:scale(0.3);-ms-transform:scale(0.3);-webkit-transform:scale(0.3);transform:scale(0.3);background-color:#fff}}.fs-modal-auto-install #request-filesystem-credentials-form h2,.fs-modal-auto-install #request-filesystem-credentials-form .request-filesystem-credentials-action-buttons{display:none}.fs-modal-auto-install #request-filesystem-credentials-form input[type=password],.fs-modal-auto-install #request-filesystem-credentials-form input[type=email],.fs-modal-auto-install #request-filesystem-credentials-form input[type=text]{-webkit-appearance:none;padding:10px 10px 5px 10px;width:300px;max-width:100%}.fs-modal-auto-install #request-filesystem-credentials-form>div,.fs-modal-auto-install #request-filesystem-credentials-form label,.fs-modal-auto-install #request-filesystem-credentials-form fieldset{width:300px;max-width:100%;margin:0 auto;display:block}
lib/freemius/assets/css/admin/gdpr-optin-notice.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"] .underlined{text-decoration:underline}.fs-notice[data-id^="gdpr_optin_actions"] ul .button,.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{vertical-align:middle}.fs-notice[data-id^="gdpr_optin_actions"] ul .action-description{display:inline-block;margin-left:3px}
lib/freemius/assets/css/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
lib/freemius/assets/css/admin/license-activation.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.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 .license-activation-message{margin:0;display:none}.fs-modal .fs-modal-body input.license_key{width:100%}.fs-modal .fs-modal-body p{font-size:14px}.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}body.has-fs-modal{overflow:hidden}
lib/freemius/assets/css/customizer.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_customizer_upsell .fs-customizer-plan{padding:10px 20px 20px 20px;border-radius:3px;background:#fff}#fs_customizer_upsell .fs-customizer-plan h2{position:relative;margin:0;line-height:2em;text-transform:uppercase}#fs_customizer_upsell .fs-customizer-plan h2 .button-link{top:-2px}#fs_customizer_upsell .fs-feature{position:relative}#fs_customizer_upsell .dashicons-yes{color:#0085ba;font-size:2em;vertical-align:bottom;margin-left:-7px;margin-right:10px}.rtl #fs_customizer_upsell .dashicons-yes{margin-left:10px;margin-right:-7px}#fs_customizer_upsell .dashicons-editor-help{color:#bbb;cursor:help}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{opacity:0;visibility:hidden;-moz-transition:opacity 0.3s ease-in-out;-o-transition:opacity 0.3s ease-in-out;-ms-transition:opacity 0.3s ease-in-out;-webkit-transition:opacity 0.3s ease-in-out;transition:opacity 0.3s ease-in-out;position:absolute;background:#000;color:#fff;font-family:'arial', serif;font-size:12px;padding:10px;z-index:999999;bottom:100%;margin-bottom:5px;left:0;right:0;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;-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);line-height:1.3em;font-weight:bold;text-align:left}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc{text-align:right}#fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{content:' ';display:block;width:0;height:0;border-style:solid;border-width:5px 5px 0 5px;border-color:#000 transparent transparent transparent;position:absolute;top:100%;left:21px}.rtl #fs_customizer_upsell .dashicons-editor-help .fs-feature-desc::after{right:21px;left:auto}#fs_customizer_upsell .dashicons-editor-help:hover .fs-feature-desc{visibility:visible;opacity:1}#fs_customizer_upsell .button-primary{display:block;text-align:center;margin-top:10px}#fs_customizer_support{display:block !important}#fs_customizer_support .button{float:right}#fs_customizer_support .button-group{width:100%;display:block;margin-top:10px}#fs_customizer_support .button-group .button{float:none;width:50%;text-align:center}
lib/freemius/assets/css/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
lib/freemius/assets/img/coming-soon-blocks.png ADDED
Binary file
lib/freemius/assets/img/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
lib/freemius/assets/img/mobile-menu.png ADDED
Binary file
lib/freemius/assets/img/plugin-icon.png ADDED
Binary file
lib/freemius/assets/img/theme-icon.png ADDED
Binary file
lib/freemius/assets/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
lib/freemius/assets/js/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
lib/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
+ }
lib/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};
lib/freemius/assets/js/postmessage.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ _hasParent = ('' !== _parent_url),
29
+ $window = $(window),
30
+ $html = $('html');
31
+
32
+ return {
33
+ init : function (url, iframes)
34
+ {
35
+ _base_url = url;
36
+ _init();
37
+
38
+ // Automatically receive forward messages.
39
+ FS.PostMessage.receiveOnce('forward', function (data){
40
+ window.location = data.url;
41
+ });
42
+
43
+ iframes = iframes || [];
44
+
45
+ if (iframes.length > 0) {
46
+ $window.on('scroll', function () {
47
+ for (var i = 0; i < iframes.length; i++) {
48
+ FS.PostMessage.postScroll(iframes[i]);
49
+ }
50
+ });
51
+ }
52
+ },
53
+ init_child : function ()
54
+ {
55
+ this.init(_parent_subdomain);
56
+
57
+ _is_child = true;
58
+
59
+ // Post height of a child right after window is loaded.
60
+ $(window).bind('load', function () {
61
+ FS.PostMessage.postHeight();
62
+
63
+ // Post message that window was loaded.
64
+ FS.PostMessage.post('loaded');
65
+ });
66
+ },
67
+ hasParent : function ()
68
+ {
69
+ return _hasParent;
70
+ },
71
+ postHeight : function (diff, wrapper) {
72
+ diff = diff || 0;
73
+ wrapper = wrapper || '#wrap_section';
74
+ this.post('height', {
75
+ height: diff + $(wrapper).outerHeight(true)
76
+ });
77
+ },
78
+ postScroll : function (iframe) {
79
+ this.post('scroll', {
80
+ top: $window.scrollTop(),
81
+ height: ($window.height() - parseFloat($html.css('paddingTop')) - parseFloat($html.css('marginTop')))
82
+ }, iframe);
83
+ },
84
+ post : function (type, data, iframe)
85
+ {
86
+ console.debug('PostMessage.post', type);
87
+
88
+ if (iframe)
89
+ {
90
+ // Post to iframe.
91
+ _postman.postMessage(JSON.stringify({
92
+ type: type,
93
+ data: data
94
+ }), iframe.src, iframe.contentWindow);
95
+ }
96
+ else {
97
+ // Post to parent.
98
+ _postman.postMessage(JSON.stringify({
99
+ type: type,
100
+ data: data
101
+ }), _parent_url, window.parent);
102
+ }
103
+ },
104
+ receive: function (type, callback)
105
+ {
106
+ console.debug('PostMessage.receive', type);
107
+
108
+ if (undef === _callbacks[type])
109
+ _callbacks[type] = [];
110
+
111
+ _callbacks[type].push(callback);
112
+ },
113
+ receiveOnce: function (type, callback)
114
+ {
115
+ if (this.is_set(type))
116
+ return;
117
+
118
+ this.receive(type, callback);
119
+ },
120
+ // Check if any callbacks assigned to a specified message type.
121
+ is_set: function (type)
122
+ {
123
+ return (undef != _callbacks[type]);
124
+ },
125
+ parent_url: function ()
126
+ {
127
+ return _parent_url;
128
+ },
129
+ parent_subdomain: function ()
130
+ {
131
+ return _parent_subdomain;
132
+ }
133
+ };
134
+ }();
135
+ })(jQuery);
lib/freemius/assets/scss/_colors.scss ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // WordPress colors.
24
+ $page-header-bkg: #333;
25
+ $page-header-color: $fms-white;
26
+ $text-dark-color: #333;
27
+ $text-light-color: #666;
28
+ $text-lightest-color: #999;
29
+
30
+ // Notices.
31
+ $wp-notice-success-color: #f7fff7;
32
+ $wp-notice-success-dark-color: #46b450;
33
+ $wp-notice-error-color: #ffeaea;
34
+ $wp-notice-error-dark-color: #dc3232;
35
+ $wp-notice-warn-color: #fff8e5;
36
+ $wp-notice-warn-dark-color: #ffb900;
37
+ $fs-notice-promotion-border-color: #00a0d2;
38
+ $fs-notice-promotion-bkg: #f2fcff;
39
+
40
+ // WP Buttons.
41
+ $button-primary-bkg: #6bc406;
42
+ $button-primary-color: $fms-white;
43
+ $button-secondary-bkg: #333;
44
+ $button-secondary-color: $fms-white;
45
+ $featured-color: #6bc406;
46
+ $wp-selected-color: #0074a3;
47
+
48
+ $wordpress_color: #01749A;
49
+ $blogger_color: #ff8100;
50
+ $wix_color: #fac102;
51
+ $shopify_color: #80d100;
52
+ $addthis_color: #fe6d4e;
53
+ $tumblr_color: #34506b;
54
+ $zepo_color: #00baf2;
55
+ $jquery_color: #000919;
56
+ $javascript_color: #00baf2;
57
+ $squarespace_color: #000;
58
+
59
+ $blog_color: #ff6600;
60
+ $facebook_color: #3b5998;
61
+ $twitter_color: #4099ff;
62
+ $linkedin_color: #4875b4;
63
+ $youtube_color: #ff3333;
64
+ $gplus_color: #c63d2d;
65
+
66
+ // Tooltip
67
+ $tooltip-color: #fff;
68
+ $tooltip-bkg-color: rgba(0,0,0,0.8);
lib/freemius/assets/scss/_functions.scss ADDED
File without changes
lib/freemius/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
lib/freemius/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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($name){
82
+ @-moz-keyframes #{$name} { @content; }
83
+ @-ms-keyframes #{$name} { @content; }
84
+ @-o-keyframes #{$name} { @content; }
85
+ @-webkit-keyframes #{$name} { @content; }
86
+ @keyframes #{$name} { @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 perspective($perspective) {
136
+ -moz-perspective: $perspective;
137
+ -ms-perspective: $perspective;
138
+ -webkit-perspective: $perspective;
139
+ perspective: $perspective;
140
+ -moz-transform-style: preserve-3d;
141
+ -ms-transform-style: preserve-3d;
142
+ -webkit-transform-style: preserve-3d;
143
+ transform-style: preserve-3d;
144
+ }
145
+
146
+ @mixin transform ($transforms) {
147
+ -moz-transform: $transforms;
148
+ -o-transform: $transforms;
149
+ -ms-transform: $transforms;
150
+ -webkit-transform: $transforms;
151
+ transform: $transforms;
152
+ }
153
+
154
+ @mixin matrix ($a, $b, $c, $d, $e, $f) {
155
+ -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
156
+ -o-transform: matrix($a, $b, $c, $d, $e, $f);
157
+ -ms-transform: matrix($a, $b, $c, $d, $e, $f);
158
+ -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
159
+ transform: matrix($a, $b, $c, $d, $e, $f);
160
+ }
161
+
162
+ @mixin rotate ($deg) {
163
+ @include transform(rotate(#{$deg}deg));
164
+ }
165
+
166
+ @mixin scale ($size) {
167
+ @include transform(scale(#{$size}));
168
+ }
169
+
170
+ @mixin translate ($x, $y) {
171
+ @include transform(translate($x, $y));
172
+ }
173
+
174
+ @mixin transition ($value...) {
175
+ -moz-transition: $value;
176
+ -o-transition: $value;
177
+ -ms-transition: $value;
178
+ -webkit-transition: $value;
179
+ transition: $value;
180
+ }
181
+
182
+ @mixin animation($str) {
183
+ -webkit-animation: #{$str};
184
+ -moz-animation: #{$str};
185
+ -ms-animation: #{$str};
186
+ -o-animation: #{$str};
187
+ animation: #{$str};
188
+ }
189
+
190
+ @mixin animation-name($str) {
191
+ -webkit-animation-name: #{$str};
192
+ -moz-animation-name: #{$str};
193
+ -ms-animation-name: #{$str};
194
+ -o-animation-name: #{$str};
195
+ animation-name: #{$str};
196
+ }
197
+
198
+ @mixin animation-duration($str) {
199
+ -webkit-animation-duration: #{$str};
200
+ -moz-animation-duration: #{$str};
201
+ -ms-animation-duration: #{$str};
202
+ -o-animation-duration: #{$str};
203
+ animation-duration: #{$str};
204
+ }
205
+
206
+ @mixin animation-direction($str) {
207
+ -webkit-animation-direction: #{$str};
208
+ -moz-animation-direction: #{$str};
209
+ -ms-animation-direction: #{$str};
210
+ -o-animation-direction: #{$str};
211
+ animation-direction: #{$str};
212
+ }
213
+
214
+ @mixin animation-delay($str) {
215
+ animation-delay:#{$str};
216
+ -o-animation-delay:#{$str};
217
+ -ms-animation-delay:#{$str};
218
+ -webkit-animation-delay:#{$str};
219
+ -moz-animation-delay:#{$str};
220
+ }
221
+
222
+ @mixin animation-iteration-count($str) {
223
+ animation-iteration-count:#{$str};
224
+ -o-animation-iteration-count:#{$str};
225
+ -ms-animation-iteration-count:#{$str};
226
+ -webkit-animation-iteration-count:#{$str};
227
+ -moz-animation-iteration-count:#{$str};
228
+ }
229
+
230
+ @mixin animation-timing-function($str) {
231
+ -webkit-animation-timing-function: #{$str};
232
+ -moz-animation-timing-function: #{$str};
233
+ -ms-animation-timing-function: #{$str};
234
+ -o-animation-timing-function: #{$str};
235
+ animation-timing-function: #{$str};
236
+ }
237
+
238
+ // ==== /CSS3 SASS MIXINS ====
239
+
240
+ @mixin opacity($opacity) {
241
+ opacity: $opacity;
242
+ $opacity-ie: $opacity * 100;
243
+ filter: alpha(opacity=$opacity-ie); //IE8
244
+ }
245
+
246
+ @mixin size($width, $height: $width)
247
+ {
248
+ width: $width;
249
+ height: $height;
250
+ }
251
+
252
+ @mixin clearfix
253
+ {
254
+ &:after {
255
+ content: "";
256
+ display: table;
257
+ clear: both;
258
+ }
259
+ }
260
+
261
+ // Placeholder text
262
+ @mixin placeholder($color: $input-color-placeholder) {
263
+ // Firefox
264
+ &::-moz-placeholder {
265
+ color: $color;
266
+ opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
267
+ }
268
+ &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
269
+ &::-webkit-input-placeholder { color: $color; } // Safari and Chrome
270
+ }
lib/freemius/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
lib/freemius/assets/scss/_vars.scss ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
6
+ $admin_mobile_max_width: 782px;
lib/freemius/assets/scss/admin/_ajax-loader.scss ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $color: $wp-selected-color;
2
+ $bkg-color: #fff;
3
+ $size: 20;
4
+
5
+ .fs-ajax-loader
6
+ {
7
+ position: relative;
8
+ width: #{8*$size + 10}px;
9
+ height: #{$size}px;
10
+ margin: auto;
11
+
12
+ .fs-ajax-loader-bar
13
+ {
14
+ position: absolute;
15
+ top: 0;
16
+ background-color: $color;
17
+ width: #{$size}px;
18
+ height: #{$size}px;
19
+ @include animation-name(bounce_ajaxLoader);
20
+ @include animation-duration(1.5s);
21
+ @include animation-iteration-count(infinite);
22
+ @include animation-direction(normal);
23
+ @include transform(.3);
24
+ }
25
+
26
+ @for $i from 0 through 7
27
+ {
28
+ .fs-ajax-loader-bar-#{$i + 1}
29
+ {
30
+ left: #{$i*($size - 1)}px;
31
+ @include animation-delay(#{0.6 + $i*0.15}s);
32
+ }
33
+ }
34
+ }
35
+
36
+ @include keyframes(bounce_ajaxLoader)
37
+ {
38
+ 0%
39
+ {
40
+ @include transform(scale(1));
41
+ background-color: $color;
42
+ }
43
+
44
+ 100%
45
+ {
46
+ @include transform(scale(.3));
47
+ background-color: $bkg-color;
48
+ }
49
+ }
lib/freemius/assets/scss/admin/_auto-install.scss ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal-auto-install
2
+ {
3
+ $max-width: 300px;
4
+
5
+ #request-filesystem-credentials-form
6
+ {
7
+ h2,
8
+ .request-filesystem-credentials-action-buttons
9
+ {
10
+ display: none;
11
+ }
12
+
13
+ input[type=password],
14
+ input[type=email],
15
+ input[type=text]
16
+ {
17
+ -webkit-appearance: none;
18
+ padding: 10px 10px 5px 10px;
19
+ width: $max-width;
20
+ max-width: 100%;
21
+ }
22
+
23
+ > div,
24
+ label,
25
+ fieldset
26
+ {
27
+ width: $max-width;
28
+ max-width: 100%;
29
+ margin: 0 auto;
30
+ display: block;
31
+ }
32
+ }
33
+ }
lib/freemius/assets/scss/admin/_deactivation-feedback.scss ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+
3
+ .fs-modal.fs-modal-deactivation-feedback {
4
+ .reason-input, .internal-message {
5
+ margin: 3px 0 3px 22px;
6
+
7
+ input, textarea {
8
+ width: 100%;
9
+ }
10
+ }
11
+
12
+ li.reason {
13
+ &.has-internal-message .internal-message {
14
+ border: 1px solid lighten($darkest-color, 80%);
15
+ padding: 7px;
16
+ display: none;
17
+ }
18
+
19
+ @media (max-width: 650px) {
20
+ li.reason {
21
+ margin-bottom: 10px;
22
+
23
+ .reason-input, .internal-message {
24
+ margin-left: 29px;
25
+ }
26
+
27
+ label {
28
+ display: table;
29
+
30
+ > span {
31
+ display: table-cell;
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ .anonymous-feedback-label {
40
+ float: left;
41
+ }
42
+
43
+ .fs-modal-panel {
44
+ margin-top: 0 !important;
45
+
46
+ h3 {
47
+ margin-top: 0;
48
+ line-height: 1.5em;
49
+ }
50
+ }
51
+ }
52
+
53
+ #the-list .deactivate > .fs-slug {
54
+ display: none;
55
+ }
lib/freemius/assets/scss/admin/_gdpr-consent.scss ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #fs_marketing_optin
2
+ {
3
+ display: none;
4
+ margin-top: 10px;
5
+ border: 1px solid #ccc;
6
+ padding: 10px;
7
+ line-height: 1.5em;
8
+
9
+ .fs-message
10
+ {
11
+ display: block;
12
+ margin-bottom: 5px;
13
+ font-size: 1.05em;
14
+ font-weight: 600;
15
+ }
16
+
17
+ &.error
18
+ {
19
+ border: 1px solid $fs-logo-magenta-color;
20
+ background: #fee;
21
+
22
+ .fs-message
23
+ {
24
+ color: $fs-logo-magenta-color;
25
+ }
26
+ }
27
+
28
+ .fs-input-container
29
+ {
30
+ margin-top: 5px;
31
+
32
+ label
33
+ {
34
+ margin-top: 5px;
35
+ display: block;
36
+
37
+ input
38
+ {
39
+ float: left;
40
+ margin: 1px 0 0 0;
41
+ }
42
+
43
+ &:first-child
44
+ {
45
+ display: block;
46
+ margin-bottom: 2px;
47
+ }
48
+ }
49
+ }
50
+
51
+ .fs-input-label
52
+ {
53
+ display: block;
54
+ margin-left: 20px;
55
+
56
+ .underlined
57
+ {
58
+ text-decoration: underline;
59
+ }
60
+ }
61
+ }
62
+
63
+ .rtl
64
+ {
65
+ #fs_marketing_optin
66
+ {
67
+ .fs-input-container
68
+ {
69
+ label input
70
+ {
71
+ float: right;
72
+ }
73
+ }
74
+
75
+ .fs-input-label
76
+ {
77
+ margin-left: 0;
78
+ margin-right: 20px;
79
+ }
80
+ }
81
+ }
lib/freemius/assets/scss/admin/_license-activation.scss ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-activation {
2
+ .fs-modal-body {
3
+ input.license_key {
4
+ width: 100%;
5
+ }
6
+ }
7
+ }
8
+
9
+ #license_options_container {
10
+ table {
11
+ &, select, #available_license_key {
12
+ width: 100%;
13
+ }
14
+
15
+ td:first-child {
16
+ width: 1%;
17
+ }
18
+
19
+ #other_license_key_container {
20
+ label {
21
+ position: relative;
22
+ top: 6px;
23
+ float: left;
24
+ margin-right: 5px;
25
+ }
26
+
27
+ div {
28
+ overflow: hidden;
29
+ width: auto;
30
+ height: 30px;
31
+ display: block;
32
+ top: 2px;
33
+ position: relative;
34
+
35
+ input {
36
+ margin: 0;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ #sites_list_container {
44
+ td {
45
+ cursor: pointer;
46
+ }
47
+ }
lib/freemius/assets/scss/admin/_license-key-resend.scss ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal.fs-modal-license-key-resend
2
+ {
3
+ .email-address-container
4
+ {
5
+ overflow: hidden;
6
+ padding-right: 2px;
7
+ }
8
+
9
+ &.fs-freemium
10
+ {
11
+ input.email-address
12
+ {
13
+ width: 300px;
14
+ }
15
+
16
+ label
17
+ {
18
+ display: block;
19
+ margin-bottom: 10px;
20
+ }
21
+ }
22
+
23
+ &.fs-premium
24
+ {
25
+ input.email-address
26
+ {
27
+ width: 100%;
28
+ }
29
+
30
+ .button-container
31
+ {
32
+ float: right;
33
+ margin-left: 7px;
34
+
35
+ @media (max-width: 650px) {
36
+ margin-top: 2px;
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ .rtl
43
+ {
44
+ .fs-modal.fs-modal-license-key-resend
45
+ {
46
+ .fs-modal-body
47
+ {
48
+ .input-container > .email-address-container
49
+ {
50
+ padding-left: 2px;
51
+ padding-right: 0;
52
+ }
53
+
54
+ .button-container
55
+ {
56
+ float: left;
57
+ margin-right: 7px;
58
+ margin-left: 0;
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ a.show-license-resend-modal
65
+ {
66
+ margin-top: 4px;
67
+ display: inline-block;
68
+ }
lib/freemius/assets/scss/admin/_modal-common.scss ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../colors";
2
+ @import "../mixins";
3
+
4
+ .fs-modal {
5
+ position: fixed;
6
+ overflow: auto;
7
+ height: 100%;
8
+ width: 100%;
9
+ top: 0;
10
+ z-index: 100000;
11
+ display: none;
12
+ background: rgba(0, 0, 0, 0.6);
13
+
14
+ .fs-modal-dialog {
15
+ background: transparent;
16
+ position: absolute;
17
+ left: 50%;
18
+ margin-left: -298px;
19
+ padding-bottom: 30px;
20
+ top: -100%;
21
+ z-index: 100001;
22
+ width: 596px;
23
+
24
+ @media (max-width: 650px) {
25
+ margin-left: -50%;
26
+ box-sizing: border-box;
27
+ padding-left: 10px;
28
+ padding-right: 10px;
29
+ width: 100%;
30
+
31
+ .fs-modal-panel > h3 > strong {
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+
37
+ &.active {
38
+ display: block;
39
+
40
+ &:before {
41
+ display: block;
42
+ }
43
+
44
+ .fs-modal-dialog {
45
+ top: 10%;
46
+ }
47
+ }
48
+
49
+ &.fs-success {
50
+ .fs-modal-header {
51
+ border-bottom-color: $wp-notice-success-dark-color;
52
+ }
53
+
54
+ .fs-modal-body {
55
+ background-color: $wp-notice-success-color;
56
+ }
57
+ }
58
+
59
+ &.fs-warn {
60
+ .fs-modal-header {
61
+ border-bottom-color: $wp-notice-warn-dark-color;
62
+ }
63
+
64
+ .fs-modal-body {
65
+ background-color: $wp-notice-warn-color;
66
+ }
67
+ }
68
+
69
+ &.fs-error {
70
+ .fs-modal-header {
71
+ border-bottom-color: $wp-notice-error-dark-color;
72
+ }
73
+
74
+ .fs-modal-body {
75
+ background-color: $wp-notice-error-color;
76
+ }
77
+ }
78
+
79
+
80
+ .fs-modal-body,
81
+ .fs-modal-footer {
82
+ border: 0;
83
+ background: #fefefe;
84
+ padding: 20px;
85
+ }
86
+
87
+ .fs-modal-header {
88
+ border-bottom: #eeeeee solid 1px;
89
+ background: #fbfbfb;
90
+ padding: 15px 20px;
91
+ position: relative;
92
+ margin-bottom: -10px;
93
+ // z-index: 2;
94
+
95
+ h4 {
96
+ margin: 0;
97
+ padding: 0;
98
+ text-transform: uppercase;
99
+ font-size: 1.2em;
100
+ font-weight: bold;
101
+ color: #cacaca;
102
+ text-shadow: 1px 1px 1px #fff;
103
+ letter-spacing: 0.6px;
104
+ -webkit-font-smoothing: antialiased;
105
+ }
106
+
107
+ .fs-close {
108
+ position: absolute;
109
+ right: 10px;
110
+ top: 12px;
111
+ cursor: pointer;
112
+ color: #bbb;
113
+ @include border-radius(20px);
114
+ padding: 3px;
115
+ @include transition(all 0.2s ease-in-out);
116
+
117
+ &:hover {
118
+ color: #fff;
119
+ background: #aaa;
120
+ }
121
+
122
+ &, &:hover
123
+ {
124
+ .dashicons
125
+ {
126
+ text-decoration: none;
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ .fs-modal-body {
133
+ border-bottom: 0;
134
+
135
+ p {
136
+ font-size: 14px;
137
+ }
138
+
139
+ h2 {
140
+ font-size: 20px;
141
+ line-height: 1.5em;
142
+ }
143
+
144
+ > div {
145
+ margin-top: 10px;
146
+
147
+ h2 {
148
+ font-weight: bold;
149
+ font-size: 20px;
150
+ margin-top: 0;
151
+ }
152
+ }
153
+ }
154
+
155
+ .fs-modal-footer {
156
+ border-top: #eeeeee solid 1px;
157
+ text-align: right;
158
+
159
+ > .button {
160
+ margin: 0 7px;
161
+
162
+ &:first-child {
163
+ margin: 0;
164
+ }
165
+ }
166
+ }
167
+
168
+ .fs-modal-panel {
169
+ > .notice.inline {
170
+ margin: 0;
171
+ display: none;
172
+ }
173
+
174
+ &:not(.active) {
175
+ display: none;
176
+ }
177
+ }
178
+ }
179
+
180
+ .rtl
181
+ {
182
+ .fs-modal {
183
+ .fs-modal-header {
184
+ .fs-close {
185
+ right: auto;
186
+ left: 20px;
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ body.has-fs-modal {
193
+ overflow: hidden;
194
+ }
lib/freemius/assets/scss/admin/_multisite-options.scss ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #multisite_options_container {
2
+ margin-top: 10px;
3
+ border: 1px solid #ccc;
4
+ padding: 5px;
5
+
6
+ a {
7
+ text-decoration: none;
8
+
9
+ &:focus {
10
+ box-shadow: none;
11
+ }
12
+
13
+ &.selected {
14
+ font-weight: bold;
15
+ }
16
+ }
17
+
18
+ &.apply-on-all-sites {
19
+ border: 0 none;
20
+ padding: 0;
21
+
22
+ #all_sites_options {
23
+ border-spacing: 0;
24
+
25
+ td:not(:first-child) {
26
+ display: none;
27
+ }
28
+ }
29
+ }
30
+
31
+ #sites_list_container {
32
+ display: none;
33
+ overflow: auto;
34
+
35
+ table td {
36
+ border-top: 1px solid #ccc;
37
+ padding: 4px 2px;
38
+ }
39
+ }
40
+ }
lib/freemius/assets/scss/admin/_themes.scss ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .theme-browser
2
+ {
3
+ .theme
4
+ {
5
+ .fs-premium-theme-badge
6
+ {
7
+ position: absolute;
8
+ top: 10px;
9
+ right: 0;
10
+ background: $fs-logo-green-color;
11
+ color: #fff;
12
+ text-transform: uppercase;
13
+ padding: 5px 10px;
14
+ @include border-radius(3px 0 0 3px);
15
+ font-weight: bold;
16
+ border-right: 0;
17
+ @include box-shadow(0 2px 1px -1px rgba(0, 0, 0, .3));
18
+ font-size: 1.1em;
19
+ }
20
+ }
21
+ }
lib/freemius/assets/scss/admin/_tooltip.scss ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-tooltip-trigger
2
+ {
3
+ &:not(a)
4
+ {
5
+ cursor: help;
6
+ }
7
+
8
+ position: relative;
9
+
10
+ .fs-tooltip
11
+ {
12
+ opacity: 0;
13
+ visibility: hidden;
14
+ @include transition(opacity 0.3s ease-in-out);
15
+ position: absolute;
16
+ background: $tooltip-bkg-color;
17
+ color: $tooltip-color;
18
+ font-family: 'arial', serif;
19
+ font-size: 12px;
20
+ padding: 10px;
21
+ z-index: 999999;
22
+ bottom: 100%;
23
+ margin-bottom: 5px;
24
+ left: 0;
25
+ right: 0;
26
+ @include border-radius(5px);
27
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
28
+ line-height: 1.3em;
29
+ font-weight: bold;
30
+ text-align: left;
31
+
32
+ .rtl &
33
+ {
34
+ text-align: right;
35
+ }
36
+
37
+ &::after
38
+ {
39
+ content: ' ';
40
+ display: block;
41
+ width: 0;
42
+ height: 0;
43
+ border-style: solid;
44
+ border-width: 5px 5px 0 5px;
45
+ border-color: $tooltip-bkg-color transparent transparent transparent;
46
+ position: absolute;
47
+ top: 100%;
48
+ left: 21px;
49
+
50
+ .rtl &
51
+ {
52
+ right: 21px;
53
+ left: auto;
54
+ }
55
+ }
56
+ }
57
+
58
+ &:hover
59
+ {
60
+ .fs-tooltip
61
+ {
62
+ visibility: visible;
63
+ opacity: 1;
64
+ }
65
+ }
66
+ }
lib/freemius/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_account
4
+ {
5
+ .postbox,
6
+ .widefat
7
+ {
8
+ max-width: 700px;
9
+ }
10
+
11
+ h3
12
+ {
13
+ font-size: 1.3em;
14
+ padding: 12px 15px;
15
+ margin: 0 0 12px 0;
16
+ line-height: 1.4;
17
+ border-bottom: 1px solid #F1F1F1;
18
+
19
+ .dashicons {
20
+ width: 26px;
21
+ height: 26px;
22
+ font-size: 1.3em;
23
+ }
24
+ }
25
+
26
+ i.dashicons
27
+ {
28
+ font-size: 1.2em;
29
+ height: 1.2em;
30
+ width: 1.2em;
31
+ }
32
+
33
+ .dashicons
34
+ {
35
+ vertical-align: middle;
36
+ }
37
+
38
+ .fs-header-actions
39
+ {
40
+ position: absolute;
41
+ top: 17px;
42
+ right: 15px;
43
+ font-size: 0.9em;
44
+
45
+ ul
46
+ {
47
+ margin: 0;
48
+ }
49
+
50
+ li
51
+ {
52
+ form
53
+ {
54
+ display: inline-block;
55
+ }
56
+
57
+ float: left;
58
+ a
59
+ {
60
+ text-decoration: none;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ #fs_account_details .button-group {
67
+ float: right;
68
+ }
69
+
70
+ .rtl #fs_account .fs-header-actions
71
+ {
72
+ left: 15px;
73
+ right: auto;
74
+ }
75
+
76
+ .fs-key-value-table
77
+ {
78
+ width: 100%;
79
+
80
+ form
81
+ {
82
+ display: inline-block;
83
+ }
84
+
85
+ tr
86
+ {
87
+ td:first-child
88
+ {
89
+ nobr
90
+ {
91
+ font-weight: bold;
92
+ }
93
+
94
+ text-align: right;
95
+
96
+ form
97
+ {
98
+ display: block;
99
+ }
100
+ }
101
+
102
+ td.fs-right
103
+ {
104
+ text-align: right;
105
+ }
106
+
107
+ &.fs-odd
108
+ {
109
+ background: #ebebeb;
110
+ }
111
+ }
112
+
113
+ td, th
114
+ {
115
+ padding: 10px;
116
+ }
117
+
118
+ code {
119
+ line-height: 28px;
120
+ }
121
+
122
+ var, code, input[type="text"]
123
+ {
124
+ color: #0073AA;
125
+ font-size: 16px;
126
+ background: none;
127
+ }
128
+
129
+ input[type="text"] {
130
+ width: 100%;
131
+ font-weight: bold;
132
+ }
133
+ }
134
+
135
+ label.fs-tag
136
+ {
137
+ background: #ffba00;
138
+ color: #fff;
139
+ display: inline-block;
140
+ border-radius: 3px;
141
+ padding: 5px;
142
+ font-size: 11px;
143
+ line-height: 11px;
144
+ vertical-align: baseline;
145
+
146
+ &.fs-warn
147
+ {
148
+ background: #ffba00;
149
+ }
150
+ &.fs-success
151
+ {
152
+ background: #46b450;
153
+ }
154
+ &.fs-error
155
+ {
156
+ background: #dc3232;
157
+ }
158
+ }
159
+
160
+ #fs_sites
161
+ {
162
+ .fs-scrollable-table
163
+ {
164
+ .fs-table-body {
165
+ max-height: 200px;
166
+ overflow: auto;
167
+ border: 1px solid #e5e5e5;
168
+
169
+ & > table.widefat {
170
+ border: none !important;
171
+ }
172
+ }
173
+
174
+ .fs-main-column {
175
+ width: 100%;
176
+ }
177
+
178
+ .fs-site-details
179
+ {
180
+ td:first-of-type
181
+ {
182
+ text-align: right;
183
+ color: grey;
184
+ width: 1px;
185
+ }
186
+
187
+ td:last-of-type
188
+ {
189
+ text-align: right;
190
+ }
191
+ }
192
+
193
+ .fs-install-details table
194
+ {
195
+ tr td
196
+ {
197
+ width: 1px;
198
+ white-space: nowrap;
199
+
200
+ &:last-of-type
201
+ {
202
+ width: auto;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+
209
+ #fs_addons
210
+ {
211
+ h3
212
+ {
213
+ border: none;
214
+ margin-bottom: 0;
215
+ padding: 4px 5px;
216
+ }
217
+
218
+ td
219
+ {
220
+ vertical-align: middle;
221
+ }
222
+
223
+ thead {
224
+ white-space: nowrap;
225
+ }
226
+
227
+ td:first-child,
228
+ th:first-child
229
+ {
230
+ text-align: left;
231
+ font-weight: bold;
232
+ }
233
+ td:last-child,
234
+ th:last-child
235
+ {
236
+ text-align: right;
237
+ }
238
+ th
239
+ {
240
+ font-weight: bold;
241
+ }
242
+ }
243
+
244
+ #fs_billing_address {
245
+ width: 100%;
246
+
247
+ tr {
248
+ td {
249
+ width: 50%;
250
+ padding: 5px;
251
+ }
252
+
253
+ &:first-of-type {
254
+ td {
255
+ padding-top: 0;
256
+ }
257
+ }
258
+ }
259
+
260
+ @mixin read-mode {
261
+ border-color: transparent;
262
+ color: #777;
263
+ border-bottom: 1px dashed #ccc;
264
+ padding-left: 0;
265
+ background: none;
266
+ }
267
+
268
+ span {
269
+ font-weight: bold;
270
+ }
271
+
272
+ input, select {
273
+ @include placeholder(transparent);
274
+
275
+ display: block;
276
+ width: 100%;
277
+ margin-top: 5px;
278
+
279
+ &.fs-read-mode {
280
+ @include read-mode();
281
+ }
282
+ }
283
+
284
+
285
+ &.fs-read-mode {
286
+ td span {
287
+ display: none;
288
+ }
289
+
290
+ input, select
291
+ {
292
+ @include read-mode();
293
+ @include placeholder(#ccc);
294
+ }
295
+ }
296
+
297
+
298
+ button {
299
+ display: block;
300
+ width: 100%;
301
+ }
302
+ }
lib/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
+ }
lib/freemius/assets/scss/admin/affiliation.scss ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_affiliation_content_wrapper {
4
+ #messages {
5
+ margin-top: 25px;
6
+ }
7
+
8
+ h3 {
9
+ font-size: 24px;
10
+ padding: 0;
11
+ margin-left: 0;
12
+ }
13
+
14
+ ul {
15
+ li {
16
+ @include box-sizing(border-box);
17
+ list-style-type: none;
18
+
19
+ &:before {
20
+ content: '✓';
21
+ margin-right: 10px;
22
+ font-weight: bold;
23
+ }
24
+ }
25
+ }
26
+
27
+ p:not(.description), li, label {
28
+ font-size: 16px !important;
29
+ line-height: 26px !important;
30
+ }
31
+
32
+ .button {
33
+ margin-top: 20px;
34
+ margin-bottom: 7px;
35
+ line-height: 35px;
36
+ height: 40px;
37
+ font-size: 16px;
38
+
39
+ &#cancel_button {
40
+ margin-right: 5px;
41
+ }
42
+ }
43
+
44
+ form {
45
+ .input-container {
46
+ .input-label {
47
+ font-weight: bold;
48
+ display: block;
49
+ width: 100%;
50
+ }
51
+
52
+ &.input-container-text {
53
+ label, input, textarea {
54
+ display: block;
55
+ }
56
+ }
57
+
58
+ margin-bottom: 15px;
59
+
60
+ #add_domain, .remove-domain {
61
+ text-decoration: none;
62
+ display: inline-block;
63
+ margin-top: 3px;
64
+
65
+ &:focus {
66
+ box-shadow: none;
67
+ }
68
+
69
+ &.disabled {
70
+ color: #aaa;
71
+ cursor: default;
72
+ }
73
+ }
74
+ }
75
+
76
+ #extra_domains_container {
77
+ .description {
78
+ margin-top: 0;
79
+ position: relative;
80
+ top: -4px;
81
+ }
82
+
83
+ .extra-domain-input-container {
84
+ margin-bottom: 15px;
85
+
86
+ .domain {
87
+ display: inline-block;
88
+ margin-right: 5px;
89
+
90
+ &:last-of-type {
91
+ margin-bottom: 0;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
lib/freemius/assets/scss/admin/checkout.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ @media screen and (max-width: 782px) {
2
+ #wpbody-content {
3
+ padding-bottom: 0 !important;
4
+ }
5
+ }
lib/freemius/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "themes";
3
+
4
+ #iframe
5
+ {
6
+ line-height: 0;
7
+ font-size: 0;
8
+ }
9
+
10
+ .fs-full-size-wrapper
11
+ {
12
+ margin: 40px 0 -65px -20px;
13
+
14
+ @media (max-width: 600px) {
15
+ margin: 0 0 -65px -10px;
16
+ }
17
+ }
18
+
19
+ .fs-notice
20
+ {
21
+ position: relative;
22
+
23
+ &.fs-has-title
24
+ {
25
+ margin-bottom: 30px !important;
26
+ }
27
+
28
+ &.success
29
+ {
30
+ color: green;
31
+ // font-weight: normal;
32
+ }
33
+
34
+ &.promotion
35
+ {
36
+ border-color: $fs-notice-promotion-border-color !important;
37
+ background-color: $fs-notice-promotion-bkg !important;
38
+ }
39
+
40
+ .fs-notice-body
41
+ {
42
+ margin: .5em 0;
43
+ padding: 2px;
44
+ }
45
+
46
+ .fs-close
47
+ {
48
+ // position: absolute;
49
+ // top: 2px;
50
+ // bottom: 2px;
51
+ // right: 2px;
52
+ // min-width: 100px;
53
+ // text-align: center;
54
+ // padding-right: 2px;
55
+ cursor: pointer;
56
+ color: #aaa;
57
+ float: right;
58
+
59
+ &:hover
60
+ {
61
+ color: #666;
62
+ // background: #A9A9A9;
63
+ }
64
+
65
+ > *
66
+ {
67
+ margin-top: 7px;
68
+ display: inline-block;
69
+ }
70
+ }
71
+
72
+ label.fs-plugin-title
73
+ {
74
+ background: rgba(0, 0, 0, 0.3);
75
+ color: #fff;
76
+ padding: 2px 10px;
77
+ position: absolute;
78
+ top: 100%;
79
+ bottom: auto;
80
+ right: auto;
81
+ @include border-radius(0 0 3px 3px);
82
+ left: 10px;
83
+ font-size: 12px;
84
+ font-weight: bold;
85
+ cursor: auto;
86
+ }
87
+ }
88
+
89
+ div.fs-notice
90
+ {
91
+ &.updated,
92
+ &.success,
93
+ &.promotion
94
+ {
95
+ display: block !important;
96
+ }
97
+ }
98
+
99
+ .rtl .fs-notice
100
+ {
101
+ .fs-close
102
+ {
103
+ // left: 2px;
104
+ // right: auto;
105
+ // padding-right: 0;
106
+ // padding-left: 2px;
107
+ float: left;
108
+ }
109
+ }
110
+
111
+ .fs-secure-notice
112
+ {
113
+ position: fixed;
114
+ top: 32px;
115
+ left: 160px;
116
+ right: 0;
117
+ background: rgb(235, 253, 235);
118
+ padding: 10px 20px;
119
+ color: green;
120
+ z-index: 9999;
121
+ @include box-shadow(0 2px 2px rgba(6, 113, 6, 0.3));
122
+ @include opacity(0.95);
123
+
124
+ &:hover
125
+ {
126
+ @include opacity(1);
127
+ }
128
+
129
+ a.fs-security-proof
130
+ {
131
+ color: green;
132
+ text-decoration: none;
133
+ }
134
+ }
135
+
136
+ @media screen and (max-width: 960px) {
137
+ .fs-secure-notice
138
+ {
139
+ left: 36px;
140
+ }
141
+ }
142
+
143
+ @media screen and (max-width: 600px) {
144
+ .fs-secure-notice
145
+ {
146
+ display: none;
147
+ }
148
+ }
149
+
150
+ @media screen and (max-width: 500px) {
151
+ #fs_promo_tab
152
+ {
153
+ display: none;
154
+ }
155
+ }
156
+
157
+ @media screen and (max-width: 782px) {
158
+ .fs-secure-notice
159
+ {
160
+ left: 0;
161
+ top: 46px;
162
+ text-align: center;
163
+ }
164
+ }
165
+
166
+ span.fs-submenu-item.fs-sub:before
167
+ {
168
+ // Add small arrow.
169
+ content: '\21B3';
170
+ padding: 0 5px;
171
+ }
172
+
173
+ .rtl
174
+ {
175
+ span.fs-submenu-item.fs-sub:before
176
+ {
177
+ // Add small RTL arrow.
178
+ content: '\21B2';
179
+ }
180
+ }
181
+
182
+ .fs-submenu-item
183
+ {
184
+ &.pricing
185
+ {
186
+ &.upgrade-mode
187
+ {
188
+ color: greenyellow;
189
+ }
190
+
191
+ &.trial-mode
192
+ {
193
+ color: #83e2ff;
194
+ }
195
+ }
196
+ }
197
+
198
+ #adminmenu .update-plugins.fs-trial
199
+ {
200
+ background-color: #00b9eb;
201
+ }
202
+ .fs-ajax-spinner
203
+ {
204
+ border: 0;
205
+ width: 20px;
206
+ height: 20px;
207
+ margin-right: 5px;
208
+ vertical-align: sub;
209
+ display: inline-block;
210
+ background: url('/wp-admin/images/wpspin_light-2x.gif');
211
+ background-size: contain;
212
+ }
213
+
214
+ .wrap.fs-section {
215
+ h2 {
216
+ text-align: left;
217
+ }
218
+ }
lib/freemius/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ .fs-error {
23
+ background: snow;
24
+ color: $fs-logo-magenta-color;
25
+ border: 1px solid $fs-logo-magenta-color;
26
+ @include box-shadow(0 1px 1px 0 rgba(0,0,0,.1));
27
+ text-align: center;
28
+ padding: 5px;
29
+ margin-bottom: 10px;
30
+ }
31
+
32
+ p
33
+ {
34
+ margin: 0;
35
+ padding: 0;
36
+ font-size: 1.2em;
37
+ }
38
+ }
39
+
40
+ .fs-license-key-container {
41
+ position: relative;
42
+ width: 280px;
43
+ margin: 10px auto 0 auto;
44
+
45
+ input {
46
+ width: 100%;
47
+ }
48
+
49
+ .dashicons {
50
+ position: absolute;
51
+ top: 5px;
52
+ right: 5px;
53
+ }
54
+ }
55
+
56
+ &.require-license-key {
57
+ #sites_list_container {
58
+ td {
59
+ cursor: pointer;
60
+ }
61
+ }
62
+ }
63
+
64
+ #delegate_to_site_admins {
65
+ margin-right: 15px;
66
+ float: right;
67
+ height: 26px;
68
+ vertical-align: middle;
69
+ line-height: 37px;
70
+ font-weight: bold;
71
+ border-bottom: 1px dashed;
72
+ text-decoration: none;
73
+
74
+ &.rtl {
75
+ margin-left: 15px;
76
+ margin-right: 0;
77
+ }
78
+ }
79
+
80
+ .fs-actions
81
+ {
82
+ padding: 10px 20px;
83
+ background: #C0C7CA;
84
+
85
+ .button
86
+ {
87
+ padding: 0 10px 1px;
88
+ line-height: 35px;
89
+ height: 37px;
90
+ font-size: 16px;
91
+ margin-bottom: 0;
92
+
93
+ .dashicons
94
+ {
95
+ font-size: 37px;
96
+ margin-left: -8px;
97
+ margin-right: 12px;
98
+ }
99
+
100
+ &.button-primary
101
+ {
102
+ padding-right: 15px;
103
+ padding-left: 15px;
104
+
105
+ &:after
106
+ {
107
+ content: ' \279C';
108
+ }
109
+
110
+ &.fs-loading
111
+ {
112
+ &:after
113
+ {
114
+ content: '';
115
+ }
116
+ }
117
+ }
118
+
119
+ &.button-secondary
120
+ {
121
+ float: right;
122
+ }
123
+ }
124
+
125
+ // .fs-skip
126
+ // {
127
+ // line-height: 38px;
128
+ // vertical-align: middle;
129
+ // text-decoration: none;
130
+ // margin-left: 10px;
131
+ // }
132
+ }
133
+
134
+ &.fs-anonymous-disabled
135
+ {
136
+ .fs-actions
137
+ {
138
+ .button.button-primary
139
+ {
140
+ width: 100%;
141
+ }
142
+ }
143
+ }
144
+
145
+ .fs-permissions
146
+ {
147
+ padding: 10px 20px;
148
+ background: #FEFEFE;
149
+ // background: #F1F1F1;
150
+ @include transition(background 0.5s ease);
151
+
152
+ .fs-license-sync-disclaimer {
153
+ text-align: center;
154
+ margin-top: 0;
155
+ }
156
+
157
+ .fs-trigger
158
+ {
159
+ font-size: 0.9em;
160
+ text-decoration: none;
161
+ text-align: center;
162
+ display: block;
163
+ }
164
+
165
+ ul
166
+ {
167
+ height: 0;
168
+ overflow: hidden;
169
+ margin: 0;
170
+
171
+ li
172
+ {
173
+ margin-bottom: 12px;
174
+
175
+ &:last-child
176
+ {
177
+ margin-bottom: 0;
178
+ }
179
+
180
+ i.dashicons
181
+ {
182
+ float: left;
183
+ font-size: 40px;
184
+ width: 40px;
185
+ height: 40px;
186
+ }
187
+
188
+ div
189
+ {
190
+ margin-left: 55px;
191
+
192
+ span
193
+ {
194
+ font-weight: bold;
195
+ text-transform: uppercase;
196
+ color: #23282d;
197
+ }
198
+
199
+ p
200
+ {
201
+ margin: 2px 0 0 0;
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ &.fs-open
208
+ {
209
+ background: #fff;
210
+
211
+ ul
212
+ {
213
+ height: auto;
214
+ margin: 20px 20px 10px 20px;
215
+ }
216
+ }
217
+
218
+ @media screen and (max-width: ($form_width - 1)) {
219
+ background: #fff;
220
+
221
+ .fs-trigger
222
+ {
223
+ display: none;
224
+ }
225
+
226
+ ul
227
+ {
228
+ height: auto;
229
+ margin: 20px;
230
+ }
231
+ }
232
+ }
233
+
234
+ .fs-freemium-licensing {
235
+ padding: 8px;
236
+ // background: #0085BA;
237
+ background: #777;
238
+ color: #fff;
239
+
240
+ p {
241
+ text-align: center;
242
+ display: block;
243
+ margin: 0;
244
+ padding: 0;
245
+ }
246
+
247
+ a {
248
+ color: #C2EEFF;
249
+ text-decoration: underline;
250
+ }
251
+ }
252
+
253
+ $icon_size: 80px;
254
+ $wp_logo_padding: $icon_size / 10;
255
+ $icons_top: 10px;
256
+
257
+ .fs-visual
258
+ {
259
+ padding: 12px;
260
+ line-height: 0;
261
+ background: #fafafa;
262
+ height: $icon_size;
263
+ position: relative;
264
+
265
+ .fs-site-icon
266
+ {
267
+ position: absolute;
268
+ left: 20px;
269
+ top: $icons_top;
270
+ }
271
+
272
+ .fs-connect-logo
273
+ {
274
+ position: absolute;
275
+ right: 20px;
276
+ top: $icons_top;
277
+ }
278
+
279
+ .fs-plugin-icon
280
+ {
281
+ position: absolute;
282
+ top: $icons_top;
283
+ left: 50%;
284
+ margin-left: - ($icon_size / 2);
285
+ }
286
+
287
+ .fs-plugin-icon,
288
+ .fs-site-icon,
289
+ img,
290
+ object
291
+ {
292
+ width: $icon_size;
293
+ height: $icon_size;
294
+ }
295
+
296
+ .dashicons-wordpress
297
+ {
298
+ font-size: $icon_size - ($wp_logo_padding * 2);
299
+ background: $wordpress_color;
300
+ color: #fff;
301
+ width: $icon_size - ($wp_logo_padding * 2);
302
+ height: $icon_size - ($wp_logo_padding * 2);
303
+ padding: $wp_logo_padding;
304
+ }
305
+
306
+ .dashicons-plus
307
+ {
308
+ position: absolute;
309
+ top: 50%;
310
+ font-size: 30px;
311
+ margin-top: -10px;
312
+ color: #bbb;
313
+
314
+ &.fs-first
315
+ {
316
+ left: 28%;
317
+ }
318
+ &.fs-second
319
+ {
320
+ left: 65%;
321
+ }
322
+ }
323
+
324
+ .fs-plugin-icon,
325
+ .fs-connect-logo,
326
+ .fs-site-icon
327
+ {
328
+ border: 1px solid #ccc;
329
+ padding: 1px;
330
+ background: #fff;
331
+ }
332
+ }
333
+
334
+ .fs-terms
335
+ {
336
+ text-align: center;
337
+ font-size: 0.85em;
338
+ padding: 5px;
339
+ background: rgba(0, 0, 0, 0.05);
340
+
341
+ &, a
342
+ {
343
+ color: #999;
344
+ }
345
+
346
+ a
347
+ {
348
+ text-decoration: none;
349
+ }
350
+ }
351
+ }
352
+
353
+ @import "multisite-options";
354
+ @import "tooltip";
355
+ @import "gdpr-consent";
356
+
357
+ .rtl
358
+ {
359
+ #fs_connect
360
+ {
361
+ .fs-actions
362
+ {
363
+ padding: 10px 20px;
364
+ background: #C0C7CA;
365
+
366
+ .button
367
+ {
368
+ .dashicons
369
+ {
370
+ font-size: 37px;
371
+ margin-left: -8px;
372
+ margin-right: 12px;
373
+ }
374
+
375
+ &.button-primary
376
+ {
377
+ &:after
378
+ {
379
+ content: ' \000bb';
380
+ }
381
+
382
+ &.fs-loading
383
+ {
384
+ &:after
385
+ {
386
+ content: '';
387
+ }
388
+ }
389
+ }
390
+
391
+ &.button-secondary
392
+ {
393
+ float: left;
394
+ }
395
+ }
396
+ }
397
+
398
+ .fs-permissions
399
+ {
400
+ ul
401
+ {
402
+ li
403
+ {
404
+ div
405
+ {
406
+ margin-right: 55px;
407
+ margin-left: 0;
408
+ }
409
+
410
+ i.dashicons
411
+ {
412
+ float: right;
413
+ }
414
+
415
+ }
416
+ }
417
+ }
418
+
419
+ .fs-visual
420
+ {
421
+ .fs-site-icon
422
+ {
423
+ right: 20px;
424
+ left: auto;
425
+ }
426
+
427
+ .fs-connect-logo
428
+ {
429
+ right: auto;
430
+ left: 20px;
431
+ }
432
+ }
433
+ }
434
+ }
435
+
436
+ #fs_theme_connect_wrapper {
437
+ position: fixed;
438
+ top: 0;
439
+ height: 100%;
440
+ width: 100%;
441
+ z-index: 99990;
442
+ background: rgba(0, 0, 0, 0.75);
443
+ text-align: center;
444
+ overflow-y: auto;
445
+
446
+ &:before {
447
+ content: "";
448
+ display: inline-block;
449
+ vertical-align: middle;
450
+ height: 100%;
451
+ }
452
+
453
+ > button.close {
454
+ color: white;
455
+ cursor: pointer;
456
+ height: 40px;
457
+ width: 40px;
458
+ position: absolute;
459
+ right: 0;
460
+ border: 0;
461
+ background-color: transparent;
462
+ top: 32px;
463
+ }
464
+
465
+ #fs_connect {
466
+ top: 0;
467
+ text-align: left;
468
+ display: inline-block;
469
+ vertical-align: middle;
470
+ margin-top: 52px;
471
+ margin-bottom: 20px;
472
+
473
+ .fs-terms
474
+ {
475
+ background: rgba(140, 140, 140, 0.64);
476
+
477
+ &, a
478
+ {
479
+ color: #c5c5c5;
480
+ }
481
+ }
482
+ }
483
+ }
484
+
485
+ .wp-pointer-content
486
+ {
487
+ #fs_connect
488
+ {
489
+ margin: 0;
490
+ @include box-shadow(none);
491
+ }
492
+ }
493
+
494
+ .fs-opt-in-pointer
495
+ {
496
+ .wp-pointer-content
497
+ {
498
+ padding: 0;
499
+ }
500
+
501
+ &.wp-pointer-top
502
+ {
503
+ .wp-pointer-arrow
504
+ {
505
+ border-bottom-color: #dfdfdf;
506
+ }
507
+ .wp-pointer-arrow-inner
508
+ {
509
+ border-bottom-color: #fafafa;
510
+ }
511
+ }
512
+
513
+ &.wp-pointer-bottom
514
+ {
515
+ .wp-pointer-arrow
516
+ {
517
+ border-top-color: #dfdfdf;
518
+ }
519
+ .wp-pointer-arrow-inner
520
+ {
521
+ border-top-color: #fafafa;
522
+ }
523
+ }
524
+
525
+ &.wp-pointer-left
526
+ {
527
+ .wp-pointer-arrow
528
+ {
529
+ border-right-color: #dfdfdf;
530
+ }
531
+ .wp-pointer-arrow-inner
532
+ {
533
+ border-right-color: #fafafa;
534
+ }
535
+ }
536
+
537
+ &.wp-pointer-right
538
+ {
539
+ .wp-pointer-arrow
540
+ {
541
+ border-left-color: #dfdfdf;
542
+ }
543
+ .wp-pointer-arrow-inner
544
+ {
545
+ border-left-color: #fafafa;
546
+ }
547
+ }
548
+ }
lib/freemius/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
92
+
93
+ #fs_log_book {
94
+ table {
95
+ font-family: Consolas,Monaco,monospace;
96
+ font-size: 12px;
97
+
98
+ th {
99
+ color: #ccc;
100
+ }
101
+
102
+ tr {
103
+ background: #232525;
104
+
105
+ &.alternate {
106
+ background: #2b2b2b;
107
+ }
108
+
109
+ td {
110
+ &.fs-col--logger {
111
+ color: #5a7435;
112
+ }
113
+ &.fs-col--type {
114
+ color: #ffc861;
115
+ }
116
+ &.fs-col--function {
117
+ color: #a7b7b1;
118
+ font-weight: bold;
119
+ }
120
+ &.fs-col--message {
121
+ &, a
122
+ {
123
+ color: #9a73ac !important;
124
+ }
125
+ }
126
+ &.fs-col--file {
127
+ color: #d07922;
128
+ }
129
+ &.fs-col--timestamp {
130
+ color: #6596be;
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
lib/freemius/assets/scss/admin/dialog-boxes.scss ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+ @import "modal-common";
3
+ @import "deactivation-feedback";
4
+ @import "license-activation";
5
+ @import "multisite-options";
6
+ @import "license-key-resend";
7
+ @import "ajax-loader";
8
+ @import "auto-install";
lib/freemius/assets/scss/admin/gdpr-optin-notice.scss ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-notice[data-id^="gdpr_optin_actions"]
2
+ {
3
+ .underlined {
4
+ text-decoration: underline;
5
+ }
6
+
7
+ ul {
8
+ .button, .action-description {
9
+ vertical-align: middle;
10
+ }
11
+
12
+ .action-description {
13
+ display: inline-block;
14
+ margin-left: 3px;
15
+ }
16
+ }
17
+ }
lib/freemius/assets/scss/admin/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
lib/freemius/assets/scss/customizer.scss ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "start";
2
+
3
+ #fs_customizer_upsell {
4
+ .fs-customizer-plan {
5
+ padding: 10px 20px 20px 20px;
6
+ border-radius: 3px;
7
+ background: #fff;
8
+
9
+ h2 {
10
+ position: relative;
11
+ margin: 0;
12
+ line-height: 2em;
13
+ text-transform: uppercase;
14
+
15
+ .button-link {
16
+ top: -2px;
17
+ }
18
+ }
19
+ }
20
+
21
+ .fs-feature {
22
+ position: relative;
23
+ }
24
+
25
+ .dashicons-yes {
26
+ color: #0085ba;
27
+ font-size: 2em;
28
+ vertical-align: bottom;
29
+ margin-left: -7px;
30
+ margin-right: 10px;
31
+
32
+ .rtl & {
33
+ margin-left: 10px;
34
+ margin-right: -7px;
35
+ }
36
+ }
37
+
38
+ .dashicons-editor-help
39
+ {
40
+ color: #bbb;
41
+ cursor: help;
42
+
43
+ $tooltip-color: #000;
44
+
45
+ .fs-feature-desc {
46
+ opacity: 0;
47
+ visibility: hidden;
48
+ @include transition(opacity 0.3s ease-in-out);
49
+
50
+ position: absolute;
51
+ background: $tooltip-color;
52
+ color: #fff;
53
+ font-family: 'arial', serif;
54
+ font-size: 12px;
55
+ padding: 10px;
56
+ z-index: 999999;
57
+ bottom: 100%;
58
+ margin-bottom: 5px;
59
+ left: 0;
60
+ right: 0;
61
+ @include border-radius(5px);
62
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.2));
63
+ line-height: 1.3em;
64
+ font-weight: bold;
65
+ text-align: left;
66
+
67
+ .rtl &
68
+ {
69
+ text-align: right;
70
+ }
71
+
72
+ &::after {
73
+ content: ' ';
74
+ display: block;
75
+ width: 0;
76
+ height: 0;
77
+ border-style: solid;
78
+ border-width: 5px 5px 0 5px;
79
+ border-color: $tooltip-color transparent transparent transparent;
80
+ position: absolute;
81
+ top: 100%;
82
+ left: 21px;
83
+
84
+ .rtl & {
85
+ right: 21px;
86
+ left: auto;
87
+ }
88
+ }
89
+ }
90
+
91
+ &:hover {
92
+ .fs-feature-desc {
93
+ visibility: visible;
94
+ opacity: 1;
95
+ }
96
+ }
97
+ }
98
+
99
+ .button-primary {
100
+ display: block;
101
+ text-align: center;
102
+ margin-top: 10px;
103
+ }
104
+ }
105
+
106
+ #fs_customizer_support
107
+ {
108
+ display: block !important;
109
+
110
+ .button {
111
+ float: right;
112
+ }
113
+
114
+ .button-group {
115
+ width: 100%;
116
+ display: block;
117
+ margin-top: 10px;
118
+
119
+ .button {
120
+ float: none;
121
+ width: 50%;
122
+ text-align: center;
123
+ }
124
+ }
125
+ }
lib/freemius/assets/scss/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ // Hide file structure from users on unprotected servers.
lib/freemius/config.php ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! defined( 'WP_FS__SLUG' ) ) {
14
+ define( 'WP_FS__SLUG', 'freemius' );
15
+ }
16
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
+ define( 'WP_FS__DEV_MODE', false );
18
+ }
19
+
20
+ #--------------------------------------------------------------------------------
21
+ #region API Connectivity Issues Simulation
22
+ #--------------------------------------------------------------------------------
23
+
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
+ }
33
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_CURL ) {
37
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
+ }
42
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
+ }
45
+
46
+ #endregion
47
+
48
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
+ }
51
+
52
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
+ /**
54
+ * @since 1.1.7.3
55
+ * @author Vova Feldman (@svovaf)
56
+ *
57
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
59
+ * between domains on a daily basis. Therefore, to eliminate the risk of
60
+ * multiple unwanted connectivity test pings, temporary ignore domain or
61
+ * server IP changes.
62
+ */
63
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
+ }
65
+
66
+ /**
67
+ * If your dev environment supports custom public network IP setup
68
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
+ * and uncomment it during dev.
70
+ */
71
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
+ // VVV default public network IP.
73
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
+
75
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
+ }
77
+
78
+ /**
79
+ * If true and running with secret key, the opt-in process
80
+ * will skip the email activation process which is invoked
81
+ * when the email of the context user already exist in Freemius
82
+ * database (as a security precaution, to prevent sharing user
83
+ * secret with unauthorized entity).
84
+ *
85
+ * IMPORTANT:
86
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
+ * CLOCK IS SYNCED.
89
+ */
90
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
+ }
93
+
94
+
95
+ #--------------------------------------------------------------------------------
96
+ #region Directories
97
+ #--------------------------------------------------------------------------------
98
+
99
+ if ( ! defined( 'WP_FS__DIR' ) ) {
100
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
+ }
102
+ if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
+ }
105
+ if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
+ }
108
+ if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
+ }
111
+ if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
+ }
114
+ if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
+ }
117
+ if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
+ }
120
+ if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
+ }
123
+
124
+ #endregion
125
+
126
+ /**
127
+ * Domain / URL / Address
128
+ */
129
+ define( 'WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com' );
130
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
131
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
132
+
133
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
134
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
135
+ }
136
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
137
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
138
+ }
139
+
140
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
141
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
142
+ }
143
+
144
+ #--------------------------------------------------------------------------------
145
+ #region HTTP
146
+ #--------------------------------------------------------------------------------
147
+
148
+ if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
149
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
150
+ }
151
+
152
+ if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
153
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
154
+ // Checks if CloudFlare's HTTPS (Flexible SSL support).
155
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
156
+ 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
157
+ ) ||
158
+ // Check if HTTPS request.
159
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
160
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
161
+ );
162
+ }
163
+
164
+ if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
165
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
166
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
167
+ }
168
+
169
+ if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
170
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
171
+ }
172
+
173
+ if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
174
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
175
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
176
+ } else {
177
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
178
+ is_string( WP_FS__REMOTE_ADDR ) &&
179
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
180
+ WP_FS__REMOTE_ADDR === '::1' )
181
+ );
182
+ }
183
+ }
184
+
185
+ if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
186
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
187
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
188
+ }
189
+
190
+ #endregion
191
+
192
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
193
+ // By default, run with Freemius production servers.
194
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
195
+ }
196
+
197
+ if ( ! defined( 'WP_FS__ADDRESS' ) ) {
198
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
199
+ }
200
+
201
+
202
+ #--------------------------------------------------------------------------------
203
+ #region API
204
+ #--------------------------------------------------------------------------------
205
+
206
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
207
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
208
+ }
209
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
210
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
211
+ }
212
+
213
+ // Set API address for local testing.
214
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
215
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
216
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
217
+ }
218
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
219
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
220
+ }
221
+ }
222
+
223
+ #endregion
224
+
225
+ #--------------------------------------------------------------------------------
226
+ #region Checkout
227
+ #--------------------------------------------------------------------------------
228
+
229
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_PRODUCTION' ) ) {
230
+ define( 'FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com' );
231
+ }
232
+
233
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS_LOCALHOST' ) ) {
234
+ define( 'FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius-local.com:8080' );
235
+ }
236
+
237
+ if ( ! defined( 'FS_CHECKOUT__ADDRESS' ) ) {
238
+ define( 'FS_CHECKOUT__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST ) );
239
+ }
240
+
241
+ #endregion
242
+
243
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
244
+
245
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
246
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
247
+ }
248
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
249
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
250
+ }
251
+ if ( ! defined( 'WP_FS__GDPR_OPTION_NAME' ) ) {
252
+ define( 'WP_FS__GDPR_OPTION_NAME', WP_FS___OPTION_PREFIX . 'gdpr' );
253
+ }
254
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
255
+
256
+ /**
257
+ * Module types
258
+ *
259
+ * @since 1.2.2
260
+ */
261
+ define( 'WP_FS__MODULE_TYPE_PLUGIN', 'plugin' );
262
+ define( 'WP_FS__MODULE_TYPE_THEME', 'theme' );
263
+
264
+ /**
265
+ * Billing Frequencies
266
+ */
267
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
268
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
269
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
270
+
271
+ /**
272
+ * Plans
273
+ */
274
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
275
+ define( 'WP_FS__PLAN_FREE', 'free' );
276
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
277
+
278
+ /**
279
+ * Times in seconds
280
+ */
281
+ if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
282
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
283
+ }
284
+ if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
285
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
286
+ }
287
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
288
+ if ( ! defined( 'WP_FS__TIME_12_HOURS_IN_SEC' ) ) {
289
+ define( 'WP_FS__TIME_12_HOURS_IN_SEC', 43200 );
290
+ }
291
+ if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
292
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', WP_FS__TIME_12_HOURS_IN_SEC * 2 );
293
+ }
294
+ if ( ! defined( 'WP_FS__TIME_WEEK_IN_SEC' ) ) {
295
+ define( 'WP_FS__TIME_WEEK_IN_SEC', 7 * WP_FS__TIME_24_HOURS_IN_SEC );
296
+ }
297
+
298
+ #--------------------------------------------------------------------------------
299
+ #region Debugging
300
+ #--------------------------------------------------------------------------------
301
+
302
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
303
+ $debug_mode = get_option( 'fs_debug_mode', null );
304
+
305
+ if ( $debug_mode === null ) {
306
+ $debug_mode = false;
307
+ add_option( 'fs_debug_mode', $debug_mode );
308
+ }
309
+
310
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
311
+ }
312
+
313
+ if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
314
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
315
+ }
316
+ if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
317
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
318
+ }
319
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
320
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
321
+ }
322
+
323
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
324
+ error_reporting( E_ALL );
325
+ }
326
+
327
+ #endregion
328
+
329
+ if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
330
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
331
+ }
332
+ if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
333
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
334
+ }
335
+ if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
336
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
337
+ }
338
+
339
+ #--------------------------------------------------------------------------------
340
+ #region Multisite Network
341
+ #--------------------------------------------------------------------------------
342
+
343
+ /**
344
+ * Do not use this define directly, it will have the wrong value
345
+ * during plugin uninstall/deletion when the inclusion of the plugin
346
+ * is triggered due to registration with register_uninstall_hook().
347
+ *
348
+ * Instead, use fs_is_network_admin().
349
+ *
350
+ * @author Vova Feldman (@svovaf)
351
+ */
352
+ if ( ! defined( 'WP_FS__IS_NETWORK_ADMIN' ) ) {
353
+ define( 'WP_FS__IS_NETWORK_ADMIN',
354
+ is_network_admin() ||
355
+ ( is_multisite() &&
356
+ ( ( defined( 'DOING_AJAX' ) && DOING_AJAX &&
357
+ ( isset( $_REQUEST['_fs_network_admin'] ) /*||
358
+ ( ! empty( $_REQUEST['action'] ) && 'delete-plugin' === $_REQUEST['action'] )*/ )
359
+ ) ||
360
+ // Plugin uninstall.
361
+ defined( 'WP_UNINSTALL_PLUGIN' ) )
362
+ )
363
+ );
364
+ }
365
+
366
+ /**
367
+ * Do not use this define directly, it will have the wrong value
368
+ * during plugin uninstall/deletion when the inclusion of the plugin
369
+ * is triggered due to registration with register_uninstall_hook().
370
+ *
371
+ * Instead, use fs_is_blog_admin().
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ */
375
+ if ( ! defined( 'WP_FS__IS_BLOG_ADMIN' ) ) {
376
+ define( 'WP_FS__IS_BLOG_ADMIN', is_blog_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['_fs_blog_admin'] ) ) );
377
+ }
378
+
379
+ if ( ! defined( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED' ) ) {
380
+ // Set to true to show network level settings even if delegated to site admins.
381
+ define( 'WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED', false );
382
+ }
383
+
384
+ #endregion
385
+
386
+ if ( ! defined( 'WP_FS__DEMO_MODE' ) ) {
387
+ define( 'WP_FS__DEMO_MODE', false );
388
+ }
lib/freemius/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+
14
+ /**
15
+ * - Each instance of Freemius class represents a single plugin
16
+ * install by a single user (the installer of the plugin).
17
+ *
18
+ * - Each website can only have one install of the same plugin.
19
+ *
20
+ * - Install entity is only created after a user connects his account with Freemius.
21
+ *
22
+ * Class Freemius_Abstract
23
+ */
24
+ abstract class Freemius_Abstract {
25
+
26
+ #----------------------------------------------------------------------------------
27
+ #region Identity
28
+ #----------------------------------------------------------------------------------
29
+
30
+ /**
31
+ * Check if user has connected his account (opted-in).
32
+ *
33
+ * Note:
34
+ * If the user opted-in and opted-out on a later stage,
35
+ * this will still return true. If you want to check if the
36
+ * user is currently opted-in, use:
37
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
38
+ *
39
+ * @since 1.0.1
40
+ * @return bool
41
+ */
42
+ abstract function is_registered();
43
+
44
+ /**
45
+ * Check if the user skipped connecting the account with Freemius.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_anonymous();
52
+
53
+ /**
54
+ * Check if the user currently in activation mode.
55
+ *
56
+ * @since 1.0.7
57
+ *
58
+ * @return bool
59
+ */
60
+ abstract function is_activation_mode();
61
+
62
+ #endregion
63
+
64
+ #----------------------------------------------------------------------------------
65
+ #region Usage Tracking
66
+ #----------------------------------------------------------------------------------
67
+
68
+ /**
69
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
70
+ *
71
+ * @author Leo Fajardo (@leorw)
72
+ * @since 1.2.1.5
73
+ *
74
+ * @return bool
75
+ */
76
+ abstract function is_tracking_allowed();
77
+
78
+ /**
79
+ * Returns TRUE if the user never opted-in or manually opted-out.
80
+ *
81
+ * @author Vova Feldman (@svovaf)
82
+ * @since 1.2.1.5
83
+ *
84
+ * @return bool
85
+ */
86
+ function is_tracking_prohibited() {
87
+ return ! $this->is_registered() || ! $this->is_tracking_allowed();
88
+ }
89
+
90
+ /**
91
+ * Opt-out from usage tracking.
92
+ *
93
+ * Note: This will not delete the account information but will stop all tracking.
94
+ *
95
+ * Returns:
96
+ * 1. FALSE - If the user never opted-in.
97
+ * 2. TRUE - If successfully opted-out.
98
+ * 3. object - API Result on failure.
99
+ *
100
+ * @author Leo Fajardo (@leorw)
101
+ * @since 1.2.1.5
102
+ *
103
+ * @return bool|object
104
+ */
105
+ abstract function stop_tracking();
106
+
107
+ /**
108
+ * Opt-in back into usage tracking.
109
+ *
110
+ * Note: This will only work if the user opted-in previously.
111
+ *
112
+ * Returns:
113
+ * 1. FALSE - If the user never opted-in.
114
+ * 2. TRUE - If successfully opted-in back to usage tracking.
115
+ * 3. object - API result on failure.
116
+ *
117
+ * @author Leo Fajardo (@leorw)
118
+ * @since 1.2.1.5
119
+ *
120
+ * @return bool|object
121
+ */
122
+ abstract function allow_tracking();
123
+
124
+ #endregion
125
+
126
+ #----------------------------------------------------------------------------------
127
+ #region Module Type
128
+ #----------------------------------------------------------------------------------
129
+
130
+ /**
131
+ * Checks if the plugin's type is "plugin". The other type is "theme".
132
+ *
133
+ * @author Leo Fajardo (@leorw)
134
+ * @since 1.2.2
135
+ *
136
+ * @return bool
137
+ */
138
+ abstract function is_plugin();
139
+
140
+ /**
141
+ * Checks if the module type is "theme". The other type is "plugin".
142
+ *
143
+ * @author Leo Fajardo (@leorw)
144
+ * @since 1.2.2
145
+ *
146
+ * @return bool
147
+ */
148
+ function is_theme() {
149
+ return ( ! $this->is_plugin() );
150
+ }
151
+
152
+ #endregion
153
+
154
+ #----------------------------------------------------------------------------------
155
+ #region Permissions
156
+ #----------------------------------------------------------------------------------
157
+
158
+ /**
159
+ * Check if plugin must be WordPress.org compliant.
160
+ *
161
+ * @since 1.0.7
162
+ *
163
+ * @return bool
164
+ */
165
+ abstract function is_org_repo_compliant();
166
+
167
+ /**
168
+ * Check if plugin is allowed to install executable files.
169
+ *
170
+ * @author Vova Feldman (@svovaf)
171
+ * @since 1.0.5
172
+ *
173
+ * @return bool
174
+ */
175
+ function is_allowed_to_install() {
176
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
177
+ }
178
+
179
+ #endregion
180
+
181
+ /**
182
+ * Check if user in trial or in free plan (not paying).
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @return bool
188
+ */
189
+ function is_not_paying() {
190
+ return ( $this->is_trial() || $this->is_free_plan() );
191
+ }
192
+
193
+ /**
194
+ * Check if the user has an activated and valid paid license on current plugin's install.
195
+ *
196
+ * @since 1.0.9
197
+ *
198
+ * @return bool
199
+ */
200
+ abstract function is_paying();
201
+
202
+ /**
203
+ * Check if the user is paying or in trial.
204
+ *
205
+ * @since 1.0.9
206
+ *
207
+ * @return bool
208
+ */
209
+ function is_paying_or_trial() {
210
+ return ( $this->is_paying() || $this->is_trial() );
211
+ }
212
+
213
+ /**
214
+ * Check if user in a trial or have feature enabled license.
215
+ *
216
+ * @author Vova Feldman (@svovaf)
217
+ * @since 1.1.7
218
+ *
219
+ * @return bool
220
+ */
221
+ abstract function can_use_premium_code();
222
+
223
+ #----------------------------------------------------------------------------------
224
+ #region Premium Only
225
+ #----------------------------------------------------------------------------------
226
+
227
+ /**
228
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
229
+ * included in the premium code.
230
+ *
231
+ * Example:
232
+ * if ( freemius()->is__premium_only() ) {
233
+ * ...
234
+ * }
235
+ */
236
+
237
+ /**
238
+ * Returns true when running premium plugin code.
239
+ *
240
+ * @since 1.0.9
241
+ *
242
+ * @return bool
243
+ */
244
+ function is__premium_only() {
245
+ return $this->is_premium();
246
+ }
247
+
248
+ /**
249
+ * Check if the user has an activated and valid paid license on current plugin's install.
250
+ *
251
+ * @since 1.0.9
252
+ *
253
+ * @return bool
254
+ *
255
+ */
256
+ function is_paying__premium_only() {
257
+ return ( $this->is__premium_only() && $this->is_paying() );
258
+ }
259
+
260
+ /**
261
+ * All code wrapped in this statement will be only included in the premium code.
262
+ *
263
+ * @since 1.0.9
264
+ *
265
+ * @param string $plan Plan name.
266
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
267
+ *
268
+ * @return bool
269
+ */
270
+ function is_plan__premium_only( $plan, $exact = false ) {
271
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
272
+ }
273
+
274
+ /**
275
+ * Check if plan matches active license' plan or active trial license' plan.
276
+ *
277
+ * All code wrapped in this statement will be only included in the premium code.
278
+ *
279
+ * @since 1.0.9
280
+ *
281
+ * @param string $plan Plan name.
282
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
283
+ *
284
+ * @return bool
285
+ */
286
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
287
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
288
+ }
289
+
290
+ /**
291
+ * Check if the user is paying or in trial.
292
+ *
293
+ * All code wrapped in this statement will be only included in the premium code.
294
+ *
295
+ * @since 1.0.9
296
+ *
297
+ * @return bool
298
+ */
299
+ function is_paying_or_trial__premium_only() {
300
+ return $this->is_premium() && $this->is_paying_or_trial();
301
+ }
302
+
303
+ /**
304
+ * Check if the user has an activated and valid paid license on current plugin's install.
305
+ *
306
+ * @since 1.0.4
307
+ *
308
+ * @return bool
309
+ *
310
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
311
+ * @using Alias to is_paying__premium_only()
312
+ */
313
+ function is_paying__fs__() {
314
+ return $this->is_paying__premium_only();
315
+ }
316
+
317
+ /**
318
+ * Check if user in a trial or have feature enabled license.
319
+ *
320
+ * All code wrapped in this statement will be only included in the premium code.
321
+ *
322
+ * @author Vova Feldman (@svovaf)
323
+ * @since 1.1.9
324
+ *
325
+ * @return bool
326
+ */
327
+ function can_use_premium_code__premium_only() {
328
+ return $this->is_premium() && $this->can_use_premium_code();
329
+ }
330
+
331
+ #endregion
332
+
333
+ #----------------------------------------------------------------------------------
334
+ #region Trial
335
+ #----------------------------------------------------------------------------------
336
+
337
+ /**
338
+ * Check if the user in a trial.
339
+ *
340
+ * @since 1.0.3
341
+ *
342
+ * @return bool
343
+ */
344
+ abstract function is_trial();
345
+
346
+ /**
347
+ * Check if trial already utilized.
348
+ *
349
+ * @since 1.0.9
350
+ *
351
+ * @return bool
352
+ */
353
+ abstract function is_trial_utilized();
354
+
355
+ #endregion
356
+
357
+ #----------------------------------------------------------------------------------
358
+ #region Plans
359
+ #----------------------------------------------------------------------------------
360
+
361
+ /**
362
+ * Check if the user is on the free plan of the product.
363
+ *
364
+ * @since 1.0.4
365
+ *
366
+ * @return bool
367
+ */
368
+ abstract function is_free_plan();
369
+
370
+ /**
371
+ * @since 1.0.2
372
+ *
373
+ * @param string $plan Plan name.
374
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
375
+ *
376
+ * @return bool
377
+ */
378
+ abstract function is_plan( $plan, $exact = false );
379
+
380
+ /**
381
+ * Check if plan based on trial. If not in trial mode, should return false.
382
+ *
383
+ * @since 1.0.9
384
+ *
385
+ * @param string $plan Plan name.
386
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
387
+ *
388
+ * @return bool
389
+ */
390
+ abstract function is_trial_plan( $plan, $exact = false );
391
+
392
+ /**
393
+ * Check if plan matches active license' plan or active trial license' plan.
394
+ *
395
+ * @since 1.0.9
396
+ *
397
+ * @param string $plan Plan name.
398
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
399
+ *
400
+ * @return bool
401
+ */
402
+ function is_plan_or_trial( $plan, $exact = false ) {
403
+ return $this->is_plan( $plan, $exact ) ||
404
+ $this->is_trial_plan( $plan, $exact );
405
+ }
406
+
407
+ /**
408
+ * Check if plugin has any paid plans.
409
+ *
410
+ * @author Vova Feldman (@svovaf)
411
+ * @since 1.0.7
412
+ *
413
+ * @return bool
414
+ */
415
+ abstract function has_paid_plan();
416
+
417
+ /**
418
+ * Check if plugin has any free plan, or is it premium only.
419
+ *
420
+ * Note: If no plans configured, assume plugin is free.
421
+ *
422
+ * @author Vova Feldman (@svovaf)
423
+ * @since 1.0.7
424
+ *
425
+ * @return bool
426
+ */
427
+ abstract function has_free_plan();
428
+
429
+ /**
430
+ * Check if plugin is premium only (no free plans).
431
+ *
432
+ * NOTE: is__premium_only() is very different method, don't get confused.
433
+ *
434
+ * @author Vova Feldman (@svovaf)
435
+ * @since 1.1.9
436
+ *
437
+ * @return bool
438
+ */
439
+ abstract function is_only_premium();
440
+
441
+ /**
442
+ * Check if module has a premium code version.
443
+ *
444
+ * Serviceware module might be freemium without any
445
+ * premium code version, where the paid features
446
+ * are all part of the service.
447
+ *
448
+ * @author Vova Feldman (@svovaf)
449
+ * @since 1.2.1.6
450
+ *
451
+ * @return bool
452
+ */
453
+ abstract function has_premium_version();
454
+
455
+ /**
456
+ * Check if module has any release on Freemius,
457
+ * or all plugin's code is on WordPress.org (Serviceware).
458
+ *
459
+ * @return bool
460
+ */
461
+ function has_release_on_freemius() {
462
+ return ! $this->is_org_repo_compliant() ||
463
+ $this->has_premium_version();
464
+ }
465
+
466
+ /**
467
+ * Checks if it's a freemium plugin.
468
+ *
469
+ * @author Vova Feldman (@svovaf)
470
+ * @since 1.1.9
471
+ *
472
+ * @return bool
473
+ */
474
+ function is_freemium() {
475
+ return $this->has_paid_plan() &&
476
+ $this->has_free_plan();
477
+ }
478
+
479
+ /**
480
+ * Check if module has only one plan.
481
+ *
482
+ * @author Vova Feldman (@svovaf)
483
+ * @since 1.2.1.7
484
+ *
485
+ * @return bool
486
+ */
487
+ abstract function is_single_plan();
488
+
489
+ #endregion
490
+
491
+ /**
492
+ * Check if running payments in sandbox mode.
493
+ *
494
+ * @since 1.0.4
495
+ *
496
+ * @return bool
497
+ */
498
+ abstract function is_payments_sandbox();
499
+
500
+ /**
501
+ * Check if running test vs. live plugin.
502
+ *
503
+ * @since 1.0.5
504
+ *
505
+ * @return bool
506
+ */
507
+ abstract function is_live();
508
+
509
+ /**
510
+ * Check if running premium plugin code.
511
+ *
512
+ * @since 1.0.5
513
+ *
514
+ * @return bool
515
+ */
516
+ abstract function is_premium();
517
+
518
+ /**
519
+ * Get upgrade URL.
520
+ *
521
+ * @author Vova Feldman (@svovaf)
522
+ * @since 1.0.2
523
+ *
524
+ * @param string $period Billing cycle.
525
+ *
526
+ * @return string
527
+ */
528
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
529
+
530
+ /**
531
+ * Check if Freemius was first added in a plugin update.
532
+ *
533
+ * @author Vova Feldman (@svovaf)
534
+ * @since 1.1.5
535
+ *
536
+ * @return bool
537
+ */
538
+ function is_plugin_update() {
539
+ return ! $this->is_plugin_new_install();
540
+ }
541
+
542
+ /**
543
+ * Check if Freemius was part of the plugin when the user installed it first.
544
+ *
545
+ * @author Vova Feldman (@svovaf)
546
+ * @since 1.1.5
547
+ *
548
+ * @return bool
549
+ */
550
+ abstract function is_plugin_new_install();
551
+
552
+ #----------------------------------------------------------------------------------
553
+ #region Marketing
554
+ #----------------------------------------------------------------------------------
555
+
556
+ /**
557
+ * Check if current user purchased any other plugins before.
558
+ *
559
+ * @author Vova Feldman (@svovaf)
560
+ * @since 1.0.9
561
+ *
562
+ * @return bool
563
+ */
564
+ abstract function has_purchased_before();
565
+
566
+ /**
567
+ * Check if current user classified as an agency.
568
+ *
569
+ * @author Vova Feldman (@svovaf)
570
+ * @since 1.0.9
571
+ *
572
+ * @return bool
573
+ */
574
+ abstract function is_agency();
575
+
576
+ /**
577
+ * Check if current user classified as a developer.
578
+ *
579
+ * @author Vova Feldman (@svovaf)
580
+ * @since 1.0.9
581
+ *
582
+ * @return bool
583
+ */
584
+ abstract function is_developer();
585
+
586
+ /**
587
+ * Check if current user classified as a business.
588
+ *
589
+ * @author Vova Feldman (@svovaf)
590
+ * @since 1.0.9
591
+ *
592
+ * @return bool
593
+ */
594
+ abstract function is_business();
595
+
596
+ #endregion
597
+ }
lib/freemius/includes/class-freemius.php ADDED
@@ -0,0 +1,20969 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
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
+ * @since 1.2.2
72
+ *
73
+ * @var string
74
+ */
75
+ private $_module_type;
76
+
77
+ #endregion Plugin Info
78
+
79
+ /**
80
+ * @since 1.0.9
81
+ *
82
+ * @var bool If false, don't turn Freemius on.
83
+ */
84
+ private $_is_on;
85
+
86
+ /**
87
+ * @since 1.1.3
88
+ *
89
+ * @var bool If false, don't turn Freemius on.
90
+ */
91
+ private $_is_anonymous;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool If false, issues with connectivity to Freemius API.
96
+ */
97
+ private $_has_api_connection;
98
+
99
+ /**
100
+ * @since 1.0.9
101
+ * @since 2.0.0 Default to true since we need the property during the instance construction, prior to the dynamic_init() execution.
102
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
103
+ */
104
+ private $_enable_anonymous = true;
105
+
106
+ /**
107
+ * @since 1.1.7.5
108
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
109
+ */
110
+ private $_anonymous_mode;
111
+
112
+ /**
113
+ * @since 1.1.9
114
+ * @var bool Hints the SDK if plugin have any free plans.
115
+ */
116
+ private $_is_premium_only;
117
+
118
+ /**
119
+ * @since 1.2.1.6
120
+ * @var bool Hints the SDK if plugin have premium code version at all.
121
+ */
122
+ private $_has_premium_version;
123
+
124
+ /**
125
+ * @since 1.2.1.6
126
+ * @var bool Hints the SDK if plugin should ignore pending mode by simulating a skip.
127
+ */
128
+ private $_ignore_pending_mode;
129
+
130
+ /**
131
+ * @since 1.0.8
132
+ * @var bool Hints the SDK if the plugin has any paid plans.
133
+ */
134
+ private $_has_paid_plans;
135
+
136
+ /**
137
+ * @since 1.2.1.5
138
+ * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
139
+ * without a specified period, if positive - the number of trial days.
140
+ */
141
+ private $_trial_days = - 1;
142
+
143
+ /**
144
+ * @since 1.2.1.5
145
+ * @var bool Hints the SDK if the trial requires a payment method or not.
146
+ */
147
+ private $_is_trial_require_payment = false;
148
+
149
+ /**
150
+ * @since 1.0.7
151
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
152
+ */
153
+ private $_is_org_compliant;
154
+
155
+ /**
156
+ * @since 1.0.7
157
+ * @var bool Hints the SDK if the plugin is has add-ons.
158
+ */
159
+ private $_has_addons;
160
+
161
+ /**
162
+ * @since 1.1.6
163
+ * @var string[]bool.
164
+ */
165
+ private $_permissions;
166
+
167
+ /**
168
+ * @var FS_Storage
169
+ */
170
+ private $_storage;
171
+
172
+ /**
173
+ * @since 1.2.2.7
174
+ * @var FS_Cache_Manager
175
+ */
176
+ private $_cache;
177
+
178
+ /**
179
+ * @since 1.0.0
180
+ *
181
+ * @var FS_Logger
182
+ */
183
+ private $_logger;
184
+ /**
185
+ * @since 1.0.4
186
+ *
187
+ * @var FS_Plugin
188
+ */
189
+ private $_plugin = false;
190
+ /**
191
+ * @since 1.0.4
192
+ *
193
+ * @var FS_Plugin|false
194
+ */
195
+ private $_parent_plugin = false;
196
+ /**
197
+ * @since 1.1.1
198
+ *
199
+ * @var Freemius
200
+ */
201
+ private $_parent = false;
202
+ /**
203
+ * @since 1.0.1
204
+ *
205
+ * @var FS_User
206
+ */
207
+ private $_user = false;
208
+ /**
209
+ * @since 1.0.1
210
+ *
211
+ * @var FS_Site
212
+ */
213
+ private $_site = false;
214
+ /**
215
+ * @since 1.0.1
216
+ *
217
+ * @var FS_Plugin_License
218
+ */
219
+ private $_license;
220
+ /**
221
+ * @since 1.0.2
222
+ *
223
+ * @var FS_Plugin_Plan[]
224
+ */
225
+ private $_plans = false;
226
+ /**
227
+ * @var FS_Plugin_License[]
228
+ * @since 1.0.5
229
+ */
230
+ private $_licenses = false;
231
+
232
+ /**
233
+ * @since 1.0.1
234
+ *
235
+ * @var FS_Admin_Menu_Manager
236
+ */
237
+ private $_menu;
238
+
239
+ /**
240
+ * @var FS_Admin_Notices
241
+ */
242
+ private $_admin_notices;
243
+
244
+ /**
245
+ * @since 1.1.6
246
+ *
247
+ * @var FS_Admin_Notices
248
+ */
249
+ private static $_global_admin_notices;
250
+
251
+ /**
252
+ * @var FS_Logger
253
+ * @since 1.0.0
254
+ */
255
+ private static $_static_logger;
256
+
257
+ /**
258
+ * @var FS_Options
259
+ * @since 1.0.2
260
+ */
261
+ private static $_accounts;
262
+
263
+ /**
264
+ * @since 1.2.2
265
+ *
266
+ * @var number
267
+ */
268
+ private $_module_id;
269
+
270
+ /**
271
+ * @var Freemius[]
272
+ */
273
+ private static $_instances = array();
274
+
275
+ /**
276
+ * @since 1.2.3
277
+ *
278
+ * @var FS_Affiliate
279
+ */
280
+ private $affiliate = null;
281
+
282
+ /**
283
+ * @since 1.2.3
284
+ *
285
+ * @var FS_AffiliateTerms
286
+ */
287
+ private $plugin_affiliate_terms = null;
288
+
289
+ /**
290
+ * @since 1.2.3
291
+ *
292
+ * @var FS_AffiliateTerms
293
+ */
294
+ private $custom_affiliate_terms = null;
295
+
296
+ /**
297
+ * @since 2.0.0
298
+ *
299
+ * @var bool
300
+ */
301
+ private $_is_multisite_integrated;
302
+
303
+ /**
304
+ * @since 2.0.0
305
+ *
306
+ * @var bool True if the current request is for a network admin screen and the plugin is network active.
307
+ */
308
+ private $_is_network_active;
309
+
310
+ /**
311
+ * @since 2.0.0
312
+ *
313
+ * @var int|null The original blog ID the plugin was loaded with.
314
+ */
315
+ private $_blog_id = null;
316
+
317
+ /**
318
+ * @since 2.0.0
319
+ *
320
+ * @var int|null The current execution context. When true, run on network context. When int, run on the specified blog context.
321
+ */
322
+ private $_context_is_network_or_blog_id = null;
323
+
324
+ /**
325
+ * @since 2.0.0
326
+ *
327
+ * @var string
328
+ */
329
+ private $_dynamically_added_top_level_page_hook_name = '';
330
+
331
+ #region Uninstall Reasons IDs
332
+
333
+ const REASON_NO_LONGER_NEEDED = 1;
334
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
335
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
336
+ const REASON_BROKE_MY_SITE = 4;
337
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
338
+ const REASON_CANT_PAY_ANYMORE = 6;
339
+ const REASON_OTHER = 7;
340
+ const REASON_DIDNT_WORK = 8;
341
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
342
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
343
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
344
+ const REASON_NOT_WORKING = 12;
345
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
346
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
347
+ const REASON_TEMPORARY_DEACTIVATION = 15;
348
+
349
+ #endregion
350
+
351
+ /* Ctor
352
+ ------------------------------------------------------------------------------------------------------------------*/
353
+
354
+ /**
355
+ * Main singleton instance.
356
+ *
357
+ * @author Vova Feldman (@svovaf)
358
+ * @since 1.0.0
359
+ *
360
+ * @param number $module_id
361
+ * @param string|bool $slug
362
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
363
+ */
364
+ private function __construct( $module_id, $slug = false, $is_init = false ) {
365
+ if ( $is_init && is_numeric( $module_id ) && is_string( $slug ) ) {
366
+ $this->store_id_slug_type_path_map( $module_id, $slug );
367
+ }
368
+
369
+ $this->_module_id = $module_id;
370
+ $this->_slug = $this->get_slug();
371
+ $this->_module_type = $this->get_module_type();
372
+
373
+ $this->_blog_id = is_multisite() ? get_current_blog_id() : null;
374
+
375
+ $this->_storage = FS_Storage::instance( $this->_module_type, $this->_slug );
376
+
377
+ $this->_cache = FS_Cache_Manager::get_manager( WP_FS___OPTION_PREFIX . "cache_{$module_id}" );
378
+
379
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $this->get_unique_affix(), WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
380
+
381
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
382
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
383
+ $this->_plugin_basename = $this->get_plugin_basename();
384
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
385
+
386
+ $this->_is_multisite_integrated = (
387
+ defined( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) &&
388
+ ( true === constant( "WP_FS__PRODUCT_{$module_id}_MULTISITE" ) )
389
+ );
390
+
391
+ $this->_is_network_active = (
392
+ is_multisite() &&
393
+ $this->_is_multisite_integrated &&
394
+ // Themes are always network activated, but the ACTUAL activation is per site.
395
+ $this->is_plugin() &&
396
+ ( is_plugin_active_for_network( $this->_plugin_basename ) ||
397
+ // Plugin network level activation or uninstall.
398
+ is_plugin_inactive( $this->_plugin_basename ) )
399
+ );
400
+
401
+ $this->_storage->set_network_active(
402
+ $this->_is_network_active,
403
+ $this->is_delegated_connection()
404
+ );
405
+
406
+ #region Migration
407
+
408
+ if ( is_multisite() ) {
409
+ /**
410
+ * If the install_timestamp exists on the site level but doesn't exist on the
411
+ * network level storage, it means that we need to process the storage with migration.
412
+ *
413
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, install_timestamp will be already set in the network level storage.
414
+ *
415
+ * @author Vova Feldman (@svovaf)
416
+ * @since 2.0.0
417
+ */
418
+ if ( false === $this->_storage->get( 'install_timestamp', false, true ) &&
419
+ false !== $this->_storage->get( 'install_timestamp', false, false )
420
+ ) {
421
+ // Initiate storage migration.
422
+ $this->_storage->migrate_to_network();
423
+
424
+ // Migrate module cache to network level storage.
425
+ $this->_cache->migrate_to_network();
426
+ }
427
+ }
428
+
429
+ #endregion
430
+
431
+ $base_name_split = explode( '/', $this->_plugin_basename );
432
+ $this->_plugin_dir_name = $base_name_split[0];
433
+
434
+ if ( $this->_logger->is_on() ) {
435
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
436
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
437
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
438
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
439
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
440
+ }
441
+
442
+ // Remember link between file to slug.
443
+ $this->store_file_slug_map();
444
+
445
+ // Store plugin's initial install timestamp.
446
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
447
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
448
+ }
449
+
450
+ if ( ! is_object( $this->_plugin ) ) {
451
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->get();
452
+ }
453
+
454
+ $this->_admin_notices = FS_Admin_Notices::instance(
455
+ $this->_slug . ( $this->is_theme() ? ':theme' : '' ),
456
+ /**
457
+ * Ensure that the admin notice will always have a title by using the stored plugin title if available and
458
+ * retrieving the title via the "get_plugin_name" method if there is no stored plugin title available.
459
+ *
460
+ * @author Leo Fajardo (@leorw)
461
+ * @since 1.2.2
462
+ */
463
+ ( is_object( $this->_plugin ) ? $this->_plugin->title : $this->get_plugin_name() ),
464
+ $this->get_unique_affix()
465
+ );
466
+
467
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
468
+ 'true' === fs_request_is_action( 'restart_freemius' )
469
+ ) {
470
+ FS_Api::clear_cache();
471
+ $this->_cache->clear();
472
+ }
473
+
474
+ $this->_register_hooks();
475
+
476
+ /**
477
+ * Starting from version 2.0.0, `FS_Site` entities no longer have the `plan` property and have `plan_id`
478
+ * instead. This should be called before calling `_load_account()`, otherwise, `$this->_site` will not be
479
+ * loaded in `_load_account` for versions of SDK starting from 2.0.0.
480
+ *
481
+ * @author Leo Fajardo (@leorw)
482
+ */
483
+ self::migrate_install_plan_to_plan_id( $this->_storage );
484
+
485
+ $this->_load_account();
486
+
487
+ $this->_version_updates_handler();
488
+ }
489
+
490
+ /**
491
+ * Checks whether this module has a settings menu.
492
+ *
493
+ * @author Leo Fajardo (@leorw)
494
+ * @since 1.2.2
495
+ *
496
+ * @return bool
497
+ */
498
+ function has_settings_menu() {
499
+ return ( $this->_is_network_active && fs_is_network_admin() ) ?
500
+ $this->_menu->has_network_menu() :
501
+ $this->_menu->has_menu();
502
+ }
503
+
504
+ /**
505
+ * Check if the context module is free wp.org theme.
506
+ *
507
+ * This method is helpful because:
508
+ * 1. wp.org themes are limited to a single submenu item,
509
+ * and sub-submenu items are most likely not allowed (never verified).
510
+ * 2. wp.org themes are not allowed to redirect the user
511
+ * after the theme activation, therefore, the agreed UX
512
+ * is showing the opt-in as a modal dialog box after
513
+ * activation (approved by @otto42, @emiluzelac, @greenshady, @grapplerulrich).
514
+ *
515
+ * @author Vova Feldman (@svovaf)
516
+ * @since 1.2.2.7
517
+ *
518
+ * @return bool
519
+ */
520
+ function is_free_wp_org_theme() {
521
+ return (
522
+ $this->is_theme() &&
523
+ $this->is_org_repo_compliant() &&
524
+ ! $this->is_premium()
525
+ );
526
+ }
527
+
528
+ /**
529
+ * Checks whether this a submenu item is visible.
530
+ *
531
+ * @author Vova Feldman (@svovaf)
532
+ * @since 1.2.2.6
533
+ * @since 1.2.2.7 Even if the menu item was specified to be hidden, when it is the context page, then show the submenu item so the user will have the right context page.
534
+ *
535
+ * @param string $slug
536
+ * @param bool $ignore_free_wp_org_theme_context This is used to decide if the associated tab should be shown
537
+ * or hidden.
538
+ *
539
+ * @return bool
540
+ */
541
+ function is_submenu_item_visible( $slug, $ignore_free_wp_org_theme_context = false ) {
542
+ if ( $this->is_admin_page( $slug ) ) {
543
+ /**
544
+ * It is the current context page, so show the submenu item
545
+ * so the user will have the right context page, even if it
546
+ * was set to hidden.
547
+ */
548
+ return true;
549
+ }
550
+
551
+ if ( ! $this->has_settings_menu() ) {
552
+ // No menu settings at all.
553
+ return false;
554
+ }
555
+
556
+ if ( ! $ignore_free_wp_org_theme_context && $this->is_free_wp_org_theme() ) {
557
+ /**
558
+ * wp.org themes are limited to a single submenu item, and
559
+ * sub-submenu items are most likely not allowed (never verified).
560
+ */
561
+ return false;
562
+ }
563
+
564
+ return $this->_menu->is_submenu_item_visible( $slug );
565
+ }
566
+
567
+ /**
568
+ * Check if a Freemius page should be accessible via the UI.
569
+ *
570
+ * @author Vova Feldman (@svovaf)
571
+ * @since 1.2.2.7
572
+ *
573
+ * @param string $slug
574
+ *
575
+ * @return bool
576
+ */
577
+ function is_page_visible( $slug ) {
578
+ if ( $this->is_admin_page( $slug ) ) {
579
+ return true;
580
+ }
581
+
582
+ return $this->_menu->is_submenu_item_visible( $slug, true, true );
583
+ }
584
+
585
+ /**
586
+ * @author Vova Feldman (@svovaf)
587
+ * @since 1.0.9
588
+ */
589
+ private function _version_updates_handler() {
590
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
591
+ // Freemius version upgrade mode.
592
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
593
+ $this->_storage->sdk_version = $this->version;
594
+
595
+ if ( empty( $this->_storage->sdk_last_version ) ||
596
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
597
+ ) {
598
+ $this->_storage->sdk_upgrade_mode = true;
599
+ $this->_storage->sdk_downgrade_mode = false;
600
+ } else {
601
+ $this->_storage->sdk_downgrade_mode = true;
602
+ $this->_storage->sdk_upgrade_mode = false;
603
+
604
+ }
605
+
606
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
607
+ }
608
+
609
+ $plugin_version = $this->get_plugin_version();
610
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
611
+ // Plugin version upgrade mode.
612
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
613
+ $this->_storage->plugin_version = $plugin_version;
614
+
615
+ if ( empty( $this->_storage->plugin_last_version ) ||
616
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
617
+ ) {
618
+ $this->_storage->plugin_upgrade_mode = true;
619
+ $this->_storage->plugin_downgrade_mode = false;
620
+ } else {
621
+ $this->_storage->plugin_downgrade_mode = true;
622
+ $this->_storage->plugin_upgrade_mode = false;
623
+ }
624
+
625
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
626
+ // Different version of the plugin was installed before, therefore it's an update.
627
+ $this->_storage->is_plugin_new_install = false;
628
+ }
629
+
630
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
631
+ }
632
+ }
633
+
634
+ #--------------------------------------------------------------------------------
635
+ #region Data Migration on SDK Update
636
+ #--------------------------------------------------------------------------------
637
+
638
+ /**
639
+ * @author Vova Feldman (@svovaf)
640
+ * @since 1.1.5
641
+ *
642
+ * @param string $sdk_prev_version
643
+ * @param string $sdk_version
644
+ */
645
+ function _sdk_version_update( $sdk_prev_version, $sdk_version ) {
646
+ /**
647
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
648
+ */
649
+ if ( empty( $sdk_prev_version ) ) {
650
+ return;
651
+ }
652
+
653
+ if ( version_compare( $sdk_prev_version, '2.1.0', '<' ) &&
654
+ version_compare( $sdk_version, '2.1.0', '>=' )
655
+ ) {
656
+ $this->_storage->handle_gdpr_admin_notice = true;
657
+ }
658
+
659
+ if ( version_compare( $sdk_prev_version, '2.0.0', '<' ) &&
660
+ version_compare( $sdk_version, '2.0.0', '>=' )
661
+ ) {
662
+ $this->migrate_to_subscriptions_collection();
663
+
664
+ $this->consolidate_licenses();
665
+
666
+ // Clear trial_plan since it's now loaded from the plans collection when needed.
667
+ $this->_storage->remove( 'trial_plan', true, false );
668
+ }
669
+
670
+ if ( version_compare( $sdk_prev_version, '1.2.3', '<' ) &&
671
+ version_compare( $sdk_version, '1.2.3', '>=' )
672
+ ) {
673
+ /**
674
+ * Starting from version 1.2.3, paths are stored as relative paths and not absolute paths; so when upgrading to 1.2.3, make paths relative.
675
+ *
676
+ * @author Leo Fajardo (@leorw)
677
+ */
678
+ $this->make_paths_relative();
679
+ }
680
+
681
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
682
+ version_compare( $sdk_version, '1.1.5', '>=' )
683
+ ) {
684
+ // On version 1.1.5 merged connectivity and is_on data.
685
+ if ( isset( $this->_storage->connectivity_test ) ) {
686
+ if ( ! isset( $this->_storage->is_on ) ) {
687
+ unset( $this->_storage->connectivity_test );
688
+ } else {
689
+ $connectivity_data = $this->_storage->connectivity_test;
690
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
691
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
692
+
693
+ // Override.
694
+ $this->_storage->connectivity_test = $connectivity_data;
695
+
696
+ // Remove previous structure.
697
+ unset( $this->_storage->is_on );
698
+ }
699
+
700
+ }
701
+ }
702
+ }
703
+
704
+ /**
705
+ * @author Leo Fajardo (@leorw)
706
+ * @since 2.0.0
707
+ *
708
+ * @param \FS_Storage $storage
709
+ * @param bool|int|null $blog_id
710
+ */
711
+ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $blog_id = null ) {
712
+ if ( empty( $storage->sdk_version ) ) {
713
+ // New installation of the plugin, no need to upgrade.
714
+ return;
715
+ }
716
+
717
+ if ( ! version_compare( $storage->sdk_version, '2.0.0', '<' ) ) {
718
+ // Previous version is >= 2.0.0, so no need to migrate.
719
+ return;
720
+ }
721
+
722
+ // Alias.
723
+ $module_type = $storage->get_module_type();
724
+ $module_slug = $storage->get_module_slug();
725
+
726
+ $installs = self::get_all_sites( $module_type, $blog_id );
727
+ $install = isset( $installs[ $module_slug ] ) ? $installs[ $module_slug ] : null;
728
+
729
+ if ( ! is_object( $install ) ) {
730
+ return;
731
+ }
732
+
733
+ if ( isset( $install->plan ) && is_object( $install->plan ) ) {
734
+ if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
735
+ $install->plan_id = self::_decrypt( $install->plan->id );
736
+ }
737
+
738
+ unset( $install->plan );
739
+
740
+ $installs[ $module_slug ] = clone $install;
741
+
742
+ self::set_account_option_by_module(
743
+ $module_type,
744
+ 'sites',
745
+ $installs,
746
+ true,
747
+ $blog_id
748
+ );
749
+ }
750
+ }
751
+
752
+ /**
753
+ * @author Leo Fajardo (@leorw)
754
+ * @since 2.0.0
755
+ */
756
+ private function migrate_to_subscriptions_collection() {
757
+ if ( ! is_object( $this->_site ) ) {
758
+ return;
759
+ }
760
+
761
+ if ( isset( $this->_storage->subscription ) && is_object( $this->_storage->subscription ) ) {
762
+ $this->_storage->subscriptions = array( $this->_storage->subscription );
763
+ }
764
+ }
765
+
766
+ /**
767
+ * @author Leo Fajardo (@leorw)
768
+ * @since 2.0.0
769
+ */
770
+ private function consolidate_licenses() {
771
+ $plugin_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_PLUGIN );
772
+ if ( isset( $plugin_licenses[ $this->_slug ] ) ) {
773
+ $plugin_licenses = $plugin_licenses[ $this->_slug ];
774
+ } else {
775
+ $plugin_licenses = array();
776
+ }
777
+
778
+ $theme_licenses = self::get_account_option( 'licenses', WP_FS__MODULE_TYPE_THEME );
779
+ if ( isset( $theme_licenses[ $this->_slug ] ) ) {
780
+ $theme_licenses = $theme_licenses[ $this->_slug ];
781
+ } else {
782
+ $theme_licenses = array();
783
+ }
784
+
785
+ if ( empty( $plugin_licenses ) && empty( $theme_licenses ) ) {
786
+ return;
787
+ }
788
+
789
+ $all_licenses = array();
790
+ $user_id_license_ids_map = array();
791
+
792
+ foreach ( $plugin_licenses as $user_id => $user_licenses ) {
793
+ if ( is_array( $user_licenses ) ) {
794
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
795
+ $user_id_license_ids_map[ $user_id ] = array();
796
+ }
797
+
798
+ foreach ( $user_licenses as $user_license ) {
799
+ $all_licenses[] = $user_license;
800
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
801
+ }
802
+ }
803
+ }
804
+
805
+ foreach ( $theme_licenses as $user_id => $user_licenses ) {
806
+ if ( is_array( $user_licenses ) ) {
807
+ if ( ! isset( $user_license_ids[ $user_id ] ) ) {
808
+ $user_id_license_ids_map[ $user_id ] = array();
809
+ }
810
+
811
+ foreach ( $user_licenses as $user_license ) {
812
+ $all_licenses[] = $user_license;
813
+ $user_id_license_ids_map[ $user_id ][] = $user_license->id;
814
+ }
815
+ }
816
+ }
817
+
818
+ self::store_user_id_license_ids_map(
819
+ $user_id_license_ids_map,
820
+ $this->_module_id
821
+ );
822
+
823
+ $this->_store_licenses( true, $this->_module_id, $all_licenses );
824
+ }
825
+
826
+ /**
827
+ * Makes paths relative.
828
+ *
829
+ * @author Leo Fajardo (@leorw)
830
+ * @since 1.2.3
831
+ */
832
+ private function make_paths_relative() {
833
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
834
+
835
+ if ( isset( $id_slug_type_path_map[ $this->_module_id ]['path'] ) ) {
836
+ $id_slug_type_path_map[ $this->_module_id ]['path'] = $this->get_relative_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
837
+
838
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
839
+ }
840
+
841
+ if ( isset( $this->_storage->plugin_main_file ) ) {
842
+ $plugin_main_file = $this->_storage->plugin_main_file;
843
+
844
+ if ( isset( $plugin_main_file->path ) ) {
845
+ $this->_storage->plugin_main_file->path = $this->get_relative_path( $this->_storage->plugin_main_file->path );
846
+ } else if ( isset( $plugin_main_file->prev_path ) ) {
847
+ $this->_storage->plugin_main_file->prev_path = $this->get_relative_path( $this->_storage->plugin_main_file->prev_path );
848
+ }
849
+ }
850
+
851
+ // Remove invalid path that is still associated with the current slug if there's any.
852
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
853
+ foreach ( $file_slug_map as $plugin_basename => $slug ) {
854
+ if ( $slug === $this->_slug &&
855
+ $plugin_basename !== $this->_plugin_basename &&
856
+ ! file_exists( $this->get_absolute_path( $plugin_basename ) )
857
+ ) {
858
+ unset( $file_slug_map[ $plugin_basename ] );
859
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
860
+
861
+ break;
862
+ }
863
+ }
864
+ }
865
+
866
+ /**
867
+ * @author Vova Feldman (@svovaf)
868
+ * @since 1.2.2.7
869
+ *
870
+ * @param string $plugin_prev_version
871
+ * @param string $plugin_version
872
+ */
873
+ function _after_version_update( $plugin_prev_version, $plugin_version ) {
874
+ if ( $this->is_theme() ) {
875
+ // Expire the cache of the previous tabs since the theme may
876
+ // have setting updates.
877
+ $this->_cache->expire( 'tabs' );
878
+ $this->_cache->expire( 'tabs_stylesheets' );
879
+ }
880
+ }
881
+
882
+ /**
883
+ * A special migration logic for the $_accounts, executed for all the plugins in the system:
884
+ * - Moves some data to the network level storage.
885
+ * - If the plugin's connection was skipped for all sites, set the plugin as if it was network skipped.
886
+ * - If the plugin's connection was ignored for all sites, don't do anything in terms of the network connection.
887
+ * - If the plugin was connected to all sites by the same super-admin, set the plugin as if was network opted-in for all sites.
888
+ * - If there's at least one site that was connected by a super-admin, find the "main super-admin" (the one that installed the majority of the plugin installs) and set the plugin as if was network activated with the main super-admin, set all the sites that were skipped or opted-in with a different user to delegated mode. Then, prompt the currently logged super-admin to choose what to do with the ignored sites.
889
+ * - If there are any sites in the network which the connection decision was not yet taken for, set this plugin into network activation mode so a super-admin can choose what to do with the rest of the sites.
890
+ *
891
+ * @author Vova Feldman (@svovaf)
892
+ * @since 2.0.0
893
+ */
894
+ private static function migrate_accounts_to_network() {
895
+ $sites = self::get_sites();
896
+ $sites_count = count( $sites );
897
+ $connection_status = array();
898
+ $plugin_slugs = array();
899
+ foreach ( $sites as $site ) {
900
+ $blog_id = self::get_site_blog_id( $site );
901
+
902
+ self::$_accounts->migrate_to_network( $blog_id );
903
+
904
+ /**
905
+ * Build a list of all Freemius powered plugins slugs.
906
+ */
907
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array(), $blog_id );
908
+ foreach ( $id_slug_type_path_map as $module_id => $data ) {
909
+ if ( WP_FS__MODULE_TYPE_PLUGIN === $data['type'] ) {
910
+ $plugin_slugs[ $data['slug'] ] = true;
911
+ }
912
+ }
913
+
914
+ $installs = self::get_account_option( 'sites', WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
915
+
916
+ if ( is_array( $installs ) ) {
917
+ foreach ( $installs as $slug => $install ) {
918
+ if ( ! isset( $connection_status[ $slug ] ) ) {
919
+ $connection_status[ $slug ] = array();
920
+ }
921
+
922
+ if ( is_object( $install ) &&
923
+ FS_Site::is_valid_id( $install->id ) &&
924
+ FS_User::is_valid_id( $install->user_id )
925
+ ) {
926
+ $connection_status[ $slug ][ $blog_id ] = $install->user_id;
927
+ }
928
+ }
929
+ }
930
+ }
931
+
932
+ foreach ( $plugin_slugs as $slug => $true ) {
933
+ if ( ! isset( $connection_status[ $slug ] ) ) {
934
+ $connection_status[ $slug ] = array();
935
+ }
936
+
937
+ foreach ( $sites as $site ) {
938
+ $blog_id = self::get_site_blog_id( $site );
939
+
940
+ if ( isset( $connection_status[ $slug ][ $blog_id ] ) ) {
941
+ continue;
942
+ }
943
+
944
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
945
+
946
+ $is_anonymous = $storage->get( 'is_anonymous', null, $blog_id );
947
+
948
+ if ( ! is_null( $is_anonymous ) ) {
949
+ // Since 1.1.3 is_anonymous is an array.
950
+ if ( is_array( $is_anonymous ) && isset( $is_anonymous['is'] ) ) {
951
+ $is_anonymous = $is_anonymous['is'];
952
+ }
953
+
954
+ if ( is_bool( $is_anonymous ) && true === $is_anonymous ) {
955
+ $connection_status[ $slug ][ $blog_id ] = 'skipped';
956
+ }
957
+ }
958
+
959
+ if ( ! isset( $connection_status[ $slug ][ $blog_id ] ) ) {
960
+ $connection_status[ $slug ][ $blog_id ] = 'ignored';
961
+ }
962
+ }
963
+ }
964
+
965
+ $super_admins = array();
966
+
967
+ foreach ( $connection_status as $slug => $blogs_status ) {
968
+ $skips = 0;
969
+ $ignores = 0;
970
+ $connections = 0;
971
+ $opted_in_users = array();
972
+ $opted_in_super_admins = array();
973
+
974
+ $storage = FS_Storage::instance( WP_FS__MODULE_TYPE_PLUGIN, $slug );
975
+
976
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
977
+ if ( 'skipped' === $status_or_user_id ) {
978
+ $skips ++;
979
+ } else if ( 'ignored' === $status_or_user_id ) {
980
+ $ignores ++;
981
+ } else if ( FS_User::is_valid_id( $status_or_user_id ) ) {
982
+ $connections ++;
983
+
984
+ if ( ! isset( $opted_in_users[ $status_or_user_id ] ) ) {
985
+ $opted_in_users[ $status_or_user_id ] = array();
986
+ }
987
+
988
+ $opted_in_users[ $status_or_user_id ][] = $blog_id;
989
+
990
+ if ( isset( $super_admins[ $status_or_user_id ] ) ||
991
+ self::is_super_admin( $status_or_user_id )
992
+ ) {
993
+ // Cache super-admin data.
994
+ $super_admins[ $status_or_user_id ] = true;
995
+
996
+ // Remember opted-in super-admins for the plugin.
997
+ $opted_in_super_admins[ $status_or_user_id ] = true;
998
+ }
999
+ }
1000
+ }
1001
+
1002
+ $main_super_admin_user_id = null;
1003
+ $all_migrated = false;
1004
+ if ( $sites_count == $skips ) {
1005
+ // All sites were skipped -> network skip by copying the anonymous mode from any of the sites.
1006
+ $storage->is_anonymous_ms = $storage->is_anonymous;
1007
+
1008
+ $all_migrated = true;
1009
+ } else if ( $sites_count == $ignores ) {
1010
+ // Don't do anything, still in activation mode.
1011
+
1012
+ $all_migrated = true;
1013
+ } else if ( 0 < count( $opted_in_super_admins ) ) {
1014
+ // Find the super-admin with the majority of installs.
1015
+ $max_installs_by_super_admin = 0;
1016
+ foreach ( $opted_in_super_admins as $user_id => $true ) {
1017
+ $installs_count = count( $opted_in_users[ $user_id ] );
1018
+
1019
+ if ( $installs_count > $max_installs_by_super_admin ) {
1020
+ $max_installs_by_super_admin = $installs_count;
1021
+ $main_super_admin_user_id = $user_id;
1022
+ }
1023
+ }
1024
+
1025
+ if ( $sites_count == $connections && 1 == count( $opted_in_super_admins ) ) {
1026
+ // Super-admin opted-in for all sites in the network.
1027
+ $storage->is_network_connected = true;
1028
+
1029
+ $all_migrated = true;
1030
+ }
1031
+
1032
+ // Store network user.
1033
+ $storage->network_user_id = $main_super_admin_user_id;
1034
+
1035
+ $storage->network_install_blog_id = ( $sites_count == $connections ) ?
1036
+ // Since all sites are opted-in, associating with the main site.
1037
+ get_current_blog_id() :
1038
+ // Associating with the 1st found opted-in site.
1039
+ $opted_in_users[ $main_super_admin_user_id ][0];
1040
+
1041
+ /**
1042
+ * Make sure we migrate the plan ID of the network install, otherwise, if after the migration
1043
+ * the 1st page that will be loaded is the network level WP Admin and $storage->network_install_blog_id
1044
+ * is different than the main site of the network, the $this->_site will not be set since the plan_id
1045
+ * will be empty.
1046
+ */
1047
+ $storage->migrate_to_network();
1048
+ self::migrate_install_plan_to_plan_id( $storage, $storage->network_install_blog_id );
1049
+ } else {
1050
+ // At least one opt-in. All the opt-in were created by a non-super-admin.
1051
+ if ( 0 == $ignores ) {
1052
+ // All sites were opted-in or skipped, all by non-super-admin. So delegate all.
1053
+ $storage->store( 'is_delegated_connection', true, true );
1054
+
1055
+ $all_migrated = true;
1056
+ }
1057
+ }
1058
+
1059
+ if ( ! $all_migrated ) {
1060
+ /**
1061
+ * Delegate all sites that were:
1062
+ * 1) Opted-in by a user that is NOT the main-super-admin.
1063
+ * 2) Skipped and non of the sites was opted-in by a super-admin. If any site was opted-in by a super-admin, there will be a main-super-admin, and we consider the skip as if it was done by that user.
1064
+ */
1065
+ foreach ( $blogs_status as $blog_id => $status_or_user_id ) {
1066
+ if ( $status_or_user_id == $main_super_admin_user_id ) {
1067
+ continue;
1068
+ }
1069
+
1070
+ if ( FS_User::is_valid_id( $status_or_user_id ) ||
1071
+ ( 'skipped' === $status_or_user_id && is_null( $main_super_admin_user_id ) )
1072
+ ) {
1073
+ $storage->store( 'is_delegated_connection', true, $blog_id );
1074
+ }
1075
+ }
1076
+ }
1077
+
1078
+
1079
+ if ( ( $connections + $skips > 0 ) ) {
1080
+ if ( $ignores > 0 ) {
1081
+ /**
1082
+ * If admin already opted-in or skipped in any of the network sites, and also
1083
+ * have sites which the connection decision was not yet taken, set this plugin
1084
+ * into network activation mode so the super-admin can choose what to do with
1085
+ * the rest of the sites.
1086
+ */
1087
+ self::set_network_upgrade_mode( $storage );
1088
+ }
1089
+ }
1090
+ }
1091
+ }
1092
+
1093
+ /**
1094
+ * Set a module into network upgrade mode.
1095
+ *
1096
+ * @author Vova Feldman (@svovaf)
1097
+ * @since 2.0.0
1098
+ *
1099
+ * @param \FS_Storage $storage
1100
+ *
1101
+ * @return bool
1102
+ */
1103
+ private static function set_network_upgrade_mode( FS_Storage $storage ) {
1104
+ return $storage->is_network_activation = true;
1105
+ }
1106
+
1107
+ /**
1108
+ * Will return true after upgrading to the SDK with the network level integration,
1109
+ * when the super-admin involvement is required regarding the rest of the sites.
1110
+ *
1111
+ * @author Vova Feldman (@svovaf)
1112
+ * @since 2.0.0
1113
+ *
1114
+ * @return bool
1115
+ */
1116
+ function is_network_upgrade_mode() {
1117
+ return $this->_storage->get( 'is_network_activation' );
1118
+ }
1119
+
1120
+ /**
1121
+ * Clear flag after the upgrade mode completion.
1122
+ *
1123
+ * @author Vova Feldman (@svovaf)
1124
+ * @since 2.0.0
1125
+ *
1126
+ * @return bool True if network activation was on and now completed.
1127
+ */
1128
+ private function network_upgrade_mode_completed() {
1129
+ if ( fs_is_network_admin() && $this->is_network_upgrade_mode() ) {
1130
+ $this->_storage->remove( 'is_network_activation' );
1131
+
1132
+ return true;
1133
+ }
1134
+
1135
+ return false;
1136
+ }
1137
+
1138
+ #endregion
1139
+
1140
+ /**
1141
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
1142
+ * if this is a new plugin installation or a plugin update.
1143
+ *
1144
+ * There are 3 different use-cases:
1145
+ * 1) New plugin installation right with Freemius:
1146
+ * 1.1 _activate_plugin_event_hook() will be executed first
1147
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
1148
+ * and $this->_storage->plugin_last_version is not set,
1149
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
1150
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1151
+ * be already set to TRUE.
1152
+ *
1153
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
1154
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
1155
+ * the activation hook do NOT fires on updates since WP 3.1.
1156
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
1157
+ * be empty, therefore, it will be set to FALSE.
1158
+ *
1159
+ * 3) Plugin update, had Freemius in prev version as well:
1160
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
1161
+ * before, $this->_storage->plugin_last_version will NOT be empty,
1162
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
1163
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
1164
+ * already set, therefore, it will not be modified.
1165
+ *
1166
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
1167
+ *
1168
+ * NOTE:
1169
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
1170
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
1171
+ * show the opt-in right away. The reason it will happen is because Freemius execution
1172
+ * will be turned off till the plugin is fully loaded at least once
1173
+ * (till $this->_storage->was_plugin_loaded is TRUE).
1174
+ *
1175
+ * @author Vova Feldman (@svovaf)
1176
+ * @since 1.1.9
1177
+ *
1178
+ */
1179
+ function _plugins_loaded() {
1180
+ // Update flag that plugin was loaded with Freemius at least once.
1181
+ $this->_storage->was_plugin_loaded = true;
1182
+
1183
+ /**
1184
+ * Bug fix - only set to false when it's a plugin, due to the
1185
+ * execution sequence of the theme hooks and our methods, if
1186
+ * this will be set for themes, Freemius will always assume
1187
+ * it's a theme update.
1188
+ *
1189
+ * @author Vova Feldman (@svovaf)
1190
+ * @since 1.2.2.2
1191
+ */
1192
+ if ( $this->is_plugin() &&
1193
+ ! isset( $this->_storage->is_plugin_new_install )
1194
+ ) {
1195
+ $this->_storage->is_plugin_new_install = false;
1196
+ }
1197
+ }
1198
+
1199
+ /**
1200
+ * Add special parameter to WP admin AJAX calls so when we
1201
+ * process AJAX calls we can identify its source properly.
1202
+ *
1203
+ * @author Leo Fajardo (@leorw)
1204
+ * @since 2.0.0
1205
+ */
1206
+ static function _enrich_ajax_url() {
1207
+ $admin_param = is_network_admin() ?
1208
+ '_fs_network_admin' :
1209
+ '_fs_blog_admin';
1210
+ ?>
1211
+ <script type="text/javascript">
1212
+ (function ($) {
1213
+ $(document).ajaxSend(function (event, jqxhr, settings) {
1214
+ if (settings.url &&
1215
+ -1 < settings.url.indexOf('admin-ajax.php') &&
1216
+ ! ( settings.url.indexOf( '<?php echo $admin_param ?>' ) > 0 )
1217
+ ) {
1218
+ if (settings.url.indexOf('?') > 0) {
1219
+ settings.url += '&';
1220
+ } else {
1221
+ settings.url += '?';
1222
+ }
1223
+
1224
+ settings.url += '<?php echo $admin_param ?>=true';
1225
+
1226
+ }
1227
+ });
1228
+ })(jQuery);
1229
+ </script>
1230
+ <?php
1231
+ }
1232
+
1233
+ /**
1234
+ * @author Vova Feldman (@svovaf)
1235
+ * @since 1.0.9
1236
+ */
1237
+ private function _register_hooks() {
1238
+ $this->_logger->entrance();
1239
+
1240
+ if ( is_admin() ) {
1241
+ add_action( 'plugins_loaded', array( &$this, '_hook_action_links_and_register_account_hooks' ) );
1242
+
1243
+ if ( $this->is_plugin() ) {
1244
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
1245
+
1246
+ /**
1247
+ * @since 1.2.2
1248
+ *
1249
+ * Hook to both free and premium version activations to support
1250
+ * auto deactivation on the other version activation.
1251
+ */
1252
+ register_activation_hook(
1253
+ $plugin_dir . $this->_free_plugin_basename,
1254
+ array( &$this, '_activate_plugin_event_hook' )
1255
+ );
1256
+
1257
+ register_activation_hook(
1258
+ $plugin_dir . $this->premium_plugin_basename(),
1259
+ array( &$this, '_activate_plugin_event_hook' )
1260
+ );
1261
+ } else {
1262
+ add_action( 'after_switch_theme', array( &$this, '_activate_theme_event_hook' ), 10, 2 );
1263
+
1264
+ /**
1265
+ * Include the required hooks to capture the theme settings' page tabs
1266
+ * and cache them.
1267
+ *
1268
+ * @author Vova Feldman (@svovaf)
1269
+ * @since 1.2.2.7
1270
+ */
1271
+ if ( ! $this->_cache->has_valid( 'tabs' ) ) {
1272
+ add_action( 'admin_footer', array( &$this, '_tabs_capture' ) );
1273
+ // Add license activation AJAX callback.
1274
+ $this->add_ajax_action( 'store_tabs', array( &$this, '_store_tabs_ajax_action' ) );
1275
+
1276
+ add_action( 'admin_enqueue_scripts', array( &$this, '_store_tabs_styles' ), 9999999 );
1277
+ }
1278
+
1279
+ add_action(
1280
+ 'admin_footer',
1281
+ array( &$this, '_add_freemius_tabs' ),
1282
+ /**
1283
+ * The tabs JS code must be executed after the tabs capture logic (_tabs_capture()).
1284
+ * That's why the priority is 11 while the tabs capture logic is added
1285
+ * with priority 10.
1286
+ *
1287
+ * @author Vova Feldman (@svovaf)
1288
+ */
1289
+ 11
1290
+ );
1291
+
1292
+ add_action( 'admin_footer', array( &$this, '_style_premium_theme' ) );
1293
+ }
1294
+
1295
+ /**
1296
+ * Part of the mechanism to identify new plugin install vs. plugin update.
1297
+ *
1298
+ * @author Vova Feldman (@svovaf)
1299
+ * @since 1.1.9
1300
+ */
1301
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
1302
+ /**
1303
+ * During the plugin activation (not theme), 'plugins_loaded' will be already executed
1304
+ * when the logic gets here since the activation logic first add the activate plugins,
1305
+ * then triggers 'plugins_loaded', and only then include the code of the plugin that
1306
+ * is activated. Which means that _plugins_loaded() will NOT be executed during the
1307
+ * plugin activation, and that IS intentional.
1308
+ *
1309
+ * @author Vova Feldman (@svovaf)
1310
+ */
1311
+ if ( $this->is_plugin() && $this->is_activation_mode( false ) ) {
1312
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
1313
+ } else {
1314
+ // If was activated before, then it was already loaded before.
1315
+ $this->_plugins_loaded();
1316
+ }
1317
+ }
1318
+
1319
+ if ( ! self::is_ajax() ) {
1320
+ if ( ! $this->is_addon() ) {
1321
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
1322
+ }
1323
+ }
1324
+
1325
+ if ( $this->_storage->handle_gdpr_admin_notice ) {
1326
+ add_action( 'init', array( &$this, '_maybe_show_gdpr_admin_notice' ) );
1327
+ }
1328
+
1329
+ add_action( 'init', array( &$this, '_maybe_add_gdpr_optin_ajax_handler') );
1330
+ }
1331
+
1332
+ if ( $this->is_plugin() ) {
1333
+ if ( $this->_is_network_active ) {
1334
+ add_action( 'wpmu_new_blog', array( $this, '_after_new_blog_callback' ), 10, 6 );
1335
+ }
1336
+
1337
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
1338
+ }
1339
+
1340
+ if ( is_multisite() ) {
1341
+ add_action( 'deactivate_blog', array( &$this, '_after_site_deactivated_callback' ) );
1342
+ add_action( 'archive_blog', array( &$this, '_after_site_deactivated_callback' ) );
1343
+ add_action( 'make_spam_blog', array( &$this, '_after_site_deactivated_callback' ) );
1344
+ add_action( 'deleted_blog', array( &$this, '_after_site_deleted_callback' ), 10, 2 );
1345
+
1346
+ add_action( 'activate_blog', array( &$this, '_after_site_reactivated_callback' ) );
1347
+ add_action( 'unarchive_blog', array( &$this, '_after_site_reactivated_callback' ) );
1348
+ add_action( 'make_ham_blog', array( &$this, '_after_site_reactivated_callback' ) );
1349
+ }
1350
+
1351
+ if ( $this->is_theme() &&
1352
+ self::is_customizer() &&
1353
+ $this->apply_filters( 'show_customizer_upsell', true )
1354
+ ) {
1355
+ // Register customizer upsell.
1356
+ add_action( 'customize_register', array( &$this, '_customizer_register' ) );
1357
+ }
1358
+
1359
+ add_action( 'admin_init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
1360
+
1361
+ if ( $this->is_theme() ) {
1362
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1363
+ }
1364
+
1365
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
1366
+ add_action( 'admin_init', array( &$this, '_add_premium_version_upgrade_selection' ) );
1367
+
1368
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
1369
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
1370
+
1371
+ if ( $this->_is_network_active && fs_is_network_admin() ) {
1372
+ $this->add_ajax_action( 'network_activate', array( &$this, '_network_activate_ajax_action' ) );
1373
+ }
1374
+
1375
+ $this->add_ajax_action( 'install_premium_version', array(
1376
+ &$this,
1377
+ '_install_premium_version_ajax_action'
1378
+ ) );
1379
+
1380
+ $this->add_ajax_action( 'submit_affiliate_application', array( &$this, '_submit_affiliate_application' ) );
1381
+
1382
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
1383
+
1384
+ $this->add_action( 'sdk_version_update', array( &$this, '_sdk_version_update' ), WP_FS__DEFAULT_PRIORITY, 2 );
1385
+
1386
+ $this->add_action(
1387
+ 'plugin_version_update',
1388
+ array( &$this, '_after_version_update' ),
1389
+ WP_FS__DEFAULT_PRIORITY,
1390
+ 2
1391
+ );
1392
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
1393
+
1394
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1395
+ add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
1396
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
1397
+
1398
+ /**
1399
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
1400
+ *
1401
+ * @author Vova Feldman (@svovaf)
1402
+ * @since 1.2.1.5
1403
+ */
1404
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
1405
+ $this->get_unique_affix() === fs_request_get( 'fs_unique_affix' )
1406
+ ) {
1407
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
1408
+ }
1409
+ }
1410
+
1411
+ /**
1412
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
1413
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
1414
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
1415
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
1416
+ *
1417
+ * @author Leo Fajardo (@leorw)
1418
+ *
1419
+ * @since 1.2.0
1420
+ */
1421
+ private function unregister_uninstall_hook() {
1422
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
1423
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
1424
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
1425
+
1426
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
1427
+ }
1428
+
1429
+ /**
1430
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
1431
+ */
1432
+ private function clear_module_main_file_cache() {
1433
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
1434
+ empty( $this->_storage->plugin_main_file->path )
1435
+ ) {
1436
+ return;
1437
+ }
1438
+
1439
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
1440
+
1441
+ // Store cached path (2nd layer cache).
1442
+ $plugin_main_file->prev_path = $plugin_main_file->path;
1443
+
1444
+ // Clear cached path.
1445
+ unset( $plugin_main_file->path );
1446
+
1447
+ $this->_storage->plugin_main_file = $plugin_main_file;
1448
+
1449
+ /**
1450
+ * Clear global cached path.
1451
+ *
1452
+ * @author Leo Fajardo (@leorw)
1453
+ * @since 1.2.2
1454
+ */
1455
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map' );
1456
+ unset( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1457
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1458
+ }
1459
+
1460
+ /**
1461
+ * @author Leo Fajardo (@leorw)
1462
+ * @since 2.0.0
1463
+ */
1464
+ function _hook_action_links_and_register_account_hooks() {
1465
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
1466
+
1467
+ if ( self::is_plugins_page() && $this->is_plugin() ) {
1468
+ $this->hook_plugin_action_links();
1469
+ }
1470
+
1471
+ $this->_register_account_hooks();
1472
+ }
1473
+
1474
+ /**
1475
+ * @author Vova Feldman (@svovaf)
1476
+ * @since 1.0.9
1477
+ */
1478
+ private function _register_account_hooks() {
1479
+ if ( ! is_admin() ) {
1480
+ return;
1481
+ }
1482
+
1483
+ /**
1484
+ * Always show the deactivation feedback form since we added
1485
+ * automatic free version deactivation upon premium code activation.
1486
+ *
1487
+ * @since 1.2.1.6
1488
+ */
1489
+ $this->add_ajax_action(
1490
+ 'submit_uninstall_reason',
1491
+ array( &$this, '_submit_uninstall_reason_action' )
1492
+ );
1493
+
1494
+ if ( ! $this->is_addon() || $this->is_parent_plugin_installed() ) {
1495
+ if ( ( $this->is_plugin() && self::is_plugins_page() ) ||
1496
+ ( $this->is_theme() && self::is_themes_page() )
1497
+ ) {
1498
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
1499
+ }
1500
+ }
1501
+ }
1502
+
1503
+ /**
1504
+ * Leverage backtrace to find caller plugin file path.
1505
+ *
1506
+ * @author Vova Feldman (@svovaf)
1507
+ * @since 1.0.6
1508
+ *
1509
+ * @param bool $is_init Is initiation sequence.
1510
+ *
1511
+ * @return string
1512
+ */
1513
+ private function _find_caller_plugin_file( $is_init = false ) {
1514
+ // Try to load the cached value of the file path.
1515
+ if ( isset( $this->_storage->plugin_main_file ) ) {
1516
+ $plugin_main_file = $this->_storage->plugin_main_file;
1517
+ if ( isset( $plugin_main_file->path ) ) {
1518
+ $absolute_path = $this->get_absolute_path( $plugin_main_file->path );
1519
+ if ( file_exists( $absolute_path ) ) {
1520
+ return $absolute_path;
1521
+ }
1522
+ }
1523
+ }
1524
+
1525
+ /**
1526
+ * @since 1.2.1
1527
+ *
1528
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
1529
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
1530
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
1531
+ *
1532
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
1533
+ * when the class instantiator isn't the module.
1534
+ */
1535
+ if ( ! $is_init ) {
1536
+ // Fetch prev path cache.
1537
+ if ( isset( $this->_storage->plugin_main_file ) &&
1538
+ isset( $this->_storage->plugin_main_file->prev_path )
1539
+ ) {
1540
+ $absolute_path = $this->get_absolute_path( $this->_storage->plugin_main_file->prev_path );
1541
+ if ( file_exists( $absolute_path ) ) {
1542
+ return $absolute_path;
1543
+ }
1544
+ }
1545
+
1546
+ wp_die(
1547
+ $this->get_text_inline( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'failed-finding-main-path' ) .
1548
+ " Module: {$this->_slug}; SDK: " . WP_FS__SDK_VERSION . ";",
1549
+ $this->get_text_inline( 'Error', 'error' ),
1550
+ array( 'back_link' => true )
1551
+ );
1552
+ }
1553
+
1554
+ /**
1555
+ * @since 1.2.1
1556
+ *
1557
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
1558
+ */
1559
+ // Find caller module.
1560
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1561
+ $this->_storage->plugin_main_file = (object) array(
1562
+ 'path' => $id_slug_type_path_map[ $this->_module_id ]['path'],
1563
+ );
1564
+
1565
+ return $this->get_absolute_path( $id_slug_type_path_map[ $this->_module_id ]['path'] );
1566
+ }
1567
+
1568
+ /**
1569
+ * @author Leo Fajardo (@leorw)
1570
+ * @since 1.2.3
1571
+ *
1572
+ * @param string $path
1573
+ *
1574
+ * @return string
1575
+ */
1576
+ private function get_relative_path( $path ) {
1577
+ $module_root_dir = $this->get_module_root_dir_path();
1578
+ if ( 0 === strpos( $path, $module_root_dir ) ) {
1579
+ $path = substr( $path, strlen( $module_root_dir ) );
1580
+ }
1581
+
1582
+ return $path;
1583
+ }
1584
+
1585
+ /**
1586
+ * @author Leo Fajardo (@leorw)
1587
+ * @since 1.2.3
1588
+ *
1589
+ * @param string $path
1590
+ * @param string|bool $module_type
1591
+ *
1592
+ * @return string
1593
+ */
1594
+ private function get_absolute_path( $path, $module_type = false ) {
1595
+ $module_root_dir = $this->get_module_root_dir_path( $module_type );
1596
+ if ( 0 !== strpos( $path, $module_root_dir ) ) {
1597
+ $path = fs_normalize_path( $module_root_dir . $path );
1598
+ }
1599
+
1600
+ return $path;
1601
+ }
1602
+
1603
+ /**
1604
+ * @author Leo Fajardo (@leorw)
1605
+ * @since 1.2.3
1606
+ *
1607
+ * @param string|bool $module_type
1608
+ *
1609
+ * @return string
1610
+ */
1611
+ private function get_module_root_dir_path( $module_type = false ) {
1612
+ $is_plugin = empty( $module_type ) ?
1613
+ $this->is_plugin() :
1614
+ ( WP_FS__MODULE_TYPE_PLUGIN === $module_type );
1615
+
1616
+ return fs_normalize_path( trailingslashit( $is_plugin ?
1617
+ WP_PLUGIN_DIR :
1618
+ get_theme_root() ) );
1619
+ }
1620
+
1621
+ /**
1622
+ * @author Leo Fajardo (@leorw)
1623
+ *
1624
+ * @param number $module_id
1625
+ * @param string $slug
1626
+ *
1627
+ * @since 1.2.2
1628
+ */
1629
+ private function store_id_slug_type_path_map( $module_id, $slug ) {
1630
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
1631
+
1632
+ $store_option = false;
1633
+
1634
+ if ( ! isset( $id_slug_type_path_map[ $module_id ] ) ) {
1635
+ $id_slug_type_path_map[ $module_id ] = array(
1636
+ 'slug' => $slug
1637
+ );
1638
+
1639
+ $store_option = true;
1640
+ }
1641
+
1642
+ if ( ! isset( $id_slug_type_path_map[ $module_id ]['path'] ) ||
1643
+ /**
1644
+ * This verification is for cases when suddenly the same module
1645
+ * is installed but with a different folder name.
1646
+ *
1647
+ * @author Vova Feldman (@svovaf)
1648
+ * @since 1.2.3
1649
+ */
1650
+ ! file_exists( $this->get_absolute_path(
1651
+ $id_slug_type_path_map[ $module_id ]['path'],
1652
+ $id_slug_type_path_map[ $module_id ]['type']
1653
+ ) )
1654
+ ) {
1655
+ $caller_main_file_and_type = $this->get_caller_main_file_and_type();
1656
+
1657
+ $id_slug_type_path_map[ $module_id ]['type'] = $caller_main_file_and_type->module_type;
1658
+ $id_slug_type_path_map[ $module_id ]['path'] = $caller_main_file_and_type->path;
1659
+
1660
+ $store_option = true;
1661
+ }
1662
+
1663
+ if ( $store_option ) {
1664
+ self::$_accounts->set_option( 'id_slug_type_path_map', $id_slug_type_path_map, true );
1665
+ }
1666
+ }
1667
+
1668
+ /**
1669
+ * Identifies the caller type: plugin or theme.
1670
+ *
1671
+ * @author Leo Fajardo (@leorw)
1672
+ * @since 1.2.2
1673
+ *
1674
+ * @author Vova Feldman (@svovaf)
1675
+ * @since 1.2.2.3 Find the earliest module in the call stack that calls to the SDK. This fix is for cases when
1676
+ * add-ons are relying on loading the SDK from the parent module, and also allows themes including the
1677
+ * SDK an internal file instead of directly from functions.php.
1678
+ * @since 1.2.1.7 Knows how to handle cases when an add-on includes the parent module logic.
1679
+ */
1680
+ private function get_caller_main_file_and_type() {
1681
+ self::require_plugin_essentials();
1682
+
1683
+ $all_plugins = get_plugins();
1684
+ $all_plugins_paths = array();
1685
+
1686
+ // Get active plugin's main files real full names (might be symlinks).
1687
+ foreach ( $all_plugins as $relative_path => &$data ) {
1688
+ if ( false === strpos( fs_normalize_path( $relative_path ), '/' ) ) {
1689
+ /**
1690
+ * Ignore plugins that don't have a folder (e.g. Hello Dolly) since they
1691
+ * can't really include the SDK.
1692
+ *
1693
+ * @author Vova Feldman
1694
+ * @since 1.2.1.7
1695
+ */
1696
+ continue;
1697
+ }
1698
+
1699
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
1700
+ }
1701
+
1702
+ $caller_file_candidate = false;
1703
+ $caller_map = array();
1704
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1705
+ $themes_dir = fs_normalize_path( get_theme_root() );
1706
+
1707
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
1708
+ if ( empty( $bt[ $i ]['file'] ) ) {
1709
+ continue;
1710
+ }
1711
+
1712
+ if ( $i > 1 && ! empty( $bt[ $i - 1 ]['file'] ) && $bt[ $i ]['file'] === $bt[ $i - 1 ]['file'] ) {
1713
+ // If file same as the prev file in the stack, skip it.
1714
+ continue;
1715
+ }
1716
+
1717
+ if ( ! empty( $bt[ $i ]['function'] ) && in_array( $bt[ $i ]['function'], array(
1718
+ 'do_action',
1719
+ 'apply_filter',
1720
+ // The string split is stupid, but otherwise, theme check
1721
+ // throws info notices.
1722
+ 'requir' . 'e_once',
1723
+ 'requir' . 'e',
1724
+ 'includ' . 'e_once',
1725
+ 'includ' . 'e'
1726
+ ) )
1727
+ ) {
1728
+ // Ignore call stack hooks and files inclusion.
1729
+ continue;
1730
+ }
1731
+
1732
+ $caller_file_path = fs_normalize_path( $bt[ $i ]['file'] );
1733
+
1734
+ if ( 'functions.php' === basename( $caller_file_path ) ) {
1735
+ /**
1736
+ * 1. Assumes that theme's starting execution file is functions.php.
1737
+ * 2. This complex logic fixes symlink issues (e.g. with Vargant).
1738
+ *
1739
+ * @author Vova Feldman (@svovaf)
1740
+ * @since 1.2.2.5
1741
+ */
1742
+
1743
+ if ( $caller_file_path == fs_normalize_path( realpath( trailingslashit( $themes_dir ) . basename( dirname( $caller_file_path ) ) . '/' . basename( $caller_file_path ) ) ) ) {
1744
+ $module_type = WP_FS__MODULE_TYPE_THEME;
1745
+
1746
+ /**
1747
+ * Relative path of the theme, e.g.:
1748
+ * `my-theme/functions.php`
1749
+ *
1750
+ * @author Leo Fajardo (@leorw)
1751
+ */
1752
+ $caller_file_candidate = basename( dirname( $caller_file_path ) ) .
1753
+ '/' .
1754
+ basename( $caller_file_path );
1755
+
1756
+ continue;
1757
+ }
1758
+ }
1759
+
1760
+ $caller_file_hash = md5( $caller_file_path );
1761
+
1762
+ if ( ! isset( $caller_map[ $caller_file_hash ] ) ) {
1763
+ foreach ( $all_plugins_paths as $plugin_path ) {
1764
+ if ( false !== strpos( $caller_file_path, fs_normalize_path( dirname( $plugin_path ) . '/' ) ) ) {
1765
+ $caller_map[ $caller_file_hash ] = fs_normalize_path( $plugin_path );
1766
+ break;
1767
+ }
1768
+ }
1769
+ }
1770
+
1771
+ if ( isset( $caller_map[ $caller_file_hash ] ) ) {
1772
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN;
1773
+ $caller_file_candidate = plugin_basename( $caller_map[ $caller_file_hash ] );
1774
+ }
1775
+ }
1776
+
1777
+ return (object) array(
1778
+ 'module_type' => $module_type,
1779
+ 'path' => $caller_file_candidate
1780
+ );
1781
+ }
1782
+
1783
+ #----------------------------------------------------------------------------------
1784
+ #region Deactivation Feedback Form
1785
+ #----------------------------------------------------------------------------------
1786
+
1787
+ /**
1788
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
1789
+ * page.
1790
+ *
1791
+ * @author Vova Feldman (@svovaf)
1792
+ * @author Leo Fajardo (@leorw)
1793
+ * @since 1.1.2
1794
+ */
1795
+ function _add_deactivation_feedback_dialog_box() {
1796
+ /* Check the type of user:
1797
+ * 1. Long-term (long-term)
1798
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
1799
+ * 3. Short-term (short-term)
1800
+ */
1801
+ $is_long_term_user = true;
1802
+
1803
+ // Check if the site is at least 2 days old.
1804
+ $time_installed = $this->_storage->install_timestamp;
1805
+
1806
+ // Difference in seconds.
1807
+ $date_diff = time() - $time_installed;
1808
+
1809
+ // Convert seconds to days.
1810
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
1811
+
1812
+ if ( $date_diff_days < 2 ) {
1813
+ $is_long_term_user = false;
1814
+ }
1815
+
1816
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
1817
+
1818
+ if ( $is_long_term_user ) {
1819
+ $user_type = 'long-term';
1820
+ } else {
1821
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
1822
+ $user_type = 'non-registered-and-non-anonymous-short-term';
1823
+ } else {
1824
+ $user_type = 'short-term';
1825
+ }
1826
+ }
1827
+
1828
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
1829
+
1830
+ // Load the HTML template for the deactivation feedback dialog box.
1831
+ $vars = array(
1832
+ 'reasons' => $uninstall_reasons,
1833
+ 'id' => $this->_module_id
1834
+ );
1835
+
1836
+ /**
1837
+ * @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.
1838
+ */
1839
+ fs_require_template( 'forms/deactivation/form.php', $vars );
1840
+ }
1841
+
1842
+ /**
1843
+ * @author Leo Fajardo (@leorw)
1844
+ * @since 1.1.2
1845
+ *
1846
+ * @param string $user_type
1847
+ *
1848
+ * @return array The uninstall reasons for the specified user type.
1849
+ */
1850
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
1851
+ $module_type = $this->_module_type;
1852
+
1853
+ $internal_message_template_var = array(
1854
+ 'id' => $this->_module_id
1855
+ );
1856
+
1857
+ $plan = $this->get_plan();
1858
+
1859
+ if ( $this->is_registered() && is_object( $plan ) && $plan->has_technical_support() ) {
1860
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
1861
+ } else {
1862
+ $contact_support_template = '';
1863
+ }
1864
+
1865
+ $reason_found_better_plugin = array(
1866
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
1867
+ 'text' => sprintf( $this->get_text_inline( 'I found a better %s', 'reason-found-a-better-plugin' ), $module_type ),
1868
+ 'input_type' => 'textfield',
1869
+ 'input_placeholder' => sprintf( $this->get_text_inline( "What's the %s's name?", 'placeholder-plugin-name' ), $module_type ),
1870
+ );
1871
+
1872
+ $reason_temporary_deactivation = array(
1873
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
1874
+ 'text' => sprintf(
1875
+ $this->get_text_inline( "It's a temporary %s. I'm just debugging an issue.", 'reason-temporary-x' ),
1876
+ strtolower( $this->is_plugin() ?
1877
+ $this->get_text_inline( 'Deactivation', 'deactivation' ) :
1878
+ $this->get_text_inline( 'Theme Switch', 'theme-switch' )
1879
+ )
1880
+ ),
1881
+ 'input_type' => '',
1882
+ 'input_placeholder' => ''
1883
+ );
1884
+
1885
+ $reason_other = array(
1886
+ 'id' => self::REASON_OTHER,
1887
+ 'text' => $this->get_text_inline( 'Other', 'reason-other' ),
1888
+ 'input_type' => 'textfield',
1889
+ 'input_placeholder' => ''
1890
+ );
1891
+
1892
+ $long_term_user_reasons = array(
1893
+ array(
1894
+ 'id' => self::REASON_NO_LONGER_NEEDED,
1895
+ 'text' => sprintf( $this->get_text_inline( 'I no longer need the %s', 'reason-no-longer-needed' ), $module_type ),
1896
+ 'input_type' => '',
1897
+ 'input_placeholder' => ''
1898
+ ),
1899
+ $reason_found_better_plugin,
1900
+ array(
1901
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
1902
+ 'text' => sprintf( $this->get_text_inline( 'I only needed the %s for a short period', 'reason-needed-for-a-short-period' ), $module_type ),
1903
+ 'input_type' => '',
1904
+ 'input_placeholder' => ''
1905
+ ),
1906
+ array(
1907
+ 'id' => self::REASON_BROKE_MY_SITE,
1908
+ 'text' => sprintf( $this->get_text_inline( 'The %s broke my site', 'reason-broke-my-site' ), $module_type ),
1909
+ 'input_type' => '',
1910
+ 'input_placeholder' => '',
1911
+ 'internal_message' => $contact_support_template
1912
+ ),
1913
+ array(
1914
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
1915
+ 'text' => sprintf( $this->get_text_inline( 'The %s suddenly stopped working', 'reason-suddenly-stopped-working' ), $module_type ),
1916
+ 'input_type' => '',
1917
+ 'input_placeholder' => '',
1918
+ 'internal_message' => $contact_support_template
1919
+ )
1920
+ );
1921
+
1922
+ if ( $this->is_paying() ) {
1923
+ $long_term_user_reasons[] = array(
1924
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
1925
+ 'text' => $this->get_text_inline( "I can't pay for it anymore", 'reason-cant-pay-anymore' ),
1926
+ 'input_type' => 'textfield',
1927
+ 'input_placeholder' => $this->get_text_inline( 'What price would you feel comfortable paying?', 'placeholder-comfortable-price' )
1928
+ );
1929
+ }
1930
+
1931
+ $reason_dont_share_info = array(
1932
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
1933
+ 'text' => $this->get_text_inline( "I don't like to share my information with you", 'reason-dont-like-to-share-my-information' ),
1934
+ 'input_type' => '',
1935
+ 'input_placeholder' => ''
1936
+ );
1937
+
1938
+ /**
1939
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
1940
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
1941
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
1942
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
1943
+ * button in the opt-in form is shown/hidden).
1944
+ */
1945
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
1946
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
1947
+ }
1948
+
1949
+ $uninstall_reasons = array(
1950
+ 'long-term' => $long_term_user_reasons,
1951
+ 'non-registered-and-non-anonymous-short-term' => array(
1952
+ array(
1953
+ 'id' => self::REASON_DIDNT_WORK,
1954
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work", 'reason-didnt-work' ), $module_type ),
1955
+ 'input_type' => '',
1956
+ 'input_placeholder' => ''
1957
+ ),
1958
+ $reason_dont_share_info,
1959
+ $reason_found_better_plugin
1960
+ ),
1961
+ 'short-term' => array(
1962
+ array(
1963
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
1964
+ 'text' => $this->get_text_inline( "I couldn't understand how to make it work", 'reason-couldnt-make-it-work' ),
1965
+ 'input_type' => '',
1966
+ 'input_placeholder' => '',
1967
+ 'internal_message' => $contact_support_template
1968
+ ),
1969
+ $reason_found_better_plugin,
1970
+ array(
1971
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
1972
+ 'text' => sprintf( $this->get_text_inline( "The %s is great, but I need specific feature that you don't support", 'reason-great-but-need-specific-feature' ), $module_type ),
1973
+ 'input_type' => 'textarea',
1974
+ 'input_placeholder' => $this->get_text_inline( 'What feature?', 'placeholder-feature' )
1975
+ ),
1976
+ array(
1977
+ 'id' => self::REASON_NOT_WORKING,
1978
+ 'text' => sprintf( $this->get_text_inline( 'The %s is not working', 'reason-not-working' ), $module_type ),
1979
+ 'input_type' => 'textarea',
1980
+ 'input_placeholder' => $this->get_text_inline( "Kindly share what didn't work so we can fix it for future users...", 'placeholder-share-what-didnt-work' )
1981
+ ),
1982
+ array(
1983
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
1984
+ 'text' => $this->get_text_inline( "It's not what I was looking for", 'reason-not-what-i-was-looking-for' ),
1985
+ 'input_type' => 'textarea',
1986
+ 'input_placeholder' => $this->get_text_inline( "What you've been looking for?", 'placeholder-what-youve-been-looking-for' )
1987
+ ),
1988
+ array(
1989
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
1990
+ 'text' => sprintf( $this->get_text_inline( "The %s didn't work as expected", 'reason-didnt-work-as-expected' ), $module_type ),
1991
+ 'input_type' => 'textarea',
1992
+ 'input_placeholder' => $this->get_text_inline( 'What did you expect?', 'placeholder-what-did-you-expect' )
1993
+ )
1994
+ )
1995
+ );
1996
+
1997
+ // Randomize the reasons for the current user type.
1998
+ shuffle( $uninstall_reasons[ $user_type ] );
1999
+
2000
+ // Keep the following reasons as the last items in the list.
2001
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
2002
+ $uninstall_reasons[ $user_type ][] = $reason_other;
2003
+
2004
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
2005
+
2006
+ return $uninstall_reasons[ $user_type ];
2007
+ }
2008
+
2009
+ /**
2010
+ * Called after the user has submitted his reason for deactivating the plugin.
2011
+ *
2012
+ * @author Leo Fajardo (@leorw)
2013
+ * @since 1.1.2
2014
+ */
2015
+ function _submit_uninstall_reason_action() {
2016
+ $this->_logger->entrance();
2017
+
2018
+ $this->check_ajax_referer( 'submit_uninstall_reason' );
2019
+
2020
+ $reason_id = fs_request_get( 'reason_id' );
2021
+
2022
+ // Check if the given reason ID is an unsigned integer.
2023
+ if ( ! ctype_digit( $reason_id ) ) {
2024
+ exit;
2025
+ }
2026
+
2027
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
2028
+ if ( ! empty( $reason_info ) ) {
2029
+ $reason_info = substr( $reason_info, 0, 128 );
2030
+ }
2031
+
2032
+ $reason = (object) array(
2033
+ 'id' => $reason_id,
2034
+ 'info' => $reason_info,
2035
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
2036
+ );
2037
+
2038
+ $this->_storage->store( 'uninstall_reason', $reason );
2039
+
2040
+ /**
2041
+ * If the module type is "theme", trigger the uninstall event here (on theme deactivation) since themes do
2042
+ * not support uninstall hook.
2043
+ *
2044
+ * @author Leo Fajardo (@leorw)
2045
+ * @since 1.2.2
2046
+ */
2047
+ if ( $this->is_theme() ) {
2048
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
2049
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2050
+ }
2051
+
2052
+ $this->_uninstall_plugin_event( false );
2053
+ $this->remove_sdk_reference();
2054
+ }
2055
+
2056
+ // Print '1' for successful operation.
2057
+ echo 1;
2058
+ exit;
2059
+ }
2060
+
2061
+ /**
2062
+ * @author Leo Fajardo (@leorw)
2063
+ * @since 2.0.2
2064
+ */
2065
+ function _delete_theme_update_data_action() {
2066
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
2067
+ }
2068
+
2069
+ #endregion
2070
+
2071
+ #----------------------------------------------------------------------------------
2072
+ #region Instance
2073
+ #----------------------------------------------------------------------------------
2074
+
2075
+ /**
2076
+ * Main singleton instance.
2077
+ *
2078
+ * @author Vova Feldman (@svovaf)
2079
+ * @since 1.0.0
2080
+ *
2081
+ * @param number $module_id
2082
+ * @param string|bool $slug
2083
+ * @param bool $is_init Is initiation sequence.
2084
+ *
2085
+ * @return Freemius|false
2086
+ */
2087
+ static function instance( $module_id, $slug = false, $is_init = false ) {
2088
+ if ( empty( $module_id ) ) {
2089
+ return false;
2090
+ }
2091
+
2092
+ /**
2093
+ * Load the essential static data prior to initiating FS_Plugin_Manager since there's an essential MS network migration logic that needs to be executed prior to the initiation.
2094
+ */
2095
+ self::_load_required_static();
2096
+
2097
+ if ( ! is_numeric( $module_id ) ) {
2098
+ if ( ! $is_init && true === $slug ) {
2099
+ $is_init = true;
2100
+ }
2101
+
2102
+ $slug = $module_id;
2103
+
2104
+ $module = FS_Plugin_Manager::instance( $slug )->get();
2105
+
2106
+ if ( is_object( $module ) ) {
2107
+ $module_id = $module->id;
2108
+ }
2109
+ }
2110
+
2111
+ $key = 'm_' . $module_id;
2112
+
2113
+ if ( ! isset( self::$_instances[ $key ] ) ) {
2114
+ self::$_instances[ $key ] = new Freemius( $module_id, $slug, $is_init );
2115
+ }
2116
+
2117
+ return self::$_instances[ $key ];
2118
+ }
2119
+
2120
+ /**
2121
+ * @author Vova Feldman (@svovaf)
2122
+ * @since 1.0.6
2123
+ *
2124
+ * @param number $addon_id
2125
+ *
2126
+ * @return bool
2127
+ */
2128
+ private static function has_instance( $addon_id ) {
2129
+ return isset( self::$_instances[ 'm_' . $addon_id ] );
2130
+ }
2131
+
2132
+ /**
2133
+ * @author Leo Fajardo (@leorw)
2134
+ * @since 1.2.2
2135
+ *
2136
+ * @param string|number $id_or_slug
2137
+ *
2138
+ * @return number|false
2139
+ */
2140
+ private static function get_module_id( $id_or_slug ) {
2141
+ if ( is_numeric( $id_or_slug ) ) {
2142
+ return $id_or_slug;
2143
+ }
2144
+
2145
+ foreach ( self::$_instances as $instance ) {
2146
+ if ( $instance->is_plugin() && ( $id_or_slug === $instance->get_slug() ) ) {
2147
+ return $instance->get_id();
2148
+ }
2149
+ }
2150
+
2151
+ return false;
2152
+ }
2153
+
2154
+ /**
2155
+ * @author Vova Feldman (@svovaf)
2156
+ * @since 1.0.6
2157
+ *
2158
+ * @param number $id
2159
+ *
2160
+ * @return false|Freemius
2161
+ */
2162
+ static function get_instance_by_id( $id ) {
2163
+ return isset ( self::$_instances[ 'm_' . $id ] ) ?
2164
+ self::$_instances[ 'm_' . $id ] :
2165
+ false;
2166
+ }
2167
+
2168
+ /**
2169
+ *
2170
+ * @author Vova Feldman (@svovaf)
2171
+ * @since 1.0.1
2172
+ *
2173
+ * @param $plugin_file
2174
+ *
2175
+ * @return false|Freemius
2176
+ */
2177
+ static function get_instance_by_file( $plugin_file ) {
2178
+ $slug = self::find_slug_by_basename( $plugin_file );
2179
+
2180
+ return ( false !== $slug ) ?
2181
+ self::instance( self::get_module_id( $slug ) ) :
2182
+ false;
2183
+ }
2184
+
2185
+ /**
2186
+ * @author Vova Feldman (@svovaf)
2187
+ * @since 1.0.6
2188
+ *
2189
+ * @return false|Freemius
2190
+ */
2191
+ function get_parent_instance() {
2192
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2193
+ }
2194
+
2195
+ /**
2196
+ * @author Vova Feldman (@svovaf)
2197
+ * @since 1.0.6
2198
+ *
2199
+ * @param string|number $id_or_slug
2200
+ *
2201
+ * @return false|Freemius
2202
+ */
2203
+ function get_addon_instance( $id_or_slug ) {
2204
+ $addon_id = self::get_module_id( $id_or_slug );
2205
+
2206
+ return self::instance( $addon_id );
2207
+ }
2208
+
2209
+ #endregion ------------------------------------------------------------------
2210
+
2211
+ /**
2212
+ * @author Vova Feldman (@svovaf)
2213
+ * @since 1.0.6
2214
+ *
2215
+ * @return bool
2216
+ */
2217
+ function is_parent_plugin_installed() {
2218
+ $is_active = self::has_instance( $this->_plugin->parent_plugin_id );
2219
+
2220
+ if ( $is_active ) {
2221
+ return true;
2222
+ }
2223
+
2224
+ /**
2225
+ * Parent module might be a theme. If that's the case, the add-on's FS
2226
+ * instance will be loaded prior to the theme's FS instance, therefore,
2227
+ * we need to check if it's active with a "look ahead".
2228
+ *
2229
+ * @author Vova Feldman
2230
+ * @since 1.2.2.3
2231
+ */
2232
+ global $fs_active_plugins;
2233
+ if ( is_object( $fs_active_plugins ) && is_array( $fs_active_plugins->plugins ) ) {
2234
+ $active_theme = wp_get_theme();
2235
+
2236
+ foreach ( $fs_active_plugins->plugins as $sdk => $module ) {
2237
+ if ( WP_FS__MODULE_TYPE_THEME === $module->type ) {
2238
+ if ( $module->plugin_path == $active_theme->get_stylesheet() ) {
2239
+ // Parent module is a theme and it's currently active.
2240
+ return true;
2241
+ }
2242
+ }
2243
+ }
2244
+ }
2245
+
2246
+ return false;
2247
+ }
2248
+
2249
+ /**
2250
+ * Check if add-on parent plugin in activation mode.
2251
+ *
2252
+ * @author Vova Feldman (@svovaf)
2253
+ * @since 1.0.7
2254
+ *
2255
+ * @return bool
2256
+ */
2257
+ function is_parent_in_activation() {
2258
+ $parent_fs = $this->get_parent_instance();
2259
+ if ( ! is_object( $parent_fs ) ) {
2260
+ return false;
2261
+ }
2262
+
2263
+ return ( $parent_fs->is_activation_mode() );
2264
+ }
2265
+
2266
+ /**
2267
+ * Is plugin in activation mode.
2268
+ *
2269
+ * @author Vova Feldman (@svovaf)
2270
+ * @since 1.0.7
2271
+ *
2272
+ * @param bool $and_on
2273
+ *
2274
+ * @return bool
2275
+ */
2276
+ function is_activation_mode( $and_on = true ) {
2277
+ return fs_is_network_admin() ?
2278
+ $this->is_network_activation_mode( $and_on ) :
2279
+ $this->is_site_activation_mode( $and_on );
2280
+ }
2281
+
2282
+ /**
2283
+ * Is plugin in activation mode.
2284
+ *
2285
+ * @author Vova Feldman (@svovaf)
2286
+ * @since 1.0.7
2287
+ *
2288
+ * @param bool $and_on
2289
+ *
2290
+ * @return bool
2291
+ */
2292
+ function is_site_activation_mode( $and_on = true ) {
2293
+ return (
2294
+ ( $this->is_on() || ! $and_on ) &&
2295
+ ( ! $this->is_registered() ||
2296
+ ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
2297
+ ( ! $this->is_enable_anonymous() ||
2298
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
2299
+ );
2300
+ }
2301
+
2302
+ /**
2303
+ * Checks if the SDK in network activation mode.
2304
+ *
2305
+ * @author Leo Fajardo (@leorw)
2306
+ * @since 2.0.0
2307
+ *
2308
+ * @param bool $and_on
2309
+ *
2310
+ * @return bool
2311
+ */
2312
+ private function is_network_activation_mode( $and_on = true ) {
2313
+ if ( ! $this->_is_network_active ) {
2314
+ // Not network activated.
2315
+ return false;
2316
+ }
2317
+
2318
+ if ( $this->is_network_upgrade_mode() ) {
2319
+ // Special flag to enforce network activation mode to decide what to do with the sites that are not yet opted-in nor skipped.
2320
+ return true;
2321
+ }
2322
+
2323
+ if ( ! $this->is_site_activation_mode( $and_on ) ) {
2324
+ // Whether the context is single site or the network, if the plugin is no longer in activation mode then it is not in network activation mode as well.
2325
+ return false;
2326
+ }
2327
+
2328
+ if ( $this->is_network_delegated_connection() ) {
2329
+ // Super-admin delegated the connection to the site admins -> not activation mode.
2330
+ return false;
2331
+ }
2332
+
2333
+ if ( $this->is_network_anonymous() ) {
2334
+ // Super-admin skipped the connection network wide -> not activation mode.
2335
+ return false;
2336
+ }
2337
+
2338
+ if ( $this->is_network_registered() ) {
2339
+ // Super-admin connected at least one site -> not activation mode.
2340
+ return false;
2341
+ }
2342
+
2343
+ return true;
2344
+ }
2345
+
2346
+ /**
2347
+ * Check if current page is the opt-in/pending-activation page.
2348
+ *
2349
+ * @author Vova Feldman (@svovaf)
2350
+ * @since 1.2.1.7
2351
+ *
2352
+ * @return bool
2353
+ */
2354
+ function is_activation_page() {
2355
+ if ( $this->_menu->is_main_settings_page() ) {
2356
+ return true;
2357
+ }
2358
+
2359
+ if ( ! $this->is_activation_mode() ) {
2360
+ return false;
2361
+ }
2362
+
2363
+ // Check if current page is matching the activation page.
2364
+ return $this->is_matching_url( $this->get_activation_url() );
2365
+ }
2366
+
2367
+ /**
2368
+ * Check if URL path's are matching and that all querystring
2369
+ * arguments of the $sub_url exist in the $url with the same values.
2370
+ *
2371
+ * WARNING:
2372
+ * 1. This method doesn't check if the sub/domain are matching.
2373
+ * 2. Ignore case sensitivity.
2374
+ *
2375
+ * @author Vova Feldman (@svovaf)
2376
+ * @since 1.2.1.7
2377
+ *
2378
+ * @param string $sub_url
2379
+ * @param string $url If argument is not set, check if the sub_url matching the current's page URL.
2380
+ *
2381
+ * @return bool
2382
+ */
2383
+ private function is_matching_url( $sub_url, $url = '' ) {
2384
+ if ( empty( $url ) ) {
2385
+ $url = $_SERVER['REQUEST_URI'];
2386
+ }
2387
+
2388
+ $url = strtolower( $url );
2389
+ $sub_url = strtolower( $sub_url );
2390
+
2391
+ if ( parse_url( $sub_url, PHP_URL_PATH ) !== parse_url( $url, PHP_URL_PATH ) ) {
2392
+ // Different path - DO NOT OVERRIDE PAGE.
2393
+ return false;
2394
+ }
2395
+
2396
+ $url_params = array();
2397
+ parse_str( parse_url( $url, PHP_URL_QUERY ), $url_params );
2398
+
2399
+ $sub_url_params = array();
2400
+ parse_str( parse_url( $sub_url, PHP_URL_QUERY ), $sub_url_params );
2401
+
2402
+ foreach ( $sub_url_params as $key => $val ) {
2403
+ if ( ! isset( $url_params[ $key ] ) || $val != $url_params[ $key ] ) {
2404
+ // Not matching query string - DO NOT OVERRIDE PAGE.
2405
+ return false;
2406
+ }
2407
+ }
2408
+
2409
+ return true;
2410
+ }
2411
+
2412
+ /**
2413
+ * Get the basenames of all active plugins for specific blog. Including network activated plugins.
2414
+ *
2415
+ * @author Vova Feldman (@svovaf)
2416
+ * @since 2.0.0
2417
+ *
2418
+ * @param int $blog_id
2419
+ *
2420
+ * @return string[]
2421
+ */
2422
+ private static function get_active_plugins_basenames( $blog_id = 0 ) {
2423
+ if ( is_multisite() && $blog_id > 0 ) {
2424
+ $active_basenames = get_blog_option( $blog_id, 'active_plugins' );
2425
+ } else {
2426
+ $active_basenames = get_option( 'active_plugins' );
2427
+ }
2428
+
2429
+ if ( is_multisite() ) {
2430
+ $network_active_basenames = get_site_option( 'active_sitewide_plugins' );
2431
+
2432
+ if ( is_array( $network_active_basenames ) && ! empty( $network_active_basenames ) ) {
2433
+ $active_basenames = array_merge( $active_basenames, $network_active_basenames );
2434
+ }
2435
+ }
2436
+
2437
+ return $active_basenames;
2438
+ }
2439
+
2440
+ /**
2441
+ * Get collection of all active plugins. Including network activated plugins.
2442
+ *
2443
+ * @author Vova Feldman (@svovaf)
2444
+ * @since 1.0.9
2445
+ *
2446
+ * @param int $blog_id Since 2.0.0
2447
+ *
2448
+ * @return array[string]array
2449
+ */
2450
+ private static function get_active_plugins( $blog_id = 0 ) {
2451
+ self::require_plugin_essentials();
2452
+
2453
+ $active_plugin = array();
2454
+ $all_plugins = get_plugins();
2455
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2456
+
2457
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
2458
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
2459
+ }
2460
+
2461
+ return $active_plugin;
2462
+ }
2463
+
2464
+ /**
2465
+ * Get collection of all site active plugins for a specified blog.
2466
+ *
2467
+ * @author Vova Feldman (@svovaf)
2468
+ * @since 2.0.0
2469
+ *
2470
+ * @param int $blog_id
2471
+ *
2472
+ * @return array[string]array
2473
+ */
2474
+ private static function get_site_active_plugins( $blog_id = 0 ) {
2475
+ $active_basenames = ( is_multisite() && $blog_id > 0 ) ?
2476
+ get_blog_option( $blog_id, 'active_plugins' ) :
2477
+ get_option( 'active_plugins' );
2478
+
2479
+ $active = array();
2480
+ foreach ( $active_basenames as $basename ) {
2481
+ $active[ $basename ] = array(
2482
+ 'is_active' => true,
2483
+ 'Version' => '1.0', // Dummy version.
2484
+ 'slug' => self::get_plugin_slug( $basename ),
2485
+ );
2486
+ }
2487
+
2488
+ return $active;
2489
+ }
2490
+
2491
+ /**
2492
+ * Get collection of all plugins with their activation status for a specified blog.
2493
+ *
2494
+ * @author Vova Feldman (@svovaf)
2495
+ * @since 1.1.8
2496
+ *
2497
+ * @param int $blog_id Since 2.0.0
2498
+ *
2499
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
2500
+ */
2501
+ private static function get_all_plugins( $blog_id = 0 ) {
2502
+ self::require_plugin_essentials();
2503
+
2504
+ $all_plugins = get_plugins();
2505
+
2506
+ $active_plugins_basenames = self::get_active_plugins_basenames( $blog_id );
2507
+
2508
+ foreach ( $all_plugins as $basename => &$data ) {
2509
+ // By default set to inactive (next foreach update the active plugins).
2510
+ $data['is_active'] = false;
2511
+ // Enrich with plugin slug.
2512
+ $data['slug'] = self::get_plugin_slug( $basename );
2513
+ }
2514
+
2515
+ // Flag active plugins.
2516
+ foreach ( $active_plugins_basenames as $basename ) {
2517
+ if ( isset( $all_plugins[ $basename ] ) ) {
2518
+ $all_plugins[ $basename ]['is_active'] = true;
2519
+ }
2520
+ }
2521
+
2522
+ return $all_plugins;
2523
+ }
2524
+
2525
+ /**
2526
+ * Get collection of all plugins and if they are network level activated.
2527
+ *
2528
+ * @author Vova Feldman (@svovaf)
2529
+ * @since 2.0.0
2530
+ *
2531
+ * @return array Key is the plugin basename and the value is an array of the plugin data.
2532
+ */
2533
+ private static function get_network_plugins() {
2534
+ self::require_plugin_essentials();
2535
+
2536
+ $all_plugins = get_plugins();
2537
+
2538
+ $network_active_basenames = is_multisite() ?
2539
+ get_site_option( 'active_sitewide_plugins' ) :
2540
+ array();
2541
+
2542
+ foreach ( $all_plugins as $basename => &$data ) {
2543
+ // By default set to inactive (next foreach update the active plugins).
2544
+ $data['is_active'] = false;
2545
+ // Enrich with plugin slug.
2546
+ $data['slug'] = self::get_plugin_slug( $basename );
2547
+ }
2548
+
2549
+ // Flag active plugins.
2550
+ foreach ( $network_active_basenames as $basename ) {
2551
+ if ( isset( $all_plugins[ $basename ] ) ) {
2552
+ $all_plugins[ $basename ]['is_active'] = true;
2553
+ }
2554
+ }
2555
+
2556
+ return $all_plugins;
2557
+ }
2558
+
2559
+ /**
2560
+ * Cached result of get_site_transient( 'update_plugins' )
2561
+ *
2562
+ * @author Vova Feldman (@svovaf)
2563
+ * @since 1.1.8
2564
+ *
2565
+ * @var object
2566
+ */
2567
+ private static $_plugins_info;
2568
+
2569
+ /**
2570
+ * Helper function to get specified plugin's slug.
2571
+ *
2572
+ * @author Vova Feldman (@svovaf)
2573
+ * @since 1.1.8
2574
+ *
2575
+ * @param $basename
2576
+ *
2577
+ * @return string
2578
+ */
2579
+ private static function get_plugin_slug( $basename ) {
2580
+ if ( ! isset( self::$_plugins_info ) ) {
2581
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
2582
+ }
2583
+
2584
+ $slug = '';
2585
+
2586
+ if ( is_object( self::$_plugins_info ) ) {
2587
+ if ( isset( self::$_plugins_info->no_update ) &&
2588
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
2589
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
2590
+ ) {
2591
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
2592
+ } else if ( isset( self::$_plugins_info->response ) &&
2593
+ isset( self::$_plugins_info->response[ $basename ] ) &&
2594
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
2595
+ ) {
2596
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
2597
+ }
2598
+ }
2599
+
2600
+ if ( empty( $slug ) ) {
2601
+ // Try to find slug from FS data.
2602
+ $slug = self::find_slug_by_basename( $basename );
2603
+ }
2604
+
2605
+ if ( empty( $slug ) ) {
2606
+ // Fallback to plugin's folder name.
2607
+ $slug = dirname( $basename );
2608
+ }
2609
+
2610
+ return $slug;
2611
+ }
2612
+
2613
+ private static $_statics_loaded = false;
2614
+
2615
+ /**
2616
+ * Load static resources.
2617
+ *
2618
+ * @author Vova Feldman (@svovaf)
2619
+ * @since 1.0.1
2620
+ */
2621
+ private static function _load_required_static() {
2622
+ if ( self::$_statics_loaded ) {
2623
+ return;
2624
+ }
2625
+
2626
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
2627
+
2628
+ self::$_static_logger->entrance();
2629
+
2630
+ self::$_accounts = FS_Options::instance( WP_FS__ACCOUNTS_OPTION_NAME, true );
2631
+
2632
+ if ( is_multisite() ) {
2633
+ $has_skipped_migration = (
2634
+ // 'id_slug_type_path_map' - was never stored on older versions, therefore, not exists on the site level.
2635
+ null === self::$_accounts->get_option( 'id_slug_type_path_map', null, false ) &&
2636
+ // 'file_slug_map' stored on the site level, so it was running an SDK version before it was integrated with MS-network.
2637
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false )
2638
+ );
2639
+
2640
+ /**
2641
+ * If the file_slug_map exists on the site level but doesn't exist on the
2642
+ * network level storage, it means that we need to process the storage with migration.
2643
+ *
2644
+ * The code in this `if` scope will only be executed once and only for the first site that will execute it because once we migrate the storage data, file_slug_map will be already set in the network level storage.
2645
+ *
2646
+ * @author Vova Feldman (@svovaf)
2647
+ * @since 2.0.0
2648
+ */
2649
+ if (
2650
+ ( $has_skipped_migration && true !== self::$_accounts->get_option( 'ms_migration_complete', false, true ) ) ||
2651
+ ( null === self::$_accounts->get_option( 'file_slug_map', null, true ) &&
2652
+ null !== self::$_accounts->get_option( 'file_slug_map', null, false ) )
2653
+ ) {
2654
+ self::migrate_options_to_network();
2655
+ }
2656
+ }
2657
+
2658
+ self::$_global_admin_notices = FS_Admin_Notices::instance( 'global' );
2659
+
2660
+ if ( ! WP_FS__DEMO_MODE ) {
2661
+ add_action( ( fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu', array(
2662
+ 'Freemius',
2663
+ '_add_debug_section'
2664
+ ) );
2665
+ }
2666
+
2667
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
2668
+
2669
+ self::add_ajax_action_static( 'get_debug_log', array( 'Freemius', '_get_debug_log' ) );
2670
+
2671
+ self::add_ajax_action_static( 'get_db_option', array( 'Freemius', '_get_db_option' ) );
2672
+
2673
+ self::add_ajax_action_static( 'set_db_option', array( 'Freemius', '_set_db_option' ) );
2674
+
2675
+ if ( 0 == did_action( 'plugins_loaded' ) ) {
2676
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
2677
+ }
2678
+
2679
+ add_action( 'admin_footer', array( 'Freemius', '_enrich_ajax_url' ) );
2680
+
2681
+ self::$_statics_loaded = true;
2682
+ }
2683
+
2684
+ /**
2685
+ * @author Leo Fajardo (@leorw)
2686
+ *
2687
+ * @since 2.1.3
2688
+ */
2689
+ private static function migrate_options_to_network() {
2690
+ self::migrate_accounts_to_network();
2691
+
2692
+ // Migrate API options from site level to network level.
2693
+ $api_network_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true, true );
2694
+ $api_network_options->migrate_to_network();
2695
+
2696
+ // Migrate API cache to network level storage.
2697
+ FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME )->migrate_to_network();
2698
+
2699
+ self::$_accounts->set_option( 'ms_migration_complete', true, true );
2700
+ }
2701
+
2702
+ #----------------------------------------------------------------------------------
2703
+ #region Localization
2704
+ #----------------------------------------------------------------------------------
2705
+
2706
+ /**
2707
+ * Load framework's text domain.
2708
+ *
2709
+ * @author Vova Feldman (@svovaf)
2710
+ * @since 1.2.1
2711
+ */
2712
+ static function _load_textdomain() {
2713
+ if ( ! is_admin() ) {
2714
+ return;
2715
+ }
2716
+
2717
+ global $fs_active_plugins;
2718
+
2719
+ // Works both for plugins and themes.
2720
+ load_plugin_textdomain(
2721
+ 'freemius',
2722
+ false,
2723
+ $fs_active_plugins->newest->sdk_path . '/languages/'
2724
+ );
2725
+ }
2726
+
2727
+ #endregion
2728
+
2729
+ #----------------------------------------------------------------------------------
2730
+ #region Debugging
2731
+ #----------------------------------------------------------------------------------
2732
+
2733
+ /**
2734
+ * @author Vova Feldman (@svovaf)
2735
+ * @since 1.0.8
2736
+ */
2737
+ static function _add_debug_section() {
2738
+ if ( ! is_super_admin() ) {
2739
+ // Add debug page only for super-admins.
2740
+ return;
2741
+ }
2742
+
2743
+ self::$_static_logger->entrance();
2744
+
2745
+ $title = sprintf( '%s [v.%s]', fs_text_inline( 'Freemius Debug' ), WP_FS__SDK_VERSION );
2746
+
2747
+ if ( WP_FS__DEV_MODE ) {
2748
+ // Add top-level debug menu item.
2749
+ $hook = FS_Admin_Menu_Manager::add_page(
2750
+ $title,
2751
+ $title,
2752
+ 'manage_options',
2753
+ 'freemius',
2754
+ array( 'Freemius', '_debug_page_render' )
2755
+ );
2756
+ } else {
2757
+ // Add hidden debug page.
2758
+ $hook = FS_Admin_Menu_Manager::add_subpage(
2759
+ null,
2760
+ $title,
2761
+ $title,
2762
+ 'manage_options',
2763
+ 'freemius',
2764
+ array( 'Freemius', '_debug_page_render' )
2765
+ );
2766
+ }
2767
+
2768
+ if ( ! empty( $hook ) ) {
2769
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
2770
+ }
2771
+ }
2772
+
2773
+ /**
2774
+ * @author Vova Feldman (@svovaf)
2775
+ * @since 1.1.7.3
2776
+ */
2777
+ static function _toggle_debug_mode() {
2778
+ $is_on = fs_request_get( 'is_on', false, 'post' );
2779
+
2780
+ if ( fs_request_is_post() && in_array( $is_on, array( 0, 1 ) ) ) {
2781
+ update_option( 'fs_debug_mode', $is_on );
2782
+
2783
+ // Turn on/off storage logging.
2784
+ FS_Logger::_set_storage_logging( ( 1 == $is_on ) );
2785
+ }
2786
+
2787
+ exit;
2788
+ }
2789
+
2790
+ /**
2791
+ * @author Vova Feldman (@svovaf)
2792
+ * @since 1.2.1.6
2793
+ */
2794
+ static function _get_debug_log() {
2795
+ $logs = FS_Logger::load_db_logs(
2796
+ fs_request_get( 'filters', false, 'post' ),
2797
+ ! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? $_POST['limit'] : 200,
2798
+ ! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? $_POST['offset'] : 0
2799
+ );
2800
+
2801
+ self::shoot_ajax_success( $logs );
2802
+ }
2803
+
2804
+ /**
2805
+ * @author Vova Feldman (@svovaf)
2806
+ * @since 1.2.1.7
2807
+ */
2808
+ static function _get_db_option() {
2809
+ $option_name = fs_request_get( 'option_name' );
2810
+
2811
+ $value = get_option( $option_name );
2812
+
2813
+ $result = array(
2814
+ 'name' => $option_name,
2815
+ );
2816
+
2817
+ if ( false !== $value ) {
2818
+ if ( ! is_string( $value ) ) {
2819
+ $value = json_encode( $value );
2820
+ }
2821
+
2822
+ $result['value'] = $value;
2823
+ }
2824
+
2825
+ self::shoot_ajax_success( $result );
2826
+ }
2827
+
2828
+ /**
2829
+ * @author Vova Feldman (@svovaf)
2830
+ * @since 1.2.1.7
2831
+ */
2832
+ static function _set_db_option() {
2833
+ $option_name = fs_request_get( 'option_name' );
2834
+ $option_value = fs_request_get( 'option_value' );
2835
+
2836
+ if ( ! empty( $option_value ) ) {
2837
+ update_option( $option_name, $option_value );
2838
+ }
2839
+
2840
+ self::shoot_ajax_success();
2841
+ }
2842
+
2843
+ /**
2844
+ * @author Vova Feldman (@svovaf)
2845
+ * @since 1.0.8
2846
+ */
2847
+ static function _debug_page_actions() {
2848
+ self::_clean_admin_content_section();
2849
+
2850
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
2851
+ check_admin_referer( 'restart_freemius' );
2852
+
2853
+ if ( ! is_multisite() ) {
2854
+ // Clear accounts data.
2855
+ self::$_accounts->clear( null, true );
2856
+ } else {
2857
+ $sites = self::get_sites();
2858
+ foreach ( $sites as $site ) {
2859
+ $blog_id = self::get_site_blog_id( $site );
2860
+ self::$_accounts->clear( $blog_id, true );
2861
+ }
2862
+
2863
+ // Clear network level storage.
2864
+ self::$_accounts->clear( true, true );
2865
+ }
2866
+
2867
+ // Clear SDK reference cache.
2868
+ delete_option( 'fs_active_plugins' );
2869
+ } else if ( fs_request_is_action( 'clear_updates_data' ) ) {
2870
+ check_admin_referer( 'clear_updates_data' );
2871
+
2872
+ if ( ! is_multisite() ) {
2873
+ set_site_transient( 'update_plugins', null );
2874
+ set_site_transient( 'update_themes', null );
2875
+ } else {
2876
+ $current_blog_id = get_current_blog_id();
2877
+
2878
+ $sites = self::get_sites();
2879
+ foreach ( $sites as $site ) {
2880
+ switch_to_blog( self::get_site_blog_id( $site ) );
2881
+
2882
+ set_site_transient( 'update_plugins', null );
2883
+ set_site_transient( 'update_themes', null );
2884
+ }
2885
+
2886
+ switch_to_blog( $current_blog_id );
2887
+ }
2888
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
2889
+ check_admin_referer( 'simulate_trial' );
2890
+
2891
+ $fs = freemius( fs_request_get( 'module_id' ) );
2892
+
2893
+ // Update SDK install to at least 24 hours before.
2894
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
2895
+ // Unset the trial shown timestamp.
2896
+ unset( $fs->_storage->trial_promotion_shown );
2897
+ } else if ( fs_request_is_action( 'simulate_network_upgrade' ) ) {
2898
+ check_admin_referer( 'simulate_network_upgrade' );
2899
+
2900
+ $fs = freemius( fs_request_get( 'module_id' ) );
2901
+
2902
+ self::set_network_upgrade_mode( $fs->_storage );
2903
+ } else if ( fs_request_is_action( 'delete_install' ) ) {
2904
+ check_admin_referer( 'delete_install' );
2905
+
2906
+ self::_delete_site_by_slug(
2907
+ fs_request_get( 'slug' ),
2908
+ fs_request_get( 'module_type' ),
2909
+ true,
2910
+ fs_request_get( 'blog_id', null )
2911
+ );
2912
+ } else if ( fs_request_is_action( 'delete_user' ) ) {
2913
+ check_admin_referer( 'delete_user' );
2914
+
2915
+ self::delete_user( fs_request_get( 'user_id' ) );
2916
+ } else if ( fs_request_is_action( 'download_logs' ) ) {
2917
+ check_admin_referer( 'download_logs' );
2918
+
2919
+ $download_url = FS_Logger::download_db_logs(
2920
+ fs_request_get( 'filters', false, 'post' )
2921
+ );
2922
+
2923
+ if ( false === $download_url ) {
2924
+ wp_die( 'Oops... there was an error while generating the logs download file. Please try again and if it doesn\'t work contact support@freemius.com.' );
2925
+ }
2926
+
2927
+ fs_redirect( $download_url );
2928
+ } else if ( fs_request_is_action( 'migrate_options_to_network' ) ) {
2929
+ check_admin_referer( 'migrate_options_to_network' );
2930
+
2931
+ self::migrate_options_to_network();
2932
+ }
2933
+ }
2934
+
2935
+ /**
2936
+ * @author Vova Feldman (@svovaf)
2937
+ * @since 1.0.8
2938
+ */
2939
+ static function _debug_page_render() {
2940
+ self::$_static_logger->entrance();
2941
+
2942
+ if ( ! is_multisite() ) {
2943
+ $all_plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
2944
+ $all_themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME );
2945
+ } else {
2946
+ $sites = self::get_sites();
2947
+
2948
+ $all_plugins_installs = array();
2949
+ $all_themes_installs = array();
2950
+
2951
+ foreach ( $sites as $site ) {
2952
+ $blog_id = self::get_site_blog_id( $site );
2953
+
2954
+ $plugins_installs = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id );
2955
+
2956
+ foreach ( $plugins_installs as $slug => $install ) {
2957
+ if ( ! isset( $all_plugins_installs[ $slug ] ) ) {
2958
+ $all_plugins_installs[ $slug ] = array();
2959
+ }
2960
+
2961
+ $install->blog_id = $blog_id;
2962
+
2963
+ $all_plugins_installs[ $slug ][] = $install;
2964
+ }
2965
+
2966
+ $themes_installs = self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id );
2967
+
2968
+ foreach ( $themes_installs as $slug => $install ) {
2969
+ if ( ! isset( $all_themes_installs[ $slug ] ) ) {
2970
+ $all_themes_installs[ $slug ] = array();
2971
+ }
2972
+
2973
+ $install->blog_id = $blog_id;
2974
+
2975
+ $all_themes_installs[ $slug ][] = $install;
2976
+ }
2977
+ }
2978
+ }
2979
+
2980
+ $licenses_by_module_type = self::get_all_licenses_by_module_type();
2981
+
2982
+ $vars = array(
2983
+ 'plugin_sites' => $all_plugins_installs,
2984
+ 'theme_sites' => $all_themes_installs,
2985
+ 'users' => self::get_all_users(),
2986
+ 'addons' => self::get_all_addons(),
2987
+ 'account_addons' => self::get_all_account_addons(),
2988
+ 'plugin_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_PLUGIN ],
2989
+ 'theme_licenses' => $licenses_by_module_type[ WP_FS__MODULE_TYPE_THEME ]
2990
+ );
2991
+
2992
+ fs_enqueue_local_style( 'fs_debug', '/admin/debug.css' );
2993
+ fs_require_once_template( 'debug.php', $vars );
2994
+ }
2995
+
2996
+ #endregion
2997
+
2998
+ #----------------------------------------------------------------------------------
2999
+ #region Connectivity Issues
3000
+ #----------------------------------------------------------------------------------
3001
+
3002
+ /**
3003
+ * Check if Freemius should be turned on for the current plugin install.
3004
+ *
3005
+ * Note:
3006
+ * $this->_is_on is updated in has_api_connectivity()
3007
+ *
3008
+ * @author Vova Feldman (@svovaf)
3009
+ * @since 1.0.9
3010
+ *
3011
+ * @return bool
3012
+ */
3013
+ function is_on() {
3014
+ self::$_static_logger->entrance();
3015
+
3016
+ if ( isset( $this->_is_on ) ) {
3017
+ return $this->_is_on;
3018
+ }
3019
+
3020
+ // If already installed or pending then sure it's on :)
3021
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
3022
+ $this->_is_on = true;
3023
+
3024
+ return true;
3025
+ }
3026
+
3027
+ return false;
3028
+ }
3029
+
3030
+ /**
3031
+ * @author Vova Feldman (@svovaf)
3032
+ * @since 1.1.7.3
3033
+ *
3034
+ * @param bool $flush_if_no_connectivity
3035
+ *
3036
+ * @return bool
3037
+ */
3038
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
3039
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
3040
+ // Connectivity test was never executed, or cache was cleared.
3041
+ return true;
3042
+ }
3043
+
3044
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
3045
+ if ( WP_FS__IS_HTTP_REQUEST ) {
3046
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
3047
+ // Domain changed.
3048
+ return true;
3049
+ }
3050
+
3051
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
3052
+ // Server IP changed.
3053
+ return true;
3054
+ }
3055
+ }
3056
+ }
3057
+
3058
+ if ( $this->_storage->connectivity_test['is_connected'] &&
3059
+ $this->_storage->connectivity_test['is_active']
3060
+ ) {
3061
+ // API connected and Freemius is active - no need to run connectivity check.
3062
+ return false;
3063
+ }
3064
+
3065
+ if ( $flush_if_no_connectivity ) {
3066
+ /**
3067
+ * If explicitly asked to flush when no connectivity - do it only
3068
+ * if at least 10 sec passed from the last API connectivity test.
3069
+ */
3070
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
3071
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
3072
+ }
3073
+
3074
+ /**
3075
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
3076
+ */
3077
+ $version = $this->get_plugin_version();
3078
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
3079
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
3080
+ return true;
3081
+ }
3082
+
3083
+ return false;
3084
+ }
3085
+
3086
+ /**
3087
+ * @author Vova Feldman (@svovaf)
3088
+ * @since 1.1.7.4
3089
+ *
3090
+ * @param int|null $blog_id Since 2.0.0.
3091
+ * @param bool $is_gdpr_test Since 2.0.2. Perform only the GDPR test.
3092
+ *
3093
+ * @return object|false
3094
+ */
3095
+ private function ping( $blog_id = null, $is_gdpr_test = false ) {
3096
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
3097
+ return false;
3098
+ }
3099
+
3100
+ $version = $this->get_plugin_version();
3101
+
3102
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
3103
+
3104
+ return $this->get_api_plugin_scope()->ping(
3105
+ $this->get_anonymous_id( $blog_id ),
3106
+ array(
3107
+ 'is_update' => json_encode( $is_update ),
3108
+ 'version' => $version,
3109
+ 'sdk' => $this->version,
3110
+ 'is_admin' => json_encode( is_admin() ),
3111
+ 'is_ajax' => json_encode( self::is_ajax() ),
3112
+ 'is_cron' => json_encode( self::is_cron() ),
3113
+ 'is_gdpr_test' => $is_gdpr_test,
3114
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
3115
+ )
3116
+ );
3117
+ }
3118
+
3119
+ /**
3120
+ * Check if there's any connectivity issue to Freemius API.
3121
+ *
3122
+ * @author Vova Feldman (@svovaf)
3123
+ * @since 1.0.9
3124
+ *
3125
+ * @param bool $flush_if_no_connectivity
3126
+ *
3127
+ * @return bool
3128
+ */
3129
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
3130
+ $this->_logger->entrance();
3131
+
3132
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
3133
+ return $this->_has_api_connection;
3134
+ }
3135
+
3136
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
3137
+ isset( $this->_storage->connectivity_test ) &&
3138
+ true === $this->_storage->connectivity_test['is_connected']
3139
+ ) {
3140
+ unset( $this->_storage->connectivity_test );
3141
+ }
3142
+
3143
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
3144
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
3145
+ /**
3146
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
3147
+ *
3148
+ * @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
3149
+ */
3150
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
3151
+ $this->is_premium() ||
3152
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3153
+
3154
+ return $this->_has_api_connection;
3155
+ }
3156
+
3157
+ $pong = $this->ping();
3158
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3159
+
3160
+ if ( ! $is_connected ) {
3161
+ // API failure.
3162
+ $this->_add_connectivity_issue_message( $pong );
3163
+ }
3164
+
3165
+ if ( $is_connected ) {
3166
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3167
+ }
3168
+
3169
+ $this->store_connectivity_info( $pong, $is_connected );
3170
+
3171
+ return $this->_has_api_connection;
3172
+ }
3173
+
3174
+ /**
3175
+ * @author Vova Feldman (@svovaf)
3176
+ * @since 1.1.7.4
3177
+ *
3178
+ * @param object $pong
3179
+ * @param bool $is_connected
3180
+ */
3181
+ private function store_connectivity_info( $pong, $is_connected ) {
3182
+ $this->_logger->entrance();
3183
+
3184
+ $version = $this->get_plugin_version();
3185
+
3186
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
3187
+ $is_active = false;
3188
+ } else {
3189
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
3190
+ }
3191
+
3192
+ $is_active = $this->apply_filters(
3193
+ 'is_on',
3194
+ $is_active,
3195
+ $this->is_plugin_update(),
3196
+ $version
3197
+ );
3198
+
3199
+ $this->_storage->connectivity_test = array(
3200
+ 'is_connected' => $is_connected,
3201
+ 'host' => $_SERVER['HTTP_HOST'],
3202
+ 'server_ip' => WP_FS__REMOTE_ADDR,
3203
+ 'is_active' => $is_active,
3204
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3205
+ // Last version with connectivity attempt.
3206
+ 'version' => $version,
3207
+ );
3208
+
3209
+ $this->_has_api_connection = $is_connected;
3210
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
3211
+ }
3212
+
3213
+ /**
3214
+ * Force turning Freemius on.
3215
+ *
3216
+ * @author Vova Feldman (@svovaf)
3217
+ * @since 1.1.8.1
3218
+ *
3219
+ * @return bool TRUE if successfully turned on.
3220
+ */
3221
+ private function turn_on() {
3222
+ $this->_logger->entrance();
3223
+
3224
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
3225
+ return false;
3226
+ }
3227
+
3228
+ $updated_connectivity = $this->_storage->connectivity_test;
3229
+ $updated_connectivity['is_active'] = true;
3230
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
3231
+ $this->_storage->connectivity_test = $updated_connectivity;
3232
+
3233
+ $this->_is_on = true;
3234
+
3235
+ return true;
3236
+ }
3237
+
3238
+ /**
3239
+ * Anonymous and unique site identifier (Hash).
3240
+ *
3241
+ * @author Vova Feldman (@svovaf)
3242
+ * @since 1.1.0
3243
+ *
3244
+ * @param null|int $blog_id Since 2.0.0
3245
+ *
3246
+ * @return string
3247
+ */
3248
+ function get_anonymous_id( $blog_id = null ) {
3249
+ $unique_id = self::$_accounts->get_option( 'unique_id', null, $blog_id );
3250
+
3251
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
3252
+ $key = fs_strip_url_protocol( get_site_url( $blog_id ) );
3253
+
3254
+ $secure_auth = SECURE_AUTH_KEY;
3255
+ if ( empty( $secure_auth ) || false !== strpos( $secure_auth, ' ' ) ) {
3256
+ // Protect against default auth key.
3257
+ $secure_auth = md5( microtime() );
3258
+ }
3259
+
3260
+ /**
3261
+ * Base the unique identifier on the WP secure authentication key. Which
3262
+ * turns the key into a secret anonymous identifier. This will help us
3263
+ * to avoid duplicate installs generation on the backend upon opt-in.
3264
+ *
3265
+ * @author Vova Feldman (@svovaf)
3266
+ * @since 1.2.3
3267
+ */
3268
+ $unique_id = md5( $key . $secure_auth );
3269
+
3270
+ self::$_accounts->set_option( 'unique_id', $unique_id, true, $blog_id );
3271
+ }
3272
+
3273
+ $this->_logger->departure( $unique_id );
3274
+
3275
+ return $unique_id;
3276
+ }
3277
+
3278
+ /**
3279
+ * @author Vova Feldman (@svovaf)
3280
+ * @since 1.1.7.4
3281
+ *
3282
+ * @return \WP_User
3283
+ */
3284
+ static function _get_current_wp_user() {
3285
+ self::require_pluggable_essentials();
3286
+ self::wp_cookie_constants();
3287
+
3288
+ return wp_get_current_user();
3289
+ }
3290
+
3291
+ /**
3292
+ * Define cookie constants which are required by Freemius::_get_current_wp_user() since
3293
+ * it uses wp_get_current_user() which needs the cookie constants set. When a plugin
3294
+ * is network activated the cookie constants are only configured after the network
3295
+ * plugins activation, therefore, if we don't define those constants WP will throw
3296
+ * PHP warnings/notices.
3297
+ *
3298
+ * @author Vova Feldman (@svovaf)
3299
+ * @since 2.1.1
3300
+ */
3301
+ private static function wp_cookie_constants() {
3302
+ if ( defined( 'LOGGED_IN_COOKIE' ) &&
3303
+ ( defined( 'AUTH_COOKIE' ) || defined( 'SECURE_AUTH_COOKIE' ) )
3304
+ ) {
3305
+ return;
3306
+ }
3307
+
3308
+ /**
3309
+ * Used to guarantee unique hash cookies
3310
+ *
3311
+ * @since 1.5.0
3312
+ */
3313
+ if ( ! defined( 'COOKIEHASH' ) ) {
3314
+ $siteurl = get_site_option( 'siteurl' );
3315
+ if ( $siteurl ) {
3316
+ define( 'COOKIEHASH', md5( $siteurl ) );
3317
+ } else {
3318
+ define( 'COOKIEHASH', '' );
3319
+ }
3320
+ }
3321
+
3322
+ if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
3323
+ define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
3324
+ }
3325
+
3326
+ /**
3327
+ * @since 2.5.0
3328
+ */
3329
+ if ( ! defined( 'AUTH_COOKIE' ) ) {
3330
+ define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
3331
+ }
3332
+
3333
+ /**
3334
+ * @since 2.6.0
3335
+ */
3336
+ if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
3337
+ define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
3338
+ }
3339
+ }
3340
+
3341
+ /**
3342
+ * @author Vova Feldman (@svovaf)
3343
+ * @since 2.1.0
3344
+ *
3345
+ * @return int
3346
+ */
3347
+ static function get_current_wp_user_id() {
3348
+ $wp_user = self::_get_current_wp_user();
3349
+
3350
+ return $wp_user->ID;
3351
+ }
3352
+
3353
+ /**
3354
+ * @author Vova Feldman (@svovaf)
3355
+ * @since 1.2.1.7
3356
+ *
3357
+ * @param string $email
3358
+ *
3359
+ * @return bool
3360
+ */
3361
+ static function is_valid_email( $email ) {
3362
+ if ( false === filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
3363
+ return false;
3364
+ }
3365
+
3366
+ $parts = explode( '@', $email );
3367
+
3368
+ if ( 2 !== count( $parts ) || empty( $parts[1] ) ) {
3369
+ return false;
3370
+ }
3371
+
3372
+ $blacklist = array(
3373
+ 'admin.',
3374
+ 'webmaster.',
3375
+ 'localhost.',
3376
+ 'dev.',
3377
+ 'development.',
3378
+ 'test.',
3379
+ 'stage.',
3380
+ 'staging.',
3381
+ );
3382
+
3383
+ // Make sure domain is not one of the blacklisted.
3384
+ foreach ( $blacklist as $invalid ) {
3385
+ if ( 0 === strpos( $parts[1], $invalid ) ) {
3386
+ return false;
3387
+ }
3388
+ }
3389
+
3390
+ // Get the UTF encoded domain name.
3391
+ $domain = idn_to_ascii( $parts[1] ) . '.';
3392
+
3393
+ return ( checkdnsrr( $domain, 'MX' ) || checkdnsrr( $domain, 'A' ) );
3394
+ }
3395
+
3396
+ /**
3397
+ * Generate API connectivity issue message.
3398
+ *
3399
+ * @author Vova Feldman (@svovaf)
3400
+ * @since 1.0.9
3401
+ *
3402
+ * @param mixed $api_result
3403
+ * @param bool $is_first_failure
3404
+ */
3405
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
3406
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
3407
+ // Don't add message if it's the free version and can run anonymously.
3408
+ return;
3409
+ }
3410
+
3411
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
3412
+ require_once ABSPATH . 'wp-includes/functions.php';
3413
+ }
3414
+
3415
+ $current_user = self::_get_current_wp_user();
3416
+ // $admin_email = get_option( 'admin_email' );
3417
+ $admin_email = $current_user->user_email;
3418
+
3419
+ // Aliases.
3420
+ $deactivate_plugin_title = $this->esc_html_inline( 'That\'s exhausting, please deactivate', 'deactivate-plugin-title' );
3421
+ $deactivate_plugin_desc = $this->esc_html_inline( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'deactivate-plugin-desc' );
3422
+ $install_previous_title = $this->esc_html_inline( 'Let\'s try your previous version', 'install-previous-title' );
3423
+ $install_previous_desc = $this->esc_html_inline( 'Uninstall this version and install the previous one.', 'install-previous-desc' );
3424
+ $fix_issue_title = $this->esc_html_inline( 'Yes - I\'m giving you a chance to fix it', 'fix-issue-title' );
3425
+ $fix_issue_desc = $this->esc_html_inline( '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.', 'fix-issue-desc' );
3426
+ /* translators: %s: product title (e.g. "Awesome Plugin" requires an access to...) */
3427
+ $x_requires_access_to_api = $this->esc_html_inline( '%s requires an access to our API.', 'x-requires-access-to-api' );
3428
+ $sysadmin_title = $this->esc_html_inline( 'I\'m a system administrator', 'sysadmin-title' );
3429
+ $happy_to_resolve_issue_asap = $this->esc_html_inline( '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.', 'happy-to-resolve-issue-asap' );
3430
+
3431
+ $message = false;
3432
+ if ( is_object( $api_result ) &&
3433
+ isset( $api_result->error ) &&
3434
+ isset( $api_result->error->code )
3435
+ ) {
3436
+ switch ( $api_result->error->code ) {
3437
+ case 'curl_missing':
3438
+ $missing_methods = '';
3439
+ if ( is_array( $api_result->missing_methods ) &&
3440
+ ! empty( $api_result->missing_methods )
3441
+ ) {
3442
+ foreach ( $api_result->missing_methods as $m ) {
3443
+ if ( 'curl_version' === $m ) {
3444
+ continue;
3445
+ }
3446
+
3447
+ if ( ! empty( $missing_methods ) ) {
3448
+ $missing_methods .= ', ';
3449
+ }
3450
+
3451
+ $missing_methods .= sprintf( '<code>%s</code>', $m );
3452
+ }
3453
+
3454
+ if ( ! empty( $missing_methods ) ) {
3455
+ $missing_methods = sprintf(
3456
+ '<br><br><b>%s</b> %s',
3457
+ $this->esc_html_inline( 'Disabled method(s):', 'curl-disabled-methods' ),
3458
+ $missing_methods
3459
+ );
3460
+ }
3461
+ }
3462
+
3463
+ $message = sprintf(
3464
+ $x_requires_access_to_api . ' ' .
3465
+ $this->esc_html_inline( 'We use PHP cURL library for the API calls, which is a very common library and usually installed and activated out of the box. Unfortunately, cURL is not activated (or disabled) on your server.', 'curl-missing-message' ) . ' ' .
3466
+ $missing_methods .
3467
+ ' %s',
3468
+ '<b>' . $this->get_plugin_name() . '</b>',
3469
+ sprintf(
3470
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3471
+ sprintf(
3472
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
3473
+ $this->get_text_inline( 'I don\'t know what is cURL or how to install it, help me!', 'curl-missing-no-clue-title' ),
3474
+ ' - ' . sprintf(
3475
+ $this->get_text_inline( '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.', 'curl-missing-no-clue-desc' ),
3476
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3477
+ )
3478
+ ),
3479
+ sprintf(
3480
+ '<b>%s</b> - %s',
3481
+ $sysadmin_title,
3482
+ esc_html( sprintf( $this->get_text_inline( 'Great, please install cURL and enable it in your php.ini file. In addition, search for the \'disable_functions\' directive in your php.ini file and remove any disabled methods starting with \'curl_\'. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the %s and reactivate it back again.', 'curl-missing-sysadmin-desc' ), $this->get_module_label( true ) ) )
3483
+ ),
3484
+ sprintf(
3485
+ '<a href="%s"><b>%s</b></a> - %s',
3486
+ 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 ),
3487
+ $deactivate_plugin_title,
3488
+ $deactivate_plugin_desc
3489
+ )
3490
+ )
3491
+ );
3492
+ break;
3493
+ case 'cloudflare_ddos_protection':
3494
+ $message = sprintf(
3495
+ $x_requires_access_to_api . ' ' .
3496
+ $this->esc_html_inline( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'cloudflare-blocks-connection-message' ) . ' ' .
3497
+ $happy_to_resolve_issue_asap .
3498
+ ' %s',
3499
+ '<b>' . $this->get_plugin_name() . '</b>',
3500
+ sprintf(
3501
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3502
+ sprintf(
3503
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
3504
+ $fix_issue_title,
3505
+ ' - ' . sprintf(
3506
+ $fix_issue_desc,
3507
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3508
+ )
3509
+ ),
3510
+ sprintf(
3511
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3512
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3513
+ $install_previous_title,
3514
+ $install_previous_desc
3515
+ ),
3516
+ sprintf(
3517
+ '<a href="%s"><b>%s</b></a> - %s',
3518
+ 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 ),
3519
+ $deactivate_plugin_title,
3520
+ $deactivate_plugin_desc
3521
+ )
3522
+ )
3523
+ );
3524
+ break;
3525
+ case 'squid_cache_block':
3526
+ $message = sprintf(
3527
+ $x_requires_access_to_api . ' ' .
3528
+ $this->esc_html_inline( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'squid-blocks-connection-message' ) .
3529
+ ' %s',
3530
+ '<b>' . $this->get_plugin_name() . '</b>',
3531
+ sprintf(
3532
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3533
+ sprintf(
3534
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a> - %s',
3535
+ $this->esc_html_inline( 'I don\'t know what is Squid or ACL, help me!', 'squid-no-clue-title' ),
3536
+ sprintf(
3537
+ $this->esc_html_inline( '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.', 'squid-no-clue-desc' ),
3538
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3539
+ )
3540
+ ),
3541
+ sprintf(
3542
+ '<b>%s</b> - %s',
3543
+ $sysadmin_title,
3544
+ sprintf(
3545
+ $this->esc_html_inline( 'Great, please whitelist the following domains: %s. Once you are done, deactivate the %s and activate it again.', 'squid-sysadmin-desc' ),
3546
+ // We use a filter since the plugin might require additional API connectivity.
3547
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array(
3548
+ 'api.freemius.com',
3549
+ 'wp.freemius.com'
3550
+ ) ) ) . '</b>',
3551
+ $this->_module_type
3552
+ )
3553
+ ),
3554
+ sprintf(
3555
+ '<a href="%s"><b>%s</b></a> - %s',
3556
+ 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 ),
3557
+ $deactivate_plugin_title,
3558
+ $deactivate_plugin_desc
3559
+ )
3560
+ )
3561
+ );
3562
+ break;
3563
+ // default:
3564
+ // $message = $this->get_text_inline( 'connectivity-test-fails-message' );
3565
+ // break;
3566
+ }
3567
+ }
3568
+
3569
+ $message_id = 'failed_connect_api';
3570
+ $type = 'error';
3571
+
3572
+ $connectivity_test_fails_message = $this->esc_html_inline( 'From unknown reason, the API connectivity test failed.', 'connectivity-test-fails-message' );
3573
+
3574
+ if ( false === $message ) {
3575
+ if ( $is_first_failure ) {
3576
+ // First attempt failed.
3577
+ $message = sprintf(
3578
+ $x_requires_access_to_api . ' ' .
3579
+ $connectivity_test_fails_message . ' ' .
3580
+ $this->esc_html_inline( '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?', 'connectivity-test-maybe-temporary' ) . '<br><br>' .
3581
+ '%s',
3582
+ '<b>' . $this->get_plugin_name() . '</b>',
3583
+ sprintf(
3584
+ '<div id="fs_firewall_issue_options">%s %s</div>',
3585
+ sprintf(
3586
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
3587
+ $this->get_text_inline( 'Yes - do your thing', 'yes-do-your-thing' )
3588
+ ),
3589
+ sprintf(
3590
+ '<a href="%s" class="button">%s</a>',
3591
+ 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 ),
3592
+ $this->get_text_inline( 'No - just deactivate', 'no-deactivate' )
3593
+ )
3594
+ )
3595
+ );
3596
+
3597
+ $message_id = 'failed_connect_api_first';
3598
+ $type = 'promotion';
3599
+ } else {
3600
+ // Second connectivity attempt failed.
3601
+ $message = sprintf(
3602
+ $x_requires_access_to_api . ' ' .
3603
+ $connectivity_test_fails_message . ' ' .
3604
+ $happy_to_resolve_issue_asap .
3605
+ ' %s',
3606
+ '<b>' . $this->get_plugin_name() . '</b>',
3607
+ sprintf(
3608
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
3609
+ sprintf(
3610
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
3611
+ $fix_issue_title,
3612
+ ' - ' . sprintf(
3613
+ $fix_issue_desc,
3614
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3615
+ )
3616
+ ),
3617
+ sprintf(
3618
+ '<a href="%s" target="_blank"><b>%s</b></a> - %s',
3619
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
3620
+ $install_previous_title,
3621
+ $install_previous_desc
3622
+ ),
3623
+ sprintf(
3624
+ '<a href="%s"><b>%s</b></a> - %s',
3625
+ 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 ),
3626
+ $deactivate_plugin_title,
3627
+ $deactivate_plugin_desc
3628
+ )
3629
+ )
3630
+ );
3631
+ }
3632
+ }
3633
+
3634
+ $this->_admin_notices->add_sticky(
3635
+ $message,
3636
+ $message_id,
3637
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
3638
+ $type
3639
+ );
3640
+ }
3641
+
3642
+ /**
3643
+ * Handle user request to resolve connectivity issue.
3644
+ * This method will send an email to Freemius API technical staff for resolution.
3645
+ * The email will contain server's info and installed plugins (might be caching issue).
3646
+ *
3647
+ * @author Vova Feldman (@svovaf)
3648
+ * @since 1.0.9
3649
+ */
3650
+ function _email_about_firewall_issue() {
3651
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
3652
+
3653
+ $pong = $this->ping();
3654
+
3655
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3656
+
3657
+ if ( $is_connected ) {
3658
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3659
+
3660
+ $this->store_connectivity_info( $pong, $is_connected );
3661
+
3662
+ echo $this->get_after_plugin_activation_redirect_url();
3663
+ exit;
3664
+ }
3665
+
3666
+ $current_user = self::_get_current_wp_user();
3667
+ $admin_email = $current_user->user_email;
3668
+
3669
+ $error_type = fs_request_get( 'error_type', 'general' );
3670
+
3671
+ switch ( $error_type ) {
3672
+ case 'squid':
3673
+ $title = 'Squid ACL Blocking Issue';
3674
+ break;
3675
+ case 'cloudflare':
3676
+ $title = 'CloudFlare Blocking Issue';
3677
+ break;
3678
+ default:
3679
+ $title = 'API Connectivity Issue';
3680
+ break;
3681
+ }
3682
+
3683
+ $custom_email_sections = array();
3684
+
3685
+ // Add 'API Error' custom email section.
3686
+ $custom_email_sections['api_error'] = array(
3687
+ 'title' => 'API Error',
3688
+ 'rows' => array(
3689
+ 'ping' => array(
3690
+ 'API Error',
3691
+ is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong )
3692
+ ),
3693
+ )
3694
+ );
3695
+
3696
+ // Send email with technical details to resolve API connectivity issues.
3697
+ $this->send_email(
3698
+ 'api@freemius.com', // recipient
3699
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
3700
+ $custom_email_sections,
3701
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
3702
+ );
3703
+
3704
+ $this->_admin_notices->add_sticky(
3705
+ sprintf(
3706
+ $this->get_text_inline( '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.', 'fix-request-sent-message' ),
3707
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
3708
+ ),
3709
+ 'server_details_sent'
3710
+ );
3711
+
3712
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
3713
+
3714
+ echo "1";
3715
+ exit;
3716
+ }
3717
+
3718
+ /**
3719
+ * Handle connectivity test retry approved by the user.
3720
+ *
3721
+ * @author Vova Feldman (@svovaf)
3722
+ * @since 1.1.7.4
3723
+ */
3724
+ function _retry_connectivity_test() {
3725
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
3726
+
3727
+ $pong = $this->ping();
3728
+
3729
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
3730
+
3731
+ if ( $is_connected ) {
3732
+ FS_GDPR_Manager::instance()->store_is_required( $pong->is_gdpr_required );
3733
+
3734
+ $this->store_connectivity_info( $pong, $is_connected );
3735
+
3736
+ echo $this->get_after_plugin_activation_redirect_url();
3737
+ } else {
3738
+ // Add connectivity issue message after 2nd failed attempt.
3739
+ $this->_add_connectivity_issue_message( $pong, false );
3740
+
3741
+ echo "1";
3742
+ }
3743
+
3744
+ exit;
3745
+ }
3746
+
3747
+ static function _add_firewall_issues_javascript() {
3748
+ $params = array();
3749
+ fs_require_once_template( 'firewall-issues-js.php', $params );
3750
+ }
3751
+
3752
+ #endregion
3753
+
3754
+ #----------------------------------------------------------------------------------
3755
+ #region Email
3756
+ #----------------------------------------------------------------------------------
3757
+
3758
+ /**
3759
+ * Generates and sends an HTML email with customizable sections.
3760
+ *
3761
+ * @author Leo Fajardo (@leorw)
3762
+ * @since 1.1.2
3763
+ *
3764
+ * @param string $to_address
3765
+ * @param string $subject
3766
+ * @param array $sections
3767
+ * @param array $headers
3768
+ *
3769
+ * @return bool Whether the email contents were sent successfully.
3770
+ */
3771
+ private function send_email(
3772
+ $to_address,
3773
+ $subject,
3774
+ $sections = array(),
3775
+ $headers = array()
3776
+ ) {
3777
+ $default_sections = $this->get_email_sections();
3778
+
3779
+ // Insert new sections or replace the default email sections.
3780
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
3781
+ foreach ( $sections as $section_id => $custom_section ) {
3782
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
3783
+ // If the section does not exist, add it.
3784
+ $default_sections[ $section_id ] = $custom_section;
3785
+ } else {
3786
+ // If the section already exists, override it.
3787
+ $current_section = $default_sections[ $section_id ];
3788
+
3789
+ // Replace the current section's title if a custom section title exists.
3790
+ if ( isset( $custom_section['title'] ) ) {
3791
+ $current_section['title'] = $custom_section['title'];
3792
+ }
3793
+
3794
+ // Insert new rows under the current section or replace the default rows.
3795
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
3796
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
3797
+ $current_section['rows'][ $row_id ] = $row;
3798
+ }
3799
+ }
3800
+
3801
+ $default_sections[ $section_id ] = $current_section;
3802
+ }
3803
+ }
3804
+ }
3805
+
3806
+ $vars = array( 'sections' => $default_sections );
3807
+ $message = fs_get_template( 'email.php', $vars );
3808
+
3809
+ // Set the type of email to HTML.
3810
+ $headers[] = 'Content-type: text/html; charset=UTF-8';
3811
+
3812
+ $header_string = implode( "\r\n", $headers );
3813
+
3814
+ return wp_mail(
3815
+ $to_address,
3816
+ $subject,
3817
+ $message,
3818
+ $header_string
3819
+ );
3820
+ }
3821
+
3822
+ /**
3823
+ * Generates the data for the sections of the email content.
3824
+ *
3825
+ * @author Leo Fajardo (@leorw)
3826
+ * @since 1.1.2
3827
+ *
3828
+ * @return array
3829
+ */
3830
+ private function get_email_sections() {
3831
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
3832
+ $current_user = self::_get_current_wp_user();
3833
+
3834
+ // Retrieve the cURL version information so that we can get the version number below.
3835
+ $curl_version_information = curl_version();
3836
+
3837
+ $active_plugin = self::get_active_plugins();
3838
+
3839
+ // Generate the list of active plugins separated by new line.
3840
+ $active_plugin_string = '';
3841
+ foreach ( $active_plugin as $plugin ) {
3842
+ $active_plugin_string .= sprintf(
3843
+ '<a href="%s">%s</a> [v%s]<br>',
3844
+ $plugin['PluginURI'],
3845
+ $plugin['Name'],
3846
+ $plugin['Version']
3847
+ );
3848
+ }
3849
+
3850
+ $server_ip = WP_FS__REMOTE_ADDR;
3851
+
3852
+ // Add PHP info for deeper investigation.
3853
+ ob_start();
3854
+ phpinfo();
3855
+ $php_info = ob_get_clean();
3856
+
3857
+ $api_domain = substr( FS_API__ADDRESS, strpos( FS_API__ADDRESS, ':' ) + 3 );
3858
+
3859
+ // Generate the default email sections.
3860
+ $sections = array(
3861
+ 'sdk' => array(
3862
+ 'title' => 'SDK',
3863
+ 'rows' => array(
3864
+ 'fs_version' => array( 'FS Version', $this->version ),
3865
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
3866
+ )
3867
+ ),
3868
+ 'plugin' => array(
3869
+ 'title' => ucfirst( $this->get_module_type() ),
3870
+ 'rows' => array(
3871
+ 'name' => array( 'Name', $this->get_plugin_name() ),
3872
+ 'version' => array( 'Version', $this->get_plugin_version() )
3873
+ )
3874
+ ),
3875
+ 'api' => array(
3876
+ 'title' => 'API Subdomain',
3877
+ 'rows' => array(
3878
+ 'dns' => array(
3879
+ 'DNS_CNAME',
3880
+ function_exists( 'dns_get_record' ) ?
3881
+ var_export( dns_get_record( $api_domain, DNS_CNAME ), true ) :
3882
+ 'dns_get_record() disabled/blocked'
3883
+ ),
3884
+ 'ip' => array(
3885
+ 'IP',
3886
+ function_exists( 'gethostbyname' ) ?
3887
+ gethostbyname( $api_domain ) :
3888
+ 'gethostbyname() disabled/blocked'
3889
+ ),
3890
+ ),
3891
+ ),
3892
+ 'site' => array(
3893
+ 'title' => 'Site',
3894
+ 'rows' => array(
3895
+ 'unique_id' => array( 'Unique ID', $this->get_anonymous_id() ),
3896
+ 'address' => array( 'Address', site_url() ),
3897
+ 'host' => array(
3898
+ 'HTTP_HOST',
3899
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
3900
+ ),
3901
+ 'hosting' => array(
3902
+ 'Hosting Company' => fs_request_has( 'hosting_company' ) ?
3903
+ fs_request_get( 'hosting_company' ) :
3904
+ 'Unknown',
3905
+ ),
3906
+ 'server_addr' => array(
3907
+ 'SERVER_ADDR',
3908
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
3909
+ )
3910
+ )
3911
+ ),
3912
+ 'user' => array(
3913
+ 'title' => 'User',
3914
+ 'rows' => array(
3915
+ 'email' => array( 'Email', $current_user->user_email ),
3916
+ 'first' => array( 'First', $current_user->user_firstname ),
3917
+ 'last' => array( 'Last', $current_user->user_lastname )
3918
+ )
3919
+ ),
3920
+ 'plugins' => array(
3921
+ 'title' => 'Plugins',
3922
+ 'rows' => array(
3923
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
3924
+ )
3925
+ ),
3926
+ 'php_info' => array(
3927
+ 'title' => 'PHP Info',
3928
+ 'rows' => array(
3929
+ 'info' => array( $php_info )
3930
+ ),
3931
+ )
3932
+ );
3933
+
3934
+ // Allow the sections to be modified by other code.
3935
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
3936
+
3937
+ return $sections;
3938
+ }
3939
+
3940
+ #endregion
3941
+
3942
+ #----------------------------------------------------------------------------------
3943
+ #region Initialization
3944
+ #----------------------------------------------------------------------------------
3945
+
3946
+ /**
3947
+ * Init plugin's Freemius instance.
3948
+ *
3949
+ * @author Vova Feldman (@svovaf)
3950
+ * @since 1.0.1
3951
+ *
3952
+ * @param number $id
3953
+ * @param string $public_key
3954
+ * @param bool $is_live
3955
+ * @param bool $is_premium
3956
+ */
3957
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
3958
+ $this->_logger->entrance();
3959
+
3960
+ $this->dynamic_init( array(
3961
+ 'id' => $id,
3962
+ 'public_key' => $public_key,
3963
+ 'is_live' => $is_live,
3964
+ 'is_premium' => $is_premium,
3965
+ ) );
3966
+ }
3967
+
3968
+ /**
3969
+ * Dynamic initiator, originally created to support initiation
3970
+ * with parent_id for add-ons.
3971
+ *
3972
+ * @author Vova Feldman (@svovaf)
3973
+ * @since 1.0.6
3974
+ *
3975
+ * @param array $plugin_info
3976
+ *
3977
+ * @throws Freemius_Exception
3978
+ */
3979
+ function dynamic_init( array $plugin_info ) {
3980
+ $this->_logger->entrance();
3981
+
3982
+ $this->parse_settings( $plugin_info );
3983
+
3984
+ if ( is_admin() && $this->is_theme() && $this->is_premium() && ! $this->has_active_valid_license() ) {
3985
+ $this->add_ajax_action(
3986
+ 'delete_theme_update_data',
3987
+ array( &$this, '_delete_theme_update_data_action' )
3988
+ );
3989
+ }
3990
+
3991
+ if ( ! self::is_ajax() ) {
3992
+ if ( ! $this->is_addon() || $this->is_only_premium() ) {
3993
+ add_action(
3994
+ ( $this->_is_network_active && fs_is_network_admin() ? 'network_' : '' ) . 'admin_menu',
3995
+ array( &$this, '_prepare_admin_menu' ),
3996
+ WP_FS__LOWEST_PRIORITY
3997
+ );
3998
+ }
3999
+ }
4000
+
4001
+ if ( $this->should_stop_execution() ) {
4002
+ return;
4003
+ }
4004
+
4005
+ if ( ! $this->is_registered() ) {
4006
+ if ( $this->is_anonymous() ) {
4007
+ // If user skipped, no need to test connectivity.
4008
+ $this->_has_api_connection = true;
4009
+ $this->_is_on = true;
4010
+ } else {
4011
+ if ( ! $this->has_api_connectivity() ) {
4012
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
4013
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
4014
+ ) {
4015
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
4016
+ // If anonymous mode is disabled, add firewall admin-notice message.
4017
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
4018
+
4019
+ $ajax_action_suffix = $this->_slug . ( $this->is_theme() ? ':theme' : '' );
4020
+ add_action( "wp_ajax_fs_resolve_firewall_issues_{$ajax_action_suffix}", array(
4021
+ &$this,
4022
+ '_email_about_firewall_issue'
4023
+ ) );
4024
+
4025
+ add_action( "wp_ajax_fs_retry_connectivity_test_{$ajax_action_suffix}", array(
4026
+ &$this,
4027
+ '_retry_connectivity_test'
4028
+ ) );
4029
+
4030
+ /**
4031
+ * Currently the admin notice manager relies on the module's type and slug. The new AJAX actions manager uses module IDs, hence, consider to replace the if block above with the commented code below after adjusting the admin notices manager to work with module IDs.
4032
+ *
4033
+ * @author Vova Feldman (@svovaf)
4034
+ * @since 2.0.0
4035
+ */
4036
+ /*$this->add_ajax_action( 'resolve_firewall_issues', array(
4037
+ &$this,
4038
+ '_email_about_firewall_issue'
4039
+ ) );
4040
+
4041
+ $this->add_ajax_action( 'retry_connectivity_test', array(
4042
+ &$this,
4043
+ '_retry_connectivity_test'
4044
+ ) );*/
4045
+ }
4046
+ }
4047
+
4048
+ return;
4049
+ } else {
4050
+ $this->_admin_notices->remove_sticky( array(
4051
+ 'failed_connect_api_first',
4052
+ 'failed_connect_api',
4053
+ ) );
4054
+
4055
+ if ( $this->_anonymous_mode ) {
4056
+ // Simulate anonymous mode.
4057
+ $this->_is_anonymous = true;
4058
+ }
4059
+ }
4060
+ }
4061
+ }
4062
+
4063
+ /**
4064
+ * This should be executed even if Freemius is off for the core module,
4065
+ * otherwise, the add-ons dialogbox won't work properly. This is esepcially
4066
+ * relevant when the developer decided to turn FS off for existing users.
4067
+ *
4068
+ * @author Vova Feldman (@svovaf)
4069
+ */
4070
+ if ( $this->is_user_in_admin() &&
4071
+ ! $this->is_addon() &&
4072
+ $this->has_addons() &&
4073
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
4074
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
4075
+ ) {
4076
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
4077
+
4078
+ new FS_Plugin_Info_Dialog( $this );
4079
+ }
4080
+
4081
+ // Check if Freemius is on for the current plugin.
4082
+ // This MUST be executed after all the plugin variables has been loaded.
4083
+ if ( ! $this->is_registered() && ! $this->is_on() ) {
4084
+ return;
4085
+ }
4086
+
4087
+ if ( $this->has_api_connectivity() ) {
4088
+ if ( self::is_cron() ) {
4089
+ $this->hook_callback_to_sync_cron();
4090
+ } else if ( $this->is_user_in_admin() ) {
4091
+ /**
4092
+ * Schedule daily data sync cron if:
4093
+ *
4094
+ * 1. User opted-in (for tracking).
4095
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
4096
+ *
4097
+ * @author Vova Feldman (@svovaf)
4098
+ * @since 1.1.7.3
4099
+ *
4100
+ */
4101
+ if ( $this->is_registered() ) {
4102
+ if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
4103
+ $this->schedule_sync_cron();
4104
+ }
4105
+ }
4106
+
4107
+ /**
4108
+ * Check if requested for manual blocking background sync.
4109
+ */
4110
+ if ( fs_request_has( 'background_sync' ) ) {
4111
+ $this->run_manual_sync();
4112
+ }
4113
+ }
4114
+ }
4115
+
4116
+ if ( $this->is_registered() ) {
4117
+ $this->hook_callback_to_install_sync();
4118
+ }
4119
+
4120
+ if ( $this->is_addon() ) {
4121
+ if ( $this->is_parent_plugin_installed() ) {
4122
+ // Link to parent FS.
4123
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
4124
+
4125
+ // Get parent plugin reference.
4126
+ $this->_parent_plugin = $this->_parent->get_plugin();
4127
+ }
4128
+ }
4129
+
4130
+ if ( $this->is_user_in_admin() ) {
4131
+ if ( $this->is_addon() ) {
4132
+ if ( ! $this->is_parent_plugin_installed() ) {
4133
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4134
+
4135
+ if ( isset( $plugin_info['parent'] ) ) {
4136
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4137
+ }
4138
+
4139
+ $this->_admin_notices->add(
4140
+ ( ! empty( $parent_name ) ?
4141
+ sprintf( $this->get_text_x_inline( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'addon-x-cannot-run-without-y' ), $this->get_plugin_name(), $parent_name ) :
4142
+ sprintf( $this->get_text_x_inline( '%s cannot run without the plugin.', 'addonX cannot run...', 'addon-x-cannot-run-without-parent' ), $this->get_plugin_name() )
4143
+ ),
4144
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
4145
+ 'error'
4146
+ );
4147
+
4148
+ return;
4149
+ } else {
4150
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
4151
+ // If parent plugin activated, automatically install add-on for the user.
4152
+ $this->_activate_addon_account( $this->_parent );
4153
+ } else if ( ! $this->_parent->is_registered() && $this->is_registered() ) {
4154
+ // If add-on activated and parent not, automatically install parent for the user.
4155
+ $this->activate_parent_account( $this->_parent );
4156
+ }
4157
+
4158
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
4159
+ if ( $this->is_premium() ) {
4160
+ // Remove add-on download admin-notice.
4161
+ $this->_parent->_admin_notices->remove_sticky( array(
4162
+ 'addon_plan_upgraded_' . $this->_slug,
4163
+ 'no_addon_license_' . $this->_slug,
4164
+ ) );
4165
+ }
4166
+
4167
+ // $this->deactivate_premium_only_addon_without_license();
4168
+ }
4169
+ }
4170
+
4171
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
4172
+
4173
+ // if ( $this->is_registered() ||
4174
+ // $this->is_anonymous() ||
4175
+ // $this->is_pending_activation()
4176
+ // ) {
4177
+ // $this->_init_admin();
4178
+ // }
4179
+ }
4180
+
4181
+ /**
4182
+ * Should be called outside `$this->is_user_in_admin()` scope
4183
+ * because the updater has some logic that needs to be executed
4184
+ * during AJAX calls.
4185
+ *
4186
+ * Currently we need to hook to the `http_request_host_is_external` filter.
4187
+ * In the future, there might be additional logic added.
4188
+ *
4189
+ * @author Vova Feldman
4190
+ * @since 1.2.1.6
4191
+ */
4192
+ if ( $this->is_premium() && $this->has_release_on_freemius() ) {
4193
+ FS_Plugin_Updater::instance( $this );
4194
+ }
4195
+
4196
+ $this->do_action( 'initiated' );
4197
+
4198
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
4199
+ if ( isset( $this->_storage->prev_is_premium ) ) {
4200
+ $this->apply_filters(
4201
+ 'after_code_type_change',
4202
+ // New code type.
4203
+ $this->_plugin->is_premium
4204
+ );
4205
+ } else {
4206
+ // Set for code type for the first time.
4207
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4208
+ }
4209
+ }
4210
+
4211
+ if ( ! $this->is_addon() ) {
4212
+ if ( $this->is_registered() ) {
4213
+ // Fix for upgrade from versions < 1.0.9.
4214
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
4215
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
4216
+ }
4217
+
4218
+ $this->do_action( 'after_init_plugin_registered' );
4219
+ } else if ( $this->is_anonymous() ) {
4220
+ $this->do_action( 'after_init_plugin_anonymous' );
4221
+ } else if ( $this->is_pending_activation() ) {
4222
+ $this->do_action( 'after_init_plugin_pending_activations' );
4223
+ }
4224
+ } else {
4225
+ if ( $this->is_registered() ) {
4226
+ $this->do_action( 'after_init_addon_registered' );
4227
+ } else if ( $this->is_anonymous() ) {
4228
+ $this->do_action( 'after_init_addon_anonymous' );
4229
+ } else if ( $this->is_pending_activation() ) {
4230
+ $this->do_action( 'after_init_addon_pending_activations' );
4231
+ }
4232
+ }
4233
+ }
4234
+
4235
+ /**
4236
+ * @author Leo Fajardo (@leorw)
4237
+ *
4238
+ * @since 1.2.1.5
4239
+ */
4240
+ function _stop_tracking_callback() {
4241
+ $this->_logger->entrance();
4242
+
4243
+ $this->check_ajax_referer( 'stop_tracking' );
4244
+
4245
+ $result = $this->stop_tracking( fs_is_network_admin() );
4246
+
4247
+ if ( true === $result ) {
4248
+ self::shoot_ajax_success();
4249
+ }
4250
+
4251
+ $this->_logger->api_error( $result );
4252
+
4253
+ self::shoot_ajax_failure(
4254
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4255
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4256
+ $result->error->message :
4257
+ var_export( $result, true ) )
4258
+ );
4259
+ }
4260
+
4261
+ /**
4262
+ * @author Leo Fajardo (@leorw)
4263
+ * @since 1.2.1.5
4264
+ */
4265
+ function _allow_tracking_callback() {
4266
+ $this->_logger->entrance();
4267
+
4268
+ $this->check_ajax_referer( 'allow_tracking' );
4269
+
4270
+ $result = $this->allow_tracking( fs_is_network_admin() );
4271
+
4272
+ if ( true === $result ) {
4273
+ self::shoot_ajax_success();
4274
+ }
4275
+
4276
+ $this->_logger->api_error( $result );
4277
+
4278
+ self::shoot_ajax_failure(
4279
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type ) .
4280
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
4281
+ $result->error->message :
4282
+ var_export( $result, true ) )
4283
+ );
4284
+ }
4285
+
4286
+ /**
4287
+ * Opt-out from usage tracking.
4288
+ *
4289
+ * Note: This will not delete the account information but will stop all tracking.
4290
+ *
4291
+ * Returns:
4292
+ * 1. FALSE - If the user never opted-in.
4293
+ * 2. TRUE - If successfully opted-out.
4294
+ * 3. object - API result on failure.
4295
+ *
4296
+ * @author Leo Fajardo (@leorw)
4297
+ * @since 1.2.1.5
4298
+ *
4299
+ * @return bool|object
4300
+ */
4301
+ function stop_site_tracking() {
4302
+ $this->_logger->entrance();
4303
+
4304
+ if ( ! $this->is_registered() ) {
4305
+ // User never opted-in.
4306
+ return false;
4307
+ }
4308
+
4309
+ if ( $this->is_tracking_prohibited() ) {
4310
+ // Already disconnected.
4311
+ return true;
4312
+ }
4313
+
4314
+ // Send update to FS.
4315
+ $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
4316
+ 'is_disconnected' => true
4317
+ ) );
4318
+
4319
+ if ( ! $this->is_api_result_entity( $result ) ||
4320
+ ! isset( $result->is_disconnected ) ||
4321
+ ! $result->is_disconnected
4322
+ ) {
4323
+ $this->_logger->api_error( $result );
4324
+
4325
+ return $result;
4326
+ }
4327
+
4328
+ $this->_site->is_disconnected = $result->is_disconnected;
4329
+ $this->_store_site();
4330
+
4331
+ $this->clear_sync_cron();
4332
+
4333
+ // Successfully disconnected.
4334
+ return true;
4335
+ }
4336
+
4337
+ /**
4338
+ * Opt-out network from usage tracking.
4339
+ *
4340
+ * Note: This will not delete the account information but will stop all tracking.
4341
+ *
4342
+ * Returns:
4343
+ * 1. FALSE - If the user never opted-in.
4344
+ * 2. TRUE - If successfully opted-out.
4345
+ * 3. object - API result on failure.
4346
+ *
4347
+ * @author Leo Fajardo (@leorw)
4348
+ * @since 1.2.1.5
4349
+ *
4350
+ * @return bool|object
4351
+ */
4352
+ function stop_network_tracking() {
4353
+ $this->_logger->entrance();
4354
+
4355
+ if ( ! $this->is_registered() ) {
4356
+ // User never opted-in.
4357
+ return false;
4358
+ }
4359
+
4360
+ $install_id_2_blog_id = array();
4361
+ $installs_map = $this->get_blog_install_map();
4362
+
4363
+ $opt_out_all = true;
4364
+
4365
+ $params = array();
4366
+ foreach ( $installs_map as $blog_id => $install ) {
4367
+ if ( $install->is_tracking_prohibited() ) {
4368
+ // Already opted-out.
4369
+ continue;
4370
+ }
4371
+
4372
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
4373
+ // Opt-out only from non-delegated installs.
4374
+ $opt_out_all = false;
4375
+ continue;
4376
+ }
4377
+
4378
+ $params[] = array( 'id' => $install->id );
4379
+
4380
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4381
+ }
4382
+
4383
+ if ( empty( $install_id_2_blog_id ) ) {
4384
+ return true;
4385
+ }
4386
+
4387
+ $params[] = array( 'is_disconnected' => true );
4388
+
4389
+ // Send update to FS.
4390
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4391
+
4392
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4393
+ $this->_logger->api_error( $result );
4394
+
4395
+ return $result;
4396
+ }
4397
+
4398
+ foreach ( $result->installs as $r_install ) {
4399
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4400
+ $install = $installs_map[ $blog_id ];
4401
+ $install->is_disconnected = $r_install->is_disconnected;
4402
+ $this->_store_site( true, $blog_id, $install );
4403
+ }
4404
+
4405
+ $this->clear_sync_cron( $opt_out_all );
4406
+
4407
+ // Successfully disconnected.
4408
+ return true;
4409
+ }
4410
+
4411
+ /**
4412
+ * Opt-out from usage tracking.
4413
+ *
4414
+ * Note: This will not delete the account information but will stop all tracking.
4415
+ *
4416
+ * Returns:
4417
+ * 1. FALSE - If the user never opted-in.
4418
+ * 2. TRUE - If successfully opted-out.
4419
+ * 3. object - API result on failure.
4420
+ *
4421
+ * @author Leo Fajardo (@leorw)
4422
+ * @since 1.2.1.5
4423
+ *
4424
+ * @param bool $is_network_action
4425
+ *
4426
+ * @return bool|object
4427
+ */
4428
+ function stop_tracking( $is_network_action = false ) {
4429
+ $this->_logger->entrance();
4430
+
4431
+ return $is_network_action ?
4432
+ $this->stop_network_tracking() :
4433
+ $this->stop_site_tracking();
4434
+ }
4435
+
4436
+ /**
4437
+ * Opt-in back into usage tracking.
4438
+ *
4439
+ * Note: This will only work if the user opted-in previously.
4440
+ *
4441
+ * Returns:
4442
+ * 1. FALSE - If the user never opted-in.
4443
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4444
+ * 3. object - API result on failure.
4445
+ *
4446
+ * @author Leo Fajardo (@leorw)
4447
+ * @since 1.2.1.5
4448
+ *
4449
+ * @return bool|object
4450
+ */
4451
+ function allow_site_tracking() {
4452
+ $this->_logger->entrance();
4453
+
4454
+ if ( ! $this->is_registered() ) {
4455
+ // User never opted-in.
4456
+ return false;
4457
+ }
4458
+
4459
+ if ( $this->is_tracking_allowed() ) {
4460
+ // Tracking already allowed.
4461
+ return true;
4462
+ }
4463
+
4464
+ $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
4465
+ 'is_disconnected' => false
4466
+ ) );
4467
+
4468
+ if ( ! $this->is_api_result_entity( $result ) ||
4469
+ ! isset( $result->is_disconnected ) ||
4470
+ $result->is_disconnected
4471
+ ) {
4472
+ $this->_logger->api_error( $result );
4473
+
4474
+ return $result;
4475
+ }
4476
+
4477
+ $this->_site->is_disconnected = $result->is_disconnected;
4478
+ $this->_store_site();
4479
+
4480
+ $this->schedule_sync_cron();
4481
+
4482
+ // Successfully reconnected.
4483
+ return true;
4484
+ }
4485
+
4486
+ /**
4487
+ * Opt-in network back into usage tracking.
4488
+ *
4489
+ * Note: This will only work if the user opted-in previously.
4490
+ *
4491
+ * Returns:
4492
+ * 1. FALSE - If the user never opted-in.
4493
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4494
+ * 3. object - API result on failure.
4495
+ *
4496
+ * @author Leo Fajardo (@leorw)
4497
+ * @since 1.2.1.5
4498
+ *
4499
+ * @return bool|object
4500
+ */
4501
+ function allow_network_tracking() {
4502
+ $this->_logger->entrance();
4503
+
4504
+ if ( ! $this->is_registered() ) {
4505
+ // User never opted-in.
4506
+ return false;
4507
+ }
4508
+
4509
+ $install_id_2_blog_id = array();
4510
+ $installs_map = $this->get_blog_install_map();
4511
+
4512
+ $params = array();
4513
+ foreach ( $installs_map as $blog_id => $install ) {
4514
+ if ( $install->is_tracking_allowed() ) {
4515
+ continue;
4516
+ }
4517
+
4518
+ $params[] = array( 'id' => $install->id );
4519
+
4520
+ $install_id_2_blog_id[ $install->id ] = $blog_id;
4521
+ }
4522
+
4523
+ if ( empty( $install_id_2_blog_id ) ) {
4524
+ return true;
4525
+ }
4526
+
4527
+ $params[] = array( 'is_disconnected' => false );
4528
+
4529
+ // Send update to FS.
4530
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json", 'put', $params );
4531
+
4532
+
4533
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
4534
+ $this->_logger->api_error( $result );
4535
+
4536
+ return $result;
4537
+ }
4538
+
4539
+ foreach ( $result->installs as $r_install ) {
4540
+ $blog_id = $install_id_2_blog_id[ $r_install->id ];
4541
+ $install = $installs_map[ $blog_id ];
4542
+ $install->is_disconnected = $r_install->is_disconnected;
4543
+ $this->_store_site( true, $blog_id, $install );
4544
+ }
4545
+
4546
+ $this->schedule_sync_cron();
4547
+
4548
+ // Successfully reconnected.
4549
+ return true;
4550
+ }
4551
+
4552
+ /**
4553
+ * Opt-in back into usage tracking.
4554
+ *
4555
+ * Note: This will only work if the user opted-in previously.
4556
+ *
4557
+ * Returns:
4558
+ * 1. FALSE - If the user never opted-in.
4559
+ * 2. TRUE - If successfully opted-in back to usage tracking.
4560
+ * 3. object - API result on failure.
4561
+ *
4562
+ * @author Leo Fajardo (@leorw)
4563
+ * @since 1.2.1.5
4564
+ *
4565
+ * @param bool $is_network_action
4566
+ *
4567
+ * @return bool|object
4568
+ */
4569
+ function allow_tracking( $is_network_action = false ) {
4570
+ $this->_logger->entrance();
4571
+
4572
+ return $is_network_action ?
4573
+ $this->allow_network_tracking() :
4574
+ $this->allow_site_tracking();
4575
+ }
4576
+
4577
+ /**
4578
+ * If user opted-in and later disabled usage-tracking,
4579
+ * re-allow tracking for licensing and updates.
4580
+ *
4581
+ * @author Leo Fajardo (@leorw)
4582
+ * @since 1.2.1.5
4583
+ *
4584
+ * @param bool $is_context_single_site
4585
+ */
4586
+ private function reconnect_locally( $is_context_single_site = false ) {
4587
+ $this->_logger->entrance();
4588
+
4589
+ if ( ! $this->is_registered() ) {
4590
+ return;
4591
+ }
4592
+
4593
+ if ( ! fs_is_network_admin() || $is_context_single_site ) {
4594
+ if ( $this->is_tracking_prohibited() ) {
4595
+ $this->_site->is_disconnected = false;
4596
+ $this->_store_site();
4597
+ }
4598
+ } else {
4599
+ $installs_map = $this->get_blog_install_map();
4600
+ foreach ( $installs_map as $blog_id => $install ) {
4601
+ /**
4602
+ * @var FS_Site $install
4603
+ */
4604
+ if ( $install->is_tracking_prohibited() ) {
4605
+ $install->is_disconnected = false;
4606
+ $this->_store_site( true, $blog_id, $install );
4607
+ }
4608
+ }
4609
+ }
4610
+ }
4611
+
4612
+ /**
4613
+ * Parse plugin's settings (as defined by the plugin dev).
4614
+ *
4615
+ * @author Vova Feldman (@svovaf)
4616
+ * @since 1.1.7.3
4617
+ *
4618
+ * @param array $plugin_info
4619
+ *
4620
+ * @throws \Freemius_Exception
4621
+ */
4622
+ private function parse_settings( &$plugin_info ) {
4623
+ $this->_logger->entrance();
4624
+
4625
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
4626
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
4627
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
4628
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
4629
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
4630
+
4631
+ /**
4632
+ * @author Vova Feldman (@svovaf)
4633
+ * @since 1.1.9 Try to pull secret key from external config.
4634
+ */
4635
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
4636
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
4637
+ }
4638
+
4639
+ if ( isset( $plugin_info['parent'] ) ) {
4640
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
4641
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
4642
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
4643
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
4644
+ }
4645
+
4646
+ if ( false === $id ) {
4647
+ throw new Freemius_Exception( array(
4648
+ 'error' => array(
4649
+ 'type' => 'ParameterNotSet',
4650
+ 'message' => 'Plugin id parameter is not set.',
4651
+ 'code' => 'plugin_id_not_set',
4652
+ 'http' => 500,
4653
+ )
4654
+ ) );
4655
+ }
4656
+ if ( false === $public_key ) {
4657
+ throw new Freemius_Exception( array(
4658
+ 'error' => array(
4659
+ 'type' => 'ParameterNotSet',
4660
+ 'message' => 'Plugin public_key parameter is not set.',
4661
+ 'code' => 'plugin_public_key_not_set',
4662
+ 'http' => 500,
4663
+ )
4664
+ ) );
4665
+ }
4666
+
4667
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
4668
+ $this->_plugin :
4669
+ new FS_Plugin();
4670
+
4671
+ $plugin->update( array(
4672
+ 'id' => $id,
4673
+ 'type' => $this->get_option( $plugin_info, 'type', $this->_module_type ),
4674
+ 'public_key' => $public_key,
4675
+ 'slug' => $this->_slug,
4676
+ 'parent_plugin_id' => $parent_id,
4677
+ 'version' => $this->get_plugin_version(),
4678
+ 'title' => $this->get_plugin_name(),
4679
+ 'file' => $this->_plugin_basename,
4680
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
4681
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
4682
+ 'affiliate_moderation' => $this->get_option( $plugin_info, 'has_affiliation' ),
4683
+ ) );
4684
+
4685
+ if ( $plugin->is_updated() ) {
4686
+ // Update plugin details.
4687
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_module_id )->store( $plugin );
4688
+ }
4689
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
4690
+ $this->_plugin->secret_key = $secret_key;
4691
+
4692
+ if ( ! isset( $plugin_info['menu'] ) ) {
4693
+ $plugin_info['menu'] = array();
4694
+
4695
+ if ( ! empty( $this->_storage->sdk_last_version ) &&
4696
+ version_compare( $this->_storage->sdk_last_version, '1.1.2', '<=' )
4697
+ ) {
4698
+ // Backward compatibility to 1.1.2
4699
+ $plugin_info['menu']['slug'] = isset( $plugin_info['menu_slug'] ) ?
4700
+ $plugin_info['menu_slug'] :
4701
+ $this->_slug;
4702
+ }
4703
+ }
4704
+
4705
+ $this->_menu = FS_Admin_Menu_Manager::instance(
4706
+ $this->_module_id,
4707
+ $this->_module_type,
4708
+ $this->get_unique_affix()
4709
+ );
4710
+
4711
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
4712
+
4713
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
4714
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
4715
+ $this->_has_premium_version = $this->get_bool_option( $plugin_info, 'has_premium_version', $this->_has_paid_plans );
4716
+ $this->_ignore_pending_mode = $this->get_bool_option( $plugin_info, 'ignore_pending_mode', false );
4717
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
4718
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
4719
+ if ( $this->_is_premium_only ) {
4720
+ // If premium only plugin, disable anonymous mode.
4721
+ $this->_enable_anonymous = false;
4722
+ $this->_anonymous_mode = false;
4723
+ } else {
4724
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
4725
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
4726
+ }
4727
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
4728
+
4729
+ if ( ! empty( $plugin_info['trial'] ) ) {
4730
+ $this->_trial_days = $this->get_numeric_option(
4731
+ $plugin_info['trial'],
4732
+ 'days',
4733
+ // Default to 0 - trial without days specification.
4734
+ 0
4735
+ );
4736
+
4737
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
4738
+ }
4739
+ }
4740
+
4741
+ /**
4742
+ * @param string[] $options
4743
+ * @param string $key
4744
+ * @param mixed $default
4745
+ *
4746
+ * @return bool
4747
+ */
4748
+ private function get_option( &$options, $key, $default = false ) {
4749
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
4750
+ }
4751
+
4752
+ private function get_bool_option( &$options, $key, $default = false ) {
4753
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
4754
+ }
4755
+
4756
+ private function get_numeric_option( &$options, $key, $default = false ) {
4757
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
4758
+ }
4759
+
4760
+ /**
4761
+ * Gate keeper.
4762
+ *
4763
+ * @author Vova Feldman (@svovaf)
4764
+ * @since 1.1.7.3
4765
+ *
4766
+ * @return bool
4767
+ */
4768
+ private function should_stop_execution() {
4769
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
4770
+ /**
4771
+ * Don't execute Freemius until plugin was fully loaded at least once,
4772
+ * to give the opportunity for the activation hook to run before pinging
4773
+ * the API for connectivity test. This logic is relevant for the
4774
+ * identification of new plugin install vs. plugin update.
4775
+ *
4776
+ * @author Vova Feldman (@svovaf)
4777
+ * @since 1.1.9
4778
+ */
4779
+ return true;
4780
+ }
4781
+
4782
+ if ( $this->is_activation_mode() ) {
4783
+ if ( ! is_admin() ) {
4784
+ /**
4785
+ * If in activation mode, don't execute Freemius outside of the
4786
+ * admin dashboard.
4787
+ *
4788
+ * @author Vova Feldman (@svovaf)
4789
+ * @since 1.1.7.3
4790
+ */
4791
+ return true;
4792
+ }
4793
+
4794
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
4795
+ /**
4796
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
4797
+ * then don't start Freemius.
4798
+ *
4799
+ * @author Vova Feldman (@svovaf)
4800
+ * @since 1.1.6.3
4801
+ *
4802
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
4803
+ */
4804
+ return true;
4805
+ }
4806
+
4807
+ if ( self::is_cron() ) {
4808
+ /**
4809
+ * If in activation mode, don't execute Freemius during wp crons
4810
+ * (wp crons have HTTP context - called as HTTP request).
4811
+ *
4812
+ * @author Vova Feldman (@svovaf)
4813
+ * @since 1.1.7.3
4814
+ */
4815
+ return true;
4816
+ }
4817
+
4818
+ if ( self::is_ajax() &&
4819
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
4820
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
4821
+ ) {
4822
+ /**
4823
+ * During activation, if running in AJAX mode, unless there's a sticky
4824
+ * connectivity issue notice, don't run Freemius.
4825
+ *
4826
+ * @author Vova Feldman (@svovaf)
4827
+ * @since 1.1.7.3
4828
+ */
4829
+ return true;
4830
+ }
4831
+ }
4832
+
4833
+ return false;
4834
+ }
4835
+
4836
+ /**
4837
+ * Triggered after code type has changed.
4838
+ *
4839
+ * @author Vova Feldman (@svovaf)
4840
+ * @since 1.1.9.1
4841
+ */
4842
+ function _after_code_type_change() {
4843
+ $this->_logger->entrance();
4844
+
4845
+ if ( $this->is_theme() ) {
4846
+ // Expire the cache of the previous tabs since the theme may
4847
+ // have setting updates after code type has changed.
4848
+ $this->_cache->expire( 'tabs' );
4849
+ $this->_cache->expire( 'tabs_stylesheets' );
4850
+ }
4851
+
4852
+ if ( $this->is_registered() ) {
4853
+ if ( ! $this->is_addon() ) {
4854
+ add_action(
4855
+ is_admin() ? 'admin_init' : 'init',
4856
+ array( &$this, '_plugin_code_type_changed' )
4857
+ );
4858
+ }
4859
+
4860
+ if ( $this->is_premium() ) {
4861
+ // Purge cached payments after switching to the premium version.
4862
+ // @todo This logic doesn't handle purging the cache for serviceware module upgrade.
4863
+ $this->get_api_user_scope()->purge_cache( "/plugins/{$this->_module_id}/payments.json?include_addons=true" );
4864
+ }
4865
+ }
4866
+ }
4867
+
4868
+ /**
4869
+ * Handles plugin's code type change (free <--> premium).
4870
+ *
4871
+ * @author Vova Feldman (@svovaf)
4872
+ * @since 1.0.9
4873
+ */
4874
+ function _plugin_code_type_changed() {
4875
+ $this->_logger->entrance();
4876
+
4877
+ if ( $this->is_premium() ) {
4878
+ $this->reconnect_locally();
4879
+
4880
+ // Activated premium code.
4881
+ $this->do_action( 'after_premium_version_activation' );
4882
+
4883
+ // Remove all sticky messages related to download of the premium version.
4884
+ $this->_admin_notices->remove_sticky( array(
4885
+ 'trial_started',
4886
+ 'plan_upgraded',
4887
+ 'plan_changed',
4888
+ 'license_activated',
4889
+ ) );
4890
+
4891
+ $notice = '';
4892
+ if ( ! $this->is_only_premium() ) {
4893
+ $notice = sprintf( $this->get_text_inline( 'Premium %s version was successfully activated.', 'premium-activated-message' ), $this->_module_type );
4894
+ }
4895
+
4896
+ $license_notice = $this->get_license_network_activation_notice();
4897
+ if ( ! empty( $license_notice ) ) {
4898
+ $notice .= ' ' . $license_notice;
4899
+ }
4900
+
4901
+ if ( ! empty( $notice ) ) {
4902
+ $this->_admin_notices->add_sticky(
4903
+ trim( $notice ),
4904
+ 'premium_activated',
4905
+ $this->get_text_x_inline( 'W00t',
4906
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
4907
+ );
4908
+ }
4909
+ } else {
4910
+ // Remove sticky message related to premium code activation.
4911
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
4912
+
4913
+ // Activated free code (after had the premium before).
4914
+ $this->do_action( 'after_free_version_reactivation' );
4915
+
4916
+ if ( $this->is_paying() && ! $this->is_premium() ) {
4917
+ $this->_admin_notices->add_sticky(
4918
+ sprintf(
4919
+ /* translators: %s: License type (e.g. you have a professional license) */
4920
+ $this->get_text_inline( 'You have a %s license.', 'you-have-x-license' ),
4921
+ $this->get_plan_title()
4922
+ ) . $this->get_complete_upgrade_instructions(),
4923
+ 'plan_upgraded',
4924
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
4925
+ );
4926
+ }
4927
+ }
4928
+
4929
+ // Schedule code type changes event.
4930
+ $this->schedule_install_sync();
4931
+
4932
+ /**
4933
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
4934
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
4935
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
4936
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
4937
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
4938
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
4939
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
4940
+ */
4941
+ $this->unregister_uninstall_hook();
4942
+
4943
+ $this->clear_module_main_file_cache();
4944
+
4945
+ // Update is_premium of latest version.
4946
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
4947
+ }
4948
+
4949
+ #endregion
4950
+
4951
+ #----------------------------------------------------------------------------------
4952
+ #region Add-ons
4953
+ #----------------------------------------------------------------------------------
4954
+
4955
+ /**
4956
+ * Check if add-on installed and activated on site.
4957
+ *
4958
+ * @author Vova Feldman (@svovaf)
4959
+ * @since 1.0.6
4960
+ *
4961
+ * @param string|number $id_or_slug
4962
+ * @param bool|null $is_premium Since 1.2.1.7 can check for specified add-on version.
4963
+ *
4964
+ * @return bool
4965
+ */
4966
+ function is_addon_activated( $id_or_slug, $is_premium = null ) {
4967
+ $this->_logger->entrance();
4968
+
4969
+ $addon_id = self::get_module_id( $id_or_slug );
4970
+ $is_activated = self::has_instance( $addon_id );
4971
+
4972
+ if ( ! $is_activated ) {
4973
+ return false;
4974
+ }
4975
+
4976
+ if ( is_bool( $is_premium ) ) {
4977
+ // Check if the specified code version is activate.
4978
+ $addon = $this->get_addon_instance( $addon_id );
4979
+ $is_activated = ( $is_premium === $addon->is_premium() );
4980
+ }
4981
+
4982
+ return $is_activated;
4983
+ }
4984
+
4985
+ /**
4986
+ * Check if add-on was connected to install
4987
+ *
4988
+ * @author Vova Feldman (@svovaf)
4989
+ * @since 1.1.7
4990
+ *
4991
+ * @param string|number $id_or_slug
4992
+ *
4993
+ * @return bool
4994
+ */
4995
+ function is_addon_connected( $id_or_slug ) {
4996
+ $this->_logger->entrance();
4997
+
4998
+ $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );
4999
+
5000
+ $addon_id = self::get_module_id( $id_or_slug );
5001
+ $addon = $this->get_addon( $addon_id );
5002
+ $slug = $addon->slug;
5003
+ if ( ! isset( $sites[ $slug ] ) ) {
5004
+ return false;
5005
+ }
5006
+
5007
+ $site = $sites[ $slug ];
5008
+
5009
+ $plugin = FS_Plugin_Manager::instance( $addon_id )->get();
5010
+
5011
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
5012
+ // The given slug do NOT belong to any of the plugin's add-ons.
5013
+ return false;
5014
+ }
5015
+
5016
+ return ( is_object( $site ) &&
5017
+ is_numeric( $site->id ) &&
5018
+ is_numeric( $site->user_id ) &&
5019
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
5020
+ );
5021
+ }
5022
+
5023
+ /**
5024
+ * Determines if add-on installed.
5025
+ *
5026
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
5027
+ *
5028
+ * @author Vova Feldman (@svovaf)
5029
+ * @since 1.0.6
5030
+ *
5031
+ * @param string|number $id_or_slug
5032
+ *
5033
+ * @return bool
5034
+ */
5035
+ function is_addon_installed( $id_or_slug ) {
5036
+ $this->_logger->entrance();
5037
+
5038
+ $addon_id = self::get_module_id( $id_or_slug );
5039
+
5040
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $addon_id ) ) );
5041
+ }
5042
+
5043
+ /**
5044
+ * Get add-on basename.
5045
+ *
5046
+ * @author Vova Feldman (@svovaf)
5047
+ * @since 1.0.6
5048
+ *
5049
+ * @param string|number $id_or_slug
5050
+ *
5051
+ * @return string
5052
+ */
5053
+ function get_addon_basename( $id_or_slug ) {
5054
+ $addon_id = self::get_module_id( $id_or_slug );
5055
+
5056
+ if ( $this->is_addon_activated( $addon_id ) ) {
5057
+ return self::instance( $addon_id )->get_plugin_basename();
5058
+ }
5059
+
5060
+ $addon = $this->get_addon( $addon_id );
5061
+ $premium_basename = "{$addon->slug}-premium/{$addon->slug}.php";
5062
+
5063
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
5064
+ return $premium_basename;
5065
+ }
5066
+
5067
+ $all_plugins = $this->get_all_plugins();
5068
+
5069
+ foreach ( $all_plugins as $basename => &$data ) {
5070
+ if ( $addon->slug === $data['slug'] ||
5071
+ $addon->slug . '-premium' === $data['slug']
5072
+ ) {
5073
+ return $basename;
5074
+ }
5075
+ }
5076
+
5077
+ $free_basename = "{$addon->slug}/{$addon->slug}.php";
5078
+
5079
+ return $free_basename;
5080
+ }
5081
+
5082
+ /**
5083
+ * Get installed add-ons instances.
5084
+ *
5085
+ * @author Vova Feldman (@svovaf)
5086
+ * @since 1.0.6
5087
+ *
5088
+ * @return Freemius[]
5089
+ */
5090
+ function get_installed_addons() {
5091
+ $installed_addons = array();
5092
+ foreach ( self::$_instances as $instance ) {
5093
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5094
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5095
+ $installed_addons[] = $instance;
5096
+ }
5097
+ }
5098
+ }
5099
+
5100
+ return $installed_addons;
5101
+ }
5102
+
5103
+ /**
5104
+ * Check if any add-ons of the plugin are installed.
5105
+ *
5106
+ * @author Leo Fajardo (@leorw)
5107
+ * @since 1.1.1
5108
+ *
5109
+ * @return bool
5110
+ */
5111
+ function has_installed_addons() {
5112
+ if ( ! $this->has_addons() ) {
5113
+ return false;
5114
+ }
5115
+
5116
+ foreach ( self::$_instances as $instance ) {
5117
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
5118
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
5119
+ return true;
5120
+ }
5121
+ }
5122
+ }
5123
+
5124
+ return false;
5125
+ }
5126
+
5127
+ /**
5128
+ * Tell Freemius that the current plugin is an add-on.
5129
+ *
5130
+ * @author Vova Feldman (@svovaf)
5131
+ * @since 1.0.6
5132
+ *
5133
+ * @param number $parent_plugin_id The parent plugin ID
5134
+ */
5135
+ function init_addon( $parent_plugin_id ) {
5136
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
5137
+ }
5138
+
5139
+ /**
5140
+ * @author Vova Feldman (@svovaf)
5141
+ * @since 1.0.6
5142
+ *
5143
+ * @return bool
5144
+ */
5145
+ function is_addon() {
5146
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
5147
+ }
5148
+
5149
+ /**
5150
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
5151
+ *
5152
+ * @param bool $is_after_trial_cancel
5153
+ *
5154
+ * @return bool If add-on was deactivated.
5155
+ */
5156
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
5157
+ if ( ! $this->has_free_plan() &&
5158
+ ! $this->has_features_enabled_license() &&
5159
+ ! $this->_has_premium_license()
5160
+ ) {
5161
+ if ( $this->is_registered() ) {
5162
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
5163
+ // if (empty($this->_storage->activation_timestamp) ||
5164
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
5165
+ // ) {
5166
+ /**
5167
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
5168
+ *
5169
+ * Retry syncing the user add-on licenses.
5170
+ */
5171
+ // Sync licenses.
5172
+ $this->_sync_licenses();
5173
+ // }
5174
+
5175
+ // Try to activate premium license.
5176
+ $this->_activate_license( true );
5177
+ }
5178
+
5179
+ if ( ! $this->has_free_plan() &&
5180
+ ! $this->has_features_enabled_license() &&
5181
+ ! $this->_has_premium_license()
5182
+ ) {
5183
+ // @todo Check if deactivate plugins also call the deactivation hook.
5184
+
5185
+ $this->_parent->_admin_notices->add_sticky(
5186
+ sprintf(
5187
+ ( $is_after_trial_cancel ?
5188
+ $this->_parent->get_text_inline(
5189
+ '%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.',
5190
+ 'addon-trial-cancelled-message'
5191
+ ) :
5192
+ $this->_parent->get_text_inline(
5193
+ '%s is a premium only add-on. You have to purchase a license first before activating the plugin.',
5194
+ 'addon-no-license-message'
5195
+ )
5196
+ ),
5197
+ '<b>' . $this->_plugin->title . '</b>'
5198
+ ) . ' ' . sprintf(
5199
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
5200
+ $this->_parent->addon_url( $this->_slug ),
5201
+ esc_attr( sprintf( $this->_parent->get_text_inline( 'More information about %s', 'more-information-about-x' ), $this->_plugin->title ) ),
5202
+ $this->_parent->get_text_inline( 'Purchase License', 'purchase-license' )
5203
+ ),
5204
+ 'no_addon_license_' . $this->_slug,
5205
+ ( $is_after_trial_cancel ? '' : $this->_parent->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...' ),
5206
+ ( $is_after_trial_cancel ? 'success' : 'error' )
5207
+ );
5208
+
5209
+ deactivate_plugins( array( $this->_plugin_basename ), true );
5210
+
5211
+ return true;
5212
+ }
5213
+ }
5214
+
5215
+ return false;
5216
+ }
5217
+
5218
+ #endregion
5219
+
5220
+ #----------------------------------------------------------------------------------
5221
+ #region Sandbox
5222
+ #----------------------------------------------------------------------------------
5223
+
5224
+ /**
5225
+ * Set Freemius into sandbox mode for debugging.
5226
+ *
5227
+ * @author Vova Feldman (@svovaf)
5228
+ * @since 1.0.4
5229
+ *
5230
+ * @param string $secret_key
5231
+ */
5232
+ function init_sandbox( $secret_key ) {
5233
+ $this->_plugin->secret_key = $secret_key;
5234
+
5235
+ // Update plugin details.
5236
+ FS_Plugin_Manager::instance( $this->_module_id )->update( $this->_plugin, true );
5237
+ }
5238
+
5239
+ /**
5240
+ * Check if running payments in sandbox mode.
5241
+ *
5242
+ * @author Vova Feldman (@svovaf)
5243
+ * @since 1.0.4
5244
+ *
5245
+ * @return bool
5246
+ */
5247
+ function is_payments_sandbox() {
5248
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
5249
+ }
5250
+
5251
+ #endregion
5252
+
5253
+ /**
5254
+ * Check if running test vs. live plugin.
5255
+ *
5256
+ * @author Vova Feldman (@svovaf)
5257
+ * @since 1.0.5
5258
+ *
5259
+ * @return bool
5260
+ */
5261
+ function is_live() {
5262
+ return $this->_plugin->is_live;
5263
+ }
5264
+
5265
+ /**
5266
+ * Check if super-admin skipped connection for all sites in the network.
5267
+ *
5268
+ * @author Vova Feldman (@svovaf)
5269
+ * @since 2.0.0
5270
+ */
5271
+ function is_network_anonymous() {
5272
+ if ( ! $this->_is_network_active ) {
5273
+ return false;
5274
+ }
5275
+
5276
+ $is_anonymous_ms = $this->_storage->get( 'is_anonymous_ms' );
5277
+
5278
+ if ( empty( $is_anonymous_ms ) ) {
5279
+ return false;
5280
+ }
5281
+
5282
+ return $is_anonymous_ms['is'];
5283
+ }
5284
+
5285
+ /**
5286
+ * Check if super-admin opted-in for all sites in the network.
5287
+ *
5288
+ * @author Vova Feldman (@svovaf)
5289
+ * @since 2.0.0
5290
+ */
5291
+ function is_network_connected() {
5292
+ if ( ! $this->_is_network_active ) {
5293
+ return false;
5294
+ }
5295
+
5296
+ return $this->_storage->get( 'is_network_connected' );
5297
+ }
5298
+
5299
+ /**
5300
+ * Check if the user skipped connecting the account with Freemius.
5301
+ *
5302
+ * @author Vova Feldman (@svovaf)
5303
+ * @since 1.0.7
5304
+ *
5305
+ * @return bool
5306
+ */
5307
+ function is_anonymous() {
5308
+ if ( ! isset( $this->_is_anonymous ) ) {
5309
+ if ( $this->is_network_anonymous() ) {
5310
+ $this->_is_anonymous = true;
5311
+ } else {
5312
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
5313
+ // Not skipped.
5314
+ $this->_is_anonymous = false;
5315
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
5316
+ // For back compatibility, since the variable was boolean before.
5317
+ $this->_is_anonymous = $this->_storage->is_anonymous;
5318
+
5319
+ // Upgrade stored data format to 1.1.3 format.
5320
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
5321
+ } else {
5322
+ // Version 1.1.3 and later.
5323
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
5324
+ }
5325
+ }
5326
+ }
5327
+
5328
+ return $this->_is_anonymous;
5329
+ }
5330
+
5331
+ /**
5332
+ * Check if the user skipped the connection of a specified site.
5333
+ *
5334
+ * @author Vova Feldman (@svovaf)
5335
+ * @since 2.0.0
5336
+ *
5337
+ * @param int $blog_id
5338
+ *
5339
+ * @return bool
5340
+ */
5341
+ function is_anonymous_site( $blog_id = 0 ) {
5342
+ if ( $this->is_network_anonymous() ) {
5343
+ return true;
5344
+ }
5345
+
5346
+ $is_anonymous = $this->_storage->get( 'is_anonymous', false, $blog_id );
5347
+
5348
+ if ( empty( $is_anonymous ) ) {
5349
+ return false;
5350
+ }
5351
+
5352
+ return $is_anonymous['is'];
5353
+ }
5354
+
5355
+ /**
5356
+ * Check if user connected his account and install pending email activation.
5357
+ *
5358
+ * @author Vova Feldman (@svovaf)
5359
+ * @since 1.0.7
5360
+ *
5361
+ * @return bool
5362
+ */
5363
+ function is_pending_activation() {
5364
+ return $this->_storage->get( 'is_pending_activation', false );
5365
+ }
5366
+
5367
+ /**
5368
+ * Check if plugin must be WordPress.org compliant.
5369
+ *
5370
+ * @since 1.0.7
5371
+ *
5372
+ * @return bool
5373
+ */
5374
+ function is_org_repo_compliant() {
5375
+ return $this->_is_org_compliant;
5376
+ }
5377
+
5378
+ #--------------------------------------------------------------------------------
5379
+ #region WP Cron Common
5380
+ #--------------------------------------------------------------------------------
5381
+
5382
+ /**
5383
+ * @author Vova Feldman (@svovaf)
5384
+ * @since 2.0.0
5385
+ *
5386
+ * @param string $name Cron name.
5387
+ *
5388
+ * @return object
5389
+ */
5390
+ private function get_cron_data( $name ) {
5391
+ $this->_logger->entrance( $name );
5392
+
5393
+ /**
5394
+ * @var object $cron_data
5395
+ */
5396
+ return $this->_storage->get( "{$name}_cron", null );
5397
+ }
5398
+
5399
+ /**
5400
+ * @author Vova Feldman (@svovaf)
5401
+ * @since 2.0.0
5402
+ *
5403
+ * @param string $name Cron name.
5404
+ */
5405
+ private function clear_cron_data( $name ) {
5406
+ $this->_logger->entrance( $name );
5407
+
5408
+ $this->_storage->remove( "{$name}_cron" );
5409
+ }
5410
+
5411
+ /**
5412
+ * @author Vova Feldman (@svovaf)
5413
+ * @since 2.0.0
5414
+ *
5415
+ * @param string $name Cron name.
5416
+ * @param int $cron_blog_id The cron executing blog ID.
5417
+ */
5418
+ private function set_cron_data( $name, $cron_blog_id = 0 ) {
5419
+ $this->_logger->entrance( $name );
5420
+
5421
+ $this->_storage->store( "{$name}_cron", (object) array(
5422
+ 'version' => $this->get_plugin_version(),
5423
+ 'blog_id' => $cron_blog_id,
5424
+ 'sdk_version' => $this->version,
5425
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
5426
+ 'on' => true,
5427
+ ) );
5428
+ }
5429
+
5430
+ /**
5431
+ * Get the cron's executing blog ID.
5432
+ *
5433
+ * @author Vova Feldman (@svovaf)
5434
+ * @since 2.0.0
5435
+ *
5436
+ * @param string $name Cron name.
5437
+ *
5438
+ * @return int
5439
+ */
5440
+ private function get_cron_blog_id( $name ) {
5441
+ $this->_logger->entrance( $name );
5442
+
5443
+ /**
5444
+ * @var object $cron_data
5445
+ */
5446
+ $cron_data = $this->get_cron_data( $name );
5447
+
5448
+ return ( is_object( $cron_data ) && is_numeric( $cron_data->blog_id ) ) ?
5449
+ $cron_data->blog_id :
5450
+ 0;
5451
+ }
5452
+
5453
+ /**
5454
+ * @author Vova Feldman (@svovaf)
5455
+ * @since 2.0.0
5456
+ *
5457
+ * @param string $name Cron name.
5458
+ *
5459
+ * @return bool
5460
+ */
5461
+ private function is_cron_on( $name ) {
5462
+ $this->_logger->entrance( $name );
5463
+
5464
+ /**
5465
+ * @var object $cron_data
5466
+ */
5467
+ $cron_data = $this->get_cron_data( $name );
5468
+
5469
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
5470
+ }
5471
+
5472
+ /**
5473
+ * Unix timestamp for previous cron execution or false if never executed.
5474
+ *
5475
+ * @author Vova Feldman (@svovaf)
5476
+ * @since 2.0.0
5477
+ *
5478
+ * @param string $name Cron name.
5479
+ *
5480
+ * @return int|false
5481
+ */
5482
+ private function cron_last_execution( $name ) {
5483
+ $this->_logger->entrance( $name );
5484
+
5485
+ return $this->_storage->get( "{$name}_timestamp" );
5486
+ }
5487
+
5488
+ /**
5489
+ * Set cron execution time to now.
5490
+ *
5491
+ * @author Vova Feldman (@svovaf)
5492
+ * @since 2.0.0
5493
+ *
5494
+ * @param string $name Cron name.
5495
+ */
5496
+ private function set_cron_execution_timestamp( $name ) {
5497
+ $this->_logger->entrance( $name );
5498
+
5499
+ $this->_storage->store( "{$name}_timestamp", time() );
5500
+ }
5501
+
5502
+ /**
5503
+ * Check if cron was executed in the last $period of seconds.
5504
+ *
5505
+ * @author Vova Feldman (@svovaf)
5506
+ * @since 2.0.0
5507
+ *
5508
+ * @param string $name Cron name.
5509
+ * @param int $period In seconds
5510
+ *
5511
+ * @return bool
5512
+ */
5513
+ private function is_cron_executed( $name, $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
5514
+ $this->_logger->entrance( $name );
5515
+
5516
+ $last_execution = $this->set_cron_execution_timestamp( $name );
5517
+
5518
+ if ( ! is_numeric( $last_execution ) ) {
5519
+ return false;
5520
+ }
5521
+
5522
+ return ( $last_execution > ( WP_FS__SCRIPT_START_TIME - $period ) );
5523
+ }
5524
+
5525
+ /**
5526
+ * WP Cron is executed on a site level. When running in a multisite network environment
5527
+ * with the network integration activated, for optimization reasons, we are consolidating
5528
+ * the installs data sync cron to be executed only from a single site.
5529
+ *
5530
+ * @author Vova Feldman (@svovaf)
5531
+ * @since 2.0.0
5532
+ *
5533
+ * @param int $except_blog_id Target any except the excluded blog ID.
5534
+ *
5535
+ * @return int
5536
+ */
5537
+ private function get_cron_target_blog_id( $except_blog_id = 0 ) {
5538
+ if ( ! is_multisite() ) {
5539
+ return 0;
5540
+ }
5541
+
5542
+ if ( $this->_is_network_active &&
5543
+ is_numeric( $this->_storage->network_install_blog_id ) &&
5544
+ $except_blog_id != $this->_storage->network_install_blog_id &&
5545
+ self::is_site_active( $this->_storage->network_install_blog_id )
5546
+ ) {
5547
+ // Try to run cron from the main network blog.
5548
+ $install = $this->get_install_by_blog_id( $this->_storage->network_install_blog_id );
5549
+
5550
+ if ( is_object( $install ) &&
5551
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5552
+ ) {
5553
+ return $this->_storage->network_install_blog_id;
5554
+ }
5555
+ }
5556
+
5557
+ // Get first opted-in blog ID with active tracking.
5558
+ $installs = $this->get_blog_install_map();
5559
+ foreach ( $installs as $blog_id => $install ) {
5560
+ if ( $except_blog_id != $blog_id &&
5561
+ self::is_site_active( $blog_id ) &&
5562
+ ( $this->is_premium() || $install->is_tracking_allowed() )
5563
+ ) {
5564
+ return $blog_id;
5565
+ }
5566
+ }
5567
+
5568
+ return 0;
5569
+ }
5570
+
5571
+ /**
5572
+ * @author Vova Feldman (@svovaf)
5573
+ * @since 2.0.0
5574
+ *
5575
+ * @param string $name Cron name.
5576
+ * @param string $action_tag Callback action tag.
5577
+ * @param bool $is_network_clear If set to TRUE, clear sync cron even if there are installs that are still connected.
5578
+ */
5579
+ private function clear_cron( $name, $action_tag = '', $is_network_clear = false ) {
5580
+ $this->_logger->entrance( $name );
5581
+
5582
+ if ( ! $this->is_cron_on( $name ) ) {
5583
+ return;
5584
+ }
5585
+
5586
+ $clear_cron = true;
5587
+ if ( ! $is_network_clear && $this->_is_network_active ) {
5588
+ $installs = $this->get_blog_install_map();
5589
+
5590
+ foreach ( $installs as $blog_id => $install ) {
5591
+ /**
5592
+ * @var FS_Site $install
5593
+ */
5594
+ if ( $install->is_tracking_allowed() ) {
5595
+ $clear_cron = false;
5596
+ break;
5597
+ }
5598
+ }
5599
+ }
5600
+
5601
+ if ( ! $clear_cron ) {
5602
+ return;
5603
+ }
5604
+
5605
+ /**
5606
+ * @var object $cron_data
5607
+ */
5608
+ $cron_data = $this->get_cron_data( $name );
5609
+
5610
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5611
+ $cron_data->blog_id :
5612
+ 0;
5613
+
5614
+ $this->clear_cron_data( $name );
5615
+
5616
+ if ( 0 < $cron_blog_id ) {
5617
+ switch_to_blog( $cron_blog_id );
5618
+ }
5619
+
5620
+ if ( empty( $action_tag ) ) {
5621
+ $action_tag = $name;
5622
+ }
5623
+
5624
+ wp_clear_scheduled_hook( $this->get_action_tag( $action_tag ) );
5625
+
5626
+ if ( 0 < $cron_blog_id ) {
5627
+ restore_current_blog();
5628
+ }
5629
+ }
5630
+
5631
+ /**
5632
+ * Unix timestamp for next cron execution or false if not scheduled.
5633
+ *
5634
+ * @author Vova Feldman (@svovaf)
5635
+ * @since 2.0.0
5636
+ *
5637
+ * @param string $name Cron name.
5638
+ * @param string $action_tag Callback action tag.
5639
+ *
5640
+ * @return int|false
5641
+ */
5642
+ private function get_next_scheduled_cron( $name, $action_tag = '' ) {
5643
+ $this->_logger->entrance( $name );
5644
+
5645
+ if ( ! $this->is_cron_on( $name ) ) {
5646
+ return false;
5647
+ }
5648
+
5649
+ /**
5650
+ * @var object $cron_data
5651
+ */
5652
+ $cron_data = $this->get_cron_data( $name );
5653
+
5654
+ $cron_blog_id = is_object( $cron_data ) && isset( $cron_data->blog_id ) ?
5655
+ $cron_data->blog_id :
5656
+ 0;
5657
+
5658
+ if ( 0 < $cron_blog_id ) {
5659
+ switch_to_blog( $cron_blog_id );
5660
+ }
5661
+
5662
+ if ( empty( $action_tag ) ) {
5663
+ $action_tag = $name;
5664
+ }
5665
+
5666
+ $next_scheduled = wp_next_scheduled( $this->get_action_tag( $action_tag ) );
5667
+
5668
+ if ( 0 < $cron_blog_id ) {
5669
+ restore_current_blog();
5670
+ }
5671
+
5672
+ return $next_scheduled;
5673
+ }
5674
+
5675
+ /**
5676
+ * @author Vova Feldman (@svovaf)
5677
+ * @since 2.0.0
5678
+ *
5679
+ * @param string $name Cron name.
5680
+ * @param string $action_tag Callback action tag.
5681
+ * @param string $recurrence 'single' or 'daily'.
5682
+ * @param int $start_at Defaults to now.
5683
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
5684
+ * @param int $except_blog_id Target any except the excluded blog ID.
5685
+ */
5686
+ private function schedule_cron(
5687
+ $name,
5688
+ $action_tag = '',
5689
+ $recurrence = 'single',
5690
+ $start_at = WP_FS__SCRIPT_START_TIME,
5691
+ $randomize_start = true,
5692
+ $except_blog_id = 0
5693
+ ) {
5694
+ $this->_logger->entrance( $name );
5695
+
5696
+ $this->clear_cron( $name, $action_tag, true );
5697
+
5698
+ $cron_blog_id = $this->get_cron_target_blog_id( $except_blog_id );
5699
+
5700
+ if ( is_multisite() && 0 == $cron_blog_id ) {
5701
+ // Don't schedule cron since couldn't find a target blog.
5702
+ return;
5703
+ }
5704
+
5705
+ if ( 0 < $cron_blog_id ) {
5706
+ switch_to_blog( $cron_blog_id );
5707
+ }
5708
+
5709
+ if ( 'daily' === $recurrence ) {
5710
+ if ( $randomize_start ) {
5711
+ // Schedule first sync with a random 12 hour time range from now.
5712
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
5713
+ }
5714
+
5715
+ // Schedule daily WP cron.
5716
+ wp_schedule_event(
5717
+ $start_at,
5718
+ 'daily',
5719
+ $this->get_action_tag( $action_tag )
5720
+ );
5721
+ } else if ( 'single' === $recurrence ) {
5722
+ // Schedule single cron.
5723
+ wp_schedule_single_event(
5724
+ $start_at,
5725
+ $this->get_action_tag( $action_tag )
5726
+ );
5727
+ }
5728
+
5729
+ $this->set_cron_data( $name, $cron_blog_id );
5730
+
5731
+ if ( 0 < $cron_blog_id ) {
5732
+ restore_current_blog();
5733
+ }
5734
+ }
5735
+
5736
+ /**
5737
+ * Consolidated cron execution for performance optimization. The max number of API requests is based on the number of unique opted-in users.
5738
+ * that doesn't halt page loading.
5739
+ *
5740
+ * @author Vova Feldman (@svovaf)
5741
+ * @since 2.0.0
5742
+ *
5743
+ * @param string $name Cron name.
5744
+ * @param callable $callable The function that should be executed.
5745
+ */
5746
+ private function execute_cron( $name, $callable ) {
5747
+ $this->_logger->entrance( $name );
5748
+
5749
+ // Store the last time data sync was executed.
5750
+ $this->set_cron_execution_timestamp( $name );
5751
+
5752
+ // Check if API is temporary down.
5753
+ if ( FS_Api::is_temporary_down() ) {
5754
+ return;
5755
+ }
5756
+
5757
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
5758
+
5759
+ $users_2_blog_ids = array();
5760
+
5761
+ if ( ! is_multisite() ) {
5762
+ // Add dummy blog.
5763
+ $users_2_blog_ids[0] = array( 0 );
5764
+ } else {
5765
+ $installs = $this->get_blog_install_map();
5766
+ foreach ( $installs as $blog_id => $install ) {
5767
+ if ( $this->is_premium() || $install->is_tracking_allowed() ) {
5768
+ if ( ! isset( $users_2_blog_ids[ $install->user_id ] ) ) {
5769
+ $users_2_blog_ids[ $install->user_id ] = array();
5770
+ }
5771
+
5772
+ $users_2_blog_ids[ $install->user_id ][] = $blog_id;
5773
+ }
5774
+ }
5775
+ }
5776
+
5777
+ foreach ( $users_2_blog_ids as $user_id => $blog_ids ) {
5778
+ if ( 0 < $blog_ids[0] ) {
5779
+ $this->switch_to_blog( $blog_ids[0] );
5780
+ }
5781
+
5782
+ call_user_func_array( $callable, array( $blog_ids ) );
5783
+
5784
+ foreach ( $blog_ids as $blog_id ) {
5785
+ $this->do_action( "after_{$name}_cron", $blog_id );
5786
+ }
5787
+ }
5788
+
5789
+ if ( is_multisite() ) {
5790
+ $this->do_action( "after_{$name}_cron_multisite" );
5791
+ }
5792
+ }
5793
+
5794
+ #endregion
5795
+
5796
+ #----------------------------------------------------------------------------------
5797
+ #region Daily Sync Cron
5798
+ #----------------------------------------------------------------------------------
5799
+
5800
+
5801
+ /**
5802
+ * @author Vova Feldman (@svovaf)
5803
+ * @since 2.0.0
5804
+ *
5805
+ * @return bool
5806
+ */
5807
+ private function is_sync_cron_scheduled() {
5808
+ return $this->is_cron_on( 'sync' );
5809
+ }
5810
+
5811
+ /**
5812
+ * Get the sync cron's executing blog ID.
5813
+ *
5814
+ * @author Vova Feldman (@svovaf)
5815
+ * @since 2.0.0
5816
+ *
5817
+ * @return int
5818
+ */
5819
+ private function get_sync_cron_blog_id() {
5820
+ return $this->get_cron_blog_id( 'sync' );
5821
+ }
5822
+
5823
+ /**
5824
+ * @author Vova Feldman (@svovaf)
5825
+ * @since 1.1.7.3
5826
+ */
5827
+ private function run_manual_sync() {
5828
+ self::require_pluggable_essentials();
5829
+
5830
+ if ( ! $this->is_user_admin() ) {
5831
+ return;
5832
+ }
5833
+
5834
+ // Run manual sync.
5835
+ $this->_sync_cron();
5836
+
5837
+ // Reschedule next cron to run 24 hours from now (performance optimization).
5838
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
5839
+ }
5840
+
5841
+ /**
5842
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
5843
+ * that doesn't halt page loading.
5844
+ *
5845
+ * @author Vova Feldman (@svovaf)
5846
+ * @since 1.1.7.3
5847
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
5848
+ */
5849
+ function _sync_cron() {
5850
+ $this->_logger->entrance();
5851
+
5852
+ $this->execute_cron( 'sync', array( &$this, '_sync_cron_method' ) );
5853
+ }
5854
+
5855
+ /**
5856
+ * The actual data sync cron logic.
5857
+ *
5858
+ * @author Vova Feldman (@svovaf)
5859
+ * @since 2.0.0
5860
+ *
5861
+ * @param int[] $blog_ids
5862
+ */
5863
+ function _sync_cron_method( array $blog_ids ) {
5864
+ if ( $this->is_registered() ) {
5865
+ if ( $this->has_paid_plan() ) {
5866
+ // Initiate background plan sync.
5867
+ $this->_sync_license( true );
5868
+
5869
+ if ( $this->is_paying() ) {
5870
+ // Check for premium plugin updates.
5871
+ $this->check_updates( true );
5872
+ }
5873
+ } else {
5874
+ // Sync install(s) (only if something changed locally).
5875
+ if ( 1 < count( $blog_ids ) ) {
5876
+ $this->sync_installs();
5877
+ } else {
5878
+ $this->sync_install();
5879
+ }
5880
+ }
5881
+ }
5882
+ }
5883
+
5884
+ /**
5885
+ * Check if sync was executed in the last $period of seconds.
5886
+ *
5887
+ * @author Vova Feldman (@svovaf)
5888
+ * @since 1.1.7.3
5889
+ *
5890
+ * @param int $period In seconds
5891
+ *
5892
+ * @return bool
5893
+ */
5894
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
5895
+ return $this->is_cron_executed( 'sync', $period );
5896
+ }
5897
+
5898
+ /**
5899
+ * @author Vova Feldman (@svovaf)
5900
+ * @since 1.1.7.3
5901
+ *
5902
+ * @return bool
5903
+ */
5904
+ private function is_sync_cron_on() {
5905
+ return $this->is_cron_on( 'sync' );
5906
+ }
5907
+
5908
+ /**
5909
+ * @author Vova Feldman (@svovaf)
5910
+ * @since 1.1.7.3
5911
+ *
5912
+ * @param int $start_at Defaults to now.
5913
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise, schedule job to start right away.
5914
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
5915
+ */
5916
+ private function schedule_sync_cron(
5917
+ $start_at = WP_FS__SCRIPT_START_TIME,
5918
+ $randomize_start = true,
5919
+ $except_blog_id = 0
5920
+ ) {
5921
+ $this->schedule_cron(
5922
+ 'sync',
5923
+ 'data_sync',
5924
+ 'daily',
5925
+ $start_at,
5926
+ $randomize_start,
5927
+ $except_blog_id
5928
+ );
5929
+ }
5930
+
5931
+ /**
5932
+ * Add the actual sync function to the cron job hook.
5933
+ *
5934
+ * @author Vova Feldman (@svovaf)
5935
+ * @since 1.1.7.3
5936
+ */
5937
+ private function hook_callback_to_sync_cron() {
5938
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
5939
+ }
5940
+
5941
+ /**
5942
+ * @author Vova Feldman (@svovaf)
5943
+ * @since 1.1.7.3
5944
+ *
5945
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
5946
+ */
5947
+ private function clear_sync_cron( $is_network_clear = false ) {
5948
+ $this->_logger->entrance();
5949
+
5950
+ $this->clear_cron( 'sync', 'data_sync', $is_network_clear );
5951
+ }
5952
+
5953
+ /**
5954
+ * Unix timestamp for next sync cron execution or false if not scheduled.
5955
+ *
5956
+ * @author Vova Feldman (@svovaf)
5957
+ * @since 1.1.7.3
5958
+ *
5959
+ * @return int|false
5960
+ */
5961
+ function next_sync_cron() {
5962
+ return $this->get_next_scheduled_cron( 'sync', 'data_sync' );
5963
+ }
5964
+
5965
+ /**
5966
+ * Unix timestamp for previous sync cron execution or false if never executed.
5967
+ *
5968
+ * @author Vova Feldman (@svovaf)
5969
+ * @since 1.1.7.3
5970
+ *
5971
+ * @return int|false
5972
+ */
5973
+ function last_sync_cron() {
5974
+ return $this->cron_last_execution( 'sync' );
5975
+ }
5976
+
5977
+ #endregion Daily Sync Cron ------------------------------------------------------------------
5978
+
5979
+ #----------------------------------------------------------------------------------
5980
+ #region Async Install Sync
5981
+ #----------------------------------------------------------------------------------
5982
+
5983
+ /**
5984
+ * @author Vova Feldman (@svovaf)
5985
+ * @since 1.1.7.3
5986
+ *
5987
+ * @return bool
5988
+ */
5989
+ private function is_install_sync_scheduled() {
5990
+ return $this->is_cron_on( 'install_sync' );
5991
+ }
5992
+
5993
+ /**
5994
+ * Get the sync cron's executing blog ID.
5995
+ *
5996
+ * @author Vova Feldman (@svovaf)
5997
+ * @since 2.0.0
5998
+ *
5999
+ * @return int
6000
+ */
6001
+ private function get_install_sync_cron_blog_id() {
6002
+ return $this->get_cron_blog_id( 'install_sync' );
6003
+ }
6004
+
6005
+ /**
6006
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
6007
+ *
6008
+ * @author Vova Feldman (@svovaf)
6009
+ * @since 1.1.7.3
6010
+ *
6011
+ * @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
6012
+ */
6013
+ private function schedule_install_sync( $except_blog_id = 0 ) {
6014
+ $this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
6015
+ }
6016
+
6017
+ /**
6018
+ * Unix timestamp for previous install sync cron execution or false if never executed.
6019
+ *
6020
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being updated. But for sure the sync event is working.
6021
+ *
6022
+ * @author Vova Feldman (@svovaf)
6023
+ * @since 1.1.7.3
6024
+ *
6025
+ * @return int|false
6026
+ */
6027
+ function last_install_sync() {
6028
+ return $this->cron_last_execution( 'install_sync' );
6029
+ }
6030
+
6031
+ /**
6032
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
6033
+ *
6034
+ * @author Vova Feldman (@svovaf)
6035
+ * @since 1.1.7.3
6036
+ *
6037
+ * @return int|false
6038
+ */
6039
+ function next_install_sync() {
6040
+ return $this->get_next_scheduled_cron( 'install_sync', 'install_sync' );
6041
+ }
6042
+
6043
+ /**
6044
+ * Add the actual install sync function to the cron job hook.
6045
+ *
6046
+ * @author Vova Feldman (@svovaf)
6047
+ * @since 1.1.7.3
6048
+ */
6049
+ private function hook_callback_to_install_sync() {
6050
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
6051
+ }
6052
+
6053
+ /**
6054
+ * @author Vova Feldman (@svovaf)
6055
+ * @since 1.1.7.3
6056
+ *
6057
+ * @param bool $is_network_clear Since 2.0.0 If set to TRUE, clear sync cron even if there are installs that are still connected.
6058
+ */
6059
+ private function clear_install_sync_cron( $is_network_clear = false ) {
6060
+ $this->_logger->entrance();
6061
+
6062
+ $this->clear_cron( 'install_sync', 'install_sync', $is_network_clear );
6063
+ }
6064
+
6065
+ /**
6066
+ * @author Vova Feldman (@svovaf)
6067
+ * @since 1.1.7.3
6068
+ * @since 2.0.0 Consolidate all the data sync into the same cron for performance optimization. The max number of API requests is based on the number of unique opted-in users.
6069
+ */
6070
+ public function _run_sync_install() {
6071
+ $this->_logger->entrance();
6072
+
6073
+ $this->execute_cron( 'sync', array( &$this, '_sync_install_cron_method' ) );
6074
+ }
6075
+
6076
+ /**
6077
+ * The actual install(s) sync cron logic.
6078
+ *
6079
+ * @author Vova Feldman (@svovaf)
6080
+ * @since 2.0.0
6081
+ *
6082
+ * @param int[] $blog_ids
6083
+ */
6084
+ function _sync_install_cron_method( array $blog_ids ) {
6085
+ if ( $this->is_registered() ) {
6086
+ if ( 1 < count( $blog_ids ) ) {
6087
+ $this->sync_installs( array(), true );
6088
+ } else {
6089
+ $this->sync_install( array(), true );
6090
+ }
6091
+ }
6092
+ }
6093
+
6094
+ #endregion Async Install Sync ------------------------------------------------------------------
6095
+
6096
+ /**
6097
+ * Show a notice that activation is currently pending.
6098
+ *
6099
+ * @author Vova Feldman (@svovaf)
6100
+ * @since 1.0.7
6101
+ *
6102
+ * @param bool|string $email
6103
+ * @param bool $is_pending_trial Since 1.2.1.5
6104
+ */
6105
+ function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
6106
+ if ( ! is_string( $email ) ) {
6107
+ $current_user = self::_get_current_wp_user();
6108
+ $email = $current_user->user_email;
6109
+ }
6110
+
6111
+ $this->_admin_notices->add_sticky(
6112
+ sprintf(
6113
+ $this->get_text_inline( '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 %s.', 'pending-activation-message' ),
6114
+ '<b>' . $this->get_plugin_name() . '</b>',
6115
+ '<b>' . $email . '</b>',
6116
+ ( $is_pending_trial ?
6117
+ $this->get_text_inline( 'start the trial', 'start-the-trial' ) :
6118
+ $this->get_text_inline( 'complete the install', 'complete-the-install' ) )
6119
+ ),
6120
+ 'activation_pending',
6121
+ 'Thanks!'
6122
+ );
6123
+ }
6124
+
6125
+ /**
6126
+ * Check if currently in plugin activation.
6127
+ *
6128
+ * @author Vova Feldman (@svovaf)
6129
+ * @since 1.1.4
6130
+ *
6131
+ * @return bool
6132
+ */
6133
+ function is_plugin_activation() {
6134
+ $result = get_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6135
+
6136
+ return !empty($result);
6137
+ }
6138
+
6139
+ /**
6140
+ *
6141
+ * NOTE: admin_menu action executed before admin_init.
6142
+ *
6143
+ * @author Vova Feldman (@svovaf)
6144
+ * @since 1.0.7
6145
+ */
6146
+ function _admin_init_action() {
6147
+ /**
6148
+ * Automatically redirect to connect/activation page after plugin activation.
6149
+ *
6150
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
6151
+ */
6152
+ if ( $this->is_plugin_activation() ) {
6153
+ delete_transient( "fs_{$this->_module_type}_{$this->_slug}_activated" );
6154
+
6155
+ if ( isset( $_GET['activate-multi'] ) ) {
6156
+ /**
6157
+ * Don't redirect if activating multiple plugins at once (bulk activation).
6158
+ */
6159
+ } else {
6160
+ $this->_redirect_on_activation_hook();
6161
+ return;
6162
+ }
6163
+ }
6164
+
6165
+ if ( fs_request_is_action( $this->get_unique_affix() . '_skip_activation' ) ) {
6166
+ check_admin_referer( $this->get_unique_affix() . '_skip_activation' );
6167
+
6168
+ $this->skip_connection( null, fs_is_network_admin() );
6169
+
6170
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
6171
+ }
6172
+
6173
+ if ( $this->is_network_activation_mode() &&
6174
+ fs_request_is_action( $this->get_unique_affix() . '_delegate_activation' )
6175
+ ) {
6176
+ check_admin_referer( $this->get_unique_affix() . '_delegate_activation' );
6177
+
6178
+ $this->delegate_connection();
6179
+
6180
+ fs_redirect( $this->get_after_activation_url( 'after_delegation_url' ) );
6181
+ }
6182
+
6183
+ $this->_add_upgrade_action_link();
6184
+
6185
+ if ( ! $this->is_addon() &&
6186
+ ! ( ! $this->_is_network_active && fs_is_network_admin() ) &&
6187
+ (
6188
+ // Not registered nor anonymous.
6189
+ ( ! $this->is_registered() && ! $this->is_anonymous() ) ||
6190
+ // OR, network level and in network upgrade mode.
6191
+ ( fs_is_network_admin() && $this->_is_network_active && $this->is_network_upgrade_mode() )
6192
+ )
6193
+ ) {
6194
+ if ( ! $this->is_pending_activation() ) {
6195
+ if ( ! $this->_menu->is_main_settings_page() ) {
6196
+ /**
6197
+ * If a user visits any other admin page before activating the premium-only theme with a valid
6198
+ * license, reactivate the previous theme.
6199
+ *
6200
+ * @author Leo Fajardo (@leorw)
6201
+ * @since 1.2.2
6202
+ */
6203
+ if ( $this->is_theme()
6204
+ && $this->is_only_premium()
6205
+ && ! $this->has_settings_menu()
6206
+ && ! isset( $_REQUEST['fs_action'] )
6207
+ && $this->can_activate_previous_theme()
6208
+ ) {
6209
+ $this->activate_previous_theme();
6210
+
6211
+ return;
6212
+ }
6213
+
6214
+ if ( ! fs_is_network_admin() &&
6215
+ $this->is_network_activation_mode() &&
6216
+ ! $this->is_delegated_connection()
6217
+ ) {
6218
+ return;
6219
+ }
6220
+
6221
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
6222
+ if ( ! $this->_anonymous_mode ) {
6223
+ // Show notice for new plugin installations.
6224
+ $this->_admin_notices->add(
6225
+ sprintf(
6226
+ $this->get_text_inline( 'You are just one step away - %s', 'you-are-step-away' ),
6227
+ sprintf( '<b><a href="%s">%s</a></b>',
6228
+ $this->get_activation_url( array(), ! $this->is_delegated_connection() ),
6229
+ sprintf( $this->get_text_x_inline( 'Complete "%s" Activation Now',
6230
+ '%s - plugin name. As complete "PluginX" activation now', 'activate-x-now' ), $this->get_plugin_name() )
6231
+ )
6232
+ ),
6233
+ '',
6234
+ 'update-nag'
6235
+ );
6236
+ }
6237
+ } else {
6238
+ if ( $this->should_add_sticky_optin_notice() ) {
6239
+ $this->add_sticky_optin_admin_notice();
6240
+ }
6241
+
6242
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
6243
+ // Don't show admin nag if plugin update.
6244
+ wp_enqueue_script( 'wp-pointer' );
6245
+ wp_enqueue_style( 'wp-pointer' );
6246
+
6247
+ $this->_enqueue_connect_essentials();
6248
+
6249
+ add_action( 'admin_print_footer_scripts', array(
6250
+ $this,
6251
+ '_add_connect_pointer_script'
6252
+ ) );
6253
+ }
6254
+ }
6255
+ }
6256
+ }
6257
+
6258
+ if ( $this->is_theme() &&
6259
+ $this->_menu->is_main_settings_page()
6260
+ ) {
6261
+ $this->_show_theme_activation_optin_dialog();
6262
+ }
6263
+ }
6264
+ }
6265
+
6266
+ /**
6267
+ * @author Vova Feldman (@svovaf)
6268
+ * @since 2.0.0
6269
+ *
6270
+ * @return bool
6271
+ */
6272
+ private function should_add_sticky_optin_notice() {
6273
+ if ( fs_is_network_admin() ) {
6274
+ if ( ! $this->_is_network_active ) {
6275
+ return false;
6276
+ }
6277
+
6278
+ if ( ! $this->is_network_activation_mode() ) {
6279
+ return false;
6280
+ }
6281
+
6282
+ return ! isset( $this->_storage->sticky_optin_added_ms );
6283
+ }
6284
+
6285
+ if ( ! $this->is_activation_mode() ) {
6286
+ return false;
6287
+ }
6288
+
6289
+ // If running from a blog admin and delegated the connection.
6290
+ return ! isset( $this->_storage->sticky_optin_added );
6291
+ }
6292
+
6293
+ /**
6294
+ * @author Leo Fajardo (@leorw)
6295
+ * @since 2.0.0
6296
+ */
6297
+ private function add_sticky_optin_admin_notice() {
6298
+ if ( ! $this->_is_network_active || ! fs_is_network_admin() ) {
6299
+ $this->_storage->sticky_optin_added = true;
6300
+ } else {
6301
+ $this->_storage->sticky_optin_added_ms = true;
6302
+ }
6303
+
6304
+ // Show notice for new plugin installations.
6305
+ $this->_admin_notices->add_sticky(
6306
+ sprintf(
6307
+ $this->get_text_inline( 'We made a few tweaks to the %s, %s', 'few-plugin-tweaks' ),
6308
+ $this->_module_type,
6309
+ sprintf( '<b><a href="%s">%s</a></b>',
6310
+ $this->get_activation_url(),
6311
+ sprintf( $this->get_text_inline( 'Opt in to make "%s" Better!', 'optin-x-now' ), $this->get_plugin_name() )
6312
+ )
6313
+ ),
6314
+ 'connect_account',
6315
+ '',
6316
+ 'update-nag'
6317
+ );
6318
+ }
6319
+
6320
+ /**
6321
+ * Enqueue connect requires scripts and styles.
6322
+ *
6323
+ * @author Vova Feldman (@svovaf)
6324
+ * @since 1.1.4
6325
+ */
6326
+ function _enqueue_connect_essentials() {
6327
+ wp_enqueue_script( 'jquery' );
6328
+ wp_enqueue_script( 'json2' );
6329
+
6330
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
6331
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
6332
+
6333
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
6334
+ }
6335
+
6336
+ /**
6337
+ * Add connect / opt-in pointer.
6338
+ *
6339
+ * @author Vova Feldman (@svovaf)
6340
+ * @since 1.1.4
6341
+ */
6342
+ function _add_connect_pointer_script() {
6343
+ $vars = array( 'id' => $this->_module_id );
6344
+ $pointer_content = fs_get_template( 'connect.php', $vars );
6345
+ ?>
6346
+ <script type="text/javascript">// <![CDATA[
6347
+ jQuery(document).ready(function ($) {
6348
+ if ('undefined' !== typeof(jQuery().pointer)) {
6349
+
6350
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
6351
+
6352
+ if (element.length > 0) {
6353
+ var optin = $(element).pointer($.extend(true, {}, {
6354
+ content : <?php echo json_encode( $pointer_content ) ?>,
6355
+ position : {
6356
+ edge : 'left',
6357
+ align: 'center'
6358
+ },
6359
+ buttons : function () {
6360
+ // Don't show pointer buttons.
6361
+ return '';
6362
+ },
6363
+ pointerWidth: 482
6364
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
6365
+
6366
+ <?php
6367
+ echo $this->apply_filters( 'optin_pointer_execute', "
6368
+
6369
+ optin.pointer('open');
6370
+
6371
+ // Tag the opt-in pointer with custom class.
6372
+ $('.wp-pointer #fs_connect')
6373
+ .parents('.wp-pointer.wp-pointer-top')
6374
+ .addClass('fs-opt-in-pointer');
6375
+
6376
+ ", 'element', 'optin' ) ?>
6377
+ }
6378
+ }
6379
+ });
6380
+ // ]]></script>
6381
+ <?php
6382
+ }
6383
+
6384
+ /**
6385
+ * Return current page's URL.
6386
+ *
6387
+ * @author Vova Feldman (@svovaf)
6388
+ * @since 1.0.7
6389
+ *
6390
+ * @return string
6391
+ */
6392
+ function current_page_url() {
6393
+ $url = 'http';
6394
+
6395
+ if ( isset( $_SERVER["HTTPS"] ) ) {
6396
+ if ( $_SERVER["HTTPS"] == "on" ) {
6397
+ $url .= "s";
6398
+ }
6399
+ }
6400
+ $url .= "://";
6401
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
6402
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
6403
+ } else {
6404
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
6405
+ }
6406
+
6407
+ return esc_url( $url );
6408
+ }
6409
+
6410
+ /**
6411
+ * Check if the current page is the plugin's main admin settings page.
6412
+ *
6413
+ * @author Vova Feldman (@svovaf)
6414
+ * @since 1.0.7
6415
+ *
6416
+ * @return bool
6417
+ */
6418
+ function _is_plugin_page() {
6419
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
6420
+ fs_is_plugin_page( $this->_slug );
6421
+ }
6422
+
6423
+ /* Events
6424
+ ------------------------------------------------------------------------------------------------------------------*/
6425
+ /**
6426
+ * Delete site install from Database.
6427
+ *
6428
+ * @author Vova Feldman (@svovaf)
6429
+ * @since 1.0.1
6430
+ *
6431
+ * @param bool $store
6432
+ * @param int|null $blog_id Since 2.0.0
6433
+ *
6434
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6435
+ */
6436
+ function _delete_site( $store = true, $blog_id = null ) {
6437
+ return self::_delete_site_by_slug( $this->_slug, $this->_module_type, $store, $blog_id );
6438
+ }
6439
+
6440
+ /**
6441
+ * Delete site install from Database.
6442
+ *
6443
+ * @author Vova Feldman (@svovaf)
6444
+ * @since 1.2.2.7
6445
+ *
6446
+ * @param string $slug
6447
+ * @param string $module_type
6448
+ * @param bool $store
6449
+ * @param int|null $blog_id Since 2.0.0
6450
+ *
6451
+ * @return false|int The install ID if deleted. Otherwise, FALSE (when install not exist).
6452
+ */
6453
+ static function _delete_site_by_slug( $slug, $module_type, $store = true, $blog_id = null ) {
6454
+ $sites = self::get_all_sites( $module_type, $blog_id );
6455
+
6456
+ $install_id = false;
6457
+
6458
+ if ( isset( $sites[ $slug ] ) ) {
6459
+ if ( is_object( $sites[ $slug ] ) ) {
6460
+ $install_id = $sites[ $slug ]->id;
6461
+ }
6462
+
6463
+ unset( $sites[ $slug ] );
6464
+
6465
+ self::set_account_option_by_module( $module_type, 'sites', $sites, $store, $blog_id );
6466
+ }
6467
+
6468
+ return $install_id;
6469
+ }
6470
+
6471
+ /**
6472
+ * Delete user.
6473
+ *
6474
+ * @author Vova Feldman (@svovaf)
6475
+ * @since 2.0.0
6476
+ *
6477
+ * @param number $user_id
6478
+ * @param bool $store
6479
+ *
6480
+ * @return false|int The user ID if deleted. Otherwise, FALSE (when install not exist).
6481
+ */
6482
+ private static function delete_user( $user_id, $store = true ) {
6483
+ $users = self::get_all_users();
6484
+
6485
+ if ( ! is_array( $users ) || ! isset( $users[ $user_id ] ) ) {
6486
+ return false;
6487
+ }
6488
+
6489
+ unset( $users[ $user_id ] );
6490
+
6491
+ self::$_accounts->set_option( 'users', $users, $store );
6492
+
6493
+ return $user_id;
6494
+ }
6495
+
6496
+ /**
6497
+ * Delete plugin's plans information.
6498
+ *
6499
+ * @param bool $store Flush to Database if true.
6500
+ * @param bool $keep_associated_plans If set to false, delete all plans, even if a plan is associated with an install.
6501
+ *
6502
+ * @author Vova Feldman (@svovaf)
6503
+ * @since 1.0.9
6504
+ */
6505
+ private function _delete_plans( $store = true, $keep_associated_plans = true ) {
6506
+ $this->_logger->entrance();
6507
+
6508
+ $plans = self::get_all_plans( $this->_module_type );
6509
+
6510
+ $plans_to_keep = array();
6511
+
6512
+ if ( $keep_associated_plans ) {
6513
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
6514
+ foreach ( $plans_ids_to_keep as $plan_id ) {
6515
+ $plan = self::_get_plan_by_id( $plan_id );
6516
+ if ( is_object( $plan ) ) {
6517
+ $plans_to_keep[] = $plan;
6518
+ }
6519
+ }
6520
+ }
6521
+
6522
+ if ( ! empty( $plans_to_keep ) ) {
6523
+ $plans[ $this->_slug ] = $plans_to_keep;
6524
+ } else {
6525
+ unset( $plans[ $this->_slug ] );
6526
+ }
6527
+
6528
+ $this->set_account_option( 'plans', $plans, $store );
6529
+ }
6530
+
6531
+ /**
6532
+ * Delete all plugin licenses.
6533
+ *
6534
+ * @author Vova Feldman (@svovaf)
6535
+ * @since 1.0.9
6536
+ *
6537
+ * @param bool $store
6538
+ */
6539
+ private function _delete_licenses( $store = true ) {
6540
+ $this->_logger->entrance();
6541
+
6542
+ $all_licenses = self::get_all_licenses();
6543
+
6544
+ unset( $all_licenses[ $this->_module_id ] );
6545
+
6546
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
6547
+ }
6548
+
6549
+ /**
6550
+ * Check if Freemius was added on new plugin installation.
6551
+ *
6552
+ * @author Vova Feldman (@svovaf)
6553
+ * @since 1.1.5
6554
+ *
6555
+ * @return bool
6556
+ */
6557
+ function is_plugin_new_install() {
6558
+ return isset( $this->_storage->is_plugin_new_install ) &&
6559
+ $this->_storage->is_plugin_new_install;
6560
+ }
6561
+
6562
+ /**
6563
+ * Check if it's the first plugin release that is running Freemius.
6564
+ *
6565
+ * @author Vova Feldman (@svovaf)
6566
+ * @since 1.2.1.5
6567
+ *
6568
+ * @return bool
6569
+ */
6570
+ function is_first_freemius_powered_version() {
6571
+ return empty( $this->_storage->plugin_last_version );
6572
+ }
6573
+
6574
+ /**
6575
+ * @author Leo Fajardo (@leorw)
6576
+ * @since 1.2.2
6577
+ *
6578
+ * @return bool|string
6579
+ */
6580
+ private function get_previous_theme_slug() {
6581
+ return isset( $this->_storage->previous_theme ) ?
6582
+ $this->_storage->previous_theme :
6583
+ false;
6584
+ }
6585
+
6586
+ /**
6587
+ * @author Leo Fajardo (@leorw)
6588
+ * @since 1.2.2
6589
+ *
6590
+ * @return string
6591
+ */
6592
+ private function can_activate_previous_theme() {
6593
+ $slug = $this->get_previous_theme_slug();
6594
+ if ( false !== $slug && current_user_can( 'switch_themes' ) ) {
6595
+ $theme_instance = wp_get_theme( $slug );
6596
+
6597
+ return $theme_instance->exists();
6598
+ }
6599
+
6600
+ return false;
6601
+ }
6602
+
6603
+ /**
6604
+ * @author Leo Fajardo (@leorw)
6605
+ * @since 1.2.2
6606
+ */
6607
+ private function activate_previous_theme() {
6608
+ switch_theme( $this->get_previous_theme_slug() );
6609
+ unset( $this->_storage->previous_theme );
6610
+
6611
+ global $pagenow;
6612
+ if ( 'themes.php' === $pagenow ) {
6613
+ /**
6614
+ * Refresh the active theme information.
6615
+ *
6616
+ * @author Leo Fajardo (@leorw)
6617
+ * @since 1.2.2
6618
+ */
6619
+ fs_redirect( $this->admin_url( $pagenow ) );
6620
+ }
6621
+ }
6622
+
6623
+ /**
6624
+ * @author Leo Fajardo (@leorw)
6625
+ * @since 1.2.2
6626
+ *
6627
+ * @return string
6628
+ */
6629
+ function get_previous_theme_activation_url() {
6630
+ if ( ! $this->can_activate_previous_theme() ) {
6631
+ return '';
6632
+ }
6633
+
6634
+ /**
6635
+ * Activation URL
6636
+ *
6637
+ * @author Leo Fajardo (@leorw)
6638
+ * @since 1.2.2
6639
+ */
6640
+ return wp_nonce_url(
6641
+ $this->admin_url( 'themes.php?action=activate&stylesheet=' . urlencode( $this->get_previous_theme_slug() ) ),
6642
+ 'switch-theme_' . $this->get_previous_theme_slug()
6643
+ );
6644
+ }
6645
+
6646
+ /**
6647
+ * Saves the slug of the previous theme if it still exists so that it can be used by the logic in the opt-in
6648
+ * form that decides whether to add a close button to the opt-in dialog or not. So after a premium-only theme is
6649
+ * activated, the close button will appear and will reactivate the previous theme if clicked. If the previous
6650
+ * theme doesn't exist, then there will be no close button.
6651
+ *
6652
+ * @author Leo Fajardo (@leorw)
6653
+ * @since 1.2.2
6654
+ *
6655
+ * @param string $slug_or_name Old theme's slug or name.
6656
+ * @param bool|WP_Theme $old_theme WP_Theme instance of the old theme if it still exists.
6657
+ */
6658
+ function _activate_theme_event_hook( $slug_or_name, $old_theme = false ) {
6659
+ $this->_storage->previous_theme = ( false !== $old_theme ) ?
6660
+ $old_theme->get_stylesheet() :
6661
+ $slug_or_name;
6662
+
6663
+ $this->_activate_plugin_event_hook();
6664
+ }
6665
+
6666
+ /**
6667
+ * Plugin activated hook.
6668
+ *
6669
+ * @author Vova Feldman (@svovaf)
6670
+ * @since 1.0.1
6671
+ *
6672
+ * @uses FS_Api
6673
+ */
6674
+ function _activate_plugin_event_hook() {
6675
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6676
+
6677
+ if ( ! $this->is_user_admin() ) {
6678
+ return;
6679
+ }
6680
+
6681
+ $this->unregister_uninstall_hook();
6682
+
6683
+ // Clear API cache on activation.
6684
+ FS_Api::clear_cache();
6685
+
6686
+ $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
6687
+
6688
+ $this->_logger->info( 'Activating ' . ( $is_premium_version_activation ? 'premium' : 'free' ) . ' plugin version.' );
6689
+
6690
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
6691
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
6692
+ $other_version_basename = $is_premium_version_activation ?
6693
+ $this->_free_plugin_basename :
6694
+ $this->premium_plugin_basename();
6695
+
6696
+ if ( ! $this->_is_network_active ) {
6697
+ /**
6698
+ * During the activation, the plugin isn't yet active, therefore,
6699
+ * _is_network_active will be set to false even if it's a network level
6700
+ * activation. So we need to fix that by looking at the is_network_admin() value.
6701
+ *
6702
+ * @author Vova Feldman
6703
+ */
6704
+ $this->_is_network_active = (
6705
+ $this->_is_multisite_integrated &&
6706
+ // Themes are always network activated, but the ACTUAL activation is per site.
6707
+ $this->is_plugin() &&
6708
+ fs_is_network_admin()
6709
+ );
6710
+ }
6711
+
6712
+ /**
6713
+ * If the other module version is activate, deactivate it.
6714
+ *
6715
+ * is_plugin_active() checks if the plugin active on the site or the network level
6716
+ * and deactivate_plugins() deactivates the plugin whether its activated on the site
6717
+ * or network level.
6718
+ *
6719
+ * @author Leo Fajardo (@leorw)
6720
+ * @since 1.2.2
6721
+ */
6722
+ if ( is_plugin_active( $other_version_basename ) ) {
6723
+ deactivate_plugins( $other_version_basename );
6724
+ }
6725
+
6726
+ if ( $this->is_registered() ) {
6727
+ if ( $is_premium_version_activation ) {
6728
+ $this->reconnect_locally();
6729
+ }
6730
+
6731
+
6732
+ // Schedule re-activation event and sync.
6733
+ // $this->sync_install( array(), true );
6734
+ $this->schedule_install_sync();
6735
+
6736
+ // If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
6737
+ if ( $is_premium_version_activation ) {
6738
+ $this->_admin_notices->add(
6739
+ sprintf( $this->get_text_inline( 'The upgrade of %s was successfully completed.', 'successful-version-upgrade-message' ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
6740
+ $this->get_text_x_inline( 'W00t',
6741
+ 'Used to express elation, enthusiasm, or triumph (especially in electronic communication).', 'woot' ) . '!'
6742
+ );
6743
+ }
6744
+ } else if ( $this->is_anonymous() ) {
6745
+ if ( isset( $this->_storage->is_anonymous_ms ) && $this->_storage->is_anonymous_ms['is'] ) {
6746
+ $plugin_version = $this->_storage->is_anonymous_ms['version'];
6747
+ $network = true;
6748
+ } else {
6749
+ $plugin_version = $this->_storage->is_anonymous['version'];
6750
+ $network = false;
6751
+ }
6752
+
6753
+ /**
6754
+ * Reset "skipped" click cache on the following:
6755
+ * 1. Freemius DEV mode.
6756
+ * 2. WordPress DEBUG mode.
6757
+ * 3. If a plugin and the user skipped the exact same version before.
6758
+ *
6759
+ * @since 1.2.2.7 Ulrich Pogson (@grapplerulrich) asked to not reset the SKIPPED flag if the exact same THEME version was activated before unless the developer is running with WP_DEBUG on, or Freemius debug mode on (WP_FS__DEV_MODE).
6760
+ *
6761
+ * @todo 4. If explicitly asked to retry after every activation.
6762
+ */
6763
+ if ( WP_FS__DEV_MODE ||
6764
+ (
6765
+ ( $this->is_plugin() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) &&
6766
+ $this->get_plugin_version() == $plugin_version
6767
+ )
6768
+ ) {
6769
+ $this->reset_anonymous_mode( $network );
6770
+ }
6771
+ }
6772
+
6773
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
6774
+ /**
6775
+ * If no previous version of plugin's version exist, it means that it's either
6776
+ * the first time that the plugin installed on the site, or the plugin was installed
6777
+ * before but didn't have Freemius integrated.
6778
+ *
6779
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
6780
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
6781
+ * only after immediate activation.
6782
+ *
6783
+ * @since 1.1.4
6784
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
6785
+ */
6786
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
6787
+ }
6788
+
6789
+ if ( ! $this->_anonymous_mode &&
6790
+ $this->has_api_connectivity( WP_FS__DEV_MODE ) &&
6791
+ ! $this->_isAutoInstall
6792
+ ) {
6793
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
6794
+ set_transient( "fs_{$this->_module_type}_{$this->_slug}_activated", true, 60 );
6795
+ }
6796
+
6797
+ /**
6798
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
6799
+ * after the plugin was loaded. The logic is located at activate_plugin()
6800
+ * ./wp-admin/includes/plugin.php.
6801
+ *
6802
+ * @author Vova Feldman (@svovaf)
6803
+ * @since 1.1.9
6804
+ */
6805
+ $this->_storage->was_plugin_loaded = true;
6806
+ }
6807
+
6808
+ /**
6809
+ * Delete account.
6810
+ *
6811
+ * @author Vova Feldman (@svovaf)
6812
+ * @since 1.0.3
6813
+ *
6814
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
6815
+ */
6816
+ function delete_account_event( $check_user = true ) {
6817
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6818
+
6819
+ if ( $check_user && ! $this->is_user_admin() ) {
6820
+ return;
6821
+ }
6822
+
6823
+ $this->do_action( 'before_account_delete' );
6824
+
6825
+ // Clear all admin notices.
6826
+ $this->_admin_notices->clear_all_sticky( false );
6827
+
6828
+ $this->_delete_site( false );
6829
+
6830
+ $delete_network_common_data = true;
6831
+
6832
+ if ( $this->_is_network_active ) {
6833
+ $installs = $this->get_blog_install_map();
6834
+
6835
+ // Don't delete common network data unless no other installs left.
6836
+ $delete_network_common_data = empty( $installs );
6837
+ }
6838
+
6839
+ if ( $delete_network_common_data ) {
6840
+ $this->_delete_plans( false );
6841
+
6842
+ $this->_delete_licenses( false );
6843
+
6844
+ // Delete add-ons related to plugin's account.
6845
+ $this->_delete_account_addons( false );
6846
+ }
6847
+
6848
+ // @todo Delete plans and licenses of add-ons.
6849
+
6850
+ self::$_accounts->store();
6851
+
6852
+ /**
6853
+ * IMPORTANT:
6854
+ * Clear crons must be executed before clearing all storage.
6855
+ * Otherwise, the cron will not be cleared.
6856
+ */
6857
+ if ( $delete_network_common_data ) {
6858
+ $this->clear_sync_cron();
6859
+ }
6860
+
6861
+ $this->clear_install_sync_cron();
6862
+
6863
+ // Clear all storage data.
6864
+ $this->_storage->clear_all( true, array(
6865
+ 'connectivity_test',
6866
+ 'is_on',
6867
+ ), false );
6868
+
6869
+ // Send delete event.
6870
+ $this->get_api_site_scope()->call( '/', 'delete' );
6871
+
6872
+ $this->do_action( 'after_account_delete' );
6873
+ }
6874
+
6875
+ /**
6876
+ * Delete network level account.
6877
+ *
6878
+ * @author Vova Feldman (@svovaf)
6879
+ * @since 2.0.0
6880
+ *
6881
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
6882
+ */
6883
+ function delete_network_account_event( $check_user = true ) {
6884
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6885
+
6886
+ if ( $check_user && ! $this->is_user_admin() ) {
6887
+ return;
6888
+ }
6889
+
6890
+ $this->do_action( 'before_network_account_delete' );
6891
+
6892
+ // Clear all admin notices.
6893
+ $this->_admin_notices->clear_all_sticky();
6894
+
6895
+ $this->_delete_plans( false, false );
6896
+
6897
+ $this->_delete_licenses( false );
6898
+
6899
+ // Delete add-ons related to plugin's account.
6900
+ $this->_delete_account_addons( false );
6901
+
6902
+ // @todo Delete plans and licenses of add-ons.
6903
+
6904
+ self::$_accounts->store( true );
6905
+
6906
+ /**
6907
+ * IMPORTANT:
6908
+ * Clear crons must be executed before clearing all storage.
6909
+ * Otherwise, the cron will not be cleared.
6910
+ */
6911
+ $this->clear_sync_cron( true );
6912
+ $this->clear_install_sync_cron( true );
6913
+
6914
+ $sites = self::get_sites();
6915
+
6916
+ $install_ids = array();
6917
+ foreach ( $sites as $site ) {
6918
+ $blog_id = self::get_site_blog_id( $site );
6919
+
6920
+ $install_id = $this->_delete_site( true, $blog_id );
6921
+
6922
+ // Clear all storage data.
6923
+ $this->_storage->clear_all( true, array( 'connectivity_test' ), $blog_id );
6924
+
6925
+ if ( FS_Site::is_valid_id( $install_id ) ) {
6926
+ $install_ids[] = $install_id;
6927
+ }
6928
+
6929
+ switch_to_blog( $blog_id );
6930
+
6931
+ $this->do_action( 'after_account_delete' );
6932
+
6933
+ restore_current_blog();
6934
+ }
6935
+
6936
+ $this->_storage->clear_all( true, array(
6937
+ 'connectivity_test',
6938
+ 'is_on',
6939
+ ), true );
6940
+
6941
+ // Send delete event.
6942
+ if ( ! empty( $install_ids ) ) {
6943
+ $result = $this->get_current_or_network_user_api_scope()->call( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', $install_ids ), 'delete' );
6944
+ }
6945
+
6946
+ $this->do_action( 'after_network_account_delete' );
6947
+ }
6948
+
6949
+ /**
6950
+ * Plugin deactivation hook.
6951
+ *
6952
+ * @author Vova Feldman (@svovaf)
6953
+ * @since 1.0.1
6954
+ */
6955
+ function _deactivate_plugin_hook() {
6956
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
6957
+
6958
+ if ( ! $this->is_user_admin() ) {
6959
+ return;
6960
+ }
6961
+
6962
+ $is_network_deactivation = fs_is_network_admin();
6963
+ $storage_keys_for_removal = array();
6964
+
6965
+ $this->_admin_notices->clear_all_sticky();
6966
+
6967
+ $storage_keys_for_removal[] = 'sticky_optin_added';
6968
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
6969
+ unset( $this->_storage->sticky_optin_added );
6970
+ }
6971
+
6972
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
6973
+ // Remember that plugin was already installed.
6974
+ $this->_storage->is_plugin_new_install = false;
6975
+ }
6976
+
6977
+ // Hook to plugin uninstall.
6978
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
6979
+
6980
+ $this->clear_module_main_file_cache();
6981
+ $this->clear_sync_cron( $this->_is_network_active );
6982
+ $this->clear_install_sync_cron();
6983
+
6984
+ if ( $this->is_registered() ) {
6985
+ if ( $this->is_premium() && ! $this->has_active_valid_license() ) {
6986
+ FS_Plugin_Updater::instance( $this )->delete_update_data();
6987
+ }
6988
+
6989
+ if ( $is_network_deactivation ) {
6990
+ // Send deactivation event.
6991
+ $this->sync_installs( array(
6992
+ 'is_active' => false,
6993
+ ) );
6994
+ } else {
6995
+ // Send deactivation event.
6996
+ $this->sync_install( array(
6997
+ 'is_active' => false,
6998
+ ) );
6999
+ }
7000
+ } else {
7001
+ if ( ! $this->has_api_connectivity() ) {
7002
+ // Reset connectivity test cache.
7003
+ unset( $this->_storage->connectivity_test );
7004
+
7005
+ $storage_keys_for_removal[] = 'connectivity_test';
7006
+ }
7007
+ }
7008
+
7009
+ if ( $is_network_deactivation ) {
7010
+ if ( isset( $this->_storage->sticky_optin_added_ms ) ) {
7011
+ unset( $this->_storage->sticky_optin_added_ms );
7012
+ }
7013
+
7014
+ if ( ! empty( $storage_keys_for_removal ) ) {
7015
+ $sites = self::get_sites();
7016
+
7017
+ foreach ( $sites as $site ) {
7018
+ $blog_id = self::get_site_blog_id( $site );
7019
+
7020
+ foreach ( $storage_keys_for_removal as $key ) {
7021
+ $this->_storage->remove( $key, false, $blog_id );
7022
+ }
7023
+
7024
+ $this->_storage->save( $blog_id );
7025
+ }
7026
+ }
7027
+ }
7028
+
7029
+ // Clear API cache on deactivation.
7030
+ FS_Api::clear_cache();
7031
+
7032
+ $this->remove_sdk_reference();
7033
+ }
7034
+
7035
+ /**
7036
+ * @author Vova Feldman (@svovaf)
7037
+ * @since 1.1.6
7038
+ */
7039
+ private function remove_sdk_reference() {
7040
+ global $fs_active_plugins;
7041
+
7042
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
7043
+ if ( $this->_plugin_basename == $data->plugin_path ) {
7044
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
7045
+ break;
7046
+ }
7047
+ }
7048
+
7049
+ fs_fallback_to_newest_active_sdk();
7050
+ }
7051
+
7052
+ /**
7053
+ * @author Vova Feldman (@svovaf)
7054
+ * @since 1.1.3
7055
+ *
7056
+ * @param bool $is_anonymous
7057
+ * @param bool|int $network_or_blog_id Since 2.0.0
7058
+ */
7059
+ private function set_anonymous_mode( $is_anonymous = true, $network_or_blog_id = 0 ) {
7060
+ // Store information regarding skip to try and opt-in the user
7061
+ // again in the future.
7062
+ $skip_info = array(
7063
+ 'is' => $is_anonymous,
7064
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
7065
+ 'version' => $this->get_plugin_version(),
7066
+ );
7067
+
7068
+ if ( true === $network_or_blog_id ) {
7069
+ $this->_storage->is_anonymous_ms = $skip_info;
7070
+ } else {
7071
+ $this->_storage->store( 'is_anonymous', $skip_info, $network_or_blog_id );
7072
+ }
7073
+
7074
+ $this->network_upgrade_mode_completed();
7075
+
7076
+ // Update anonymous mode cache.
7077
+ $this->_is_anonymous = $is_anonymous;
7078
+ }
7079
+
7080
+ /**
7081
+ * @author Vova Feldman (@svovaf)
7082
+ * @since 2.0.0
7083
+ *
7084
+ * @param int $blog_id Site ID.
7085
+ * @param int $user_id User ID.
7086
+ * @param string $domain Site domain.
7087
+ * @param string $path Site path.
7088
+ * @param int $network_id Network ID. Only relevant on multi-network installations.
7089
+ * @param array $meta Metadata. Used to set initial site options.
7090
+ *
7091
+ * @uses Freemius::is_license_network_active() to check if the context license was network activated by the super-admin.
7092
+ * @uses Freemius::is_network_connected() to check if the super-admin network opted-in.
7093
+ * @uses Freemius::is_network_anonymous() to check if the super-admin network skipped.
7094
+ * @uses Freemius::is_network_delegated_connection() to check if the super-admin network delegated the connection to the site admins.
7095
+ */
7096
+ function _after_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
7097
+ $this->_logger->entrance();
7098
+
7099
+ if ( $this->is_premium() &&
7100
+ $this->is_network_connected() &&
7101
+ is_object( $this->_license ) &&
7102
+ $this->_license->can_activate( FS_Site::is_localhost_by_address( $domain ) ) &&
7103
+ $this->is_license_network_active( $blog_id )
7104
+ ) {
7105
+ /**
7106
+ * Running the premium version, the license was network activated, and the license can also be activated on the current site -> so try to opt-in with the license key.
7107
+ */
7108
+ $current_blog_id = get_current_blog_id();
7109
+ $license = clone $this->_license;
7110
+
7111
+ $this->switch_to_blog( $blog_id );
7112
+
7113
+ // Opt-in with network user.
7114
+ $this->install_with_user(
7115
+ $this->get_network_user(),
7116
+ $license->secret_key,
7117
+ false,
7118
+ false,
7119
+ false
7120
+ );
7121
+
7122
+ if ( is_object( $this->_site ) ) {
7123
+ if ( $this->_site->license_id == $license->id ) {
7124
+ /**
7125
+ * If the license was activated successfully, sync the license data from the remote server.
7126
+ */
7127
+ $this->_license = $license;
7128
+ $this->sync_site_license();
7129
+ }
7130
+ }
7131
+
7132
+ $this->switch_to_blog( $current_blog_id );
7133
+
7134
+ if ( is_object( $this->_site ) ) {
7135
+ // Already connected (with or without a license), so no need to continue.
7136
+ return;
7137
+ }
7138
+ }
7139
+
7140
+ if ( $this->is_network_anonymous() ) {
7141
+ /**
7142
+ * Opt-in was network skipped so automatically skip the opt-in for the new site.
7143
+ */
7144
+ $this->skip_site_connection( $blog_id );
7145
+ } else if ( $this->is_network_delegated_connection() ) {
7146
+ /**
7147
+ * Opt-in was network delegated so automatically delegate the opt-in for the new site's admin.
7148
+ */
7149
+ $this->delegate_site_connection( $blog_id );
7150
+ } else if ( $this->is_network_connected() ) {
7151
+ /**
7152
+ * Opt-in was network activated so automatically opt-in with the network user and new site admin.
7153
+ */
7154
+ $current_blog_id = get_current_blog_id();
7155
+
7156
+ $this->switch_to_blog( $blog_id );
7157
+
7158
+ // Opt-in with network user.
7159
+ $this->install_with_user(
7160
+ $this->get_network_user(),
7161
+ false,
7162
+ false,
7163
+ false,
7164
+ false
7165
+ );
7166
+
7167
+ $this->switch_to_blog( $current_blog_id );
7168
+ } else {
7169
+ /**
7170
+ * If the super-admin mixed different options (connect, skip, delegated):
7171
+ * a) If at least one site connection was delegated, then automatically delegate connection.
7172
+ * b) Otherwise, it means that at least one site was skipped and at least one site was connected. For a simplified UX in the initial release of the multisite network integration, skip the connection for the newly created site. If the super-admin will want to opt-in they can still do that from the network level Account page.
7173
+ */
7174
+ $has_delegated_site = false;
7175
+
7176
+ $sites = self::get_sites();
7177
+ foreach ( $sites as $site ) {
7178
+ $blog_id = self::get_site_blog_id( $site );
7179
+
7180
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
7181
+ $has_delegated_site = true;
7182
+ break;
7183
+ }
7184
+ }
7185
+
7186
+ if ( $has_delegated_site ) {
7187
+ $this->delegate_site_connection( $blog_id );
7188
+ } else {
7189
+ $this->skip_site_connection( $blog_id );
7190
+ }
7191
+ }
7192
+ }
7193
+
7194
+ /**
7195
+ * @author Vova Feldman (@svovaf)
7196
+ * @since 1.1.3
7197
+ *
7198
+ * @param bool|int $network_or_blog_id Since 2.0.0.
7199
+ */
7200
+ private function reset_anonymous_mode( $network_or_blog_id = 0 ) {
7201
+ if ( true === $network_or_blog_id ) {
7202
+ unset( $this->_storage->is_anonymous_ms );
7203
+ } else {
7204
+ $this->_storage->remove( 'is_anonymous', true, $network_or_blog_id );
7205
+ }
7206
+
7207
+ /**
7208
+ * Ensure that this field is also "false", otherwise, if the current module's type is "theme" and the module
7209
+ * has no menus, the opt-in popup will not be shown immediately (in this case, the user will have to click
7210
+ * on the admin notice that contains the opt-in link in order to trigger the opt-in popup).
7211
+ *
7212
+ * @author Leo Fajardo (@leorw)
7213
+ * @since 1.2.2
7214
+ */
7215
+ if ( ! $this->_is_network_active ||
7216
+ 0 === $network_or_blog_id ||
7217
+ get_current_blog_id() == $network_or_blog_id ||
7218
+ ( true === $network_or_blog_id && fs_is_network_admin() )
7219
+ ) {
7220
+ unset( $this->_is_anonymous );
7221
+ }
7222
+ }
7223
+
7224
+ /**
7225
+ * Clears the anonymous mode and redirects to the opt-in screen.
7226
+ *
7227
+ * @author Vova Feldman (@svovaf)
7228
+ * @since 1.1.7
7229
+ */
7230
+ function connect_again() {
7231
+ if ( ! $this->is_anonymous() ) {
7232
+ return;
7233
+ }
7234
+
7235
+ $this->reset_anonymous_mode( fs_is_network_admin() );
7236
+
7237
+ fs_redirect( $this->get_activation_url() );
7238
+ }
7239
+
7240
+ /**
7241
+ * Skip account connect, and set anonymous mode.
7242
+ *
7243
+ * @author Vova Feldman (@svovaf)
7244
+ * @since 1.1.1
7245
+ *
7246
+ * @param array|null $sites Since 2.0.0. Specific sites.
7247
+ * @param bool $skip_all_network Since 2.0.0. If true, skip connection for all sites.
7248
+ */
7249
+ function skip_connection( $sites = null, $skip_all_network = false ) {
7250
+ $this->_logger->entrance();
7251
+
7252
+ $this->_admin_notices->remove_sticky( 'connect_account' );
7253
+
7254
+ if ( $skip_all_network ) {
7255
+ $this->set_anonymous_mode( true, true );
7256
+ }
7257
+
7258
+ if ( ! $skip_all_network && empty( $sites ) ) {
7259
+ $this->skip_site_connection();
7260
+ } else {
7261
+ $uids = array();
7262
+
7263
+ if ( $skip_all_network ) {
7264
+ $this->set_anonymous_mode( true, true );
7265
+
7266
+ $sites = self::get_sites();
7267
+ foreach ( $sites as $site ) {
7268
+ $blog_id = self::get_site_blog_id( $site );
7269
+ $this->skip_site_connection( $blog_id, false );
7270
+ $uids[] = $this->get_anonymous_id( $blog_id );
7271
+ }
7272
+ } else if ( ! empty( $sites ) ) {
7273
+ foreach ( $sites as $site ) {
7274
+ $uids[] = $site['uid'];
7275
+ $this->skip_site_connection( $site['blog_id'], false );
7276
+ }
7277
+ }
7278
+
7279
+ // Send anonymous skip event.
7280
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
7281
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7282
+ 'uids' => $uids,
7283
+ ) );
7284
+ }
7285
+
7286
+ $this->network_upgrade_mode_completed();
7287
+ }
7288
+
7289
+ /**
7290
+ * Skip connection for specific site in the network.
7291
+ *
7292
+ * @author Vova Feldman (@svovaf)
7293
+ * @since 2.0.0
7294
+ *
7295
+ * @param int|null $blog_id
7296
+ * @param bool $send_skip
7297
+ */
7298
+ private function skip_site_connection( $blog_id = null, $send_skip = true ) {
7299
+ $this->_logger->entrance();
7300
+
7301
+ $this->_admin_notices->remove_sticky( 'connect_account', $blog_id );
7302
+
7303
+ $this->set_anonymous_mode( true, $blog_id );
7304
+
7305
+ if ( $send_skip ) {
7306
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
7307
+ 'uids' => array( $this->get_anonymous_id( $blog_id ) ),
7308
+ ) );
7309
+ }
7310
+ }
7311
+
7312
+ /**
7313
+ * Plugin version update hook.
7314
+ *
7315
+ * @author Vova Feldman (@svovaf)
7316
+ * @since 1.0.4
7317
+ */
7318
+ private function update_plugin_version_event() {
7319
+ $this->_logger->entrance();
7320
+
7321
+ if ( ! $this->is_registered() ) {
7322
+ return;
7323
+ }
7324
+
7325
+ $this->schedule_install_sync();
7326
+ // $this->sync_install( array(), true );
7327
+ }
7328
+
7329
+ /**
7330
+ * Generate an MD5 signature of a plugins collection.
7331
+ * This helper methods used to identify changes in a plugins collection.
7332
+ *
7333
+ * @author Vova Feldman (@svovaf)
7334
+ * @since 2.0.0
7335
+ *
7336
+ * @param array [string]array $plugins
7337
+ *
7338
+ * @return string
7339
+ */
7340
+ private function get_plugins_thumbprint( $plugins ) {
7341
+ ksort( $plugins );
7342
+
7343
+ $thumbprint = '';
7344
+ foreach ( $plugins as $basename => $data ) {
7345
+ $thumbprint .= $data['slug'] . ',' .
7346
+ $data['Version'] . ',' .
7347
+ ( $data['is_active'] ? '1' : '0' ) . ';';
7348
+ }
7349
+
7350
+ return md5( $thumbprint );
7351
+ }
7352
+
7353
+ /**
7354
+ * Return a list of modified plugins since the last sync.
7355
+ *
7356
+ * Note:
7357
+ * There's no point to store a plugins counter since even if the number of
7358
+ * plugins didn't change, we still need to check if the versions are all the
7359
+ * same and the activity state is similar.
7360
+ *
7361
+ * @author Vova Feldman (@svovaf)
7362
+ * @since 1.1.8
7363
+ *
7364
+ * @return array|false
7365
+ */
7366
+ private function get_plugins_data_for_api() {
7367
+ // Alias.
7368
+ $site_active_plugins_option_name = 'active_plugins';
7369
+ $network_plugins_option_name = 'all_plugins';
7370
+
7371
+ /**
7372
+ * Collection of all site level active plugins.
7373
+ */
7374
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7375
+
7376
+ if ( ! is_object( $site_active_plugins_cache ) ) {
7377
+ $site_active_plugins_cache = (object) array(
7378
+ 'timestamp' => '',
7379
+ 'md5' => '',
7380
+ 'plugins' => array(),
7381
+ );
7382
+ }
7383
+
7384
+ $time = time();
7385
+
7386
+ if ( ! empty( $site_active_plugins_cache->timestamp ) &&
7387
+ ( $time - $site_active_plugins_cache->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7388
+ ) {
7389
+ // Don't send plugin updates if last update was in the past 5 min.
7390
+ return false;
7391
+ }
7392
+
7393
+ // Write timestamp to lock the logic.
7394
+ $site_active_plugins_cache->timestamp = $time;
7395
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7396
+
7397
+ // Reload options from DB.
7398
+ self::$_accounts->load( true );
7399
+ $site_active_plugins_cache = self::$_accounts->get_option( $site_active_plugins_option_name );
7400
+
7401
+ if ( $time != $site_active_plugins_cache->timestamp ) {
7402
+ // If timestamp is different, then another thread captured the lock.
7403
+ return false;
7404
+ }
7405
+
7406
+ /**
7407
+ * Collection of all plugins (network level).
7408
+ */
7409
+ $network_plugins_cache = self::$_accounts->get_option( $network_plugins_option_name );
7410
+
7411
+ if ( ! is_object( $network_plugins_cache ) ) {
7412
+ $network_plugins_cache = (object) array(
7413
+ 'timestamp' => '',
7414
+ 'md5' => '',
7415
+ 'plugins' => array(),
7416
+ );
7417
+ }
7418
+
7419
+ // Check if there's a change in plugins.
7420
+ $network_plugins = self::get_network_plugins();
7421
+ $site_active_plugins = self::get_site_active_plugins();
7422
+
7423
+ $network_plugins_thumbprint = $this->get_plugins_thumbprint( $network_plugins );
7424
+ $site_active_plugins_thumbprint = $this->get_plugins_thumbprint( $site_active_plugins );
7425
+
7426
+ // Check if plugins status changed (version or active/inactive).
7427
+ $network_plugins_changed = ( $network_plugins_cache->md5 !== $network_plugins_thumbprint );
7428
+ $site_active_plugins_changed = ( $site_active_plugins_cache->md5 !== $site_active_plugins_thumbprint );
7429
+
7430
+ if ( ! $network_plugins_changed &&
7431
+ ! $site_active_plugins_changed
7432
+ ) {
7433
+ // No changes.
7434
+ return array();
7435
+ }
7436
+
7437
+ $plugins_update_data = array();
7438
+
7439
+ foreach ( $network_plugins_cache->plugins as $basename => $data ) {
7440
+ if ( ! isset( $network_plugins[ $basename ] ) ) {
7441
+ // Plugin uninstalled.
7442
+ $uninstalled_plugin_data = $data;
7443
+ $uninstalled_plugin_data['is_active'] = false;
7444
+ $uninstalled_plugin_data['is_uninstalled'] = true;
7445
+ $plugins_update_data[] = $uninstalled_plugin_data;
7446
+
7447
+ unset( $network_plugins[ $basename ] );
7448
+
7449
+ unset( $network_plugins_cache->plugins[ $basename ] );
7450
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7451
+
7452
+ continue;
7453
+ }
7454
+
7455
+ $was_active = $data['is_active'] ||
7456
+ ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7457
+ true === $site_active_plugins_cache->plugins[ $basename ]['is_active'] );
7458
+ $is_active = $network_plugins[ $basename ]['is_active'] ||
7459
+ ( isset( $site_active_plugins[ $basename ] ) &&
7460
+ $site_active_plugins[ $basename ]['is_active'] );
7461
+
7462
+ if ( ! isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7463
+ isset( $site_active_plugins[ $basename ] )
7464
+ ) {
7465
+ // Plugin was site level activated.
7466
+ $site_active_plugins_cache->plugins[ $basename ] = $network_plugins[ $basename ];
7467
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7468
+ } else if ( isset( $site_active_plugins_cache->plugins[ $basename ] ) &&
7469
+ ! isset( $site_active_plugins[ $basename ] )
7470
+ ) {
7471
+ // Plugin was site level deactivated.
7472
+ unset( $site_active_plugins_cache->plugins[ $basename ] );
7473
+ }
7474
+
7475
+ $prev_version = $data['version'];
7476
+ $current_version = $network_plugins[ $basename ]['Version'];
7477
+
7478
+ if ( $was_active !== $is_active || $prev_version !== $current_version ) {
7479
+ // Plugin activated or deactivated, or version changed.
7480
+
7481
+ if ( $was_active !== $is_active ) {
7482
+ if ( $data['is_active'] != $network_plugins[ $basename ]['is_active'] ) {
7483
+ $network_plugins_cache->plugins[ $basename ]['is_active'] = $data['is_active'];
7484
+ }
7485
+ }
7486
+
7487
+ if ( $prev_version !== $current_version ) {
7488
+ $network_plugins_cache->plugins[ $basename ]['Version'] = $current_version;
7489
+ }
7490
+
7491
+ $updated_plugin_data = $data;
7492
+ $updated_plugin_data['is_active'] = $is_active;
7493
+ $updated_plugin_data['version'] = $current_version;
7494
+ $updated_plugin_data['title'] = $network_plugins[ $basename ]['Name'];
7495
+ $plugins_update_data[] = $updated_plugin_data;
7496
+ }
7497
+ }
7498
+
7499
+ // Find new plugins that weren't yet seen before.
7500
+ foreach ( $network_plugins as $basename => $data ) {
7501
+ if ( ! isset( $network_plugins_cache->plugins[ $basename ] ) ) {
7502
+ // New plugin.
7503
+ $new_plugin = array(
7504
+ 'slug' => $data['slug'],
7505
+ 'version' => $data['Version'],
7506
+ 'title' => $data['Name'],
7507
+ 'is_active' => $data['is_active'],
7508
+ 'is_uninstalled' => false,
7509
+ );
7510
+
7511
+ $plugins_update_data[] = $new_plugin;
7512
+ $network_plugins_cache->plugins[ $basename ] = $new_plugin;
7513
+
7514
+ if ( isset( $site_active_plugins[ $basename ] ) ) {
7515
+ $site_active_plugins_cache->plugins[ $basename ] = $new_plugin;
7516
+ $site_active_plugins_cache->plugins[ $basename ]['is_active'] = true;
7517
+ }
7518
+ }
7519
+ }
7520
+
7521
+ $site_active_plugins_cache->md5 = $site_active_plugins_thumbprint;
7522
+ $site_active_plugins_cache->timestamp = $time;
7523
+ self::$_accounts->set_option( $site_active_plugins_option_name, $site_active_plugins_cache, true );
7524
+
7525
+ $network_plugins_cache->md5 = $network_plugins_thumbprint;
7526
+ $network_plugins_cache->timestamp = $time;
7527
+ self::$_accounts->set_option( $network_plugins_option_name, $network_plugins_cache, true );
7528
+
7529
+ return $plugins_update_data;
7530
+ }
7531
+
7532
+ /**
7533
+ * Return a list of modified themes since the last sync.
7534
+ *
7535
+ * Note:
7536
+ * There's no point to store a themes counter since even if the number of
7537
+ * themes didn't change, we still need to check if the versions are all the
7538
+ * same and the activity state is similar.
7539
+ *
7540
+ * @author Vova Feldman (@svovaf)
7541
+ * @since 1.1.8
7542
+ *
7543
+ * @return array|false
7544
+ */
7545
+ private function get_themes_data_for_api() {
7546
+ // Alias.
7547
+ $option_name = 'all_themes';
7548
+
7549
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7550
+
7551
+ if ( ! is_object( $all_cached_themes ) ) {
7552
+ $all_cached_themes = (object) array(
7553
+ 'timestamp' => '',
7554
+ 'md5' => '',
7555
+ 'themes' => array(),
7556
+ );
7557
+ }
7558
+
7559
+ $time = time();
7560
+
7561
+ if ( ! empty( $all_cached_themes->timestamp ) &&
7562
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
7563
+ ) {
7564
+ // Don't send theme updates if last update was in the past 5 min.
7565
+ return false;
7566
+ }
7567
+
7568
+ // Write timestamp to lock the logic.
7569
+ $all_cached_themes->timestamp = $time;
7570
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7571
+
7572
+ // Reload options from DB.
7573
+ self::$_accounts->load( true );
7574
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
7575
+
7576
+ if ( $time != $all_cached_themes->timestamp ) {
7577
+ // If timestamp is different, then another thread captured the lock.
7578
+ return false;
7579
+ }
7580
+
7581
+ // Get active theme.
7582
+ $active_theme = wp_get_theme();
7583
+ $active_theme_stylesheet = $active_theme->get_stylesheet();
7584
+
7585
+ // Check if there's a change in themes.
7586
+ $all_themes = wp_get_themes();
7587
+
7588
+ // Check if themes changed.
7589
+ ksort( $all_themes );
7590
+
7591
+ $themes_signature = '';
7592
+ foreach ( $all_themes as $slug => $data ) {
7593
+ $is_active = ( $slug === $active_theme_stylesheet );
7594
+ $themes_signature .= $slug . ',' .
7595
+ $data->version . ',' .
7596
+ ( $is_active ? '1' : '0' ) . ';';
7597
+ }
7598
+
7599
+ // Check if themes status changed (version or active/inactive).
7600
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
7601
+
7602
+ $themes_update_data = array();
7603
+
7604
+ if ( $themes_changed ) {
7605
+ // Change in themes, report changes.
7606
+
7607
+ // Update existing themes info.
7608
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
7609
+ $is_active = ( $slug === $active_theme_stylesheet );
7610
+
7611
+ if ( ! isset( $all_themes[ $slug ] ) ) {
7612
+ // Plugin uninstalled.
7613
+ $uninstalled_theme_data = $data;
7614
+ $uninstalled_theme_data['is_active'] = false;
7615
+ $uninstalled_theme_data['is_uninstalled'] = true;
7616
+ $themes_update_data[] = $uninstalled_theme_data;
7617
+
7618
+ unset( $all_themes[ $slug ] );
7619
+ unset( $all_cached_themes->themes[ $slug ] );
7620
+ } else if ( $data['is_active'] !== $is_active ||
7621
+ $data['version'] !== $all_themes[ $slug ]->version
7622
+ ) {
7623
+ // Plugin activated or deactivated, or version changed.
7624
+
7625
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
7626
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
7627
+
7628
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
7629
+ }
7630
+ }
7631
+
7632
+ // Find new themes that weren't yet seen before.
7633
+ foreach ( $all_themes as $slug => $data ) {
7634
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
7635
+ $is_active = ( $slug === $active_theme_stylesheet );
7636
+
7637
+ // New plugin.
7638
+ $new_plugin = array(
7639
+ 'slug' => $slug,
7640
+ 'version' => $data->version,
7641
+ 'title' => $data->name,
7642
+ 'is_active' => $is_active,
7643
+ 'is_uninstalled' => false,
7644
+ );
7645
+
7646
+ $themes_update_data[] = $new_plugin;
7647
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
7648
+ }
7649
+ }
7650
+
7651
+ $all_cached_themes->md5 = md5( $themes_signature );
7652
+ $all_cached_themes->timestamp = time();
7653
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
7654
+ }
7655
+
7656
+ return $themes_update_data;
7657
+ }
7658
+
7659
+ /**
7660
+ * Get site data for API install request.
7661
+ *
7662
+ * @author Vova Feldman (@svovaf)
7663
+ * @since 1.1.2
7664
+ *
7665
+ * @param string[] string $override
7666
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
7667
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
7668
+ *
7669
+ * @return array
7670
+ */
7671
+ private function get_install_data_for_api(
7672
+ array $override,
7673
+ $include_plugins = true,
7674
+ $include_themes = true
7675
+ ) {
7676
+ /**
7677
+ * @since 1.1.8 Also send plugin updates.
7678
+ */
7679
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
7680
+ $plugins = $this->get_plugins_data_for_api();
7681
+ if ( ! empty( $plugins ) ) {
7682
+ $override['plugins'] = $plugins;
7683
+ }
7684
+ }
7685
+ /**
7686
+ * @since 1.1.8 Also send themes updates.
7687
+ */
7688
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
7689
+ $themes = $this->get_themes_data_for_api();
7690
+ if ( ! empty( $themes ) ) {
7691
+ $override['themes'] = $themes;
7692
+ }
7693
+ }
7694
+
7695
+ return array_merge( array(
7696
+ 'version' => $this->get_plugin_version(),
7697
+ 'is_premium' => $this->is_premium(),
7698
+ 'language' => get_bloginfo( 'language' ),
7699
+ 'charset' => get_bloginfo( 'charset' ),
7700
+ 'platform_version' => get_bloginfo( 'version' ),
7701
+ 'sdk_version' => $this->version,
7702
+ 'programming_language_version' => phpversion(),
7703
+ 'title' => get_bloginfo( 'name' ),
7704
+ 'url' => get_site_url(),
7705
+ // Special params.
7706
+ 'is_active' => true,
7707
+ 'is_disconnected' => $this->is_tracking_prohibited(),
7708
+ 'is_uninstalled' => false,
7709
+ ), $override );
7710
+ }
7711
+
7712
+ /**
7713
+ * Update installs details.
7714
+ *
7715
+ * @todo V1 of multiste network support doesn't support plugin and theme data sending.
7716
+ *
7717
+ * @author Vova Feldman (@svovaf)
7718
+ * @since 2.0.0
7719
+ *
7720
+ * @param string[] string $override
7721
+ * @param bool $only_diff
7722
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
7723
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
7724
+ *
7725
+ * @return array
7726
+ */
7727
+ private function get_installs_data_for_api(
7728
+ array $override,
7729
+ $only_diff = false,
7730
+ $include_plugins = true,
7731
+ $include_themes = true
7732
+ ) {
7733
+ /**
7734
+ * @since 1.1.8 Also send plugin updates.
7735
+ */
7736
+ // if ( $include_plugins && ! isset( $override['plugins'] ) ) {
7737
+ // $plugins = $this->get_plugins_data_for_api();
7738
+ // if ( ! empty( $plugins ) ) {
7739
+ // $override['plugins'] = $plugins;
7740
+ // }
7741
+ // }
7742
+ /**
7743
+ * @since 1.1.8 Also send themes updates.
7744
+ */
7745
+ // if ( $include_themes && ! isset( $override['themes'] ) ) {
7746
+ // $themes = $this->get_themes_data_for_api();
7747
+ // if ( ! empty( $themes ) ) {
7748
+ // $override['themes'] = $themes;
7749
+ // }
7750
+ // }
7751
+
7752
+ // Common properties.
7753
+ $common = array_merge( array(
7754
+ 'version' => $this->get_plugin_version(),
7755
+ 'is_premium' => $this->is_premium(),
7756
+ 'sdk_version' => $this->version,
7757
+ 'programming_language_version' => phpversion(),
7758
+ 'platform_version' => get_bloginfo( 'version' ),
7759
+ ), $override );
7760
+
7761
+
7762
+ $is_common_diff_for_any_site = false;
7763
+ $common_diff_union = array();
7764
+
7765
+ $installs_data = array();
7766
+
7767
+ $sites = self::get_sites();
7768
+
7769
+ foreach ( $sites as $site ) {
7770
+ $blog_id = self::get_site_blog_id( $site );
7771
+
7772
+ $install = $this->get_install_by_blog_id( $blog_id );
7773
+
7774
+ if ( is_object( $install ) ) {
7775
+ if ( $install->user_id != $this->_user->id ) {
7776
+ // Install belongs to a different owner.
7777
+ continue;
7778
+ }
7779
+
7780
+ if ( ! $this->is_premium() && $install->is_tracking_prohibited() ) {
7781
+ // Don't send updates regarding opted-out installs.
7782
+ continue;
7783
+ }
7784
+
7785
+ $install_data = $this->get_site_info( $site );
7786
+
7787
+ $uid = $install_data['uid'];
7788
+
7789
+ unset( $install_data['blog_id'] );
7790
+ unset( $install_data['uid'] );
7791
+
7792
+ $install_data['is_disconnected'] = $install->is_disconnected;
7793
+ $install_data['is_active'] = $this->is_active_for_site( $blog_id );
7794
+ $install_data['is_uninstalled'] = $install->is_uninstalled;
7795
+
7796
+ $common_diff = null;
7797
+ $is_common_diff = false;
7798
+ if ( $only_diff ) {
7799
+ $install_data = $this->get_install_diff_for_api( $install_data, $install, $override );
7800
+ $common_diff = $this->get_install_diff_for_api( $common, $install, $override );
7801
+
7802
+ $is_common_diff = ! empty( $common_diff );
7803
+
7804
+ if ( $is_common_diff ) {
7805
+ foreach ( $common_diff as $k => $v ) {
7806
+ if ( ! isset( $common_diff_union[ $k ] ) ) {
7807
+ $common_diff_union[ $k ] = $v;
7808
+ }
7809
+ }
7810
+ }
7811
+
7812
+ $is_common_diff_for_any_site = $is_common_diff_for_any_site || $is_common_diff;
7813
+ }
7814
+
7815
+ if ( ! empty( $install_data ) || $is_common_diff ) {
7816
+ // Add install ID and site unique ID.
7817
+ $install_data['id'] = $install->id;
7818
+ $install_data['uid'] = $uid;
7819
+
7820
+ $installs_data[] = $install_data;
7821
+ }
7822
+ }
7823
+ }
7824
+
7825
+ restore_current_blog();
7826
+
7827
+ if ( 0 < count( $installs_data ) && ( $is_common_diff_for_any_site || ! $only_diff ) ) {
7828
+ if ( ! $only_diff ) {
7829
+ $installs_data[] = $common;
7830
+ } else if ( ! empty( $common_diff_union ) ) {
7831
+ $installs_data[] = $common_diff_union;
7832
+ }
7833
+ }
7834
+
7835
+ foreach ( $installs_data as &$data ) {
7836
+ $data = (object) $data;
7837
+ }
7838
+
7839
+ return $installs_data;
7840
+ }
7841
+
7842
+ /**
7843
+ * Compare site actual data to the stored install data and return the differences for an API data sync.
7844
+ *
7845
+ * @author Vova Feldman (@svovaf)
7846
+ * @since 2.0.0
7847
+ *
7848
+ * @param array $site
7849
+ * @param FS_Site $install
7850
+ * @param string[] string $override
7851
+ *
7852
+ * @return array
7853
+ */
7854
+ private function get_install_diff_for_api( $site, $install, $override = array() ) {
7855
+ $diff = array();
7856
+ $special = array();
7857
+ $special_override = false;
7858
+
7859
+ foreach ( $site as $p => $v ) {
7860
+ if ( property_exists( $install, $p ) ) {
7861
+ if ( ( is_bool( $install->{$p} ) || ! empty( $install->{$p} ) ) &&
7862
+ $install->{$p} != $v
7863
+ ) {
7864
+ $install->{$p} = $v;
7865
+ $diff[ $p ] = $v;
7866
+ }
7867
+ } else {
7868
+ $special[ $p ] = $v;
7869
+
7870
+ if ( isset( $override[ $p ] ) ||
7871
+ 'plugins' === $p ||
7872
+ 'themes' === $p
7873
+ ) {
7874
+ $special_override = true;
7875
+ }
7876
+ }
7877
+ }
7878
+
7879
+ if ( $special_override || 0 < count( $diff ) ) {
7880
+ // Add special params only if has at least one
7881
+ // standard param, or if explicitly requested to
7882
+ // override a special param or a param which is not exist
7883
+ // in the install object.
7884
+ $diff = array_merge( $diff, $special );
7885
+ }
7886
+
7887
+ return $diff;
7888
+ }
7889
+
7890
+ /**
7891
+ * Update install only if changed.
7892
+ *
7893
+ * @author Vova Feldman (@svovaf)
7894
+ * @since 1.0.9
7895
+ *
7896
+ * @param string[] string $override
7897
+ * @param bool $flush
7898
+ *
7899
+ * @return false|object|string
7900
+ */
7901
+ private function send_install_update( $override = array(), $flush = false ) {
7902
+ $this->_logger->entrance();
7903
+
7904
+ $check_properties = $this->get_install_data_for_api( $override );
7905
+
7906
+ if ( $flush ) {
7907
+ $params = $check_properties;
7908
+ } else {
7909
+ $params = $this->get_install_diff_for_api( $check_properties, $this->_site, $override );
7910
+ }
7911
+
7912
+ if ( 0 < count( $params ) ) {
7913
+ if ( ! is_multisite() ) {
7914
+ // Update last install sync timestamp.
7915
+ $this->set_cron_execution_timestamp( 'install_sync' );
7916
+ }
7917
+
7918
+ $params['uid'] = $this->get_anonymous_id();
7919
+
7920
+ // Send updated values to FS.
7921
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
7922
+
7923
+ if ( $this->is_api_result_entity( $site ) ) {
7924
+ if ( ! is_multisite() ) {
7925
+ // I successfully sent install update, clear scheduled sync if exist.
7926
+ $this->clear_install_sync_cron();
7927
+ }
7928
+ }
7929
+
7930
+ return $site;
7931
+ }
7932
+
7933
+ return false;
7934
+ }
7935
+
7936
+ /**
7937
+ * Update installs only if changed.
7938
+ *
7939
+ * @author Vova Feldman (@svovaf)
7940
+ * @since 2.0.0
7941
+ *
7942
+ * @param string[] string $override
7943
+ * @param bool $flush
7944
+ *
7945
+ * @return false|object|string
7946
+ */
7947
+ private function send_installs_update( $override = array(), $flush = false ) {
7948
+ $this->_logger->entrance();
7949
+
7950
+ $installs_data = $this->get_installs_data_for_api( $override, ! $flush );
7951
+
7952
+ if ( empty( $installs_data ) ) {
7953
+ return false;
7954
+ }
7955
+
7956
+ // Update last install sync timestamp.
7957
+ $this->set_cron_execution_timestamp( 'install_sync' );
7958
+
7959
+ // Send updated values to FS.
7960
+ $result = $this->get_api_user_scope()->call( "/plugins/{$this->_plugin->id}/installs.json", 'put', $installs_data );
7961
+
7962
+ if ( $this->is_api_result_object( $result, 'installs' ) ) {
7963
+ // I successfully sent installs update, clear scheduled sync if exist.
7964
+ $this->clear_install_sync_cron();
7965
+ }
7966
+
7967
+ return $result;
7968
+ }
7969
+
7970
+ /**
7971
+ * Update install only if changed.
7972
+ *
7973
+ * @author Vova Feldman (@svovaf)
7974
+ * @since 1.0.9
7975
+ *
7976
+ * @param string[] string $override
7977
+ * @param bool $flush
7978
+ */
7979
+ private function sync_install( $override = array(), $flush = false ) {
7980
+ $this->_logger->entrance();
7981
+
7982
+ $site = $this->send_install_update( $override, $flush );
7983
+
7984
+ if ( false === $site ) {
7985
+ // No sync required.
7986
+ return;
7987
+ }
7988
+
7989
+ if ( ! $this->is_api_result_entity( $site ) ) {
7990
+ // Failed to sync, don't update locally.
7991
+ return;
7992
+ }
7993
+
7994
+ $this->_site = new FS_Site( $site );
7995
+
7996
+ $this->_store_site( true );
7997
+ }
7998
+
7999
+ /**
8000
+ * Update install only if changed.
8001
+ *
8002
+ * @author Vova Feldman (@svovaf)
8003
+ * @since 1.0.9
8004
+ *
8005
+ * @param string[] string $override
8006
+ * @param bool $flush
8007
+ */
8008
+ private function sync_installs( $override = array(), $flush = false ) {
8009
+ $this->_logger->entrance();
8010
+
8011
+ $result = $this->send_installs_update( $override, $flush );
8012
+
8013
+ if ( false === $result ) {
8014
+ // No sync required.
8015
+ return;
8016
+ }
8017
+
8018
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
8019
+ // Failed to sync, don't update locally.
8020
+ return;
8021
+ }
8022
+
8023
+ $address_to_blog_map = $this->get_address_to_blog_map();
8024
+
8025
+ foreach ( $result->installs as $install ) {
8026
+ $this->_site = new FS_Site( $install );
8027
+
8028
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
8029
+ $blog_id = $address_to_blog_map[ $address ];
8030
+
8031
+ $this->_store_site( true, $blog_id );
8032
+ }
8033
+ }
8034
+
8035
+ /**
8036
+ * Track install's custom event.
8037
+ *
8038
+ * IMPORTANT:
8039
+ * Custom event tracking is currently only supported for specific clients.
8040
+ * If you are not one of them, please don't use this method. If you will,
8041
+ * the API will simply ignore your request based on the plugin ID.
8042
+ *
8043
+ * Need custom tracking for your plugin or theme?
8044
+ * If you are interested in custom event tracking please contact yo@freemius.com
8045
+ * for further details.
8046
+ *
8047
+ * @author Vova Feldman (@svovaf)
8048
+ * @since 1.2.1
8049
+ *
8050
+ * @param string $name Event name.
8051
+ * @param array $properties Associative key/value array with primitive values only
8052
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8053
+ * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
8054
+ *
8055
+ * @return object|false Event data or FALSE on failure.
8056
+ *
8057
+ * @throws \Freemius_InvalidArgumentException
8058
+ */
8059
+ public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
8060
+ $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
8061
+
8062
+ if ( ! $this->is_registered() ) {
8063
+ return false;
8064
+ }
8065
+
8066
+ $event = array( 'type' => $name );
8067
+
8068
+ if ( is_numeric( $process_at ) && $process_at > time() ) {
8069
+ $event['process_at'] = $process_at;
8070
+ }
8071
+
8072
+ if ( $once ) {
8073
+ $event['once'] = true;
8074
+ }
8075
+
8076
+ if ( ! empty( $properties ) ) {
8077
+ // Verify associative array values are primitive.
8078
+ foreach ( $properties as $k => $v ) {
8079
+ if ( ! is_scalar( $v ) ) {
8080
+ throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
8081
+ }
8082
+ }
8083
+
8084
+ $event['properties'] = $properties;
8085
+ }
8086
+
8087
+ $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
8088
+
8089
+ return $this->is_api_error( $result ) ?
8090
+ false :
8091
+ $result;
8092
+ }
8093
+
8094
+ /**
8095
+ * Track install's custom event only once, but it still triggers the API call.
8096
+ *
8097
+ * IMPORTANT:
8098
+ * Custom event tracking is currently only supported for specific clients.
8099
+ * If you are not one of them, please don't use this method. If you will,
8100
+ * the API will simply ignore your request based on the plugin ID.
8101
+ *
8102
+ * Need custom tracking for your plugin or theme?
8103
+ * If you are interested in custom event tracking please contact yo@freemius.com
8104
+ * for further details.
8105
+ *
8106
+ * @author Vova Feldman (@svovaf)
8107
+ * @since 1.2.1
8108
+ *
8109
+ * @param string $name Event name.
8110
+ * @param array $properties Associative key/value array with primitive values only
8111
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
8112
+ *
8113
+ * @return object|false Event data or FALSE on failure.
8114
+ *
8115
+ * @throws \Freemius_InvalidArgumentException
8116
+ *
8117
+ * @user Freemius::track_event()
8118
+ */
8119
+ public function track_event_once( $name, $properties = array(), $process_at = false ) {
8120
+ return $this->track_event( $name, $properties, $process_at, true );
8121
+ }
8122
+
8123
+ /**
8124
+ * Plugin uninstall hook.
8125
+ *
8126
+ * @author Vova Feldman (@svovaf)
8127
+ * @since 1.0.1
8128
+ *
8129
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
8130
+ */
8131
+ function _uninstall_plugin_event( $check_user = true ) {
8132
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
8133
+
8134
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
8135
+ return;
8136
+ }
8137
+
8138
+ $params = array();
8139
+ $uninstall_reason = null;
8140
+ if ( isset( $this->_storage->uninstall_reason ) ) {
8141
+ $uninstall_reason = $this->_storage->uninstall_reason;
8142
+ $params['reason_id'] = $uninstall_reason->id;
8143
+ $params['reason_info'] = $uninstall_reason->info;
8144
+ }
8145
+
8146
+ if ( ! $this->is_registered() ) {
8147
+ // Send anonymous uninstall event only if user submitted a feedback.
8148
+ if ( isset( $uninstall_reason ) ) {
8149
+ if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
8150
+ $this->opt_in( false, false, false, false, true );
8151
+ } else {
8152
+ $params['uid'] = $this->get_anonymous_id();
8153
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
8154
+ }
8155
+ }
8156
+ } else {
8157
+ $params = array_merge( $params, array(
8158
+ 'is_active' => false,
8159
+ 'is_uninstalled' => true,
8160
+ ) );
8161
+
8162
+ if ( $this->_is_network_active ) {
8163
+ // Send uninstall event.
8164
+ $this->send_installs_update( $params );
8165
+ } else {
8166
+ // Send uninstall event.
8167
+ $this->send_install_update( $params );
8168
+ }
8169
+ }
8170
+
8171
+ // @todo Decide if we want to delete plugin information from db.
8172
+ }
8173
+
8174
+ /**
8175
+ * @author Vova Feldman (@svovaf)
8176
+ * @since 1.1.1
8177
+ *
8178
+ * @return string
8179
+ */
8180
+ function premium_plugin_basename() {
8181
+ return "{$this->_slug}-premium/" . basename( $this->_free_plugin_basename );
8182
+ }
8183
+
8184
+ /**
8185
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
8186
+ *
8187
+ * @author Vova Feldman (@svovaf)
8188
+ * @since 1.0.2
8189
+ */
8190
+ public static function _uninstall_plugin_hook() {
8191
+ self::_load_required_static();
8192
+
8193
+ self::$_static_logger->entrance();
8194
+
8195
+ if ( ! current_user_can( 'activate_plugins' ) ) {
8196
+ return;
8197
+ }
8198
+
8199
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
8200
+
8201
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
8202
+
8203
+ define( 'WP_FS__UNINSTALL_MODE', true );
8204
+
8205
+ $fs = self::get_instance_by_file( $plugin_file );
8206
+
8207
+ if ( is_object( $fs ) ) {
8208
+ self::require_plugin_essentials();
8209
+
8210
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
8211
+ is_plugin_active( $fs->premium_plugin_basename() )
8212
+ ) {
8213
+ // Deleting Free or Premium plugin version while the other version still installed.
8214
+ return;
8215
+ }
8216
+
8217
+ $fs->_uninstall_plugin_event();
8218
+
8219
+ $fs->do_action( 'after_uninstall' );
8220
+ }
8221
+ }
8222
+
8223
+ #----------------------------------------------------------------------------------
8224
+ #region Plugin Information
8225
+ #----------------------------------------------------------------------------------
8226
+
8227
+ /**
8228
+ * Load WordPress core plugin.php essential module.
8229
+ *
8230
+ * @author Vova Feldman (@svovaf)
8231
+ * @since 1.1.1
8232
+ */
8233
+ private static function require_plugin_essentials() {
8234
+ if ( ! function_exists( 'get_plugins' ) ) {
8235
+ self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
8236
+
8237
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
8238
+ }
8239
+ }
8240
+
8241
+ /**
8242
+ * Load WordPress core pluggable.php module.
8243
+ *
8244
+ * @author Vova Feldman (@svovaf)
8245
+ * @since 1.1.2
8246
+ */
8247
+ private static function require_pluggable_essentials() {
8248
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
8249
+ require_once ABSPATH . 'wp-includes/pluggable.php';
8250
+ }
8251
+ }
8252
+
8253
+ /**
8254
+ * Return plugin data.
8255
+ *
8256
+ * @author Vova Feldman (@svovaf)
8257
+ * @since 1.0.1
8258
+ *
8259
+ * @return array
8260
+ */
8261
+ function get_plugin_data() {
8262
+ if ( ! isset( $this->_plugin_data ) ) {
8263
+ self::require_plugin_essentials();
8264
+
8265
+ if ( $this->is_plugin() ) {
8266
+ /**
8267
+ * @author Vova Feldman (@svovaf)
8268
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
8269
+ *
8270
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
8271
+ */
8272
+ $plugin_data = get_plugin_data(
8273
+ $this->_plugin_main_file_path,
8274
+ false,
8275
+ false
8276
+ );
8277
+ } else {
8278
+ $theme_data = wp_get_theme();
8279
+
8280
+ if ( $this->_plugin_basename !== $theme_data->get_stylesheet() && is_child_theme() ) {
8281
+ $parent_theme = $theme_data->parent();
8282
+
8283
+ if ( ( $parent_theme instanceof WP_Theme ) && $this->_plugin_basename === $parent_theme->get_stylesheet() ) {
8284
+ $theme_data = $parent_theme;
8285
+ }
8286
+ }
8287
+
8288
+ $plugin_data = array(
8289
+ 'Name' => $theme_data->get( 'Name' ),
8290
+ 'Version' => $theme_data->get( 'Version' ),
8291
+ 'Author' => $theme_data->get( 'Author' ),
8292
+ 'Description' => $theme_data->get( 'Description' ),
8293
+ 'PluginURI' => $theme_data->get( 'ThemeURI' ),
8294
+ );
8295
+ }
8296
+
8297
+ $this->_plugin_data = $plugin_data;
8298
+ }
8299
+
8300
+ return $this->_plugin_data;
8301
+ }
8302
+
8303
+ /**
8304
+ * @author Vova Feldman (@svovaf)
8305
+ * @since 1.0.1
8306
+ * @since 1.2.2.5 If slug not set load slug by module ID.
8307
+ *
8308
+ * @return string Plugin slug.
8309
+ */
8310
+ function get_slug() {
8311
+ if ( ! isset( $this->_slug ) ) {
8312
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
8313
+ $this->_slug = $id_slug_type_path_map[ $this->_module_id ]['slug'];
8314
+ }
8315
+
8316
+ return $this->_slug;
8317
+ }
8318
+
8319
+ /**
8320
+ * @author Vova Feldman (@svovaf)
8321
+ * @since 1.2.1.7
8322
+ *
8323
+ * @return string Plugin slug.
8324
+ */
8325
+ function get_target_folder_name() {
8326
+ return $this->_slug . ( $this->can_use_premium_code() ? '-premium' : '' );
8327
+ }
8328
+
8329
+ /**
8330
+ * @author Vova Feldman (@svovaf)
8331
+ * @since 1.0.1
8332
+ *
8333
+ * @return number Plugin ID.
8334
+ */
8335
+ function get_id() {
8336
+ return $this->_plugin->id;
8337
+ }
8338
+
8339
+ /**
8340
+ * @author Vova Feldman (@svovaf)
8341
+ * @since 1.2.1.5
8342
+ *
8343
+ * @return string Freemius SDK version
8344
+ */
8345
+ function get_sdk_version() {
8346
+ return $this->version;
8347
+ }
8348
+
8349
+ /**
8350
+ * @author Vova Feldman (@svovaf)
8351
+ * @since 1.2.1.5
8352
+ *
8353
+ * @return number Parent plugin ID (if parent exist).
8354
+ */
8355
+ function get_parent_id() {
8356
+ return $this->is_addon() ?
8357
+ $this->get_parent_instance()->get_id() :
8358
+ $this->_plugin->id;
8359
+ }
8360
+
8361
+ /**
8362
+ * @author Vova Feldman (@svovaf)
8363
+ * @since 1.0.1
8364
+ *
8365
+ * @return string Plugin public key.
8366
+ */
8367
+ function get_public_key() {
8368
+ return $this->_plugin->public_key;
8369
+ }
8370
+
8371
+ /**
8372
+ * Will be available only on sandbox mode.
8373
+ *
8374
+ * @author Vova Feldman (@svovaf)
8375
+ * @since 1.0.4
8376
+ *
8377
+ * @return mixed Plugin secret key.
8378
+ */
8379
+ function get_secret_key() {
8380
+ return $this->_plugin->secret_key;
8381
+ }
8382
+
8383
+ /**
8384
+ * @author Vova Feldman (@svovaf)
8385
+ * @since 1.1.1
8386
+ *
8387
+ * @return bool
8388
+ */
8389
+ function has_secret_key() {
8390
+ return ! empty( $this->_plugin->secret_key );
8391
+ }
8392
+
8393
+ /**
8394
+ * @author Vova Feldman (@svovaf)
8395
+ * @since 1.0.9
8396
+ *
8397
+ * @return string
8398
+ */
8399
+ function get_plugin_name() {
8400
+ $this->_logger->entrance();
8401
+
8402
+ if ( ! isset( $this->_plugin_name ) ) {
8403
+ $plugin_data = $this->get_plugin_data();
8404
+
8405
+ // Get name.
8406
+ $this->_plugin_name = $plugin_data['Name'];
8407
+
8408
+ // Check if plugin name contains "(Premium)" suffix and remove it.
8409
+ $suffix = ' (premium)';
8410
+ $suffix_len = strlen( $suffix );
8411
+
8412
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
8413
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
8414
+ ) {
8415
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
8416
+ }
8417
+
8418
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
8419
+ }
8420
+
8421
+ return $this->_plugin_name;
8422
+ }
8423
+
8424
+ /**
8425
+ * @author Vova Feldman (@svovaf)
8426
+ * @since 1.0.0
8427
+ *
8428
+ * @return string
8429
+ */
8430
+ function get_plugin_version() {
8431
+ $this->_logger->entrance();
8432
+
8433
+ $plugin_data = $this->get_plugin_data();
8434
+
8435
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
8436
+
8437
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
8438
+ }
8439
+
8440
+ /**
8441
+ * @author Vova Feldman (@svovaf)
8442
+ * @since 1.2.1.7
8443
+ *
8444
+ * @return string
8445
+ */
8446
+ function get_plugin_title() {
8447
+ $this->_logger->entrance();
8448
+
8449
+ $title = $this->_plugin->title;
8450
+
8451
+ return $this->apply_filters( 'plugin_title', $title );
8452
+ }
8453
+
8454
+ /**
8455
+ * @author Vova Feldman (@svovaf)
8456
+ * @since 1.2.2.7
8457
+ *
8458
+ * @param bool $lowercase
8459
+ *
8460
+ * @return string
8461
+ */
8462
+ function get_module_label( $lowercase = false ) {
8463
+ $label = $this->is_addon() ?
8464
+ $this->get_text_inline( 'Add-On', 'addon' ) :
8465
+ ( $this->is_plugin() ?
8466
+ $this->get_text_inline( 'Plugin', 'plugin' ) :
8467
+ $this->get_text_inline( 'Theme', 'theme' ) );
8468
+
8469
+ if ( $lowercase ) {
8470
+ $label = strtolower( $label );
8471
+ }
8472
+
8473
+ return $label;
8474
+ }
8475
+
8476
+ /**
8477
+ * @author Vova Feldman (@svovaf)
8478
+ * @since 1.0.4
8479
+ *
8480
+ * @return string
8481
+ */
8482
+ function get_plugin_basename() {
8483
+ if ( ! isset( $this->_plugin_basename ) ) {
8484
+ if ( $this->is_plugin() ) {
8485
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
8486
+ } else {
8487
+ $this->_plugin_basename = basename( dirname( $this->_plugin_main_file_path ) );
8488
+ }
8489
+ }
8490
+
8491
+ return $this->_plugin_basename;
8492
+ }
8493
+
8494
+ function get_plugin_folder_name() {
8495
+ $this->_logger->entrance();
8496
+
8497
+ $plugin_folder = $this->_plugin_basename;
8498
+
8499
+ while ( '.' !== dirname( $plugin_folder ) ) {
8500
+ $plugin_folder = dirname( $plugin_folder );
8501
+ }
8502
+
8503
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
8504
+
8505
+ return $plugin_folder;
8506
+ }
8507
+
8508
+ #endregion ------------------------------------------------------------------
8509
+
8510
+ /* Account
8511
+ ------------------------------------------------------------------------------------------------------------------*/
8512
+
8513
+ /**
8514
+ * Find plugin's slug by plugin's basename.
8515
+ *
8516
+ * @author Vova Feldman (@svovaf)
8517
+ * @since 1.0.9
8518
+ *
8519
+ * @param string $plugin_base_name
8520
+ *
8521
+ * @return false|string
8522
+ */
8523
+ private static function find_slug_by_basename( $plugin_base_name ) {
8524
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
8525
+
8526
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
8527
+ return false;
8528
+ }
8529
+
8530
+ return $file_slug_map[ $plugin_base_name ];
8531
+ }
8532
+
8533
+ /**
8534
+ * Store the map between the plugin's basename to the slug.
8535
+ *
8536
+ * @author Vova Feldman (@svovaf)
8537
+ * @since 1.0.9
8538
+ */
8539
+ private function store_file_slug_map() {
8540
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
8541
+
8542
+ if ( ! array( $file_slug_map ) ) {
8543
+ $file_slug_map = array();
8544
+ }
8545
+
8546
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
8547
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
8548
+ ) {
8549
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
8550
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
8551
+ }
8552
+ }
8553
+
8554
+ /**
8555
+ * @return array[number]FS_User
8556
+ */
8557
+ static function get_all_users() {
8558
+ $users = self::$_accounts->get_option( 'users', array() );
8559
+
8560
+ if ( ! is_array( $users ) ) {
8561
+ $users = array();
8562
+ }
8563
+
8564
+ return $users;
8565
+ }
8566
+
8567
+ /**
8568
+ * @param string $module_type
8569
+ * @param null|int $blog_id Since 2.0.0
8570
+ *
8571
+ * @return array[string]FS_Site
8572
+ */
8573
+ private static function get_all_sites(
8574
+ $module_type = WP_FS__MODULE_TYPE_PLUGIN,
8575
+ $blog_id = null
8576
+ ) {
8577
+ $sites = self::get_account_option( 'sites', $module_type, $blog_id );
8578
+
8579
+ if ( ! is_array( $sites ) ) {
8580
+ $sites = array();
8581
+ }
8582
+
8583
+ return $sites;
8584
+ }
8585
+
8586
+ /**
8587
+ * @author Leo Fajardo (@leorw)
8588
+ *
8589
+ * @since 1.2.2
8590
+ *
8591
+ * @param string $option_name
8592
+ * @param string $module_type
8593
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8594
+ *
8595
+ * @return mixed
8596
+ */
8597
+ private static function get_account_option( $option_name, $module_type = null, $network_level_or_blog_id = null ) {
8598
+ if ( ! is_null( $module_type ) && WP_FS__MODULE_TYPE_PLUGIN !== $module_type ) {
8599
+ $option_name = $module_type . '_' . $option_name;
8600
+ }
8601
+
8602
+ return self::$_accounts->get_option( $option_name, array(), $network_level_or_blog_id );
8603
+ }
8604
+
8605
+ /**
8606
+ * @author Leo Fajardo (@leorw)
8607
+ *
8608
+ * @since 1.2.2
8609
+ *
8610
+ * @param string $option_name
8611
+ * @param mixed $option_value
8612
+ * @param bool $store
8613
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8614
+ */
8615
+ private function set_account_option( $option_name, $option_value, $store, $network_level_or_blog_id = null ) {
8616
+ self::set_account_option_by_module(
8617
+ $this->_module_type,
8618
+ $option_name,
8619
+ $option_value,
8620
+ $store,
8621
+ $network_level_or_blog_id
8622
+ );
8623
+ }
8624
+
8625
+ /**
8626
+ * @author Vova Feldman (@svovaf)
8627
+ *
8628
+ * @since 1.2.2.7
8629
+ *
8630
+ * @param string $module_type
8631
+ * @param string $option_name
8632
+ * @param mixed $option_value
8633
+ * @param bool $store
8634
+ * @param null|int $network_level_or_blog_id Since 2.0.0
8635
+ */
8636
+ private static function set_account_option_by_module(
8637
+ $module_type,
8638
+ $option_name,
8639
+ $option_value,
8640
+ $store,
8641
+ $network_level_or_blog_id = null
8642
+ ) {
8643
+ if ( WP_FS__MODULE_TYPE_PLUGIN != $module_type ) {
8644
+ $option_name = $module_type . '_' . $option_name;
8645
+ }
8646
+
8647
+ self::$_accounts->set_option( $option_name, $option_value, $store, $network_level_or_blog_id );
8648
+ }
8649
+
8650
+ /**
8651
+ * @author Vova Feldman (@svovaf)
8652
+ * @since 1.0.6
8653
+ *
8654
+ * @param number|null $module_id
8655
+ *
8656
+ * @return FS_Plugin_License[]
8657
+ */
8658
+ private static function get_all_licenses( $module_id = null ) {
8659
+ $licenses = self::get_account_option( 'all_licenses' );
8660
+
8661
+ if ( ! is_array( $licenses ) ) {
8662
+ $licenses = array();
8663
+ }
8664
+
8665
+ if ( is_null( $module_id ) ) {
8666
+ return $licenses;
8667
+ }
8668
+
8669
+ $licenses = isset( $licenses[ $module_id ] ) ?
8670
+ $licenses[ $module_id ] :
8671
+ array();
8672
+
8673
+ return $licenses;
8674
+ }
8675
+
8676
+ /**
8677
+ * @author Leo Fajardo (@leorw)
8678
+ * @since 2.0.0
8679
+ *
8680
+ * @return array
8681
+ */
8682
+ private static function get_all_licenses_by_module_type() {
8683
+ $licenses = self::get_account_option( 'all_licenses' );
8684
+
8685
+ $licenses_by_module_type = array(
8686
+ WP_FS__MODULE_TYPE_PLUGIN => array(),
8687
+ WP_FS__MODULE_TYPE_THEME => array()
8688
+ );
8689
+
8690
+ if ( ! is_array( $licenses ) ) {
8691
+ return $licenses_by_module_type;
8692
+ }
8693
+
8694
+ foreach ( $licenses as $module_id => $module_licenses ) {
8695
+ $fs = self::get_instance_by_id( $module_id );
8696
+ if ( false === $fs ) {
8697
+ continue;
8698
+ }
8699
+
8700
+ $licenses_by_module_type[ $fs->_module_type ] = array_merge( $licenses_by_module_type[ $fs->_module_type ], $module_licenses );
8701
+ }
8702
+
8703
+ return $licenses_by_module_type;
8704
+ }
8705
+
8706
+ /**
8707
+ * @author Leo Fajardo (@leorw)
8708
+ * @since 2.0.0
8709
+ *
8710
+ * @param number $module_id
8711
+ * @param number|null $user_id
8712
+ *
8713
+ * @return array
8714
+ */
8715
+ private static function get_user_id_license_ids_map( $module_id, $user_id = null ) {
8716
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
8717
+
8718
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
8719
+ $all_modules_user_id_license_ids_map = array();
8720
+ }
8721
+
8722
+ $user_id_license_ids_map = isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ?
8723
+ $all_modules_user_id_license_ids_map[ $module_id ] :
8724
+ array();
8725
+
8726
+ if ( FS_User::is_valid_id( $user_id ) ) {
8727
+ $user_id_license_ids_map = isset( $user_id_license_ids_map[ $user_id ] ) ?
8728
+ $user_id_license_ids_map[ $user_id ] :
8729
+ array();
8730
+ }
8731
+
8732
+ return $user_id_license_ids_map;
8733
+ }
8734
+
8735
+ /**
8736
+ * @author Leo Fajardo (@leorw)
8737
+ * @since 2.0.0
8738
+ *
8739
+ * @param array $new_user_id_license_ids_map
8740
+ * @param number $module_id
8741
+ * @param number|null $user_id
8742
+ */
8743
+ private static function store_user_id_license_ids_map( $new_user_id_license_ids_map, $module_id, $user_id = null ) {
8744
+ $all_modules_user_id_license_ids_map = self::get_account_option( 'user_id_license_ids_map' );
8745
+ if ( ! is_array( $all_modules_user_id_license_ids_map ) ) {
8746
+ $all_modules_user_id_license_ids_map = array();
8747
+ }
8748
+
8749
+ if ( ! isset( $all_modules_user_id_license_ids_map[ $module_id ] ) ) {
8750
+ $all_modules_user_id_license_ids_map[ $module_id ] = array();
8751
+ }
8752
+
8753
+ if ( FS_User::is_valid_id( $user_id ) ) {
8754
+ $all_modules_user_id_license_ids_map[ $module_id ][ $user_id ] = $new_user_id_license_ids_map;
8755
+ } else {
8756
+ $all_modules_user_id_license_ids_map[ $module_id ] = $new_user_id_license_ids_map;
8757
+ }
8758
+
8759
+ self::$_accounts->set_option( 'user_id_license_ids_map', $all_modules_user_id_license_ids_map, true );
8760
+ }
8761
+
8762
+ /**
8763
+ * Get a collection of the user's linked license IDs.
8764
+ *
8765
+ * @author Vova Feldman (@svovaf)
8766
+ * @since 2.0.0
8767
+ *
8768
+ * @param number $user_id
8769
+ *
8770
+ * @return number[]
8771
+ */
8772
+ private function get_user_linked_license_ids( $user_id ) {
8773
+ return self::get_user_id_license_ids_map( $this->_module_id, $user_id );
8774
+ }
8775
+
8776
+ /**
8777
+ * Override the user's linked license IDs with a new IDs collection.
8778
+ *
8779
+ * @author Vova Feldman (@svovaf)
8780
+ * @since 2.0.0
8781
+ *
8782
+ * @param number $user_id
8783
+ * @param number[] $license_ids
8784
+ */
8785
+ private function set_user_linked_license_ids( $user_id, array $license_ids ) {
8786
+ self::store_user_id_license_ids_map( $license_ids, $this->_module_id, $user_id );
8787
+ }
8788
+
8789
+ /**
8790
+ * Link a specified license ID to a given user.
8791
+ *
8792
+ * @author Vova Feldman (@svovaf)
8793
+ * @since 2.0.0
8794
+ *
8795
+ * @param number $license_id
8796
+ * @param number $user_id
8797
+ */
8798
+ private function link_license_2_user( $license_id, $user_id ) {
8799
+ $license_ids = $this->get_user_linked_license_ids( $user_id );
8800
+
8801
+ if ( in_array( $license_id, $license_ids ) ) {
8802
+ // License already linked.
8803
+ return;
8804
+ }
8805
+
8806
+ $license_ids[] = $license_id;
8807
+
8808
+ $this->set_user_linked_license_ids( $user_id, $license_ids );
8809
+ }
8810
+
8811
+ /**
8812
+ * @param string|bool $module_type
8813
+ *
8814
+ * @return FS_Plugin_Plan[]
8815
+ */
8816
+ private static function get_all_plans( $module_type = false ) {
8817
+ $plans = self::get_account_option( 'plans', $module_type );
8818
+
8819
+ if ( ! is_array( $plans ) ) {
8820
+ $plans = array();
8821
+ }
8822
+
8823
+ return $plans;
8824
+ }
8825
+
8826
+ /**
8827
+ * @author Vova Feldman (@svovaf)
8828
+ * @since 1.0.4
8829
+ *
8830
+ * @return FS_Plugin_Tag[]
8831
+ */
8832
+ private static function get_all_updates() {
8833
+ $updates = self::$_accounts->get_option( 'updates', array() );
8834
+
8835
+ if ( ! is_array( $updates ) ) {
8836
+ $updates = array();
8837
+ }
8838
+
8839
+ return $updates;
8840
+ }
8841
+
8842
+ /**
8843
+ * @author Vova Feldman (@svovaf)
8844
+ * @since 1.0.6
8845
+ *
8846
+ * @return array<number,FS_Plugin[]>|false
8847
+ */
8848
+ private static function get_all_addons() {
8849
+ $addons = self::$_accounts->get_option( 'addons', array() );
8850
+
8851
+ if ( ! is_array( $addons ) ) {
8852
+ $addons = array();
8853
+ }
8854
+
8855
+ return $addons;
8856
+ }
8857
+
8858
+ /**
8859
+ * @author Vova Feldman (@svovaf)
8860
+ * @since 1.0.6
8861
+ *
8862
+ * @return FS_Plugin[]|false
8863
+ */
8864
+ private static function get_all_account_addons() {
8865
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
8866
+
8867
+ if ( ! is_array( $addons ) ) {
8868
+ $addons = array();
8869
+ }
8870
+
8871
+ return $addons;
8872
+ }
8873
+
8874
+ /**
8875
+ * Check if user has connected his account (opted-in).
8876
+ *
8877
+ * Note:
8878
+ * If the user opted-in and opted-out on a later stage,
8879
+ * this will still return true. If you want to check if the
8880
+ * user is currently opted-in, use:
8881
+ * `$fs->is_registered() && $fs->is_tracking_allowed()`
8882
+ *
8883
+ * @author Vova Feldman (@svovaf)
8884
+ * @since 1.0.1
8885
+ * @return bool
8886
+ */
8887
+ function is_registered() {
8888
+ return is_object( $this->_user );
8889
+ }
8890
+
8891
+ /**
8892
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
8893
+ *
8894
+ * @author Leo Fajardo (@leorw)
8895
+ * @since 1.2.1.5
8896
+ *
8897
+ * @return bool
8898
+ */
8899
+ function is_tracking_allowed() {
8900
+ return ( is_object( $this->_site ) && $this->_site->is_tracking_allowed() );
8901
+ }
8902
+
8903
+ /**
8904
+ * @author Vova Feldman (@svovaf)
8905
+ * @since 1.0.4
8906
+ *
8907
+ * @return FS_Plugin
8908
+ */
8909
+ function get_plugin() {
8910
+ return $this->_plugin;
8911
+ }
8912
+
8913
+ /**
8914
+ * @author Vova Feldman (@svovaf)
8915
+ * @since 1.0.3
8916
+ *
8917
+ * @return FS_User
8918
+ */
8919
+ function get_user() {
8920
+ return $this->_user;
8921
+ }
8922
+
8923
+ /**
8924
+ * @author Vova Feldman (@svovaf)
8925
+ * @since 1.0.3
8926
+ *
8927
+ * @return FS_Site
8928
+ */
8929
+ function get_site() {
8930
+ return $this->_site;
8931
+ }
8932
+
8933
+ /**
8934
+ * Get plugin add-ons.
8935
+ *
8936
+ * @author Vova Feldman (@svovaf)
8937
+ * @since 1.0.6
8938
+ *
8939
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
8940
+ *
8941
+ * @param bool $flush
8942
+ *
8943
+ * @return FS_Plugin[]|false
8944
+ */
8945
+ function get_addons( $flush = false ) {
8946
+ $this->_logger->entrance();
8947
+
8948
+ if ( ! $this->_has_addons ) {
8949
+ return false;
8950
+ }
8951
+
8952
+ $addons = $this->sync_addons( $flush );
8953
+
8954
+ return ( ! is_array( $addons ) || empty( $addons ) ) ?
8955
+ false :
8956
+ $addons;
8957
+ }
8958
+
8959
+ /**
8960
+ * @author Vova Feldman (@svovaf)
8961
+ * @since 1.0.6
8962
+ *
8963
+ * @return FS_Plugin[]|false
8964
+ */
8965
+ function get_account_addons() {
8966
+ $this->_logger->entrance();
8967
+
8968
+ $addons = self::get_all_account_addons();
8969
+
8970
+ if ( ! is_array( $addons ) ||
8971
+ ! isset( $addons[ $this->_plugin->id ] ) ||
8972
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
8973
+ 0 === count( $addons[ $this->_plugin->id ] )
8974
+ ) {
8975
+ return false;
8976
+ }
8977
+
8978
+ return $addons[ $this->_plugin->id ];
8979
+ }
8980
+
8981
+ /**
8982
+ * Check if user has any
8983
+ *
8984
+ * @author Vova Feldman (@svovaf)
8985
+ * @since 1.1.6
8986
+ *
8987
+ * @return bool
8988
+ */
8989
+ function has_account_addons() {
8990
+ $addons = $this->get_account_addons();
8991
+
8992
+ return is_array( $addons ) && ( 0 < count( $addons ) );
8993
+ }
8994
+
8995
+
8996
+ /**
8997
+ * Get add-on by ID (from local data).
8998
+ *
8999
+ * @author Vova Feldman (@svovaf)
9000
+ * @since 1.0.6
9001
+ *
9002
+ * @param number $id
9003
+ *
9004
+ * @return FS_Plugin|false
9005
+ */
9006
+ function get_addon( $id ) {
9007
+ $this->_logger->entrance();
9008
+
9009
+ $addons = $this->get_addons();
9010
+
9011
+ if ( is_array( $addons ) ) {
9012
+ foreach ( $addons as $addon ) {
9013
+ if ( $id == $addon->id ) {
9014
+ return $addon;
9015
+ }
9016
+ }
9017
+ }
9018
+
9019
+ return false;
9020
+ }
9021
+
9022
+ /**
9023
+ * Get add-on by slug (from local data).
9024
+ *
9025
+ * @author Vova Feldman (@svovaf)
9026
+ * @since 1.0.6
9027
+ *
9028
+ * @param string $slug
9029
+ *
9030
+ * @param bool $flush
9031
+ *
9032
+ * @return FS_Plugin|false
9033
+ */
9034
+ function get_addon_by_slug( $slug, $flush = false ) {
9035
+ $this->_logger->entrance();
9036
+
9037
+ $addons = $this->get_addons( $flush );
9038
+
9039
+ if ( is_array( $addons ) ) {
9040
+ foreach ( $addons as $addon ) {
9041
+ if ( $slug === $addon->slug ) {
9042
+ return $addon;
9043
+ }
9044
+ }
9045
+ }
9046
+
9047
+ return false;
9048
+ }
9049
+
9050
+ /**
9051
+ * @author Vova Feldman (@svovaf)
9052
+ * @since 2.0.0
9053
+ *
9054
+ * @param number $user_id
9055
+ *
9056
+ * @return FS_User
9057
+ */
9058
+ static function _get_user_by_id( $user_id ) {
9059
+ self::$_static_logger->entrance( "user_id = {$user_id}" );
9060
+
9061
+ $users = self::get_all_users();
9062
+
9063
+ if ( is_array( $users ) ) {
9064
+ if ( isset( $users[ $user_id ] ) &&
9065
+ $users[ $user_id ] instanceof FS_User &&
9066
+ $user_id == $users[ $user_id ]->id
9067
+ ) {
9068
+ return $users[ $user_id ];
9069
+ }
9070
+
9071
+ // If user wasn't found by the key, iterate over all the users collection.
9072
+ foreach ( $users as $user ) {
9073
+ /**
9074
+ * @var FS_User $user
9075
+ */
9076
+ if ( $user_id == $user->id ) {
9077
+ return $user;
9078
+ }
9079
+ }
9080
+ }
9081
+
9082
+ return null;
9083
+ }
9084
+
9085
+ /**
9086
+ * Checks if a Freemius user_id is associated with a super-admin.
9087
+ *
9088
+ * @author Vova Feldman (@svovaf)
9089
+ * @since 2.0.0
9090
+ *
9091
+ * @param number $user_id
9092
+ *
9093
+ * @return bool
9094
+ */
9095
+ private static function is_super_admin( $user_id ) {
9096
+ $is_super_admin = false;
9097
+
9098
+ $user = self::_get_user_by_id( $user_id );
9099
+
9100
+ if ( $user instanceof FS_User && ! empty( $user->email ) ) {
9101
+ self::require_pluggable_essentials();
9102
+
9103
+ $wp_user = get_user_by( 'email', $user->email );
9104
+
9105
+ if ( $wp_user instanceof WP_User ) {
9106
+ $super_admins = get_super_admins();
9107
+ $is_super_admin = ( is_array( $super_admins ) && in_array( $wp_user->user_login, $super_admins ) );
9108
+ }
9109
+ }
9110
+
9111
+ return $is_super_admin;
9112
+ }
9113
+
9114
+ #----------------------------------------------------------------------------------
9115
+ #region Plans & Licensing
9116
+ #----------------------------------------------------------------------------------
9117
+
9118
+ /**
9119
+ * Check if running premium plugin code.
9120
+ *
9121
+ * @author Vova Feldman (@svovaf)
9122
+ * @since 1.0.5
9123
+ *
9124
+ * @return bool
9125
+ */
9126
+ function is_premium() {
9127
+ return $this->_plugin->is_premium;
9128
+ }
9129
+
9130
+ /**
9131
+ * Get site's plan ID.
9132
+ *
9133
+ * @author Vova Feldman (@svovaf)
9134
+ * @since 1.0.2
9135
+ *
9136
+ * @return number
9137
+ */
9138
+ function get_plan_id() {
9139
+ return $this->_site->plan_id;
9140
+ }
9141
+
9142
+ /**
9143
+ * Get site's plan title.
9144
+ *
9145
+ * @author Vova Feldman (@svovaf)
9146
+ * @since 1.0.2
9147
+ *
9148
+ * @return string
9149
+ */
9150
+ function get_plan_title() {
9151
+ $plan = $this->get_plan();
9152
+
9153
+ return is_object( $plan ) ? $plan->title : 'PLAN_TITLE';
9154
+ }
9155
+
9156
+ /**
9157
+ * Get site's plan name.
9158
+ *
9159
+ * @author Vova Feldman (@svovaf)
9160
+ * @since 2.0.0
9161
+ *
9162
+ * @return string
9163
+ */
9164
+ function get_plan_name() {
9165
+ $plan = $this->get_plan();
9166
+
9167
+ return is_object( $plan ) ? $plan->name : 'PLAN_NAME';
9168
+ }
9169
+
9170
+ /**
9171
+ * @author Vova Feldman (@svovaf)
9172
+ * @since 1.0.9
9173
+ *
9174
+ * @return FS_Plugin_Plan|false
9175
+ */
9176
+ function get_plan() {
9177
+ if ( ! is_object( $this->_site ) ) {
9178
+ return false;
9179
+ }
9180
+
9181
+ return FS_Plugin_Plan::is_valid_id( $this->_site->plan_id ) ?
9182
+ $this->_get_plan_by_id( $this->_site->plan_id ) :
9183
+ false;
9184
+ }
9185
+
9186
+ /**
9187
+ * @author Vova Feldman (@svovaf)
9188
+ * @since 1.0.3
9189
+ *
9190
+ * @return bool
9191
+ */
9192
+ function is_trial() {
9193
+ $this->_logger->entrance();
9194
+
9195
+ if ( ! $this->is_registered() || ! is_object( $this->_site ) ) {
9196
+ return false;
9197
+ }
9198
+
9199
+ return $this->_site->is_trial();
9200
+ }
9201
+
9202
+ /**
9203
+ * Check if currently in a trial with payment method (credit card or paypal).
9204
+ *
9205
+ * @author Vova Feldman (@svovaf)
9206
+ * @since 1.1.7
9207
+ *
9208
+ * @return bool
9209
+ */
9210
+ function is_paid_trial() {
9211
+ $this->_logger->entrance();
9212
+
9213
+ if ( ! $this->is_trial() ) {
9214
+ return false;
9215
+ }
9216
+
9217
+ return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
9218
+ }
9219
+
9220
+ /**
9221
+ * Check if trial already utilized.
9222
+ *
9223
+ * @since 1.0.9
9224
+ *
9225
+ * @return bool
9226
+ */
9227
+ function is_trial_utilized() {
9228
+ $this->_logger->entrance();
9229
+
9230
+ if ( ! $this->is_registered() ) {
9231
+ return false;
9232
+ }
9233
+
9234
+ return $this->_site->is_trial_utilized();
9235
+ }
9236
+
9237
+ /**
9238
+ * Get trial plan information (if in trial).
9239
+ *
9240
+ * @author Vova Feldman (@svovaf)
9241
+ * @since 1.0.9
9242
+ *
9243
+ * @return bool|FS_Plugin_Plan
9244
+ */
9245
+ function get_trial_plan() {
9246
+ $this->_logger->entrance();
9247
+
9248
+ if ( ! $this->is_trial() ) {
9249
+ return false;
9250
+ }
9251
+
9252
+ // Try to load plan from local cache.
9253
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
9254
+
9255
+ if ( ! is_object( $trial_plan ) ) {
9256
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
9257
+
9258
+ /**
9259
+ * If managed to fetch the plan, add it to the plans collection.
9260
+ */
9261
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9262
+ if ( ! is_array( $this->_plans ) ) {
9263
+ $this->_plans = array();
9264
+ }
9265
+
9266
+ $this->_plans[] = $trial_plan;
9267
+ $this->_store_plans();
9268
+ }
9269
+ }
9270
+
9271
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
9272
+ return $trial_plan;
9273
+ }
9274
+
9275
+ /**
9276
+ * If for some reason failed to get the trial plan, fallback to a dummy name and title.
9277
+ */
9278
+ $trial_plan = new FS_Plugin_Plan();
9279
+ $trial_plan->id = $this->_site->trial_plan_id;
9280
+ $trial_plan->name = 'pro';
9281
+ $trial_plan->title = 'Pro';
9282
+
9283
+ return $trial_plan;
9284
+ }
9285
+
9286
+ /**
9287
+ * Check if the user has an activate, non-expired license on current plugin's install.
9288
+ *
9289
+ * @since 1.0.9
9290
+ *
9291
+ * @return bool
9292
+ */
9293
+ function is_paying() {
9294
+ $this->_logger->entrance();
9295
+
9296
+ if ( ! $this->is_registered() ) {
9297
+ return false;
9298
+ }
9299
+
9300
+ if ( ! $this->has_paid_plan() ) {
9301
+ return false;
9302
+ }
9303
+
9304
+ return (
9305
+ ! $this->is_trial() &&
9306
+ 'free' !== $this->get_plan_name() &&
9307
+ $this->has_active_valid_license()
9308
+ );
9309
+ }
9310
+
9311
+ /**
9312
+ * @author Vova Feldman (@svovaf)
9313
+ * @since 1.0.4
9314
+ *
9315
+ * @return bool
9316
+ */
9317
+ function is_free_plan() {
9318
+ if ( ! $this->is_registered() ) {
9319
+ return true;
9320
+ }
9321
+
9322
+ if ( ! $this->has_paid_plan() ) {
9323
+ return true;
9324
+ }
9325
+
9326
+ return (
9327
+ 'free' === $this->get_plan_name() ||
9328
+ ! $this->has_features_enabled_license()
9329
+ );
9330
+ }
9331
+
9332
+ /**
9333
+ * @author Vova Feldman (@svovaf)
9334
+ * @since 1.0.5
9335
+ *
9336
+ * @return bool
9337
+ */
9338
+ function _has_premium_license() {
9339
+ $this->_logger->entrance();
9340
+
9341
+ $premium_license = $this->_get_available_premium_license();
9342
+
9343
+ return ( false !== $premium_license );
9344
+ }
9345
+
9346
+ /**
9347
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
9348
+ *
9349
+ * @author Vova Feldman (@svovaf)
9350
+ * @since 1.1.7.3
9351
+ *
9352
+ * @return bool
9353
+ */
9354
+ function has_any_license() {
9355
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
9356
+ }
9357
+
9358
+ /**
9359
+ * @author Vova Feldman (@svovaf)
9360
+ * @since 1.0.5
9361
+ *
9362
+ * @param bool|null $is_localhost
9363
+ *
9364
+ * @return FS_Plugin_License|false
9365
+ */
9366
+ function _get_available_premium_license( $is_localhost = null ) {
9367
+ $this->_logger->entrance();
9368
+
9369
+ $licenses = $this->get_available_premium_licenses( $is_localhost );
9370
+ if ( ! empty( $licenses ) ) {
9371
+ return $licenses[0];
9372
+ }
9373
+
9374
+ return false;
9375
+ }
9376
+
9377
+ /**
9378
+ * @author Vova Feldman (@svovaf)
9379
+ * @since 1.0.5
9380
+ *
9381
+ * @param bool|null $is_localhost
9382
+ *
9383
+ * @return FS_Plugin_License[]
9384
+ */
9385
+ function get_available_premium_licenses( $is_localhost = null ) {
9386
+ $this->_logger->entrance();
9387
+
9388
+ $licenses = array();
9389
+ if ( ! $this->has_paid_plan() ) {
9390
+ return $licenses;
9391
+ }
9392
+
9393
+ if ( is_array( $this->_licenses ) ) {
9394
+ foreach ( $this->_licenses as $license ) {
9395
+ if ( ! $license->can_activate( $is_localhost ) ) {
9396
+ continue;
9397
+ }
9398
+
9399
+ $licenses[] = $license;
9400
+ }
9401
+ }
9402
+
9403
+ return $licenses;
9404
+ }
9405
+
9406
+ /**
9407
+ * Sync local plugin plans with remote server.
9408
+ *
9409
+ * IMPORTANT: If for some reason a site is associated with deleted plan, we'll preserve the plan's information and append it as the last plan. This means that if plan is deleted, the is_plan() method will ALWAYS return true for any given argument (it becomes the most inclusive plan).
9410
+ *
9411
+ * @author Vova Feldman (@svovaf)
9412
+ * @since 1.0.5
9413
+ *
9414
+ * @return FS_Plugin_Plan[]|object
9415
+ */
9416
+ function _sync_plans() {
9417
+ $plans = $this->_fetch_plugin_plans();
9418
+
9419
+ if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
9420
+ $plans_map = array();
9421
+ foreach ( $plans as $plan ) {
9422
+ $plans_map[ $plan->id ] = true;
9423
+ }
9424
+
9425
+ $plans_ids_to_keep = $this->get_plans_ids_associated_with_installs();
9426
+
9427
+ foreach ( $plans_ids_to_keep as $plan_id ) {
9428
+ if ( isset( $plans_map[ $plan_id ] ) ) {
9429
+ continue;
9430
+ }
9431
+
9432
+ $missing_plan = self::_get_plan_by_id( $plan_id );
9433
+
9434
+ if ( is_object( $missing_plan ) ) {
9435
+ $plans[] = $missing_plan;
9436
+ }
9437
+ }
9438
+
9439
+ $this->_plans = $plans;
9440
+ $this->_store_plans();
9441
+ }
9442
+
9443
+ $this->do_action( 'after_plans_sync', $plans );
9444
+
9445
+ return $this->_plans;
9446
+ }
9447
+
9448
+ /**
9449
+ * Check if specified plan exists locally. If not, fetch it and store it.
9450
+ *
9451
+ * @author Vova Feldman (@svovaf)
9452
+ * @since 2.0.0
9453
+ *
9454
+ * @param number $plan_id
9455
+ *
9456
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9457
+ */
9458
+ private function sync_plan_if_not_exist( $plan_id ) {
9459
+ $plan = self::_get_plan_by_id( $plan_id );
9460
+
9461
+ if ( is_object( $plan ) ) {
9462
+ // Plan already exists.
9463
+ return $plan;
9464
+ }
9465
+
9466
+ $plan = $this->fetch_plan_by_id( $plan_id );
9467
+
9468
+ if ( $plan instanceof FS_Plugin_Plan ) {
9469
+ $this->_plans[] = $plan;
9470
+ $this->_store_plans();
9471
+
9472
+ return $plan;
9473
+ }
9474
+
9475
+ return $plan;
9476
+ }
9477
+
9478
+ /**
9479
+ * Check if specified license exists locally. If not, fetch it and store it.
9480
+ *
9481
+ * @author Vova Feldman (@svovaf)
9482
+ * @since 2.0.0
9483
+ *
9484
+ * @param number $license_id
9485
+ * @param string $license_key
9486
+ *
9487
+ * @return \FS_Plugin_Plan|object The plan entity or the API error object on failure.
9488
+ */
9489
+ private function sync_license_if_not_exist( $license_id, $license_key ) {
9490
+ $license = $this->_get_license_by_id( $license_id );
9491
+
9492
+ if ( is_object( $license ) ) {
9493
+ // License already exists.
9494
+ return $license;
9495
+ }
9496
+
9497
+ $license = $this->fetch_license_by_key( $license_id, $license_key );
9498
+
9499
+ if ( $license instanceof FS_Plugin_License ) {
9500
+ $this->_licenses[] = $license;
9501
+ $this->_license = $license;
9502
+ $this->_store_licenses();
9503
+
9504
+ return $license;
9505
+ }
9506
+
9507
+ return $license;
9508
+ }
9509
+
9510
+ /**
9511
+ * Get a collection of unique plan IDs that are associated with any installs in the network.
9512
+ *
9513
+ * @author Leo Fajardo (@leorw)
9514
+ * @since 2.0.0
9515
+ *
9516
+ * @return number[]
9517
+ */
9518
+ private function get_plans_ids_associated_with_installs() {
9519
+ if ( ! $this->_is_network_active ) {
9520
+ if ( ! is_object( $this->_site ) ||
9521
+ ! FS_Plugin_Plan::is_valid_id( $this->_site->plan_id )
9522
+ ) {
9523
+ return array();
9524
+ }
9525
+
9526
+ return array( $this->_site->plan_id );
9527
+ }
9528
+
9529
+ $plan_ids = array();
9530
+ $sites = self::get_sites();
9531
+ foreach ( $sites as $site ) {
9532
+ $blog_id = self::get_site_blog_id( $site );
9533
+ $install = $this->get_install_by_blog_id( $blog_id );
9534
+
9535
+ if ( ! is_object( $install ) ||
9536
+ ! FS_Plugin_Plan::is_valid_id( $install->plan_id )
9537
+ ) {
9538
+ continue;
9539
+ }
9540
+
9541
+ $plan_ids[ $install->plan_id ] = true;
9542
+ }
9543
+
9544
+ return array_keys( $plan_ids );
9545
+ }
9546
+
9547
+ /**
9548
+ * Get a collection of unique license IDs that are associated with any installs in the network.
9549
+ *
9550
+ * @author Leo Fajardo (@leorw)
9551
+ * @since 2.0.0
9552
+ *
9553
+ * @return number[]
9554
+ */
9555
+ private function get_license_ids_associated_with_installs() {
9556
+ if ( ! $this->_is_network_active ) {
9557
+ if ( ! is_object( $this->_site ) ||
9558
+ ! FS_Plugin_License::is_valid_id( $this->_site->license_id )
9559
+ ) {
9560
+ return array();
9561
+ }
9562
+
9563
+ return array( $this->_site->license_id );
9564
+ }
9565
+
9566
+ $license_ids = array();
9567
+ $sites = self::get_sites();
9568
+ foreach ( $sites as $site ) {
9569
+ $blog_id = self::get_site_blog_id( $site );
9570
+ $install = $this->get_install_by_blog_id( $blog_id );
9571
+
9572
+ if ( ! is_object( $install ) ||
9573
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
9574
+ ) {
9575
+ continue;
9576
+ }
9577
+
9578
+ $license_ids[ $install->license_id ] = true;
9579
+ }
9580
+
9581
+ return array_keys( $license_ids );
9582
+ }
9583
+
9584
+ /**
9585
+ * @author Vova Feldman (@svovaf)
9586
+ * @since 1.0.5
9587
+ *
9588
+ * @param number $id
9589
+ *
9590
+ * @return FS_Plugin_Plan|false
9591
+ */
9592
+ function _get_plan_by_id( $id ) {
9593
+ $this->_logger->entrance();
9594
+
9595
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
9596
+ $this->_sync_plans();
9597
+ }
9598
+
9599
+ foreach ( $this->_plans as $plan ) {
9600
+ if ( $id == $plan->id ) {
9601
+ return $plan;
9602
+ }
9603
+ }
9604
+
9605
+ return false;
9606
+ }
9607
+
9608
+ /**
9609
+ * @author Vova Feldman (@svovaf)
9610
+ * @since 1.1.8.1
9611
+ *
9612
+ * @param string $name
9613
+ *
9614
+ * @return FS_Plugin_Plan|false
9615
+ */
9616
+ private function get_plan_by_name( $name ) {
9617
+ $this->_logger->entrance();
9618
+
9619
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
9620
+ $this->_sync_plans();
9621
+ }
9622
+
9623
+ foreach ( $this->_plans as $plan ) {
9624
+ if ( $name == $plan->name ) {
9625
+ return $plan;
9626
+ }
9627
+ }
9628
+
9629
+ return false;
9630
+ }
9631
+
9632
+ /**
9633
+ * Sync local licenses with remote server.
9634
+ *
9635
+ * @author Vova Feldman (@svovaf)
9636
+ * @since 1.0.6
9637
+ *
9638
+ * @param number|bool $site_license_id
9639
+ * @param number|null $blog_id
9640
+ *
9641
+ * @return FS_Plugin_License[]|object
9642
+ */
9643
+ function _sync_licenses( $site_license_id = false, $blog_id = null ) {
9644
+ $this->_logger->entrance();
9645
+
9646
+ $is_network_admin = fs_is_network_admin();
9647
+
9648
+ if ( $is_network_admin && is_null( $blog_id ) ) {
9649
+ $all_licenses = self::get_all_licenses( $this->_module_id );
9650
+ } else {
9651
+ $all_licenses = $this->get_user_licenses( $this->_user->id );
9652
+ }
9653
+
9654
+ $foreign_licenses = array(
9655
+ 'ids' => array(),
9656
+ 'license_keys' => array()
9657
+ );
9658
+
9659
+ $all_licenses_map = array();
9660
+ foreach ( $all_licenses as $license ) {
9661
+ $all_licenses_map[ $license->id ] = true;
9662
+ if ( $license->user_id == $this->_user->id || $license->id == $site_license_id ) {
9663
+ continue;
9664
+ }
9665
+
9666
+ $foreign_licenses['ids'][] = $license->id;
9667
+ $foreign_licenses['license_keys'][] = $license->secret_key;
9668
+ }
9669
+
9670
+ if ( empty( $foreign_licenses['ids'] ) ) {
9671
+ $foreign_licenses = array();
9672
+ }
9673
+
9674
+ $licenses = $this->_fetch_licenses( false, $site_license_id, $foreign_licenses, $blog_id );
9675
+
9676
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
9677
+ $licenses_map = array();
9678
+ foreach ( $licenses as $license ) {
9679
+ $licenses_map[ $license->id ] = true;
9680
+ }
9681
+
9682
+ // $license_ids_to_keep = $this->get_license_ids_associated_with_installs();
9683
+ // foreach ( $license_ids_to_keep as $license_id ) {
9684
+ // if ( isset( $licenses_map[ $license_id ] ) ) {
9685
+ // continue;
9686
+ // }
9687
+ //
9688
+ // $missing_license = self::_get_license_by_id( $license_id, false );
9689
+ // if ( is_object( $missing_license ) ) {
9690
+ // $licenses[] = $missing_license;
9691
+ // $licenses_map[ $missing_license->id ] = true;
9692
+ // }
9693
+ // }
9694
+
9695
+ $user_license_ids = $this->get_user_linked_license_ids( $this->_user->id );
9696
+
9697
+ foreach ( $user_license_ids as $key => $license_id ) {
9698
+ if ( ! isset( $licenses_map[ $license_id ] ) ) {
9699
+ // Remove access to licenses that no longer exist.
9700
+ unset( $user_license_ids[ $key ] );
9701
+ }
9702
+ }
9703
+
9704
+ if ( ! empty( $user_license_ids ) ) {
9705
+ foreach ( $licenses_map as $license_id => $value ) {
9706
+ if ( ! isset( $all_licenses_map[ $license_id ] ) ) {
9707
+ // Associate new licenses with the user who triggered the license syncing.
9708
+ $user_license_ids[] = $license_id;
9709
+ }
9710
+ }
9711
+
9712
+ $user_license_ids = array_unique( $user_license_ids );
9713
+ } else {
9714
+ $user_license_ids = array_keys( $licenses_map );
9715
+ }
9716
+
9717
+ if ( ! $is_network_admin || ! is_null( $blog_id ) ) {
9718
+ $user_licenses = array();
9719
+ foreach ( $licenses as $license ) {
9720
+ if ( ! in_array( $license->id, $user_license_ids ) ) {
9721
+ continue;
9722
+ }
9723
+
9724
+ $user_licenses[] = $license;
9725
+ }
9726
+
9727
+ $this->_licenses = $user_licenses;
9728
+ } else {
9729
+ $this->_licenses = $licenses;
9730
+ }
9731
+
9732
+ $this->set_user_linked_license_ids( $this->_user->id, $user_license_ids );
9733
+
9734
+ $this->_store_licenses( true, $this->_module_id, $licenses );
9735
+ }
9736
+
9737
+ // Update current license.
9738
+ if ( is_object( $this->_license ) ) {
9739
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
9740
+ }
9741
+
9742
+ return $this->_licenses;
9743
+ }
9744
+
9745
+ /**
9746
+ * @author Vova Feldman (@svovaf)
9747
+ * @since 1.0.5
9748
+ *
9749
+ * @param number $id
9750
+ * @param bool $sync_licenses
9751
+ *
9752
+ * @return FS_Plugin_License|false
9753
+ */
9754
+ function _get_license_by_id( $id, $sync_licenses = true ) {
9755
+ $this->_logger->entrance();
9756
+
9757
+ if ( ! FS_Plugin_License::is_valid_id( $id ) ) {
9758
+ return false;
9759
+ }
9760
+
9761
+ /**
9762
+ * When running from the network level admin and opted-in from the network,
9763
+ * check if the license exists in the network user licenses collection.
9764
+ *
9765
+ * @author Vova Feldman (@svovaf)
9766
+ * @since 2.0.0
9767
+ */
9768
+ if ( fs_is_network_admin() &&
9769
+ $this->is_network_registered() &&
9770
+ ( ! is_object( $this->_user ) || $this->_storage->network_user_id != $this->_user->id )
9771
+ ) {
9772
+ $licenses = $this->get_user_licenses( $this->_storage->network_user_id );
9773
+
9774
+ foreach ( $licenses as $license ) {
9775
+ if ( $id == $license->id ) {
9776
+ return $license;
9777
+ }
9778
+ }
9779
+ }
9780
+
9781
+ if ( ! $this->has_any_license() && $sync_licenses ) {
9782
+ $this->_sync_licenses( $id );
9783
+ }
9784
+
9785
+ if ( is_array( $this->_licenses ) ) {
9786
+ foreach ( $this->_licenses as $license ) {
9787
+ if ( $id == $license->id ) {
9788
+ return $license;
9789
+ }
9790
+ }
9791
+ }
9792
+
9793
+ return false;
9794
+ }
9795
+
9796
+ /**
9797
+ * Get license by ID. Unlike _get_license_by_id(), this method only checks the local storage and return any license, whether it's associated with the current context user/install or not.
9798
+ *
9799
+ * @author Vova Feldman (@svovaf)
9800
+ * @since 2.0.0
9801
+ *
9802
+ * @param number $id
9803
+ *
9804
+ * @return FS_Plugin_License
9805
+ */
9806
+ private function get_license_by_id( $id ) {
9807
+ $licenses = self::get_all_licenses( $this->_module_id );
9808
+
9809
+ if ( is_array( $licenses ) && ! empty( $licenses ) ) {
9810
+ foreach ( $licenses as $license ) {
9811
+ if ( $id == $license->id ) {
9812
+ return $license;
9813
+ }
9814
+ }
9815
+ }
9816
+
9817
+ return null;
9818
+ }
9819
+
9820
+ /**
9821
+ * Synchronize the site's context license by fetching the license form the API and updating the local data with it.
9822
+ *
9823
+ * @author Vova Feldman (@svovaf)
9824
+ * @since 2.0.0
9825
+ *
9826
+ * @return \FS_Plugin_License|mixed
9827
+ */
9828
+ private function sync_site_license() {
9829
+ $api = $this->get_api_user_scope();
9830
+
9831
+ $result = $api->get( "/licenses/{$this->_license->id}.json?license_key=" . urlencode( $this->_license->secret_key ), true );
9832
+
9833
+ if ( ! $this->is_api_result_entity( $result ) ) {
9834
+ return $result;
9835
+ }
9836
+
9837
+ $license = $this->_update_site_license( new FS_Plugin_License( $result ) );
9838
+ $this->_store_licenses();
9839
+
9840
+ return $license;
9841
+ }
9842
+
9843
+ /**
9844
+ * Get all user's available licenses for the current module.
9845
+ *
9846
+ * @author Vova Feldman (@svovaf)
9847
+ * @since 2.0.0
9848
+ *
9849
+ * @param number $user_id
9850
+ *
9851
+ * @return FS_Plugin_License[]
9852
+ */
9853
+ private function get_user_licenses( $user_id ) {
9854
+ $all_licenses = self::get_all_licenses( $this->_module_id );
9855
+ if ( empty( $all_licenses ) ) {
9856
+ return array();
9857
+ }
9858
+
9859
+ $user_license_ids = $this->get_user_linked_license_ids( $user_id );
9860
+ if ( empty( $user_license_ids ) ) {
9861
+ return array();
9862
+ }
9863
+
9864
+ $licenses = array();
9865
+ foreach ( $all_licenses as $license ) {
9866
+ if ( in_array( $license->id, $user_license_ids ) ) {
9867
+ $licenses[] = $license;
9868
+ }
9869
+ }
9870
+
9871
+ return $licenses;
9872
+ }
9873
+
9874
+ /**
9875
+ * Checks if the context license is network activated except on the given blog ID.
9876
+ *
9877
+ * @author Vova Feldman (@svovaf)
9878
+ * @since 2.0.0
9879
+ *
9880
+ * @param int $except_blog_id
9881
+ *
9882
+ * @return bool
9883
+ */
9884
+ private function is_license_network_active( $except_blog_id = 0 ) {
9885
+ $this->_logger->entrance();
9886
+
9887
+ if ( ! is_object( $this->_license ) ) {
9888
+ return false;
9889
+ }
9890
+
9891
+ $sites = self::get_sites();
9892
+
9893
+ if ( $this->_license->total_activations() < ( count( $sites ) - 1 ) ) {
9894
+ // There are more sites than the number of activations, so license cannot be network activated.
9895
+ return false;
9896
+ }
9897
+
9898
+ foreach ( $sites as $site ) {
9899
+ $blog_id = self::get_site_blog_id( $site );
9900
+
9901
+ if ( $except_blog_id == $blog_id ) {
9902
+ // Skip excluded blog.
9903
+ continue;
9904
+ }
9905
+
9906
+ $install = $this->get_install_by_blog_id( $blog_id );
9907
+
9908
+ if ( is_object( $install ) && $install->license_id != $this->_license->id ) {
9909
+ return false;
9910
+ }
9911
+ }
9912
+
9913
+ return true;
9914
+ }
9915
+
9916
+ /**
9917
+ * Checks if license can be activated on all the network sites (opted-in or skipped) that are not yet associated with a license. If possible, try to make the activation, if not return false.
9918
+ *
9919
+ * Notice: On success, this method will also update the license activations counters (without updating the license in the storage).
9920
+ *
9921
+ * @author Vova Feldman (@svovaf)
9922
+ * @since 2.0.0
9923
+ *
9924
+ * @param \FS_User $user
9925
+ * @param \FS_Plugin_License $license
9926
+ *
9927
+ * @return bool
9928
+ */
9929
+ private function try_activate_license_on_network( FS_User $user, FS_Plugin_License $license ) {
9930
+ $this->_logger->entrance();
9931
+
9932
+ $result = $this->can_activate_license_on_network( $license );
9933
+
9934
+ if ( false === $result ) {
9935
+ return false;
9936
+ }
9937
+
9938
+ $installs_without_license = $result['installs'];
9939
+ if ( ! empty( $installs_without_license ) ) {
9940
+ $this->activate_license_on_many_installs( $user, $license->secret_key, $installs_without_license );
9941
+ }
9942
+
9943
+ $disconnected_site_ids = $result['sites'];
9944
+ if ( ! empty( $disconnected_site_ids ) ) {
9945
+ $this->activate_license_on_many_sites( $user, $license->secret_key, $disconnected_site_ids );
9946
+ }
9947
+
9948
+ $this->link_license_2_user( $license->id, $user->id );
9949
+
9950
+ // Sync license after activations.
9951
+ $license->activated += $result['production_count'];
9952
+ $license->activated_local += $result['localhost_count'];
9953
+
9954
+ // $this->_store_licenses()
9955
+
9956
+ return true;
9957
+ }
9958
+
9959
+ /**
9960
+ * Checks if the given license can be activated on the whole network.
9961
+ *
9962
+ * @author Vova Feldman (@svovaf)
9963
+ * @since 2.0.0
9964
+ *
9965
+ * @param \FS_Plugin_License $license
9966
+ *
9967
+ * @return false|array {
9968
+ * @type array[int]FS_Site $installs Blog ID to install map.
9969
+ * @type int[] $sites Non-connected blog IDs.
9970
+ * @type int $production_count Production sites count.
9971
+ * @type int $localhost_count Production sites count.
9972
+ * }
9973
+ */
9974
+ private function can_activate_license_on_network( FS_Plugin_License $license ) {
9975
+ $sites = self::get_sites();
9976
+
9977
+ $production_count = 0;
9978
+ $localhost_count = 0;
9979
+
9980
+ $installs_without_license = array();
9981
+ $disconnected_site_ids = array();
9982
+
9983
+ foreach ( $sites as $site ) {
9984
+ $blog_id = self::get_site_blog_id( $site );
9985
+ $install = $this->get_install_by_blog_id( $blog_id );
9986
+
9987
+ if ( is_object( $install ) ) {
9988
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
9989
+ // License already activated on the install.
9990
+ continue;
9991
+ }
9992
+
9993
+ $url = $install->url;
9994
+
9995
+ $installs_without_license[ $blog_id ] = $install;
9996
+ } else {
9997
+ $url = is_object( $site ) ?
9998
+ $site->siteurl :
9999
+ get_site_url( $blog_id );
10000
+
10001
+ $disconnected_site_ids[] = $blog_id;
10002
+ }
10003
+
10004
+ if ( FS_Site::is_localhost_by_address( $url ) ) {
10005
+ $localhost_count ++;
10006
+ } else {
10007
+ $production_count ++;
10008
+ }
10009
+ }
10010
+
10011
+ if ( ! $license->can_activate_bulk( $production_count, $localhost_count ) ) {
10012
+ return false;
10013
+ }
10014
+
10015
+ return array(
10016
+ 'installs' => $installs_without_license,
10017
+ 'sites' => $disconnected_site_ids,
10018
+ 'production_count' => $production_count,
10019
+ 'localhost_count' => $localhost_count,
10020
+ );
10021
+ }
10022
+
10023
+ /**
10024
+ * Activate a given license on a collection of installs.
10025
+ *
10026
+ * @author Vova Feldman (@svovaf)
10027
+ * @since 2.0.0
10028
+ *
10029
+ * @param \FS_User $user
10030
+ * @param string $license_key
10031
+ * @param array $blog_2_install_map {
10032
+ * @key int Blog ID.
10033
+ * @value FS_Site Blog's associated install.
10034
+ * }
10035
+ *
10036
+ * @return mixed|true
10037
+ */
10038
+ private function activate_license_on_many_installs(
10039
+ FS_User $user,
10040
+ $license_key,
10041
+ array $blog_2_install_map
10042
+ ) {
10043
+ $params = array(
10044
+ array( 'license_key' => $this->apply_filters( 'license_key', $license_key ) )
10045
+ );
10046
+
10047
+ $install_2_blog_map = array();
10048
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
10049
+ $params[] = array( 'id' => $install->id );
10050
+
10051
+ $install_2_blog_map[ $install->id ] = $blog_id;
10052
+ }
10053
+
10054
+ $result = $this->get_api_user_scope_by_user( $user )->call(
10055
+ "plugins/{$this->_plugin->id}/installs.json",
10056
+ 'PUT',
10057
+ $params
10058
+ );
10059
+
10060
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
10061
+ return $result;
10062
+ }
10063
+
10064
+ foreach ( $result->installs as $r_install ) {
10065
+ $install = new FS_Site( $r_install );
10066
+ $install->is_disconnected = false;
10067
+
10068
+ // Update install.
10069
+ $this->_store_site(
10070
+ true,
10071
+ $install_2_blog_map[ $r_install->id ],
10072
+ $install
10073
+ );
10074
+ }
10075
+
10076
+ return true;
10077
+ }
10078
+
10079
+ /**
10080
+ * Activate a given license on a collection of blogs/sites that are not yet opted-in.
10081
+ *
10082
+ * @author Vova Feldman (@svovaf)
10083
+ * @since 2.0.0
10084
+ *
10085
+ * @param \FS_User $user
10086
+ * @param string $license_key
10087
+ * @param int[] $site_ids
10088
+ *
10089
+ * @return true|mixed True if successful, otherwise, the API result.
10090
+ */
10091
+ private function activate_license_on_many_sites(
10092
+ FS_User $user,
10093
+ $license_key,
10094
+ array $site_ids
10095
+ ) {
10096
+ $sites = array();
10097
+ foreach ( $site_ids as $site_id ) {
10098
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
10099
+ }
10100
+
10101
+ // Install the plugin.
10102
+ $result = $this->create_installs_with_user(
10103
+ $user,
10104
+ $license_key,
10105
+ false,
10106
+ $sites,
10107
+ false,
10108
+ true
10109
+ );
10110
+
10111
+ if ( ! $this->is_api_result_entity( $result ) &&
10112
+ ! $this->is_api_result_object( $result, 'installs' )
10113
+ ) {
10114
+ return $result;
10115
+ }
10116
+
10117
+ $installs = array();
10118
+ foreach ( $result->installs as $install ) {
10119
+ $installs[] = new FS_Site( $install );
10120
+ }
10121
+
10122
+ // Map site addresses to their blog IDs.
10123
+ $address_to_blog_map = $this->get_address_to_blog_map();
10124
+
10125
+ $first_blog_id = null;
10126
+
10127
+ foreach ( $installs as $install ) {
10128
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
10129
+ $blog_id = $address_to_blog_map[ $address ];
10130
+
10131
+ $this->_store_site( true, $blog_id, $install );
10132
+
10133
+ $this->reset_anonymous_mode( $blog_id );
10134
+
10135
+ if ( is_null( $first_blog_id ) ) {
10136
+ $first_blog_id = $blog_id;
10137
+ }
10138
+ }
10139
+
10140
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
10141
+ $this->_storage->network_install_blog_id = $first_blog_id;
10142
+ }
10143
+
10144
+ return true;
10145
+ }
10146
+
10147
+ /**
10148
+ * Sync site's license with user licenses.
10149
+ *
10150
+ * @author Vova Feldman (@svovaf)
10151
+ * @since 1.0.6
10152
+ *
10153
+ * @param FS_Plugin_License|null $new_license
10154
+ *
10155
+ * @return FS_Plugin_License|null
10156
+ */
10157
+ function _update_site_license( $new_license ) {
10158
+ $this->_logger->entrance();
10159
+
10160
+ $this->_license = $new_license;
10161
+
10162
+ if ( ! is_object( $new_license ) ) {
10163
+ $this->_site->license_id = null;
10164
+ $this->_sync_site_subscription( null );
10165
+
10166
+ return $this->_license;
10167
+ }
10168
+
10169
+ $this->_site->license_id = $this->_license->id;
10170
+
10171
+ if ( ! is_array( $this->_licenses ) ) {
10172
+ $this->_licenses = array();
10173
+ }
10174
+
10175
+ $is_license_found = false;
10176
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
10177
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
10178
+ $this->_licenses[ $i ] = $new_license;
10179
+
10180
+ $is_license_found = true;
10181
+ break;
10182
+ }
10183
+ }
10184
+
10185
+ // If new license just append.
10186
+ if ( ! $is_license_found ) {
10187
+ $this->_licenses[] = $new_license;
10188
+ }
10189
+
10190
+ $this->_sync_site_subscription( $new_license );
10191
+
10192
+ return $this->_license;
10193
+ }
10194
+
10195
+ /**
10196
+ * Sync site's subscription.
10197
+ *
10198
+ * @author Vova Feldman (@svovaf)
10199
+ * @since 1.0.9
10200
+ *
10201
+ * @param FS_Plugin_License|null $license
10202
+ *
10203
+ * @return bool|\FS_Subscription
10204
+ */
10205
+ private function _sync_site_subscription( $license ) {
10206
+ if ( ! is_object( $license ) ) {
10207
+ $this->delete_unused_subscriptions();
10208
+
10209
+ return false;
10210
+ }
10211
+
10212
+ // Load subscription details if not lifetime.
10213
+ $subscription = $license->is_lifetime() ?
10214
+ false :
10215
+ $this->_fetch_site_license_subscription();
10216
+
10217
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
10218
+ $this->store_subscription( $subscription );
10219
+ } else {
10220
+ $this->delete_unused_subscriptions();
10221
+ }
10222
+
10223
+ return $subscription;
10224
+ }
10225
+
10226
+ /**
10227
+ * @author Vova Feldman (@svovaf)
10228
+ * @since 1.0.6
10229
+ *
10230
+ * @return bool|\FS_Plugin_License
10231
+ */
10232
+ function _get_license() {
10233
+ if ( ! fs_is_network_admin() || is_object( $this->_license ) ) {
10234
+ return $this->_license;
10235
+ }
10236
+
10237
+ return $this->_get_available_premium_license();
10238
+ }
10239
+
10240
+ /**
10241
+ * @param number $license_id
10242
+ *
10243
+ * @return null|\FS_Subscription
10244
+ */
10245
+ function _get_subscription( $license_id ) {
10246
+ if ( ! isset( $this->_storage->subscriptions ) ||
10247
+ empty( $this->_storage->subscriptions )
10248
+ ) {
10249
+ return null;
10250
+ }
10251
+
10252
+ foreach ( $this->_storage->subscriptions as $subscription ) {
10253
+ if ( $subscription->license_id == $license_id ) {
10254
+ return $subscription;
10255
+ }
10256
+ }
10257
+
10258
+ return null;
10259
+ }
10260
+
10261
+ /**
10262
+ * @author Leo Fajardo (@leorw)
10263
+ * @since 2.0.0
10264
+ *
10265
+ * @param FS_Subscription $subscription
10266
+ */
10267
+ function store_subscription( FS_Subscription $subscription ) {
10268
+ if ( ! isset( $this->_storage->subscriptions ) ) {
10269
+ $this->_storage->subscriptions = array();
10270
+ }
10271
+
10272
+ if ( empty( $this->_storage->subscriptions ) || ! is_multisite() ) {
10273
+ $this->_storage->subscriptions = array( $subscription );
10274
+
10275
+ return;
10276
+ }
10277
+
10278
+ $subscriptions = $this->_storage->subscriptions;
10279
+
10280
+ $updated_subscription = false;
10281
+ foreach ( $subscriptions as $key => $existing_subscription ) {
10282
+ if ( $existing_subscription->id == $subscription->id ) {
10283
+ $subscriptions[ $key ] = $subscription;
10284
+ $updated_subscription = true;
10285
+ break;
10286
+ }
10287
+ }
10288
+
10289
+ if ( ! $updated_subscription ) {
10290
+ $subscriptions[] = $subscription;
10291
+ }
10292
+
10293
+ $this->_storage->subscriptions = $subscriptions;
10294
+ }
10295
+
10296
+ /**
10297
+ * @author Leo Fajardo (@leorw)
10298
+ * @since 2.0.0
10299
+ */
10300
+ function delete_unused_subscriptions() {
10301
+ if ( ! isset( $this->_storage->subscriptions ) ||
10302
+ empty( $this->_storage->subscriptions ) ||
10303
+ // Clean up only if there are already at least 3 subscriptions.
10304
+ ( count( $this->_storage->subscriptions ) < 3 )
10305
+ ) {
10306
+ return;
10307
+ }
10308
+
10309
+ if ( ! is_multisite() ) {
10310
+ // If not multisite, there should only be 1 subscription, so just clear the array.
10311
+ $this->_storage->subscriptions = array();
10312
+
10313
+ return;
10314
+ }
10315
+
10316
+ $subscriptions_to_keep_by_license_id_map = array();
10317
+ $sites = self::get_sites();
10318
+ foreach ( $sites as $site ) {
10319
+ $blog_id = self::get_site_blog_id( $site );
10320
+ $install = $this->get_install_by_blog_id( $blog_id );
10321
+
10322
+ if ( ! is_object( $install ) ||
10323
+ ! FS_Plugin_License::is_valid_id( $install->license_id )
10324
+ ) {
10325
+ continue;
10326
+ }
10327
+
10328
+ $subscriptions_to_keep_by_license_id_map[ $install->license_id ] = true;
10329
+ }
10330
+
10331
+ if ( empty( $subscriptions_to_keep_by_license_id_map ) ) {
10332
+ $this->_storage->subscriptions = array();
10333
+
10334
+ return;
10335
+ }
10336
+
10337
+ foreach ( $this->_storage->subscriptions as $key => $subscription ) {
10338
+ if ( ! isset( $subscriptions_to_keep_by_license_id_map[ $subscription->license_id ] ) ) {
10339
+ unset( $this->_storage->subscriptions[ $key ] );
10340
+ }
10341
+ }
10342
+ }
10343
+
10344
+ /**
10345
+ * @author Vova Feldman (@svovaf)
10346
+ * @since 1.0.2
10347
+ *
10348
+ * @param string $plan Plan name
10349
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10350
+ *
10351
+ * @return bool
10352
+ */
10353
+ function is_plan( $plan, $exact = false ) {
10354
+ $this->_logger->entrance();
10355
+
10356
+ if ( ! $this->is_registered() ) {
10357
+ return false;
10358
+ }
10359
+
10360
+ $plan = strtolower( $plan );
10361
+
10362
+ $current_plan_name = $this->get_plan_name();
10363
+
10364
+ if ( $current_plan_name === $plan ) {
10365
+ // Exact plan.
10366
+ return true;
10367
+ } else if ( $exact ) {
10368
+ // Required exact, but plans are different.
10369
+ return false;
10370
+ }
10371
+
10372
+ $current_plan_order = - 1;
10373
+ $required_plan_order = - 1;
10374
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10375
+ if ( $plan === $this->_plans[ $i ]->name ) {
10376
+ $required_plan_order = $i;
10377
+ } else if ( $current_plan_name === $this->_plans[ $i ]->name ) {
10378
+ $current_plan_order = $i;
10379
+ }
10380
+ }
10381
+
10382
+ return ( $current_plan_order > $required_plan_order );
10383
+ }
10384
+
10385
+ /**
10386
+ * Check if module has only one plan.
10387
+ *
10388
+ * @author Vova Feldman (@svovaf)
10389
+ * @since 1.2.1.7
10390
+ *
10391
+ * @return bool
10392
+ */
10393
+ function is_single_plan() {
10394
+ $this->_logger->entrance();
10395
+
10396
+ if ( ! $this->is_registered() ||
10397
+ ! is_array( $this->_plans ) ||
10398
+ 0 === count( $this->_plans )
10399
+ ) {
10400
+ return true;
10401
+ }
10402
+
10403
+ return ( 1 === count( $this->_plans ) );
10404
+ }
10405
+
10406
+ /**
10407
+ * Check if plan based on trial. If not in trial mode, should return false.
10408
+ *
10409
+ * @since 1.0.9
10410
+ *
10411
+ * @param string $plan Plan name
10412
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
10413
+ *
10414
+ * @return bool
10415
+ */
10416
+ function is_trial_plan( $plan, $exact = false ) {
10417
+ $this->_logger->entrance();
10418
+
10419
+ if ( ! $this->is_registered() ) {
10420
+ return false;
10421
+ }
10422
+
10423
+ if ( ! $this->is_trial() ) {
10424
+ return false;
10425
+ }
10426
+
10427
+ $trial_plan = $this->get_trial_plan();
10428
+
10429
+ if ( $trial_plan->name === $plan ) {
10430
+ // Exact plan.
10431
+ return true;
10432
+ } else if ( $exact ) {
10433
+ // Required exact, but plans are different.
10434
+ return false;
10435
+ }
10436
+
10437
+ $current_plan_order = - 1;
10438
+ $required_plan_order = - 1;
10439
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
10440
+ if ( $plan === $this->_plans[ $i ]->name ) {
10441
+ $required_plan_order = $i;
10442
+ } else if ( $trial_plan->name === $this->_plans[ $i ]->name ) {
10443
+ $current_plan_order = $i;
10444
+ }
10445
+ }
10446
+
10447
+ return ( $current_plan_order > $required_plan_order );
10448
+ }
10449
+
10450
+ /**
10451
+ * Check if plugin has any paid plans.
10452
+ *
10453
+ * @author Vova Feldman (@svovaf)
10454
+ * @since 1.0.7
10455
+ *
10456
+ * @return bool
10457
+ */
10458
+ function has_paid_plan() {
10459
+ return $this->_has_paid_plans ||
10460
+ FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
10461
+ }
10462
+
10463
+ /**
10464
+ * Check if plugin has any plan with a trail.
10465
+ *
10466
+ * @author Vova Feldman (@svovaf)
10467
+ * @since 1.0.9
10468
+ *
10469
+ * @return bool
10470
+ */
10471
+ function has_trial_plan() {
10472
+ /**
10473
+ * @author Vova Feldman(@svovaf)
10474
+ * @since 1.2.1.5
10475
+ *
10476
+ * Allow setting a trial from the SDK without calling the API.
10477
+ * But, if the user did opt-in, continue using the real data from the API.
10478
+ */
10479
+ if ( $this->_trial_days >= 0 ) {
10480
+ return true;
10481
+ }
10482
+
10483
+ return $this->_storage->get( 'has_trial_plan', false );
10484
+ }
10485
+
10486
+ /**
10487
+ * Check if plugin has any free plan, or is it premium only.
10488
+ *
10489
+ * Note: If no plans configured, assume plugin is free.
10490
+ *
10491
+ * @author Vova Feldman (@svovaf)
10492
+ * @since 1.0.7
10493
+ *
10494
+ * @return bool
10495
+ */
10496
+ function has_free_plan() {
10497
+ return ! $this->is_only_premium();
10498
+ }
10499
+
10500
+ /**
10501
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
10502
+ * or "Change License" link on the plugins
10503
+ * page.
10504
+ *
10505
+ * @author Leo Fajardo (@leorw)
10506
+ * @since 1.1.9
10507
+ */
10508
+ function _add_license_activation_dialog_box() {
10509
+ $vars = array(
10510
+ 'id' => $this->_module_id,
10511
+ );
10512
+
10513
+ fs_require_template( 'forms/license-activation.php', $vars );
10514
+ fs_require_template( 'forms/resend-key.php', $vars );
10515
+ }
10516
+
10517
+ /**
10518
+ * @author Leo Fajardo (@leorw)
10519
+ * @since 2.0.2
10520
+ */
10521
+ function _add_premium_version_upgrade_selection_dialog_box() {
10522
+ $modules_update = get_site_transient( $this->is_theme() ? 'update_themes' : 'update_plugins' );
10523
+ if ( ! isset( $modules_update->response[ $this->_plugin_basename ] ) ) {
10524
+ return;
10525
+ }
10526
+
10527
+ $vars = array(
10528
+ 'id' => $this->_module_id,
10529
+ 'new_version' => is_object( $modules_update->response[ $this->_plugin_basename ] ) ?
10530
+ $modules_update->response[ $this->_plugin_basename ]->new_version :
10531
+ $modules_update->response[ $this->_plugin_basename ]['new_version']
10532
+ );
10533
+
10534
+ fs_require_template( 'forms/premium-versions-upgrade-metadata.php', $vars );
10535
+ fs_require_once_template( 'forms/premium-versions-upgrade-handler.php', $vars );
10536
+ }
10537
+
10538
+ /**
10539
+ * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
10540
+ * page.
10541
+ *
10542
+ * @author Leo Fajardo (@leorw)
10543
+ * @since 1.2.1.5
10544
+ */
10545
+ function _add_optout_dialog() {
10546
+ if ( $this->is_theme() ) {
10547
+ $vars = null;
10548
+ fs_require_once_template( '/js/jquery.content-change.php', $vars );
10549
+ }
10550
+
10551
+ $vars = array( 'id' => $this->_module_id );
10552
+ fs_require_template( 'forms/optout.php', $vars );
10553
+ }
10554
+
10555
+ /**
10556
+ * Prepare page to include all required UI and logic for the license activation dialog.
10557
+ *
10558
+ * @author Vova Feldman (@svovaf)
10559
+ * @since 1.2.0
10560
+ */
10561
+ function _add_license_activation() {
10562
+ if ( ! $this->is_user_admin() ) {
10563
+ // Only admins can activate a license.
10564
+ return;
10565
+ }
10566
+
10567
+ if ( ! $this->has_paid_plan() ) {
10568
+ // Module doesn't have any paid plans.
10569
+ return;
10570
+ }
10571
+
10572
+ if ( ! $this->is_premium() ) {
10573
+ // Only add license activation logic to the premium version.
10574
+ return;
10575
+ }
10576
+
10577
+ // Add license activation link and AJAX request handler.
10578
+ if ( self::is_plugins_page() ) {
10579
+ /**
10580
+ * @since 1.2.0 Add license action link only on plugins page.
10581
+ */
10582
+ $this->_add_license_action_link();
10583
+ }
10584
+
10585
+ // Add license activation AJAX callback.
10586
+ $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
10587
+
10588
+ // Add resend license AJAX callback.
10589
+ $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
10590
+ }
10591
+
10592
+ /**
10593
+ * @author Leo Fajardo (@leorw)
10594
+ * @since 2.0.2
10595
+ */
10596
+ function _add_premium_version_upgrade_selection() {
10597
+ if ( ! $this->is_user_admin() ) {
10598
+ return;
10599
+ }
10600
+
10601
+ if ( ! $this->is_premium() || $this->has_any_active_valid_license() ) {
10602
+ // This is relevant only to the free versions and premium versions without an active license.
10603
+ return;
10604
+ }
10605
+
10606
+ if ( self::is_updates_page() || ( $this->is_plugin() && self::is_plugins_page() ) ) {
10607
+ $this->_add_premium_version_upgrade_selection_action();
10608
+ }
10609
+ }
10610
+
10611
+ /**
10612
+ * @author Leo Fajardo (@leorw)
10613
+ *
10614
+ * @since 1.1.9
10615
+ * @since 2.0.0 When a super-admin that hasn't connected before is network activating a license and excluding some of the sites for the license activation, go over the unselected sites in the network and if a site is not connected, skipped, nor delegated, if it's a freemium product then just skip the connection for the site, if it's a premium only product, delegate the connection and license activation to the site admin (Vova Feldman @svovaf).
10616
+ */
10617
+ function _activate_license_ajax_action() {
10618
+ $this->_logger->entrance();
10619
+
10620
+ $this->check_ajax_referer( 'activate_license' );
10621
+
10622
+ $license_key = trim( fs_request_get( 'license_key' ) );
10623
+
10624
+ if ( empty( $license_key ) ) {
10625
+ exit;
10626
+ }
10627
+
10628
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
10629
+ $fs = ( $plugin_id == $this->_module_id ) ?
10630
+ $this :
10631
+ $this->get_addon_instance( $plugin_id );
10632
+
10633
+ $error = false;
10634
+ $next_page = false;
10635
+
10636
+ $sites = fs_is_network_admin() ?
10637
+ fs_request_get( 'sites', array(), 'post' ) :
10638
+ array();
10639
+
10640
+ $blog_id = fs_request_get( 'blog_id' );
10641
+ $has_valid_blog_id = is_numeric( $blog_id );
10642
+
10643
+ if ( $fs->is_registered() ) {
10644
+ if ( fs_is_network_admin() && ! $has_valid_blog_id ) {
10645
+ // If no specific blog ID was provided, activate the license for all sites in the network.
10646
+ $blog_2_install_map = array();
10647
+ $site_ids = array();
10648
+
10649
+ foreach ( $sites as $site ) {
10650
+ if ( ! isset( $site['blog_id'] ) || ! is_numeric( $site['blog_id'] ) ) {
10651
+ continue;
10652
+ }
10653
+
10654
+ $install = $this->get_install_by_blog_id( $site['blog_id'] );
10655
+
10656
+ if ( is_object( $install ) ) {
10657
+ $blog_2_install_map[ $site['blog_id'] ] = $install;
10658
+ } else {
10659
+ $site_ids[] = $site['blog_id'];
10660
+ }
10661
+ }
10662
+
10663
+ $user = $this->get_current_or_network_user();
10664
+
10665
+ if ( ! empty( $blog_2_install_map ) ) {
10666
+ $result = $this->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
10667
+
10668
+ if ( true !== $result ) {
10669
+ $error = FS_Api::is_api_error_object( $result ) ?
10670
+ $result->error->message :
10671
+ var_export( $result, true );
10672
+ }
10673
+ }
10674
+
10675
+ if ( empty( $error ) && ! empty( $site_ids ) ) {
10676
+ $result = $this->activate_license_on_many_sites( $user, $license_key, $site_ids );
10677
+
10678
+ if ( true !== $result ) {
10679
+ $error = FS_Api::is_api_error_object( $result ) ?
10680
+ $result->error->message :
10681
+ var_export( $result, true );
10682
+ }
10683
+ }
10684
+ } else {
10685
+ if ( $has_valid_blog_id ) {
10686
+ /**
10687
+ * If a specific blog ID was provided, activate the license only for the install that is
10688
+ * associated with the given blog ID.
10689
+ *
10690
+ * @author Leo Fajardo (@leorw)
10691
+ */
10692
+ $this->switch_to_blog( $blog_id );
10693
+ }
10694
+
10695
+ $api = $fs->get_api_site_scope();
10696
+
10697
+ $params = array(
10698
+ 'license_key' => $fs->apply_filters( 'license_key', $license_key )
10699
+ );
10700
+
10701
+ $install = $api->call( '/', 'put', $params );
10702
+
10703
+ if ( FS_Api::is_api_error( $install ) ) {
10704
+ $error = FS_Api::is_api_error_object( $install ) ?
10705
+ $install->error->message :
10706
+ var_export( $install->error, true );
10707
+ } else {
10708
+ $fs->reconnect_locally( $has_valid_blog_id );
10709
+ }
10710
+ }
10711
+
10712
+ if ( empty( $error ) ) {
10713
+ $this->network_upgrade_mode_completed();
10714
+
10715
+ $fs->_sync_license( true, $has_valid_blog_id );
10716
+
10717
+ $next_page = $fs->is_addon() ?
10718
+ $fs->get_parent_instance()->get_account_url() :
10719
+ $fs->get_account_url();
10720
+ }
10721
+ } else {
10722
+ $next_page = $fs->opt_in(
10723
+ false,
10724
+ false,
10725
+ false,
10726
+ $license_key,
10727
+ false,
10728
+ false,
10729
+ false,
10730
+ fs_request_get_bool( 'is_marketing_allowed', null ),
10731
+ $sites
10732
+ );
10733
+
10734
+ if ( isset( $next_page->error ) ) {
10735
+ $error = $next_page->error;
10736
+ } else {
10737
+ if ( fs_is_network_admin() ) {
10738
+ /**
10739
+ * Get the list of sites that were just opted-in (and license activated).
10740
+ * This is an optimization for the next part below saving some DB queries.
10741
+ */
10742
+ $connected_sites = array();
10743
+ foreach ( $sites as $site ) {
10744
+ if ( isset( $site['blog_id'] ) && is_numeric( $site['blog_id'] ) ) {
10745
+ $connected_sites[ $site['blog_id'] ] = true;
10746
+ }
10747
+ }
10748
+
10749
+ $all_sites = self::get_sites();
10750
+ $pending_sites = array();
10751
+
10752
+ /**
10753
+ * Check if there are any sites that are not connected, skipped, nor delegated. For every site that falls into that category, if the product is freemium, skip the connection. If the product is premium only, delegate the connection to the site administrator.
10754
+ *
10755
+ * @author Vova Feldman (@svovaf)
10756
+ */
10757
+ foreach ( $all_sites as $site ) {
10758
+ $blog_id = self::get_site_blog_id( $site );
10759
+
10760
+ if ( isset( $connected_sites[ $blog_id ] ) ) {
10761
+ // Site was just connected.
10762
+ continue;
10763
+ }
10764
+
10765
+ if ( $this->is_installed_on_site( $blog_id ) ) {
10766
+ // Site was already connected before.
10767
+ continue;
10768
+ }
10769
+
10770
+ if ( $this->is_site_delegated_connection( $blog_id ) ) {
10771
+ // Site's connection was delegated.
10772
+ continue;
10773
+ }
10774
+
10775
+ if ( $this->is_anonymous_site( $blog_id ) ) {
10776
+ // Site connection was already skipped.
10777
+ continue;
10778
+ }
10779
+
10780
+ $pending_sites[] = self::get_site_info( $site );
10781
+ }
10782
+
10783
+ if ( ! empty( $pending_sites ) ) {
10784
+ if ( $this->is_freemium() ) {
10785
+ $this->skip_connection( $pending_sites );
10786
+ } else {
10787
+ $this->delegate_connection( $pending_sites );
10788
+ }
10789
+ }
10790
+ }
10791
+ }
10792
+ }
10793
+
10794
+ $result = array(
10795
+ 'success' => ( false === $error )
10796
+ );
10797
+
10798
+ if ( false !== $error ) {
10799
+ $result['error'] = $error;
10800
+ } else {
10801
+ $result['next_page'] = $next_page;
10802
+ }
10803
+
10804
+ echo json_encode( $result );
10805
+
10806
+ exit;
10807
+ }
10808
+
10809
+ /**
10810
+ * @author Leo Fajardo (@leorw)
10811
+ * @since 1.2.3.1
10812
+ */
10813
+ function _network_activate_ajax_action() {
10814
+ $this->_logger->entrance();
10815
+
10816
+ $this->check_ajax_referer( 'network_activate' );
10817
+
10818
+ $plugin_id = fs_request_get( 'module_id', '', 'post' );
10819
+ $fs = ( $plugin_id == $this->_module_id ) ?
10820
+ $this :
10821
+ $this->get_addon_instance( $plugin_id );
10822
+
10823
+ $error = false;
10824
+
10825
+ $sites = fs_request_get( 'sites', array(), 'post' );
10826
+ if ( is_array( $sites ) && ! empty( $sites ) ) {
10827
+ $sites_by_action = array(
10828
+ 'allow' => array(),
10829
+ 'delegate' => array(),
10830
+ 'skip' => array()
10831
+ );
10832
+
10833
+ foreach ( $sites as $site ) {
10834
+ $sites_by_action[ $site['action'] ][] = $site;
10835
+ }
10836
+
10837
+ $total_sites = count( $sites );
10838
+ $total_sites_to_delegate = count( $sites_by_action['delegate'] );
10839
+
10840
+ $next_page = '';
10841
+ if ( $total_sites === $total_sites_to_delegate &&
10842
+ ! $this->is_network_upgrade_mode()
10843
+ ) {
10844
+ $this->delegate_connection();
10845
+ } else {
10846
+ if ( ! empty( $sites_by_action['delegate'] ) ) {
10847
+ $this->delegate_connection( $sites_by_action['delegate'] );
10848
+ }
10849
+
10850
+ if ( ! empty( $sites_by_action['skip'] ) ) {
10851
+ $this->skip_connection( $sites_by_action['skip'] );
10852
+ }
10853
+
10854
+ if ( ! empty( $sites_by_action['allow'] ) ) {
10855
+ if ( ! $fs->is_registered() || ! $this->_is_network_active ) {
10856
+ $next_page = $fs->opt_in(
10857
+ false,
10858
+ false,
10859
+ false,
10860
+ false,
10861
+ false,
10862
+ false,
10863
+ false,
10864
+ fs_request_get_bool( 'is_marketing_allowed', null ),
10865
+ $sites_by_action['allow']
10866
+ );
10867
+ } else {
10868
+ $next_page = $fs->install_with_user(
10869
+ $this->get_network_user(),
10870
+ false,
10871
+ false,
10872
+ false,
10873
+ true,
10874
+ $sites_by_action['allow']
10875
+ );
10876
+ }
10877
+
10878
+ if ( is_object( $next_page ) && isset( $next_page->error ) ) {
10879
+ $error = $next_page->error;
10880
+ }
10881
+ }
10882
+ }
10883
+
10884
+ if ( empty( $next_page ) ) {
10885
+ $next_page = $this->get_after_activation_url( 'after_network_activation_url' );
10886
+ }
10887
+ } else {
10888
+ $error = $this->get_text_inline( 'Invalid site details collection.', 'invalid_site_details_collection' );
10889
+ }
10890
+
10891
+ $result = array(
10892
+ 'success' => ( false === $error )
10893
+ );
10894
+
10895
+ if ( false !== $error ) {
10896
+ $result['error'] = $error;
10897
+ } else {
10898
+ $result['next_page'] = $next_page;
10899
+ }
10900
+
10901
+ echo json_encode( $result );
10902
+
10903
+ exit;
10904
+ }
10905
+
10906
+ /**
10907
+ * Billing update AJAX callback.
10908
+ *
10909
+ * @author Vova Feldman (@svovaf)
10910
+ * @since 1.2.1.5
10911
+ */
10912
+ function _update_billing_ajax_action() {
10913
+ $this->_logger->entrance();
10914
+
10915
+ $this->check_ajax_referer( 'update_billing' );
10916
+
10917
+ if ( ! $this->is_user_admin() ) {
10918
+ // Only for admins.
10919
+ self::shoot_ajax_failure();
10920
+ }
10921
+
10922
+ $billing = fs_request_get( 'billing' );
10923
+
10924
+ $api = $this->get_api_user_scope();
10925
+ $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
10926
+ 'plugin_id' => $this->get_parent_id(),
10927
+ ) ) );
10928
+
10929
+ if ( ! $this->is_api_result_entity( $result ) ) {
10930
+ self::shoot_ajax_failure();
10931
+ }
10932
+
10933
+ // Purge cached billing.
10934
+ $this->get_api_user_scope()->purge_cache( 'billing.json' );
10935
+
10936
+ self::shoot_ajax_success();
10937
+ }
10938
+
10939
+ /**
10940
+ * Trial start for anonymous users (AJAX callback).
10941
+ *
10942
+ * @author Vova Feldman (@svovaf)
10943
+ * @since 1.2.1.5
10944
+ */
10945
+ function _start_trial_ajax_action() {
10946
+ $this->_logger->entrance();
10947
+
10948
+ $this->check_ajax_referer( 'start_trial' );
10949
+
10950
+ if ( ! $this->is_user_admin() ) {
10951
+ // Only for admins.
10952
+ self::shoot_ajax_failure();
10953
+ }
10954
+
10955
+ $trial_data = fs_request_get( 'trial' );
10956
+
10957
+ $next_page = $this->opt_in(
10958
+ false,
10959
+ false,
10960
+ false,
10961
+ false,
10962
+ false,
10963
+ $trial_data['plan_id']
10964
+ );
10965
+
10966
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
10967
+ self::shoot_ajax_failure(
10968
+ isset( $next_page->error ) ?
10969
+ $next_page->error->message :
10970
+ var_export( $next_page, true )
10971
+ );
10972
+ }
10973
+
10974
+ $this->shoot_ajax_success( array(
10975
+ 'next_page' => $next_page,
10976
+ ) );
10977
+ }
10978
+
10979
+ /**
10980
+ * @author Leo Fajardo (@leorw)
10981
+ * @since 1.2.0
10982
+ */
10983
+ function _resend_license_key_ajax_action() {
10984
+ $this->_logger->entrance();
10985
+
10986
+ $this->check_ajax_referer( 'resend_license_key' );
10987
+
10988
+ $email_address = sanitize_email( trim( fs_request_get( 'email', '', 'post' ) ) );
10989
+
10990
+ if ( empty( $email_address ) ) {
10991
+ exit;
10992
+ }
10993
+
10994
+ $error = false;
10995
+
10996
+ $api = $this->get_api_plugin_scope();
10997
+ $result = $api->call( '/licenses/resend.json', 'post',
10998
+ array(
10999
+ 'email' => $email_address,
11000
+ 'url' => home_url(),
11001
+ )
11002
+ );
11003
+
11004
+ if ( is_object( $result ) && isset( $result->error ) ) {
11005
+ $error = $result->error;
11006
+
11007
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
11008
+ $error = $this->get_text_inline( "We couldn't find your email address in the system, are you sure it's the right address?", 'email-not-found' );
11009
+ } else if ( 'no_license' === $error->code ) {
11010
+ $error = $this->get_text_inline( "We can't see any active licenses associated with that email address, are you sure it's the right address?", 'no-active-licenses' );
11011
+ } else {
11012
+ $error = $error->message;
11013
+ }
11014
+ }
11015
+
11016
+ $licenses = array(
11017
+ 'success' => ( false === $error )
11018
+ );
11019
+
11020
+ if ( false !== $error ) {
11021
+ $licenses['error'] = sprintf( '%s... %s', $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ), strtolower( $error ) );
11022
+ }
11023
+
11024
+ echo json_encode( $licenses );
11025
+
11026
+ exit;
11027
+ }
11028
+
11029
+ /**
11030
+ * @author Vova Feldman (@svovaf)
11031
+ * @since 1.2.1.8
11032
+ *
11033
+ * @var string
11034
+ */
11035
+ private static $_pagenow;
11036
+
11037
+ /**
11038
+ * Get current page or the referer if executing a WP AJAX request.
11039
+ *
11040
+ * @author Vova Feldman (@svovaf)
11041
+ * @since 1.2.1.8
11042
+ *
11043
+ * @return string
11044
+ */
11045
+ static function get_current_page() {
11046
+ if ( ! isset( self::$_pagenow ) ) {
11047
+ global $pagenow;
11048
+
11049
+ self::$_pagenow = $pagenow;
11050
+
11051
+ if ( self::is_ajax() &&
11052
+ 'admin-ajax.php' === $pagenow
11053
+ ) {
11054
+ $referer = fs_get_raw_referer();
11055
+
11056
+ if ( is_string( $referer ) ) {
11057
+ $parts = explode( '?', $referer );
11058
+
11059
+ self::$_pagenow = basename( $parts[0] );
11060
+ }
11061
+ }
11062
+ }
11063
+
11064
+ return self::$_pagenow;
11065
+ }
11066
+
11067
+ /**
11068
+ * Helper method to check if user in the plugins page.
11069
+ *
11070
+ * @author Vova Feldman (@svovaf)
11071
+ * @since 1.2.1.5
11072
+ *
11073
+ * @return bool
11074
+ */
11075
+ static function is_plugins_page() {
11076
+ return ( 'plugins.php' === self::get_current_page() );
11077
+ }
11078
+
11079
+ /**
11080
+ * @author Leo Fajardo (@leorw)
11081
+ * @since 2.0.2
11082
+ *
11083
+ * @return bool
11084
+ */
11085
+ static function is_updates_page() {
11086
+ return ( 'update-core.php' === self::get_current_page() );
11087
+ }
11088
+
11089
+ /**
11090
+ * Helper method to check if user in the themes page.
11091
+ *
11092
+ * @author Vova Feldman (@svovaf)
11093
+ * @since 1.2.2.6
11094
+ *
11095
+ * @return bool
11096
+ */
11097
+ static function is_themes_page() {
11098
+ return ( 'themes.php' === self::get_current_page() );
11099
+ }
11100
+
11101
+ #----------------------------------------------------------------------------------
11102
+ #region Affiliation
11103
+ #----------------------------------------------------------------------------------
11104
+
11105
+ /**
11106
+ * @author Leo Fajardo (@leorw)
11107
+ * @since 1.2.3
11108
+ *
11109
+ * @return bool
11110
+ */
11111
+ function has_affiliate_program() {
11112
+ if ( ! is_object( $this->_plugin ) ) {
11113
+ return false;
11114
+ }
11115
+
11116
+ return $this->_plugin->has_affiliate_program();
11117
+ }
11118
+
11119
+ /**
11120
+ * @author Leo Fajardo (@leorw)
11121
+ * @since 1.2.4
11122
+ */
11123
+ private function fetch_affiliate_terms() {
11124
+ if ( ! is_object( $this->plugin_affiliate_terms ) ) {
11125
+ $plugins_api = $this->get_api_plugin_scope();
11126
+ $affiliate_terms = $plugins_api->get( '/aff.json?type=affiliation', false );
11127
+
11128
+ if ( ! $this->is_api_result_entity( $affiliate_terms ) ) {
11129
+ return;
11130
+ }
11131
+
11132
+ $this->plugin_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11133
+ }
11134
+ }
11135
+
11136
+ /**
11137
+ * @author Leo Fajardo (@leorw)
11138
+ * @since 1.2.4
11139
+ */
11140
+ private function fetch_affiliate_and_custom_terms() {
11141
+ if ( ! empty( $this->_storage->affiliate_application_data ) ) {
11142
+ $application_data = $this->_storage->affiliate_application_data;
11143
+ $flush = ( ! isset( $application_data['status'] ) || 'pending' === $application_data['status'] );
11144
+
11145
+ $users_api = $this->get_api_user_scope();
11146
+ $result = $users_api->get( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json", $flush );
11147
+ if ( $this->is_api_result_object( $result, 'affiliates' ) ) {
11148
+ if ( ! empty( $result->affiliates ) ) {
11149
+ $affiliate = new FS_Affiliate( $result->affiliates[0] );
11150
+
11151
+ if ( ! isset( $application_data['status'] ) || $application_data['status'] !== $affiliate->status ) {
11152
+ $application_data['status'] = $affiliate->status;
11153
+ $this->_storage->affiliate_application_data = $application_data;
11154
+ }
11155
+
11156
+ if ( $affiliate->is_using_custom_terms ) {
11157
+ $affiliate_terms = $users_api->get( "/plugins/{$this->_plugin->id}/affiliates/{$affiliate->id}/aff/{$affiliate->custom_affiliate_terms_id}.json", $flush );
11158
+ if ( $this->is_api_result_entity( $affiliate_terms ) ) {
11159
+ $this->custom_affiliate_terms = new FS_AffiliateTerms( $affiliate_terms );
11160
+ }
11161
+ }
11162
+
11163
+ $this->affiliate = $affiliate;
11164
+ }
11165
+ }
11166
+ }
11167
+ }
11168
+
11169
+ /**
11170
+ * @author Leo Fajardo (@leorw)
11171
+ * @since 1.2.3
11172
+ */
11173
+ private function fetch_affiliate_and_terms() {
11174
+ $this->_logger->entrance();
11175
+
11176
+ $this->fetch_affiliate_terms();
11177
+ $this->fetch_affiliate_and_custom_terms();
11178
+ }
11179
+
11180
+ /**
11181
+ * @author Leo Fajardo (@leorw)
11182
+ * @since 1.2.3
11183
+ *
11184
+ * @return FS_Affiliate
11185
+ */
11186
+ function get_affiliate() {
11187
+ return $this->affiliate;
11188
+ }
11189
+
11190
+
11191
+ /**
11192
+ * @author Leo Fajardo (@leorw)
11193
+ * @since 1.2.3
11194
+ *
11195
+ * @return FS_AffiliateTerms
11196
+ */
11197
+ function get_affiliate_terms() {
11198
+ return is_object( $this->custom_affiliate_terms ) ?
11199
+ $this->custom_affiliate_terms :
11200
+ $this->plugin_affiliate_terms;
11201
+ }
11202
+
11203
+ /**
11204
+ * @author Leo Fajardo (@leorw)
11205
+ * @since 1.2.3
11206
+ */
11207
+ function _submit_affiliate_application() {
11208
+ $this->_logger->entrance();
11209
+
11210
+ $this->check_ajax_referer( 'submit_affiliate_application' );
11211
+
11212
+ if ( ! $this->is_user_admin() ) {
11213
+ // Only for admins.
11214
+ self::shoot_ajax_failure();
11215
+ }
11216
+
11217
+ $affiliate = fs_request_get( 'affiliate' );
11218
+
11219
+ if ( empty( $affiliate['promotion_methods'] ) ) {
11220
+ unset( $affiliate['promotion_methods'] );
11221
+ }
11222
+
11223
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11224
+ $affiliate['additional_domains'] = array_unique( $affiliate['additional_domains'] );
11225
+ }
11226
+
11227
+ if ( ! $this->is_registered() ) {
11228
+ // Opt in but don't track usage.
11229
+ $next_page = $this->opt_in(
11230
+ false,
11231
+ false,
11232
+ false,
11233
+ false,
11234
+ false,
11235
+ false,
11236
+ true
11237
+ );
11238
+
11239
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
11240
+ self::shoot_ajax_failure(
11241
+ isset( $next_page->error ) ?
11242
+ $next_page->error->message :
11243
+ var_export( $next_page, true )
11244
+ );
11245
+ } else if ( $this->is_pending_activation() ) {
11246
+ self::shoot_ajax_failure( $this->get_text_inline( 'Account is pending activation.', 'account-is-pending-activation' ) );
11247
+ }
11248
+ }
11249
+
11250
+ $this->fetch_affiliate_terms();
11251
+
11252
+ $api = $this->get_api_user_scope();
11253
+ $result = $api->call(
11254
+ ( "/plugins/{$this->_plugin->id}/aff/{$this->plugin_affiliate_terms->id}/affiliates.json" ),
11255
+ 'post',
11256
+ $affiliate
11257
+ );
11258
+
11259
+ if ( $this->is_api_error( $result ) ) {
11260
+ self::shoot_ajax_failure(
11261
+ isset( $result->error ) ?
11262
+ $result->error->message :
11263
+ var_export( $result, true )
11264
+ );
11265
+ } else {
11266
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
11267
+ $this->_admin_notices->remove_sticky( 'affiliate_program' );
11268
+ }
11269
+
11270
+ $affiliate_application_data = array(
11271
+ 'status' => 'pending',
11272
+ 'stats_description' => $affiliate['stats_description'],
11273
+ 'promotion_method_description' => $affiliate['promotion_method_description'],
11274
+ );
11275
+
11276
+ if ( ! empty( $affiliate['promotion_methods'] ) ) {
11277
+ $affiliate_application_data['promotion_methods'] = $affiliate['promotion_methods'];
11278
+ }
11279
+
11280
+ if ( ! empty( $affiliate['domain'] ) ) {
11281
+ $affiliate_application_data['domain'] = $affiliate['domain'];
11282
+ }
11283
+
11284
+ if ( ! empty( $affiliate['additional_domains'] ) ) {
11285
+ $affiliate_application_data['additional_domains'] = $affiliate['additional_domains'];
11286
+ }
11287
+
11288
+ $this->_storage->affiliate_application_data = $affiliate_application_data;
11289
+ }
11290
+
11291
+ // Purge cached affiliate.
11292
+ $api->purge_cache( 'affiliate.json' );
11293
+
11294
+ self::shoot_ajax_success( $result );
11295
+ }
11296
+
11297
+ /**
11298
+ * @author Leo Fajardo (@leorw)
11299
+ * @since 1.2.3
11300
+ *
11301
+ * @return array|null
11302
+ */
11303
+ function get_affiliate_application_data() {
11304
+ if ( empty( $this->_storage->affiliate_application_data ) ) {
11305
+ return null;
11306
+ }
11307
+
11308
+ return $this->_storage->affiliate_application_data;
11309
+ }
11310
+
11311
+ #endregion Affiliation ------------------------------------------------------------
11312
+
11313
+ #----------------------------------------------------------------------------------
11314
+ #region URL Generators
11315
+ #----------------------------------------------------------------------------------
11316
+
11317
+ /**
11318
+ * Alias to pricing_url().
11319
+ *
11320
+ * @author Vova Feldman (@svovaf)
11321
+ * @since 1.0.2
11322
+ *
11323
+ * @uses pricing_url()
11324
+ *
11325
+ * @param string $period Billing cycle
11326
+ * @param bool $is_trial
11327
+ *
11328
+ * @return string
11329
+ */
11330
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11331
+ return $this->pricing_url( $period, $is_trial );
11332
+ }
11333
+
11334
+ /**
11335
+ * @author Vova Feldman (@svovaf)
11336
+ * @since 1.0.9
11337
+ *
11338
+ * @uses get_upgrade_url()
11339
+ *
11340
+ * @return string
11341
+ */
11342
+ function get_trial_url() {
11343
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
11344
+ }
11345
+
11346
+ /**
11347
+ * Plugin's pricing URL.
11348
+ *
11349
+ * @author Vova Feldman (@svovaf)
11350
+ * @since 1.0.4
11351
+ *
11352
+ * @param string $billing_cycle Billing cycle
11353
+ *
11354
+ * @param bool $is_trial
11355
+ *
11356
+ * @return string
11357
+ */
11358
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
11359
+ $this->_logger->entrance();
11360
+
11361
+ $params = array(
11362
+ 'billing_cycle' => $billing_cycle
11363
+ );
11364
+
11365
+ if ( $is_trial ) {
11366
+ $params['trial'] = 'true';
11367
+ }
11368
+
11369
+ if ( $this->is_addon() ) {
11370
+ return $this->_parent->addon_url( $this->_slug );
11371
+ }
11372
+
11373
+ return $this->_get_admin_page_url( 'pricing', $params );
11374
+ }
11375
+
11376
+ /**
11377
+ * Checkout page URL.
11378
+ *
11379
+ * @author Vova Feldman (@svovaf)
11380
+ * @since 1.0.6
11381
+ *
11382
+ * @param string $billing_cycle Billing cycle
11383
+ * @param bool $is_trial
11384
+ * @param array $extra (optional) Extra parameters, override other query params.
11385
+ *
11386
+ * @return string
11387
+ */
11388
+ function checkout_url(
11389
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
11390
+ $is_trial = false,
11391
+ $extra = array()
11392
+ ) {
11393
+ $this->_logger->entrance();
11394
+
11395
+ $params = array(
11396
+ 'checkout' => 'true',
11397
+ 'billing_cycle' => $billing_cycle,
11398
+ );
11399
+
11400
+ if ( $is_trial ) {
11401
+ $params['trial'] = 'true';
11402
+ }
11403
+
11404
+ /**
11405
+ * Params in extra override other params.
11406
+ */
11407
+ $params = array_merge( $params, $extra );
11408
+
11409
+ return $this->_get_admin_page_url( 'pricing', $params );
11410
+ }
11411
+
11412
+ /**
11413
+ * Add-on checkout URL.
11414
+ *
11415
+ * @author Vova Feldman (@svovaf)
11416
+ * @since 1.1.7
11417
+ *
11418
+ * @param number $addon_id
11419
+ * @param number $pricing_id
11420
+ * @param string $billing_cycle
11421
+ * @param bool $is_trial
11422
+ *
11423
+ * @return string
11424
+ */
11425
+ function addon_checkout_url(
11426
+ $addon_id,
11427
+ $pricing_id,
11428
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
11429
+ $is_trial = false
11430
+ ) {
11431
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
11432
+ 'plugin_id' => $addon_id,
11433
+ 'pricing_id' => $pricing_id,
11434
+ ) );
11435
+ }
11436
+
11437
+ #endregion
11438
+
11439
+ #endregion ------------------------------------------------------------------
11440
+
11441
+ /**
11442
+ * Check if plugin has any add-ons.
11443
+ *
11444
+ * @author Vova Feldman (@svovaf)
11445
+ * @since 1.0.5
11446
+ *
11447
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
11448
+ *
11449
+ * @return bool
11450
+ */
11451
+ function has_addons() {
11452
+ $this->_logger->entrance();
11453
+
11454
+ return $this->_has_addons;
11455
+ }
11456
+
11457
+ /**
11458
+ * Check if plugin can work in anonymous mode.
11459
+ *
11460
+ * @author Vova Feldman (@svovaf)
11461
+ * @since 1.0.9
11462
+ *
11463
+ * @return bool
11464
+ *
11465
+ * @deprecated Please use is_enable_anonymous() instead.
11466
+ */
11467
+ function enable_anonymous() {
11468
+ return $this->_enable_anonymous;
11469
+ }
11470
+
11471
+ /**
11472
+ * Check if plugin can work in anonymous mode.
11473
+ *
11474
+ * @author Vova Feldman (@svovaf)
11475
+ * @since 1.1.9
11476
+ *
11477
+ * @return bool
11478
+ */
11479
+ function is_enable_anonymous() {
11480
+ return $this->_enable_anonymous;
11481
+ }
11482
+
11483
+ /**
11484
+ * Check if plugin is premium only (no free plans).
11485
+ *
11486
+ * @author Vova Feldman (@svovaf)
11487
+ * @since 1.1.9
11488
+ *
11489
+ * @return bool
11490
+ */
11491
+ function is_only_premium() {
11492
+ return $this->_is_premium_only;
11493
+ }
11494
+
11495
+ /**
11496
+ * Checks if the plugin's type is "plugin". The other type is "theme".
11497
+ *
11498
+ * @author Leo Fajardo (@leorw)
11499
+ * @since 1.2.2
11500
+ *
11501
+ * @return bool
11502
+ */
11503
+ function is_plugin() {
11504
+ return ( WP_FS__MODULE_TYPE_PLUGIN === $this->_module_type );
11505
+ }
11506
+
11507
+ /**
11508
+ * @author Leo Fajardo (@leorw)
11509
+ * @since 1.2.2
11510
+ *
11511
+ * @return string
11512
+ */
11513
+ function get_module_type() {
11514
+ if ( ! isset( $this->_module_type ) ) {
11515
+ $id_slug_type_path_map = self::$_accounts->get_option( 'id_slug_type_path_map', array() );
11516
+ $this->_module_type = $id_slug_type_path_map[ $this->_module_id ]['type'];
11517
+ }
11518
+
11519
+ return $this->_module_type;
11520
+ }
11521
+
11522
+ /**
11523
+ * @author Leo Fajardo (@leorw)
11524
+ * @since 1.2.2
11525
+ *
11526
+ * @return string
11527
+ */
11528
+ function get_plugin_main_file_path() {
11529
+ return $this->_plugin_main_file_path;
11530
+ }
11531
+
11532
+ /**
11533
+ * Check if module has a premium code version.
11534
+ *
11535
+ * Serviceware module might be freemium without any
11536
+ * premium code version, where the paid features
11537
+ * are all part of the service.
11538
+ *
11539
+ * @author Vova Feldman (@svovaf)
11540
+ * @since 1.2.1.6
11541
+ *
11542
+ * @return bool
11543
+ */
11544
+ function has_premium_version() {
11545
+ return $this->_has_premium_version;
11546
+ }
11547
+
11548
+ /**
11549
+ * Check if feature supported with current site's plan.
11550
+ *
11551
+ * @author Vova Feldman (@svovaf)
11552
+ * @since 1.0.1
11553
+ *
11554
+ * @todo IMPLEMENT
11555
+ *
11556
+ * @param number $feature_id
11557
+ *
11558
+ * @throws Exception
11559
+ */
11560
+ function is_feature_supported( $feature_id ) {
11561
+ throw new Exception( 'not implemented' );
11562
+ }
11563
+
11564
+ /**
11565
+ * @author Vova Feldman (@svovaf)
11566
+ * @since 1.0.1
11567
+ *
11568
+ * @return bool Is running in SSL/HTTPS
11569
+ */
11570
+ function is_ssl() {
11571
+ return WP_FS__IS_HTTPS;
11572
+ }
11573
+
11574
+ /**
11575
+ * @author Vova Feldman (@svovaf)
11576
+ * @since 1.0.9
11577
+ *
11578
+ * @return bool Is running in AJAX call.
11579
+ *
11580
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
11581
+ */
11582
+ static function is_ajax() {
11583
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
11584
+ }
11585
+
11586
+ /**
11587
+ * Check if it's an AJAX call targeted for the current module.
11588
+ *
11589
+ * @author Vova Feldman (@svovaf)
11590
+ * @since 1.2.0
11591
+ *
11592
+ * @param array|string $actions Collection of AJAX actions.
11593
+ *
11594
+ * @return bool
11595
+ */
11596
+ function is_ajax_action( $actions ) {
11597
+ // Verify it's an ajax call.
11598
+ if ( ! self::is_ajax() ) {
11599
+ return false;
11600
+ }
11601
+
11602
+ // Verify the call is relevant for the plugin.
11603
+ if ( $this->_module_id != fs_request_get( 'module_id' ) ) {
11604
+ return false;
11605
+ }
11606
+
11607
+ // Verify it's one of the specified actions.
11608
+ if ( is_string( $actions ) ) {
11609
+ $actions = explode( ',', $actions );
11610
+ }
11611
+
11612
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
11613
+ $ajax_action = fs_request_get( 'action' );
11614
+
11615
+ foreach ( $actions as $action ) {
11616
+ if ( $ajax_action === $this->get_action_tag( $action ) ) {
11617
+ return true;
11618
+ }
11619
+ }
11620
+ }
11621
+
11622
+ return false;
11623
+ }
11624
+
11625
+ /**
11626
+ * Check if it's an AJAX call targeted for current request.
11627
+ *
11628
+ * @author Vova Feldman (@svovaf)
11629
+ * @since 1.2.0
11630
+ *
11631
+ * @param array|string $actions Collection of AJAX actions.
11632
+ * @param number|null $module_id
11633
+ *
11634
+ * @return bool
11635
+ */
11636
+ static function is_ajax_action_static( $actions, $module_id = null ) {
11637
+ // Verify it's an ajax call.
11638
+ if ( ! self::is_ajax() ) {
11639
+ return false;
11640
+ }
11641
+
11642
+
11643
+ if ( ! empty( $module_id ) ) {
11644
+ // Verify the call is relevant for the plugin.
11645
+ if ( $module_id != fs_request_get( 'module_id' ) ) {
11646
+ return false;
11647
+ }
11648
+ }
11649
+
11650
+ // Verify it's one of the specified actions.
11651
+ if ( is_string( $actions ) ) {
11652
+ $actions = explode( ',', $actions );
11653
+ }
11654
+
11655
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
11656
+ $ajax_action = fs_request_get( 'action' );
11657
+
11658
+ foreach ( $actions as $action ) {
11659
+ if ( $ajax_action === self::get_ajax_action_static( $action, $module_id ) ) {
11660
+ return true;
11661
+ }
11662
+ }
11663
+ }
11664
+
11665
+ return false;
11666
+ }
11667
+
11668
+ /**
11669
+ * @author Vova Feldman (@svovaf)
11670
+ * @since 1.1.7
11671
+ *
11672
+ * @return bool
11673
+ */
11674
+ static function is_cron() {
11675
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
11676
+ }
11677
+
11678
+ /**
11679
+ * Check if a real user is visiting the admin dashboard.
11680
+ *
11681
+ * @author Vova Feldman (@svovaf)
11682
+ * @since 1.1.7
11683
+ *
11684
+ * @return bool
11685
+ */
11686
+ function is_user_in_admin() {
11687
+ return is_admin() && ! self::is_ajax() && ! self::is_cron();
11688
+ }
11689
+
11690
+ /**
11691
+ * Check if a real user is in the customizer view.
11692
+ *
11693
+ * @author Vova Feldman (@svovaf)
11694
+ * @since 1.2.2.7
11695
+ *
11696
+ * @return bool
11697
+ */
11698
+ static function is_customizer() {
11699
+ return is_customize_preview();
11700
+ }
11701
+
11702
+ /**
11703
+ * Check if running in HTTPS and if site's plan matching the specified plan.
11704
+ *
11705
+ * @param string $plan
11706
+ * @param bool $exact
11707
+ *
11708
+ * @return bool
11709
+ */
11710
+ function is_ssl_and_plan( $plan, $exact = false ) {
11711
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
11712
+ }
11713
+
11714
+ /**
11715
+ * Construct plugin's settings page URL.
11716
+ *
11717
+ * @author Vova Feldman (@svovaf)
11718
+ * @since 1.0.4
11719
+ *
11720
+ * @param string $page
11721
+ * @param array $params
11722
+ * @param bool|null $network
11723
+ *
11724
+ * @return string
11725
+ */
11726
+ function _get_admin_page_url( $page = '', $params = array(), $network = null ) {
11727
+ if ( is_null( $network ) ) {
11728
+ $network = (
11729
+ $this->_is_network_active &&
11730
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
11731
+ );
11732
+ }
11733
+
11734
+ if ( 0 < count( $params ) ) {
11735
+ foreach ( $params as $k => $v ) {
11736
+ $params[ $k ] = urlencode( $v );
11737
+ }
11738
+ }
11739
+
11740
+ $page_param = $this->_menu->get_slug( $page );
11741
+
11742
+ if ( empty( $page ) &&
11743
+ $this->is_theme() &&
11744
+ // Show the opt-in as an overlay for free wp.org themes or themes without any settings page.
11745
+ ( $this->is_free_wp_org_theme() || ! $this->has_settings_menu() )
11746
+ ) {
11747
+ $params[ $this->get_unique_affix() . '_show_optin' ] = 'true';
11748
+
11749
+ return add_query_arg(
11750
+ $params,
11751
+ $this->admin_url( 'themes.php', 'admin', $network )
11752
+ );
11753
+ }
11754
+
11755
+ if ( ! $this->has_settings_menu() ) {
11756
+ if ( ! empty( $page ) ) {
11757
+ // Module doesn't have a setting page, but since the request is for
11758
+ // a specific Freemius page, use the admin.php path.
11759
+ return add_query_arg( array_merge( $params, array(
11760
+ 'page' => $page_param,
11761
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11762
+ } else {
11763
+ if ( $this->is_activation_mode() ) {
11764
+ /**
11765
+ * @author Vova Feldman
11766
+ * @since 1.2.1.6
11767
+ *
11768
+ * If plugin doesn't have a settings page, create one for the opt-in screen.
11769
+ */
11770
+ return add_query_arg( array_merge( $params, array(
11771
+ 'page' => $this->_slug,
11772
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11773
+ } else {
11774
+ // Plugin without a settings page.
11775
+ return add_query_arg(
11776
+ $params,
11777
+ $this->admin_url( 'plugins.php', 'admin', $network )
11778
+ );
11779
+ }
11780
+ }
11781
+ }
11782
+
11783
+ // Module has a submenu settings page.
11784
+ if ( ! $this->_menu->is_top_level() ) {
11785
+ $parent_slug = $this->_menu->get_parent_slug();
11786
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
11787
+ $parent_slug :
11788
+ 'admin.php';
11789
+
11790
+ return add_query_arg( array_merge( $params, array(
11791
+ 'page' => $page_param,
11792
+ ) ), $this->admin_url( $menu_file, 'admin', $network ) );
11793
+ }
11794
+
11795
+ // Module has a top level CPT settings page.
11796
+ if ( $this->_menu->is_cpt() ) {
11797
+ if ( empty( $page ) && $this->is_activation_mode() ) {
11798
+ return add_query_arg( array_merge( $params, array(
11799
+ 'page' => $page_param
11800
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11801
+ } else {
11802
+ if ( ! empty( $page ) ) {
11803
+ $params['page'] = $page_param;
11804
+ }
11805
+
11806
+ return add_query_arg(
11807
+ $params,
11808
+ $this->admin_url( $this->_menu->get_raw_slug(), 'admin', $network )
11809
+ );
11810
+ }
11811
+ }
11812
+
11813
+ // Module has a custom top level settings page.
11814
+ return add_query_arg( array_merge( $params, array(
11815
+ 'page' => $page_param,
11816
+ ) ), $this->admin_url( 'admin.php', 'admin', $network ) );
11817
+ }
11818
+
11819
+ #--------------------------------------------------------------------------------
11820
+ #region Multisite
11821
+ #--------------------------------------------------------------------------------
11822
+
11823
+ /**
11824
+ * @author Leo Fajardo (@leorw)
11825
+ * @since 2.0.0
11826
+ *
11827
+ * @return bool
11828
+ */
11829
+ function is_network_active() {
11830
+ return $this->_is_network_active;
11831
+ }
11832
+
11833
+ /**
11834
+ * Delegate activation for the given sites in the network (or all sites if `null`) to site admins.
11835
+ *
11836
+ * @author Leo Fajardo (@leorw)
11837
+ * @since 2.0.0
11838
+ *
11839
+ * @param array|null $sites
11840
+ */
11841
+ private function delegate_connection( $sites = null ) {
11842
+ $this->_logger->entrance();
11843
+
11844
+ $this->_admin_notices->remove_sticky( 'connect_account' );
11845
+
11846
+ if ( is_null( $sites ) ) {
11847
+ // All sites delegation.
11848
+ $this->_storage->store( 'is_delegated_connection', true, true, true );
11849
+ } else {
11850
+ // Specified sites delegation.
11851
+ foreach ( $sites as $site ) {
11852
+ $this->delegate_site_connection( $site['blog_id'] );
11853
+ }
11854
+ }
11855
+
11856
+ $this->network_upgrade_mode_completed();
11857
+ }
11858
+
11859
+ /**
11860
+ * Delegate specific network site conncetion to the site admin.
11861
+ *
11862
+ * @author Vova Feldman (@svovaf)
11863
+ * @since 2.0.0
11864
+ *
11865
+ * @param int $blog_id
11866
+ */
11867
+ private function delegate_site_connection( $blog_id ) {
11868
+ $this->_storage->store( 'is_delegated_connection', true, $blog_id, true );
11869
+ }
11870
+
11871
+ /**
11872
+ * Check if super-admin delegated the connection of ALL sites to the site admins.
11873
+ *
11874
+ * @author Vova Feldman (@svovaf)
11875
+ * @since 2.0.0
11876
+ *
11877
+ * @return bool
11878
+ */
11879
+ function is_network_delegated_connection() {
11880
+ if ( ! $this->_is_network_active ) {
11881
+ return false;
11882
+ }
11883
+
11884
+ return $this->_storage->get( 'is_delegated_connection', false, true );
11885
+ }
11886
+
11887
+ /**
11888
+ * @author Leo Fajardo (@leorw)
11889
+ * @since 2.0.0
11890
+ *
11891
+ * @param int $blog_id
11892
+ *
11893
+ * @return bool
11894
+ */
11895
+ function is_site_delegated_connection( $blog_id = 0 ) {
11896
+ if ( ! $this->_is_network_active ) {
11897
+ return false;
11898
+ }
11899
+
11900
+ if ( 0 == $blog_id ) {
11901
+ $blog_id = get_current_blog_id();
11902
+ }
11903
+
11904
+ return $this->_storage->get( 'is_delegated_connection', false, $blog_id );
11905
+ }
11906
+
11907
+ /**
11908
+ * Check if delegated the connection. When running within the the network admin,
11909
+ * and haven't specified the blog ID, checks if network level delegated. If running
11910
+ * within a site admin or specified a blog ID, check if delegated the connection for
11911
+ * the current context site.
11912
+ *
11913
+ * If executed outside the the admin, check if delegated the connection
11914
+ * for the current context site OR the whole network.
11915
+ *
11916
+ * @author Vova Feldman (@svovaf)
11917
+ * @since 2.0.0
11918
+ *
11919
+ * @param int $blog_id If set, checks if network delegated or blog specific delegated.
11920
+ *
11921
+ * @return bool
11922
+ */
11923
+ function is_delegated_connection( $blog_id = 0 ) {
11924
+ if ( ! $this->_is_network_active ) {
11925
+ return false;
11926
+ }
11927
+
11928
+ if ( fs_is_network_admin() && 0 == $blog_id ) {
11929
+ return $this->is_network_delegated_connection();
11930
+ }
11931
+
11932
+ return (
11933
+ $this->is_network_delegated_connection() ||
11934
+ $this->is_site_delegated_connection( $blog_id )
11935
+ );
11936
+ }
11937
+
11938
+ /**
11939
+ * Check if the current module is active for the site.
11940
+ *
11941
+ * @author Vova Feldman (@svovaf)
11942
+ * @since 2.0.0
11943
+ *
11944
+ * @param int $blog_id
11945
+ *
11946
+ * @return bool
11947
+ */
11948
+ function is_active_for_site( $blog_id ) {
11949
+ if ( ! is_multisite() ) {
11950
+ // Not a multisite and this code is executed, means that the plugin is active.
11951
+ return true;
11952
+ }
11953
+
11954
+ if ( $this->is_theme() ) {
11955
+ // All themes are site level activated.
11956
+ return true;
11957
+ }
11958
+
11959
+ if ( $this->_is_network_active ) {
11960
+ // Plugin was network activated so it's active.
11961
+ return true;
11962
+ }
11963
+
11964
+ return in_array( $this->_plugin_basename, (array) get_blog_option( $blog_id, 'active_plugins', array() ) );
11965
+ }
11966
+
11967
+ /**
11968
+ * @author Leo Fajardo (@leorw)
11969
+ * @since 2.0.0
11970
+ *
11971
+ * @return array Active & public sites collection.
11972
+ */
11973
+ static function get_sites() {
11974
+ /**
11975
+ * For consistency with get_blog_list() which only return active public sites.
11976
+ *
11977
+ * @author Vova Feldman (@svovaf)
11978
+ */
11979
+ $args = array(
11980
+ 'public' => 1,
11981
+ 'archived' => 0,
11982
+ 'mature' => 0,
11983
+ 'spam' => 0,
11984
+ 'deleted' => 0,
11985
+ );
11986
+
11987
+ if ( function_exists( 'get_sites' ) ) {
11988
+ // For WP 4.6 and above.
11989
+ return get_sites( $args );
11990
+ } else if ( function_exists( 'wp_get_sites' ) ) {
11991
+ // For WP 3.7 to WP 4.5.
11992
+ return wp_get_sites( $args );
11993
+ } else {
11994
+ // For WP 3.6 and below.
11995
+ return get_blog_list( 0, 'all' );
11996
+ }
11997
+ }
11998
+
11999
+ /**
12000
+ * Checks if a given blog is active.
12001
+ *
12002
+ * @author Vova Feldman (@svovaf)
12003
+ * @since 2.0.0
12004
+ *
12005
+ * @param $blog_id
12006
+ *
12007
+ * @return bool
12008
+ */
12009
+ private static function is_site_active( $blog_id ) {
12010
+ global $wpdb;
12011
+
12012
+ $blog_info = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d", $blog_id ) );
12013
+
12014
+ if ( ! is_object( $blog_info ) ) {
12015
+ return false;
12016
+ }
12017
+
12018
+ return (
12019
+ true == $blog_info->public &&
12020
+ false == $blog_info->archived &&
12021
+ false == $blog_info->mature &&
12022
+ false == $blog_info->spam &&
12023
+ false == $blog_info->deleted
12024
+ );
12025
+ }
12026
+
12027
+ /**
12028
+ * Get a mapping between the site addresses to their blog IDs.
12029
+ *
12030
+ * @author Vova Feldman (@svovaf)
12031
+ * @since 2.0.0
12032
+ *
12033
+ * @return array {
12034
+ * @key string Site address without protocol with a trailing slash.
12035
+ * @value int Site's blog ID.
12036
+ * }
12037
+ */
12038
+ private function get_address_to_blog_map() {
12039
+ $sites = self::get_sites();
12040
+
12041
+ // Map site addresses to their blog IDs.
12042
+ $address_to_blog_map = array();
12043
+ foreach ( $sites as $site ) {
12044
+ $blog_id = self::get_site_blog_id( $site );
12045
+ $address = trailingslashit( fs_strip_url_protocol( get_site_url( $blog_id ) ) );
12046
+ $address_to_blog_map[ $address ] = $blog_id;
12047
+ }
12048
+
12049
+ return $address_to_blog_map;
12050
+ }
12051
+
12052
+ /**
12053
+ * Get a mapping between the site addresses to their blog IDs.
12054
+ *
12055
+ * @author Vova Feldman (@svovaf)
12056
+ * @since 2.0.0
12057
+ *
12058
+ * @return array {
12059
+ * @key int Site's blog ID.
12060
+ * @value FS_Site Associated install.
12061
+ * }
12062
+ */
12063
+ function get_blog_install_map() {
12064
+ $sites = self::get_sites();
12065
+
12066
+ // Map site blog ID to its install.
12067
+ $install_map = array();
12068
+
12069
+ foreach ( $sites as $site ) {
12070
+ $blog_id = self::get_site_blog_id( $site );
12071
+ $install = $this->get_install_by_blog_id( $blog_id );
12072
+
12073
+ if ( is_object( $install ) ) {
12074
+ $install_map[ $blog_id ] = $install;
12075
+ }
12076
+ }
12077
+
12078
+ return $install_map;
12079
+ }
12080
+
12081
+ /**
12082
+ * Gets a map of module IDs that the given user has opted-in to.
12083
+ *
12084
+ * @author Leo Fajardo (@leorw)
12085
+ * @since 2.1.0
12086
+ *
12087
+ * @param number $fs_user_id
12088
+ *
12089
+ * @return array {
12090
+ * @key number $plugin_id
12091
+ * @value bool Always true.
12092
+ * }
12093
+ */
12094
+ private static function get_user_opted_in_module_ids_map( $fs_user_id ) {
12095
+ self::$_static_logger->entrance();
12096
+
12097
+ if ( ! is_multisite() ) {
12098
+ $installs = array_merge(
12099
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN ),
12100
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME )
12101
+ );
12102
+ } else {
12103
+ $sites = self::get_sites();
12104
+
12105
+ $installs = array();
12106
+ foreach ( $sites as $site ) {
12107
+ $blog_id = self::get_site_blog_id( $site );
12108
+
12109
+ $installs = array_merge(
12110
+ $installs,
12111
+ self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN, $blog_id ),
12112
+ self::get_all_sites( WP_FS__MODULE_TYPE_THEME, $blog_id )
12113
+ );
12114
+ }
12115
+ }
12116
+
12117
+ $module_ids_map = array();
12118
+ foreach ( $installs as $install ) {
12119
+ if ( is_object( $install ) &&
12120
+ FS_Site::is_valid_id( $install->id ) &&
12121
+ FS_User::is_valid_id( $install->user_id ) &&
12122
+ ( $install->user_id == $fs_user_id )
12123
+ ) {
12124
+ $module_ids_map[ $install->plugin_id ] = true;
12125
+ }
12126
+ }
12127
+
12128
+ return $module_ids_map;
12129
+ }
12130
+
12131
+ /**
12132
+ * @author Leo Fajardo (@leorw)
12133
+ *
12134
+ * @return null|array {
12135
+ * 'install' => FS_Site Module's install,
12136
+ * 'blog_id' => string The associated blog ID.
12137
+ * }
12138
+ */
12139
+ private function find_first_install() {
12140
+ $sites = self::get_sites();
12141
+
12142
+ foreach ( $sites as $site ) {
12143
+ $blog_id = self::get_site_blog_id( $site );
12144
+ $install = $this->get_install_by_blog_id( $blog_id );
12145
+
12146
+ if ( is_object( $install ) ) {
12147
+ return array(
12148
+ 'install' => $install,
12149
+ 'blog_id' => $blog_id
12150
+ );
12151
+ }
12152
+ }
12153
+
12154
+ return null;
12155
+ }
12156
+
12157
+ /**
12158
+ * Switches the Freemius site level context to a specified blog.
12159
+ *
12160
+ * @author Vova Feldman (@svovaf)
12161
+ * @since 2.0.0
12162
+ *
12163
+ * @param int $blog_id
12164
+ * @param FS_Site $install
12165
+ */
12166
+ function switch_to_blog( $blog_id, FS_Site $install = null ) {
12167
+ if ( $blog_id == $this->_context_is_network_or_blog_id ) {
12168
+ return;
12169
+ }
12170
+
12171
+ switch_to_blog( $blog_id );
12172
+ $this->_context_is_network_or_blog_id = $blog_id;
12173
+
12174
+ self::$_accounts->set_site_blog_context( $blog_id );
12175
+ $this->_storage->set_site_blog_context( $blog_id );
12176
+ $this->_storage->set_network_active( true, $this->is_delegated_connection( $blog_id ) );
12177
+
12178
+ $this->_site = is_object( $install ) ?
12179
+ $install :
12180
+ $this->get_install_by_blog_id( $blog_id );
12181
+
12182
+ $this->_user = false;
12183
+ $this->_licenses = false;
12184
+ $this->_license = null;
12185
+
12186
+ if ( is_object( $this->_site ) ) {
12187
+ // Try to fetch user from install.
12188
+ $this->_user = self::_get_user_by_id( $this->_site->user_id );
12189
+
12190
+ if ( ! is_object( $this->_user ) &&
12191
+ FS_User::is_valid_id( $this->_storage->prev_user_id )
12192
+ ) {
12193
+ // Try to fetch previously saved user.
12194
+ $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );
12195
+
12196
+ if ( ! is_object( $this->_user ) ) {
12197
+ // Fallback to network's user.
12198
+ $this->_user = $this->get_network_user();
12199
+ }
12200
+ }
12201
+
12202
+ $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
12203
+
12204
+ if ( ! empty( $all_plugin_licenses ) ) {
12205
+ if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
12206
+ $this->_license = null;
12207
+ } else {
12208
+ $license_found = false;
12209
+ foreach ( $all_plugin_licenses as $license ) {
12210
+ if ( $license->id == $this->_site->license_id ) {
12211
+ // License found.
12212
+ $this->_license = $license;
12213
+ $license_found = true;
12214
+ break;
12215
+ }
12216
+ }
12217
+
12218
+ if ( $license_found ) {
12219
+ $this->link_license_2_user( $this->_license->id, $this->_user->id );
12220
+ }
12221
+ }
12222
+
12223
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
12224
+ }
12225
+ }
12226
+
12227
+ unset( $this->_site_api );
12228
+ unset( $this->_user_api );
12229
+ }
12230
+
12231
+ /**
12232
+ * Restore the blog context to the blog that originally loaded the module.
12233
+ *
12234
+ * @author Vova Feldman (@svovaf)
12235
+ * @since 2.0.0
12236
+ */
12237
+ function restore_current_blog() {
12238
+ $this->switch_to_blog( $this->_blog_id );
12239
+ }
12240
+
12241
+ /**
12242
+ * @author Vova Feldman (@svovaf)
12243
+ * @since 2.0.0
12244
+ *
12245
+ * @param array|WP_Site $site
12246
+ *
12247
+ * @return int
12248
+ */
12249
+ static function get_site_blog_id( &$site ) {
12250
+ return ( $site instanceof WP_Site ) ?
12251
+ $site->blog_id :
12252
+ ( is_object( $site ) && isset( $site->userblog_id ) ?
12253
+ $site->userblog_id :
12254
+ $site['blog_id'] );
12255
+ }
12256
+
12257
+ /**
12258
+ * @author Leo Fajardo (@leorw)
12259
+ * @since 2.0.0
12260
+ *
12261
+ * @param array|WP_Site|null $site
12262
+ *
12263
+ * @return array
12264
+ */
12265
+ function get_site_info( $site = null ) {
12266
+ $this->_logger->entrance();
12267
+
12268
+ $switched = false;
12269
+
12270
+ if ( is_null( $site ) ) {
12271
+ $url = get_site_url();
12272
+ $name = get_bloginfo( 'name' );
12273
+ $blog_id = null;
12274
+ } else {
12275
+ $blog_id = self::get_site_blog_id( $site );
12276
+
12277
+ if ( get_current_blog_id() != $blog_id ) {
12278
+ switch_to_blog( $blog_id );
12279
+ $switched = true;
12280
+ }
12281
+
12282
+ if ( $site instanceof WP_Site ) {
12283
+ $url = $site->siteurl;
12284
+ $name = $site->blogname;
12285
+ } else {
12286
+ $url = get_site_url( $blog_id );
12287
+ $name = get_bloginfo( 'name' );
12288
+ }
12289
+ }
12290
+
12291
+ $info = array(
12292
+ 'uid' => $this->get_anonymous_id( $blog_id ),
12293
+ 'url' => $url,
12294
+ 'title' => $name,
12295
+ 'language' => get_bloginfo( 'language' ),
12296
+ 'charset' => get_bloginfo( 'charset' ),
12297
+ );
12298
+
12299
+ if ( is_numeric( $blog_id ) ) {
12300
+ $info['blog_id'] = $blog_id;
12301
+ }
12302
+
12303
+ if ( $switched ) {
12304
+ restore_current_blog();
12305
+ }
12306
+
12307
+ return $info;
12308
+ }
12309
+
12310
+ /**
12311
+ * Load the module's install based on the blog ID.
12312
+ *
12313
+ * @author Vova Feldman (@svovaf)
12314
+ * @since 2.0.0
12315
+ *
12316
+ * @param int|null $blog_id
12317
+ *
12318
+ * @return FS_Site
12319
+ */
12320
+ function get_install_by_blog_id( $blog_id = null ) {
12321
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
12322
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
12323
+
12324
+ if ( is_object( $install ) &&
12325
+ is_numeric( $install->id ) &&
12326
+ is_numeric( $install->user_id ) &&
12327
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
12328
+ ) {
12329
+ // Load site.
12330
+ $install = clone $install;
12331
+ }
12332
+
12333
+ return $install;
12334
+ }
12335
+
12336
+ /**
12337
+ * Check if module is installed on a specified site.
12338
+ *
12339
+ * @author Vova Feldman (@svovaf)
12340
+ * @since 2.0.0
12341
+ *
12342
+ * @param int|null $blog_id
12343
+ *
12344
+ * @return bool
12345
+ */
12346
+ function is_installed_on_site( $blog_id = null ) {
12347
+ $installs = self::get_all_sites( $this->_module_type, $blog_id );
12348
+ $install = isset( $installs[ $this->_slug ] ) ? $installs[ $this->_slug ] : null;
12349
+
12350
+ return (
12351
+ is_object( $install ) &&
12352
+ is_numeric( $install->id ) &&
12353
+ is_numeric( $install->user_id ) &&
12354
+ FS_Plugin_Plan::is_valid_id( $install->plan_id )
12355
+ );
12356
+ }
12357
+
12358
+ /**
12359
+ * Check if super-admin connected at least one site via the network opt-in.
12360
+ *
12361
+ * @author Vova Feldman (@svovaf)
12362
+ * @since 2.0.0
12363
+ *
12364
+ * @return bool
12365
+ */
12366
+ function is_network_registered() {
12367
+ if ( ! $this->_is_network_active ) {
12368
+ return false;
12369
+ }
12370
+
12371
+ return FS_User::is_valid_id( $this->_storage->network_user_id );
12372
+ }
12373
+
12374
+ /**
12375
+ * Returns the main user associated with the network.
12376
+ *
12377
+ * @author Vova Feldman (@svovaf)
12378
+ * @since 2.0.0
12379
+ *
12380
+ * @return FS_User
12381
+ */
12382
+ function get_network_user() {
12383
+ if ( ! $this->_is_network_active ) {
12384
+ return null;
12385
+ }
12386
+
12387
+ return FS_User::is_valid_id( $this->_storage->network_user_id ) ?
12388
+ self::_get_user_by_id( $this->_storage->network_user_id ) :
12389
+ null;
12390
+ }
12391
+
12392
+ /**
12393
+ * Returns the current context user or the network's main user.
12394
+ *
12395
+ * @author Vova Feldman (@svovaf)
12396
+ * @since 2.0.0
12397
+ *
12398
+ * @return FS_User
12399
+ */
12400
+ function get_current_or_network_user() {
12401
+ return ( $this->_user instanceof FS_User ) ?
12402
+ $this->_user :
12403
+ $this->get_network_user();
12404
+ }
12405
+
12406
+ /**
12407
+ * Returns the main install associated with the network.
12408
+ *
12409
+ * @author Vova Feldman (@svovaf)
12410
+ * @since 2.0.0
12411
+ *
12412
+ * @return FS_Site
12413
+ */
12414
+ function get_network_install() {
12415
+ if ( ! $this->_is_network_active ) {
12416
+ return null;
12417
+ }
12418
+
12419
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
12420
+ $this->get_install_by_blog_id( $this->_storage->network_install_blog_id ) :
12421
+ null;
12422
+ }
12423
+
12424
+ /**
12425
+ * Returns the blog ID that is associated with the main install.
12426
+ *
12427
+ * @author Leo Fajardo (@leorw)
12428
+ * @since 2.0.0
12429
+ *
12430
+ * @return int|null
12431
+ */
12432
+ function get_network_install_blog_id() {
12433
+ if ( ! $this->_is_network_active ) {
12434
+ return null;
12435
+ }
12436
+
12437
+ return FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ?
12438
+ $this->_storage->network_install_blog_id :
12439
+ null;
12440
+ }
12441
+
12442
+ /**
12443
+ * Returns the current context install or the network's main install.
12444
+ *
12445
+ * @author Vova Feldman (@svovaf)
12446
+ * @since 2.0.0
12447
+ *
12448
+ * @return FS_Site
12449
+ */
12450
+ function get_current_or_network_install() {
12451
+ return ( $this->_site instanceof FS_Site ) ?
12452
+ $this->_site :
12453
+ $this->get_network_install();
12454
+ }
12455
+
12456
+ /**
12457
+ * Check if executing a site level action from the network level admin.
12458
+ *
12459
+ * @author Vova Feldman (@svovaf)
12460
+ * @since 2.0.0
12461
+ *
12462
+ * @return false|int If yes, return the requested blog ID.
12463
+ */
12464
+ private function is_network_level_site_specific_action() {
12465
+ if ( ! $this->_is_network_active ) {
12466
+ return false;
12467
+ }
12468
+
12469
+ if ( ! fs_is_network_admin() ) {
12470
+ return false;
12471
+ }
12472
+
12473
+ $blog_id = fs_request_get( 'blog_id', '' );
12474
+
12475
+ return is_numeric( $blog_id ) ? $blog_id : false;
12476
+ }
12477
+
12478
+ /**
12479
+ * Check if executing an action from the network level admin.
12480
+ *
12481
+ * @author Vova Feldman (@svovaf)
12482
+ * @since 2.0.0
12483
+ *
12484
+ * @return bool
12485
+ */
12486
+ private function is_network_level_action() {
12487
+ return ( $this->_is_network_active && fs_is_network_admin() );
12488
+ }
12489
+
12490
+ /**
12491
+ * Needs to be executed after site deactivation, archive, deletion, or flag as spam.
12492
+ * The logic updates the network level user and blog, and reschedule the crons if the cron executing site matching the site that is no longer publicly active.
12493
+ *
12494
+ * @author Vova Feldman (@svovaf)
12495
+ * @since 2.0.0
12496
+ *
12497
+ * @param int $context_blog_id
12498
+ */
12499
+ private function update_multisite_data_after_site_deactivation( $context_blog_id = 0 ) {
12500
+ $this->_logger->entrance();
12501
+
12502
+ if ( $this->_is_network_active ) {
12503
+ if ( $context_blog_id == $this->_storage->network_install_blog_id ) {
12504
+ $installs_map = $this->get_blog_install_map();
12505
+
12506
+ foreach ( $installs_map as $blog_id => $install ) {
12507
+ /**
12508
+ * @var FS_Site $install
12509
+ */
12510
+ if ( $context_blog_id == $blog_id ) {
12511
+ continue;
12512
+ }
12513
+
12514
+ if ( $install->user_id != $this->_storage->network_user_id ) {
12515
+ continue;
12516
+ }
12517
+
12518
+ // Switch reference to a blog that is opted-in and belong to the same super-admin.
12519
+ $this->_storage->network_install_blog_id = $blog_id;
12520
+ break;
12521
+ }
12522
+ }
12523
+ }
12524
+
12525
+ if ( $this->is_sync_cron_scheduled() &&
12526
+ $context_blog_id == $this->get_sync_cron_blog_id()
12527
+ ) {
12528
+ $this->schedule_sync_cron( WP_FS__SCRIPT_START_TIME, true, $context_blog_id );
12529
+ }
12530
+
12531
+ if ( $this->is_install_sync_scheduled() &&
12532
+ $context_blog_id == $this->get_install_sync_cron_blog_id()
12533
+ ) {
12534
+ $this->schedule_install_sync( $context_blog_id );
12535
+ }
12536
+ }
12537
+
12538
+ /**
12539
+ * Executed after site deactivation, archive, or flag as spam.
12540
+ *
12541
+ * @author Vova Feldman (@svovaf)
12542
+ * @since 2.0.0
12543
+ *
12544
+ * @param int $context_blog_id
12545
+ */
12546
+ public function _after_site_deactivated_callback( $context_blog_id = 0 ) {
12547
+ $this->_logger->entrance();
12548
+
12549
+ $install = $this->get_install_by_blog_id( $context_blog_id );
12550
+
12551
+ if ( ! is_object( $install ) ) {
12552
+ // Site not connected.
12553
+ return;
12554
+ }
12555
+
12556
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
12557
+
12558
+ $current_blog_id = get_current_blog_id();
12559
+
12560
+ $this->switch_to_blog( $context_blog_id );
12561
+
12562
+ // Send deactivation event.
12563
+ $this->sync_install( array(
12564
+ 'is_active' => false,
12565
+ ) );
12566
+
12567
+ $this->switch_to_blog( $current_blog_id );
12568
+ }
12569
+
12570
+ /**
12571
+ * Executed after site deletion.
12572
+ *
12573
+ * @author Vova Feldman (@svovaf)
12574
+ * @since 2.0.0
12575
+ *
12576
+ * @param int $context_blog_id
12577
+ * @param bool $drop True if site's database tables should be dropped. Default is false.
12578
+ */
12579
+ public function _after_site_deleted_callback( $context_blog_id = 0, $drop = false ) {
12580
+ $this->_logger->entrance();
12581
+
12582
+ $install = $this->get_install_by_blog_id( $context_blog_id );
12583
+
12584
+ if ( ! is_object( $install ) ) {
12585
+ // Site not connected.
12586
+ return;
12587
+ }
12588
+
12589
+ $this->update_multisite_data_after_site_deactivation( $context_blog_id );
12590
+
12591
+ $current_blog_id = get_current_blog_id();
12592
+
12593
+ $this->switch_to_blog( $context_blog_id );
12594
+
12595
+ if ( $drop ) {
12596
+ // Delete install if dropping site DB.
12597
+ $this->delete_account_event();
12598
+ } else {
12599
+ // Send deactivation event.
12600
+ $this->sync_install( array(
12601
+ 'is_active' => false,
12602
+ ) );
12603
+ }
12604
+
12605
+ $this->switch_to_blog( $current_blog_id );
12606
+ }
12607
+
12608
+ /**
12609
+ * Executed after site re-activation.
12610
+ *
12611
+ * @author Vova Feldman (@svovaf)
12612
+ * @since 2.0.0
12613
+ *
12614
+ * @param int $context_blog_id
12615
+ */
12616
+ public function _after_site_reactivated_callback( $context_blog_id = 0 ) {
12617
+ $this->_logger->entrance();
12618
+
12619
+ $install = $this->get_install_by_blog_id( $context_blog_id );
12620
+
12621
+ if ( ! is_object( $install ) ) {
12622
+ // Site not connected.
12623
+ return;
12624
+ }
12625
+
12626
+ if ( ! self::is_site_active( $context_blog_id ) ) {
12627
+ // Site not yet active (can be in spam mode, archived, deleted...).
12628
+ return;
12629
+ }
12630
+
12631
+ $current_blog_id = get_current_blog_id();
12632
+
12633
+ $this->switch_to_blog( $context_blog_id );
12634
+
12635
+ // Send re-activation event.
12636
+ $this->sync_install( array(
12637
+ 'is_active' => true,
12638
+ ) );
12639
+
12640
+ $this->switch_to_blog( $current_blog_id );
12641
+ }
12642
+
12643
+ #endregion Multisite
12644
+
12645
+ /**
12646
+ * @author Leo Fajardo (@leorw)
12647
+ *
12648
+ * @param string $path
12649
+ * @param string $scheme
12650
+ * @param bool $network
12651
+ *
12652
+ * @return string
12653
+ */
12654
+ private function admin_url( $path = '', $scheme = 'admin', $network = true ) {
12655
+ return ( $this->_is_network_active && $network ) ?
12656
+ network_admin_url( $path, $scheme ) :
12657
+ admin_url( $path, $scheme );
12658
+ }
12659
+
12660
+ /**
12661
+ * Check if currently in a specified admin page.
12662
+ *
12663
+ * @author Vova Feldman (@svovaf)
12664
+ * @since 1.2.2.7
12665
+ *
12666
+ * @param string $page
12667
+ *
12668
+ * @return bool
12669
+ */
12670
+ function is_admin_page( $page ) {
12671
+ return ( $this->_menu->get_slug( $page ) === fs_request_get( 'page', '', 'get' ) );
12672
+ }
12673
+
12674
+ /**
12675
+ * Get module's main admin setting page URL.
12676
+ *
12677
+ * @author Vova Feldman (@svovaf)
12678
+ * @since 1.2.2.7
12679
+ *
12680
+ * @return string
12681
+ */
12682
+ function main_menu_url() {
12683
+ return $this->_menu->main_menu_url();
12684
+ }
12685
+
12686
+ /**
12687
+ * Check if currently on the theme's setting page or
12688
+ * on any of the Freemius added pages (via tabs).
12689
+ *
12690
+ * @author Vova Feldman (@svovaf)
12691
+ * @since 1.2.2.7
12692
+ *
12693
+ * @return bool
12694
+ */
12695
+ function is_theme_settings_page() {
12696
+ return fs_starts_with(
12697
+ fs_request_get( 'page', '', 'get' ),
12698
+ $this->_menu->get_slug()
12699
+ );
12700
+ }
12701
+
12702
+ /**
12703
+ * Plugin's account page + sync license URL.
12704
+ *
12705
+ * @author Vova Feldman (@svovaf)
12706
+ * @since 1.1.9.1
12707
+ *
12708
+ * @param bool|number $plugin_id
12709
+ * @param bool $add_action_nonce
12710
+ * @param array $params
12711
+ *
12712
+ * @return string
12713
+ */
12714
+ function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true, $params = array() ) {
12715
+ if ( is_numeric( $plugin_id ) ) {
12716
+ $params['plugin_id'] = $plugin_id;
12717
+ }
12718
+
12719
+ return $this->get_account_url(
12720
+ $this->get_unique_affix() . '_sync_license',
12721
+ $params,
12722
+ $add_action_nonce
12723
+ );
12724
+ }
12725
+
12726
+ /**
12727
+ * Plugin's account URL.
12728
+ *
12729
+ * @author Vova Feldman (@svovaf)
12730
+ * @since 1.0.4
12731
+ *
12732
+ * @param bool|string $action
12733
+ * @param array $params
12734
+ *
12735
+ * @param bool $add_action_nonce
12736
+ *
12737
+ * @return string
12738
+ */
12739
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
12740
+ if ( is_string( $action ) ) {
12741
+ $params['fs_action'] = $action;
12742
+ }
12743
+
12744
+ self::require_pluggable_essentials();
12745
+
12746
+ return ( $add_action_nonce && is_string( $action ) ) ?
12747
+ fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
12748
+ $this->_get_admin_page_url( 'account', $params );
12749
+ }
12750
+
12751
+ /**
12752
+ * @author Vova Feldman (@svovaf)
12753
+ * @since 1.2.0
12754
+ *
12755
+ * @param string $tab
12756
+ * @param bool $action
12757
+ * @param array $params
12758
+ * @param bool $add_action_nonce
12759
+ *
12760
+ * @return string
12761
+ *
12762
+ * @uses get_account_url()
12763
+ */
12764
+ function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
12765
+ $params['tab'] = $tab;
12766
+
12767
+ return $this->get_account_url( $action, $params, $add_action_nonce );
12768
+ }
12769
+
12770
+ /**
12771
+ * Plugin's account URL.
12772
+ *
12773
+ * @author Vova Feldman (@svovaf)
12774
+ * @since 1.0.4
12775
+ *
12776
+ * @param bool|string $topic
12777
+ * @param bool|string $message
12778
+ *
12779
+ * @return string
12780
+ */
12781
+ function contact_url( $topic = false, $message = false ) {
12782
+ $params = array();
12783
+ if ( is_string( $topic ) ) {
12784
+ $params['topic'] = $topic;
12785
+ }
12786
+ if ( is_string( $message ) ) {
12787
+ $params['message'] = $message;
12788
+ }
12789
+
12790
+ if ( $this->is_addon() ) {
12791
+ $params['addon_id'] = $this->get_id();
12792
+
12793
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
12794
+ } else {
12795
+ return $this->_get_admin_page_url( 'contact', $params );
12796
+ }
12797
+ }
12798
+
12799
+ /**
12800
+ * Add-on direct info URL.
12801
+ *
12802
+ * @author Vova Feldman (@svovaf)
12803
+ * @since 1.1.0
12804
+ *
12805
+ * @param string $slug
12806
+ *
12807
+ * @return string
12808
+ */
12809
+ function addon_url( $slug ) {
12810
+ return $this->_get_admin_page_url( 'addons', array(
12811
+ 'slug' => $slug
12812
+ ) );
12813
+ }
12814
+
12815
+ /* Logger
12816
+ ------------------------------------------------------------------------------------------------------------------*/
12817
+ /**
12818
+ * @param string $id
12819
+ * @param bool $prefix_slug
12820
+ *
12821
+ * @return FS_Logger
12822
+ */
12823
+ function get_logger( $id = '', $prefix_slug = true ) {
12824
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
12825
+ }
12826
+
12827
+ /**
12828
+ * Note: This method is used externally so don't delete it.
12829
+ *
12830
+ * @param $id
12831
+ * @param bool $load_options
12832
+ * @param bool $prefix_slug
12833
+ *
12834
+ * @return FS_Option_Manager
12835
+ */
12836
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
12837
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
12838
+ }
12839
+
12840
+ /* Security
12841
+ ------------------------------------------------------------------------------------------------------------------*/
12842
+ private static function _encrypt( $str ) {
12843
+ if ( is_null( $str ) ) {
12844
+ return null;
12845
+ }
12846
+
12847
+ /**
12848
+ * The encrypt/decrypt functions are used to protect
12849
+ * the user from messing up with some of the sensitive
12850
+ * data stored for the module as a JSON in the database.
12851
+ *
12852
+ * I used the same suggested hack by the theme review team.
12853
+ * For more details, look at the function `Base64UrlDecode()`
12854
+ * in `./sdk/FreemiusBase.php`.
12855
+ *
12856
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
12857
+ *
12858
+ * @author Vova Feldman (@svovaf)
12859
+ * @since 1.2.2
12860
+ */
12861
+ $fn = 'base64' . '_encode';
12862
+
12863
+ return $fn( $str );
12864
+ }
12865
+
12866
+ static function _decrypt( $str ) {
12867
+ if ( is_null( $str ) ) {
12868
+ return null;
12869
+ }
12870
+
12871
+ /**
12872
+ * The encrypt/decrypt functions are used to protect
12873
+ * the user from messing up with some of the sensitive
12874
+ * data stored for the module as a JSON in the database.
12875
+ *
12876
+ * I used the same suggested hack by the theme review team.
12877
+ * For more details, look at the function `Base64UrlDecode()`
12878
+ * in `./sdk/FreemiusBase.php`.
12879
+ *
12880
+ * @todo Remove this hack once the base64 error is removed from the Theme Check.
12881
+ *
12882
+ * @author Vova Feldman (@svovaf)
12883
+ * @since 1.2.2
12884
+ */
12885
+ $fn = 'base64' . '_decode';
12886
+
12887
+ return $fn( $str );
12888
+ }
12889
+
12890
+ /**
12891
+ * @author Vova Feldman (@svovaf)
12892
+ * @since 1.0.5
12893
+ *
12894
+ * @param FS_Entity $entity
12895
+ *
12896
+ * @return FS_Entity Return an encrypted clone entity.
12897
+ */
12898
+ private static function _encrypt_entity( FS_Entity $entity ) {
12899
+ $clone = clone $entity;
12900
+ $props = get_object_vars( $entity );
12901
+
12902
+ foreach ( $props as $key => $val ) {
12903
+ $clone->{$key} = self::_encrypt( $val );
12904
+ }
12905
+
12906
+ return $clone;
12907
+ }
12908
+
12909
+ /**
12910
+ * @author Vova Feldman (@svovaf)
12911
+ * @since 1.0.5
12912
+ *
12913
+ * @param FS_Entity $entity
12914
+ *
12915
+ * @return FS_Entity Return an decrypted clone entity.
12916
+ */
12917
+ private static function decrypt_entity( FS_Entity $entity ) {
12918
+ $clone = clone $entity;
12919
+ $props = get_object_vars( $entity );
12920
+
12921
+ foreach ( $props as $key => $val ) {
12922
+ $clone->{$key} = self::_decrypt( $val );
12923
+ }
12924
+
12925
+ return $clone;
12926
+ }
12927
+
12928
+ /**
12929
+ * Tries to activate account based on POST params.
12930
+ *
12931
+ * @author Vova Feldman (@svovaf)
12932
+ * @since 1.0.2
12933
+ *
12934
+ * @deprecated Not in use, outdated.
12935
+ */
12936
+ function _activate_account() {
12937
+ if ( $this->is_registered() ) {
12938
+ // Already activated.
12939
+ return;
12940
+ }
12941
+
12942
+ self::_clean_admin_content_section();
12943
+
12944
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
12945
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
12946
+
12947
+ // Verify matching plugin details.
12948
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
12949
+ return;
12950
+ }
12951
+
12952
+ $user = new FS_User();
12953
+ $user->id = fs_request_get( 'user_id' );
12954
+ $user->public_key = fs_request_get( 'user_public_key' );
12955
+ $user->secret_key = fs_request_get( 'user_secret_key' );
12956
+ $user->email = fs_request_get( 'user_email' );
12957
+ $user->first = fs_request_get( 'user_first' );
12958
+ $user->last = fs_request_get( 'user_last' );
12959
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
12960
+
12961
+ $site = new FS_Site();
12962
+ $site->id = fs_request_get( 'install_id' );
12963
+ $site->public_key = fs_request_get( 'install_public_key' );
12964
+ $site->secret_key = fs_request_get( 'install_secret_key' );
12965
+ $site->plan_id = fs_request_get( 'plan_id' );
12966
+
12967
+ $plans = array();
12968
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
12969
+ foreach ( $plans_data as $p ) {
12970
+ $plan = new FS_Plugin_Plan( $p );
12971
+ if ( $site->plan_id == $plan->id ) {
12972
+ $plan->title = fs_request_get( 'plan_title' );
12973
+ $plan->name = fs_request_get( 'plan_name' );
12974
+ }
12975
+
12976
+ $plans[] = $plan;
12977
+ }
12978
+
12979
+ $this->_set_account( $user, $site, $plans );
12980
+
12981
+ // Reload the page with the keys.
12982
+ fs_redirect( $this->_get_admin_page_url() );
12983
+ }
12984
+ }
12985
+
12986
+ /**
12987
+ * @author Vova Feldman (@svovaf)
12988
+ * @since 1.0.7
12989
+ *
12990
+ * @param string $email
12991
+ *
12992
+ * @return FS_User|false
12993
+ */
12994
+ static function _get_user_by_email( $email ) {
12995
+ self::$_static_logger->entrance();
12996
+
12997
+ $email = trim( strtolower( $email ) );
12998
+
12999
+ $users = self::get_all_users();
13000
+
13001
+ if ( is_array( $users ) ) {
13002
+ foreach ( $users as $user ) {
13003
+ if ( $email === trim( strtolower( $user->email ) ) ) {
13004
+ return $user;
13005
+ }
13006
+ }
13007
+ }
13008
+
13009
+ return false;
13010
+ }
13011
+
13012
+ #----------------------------------------------------------------------------------
13013
+ #region Account (Loading, Updates & Activation)
13014
+ #----------------------------------------------------------------------------------
13015
+
13016
+ /***
13017
+ * Load account information (user + site).
13018
+ *
13019
+ * @author Vova Feldman (@svovaf)
13020
+ * @since 1.0.1
13021
+ */
13022
+ private function _load_account() {
13023
+ $this->_logger->entrance();
13024
+
13025
+ $this->do_action( 'before_account_load' );
13026
+
13027
+ $users = self::get_all_users();
13028
+ $plans = self::get_all_plans( $this->_module_type );
13029
+
13030
+ if ( $this->_logger->is_on() && is_admin() ) {
13031
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
13032
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
13033
+ }
13034
+
13035
+ $site = fs_is_network_admin() ?
13036
+ $this->get_network_install() :
13037
+ $this->get_install_by_blog_id();
13038
+
13039
+ if ( fs_is_network_admin() &&
13040
+ ! is_object( $site ) &&
13041
+ FS_Site::is_valid_id( $this->_storage->network_install_blog_id )
13042
+ ) {
13043
+ $first_install = $this->find_first_install();
13044
+
13045
+ if ( is_null( $first_install ) ) {
13046
+ unset( $this->_storage->network_install_blog_id );
13047
+ } else {
13048
+ $site = $first_install['install'];
13049
+ $this->_storage->network_install_blog_id = $first_install['blog_id'];
13050
+ }
13051
+ }
13052
+
13053
+ if ( is_object( $site ) &&
13054
+ is_numeric( $site->id ) &&
13055
+ is_numeric( $site->user_id ) &&
13056
+ FS_Plugin_Plan::is_valid_id( $site->plan_id )
13057
+ ) {
13058
+ // Load site.
13059
+ $this->_site = $site;
13060
+
13061
+ // Load plans.
13062
+ $this->_plans = $plans[ $this->_slug ];
13063
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
13064
+ $this->_sync_plans();
13065
+ } else {
13066
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
13067
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
13068
+ $this->_plans[ $i ] = self::decrypt_entity( $this->_plans[ $i ] );
13069
+ } else {
13070
+ unset( $this->_plans[ $i ] );
13071
+ }
13072
+ }
13073
+ }
13074
+ }
13075
+
13076
+ $user = null;
13077
+ if ( fs_is_network_admin() && $this->_is_network_active ) {
13078
+ $user = $this->get_network_user();
13079
+ }
13080
+
13081
+ if ( is_object( $user ) ) {
13082
+ $this->_user = clone $user;
13083
+ } else if ( $this->_site ) {
13084
+ $user = self::_get_user_by_id( $this->_site->user_id );
13085
+
13086
+ if ( ! is_object( $user ) && FS_User::is_valid_id( $this->_storage->prev_user_id ) ) {
13087
+ /**
13088
+ * Try to load the previous owner. This recovery is used for the following use-case:
13089
+ * 1. Opt-in
13090
+ * 2. Cloning site1 to site2
13091
+ * 3. Ownership switch in site1 (same applies for site2)
13092
+ * 4. Install data sync on site2
13093
+ * 5. Now site2's install is associated with the new owner which does not exists locally.
13094
+ */
13095
+ $user = self::_get_user_by_id( $this->_storage->prev_user_id );
13096
+ }
13097
+
13098
+ if ( ! is_object( $user ) ) {
13099
+ /**
13100
+ * This is a special fault tolerance mechanism to handle a scenario that the user data is missing.
13101
+ */
13102
+ $user = $this->fetch_user_by_install();
13103
+ }
13104
+
13105
+ $this->_user = ( $user instanceof FS_User ) ?
13106
+ clone $user :
13107
+ null;
13108
+ }
13109
+
13110
+ if ( is_object( $this->_user ) ) {
13111
+ // Load licenses.
13112
+ $this->_licenses = $this->get_user_licenses( $this->_user->id );
13113
+ }
13114
+
13115
+ if ( is_object( $this->_site ) ) {
13116
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
13117
+
13118
+ if ( $this->_site->version != $this->get_plugin_version() ) {
13119
+ // If stored install version is different than current installed plugin version,
13120
+ // then update plugin version event.
13121
+ $this->update_plugin_version_event();
13122
+ }
13123
+ }
13124
+
13125
+ if ( $this->is_theme() ) {
13126
+ $this->_register_account_hooks();
13127
+ }
13128
+ }
13129
+
13130
+ /**
13131
+ * Special user recovery mechanism.
13132
+ *
13133
+ * @author Vova Feldman (@svovaf)
13134
+ * @since 2.0.0
13135
+ *
13136
+ * @return \FS_User|mixed
13137
+ */
13138
+ private function fetch_user_by_install() {
13139
+ $api = $this->get_api_site_scope();
13140
+
13141
+ $uid = $this->get_anonymous_id();
13142
+ $request_path = "/users/{$this->_site->user_id}.json?uid={$uid}";
13143
+
13144
+ $result = $api->get( $request_path, false, WP_FS__TIME_10_MIN_IN_SEC );
13145
+
13146
+ if ( $this->is_api_result_entity( $result ) ) {
13147
+ $user = new FS_User( $result );
13148
+ $this->_user = $user;
13149
+ $this->_store_user();
13150
+
13151
+ return $user;
13152
+ }
13153
+
13154
+ $error_code = FS_Api::get_error_code( $result );
13155
+
13156
+ if ( in_array( $error_code, array( 'invalid_unique_id', 'user_cannot_be_recovered' ) ) ) {
13157
+ /**
13158
+ * Those API errors will continue coming and are not recoverable with the
13159
+ * current site's data. Therefore, extend the API call's cached result to 7 days.
13160
+ */
13161
+ $api->update_cache_expiration( $request_path, WP_FS__TIME_WEEK_IN_SEC );
13162
+ }
13163
+
13164
+ return $result;
13165
+ }
13166
+
13167
+ /**
13168
+ * @author Vova Feldman (@svovaf)
13169
+ * @since 1.0.1
13170
+ *
13171
+ * @param FS_User $user
13172
+ * @param FS_Site $site
13173
+ * @param bool|array $plans
13174
+ */
13175
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
13176
+ $site->user_id = $user->id;
13177
+
13178
+ $this->_site = $site;
13179
+ $this->_user = $user;
13180
+ if ( false !== $plans ) {
13181
+ $this->_plans = $plans;
13182
+ }
13183
+
13184
+ $this->send_install_update();
13185
+
13186
+ $this->_store_account();
13187
+
13188
+ }
13189
+
13190
+ /**
13191
+ * @author Vova Feldman (@svovaf)
13192
+ * @since 1.1.7.4
13193
+ *
13194
+ * @param array $override_with
13195
+ * @param bool|int|null $network_level_or_blog_id If true, return params for network level opt-in. If integer, get params for specified blog in the network.
13196
+ *
13197
+ * @return array
13198
+ */
13199
+ function get_opt_in_params( $override_with = array(), $network_level_or_blog_id = null ) {
13200
+ $this->_logger->entrance();
13201
+
13202
+ $current_user = self::_get_current_wp_user();
13203
+
13204
+ $activation_action = $this->get_unique_affix() . '_activate_new';
13205
+ $return_url = $this->is_anonymous() ?
13206
+ // If skipped already, then return to the account page.
13207
+ $this->get_account_url( $activation_action, array(), false ) :
13208
+ // Return to the module's main page.
13209
+ $this->get_after_activation_url( 'after_connect_url', array( 'fs_action' => $activation_action ) );
13210
+
13211
+ $params = array(
13212
+ 'user_firstname' => $current_user->user_firstname,
13213
+ 'user_lastname' => $current_user->user_lastname,
13214
+ 'user_nickname' => $current_user->user_nicename,
13215
+ 'user_email' => $current_user->user_email,
13216
+ 'user_ip' => WP_FS__REMOTE_ADDR,
13217
+ 'plugin_slug' => $this->_slug,
13218
+ 'plugin_id' => $this->get_id(),
13219
+ 'plugin_public_key' => $this->get_public_key(),
13220
+ 'plugin_version' => $this->get_plugin_version(),
13221
+ 'return_url' => fs_nonce_url( $return_url, $activation_action ),
13222
+ 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
13223
+ 'account',
13224
+ array( 'fs_action' => 'sync_user' )
13225
+ ), 'sync_user' ),
13226
+ 'platform_version' => get_bloginfo( 'version' ),
13227
+ 'sdk_version' => $this->version,
13228
+ 'programming_language_version' => phpversion(),
13229
+ 'is_premium' => $this->is_premium(),
13230
+ 'is_active' => true,
13231
+ 'is_uninstalled' => false,
13232
+ );
13233
+
13234
+ if ( true === $network_level_or_blog_id ) {
13235
+ if ( ! isset( $override_with['sites'] ) ) {
13236
+ $params['sites'] = array();
13237
+
13238
+ $sites = self::get_sites();
13239
+
13240
+ foreach ( $sites as $site ) {
13241
+ $blog_id = self::get_site_blog_id( $site );
13242
+ if ( ! $this->is_site_delegated_connection( $blog_id ) &&
13243
+ ! $this->is_installed_on_site( $blog_id )
13244
+ ) {
13245
+ $params['sites'][] = $this->get_site_info( $site );
13246
+ }
13247
+ }
13248
+ }
13249
+ } else {
13250
+ $site = is_numeric( $network_level_or_blog_id ) ?
13251
+ array( 'blog_id' => $network_level_or_blog_id ) :
13252
+ null;
13253
+
13254
+ $site = $this->get_site_info( $site );
13255
+
13256
+ $params = array_merge( $params, array(
13257
+ 'site_uid' => $site['uid'],
13258
+ 'site_url' => $site['url'],
13259
+ 'site_name' => $site['title'],
13260
+ 'language' => $site['language'],
13261
+ 'charset' => $site['charset'],
13262
+ ) );
13263
+ }
13264
+
13265
+ if ( $this->is_pending_activation() &&
13266
+ ! empty( $this->_storage->pending_license_key )
13267
+ ) {
13268
+ $params['license_key'] = $this->_storage->pending_license_key;
13269
+ }
13270
+
13271
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
13272
+ // Even though rand() is known for its security issues,
13273
+ // the timestamp adds another layer of protection.
13274
+ // It would be very hard for an attacker to get the secret key form here.
13275
+ // Plus, this should never run in production since the secret should never
13276
+ // be included in the production version.
13277
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
13278
+ $params['salt'] = md5( uniqid( rand() ) );
13279
+ $params['secure'] = md5(
13280
+ $params['ts'] .
13281
+ $params['salt'] .
13282
+ $this->get_secret_key()
13283
+ );
13284
+ }
13285
+
13286
+ return array_merge( $params, $override_with );
13287
+ }
13288
+
13289
+ /**
13290
+ * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
13291
+ * 2. If there was an API error, return the API result.
13292
+ *
13293
+ * @author Vova Feldman (@svovaf)
13294
+ * @since 1.1.7.4
13295
+ *
13296
+ * @param string|bool $email
13297
+ * @param string|bool $first
13298
+ * @param string|bool $last
13299
+ * @param string|bool $license_key
13300
+ * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
13301
+ * In this case, the user and site info will be sent to the server but no
13302
+ * data will be saved to the WP installation's database.
13303
+ * @param number|bool $trial_plan_id
13304
+ * @param bool $is_disconnected Whether or not to opt in without tracking.
13305
+ * @param null|bool $is_marketing_allowed
13306
+ * @param array $sites If network-level opt-in, an array of containing details of sites.
13307
+ *
13308
+ * @return string|object
13309
+ * @use WP_Error
13310
+ */
13311
+ function opt_in(
13312
+ $email = false,
13313
+ $first = false,
13314
+ $last = false,
13315
+ $license_key = false,
13316
+ $is_uninstall = false,
13317
+ $trial_plan_id = false,
13318
+ $is_disconnected = false,
13319
+ $is_marketing_allowed = null,
13320
+ $sites = array()
13321
+ ) {
13322
+ $this->_logger->entrance();
13323
+
13324
+ if ( false === $email ) {
13325
+ $current_user = self::_get_current_wp_user();
13326
+ $email = $current_user->user_email;
13327
+ }
13328
+
13329
+ /**
13330
+ * @since 1.2.1 If activating with license key, ignore the context-user
13331
+ * since the user will be automatically loaded from the license.
13332
+ */
13333
+ if ( empty( $license_key ) ) {
13334
+ // Clean up pending license if opt-ing in again.
13335
+ $this->_storage->remove( 'pending_license_key' );
13336
+
13337
+ if ( ! $is_uninstall ) {
13338
+ $fs_user = Freemius::_get_user_by_email( $email );
13339
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
13340
+ return $this->install_with_current_user(
13341
+ false,
13342
+ $trial_plan_id,
13343
+ $sites
13344
+ );
13345
+ }
13346
+ }
13347
+ }
13348
+
13349
+ $user_info = array();
13350
+ if ( ! empty( $email ) ) {
13351
+ $user_info['user_email'] = $email;
13352
+ }
13353
+ if ( ! empty( $first ) ) {
13354
+ $user_info['user_firstname'] = $first;
13355
+ }
13356
+ if ( ! empty( $last ) ) {
13357
+ $user_info['user_lastname'] = $last;
13358
+ }
13359
+
13360
+ if ( ! empty( $sites ) ) {
13361
+ $is_network = true;
13362
+
13363
+ $user_info['sites'] = $sites;
13364
+ } else {
13365
+ $is_network = false;
13366
+ }
13367
+
13368
+ $params = $this->get_opt_in_params( $user_info, $is_network );
13369
+
13370
+ $filtered_license_key = false;
13371
+ if ( is_string( $license_key ) ) {
13372
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
13373
+ $params['license_key'] = $filtered_license_key;
13374
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
13375
+ $params['trial_plan_id'] = $trial_plan_id;
13376
+ }
13377
+
13378
+ if ( $is_uninstall ) {
13379
+ $params['uninstall_params'] = array(
13380
+ 'reason_id' => $this->_storage->uninstall_reason->id,
13381
+ 'reason_info' => $this->_storage->uninstall_reason->info
13382
+ );
13383
+ }
13384
+
13385
+ if ( isset( $params['license_key'] ) ) {
13386
+ $fs_user = Freemius::_get_user_by_email( $email );
13387
+
13388
+ if ( is_object( $fs_user ) ) {
13389
+ /**
13390
+ * If opting in with a context license and the context WP Admin user already opted in
13391
+ * before from the current site, add the user context security params to avoid the
13392
+ * unnecessary email activation when the context license is owned by the same context user.
13393
+ *
13394
+ * @author Leo Fajardo (@leorw)
13395
+ * @since 1.2.3
13396
+ */
13397
+ $params = array_merge( $params, FS_Security::instance()->get_context_params(
13398
+ $fs_user,
13399
+ false,
13400
+ 'install_with_existing_user'
13401
+ ) );
13402
+ }
13403
+ }
13404
+
13405
+ if ( is_bool( $is_marketing_allowed ) ) {
13406
+ $params['is_marketing_allowed'] = $is_marketing_allowed;
13407
+ }
13408
+
13409
+ $params['is_disconnected'] = $is_disconnected;
13410
+ $params['format'] = 'json';
13411
+
13412
+ $request = array(
13413
+ 'method' => 'POST',
13414
+ 'body' => $params,
13415
+ 'timeout' => WP_FS__DEBUG_SDK ? 60 : 30,
13416
+ );
13417
+
13418
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
13419
+ $response = self::safe_remote_post( $url, $request );
13420
+
13421
+ if ( is_wp_error( $response ) ) {
13422
+ /**
13423
+ * @var WP_Error $response
13424
+ */
13425
+ $result = new stdClass();
13426
+
13427
+ $error_code = $response->get_error_code();
13428
+ $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
13429
+
13430
+ $result->error = (object) array(
13431
+ 'type' => $error_type,
13432
+ 'message' => $response->get_error_message(),
13433
+ 'code' => $error_code,
13434
+ 'http' => 402
13435
+ );
13436
+
13437
+ return $result;
13438
+ }
13439
+
13440
+ // Module is being uninstalled, don't handle the returned data.
13441
+ if ( $is_uninstall ) {
13442
+ return true;
13443
+ }
13444
+
13445
+ /**
13446
+ * When json_decode() executed on PHP 5.2 with an invalid JSON, it will throw a PHP warning. Unfortunately, the new Theme Check doesn't allow PHP silencing and the theme review team isn't open to change that, therefore, instead of using `@json_decode()` we had to use the method without the `@` directive.
13447
+ *
13448
+ * @author Vova Feldman (@svovaf)
13449
+ * @since 1.2.3
13450
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:5
13451
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:9
13452
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:12
13453
+ * @link https://themes.trac.wordpress.org/ticket/46134#comment:14
13454
+ */
13455
+ $decoded = is_string( $response['body'] ) ?
13456
+ json_decode( $response['body'] ) :
13457
+ null;
13458
+
13459
+ if ( empty( $decoded ) ) {
13460
+ return false;
13461
+ }
13462
+
13463
+ if ( ! $this->is_api_result_object( $decoded ) ) {
13464
+ if ( ! empty( $params['license_key'] ) ) {
13465
+ // Pass the fully entered license key to the failure handler.
13466
+ $params['license_key'] = $license_key;
13467
+ }
13468
+
13469
+ return $is_uninstall ?
13470
+ $decoded :
13471
+ $this->apply_filters( 'after_install_failure', $decoded, $params );
13472
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
13473
+ if ( $is_network ) {
13474
+ $site_ids = array();
13475
+ foreach ( $sites as $site ) {
13476
+ $site_ids[] = $site['blog_id'];
13477
+ }
13478
+
13479
+ /**
13480
+ * Store the sites so that they can be installed once the user has clicked on the activation link
13481
+ * in the email.
13482
+ *
13483
+ * @author Leo Fajardo (@leorw)
13484
+ */
13485
+ $this->_storage->pending_sites_info = array(
13486
+ 'blog_ids' => $site_ids,
13487
+ 'license_key' => $license_key,
13488
+ 'trial_plan_id' => $trial_plan_id
13489
+ );
13490
+ }
13491
+
13492
+ // Pending activation, add message.
13493
+ return $this->set_pending_confirmation(
13494
+ ( isset( $decoded->email ) ?
13495
+ $decoded->email :
13496
+ true ),
13497
+ false,
13498
+ $filtered_license_key,
13499
+ ! empty( $params['trial_plan_id'] )
13500
+ );
13501
+ } else if ( isset( $decoded->install_secret_key ) ) {
13502
+ return $this->install_with_new_user(
13503
+ $decoded->user_id,
13504
+ $decoded->user_public_key,
13505
+ $decoded->user_secret_key,
13506
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
13507
+ $decoded->is_marketing_allowed :
13508
+ null ),
13509
+ $decoded->install_id,
13510
+ $decoded->install_public_key,
13511
+ $decoded->install_secret_key,
13512
+ false
13513
+ );
13514
+ } else if ( is_array( $decoded->installs ) ) {
13515
+ return $this->install_many_with_new_user(
13516
+ $decoded->user_id,
13517
+ $decoded->user_public_key,
13518
+ $decoded->user_secret_key,
13519
+ ( isset( $decoded->is_marketing_allowed ) && ! is_null( $decoded->is_marketing_allowed ) ?
13520
+ $decoded->is_marketing_allowed :
13521
+ null ),
13522
+ $decoded->installs,
13523
+ false
13524
+ );
13525
+ }
13526
+
13527
+ return $decoded;
13528
+ }
13529
+
13530
+ /**
13531
+ * Set user and site identities.
13532
+ *
13533
+ * @author Vova Feldman (@svovaf)
13534
+ * @since 1.0.9
13535
+ *
13536
+ * @param FS_User $user
13537
+ * @param FS_Site $site
13538
+ * @param bool $redirect
13539
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
13540
+ * redirect (or return a URL) to the account page with a special parameter to
13541
+ * trigger the auto installation processes.
13542
+ *
13543
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13544
+ */
13545
+ function setup_account(
13546
+ FS_User $user,
13547
+ FS_Site $site,
13548
+ $redirect = true,
13549
+ $auto_install = false
13550
+ ) {
13551
+ return $this->setup_network_account(
13552
+ $user,
13553
+ array( $site ),
13554
+ $redirect,
13555
+ $auto_install,
13556
+ false
13557
+ );
13558
+ }
13559
+
13560
+ /**
13561
+ * Set user and site identities.
13562
+ *
13563
+ * @author Vova Feldman (@svovaf)
13564
+ * @since 2.0.0
13565
+ *
13566
+ * @param FS_User $user
13567
+ * @param FS_Site[] $installs
13568
+ * @param bool $redirect
13569
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will redirect (or return a URL) to the account page with a special parameter to trigger the auto installation processes.
13570
+ * @param bool $is_network_level_opt_in
13571
+ *
13572
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13573
+ */
13574
+ function setup_network_account(
13575
+ FS_User $user,
13576
+ array $installs,
13577
+ $redirect = true,
13578
+ $auto_install = false,
13579
+ $is_network_level_opt_in = true
13580
+ ) {
13581
+ $first_install = $installs[0];
13582
+
13583
+ $this->_user = $user;
13584
+ $this->_site = $first_install;
13585
+
13586
+ $this->_sync_plans();
13587
+
13588
+ if ( $this->_storage->handle_gdpr_admin_notice &&
13589
+ $this->should_handle_gdpr_admin_notice() &&
13590
+ FS_GDPR_Manager::instance()->should_show_opt_in_notice()
13591
+ ) {
13592
+ /**
13593
+ * Clear user lock after an opt-in.
13594
+ */
13595
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-user-lock.php';
13596
+ FS_User_Lock::instance()->unlock();
13597
+ }
13598
+
13599
+ if ( 1 < count( $installs ) ) {
13600
+ // Only network level opt-in can have more than one install.
13601
+ $is_network_level_opt_in = true;
13602
+ }
13603
+ // $is_network_level_opt_in = self::is_ajax_action_static( 'network_activate', $this->_module_id );
13604
+ // If Freemius was OFF before, turn it on.
13605
+ $this->turn_on();
13606
+
13607
+ if ( ! $this->_is_network_active || ! $is_network_level_opt_in ) {
13608
+ $this->_set_account( $user, $first_install );
13609
+
13610
+ $this->do_action( 'after_account_connection', $user, $first_install );
13611
+ } else {
13612
+ $this->_store_user();
13613
+
13614
+ // Map site addresses to their blog IDs.
13615
+ $address_to_blog_map = $this->get_address_to_blog_map();
13616
+
13617
+ $first_blog_id = null;
13618
+ $blog_2_install_map = array();
13619
+ foreach ( $installs as $install ) {
13620
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
13621
+ $blog_id = $address_to_blog_map[ $address ];
13622
+
13623
+ $this->_store_site( true, $blog_id, $install );
13624
+
13625
+ if ( is_null( $first_blog_id ) ) {
13626
+ $first_blog_id = $blog_id;
13627
+ }
13628
+
13629
+ $blog_2_install_map[ $blog_id ] = $install;
13630
+ }
13631
+
13632
+ if ( ! FS_User::is_valid_id( $this->_storage->network_user_id ) ||
13633
+ ! is_object( self::_get_user_by_id( $this->_storage->network_user_id ) )
13634
+ ) {
13635
+ // Store network user.
13636
+ $this->_storage->network_user_id = $this->_user->id;
13637
+ }
13638
+
13639
+ if ( ! FS_Site::is_valid_id( $this->_storage->network_install_blog_id ) ) {
13640
+ $this->_storage->network_install_blog_id = $first_blog_id;
13641
+ }
13642
+
13643
+ if ( count( $installs ) === count( $address_to_blog_map ) ) {
13644
+ // Super-admin opted-in for all sites in the network.
13645
+ $this->_storage->is_network_connected = true;
13646
+ }
13647
+
13648
+ $this->_store_licenses( false );
13649
+
13650
+ self::$_accounts->store();
13651
+
13652
+ // Don't sync the installs data on network upgrade
13653
+ if ( ! $this->network_upgrade_mode_completed() ) {
13654
+ $this->send_installs_update();
13655
+ }
13656
+
13657
+ // Switch install context back to the first install.
13658
+ $this->_site = $first_install;
13659
+
13660
+ $current_blog = get_current_blog_id();
13661
+
13662
+ foreach ( $blog_2_install_map as $blog_id => $install ) {
13663
+ $this->switch_to_blog( $blog_id );
13664
+
13665
+ $this->do_action( 'after_account_connection', $user, $install );
13666
+ }
13667
+
13668
+ $this->switch_to_blog( $current_blog );
13669
+
13670
+ $this->do_action( 'after_network_account_connection', $user, $blog_2_install_map );
13671
+ }
13672
+
13673
+ if ( is_numeric( $first_install->license_id ) ) {
13674
+ $this->_license = $this->_get_license_by_id( $first_install->license_id );
13675
+ }
13676
+
13677
+ $this->_admin_notices->remove_sticky( 'connect_account' );
13678
+
13679
+ if ( $this->is_pending_activation() || ! $this->has_settings_menu() ) {
13680
+ // Remove pending activation sticky notice (if still exist).
13681
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
13682
+
13683
+ // Remove plugin from pending activation mode.
13684
+ unset( $this->_storage->is_pending_activation );
13685
+
13686
+ if ( ! $this->is_paying_or_trial() ) {
13687
+ $this->_admin_notices->add_sticky(
13688
+ sprintf( $this->get_text_inline( '%s activation was successfully completed.', 'plugin-x-activation-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
13689
+ 'activation_complete'
13690
+ );
13691
+ }
13692
+ }
13693
+
13694
+ if ( $this->is_paying_or_trial() ) {
13695
+ if ( ! $this->is_premium() ||
13696
+ ! $this->has_premium_version() ||
13697
+ ! $this->has_settings_menu()
13698
+ ) {
13699
+ if ( $this->is_paying() ) {
13700
+ $this->_admin_notices->add_sticky(
13701
+ sprintf(
13702
+ $this->get_text_inline( 'Your account was successfully activated with the %s plan.', 'activation-with-plan-x-message' ),
13703
+ $this->get_plan_title()
13704
+ ) . $this->get_complete_upgrade_instructions(),
13705
+ 'plan_upgraded',
13706
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
13707
+ );
13708
+ } else {
13709
+ $trial_plan = $this->get_trial_plan();
13710
+
13711
+ $this->_admin_notices->add_sticky(
13712
+ sprintf(
13713
+ $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
13714
+ '<i>' . $this->get_plugin_name() . '</i>'
13715
+ ) . $this->get_complete_upgrade_instructions( $trial_plan->title ),
13716
+ 'trial_started',
13717
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
13718
+ );
13719
+ }
13720
+ }
13721
+
13722
+ $this->_admin_notices->remove_sticky( array(
13723
+ 'trial_promotion',
13724
+ ) );
13725
+ }
13726
+
13727
+ $plugin_id = fs_request_get( 'plugin_id', false );
13728
+
13729
+ // Store activation time ONLY for plugins & themes (not add-ons).
13730
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
13731
+ if ( empty( $this->_storage->activation_timestamp ) ) {
13732
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
13733
+ }
13734
+ }
13735
+
13736
+ $next_page = '';
13737
+
13738
+ $extra = array();
13739
+ if ( $auto_install ) {
13740
+ $extra['auto_install'] = 'true';
13741
+ }
13742
+
13743
+ if ( is_numeric( $plugin_id ) ) {
13744
+ /**
13745
+ * @author Leo Fajardo (@leorw)
13746
+ * @since 1.2.1.6
13747
+ *
13748
+ * Also sync the license after an anonymous user subscribes.
13749
+ */
13750
+ if ( $this->is_anonymous() || $plugin_id != $this->_plugin->id ) {
13751
+ // Add-on was installed - sync license right after install.
13752
+ $next_page = $this->_get_sync_license_url( $plugin_id, true, $extra );
13753
+ }
13754
+ } else {
13755
+ /**
13756
+ * @author Vova Feldman (@svovaf)
13757
+ * @since 1.1.9 If site installed with a valid license, sync license.
13758
+ */
13759
+ if ( $this->is_paying() ) {
13760
+ $this->_sync_plugin_license(
13761
+ true,
13762
+ // Installs data is already synced in the beginning of this method directly or via _set_account().
13763
+ false
13764
+ );
13765
+ }
13766
+
13767
+ // Reload the page with the keys.
13768
+ $next_page = $this->is_anonymous() ?
13769
+ // If user previously skipped, redirect to account page.
13770
+ $this->get_account_url( false, $extra ) :
13771
+ $this->get_after_activation_url( 'after_connect_url', array(), $is_network_level_opt_in );
13772
+ }
13773
+
13774
+ if ( ! empty( $next_page ) && $redirect ) {
13775
+ fs_redirect( $next_page );
13776
+ }
13777
+
13778
+ return $next_page;
13779
+ }
13780
+
13781
+ /**
13782
+ * Install plugin with new user information after approval.
13783
+ *
13784
+ * @author Vova Feldman (@svovaf)
13785
+ * @since 1.0.7
13786
+ */
13787
+ function _install_with_new_user() {
13788
+ $this->_logger->entrance();
13789
+
13790
+ if ( $this->is_registered() ) {
13791
+ return;
13792
+ }
13793
+
13794
+ if ( ( $this->is_plugin() && fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) ||
13795
+ // @todo This logic should be improved because it's executed on every load of a theme.
13796
+ $this->is_theme()
13797
+ ) {
13798
+ // check_admin_referer( $this->_slug . '_activate_new' );
13799
+
13800
+ if ( fs_request_has( 'user_secret_key' ) ) {
13801
+ if ( fs_is_network_admin() && isset( $this->_storage->pending_sites_info ) ) {
13802
+ $pending_sites_info = $this->_storage->pending_sites_info;
13803
+
13804
+ $this->install_many_pending_with_user(
13805
+ fs_request_get( 'user_id' ),
13806
+ fs_request_get( 'user_public_key' ),
13807
+ fs_request_get( 'user_secret_key' ),
13808
+ fs_request_get_bool( 'is_marketing_allowed', null ),
13809
+ $pending_sites_info['blog_ids'],
13810
+ $pending_sites_info['license_key'],
13811
+ $pending_sites_info['trial_plan_id']
13812
+ );
13813
+ } else {
13814
+ $this->install_with_new_user(
13815
+ fs_request_get( 'user_id' ),
13816
+ fs_request_get( 'user_public_key' ),
13817
+ fs_request_get( 'user_secret_key' ),
13818
+ fs_request_get_bool( 'is_marketing_allowed', null ),
13819
+ fs_request_get( 'install_id' ),
13820
+ fs_request_get( 'install_public_key' ),
13821
+ fs_request_get( 'install_secret_key' ),
13822
+ true,
13823
+ fs_request_get_bool( 'auto_install' )
13824
+ );
13825
+ }
13826
+ } else if ( fs_request_has( 'pending_activation' ) ) {
13827
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
13828
+ }
13829
+ }
13830
+ }
13831
+
13832
+ /**
13833
+ * @author Vova Feldman (@svovaf)
13834
+ * @since 2.0.0
13835
+ *
13836
+ * @param number $id
13837
+ * @param string $public_key
13838
+ * @param string $secret_key
13839
+ *
13840
+ * @return \FS_User
13841
+ */
13842
+ private function setup_user( $id, $public_key, $secret_key ) {
13843
+ $user = self::_get_user_by_id( $id );
13844
+
13845
+ if ( is_object( $user ) ) {
13846
+ $this->_user = $user;
13847
+ } else {
13848
+ $user = new FS_User();
13849
+ $user->id = $id;
13850
+ $user->public_key = $public_key;
13851
+ $user->secret_key = $secret_key;
13852
+
13853
+ $this->_user = $user;
13854
+ $user_result = $this->get_api_user_scope()->get();
13855
+ $user = new FS_User( $user_result );
13856
+
13857
+ $this->_user = $user;
13858
+ $this->_store_user();
13859
+ }
13860
+
13861
+ return $user;
13862
+ }
13863
+
13864
+ /**
13865
+ * Install plugin with new user.
13866
+ *
13867
+ * @author Vova Feldman (@svovaf)
13868
+ * @since 1.1.7.4
13869
+ *
13870
+ * @param number $user_id
13871
+ * @param string $user_public_key
13872
+ * @param string $user_secret_key
13873
+ * @param bool|null $is_marketing_allowed
13874
+ * @param number $install_id
13875
+ * @param string $install_public_key
13876
+ * @param string $install_secret_key
13877
+ * @param bool $redirect
13878
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
13879
+ * redirect (or return a URL) to the account page with a special parameter to
13880
+ * trigger the auto installation processes.
13881
+ *
13882
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13883
+ */
13884
+ private function install_with_new_user(
13885
+ $user_id,
13886
+ $user_public_key,
13887
+ $user_secret_key,
13888
+ $is_marketing_allowed,
13889
+ $install_id,
13890
+ $install_public_key,
13891
+ $install_secret_key,
13892
+ $redirect = true,
13893
+ $auto_install = false
13894
+ ) {
13895
+ /**
13896
+ * This method is also executed after opting in with a license key since the
13897
+ * license can be potentially associated with a different owner.
13898
+ *
13899
+ * @since 2.0.0
13900
+ */
13901
+ $user = self::_get_user_by_id( $user_id );
13902
+
13903
+ if ( ! is_object( $user ) ) {
13904
+ $user = new FS_User();
13905
+ $user->id = $user_id;
13906
+ $user->public_key = $user_public_key;
13907
+ $user->secret_key = $user_secret_key;
13908
+
13909
+ $this->_user = $user;
13910
+ $user_result = $this->get_api_user_scope()->get();
13911
+ $user = new FS_User( $user_result );
13912
+ }
13913
+
13914
+ $this->_user = $user;
13915
+
13916
+ $site = new FS_Site();
13917
+ $site->id = $install_id;
13918
+ $site->public_key = $install_public_key;
13919
+ $site->secret_key = $install_secret_key;
13920
+
13921
+ $this->_site = $site;
13922
+ $site_result = $this->get_api_site_scope()->get();
13923
+ $site = new FS_Site( $site_result );
13924
+ $this->_site = $site;
13925
+
13926
+ if ( ! is_null( $is_marketing_allowed ) ) {
13927
+ $this->disable_opt_in_notice_and_lock_user();
13928
+ }
13929
+
13930
+ return $this->setup_account(
13931
+ $this->_user,
13932
+ $this->_site,
13933
+ $redirect,
13934
+ $auto_install
13935
+ );
13936
+ }
13937
+
13938
+ /**
13939
+ * Install plugin with user.
13940
+ *
13941
+ * @author Leo Fajardo (@leorw)
13942
+ * @since 2.0.0
13943
+ *
13944
+ * @param number $user_id
13945
+ * @param string $user_public_key
13946
+ * @param string $user_secret_key
13947
+ * @param bool|null $is_marketing_allowed
13948
+ * @param array $site_ids
13949
+ * @param bool $license_key
13950
+ * @param bool $trial_plan_id
13951
+ * @param bool $redirect
13952
+ *
13953
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13954
+ */
13955
+ private function install_many_pending_with_user(
13956
+ $user_id,
13957
+ $user_public_key,
13958
+ $user_secret_key,
13959
+ $is_marketing_allowed,
13960
+ $site_ids,
13961
+ $license_key = false,
13962
+ $trial_plan_id = false,
13963
+ $redirect = true
13964
+ ) {
13965
+ $user = $this->setup_user( $user_id, $user_public_key, $user_secret_key );
13966
+
13967
+ if ( ! is_null( $is_marketing_allowed ) ) {
13968
+ $this->disable_opt_in_notice_and_lock_user();
13969
+ }
13970
+
13971
+ $sites = array();
13972
+ foreach ( $site_ids as $site_id ) {
13973
+ $sites[] = $this->get_site_info( array( 'blog_id' => $site_id ) );
13974
+ }
13975
+
13976
+ $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
13977
+ }
13978
+
13979
+ /**
13980
+ * Multi-site install with a new user.
13981
+ *
13982
+ * @author Vova Feldman (@svovaf)
13983
+ * @since 2.0.0
13984
+ *
13985
+ * @param number $user_id
13986
+ * @param string $user_public_key
13987
+ * @param string $user_secret_key
13988
+ * @param bool|null $is_marketing_allowed
13989
+ * @param object[] $installs
13990
+ * @param bool $redirect
13991
+ * @param bool $auto_install Since 1.2.1.7 If `true` and setting up an account with a valid license, will
13992
+ * redirect (or return a URL) to the account page with a special parameter to
13993
+ * trigger the auto installation processes.
13994
+ *
13995
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
13996
+ */
13997
+ private function install_many_with_new_user(
13998
+ $user_id,
13999
+ $user_public_key,
14000
+ $user_secret_key,
14001
+ $is_marketing_allowed,
14002
+ array $installs,
14003
+ $redirect = true,
14004
+ $auto_install = false
14005
+ ) {
14006
+ $this->setup_user( $user_id, $user_public_key, $user_secret_key );
14007
+
14008
+ if ( ! is_null( $is_marketing_allowed ) ) {
14009
+ $this->disable_opt_in_notice_and_lock_user();
14010
+ }
14011
+
14012
+ $install_ids = array();
14013
+
14014
+ foreach ( $installs as $install ) {
14015
+ $install_ids[] = $install->id;
14016
+ }
14017
+
14018
+ $left = count( $install_ids );
14019
+ $offset = 0;
14020
+
14021
+ $installs = array();
14022
+ while ( $left > 0 ) {
14023
+ $result = $this->get_api_user_scope()->get( "/plugins/{$this->_module_id}/installs.json?ids=" . implode( ',', array_slice( $install_ids, $offset, 25 ) ) );
14024
+
14025
+ if ( ! $this->is_api_result_object( $result, 'installs' ) ) {
14026
+ // @todo Handle API error.
14027
+ }
14028
+
14029
+ $installs = array_merge( $installs, $result->installs );
14030
+
14031
+ $left -= 25;
14032
+ }
14033
+
14034
+ foreach ( $installs as &$install ) {
14035
+ $install = new FS_Site( $install );
14036
+ }
14037
+
14038
+ return $this->setup_network_account(
14039
+ $this->_user,
14040
+ $installs,
14041
+ $redirect,
14042
+ $auto_install
14043
+ );
14044
+ }
14045
+
14046
+ /**
14047
+ * @author Vova Feldman (@svovaf)
14048
+ * @since 1.1.7.4
14049
+ *
14050
+ * @param string|bool $email
14051
+ * @param bool $redirect
14052
+ * @param string|bool $license_key Since 1.2.1.5
14053
+ * @param bool $is_pending_trial Since 1.2.1.5
14054
+ *
14055
+ * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
14056
+ */
14057
+ private function set_pending_confirmation(
14058
+ $email = false,
14059
+ $redirect = true,
14060
+ $license_key = false,
14061
+ $is_pending_trial = false
14062
+ ) {
14063
+ if ( $this->_ignore_pending_mode ) {
14064
+ /**
14065
+ * If explicitly asked to ignore pending mode, set to anonymous mode
14066
+ * if require confirmation before finalizing the opt-in.
14067
+ *
14068
+ * @author Vova Feldman
14069
+ * @since 1.2.1.6
14070
+ */
14071
+ $this->skip_connection( null, fs_is_network_admin() );
14072
+ } else {
14073
+ // Install must be activated via email since
14074
+ // user with the same email already exist.
14075
+ $this->_storage->is_pending_activation = true;
14076
+ $this->_add_pending_activation_notice( $email, $is_pending_trial );
14077
+ }
14078
+
14079
+ if ( ! empty( $license_key ) ) {
14080
+ $this->_storage->pending_license_key = $license_key;
14081
+ }
14082
+
14083
+ // Remove the opt-in sticky notice.
14084
+ $this->_admin_notices->remove_sticky( array(
14085
+ 'connect_account',
14086
+ 'trial_promotion',
14087
+ ) );
14088
+
14089
+ $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
14090
+
14091
+ // Reload the page with with pending activation message.
14092
+ if ( $redirect ) {
14093
+ fs_redirect( $next_page );
14094
+ }
14095
+
14096
+ return $next_page;
14097
+ }
14098
+
14099
+ /**
14100
+ * Install plugin with current logged WP user info.
14101
+ *
14102
+ * @author Vova Feldman (@svovaf)
14103
+ * @since 1.0.7
14104
+ */
14105
+ function _install_with_current_user() {
14106
+ $this->_logger->entrance();
14107
+
14108
+ if ( $this->is_registered() ) {
14109
+ return;
14110
+ }
14111
+
14112
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) && fs_request_is_post() ) {
14113
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
14114
+
14115
+ /**
14116
+ * @author Vova Feldman (@svovaf)
14117
+ * @since 1.1.9 Add license key if given.
14118
+ */
14119
+ $license_key = fs_request_get( 'license_secret_key' );
14120
+
14121
+ $this->install_with_current_user( $license_key );
14122
+ }
14123
+ }
14124
+
14125
+
14126
+ /**
14127
+ * @author Vova Feldman (@svovaf)
14128
+ * @since 1.1.7.4
14129
+ *
14130
+ * @param string|bool $license_key
14131
+ * @param number|bool $trial_plan_id
14132
+ * @param array $sites Since 2.0.0
14133
+ * @param bool $redirect
14134
+ *
14135
+ * @return object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install.
14136
+ */
14137
+ private function install_with_current_user(
14138
+ $license_key = false,
14139
+ $trial_plan_id = false,
14140
+ $sites = array(),
14141
+ $redirect = true
14142
+ ) {
14143
+ // Get current logged WP user.
14144
+ $current_user = self::_get_current_wp_user();
14145
+
14146
+ // Find the relevant FS user by the email.
14147
+ $user = self::_get_user_by_email( $current_user->user_email );
14148
+
14149
+ return $this->install_with_user( $user, $license_key, $trial_plan_id, $redirect, true, $sites );
14150
+ }
14151
+
14152
+ /**
14153
+ * @author Vova Feldman (@svovaf)
14154
+ * @since 2.0.0
14155
+ *
14156
+ * @param \FS_User $user
14157
+ * @param string|bool $license_key
14158
+ * @param number|bool $trial_plan_id
14159
+ * @param bool $redirect
14160
+ * @param bool $setup_account Since 2.0.0. When set to FALSE, executes a light installation without setting up the account as if it's the first opt-in.
14161
+ * @param array $sites Since 2.0.0. If not empty, should be a collection of site details for the bulk install API request.
14162
+ *
14163
+ * @return \FS_Site|object|string If redirect is `false`, returns the next page the user should be redirected to, or the API error object if failed to install. If $setup_account is set to `false`, return the newly created install.
14164
+ */
14165
+ private function install_with_user(
14166
+ FS_User $user,
14167
+ $license_key = false,
14168
+ $trial_plan_id = false,
14169
+ $redirect = true,
14170
+ $setup_account = true,
14171
+ $sites = array()
14172
+ ) {
14173
+ // We have to set the user before getting user scope API handler.
14174
+ $this->_user = $user;
14175
+
14176
+ // Install the plugin.
14177
+ $result = $this->create_installs_with_user(
14178
+ $user,
14179
+ $license_key,
14180
+ $trial_plan_id,
14181
+ $sites,
14182
+ $redirect
14183
+ );
14184
+
14185
+ if ( ! $this->is_api_result_entity( $result ) &&
14186
+ ! $this->is_api_result_object( $result, 'installs' )
14187
+ ) {
14188
+ // @todo Handler potential API error of the $result
14189
+ }
14190
+
14191
+ if ( empty( $sites ) ) {
14192
+ $site = new FS_Site( $result );
14193
+ $this->_site = $site;
14194
+
14195
+ if ( ! $setup_account ) {
14196
+ $this->_store_site();
14197
+
14198
+ $this->sync_plan_if_not_exist( $site->plan_id );
14199
+
14200
+ if ( ! empty( $license_key ) && FS_Plugin_License::is_valid_id( $site->license_id ) ) {
14201
+ $this->sync_license_if_not_exist( $site->license_id, $license_key );
14202
+ }
14203
+
14204
+ $this->_admin_notices->remove_sticky( 'connect_account', false );
14205
+
14206
+ return $site;
14207
+ }
14208
+
14209
+ return $this->setup_account( $this->_user, $this->_site, $redirect );
14210
+ } else {
14211
+ $installs = array();
14212
+ foreach ( $result->installs as $install ) {
14213
+ $installs[] = new FS_Site( $install );
14214
+ }
14215
+
14216
+ return $this->setup_network_account(
14217
+ $user,
14218
+ $installs,
14219
+ $redirect
14220
+ );
14221
+ }
14222
+ }
14223
+
14224
+ /**
14225
+ * Initiate an API request to create a collection of installs.
14226
+ *
14227
+ * @author Vova Feldman (@svovaf)
14228
+ * @since 2.0.0
14229
+ *
14230
+ * @param \FS_User $user
14231
+ * @param bool $license_key
14232
+ * @param bool $trial_plan_id
14233
+ * @param array $sites
14234
+ * @param bool $redirect
14235
+ * @param bool $silent
14236
+ *
14237
+ * @return object|mixed
14238
+ */
14239
+ private function create_installs_with_user(
14240
+ FS_User $user,
14241
+ $license_key = false,
14242
+ $trial_plan_id = false,
14243
+ $sites = array(),
14244
+ $redirect = false,
14245
+ $silent = false
14246
+ ) {
14247
+ $extra_install_params = array(
14248
+ 'uid' => $this->get_anonymous_id(),
14249
+ 'is_disconnected' => false,
14250
+ );
14251
+
14252
+ if ( ! empty( $license_key ) ) {
14253
+ $extra_install_params['license_key'] = $this->apply_filters( 'license_key', $license_key );
14254
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
14255
+ $extra_install_params['trial_plan_id'] = $trial_plan_id;
14256
+ }
14257
+
14258
+ if ( ! empty( $sites ) ) {
14259
+ $extra_install_params['sites'] = $sites;
14260
+ }
14261
+
14262
+ $args = $this->get_install_data_for_api( $extra_install_params, false, false );
14263
+
14264
+ // Install the plugin.
14265
+ $result = $this->get_api_user_scope_by_user( $user )->call(
14266
+ "/plugins/{$this->get_id()}/installs.json",
14267
+ 'post',
14268
+ $args
14269
+ );
14270
+
14271
+ if ( ! $this->is_api_result_entity( $result ) &&
14272
+ ! $this->is_api_result_object( $result, 'installs' )
14273
+ ) {
14274
+ if ( ! empty( $args['license_key'] ) ) {
14275
+ // Pass full the fully entered license key to the failure handler.
14276
+ $args['license_key'] = $license_key;
14277
+ }
14278
+
14279
+ $result = $this->apply_filters( 'after_install_failure', $result, $args );
14280
+
14281
+ if ( ! $silent ) {
14282
+ $this->_admin_notices->add(
14283
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14284
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $result->error->message . '</b>',
14285
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14286
+ 'error'
14287
+ );
14288
+ }
14289
+
14290
+ if ( $redirect ) {
14291
+ /**
14292
+ * We set the user before getting the user scope API handler, so the user became temporarily
14293
+ * registered (`is_registered() = true`). Since the API returned an error and we will redirect,
14294
+ * we have to set the user to `null`, otherwise, the user will be redirected to the wrong
14295
+ * activation page based on the return value of `is_registered()`. In addition, in case the
14296
+ * context plugin doesn't have a settings menu and the default page is the `Plugins` page,
14297
+ * misleading plugin activation errors will be shown on the `Plugins` page.
14298
+ *
14299
+ * @author Leo Fajardo (@leorw)
14300
+ */
14301
+ $this->_user = null;
14302
+
14303
+ fs_redirect( $this->get_activation_url( array( 'error' => $result->error->message ) ) );
14304
+ }
14305
+ }
14306
+
14307
+ return $result;
14308
+ }
14309
+
14310
+ /**
14311
+ * Tries to activate add-on account based on parent plugin info.
14312
+ *
14313
+ * @author Vova Feldman (@svovaf)
14314
+ * @since 1.0.6
14315
+ *
14316
+ * @param Freemius $parent_fs
14317
+ */
14318
+ private function _activate_addon_account( Freemius $parent_fs ) {
14319
+ if ( $this->is_registered() ) {
14320
+ // Already activated.
14321
+ return;
14322
+ }
14323
+
14324
+ // Activate add-on with parent plugin credentials.
14325
+ $addon_install = $parent_fs->get_api_site_scope()->call(
14326
+ "/addons/{$this->_plugin->id}/installs.json",
14327
+ 'post',
14328
+ $this->get_install_data_for_api( array(
14329
+ 'uid' => $this->get_anonymous_id(),
14330
+ ), false, false )
14331
+ );
14332
+
14333
+ if ( isset( $addon_install->error ) ) {
14334
+ $this->_admin_notices->add(
14335
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14336
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
14337
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14338
+ 'error'
14339
+ );
14340
+
14341
+ return;
14342
+ }
14343
+
14344
+ // Get user information based on parent's plugin.
14345
+ $user = $parent_fs->get_user();
14346
+
14347
+ // First of all, set site and user info - otherwise we won't
14348
+ // be able to invoke API calls.
14349
+ $this->_site = new FS_Site( $addon_install );
14350
+ $this->_user = $user;
14351
+
14352
+ // Sync add-on plans.
14353
+ $this->_sync_plans();
14354
+
14355
+ // Get site's current plan.
14356
+ //$this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
14357
+
14358
+ $this->_set_account( $user, $this->_site );
14359
+
14360
+ // Sync licenses.
14361
+ $this->_sync_licenses();
14362
+
14363
+ // Try to activate premium license.
14364
+ $this->_activate_license( true );
14365
+ }
14366
+
14367
+ /**
14368
+ * Tries to activate parent account based on add-on's info.
14369
+ *
14370
+ * @author Vova Feldman (@svovaf)
14371
+ * @since 1.2.2.7
14372
+ *
14373
+ * @param Freemius $parent_fs
14374
+ */
14375
+ private function activate_parent_account( Freemius $parent_fs ) {
14376
+ if ( ! $this->is_addon() ) {
14377
+ // This is not an add-on.
14378
+ return;
14379
+ }
14380
+
14381
+ if ( $parent_fs->is_registered() ) {
14382
+ // Already activated.
14383
+ return;
14384
+ }
14385
+
14386
+ // Activate parent with add-on's user credentials.
14387
+ $parent_install = $this->get_api_user_scope()->call(
14388
+ "/plugins/{$parent_fs->_plugin->id}/installs.json",
14389
+ 'post',
14390
+ $parent_fs->get_install_data_for_api( array(
14391
+ 'uid' => $parent_fs->get_anonymous_id(),
14392
+ ), false, false )
14393
+ );
14394
+
14395
+ if ( isset( $parent_install->error ) ) {
14396
+ $this->_admin_notices->add(
14397
+ sprintf( $this->get_text_inline( 'Couldn\'t activate %s.', 'could-not-activate-x' ), $this->get_plugin_name() ) . ' ' .
14398
+ $this->get_text_inline( 'Please contact us with the following message:', 'contact-us-with-error-message' ) . ' ' . '<b>' . $parent_install->error->message . '</b>',
14399
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
14400
+ 'error'
14401
+ );
14402
+
14403
+ return;
14404
+ }
14405
+
14406
+ $parent_fs->_admin_notices->remove_sticky( 'connect_account' );
14407
+
14408
+ if ( $parent_fs->is_pending_activation() ) {
14409
+ $parent_fs->_admin_notices->remove_sticky( 'activation_pending' );
14410
+
14411
+ unset( $parent_fs->_storage->is_pending_activation );
14412
+ }
14413
+
14414
+ // Get user information based on parent's plugin.
14415
+ $user = $this->get_user();
14416
+
14417
+ // First of all, set site info - otherwise we won't
14418
+ // be able to invoke API calls.
14419
+ $parent_fs->_site = new FS_Site( $parent_install );
14420
+ $parent_fs->_user = $user;
14421
+
14422
+ // Sync add-on plans.
14423
+ $parent_fs->_sync_plans();
14424
+
14425
+ $parent_fs->_set_account( $user, $parent_fs->_site );
14426
+ }
14427
+
14428
+ #endregion
14429
+
14430
+ #----------------------------------------------------------------------------------
14431
+ #region Admin Menu Items
14432
+ #----------------------------------------------------------------------------------
14433
+
14434
+ private $_menu_items = array();
14435
+
14436
+ /**
14437
+ * @author Vova Feldman (@svovaf)
14438
+ * @since 1.2.1.8
14439
+ *
14440
+ * @return array
14441
+ */
14442
+ function get_menu_items() {
14443
+ return $this->_menu_items;
14444
+ }
14445
+
14446
+ /**
14447
+ * @author Vova Feldman (@svovaf)
14448
+ * @since 1.0.7
14449
+ *
14450
+ * @return string
14451
+ */
14452
+ function get_menu_slug() {
14453
+ return $this->_menu->get_slug();
14454
+ }
14455
+
14456
+ /**
14457
+ * @author Vova Feldman (@svovaf)
14458
+ * @since 1.0.9
14459
+ */
14460
+ function _prepare_admin_menu() {
14461
+ // if ( ! $this->is_on() ) {
14462
+ // return;
14463
+ // }
14464
+
14465
+ /**
14466
+ * When running from a site admin with a network activated module and the connection
14467
+ * was NOT delegated and the user still haven't skipped or opted-in, then hide the
14468
+ * site level settings.
14469
+ *
14470
+ * @author Vova Feldman (@svovaf)
14471
+ * @since 2.0.0
14472
+ */
14473
+ $should_hide_site_admin_settings = (
14474
+ $this->_is_network_active &&
14475
+ ! fs_is_network_admin() &&
14476
+ ! $this->is_delegated_connection() &&
14477
+ ! $this->is_anonymous() &&
14478
+ ! $this->is_registered()
14479
+ );
14480
+
14481
+ if ( ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) ||
14482
+ $should_hide_site_admin_settings
14483
+ ) {
14484
+ $this->_menu->remove_menu_item( $should_hide_site_admin_settings );
14485
+ } else {
14486
+ $this->do_action( fs_is_network_admin() ?
14487
+ 'before_network_admin_menu_init' :
14488
+ 'before_admin_menu_init'
14489
+ );
14490
+
14491
+ $this->add_menu_action();
14492
+
14493
+ $this->add_network_menu_when_missing();
14494
+
14495
+ $this->add_submenu_items();
14496
+ }
14497
+ }
14498
+
14499
+ /**
14500
+ * Admin dashboard menu items modifications.
14501
+ *
14502
+ * NOTE: admin_menu action executed before admin_init.
14503
+ *
14504
+ * @author Vova Feldman (@svovaf)
14505
+ * @since 1.0.7
14506
+ *
14507
+ */
14508
+ private function add_menu_action() {
14509
+ if ( $this->is_activation_mode() ) {
14510
+ if ( $this->is_plugin() || ( $this->has_settings_menu() && ! $this->is_free_wp_org_theme() ) ) {
14511
+ $this->override_plugin_menu_with_activation();
14512
+ } else {
14513
+ /**
14514
+ * Handle theme opt-in when the opt-in form shows as a dialog box in the themes page.
14515
+ */
14516
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
14517
+ add_action( 'load-themes.php', array( &$this, '_install_with_current_user' ) );
14518
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ||
14519
+ fs_request_get_bool( 'pending_activation' )
14520
+ ) {
14521
+ add_action( 'load-themes.php', array( &$this, '_install_with_new_user' ) );
14522
+ }
14523
+ }
14524
+ } else {
14525
+ if ( ! $this->is_registered() ) {
14526
+ // If not registered try to install user.
14527
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
14528
+ $this->_install_with_new_user();
14529
+ }
14530
+ } else if (
14531
+ fs_request_is_action( 'sync_user' ) &&
14532
+ ( ! $this->has_settings_menu() || $this->is_free_wp_org_theme() )
14533
+ ) {
14534
+ $this->_handle_account_user_sync();
14535
+ }
14536
+ }
14537
+ }
14538
+
14539
+ /**
14540
+ * @author Vova Feldman (@svovaf)
14541
+ * @since 1.0.1
14542
+ */
14543
+ function _redirect_on_clicked_menu_link() {
14544
+ $this->_logger->entrance();
14545
+
14546
+ $page = fs_request_get('page');
14547
+ $page = is_string($page) ? strtolower($page) : '';
14548
+
14549
+ $this->_logger->log( 'page = ' . $page );
14550
+
14551
+ foreach ( $this->_menu_items as $priority => $items ) {
14552
+ foreach ( $items as $item ) {
14553
+ if ( isset( $item['url'] ) ) {
14554
+ if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
14555
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
14556
+
14557
+ fs_redirect( $item['url'] );
14558
+ }
14559
+ }
14560
+ }
14561
+ }
14562
+ }
14563
+
14564
+ /**
14565
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
14566
+ *
14567
+ * @author Vova Feldman (@svovaf)
14568
+ * @since 1.0.1
14569
+ */
14570
+ private function override_plugin_menu_with_activation() {
14571
+ $this->_logger->entrance();
14572
+
14573
+ $hook = false;
14574
+
14575
+ if ( ! $this->_menu->has_menu() ) {
14576
+ // Add the opt-in page without a menu item.
14577
+ $hook = FS_Admin_Menu_Manager::add_subpage(
14578
+ null,
14579
+ $this->get_plugin_name(),
14580
+ $this->get_plugin_name(),
14581
+ 'manage_options',
14582
+ $this->_slug,
14583
+ array( &$this, '_connect_page_render' )
14584
+ );
14585
+ } else if ( $this->_menu->is_top_level() ) {
14586
+ if ( $this->_menu->is_override_exact() ) {
14587
+ // Make sure the current page is matching the activation page.
14588
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
14589
+ return;
14590
+ }
14591
+ }
14592
+
14593
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
14594
+
14595
+ if ( false === $hook ) {
14596
+ // Create new menu item just for the opt-in.
14597
+ $hook = FS_Admin_Menu_Manager::add_page(
14598
+ $this->get_plugin_name(),
14599
+ $this->get_plugin_name(),
14600
+ 'manage_options',
14601
+ $this->_menu->get_slug(),
14602
+ array( &$this, '_connect_page_render' )
14603
+ );
14604
+ }
14605
+ } else {
14606
+ $menus = array( $this->_menu->get_parent_slug() );
14607
+
14608
+ if ( $this->_menu->is_override_exact() ) {
14609
+ // Make sure the current page is matching the activation page.
14610
+ if ( ! $this->is_matching_url( $this->get_activation_url() ) ) {
14611
+ return;
14612
+ }
14613
+ }
14614
+
14615
+ foreach ( $menus as $parent_slug ) {
14616
+ $hook = $this->_menu->override_submenu_action(
14617
+ $parent_slug,
14618
+ $this->_menu->get_raw_slug(),
14619
+ array( &$this, '_connect_page_render' )
14620
+ );
14621
+
14622
+ if ( false !== $hook ) {
14623
+ // Found plugin's submenu item.
14624
+ break;
14625
+ }
14626
+ }
14627
+ }
14628
+
14629
+ if ( $this->is_activation_page() ) {
14630
+ // Clean admin page from distracting content.
14631
+ self::_clean_admin_content_section();
14632
+ }
14633
+
14634
+ if ( false !== $hook ) {
14635
+ if ( fs_request_is_action( $this->get_unique_affix() . '_activate_existing' ) ) {
14636
+ $this->_install_with_current_user();
14637
+ } else if ( fs_request_is_action( $this->get_unique_affix() . '_activate_new' ) ) {
14638
+ $this->_install_with_new_user();
14639
+ }
14640
+ }
14641
+ }
14642
+
14643
+ /**
14644
+ * If a plugin was network activated and connected but don't have a network
14645
+ * level settings, then add an artificial menu item for the Account and other
14646
+ * Freemius settings.
14647
+ *
14648
+ * @author Vova Feldman (@svovaf)
14649
+ * @since 2.0.0
14650
+ */
14651
+ private function add_network_menu_when_missing() {
14652
+ $this->_logger->entrance();
14653
+
14654
+ if ( ! $this->_is_network_active ) {
14655
+ // Plugin wasn't activated on the network level.
14656
+ return;
14657
+ }
14658
+
14659
+ if ( ! fs_is_network_admin() ) {
14660
+ // The context is not the network admin.
14661
+ return;
14662
+ }
14663
+
14664
+ if ( $this->_menu->has_network_menu() ) {
14665
+ // Plugin already has a network level menu.
14666
+ return;
14667
+ }
14668
+
14669
+ if ( $this->is_network_activation_mode() ) {
14670
+ /**
14671
+ * Do not add during activation mode, otherwise, there will be duplicate menus while the opt-in
14672
+ * screen is being shown.
14673
+ *
14674
+ * @author Leo Fajardo (@leorw)
14675
+ */
14676
+ return;
14677
+ }
14678
+
14679
+ if ( ! WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ) {
14680
+ if ( $this->is_network_delegated_connection() ) {
14681
+ // Super-admin delegated the connection to the site admins.
14682
+ return;
14683
+ }
14684
+ }
14685
+
14686
+ if ( ! $this->_menu->has_menu() || $this->_menu->is_top_level() ) {
14687
+ $this->_dynamically_added_top_level_page_hook_name = $this->_menu->add_page_and_update(
14688
+ $this->get_plugin_name(),
14689
+ $this->get_plugin_name(),
14690
+ 'manage_options',
14691
+ $this->_menu->has_menu() ? $this->_menu->get_slug() : $this->_slug
14692
+ );
14693
+ } else {
14694
+ $this->_menu->add_subpage_and_update(
14695
+ $this->_menu->get_parent_slug(),
14696
+ $this->get_plugin_name(),
14697
+ $this->get_plugin_name(),
14698
+ 'manage_options',
14699
+ $this->_menu->get_slug()
14700
+ );
14701
+ }
14702
+ }
14703
+
14704
+ /**
14705
+ * @author Leo Fajardo (@leorw)
14706
+ * @since 1.2.1
14707
+ *
14708
+ * return string
14709
+ */
14710
+ function get_top_level_menu_capability() {
14711
+ global $menu;
14712
+
14713
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
14714
+
14715
+ foreach ( $menu as $menu_info ) {
14716
+ /**
14717
+ * The second element in the menu info array is the capability/role that has access to the menu and the
14718
+ * third element is the menu slug.
14719
+ */
14720
+ if ( $menu_info[2] === $top_level_menu_slug ) {
14721
+ return $menu_info[1];
14722
+ }
14723
+ }
14724
+
14725
+ return 'read';
14726
+ }
14727
+
14728
+ /**
14729
+ * @author Vova Feldman (@svovaf)
14730
+ * @since 1.0.0
14731
+ *
14732
+ * @return string
14733
+ */
14734
+ private function get_top_level_menu_slug() {
14735
+ return ( $this->is_addon() ?
14736
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
14737
+ $this->_menu->get_top_level_menu_slug() );
14738
+ }
14739
+
14740
+ /**
14741
+ * @author Vova Feldman (@svovaf)
14742
+ * @since 1.2.2.7
14743
+ *
14744
+ * @return string
14745
+ */
14746
+ function get_pricing_cta_label() {
14747
+ $label = $this->get_text_inline( 'Upgrade', 'upgrade' );
14748
+
14749
+ if ( $this->is_in_trial_promotion() &&
14750
+ ! $this->is_paying_or_trial()
14751
+ ) {
14752
+ // If running a trial promotion, modify the pricing to load the trial.
14753
+ $label = $this->get_text_inline( 'Start Trial', 'start-trial' );
14754
+ } else if ( $this->is_paying() ) {
14755
+ $label = $this->get_text_inline( 'Pricing', 'pricing' );
14756
+ }
14757
+
14758
+ return $label;
14759
+ }
14760
+
14761
+ /**
14762
+ * @author Vova Feldman (@svovaf)
14763
+ * @since 1.2.2.7
14764
+ *
14765
+ * @return bool
14766
+ */
14767
+ function is_pricing_page_visible() {
14768
+ return (
14769
+ // Has at least one paid plan.
14770
+ $this->has_paid_plan() &&
14771
+ // Didn't ask to hide the pricing page.
14772
+ $this->is_page_visible( 'pricing' ) &&
14773
+ // Don't have a valid active license or has more than one plan.
14774
+ ( ! $this->is_paying() || ! $this->is_single_plan() )
14775
+ );
14776
+ }
14777
+
14778
+ /**
14779
+ * Add default Freemius menu items.
14780
+ *
14781
+ * @author Vova Feldman (@svovaf)
14782
+ * @since 1.0.0
14783
+ * @since 1.2.2.7 Also add submenu items when running in a free .org theme so the tabs will be visible.
14784
+ */
14785
+ private function add_submenu_items() {
14786
+ $this->_logger->entrance();
14787
+
14788
+ $is_activation_mode = $this->is_activation_mode();
14789
+
14790
+ if ( $this->is_addon() ) {
14791
+ // No submenu items for add-ons.
14792
+ $add_submenu_items = false;
14793
+ } else if ( $this->is_free_wp_org_theme() && ! fs_is_network_admin() ) {
14794
+ // Also add submenu items when running in a free .org theme so the tabs will be visible.
14795
+ $add_submenu_items = true;
14796
+ } else if ( $is_activation_mode && ! $this->is_free_wp_org_theme() ) {
14797
+ $add_submenu_items = false;
14798
+ } else if ( fs_is_network_admin() ) {
14799
+ /**
14800
+ * Add submenu items to network level when plugin was network
14801
+ * activated and the super-admin did NOT delegated the connection
14802
+ * of all sites to site admins.
14803
+ */
14804
+ $add_submenu_items = (
14805
+ $this->_is_network_active &&
14806
+ ( WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED ||
14807
+ ! $this->is_network_delegated_connection() )
14808
+ );
14809
+ } else {
14810
+ $add_submenu_items = ( ! $this->_is_network_active || $this->is_delegated_connection() );
14811
+ }
14812
+
14813
+ if ( $add_submenu_items ) {
14814
+ if ( $this->has_affiliate_program() ) {
14815
+ // Add affiliation page.
14816
+ $this->add_submenu_item(
14817
+ $this->get_text_inline( 'Affiliation', 'affiliation' ),
14818
+ array( &$this, '_affiliation_page_render' ),
14819
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Affiliation', 'affiliation' ),
14820
+ 'manage_options',
14821
+ 'affiliation',
14822
+ 'Freemius::_clean_admin_content_section',
14823
+ WP_FS__DEFAULT_PRIORITY,
14824
+ $this->is_submenu_item_visible( 'affiliation' )
14825
+ );
14826
+ }
14827
+ }
14828
+
14829
+ if ( $add_submenu_items ||
14830
+ ( $is_activation_mode &&
14831
+ $this->is_only_premium() &&
14832
+ $this->is_admin_page( 'account' ) &&
14833
+ fs_request_is_action( $this->get_unique_affix() . '_sync_license' )
14834
+ )
14835
+ ) {
14836
+ if ( ! WP_FS__DEMO_MODE && $this->is_registered() ) {
14837
+ $show_account = (
14838
+ $this->is_submenu_item_visible( 'account' ) &&
14839
+ /**
14840
+ * @since 1.2.2.7 Don't show the Account for free WP.org themes without any paid plans.
14841
+ */
14842
+ ( ! $this->is_free_wp_org_theme() || $this->has_paid_plan() )
14843
+ );
14844
+
14845
+ // Add user account page.
14846
+ $this->add_submenu_item(
14847
+ $this->get_text_inline( 'Account', 'account' ),
14848
+ array( &$this, '_account_page_render' ),
14849
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Account', 'account' ),
14850
+ 'manage_options',
14851
+ 'account',
14852
+ array( &$this, '_account_page_load' ),
14853
+ WP_FS__DEFAULT_PRIORITY,
14854
+ ( $add_submenu_items && $show_account )
14855
+ );
14856
+ }
14857
+ }
14858
+
14859
+ if ( $add_submenu_items ) {
14860
+ // Add contact page.
14861
+ $this->add_submenu_item(
14862
+ $this->get_text_inline( 'Contact Us', 'contact-us' ),
14863
+ array( &$this, '_contact_page_render' ),
14864
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Contact Us', 'contact-us' ),
14865
+ 'manage_options',
14866
+ 'contact',
14867
+ 'Freemius::_clean_admin_content_section',
14868
+ WP_FS__DEFAULT_PRIORITY,
14869
+ $this->is_submenu_item_visible( 'contact' )
14870
+ );
14871
+
14872
+ if ( $this->has_addons() ) {
14873
+ $this->add_submenu_item(
14874
+ $this->get_text_inline( 'Add-Ons', 'add-ons' ),
14875
+ array( &$this, '_addons_page_render' ),
14876
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_inline( 'Add-Ons', 'add-ons' ),
14877
+ 'manage_options',
14878
+ 'addons',
14879
+ array( &$this, '_addons_page_load' ),
14880
+ WP_FS__LOWEST_PRIORITY - 1,
14881
+ $this->is_submenu_item_visible( 'addons' )
14882
+ );
14883
+ }
14884
+ }
14885
+
14886
+ if ( $add_submenu_items ||
14887
+ ( $is_activation_mode && $this->is_only_premium() && $this->is_admin_page( 'pricing' ) )
14888
+ ) {
14889
+ if ( ! WP_FS__DEMO_MODE ) {
14890
+ $show_pricing = (
14891
+ $this->is_submenu_item_visible( 'pricing' ) &&
14892
+ $this->is_pricing_page_visible()
14893
+ );
14894
+
14895
+ $pricing_cta_text = $this->get_pricing_cta_label();
14896
+ $pricing_class = 'upgrade-mode';
14897
+ if ( $show_pricing ) {
14898
+ if ( $this->is_in_trial_promotion() &&
14899
+ ! $this->is_paying_or_trial()
14900
+ ) {
14901
+ // If running a trial promotion, modify the pricing to load the trial.
14902
+ $pricing_class = 'trial-mode';
14903
+ } else if ( $this->is_paying() ) {
14904
+ $pricing_class = '';
14905
+ }
14906
+ }
14907
+
14908
+ // Add upgrade/pricing page.
14909
+ $this->add_submenu_item(
14910
+ $pricing_cta_text . '&nbsp;&nbsp;' . ( is_rtl() ? $this->get_text_x_inline( '&#x2190;', 'ASCII arrow left icon', 'symbol_arrow-left' ) : $this->get_text_x_inline( '&#x27a4;', 'ASCII arrow right icon', 'symbol_arrow-right' ) ),
14911
+ array( &$this, '_pricing_page_render' ),
14912
+ $this->get_plugin_name() . ' &ndash; ' . $this->get_text_x_inline( 'Pricing', 'noun', 'pricing' ),
14913
+ 'manage_options',
14914
+ 'pricing',
14915
+ 'Freemius::_clean_admin_content_section',
14916
+ WP_FS__LOWEST_PRIORITY,
14917
+ ( $add_submenu_items && $show_pricing ),
14918
+ $pricing_class
14919
+ );
14920
+ }
14921
+ }
14922
+
14923
+ if ( 0 < count( $this->_menu_items ) ) {
14924
+ if ( ! $this->_menu->is_top_level() ) {
14925
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
14926
+
14927
+ // Append submenu items right after the plugin's submenu item.
14928
+ $this->order_sub_submenu_items();
14929
+ } else {
14930
+ // Append submenu items.
14931
+ $this->embed_submenu_items();
14932
+ }
14933
+ }
14934
+ }
14935
+
14936
+ /**
14937
+ * Moved the actual submenu item additions to a separated function,
14938
+ * in order to support sub-submenu items when the plugin's settings
14939
+ * only have a submenu and not top-level menu item.
14940
+ *
14941
+ * @author Vova Feldman (@svovaf)
14942
+ * @since 1.1.4
14943
+ */
14944
+ private function embed_submenu_items() {
14945
+ $item_template = $this->_menu->is_top_level() ?
14946
+ '<span class="fs-submenu-item %s %s %s">%s</span>' :
14947
+ '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
14948
+
14949
+ $top_level_menu_capability = $this->get_top_level_menu_capability();
14950
+
14951
+ ksort( $this->_menu_items );
14952
+
14953
+ $is_first_submenu_item = true;
14954
+
14955
+ foreach ( $this->_menu_items as $priority => $items ) {
14956
+ foreach ( $items as $item ) {
14957
+ if ( $item['show_submenu'] && $is_first_submenu_item ) {
14958
+ if ( $this->_is_network_active && ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
14959
+ $item['menu_slug'] = '';
14960
+
14961
+ $this->_menu->override_menu_item( $item['render_function'] );
14962
+ }
14963
+
14964
+ $is_first_submenu_item = false;
14965
+ }
14966
+
14967
+ $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
14968
+
14969
+ $menu_item = sprintf(
14970
+ $item_template,
14971
+ $this->get_unique_affix(),
14972
+ $item['menu_slug'],
14973
+ ! empty( $item['class'] ) ? $item['class'] : '',
14974
+ $item['menu_title']
14975
+ );
14976
+
14977
+ $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
14978
+
14979
+ if ( ! isset( $item['url'] ) ) {
14980
+ $hook = FS_Admin_Menu_Manager::add_subpage(
14981
+ $item['show_submenu'] ?
14982
+ $this->get_top_level_menu_slug() :
14983
+ null,
14984
+ $item['page_title'],
14985
+ $menu_item,
14986
+ $capability,
14987
+ $menu_slug,
14988
+ $item['render_function']
14989
+ );
14990
+
14991
+ if ( false !== $item['before_render_function'] ) {
14992
+ add_action( "load-$hook", $item['before_render_function'] );
14993
+ }
14994
+ } else {
14995
+ FS_Admin_Menu_Manager::add_subpage(
14996
+ $item['show_submenu'] ?
14997
+ $this->get_top_level_menu_slug() :
14998
+ null,
14999
+ $item['page_title'],
15000
+ $menu_item,
15001
+ $capability,
15002
+ $menu_slug,
15003
+ array( $this, '' )
15004
+ );
15005
+ }
15006
+ }
15007
+ }
15008
+ }
15009
+
15010
+ /**
15011
+ * Re-order the submenu items so all Freemius added new submenu items
15012
+ * are added right after the plugin's settings submenu item.
15013
+ *
15014
+ * @author Vova Feldman (@svovaf)
15015
+ * @since 1.1.4
15016
+ */
15017
+ private function order_sub_submenu_items() {
15018
+ global $submenu;
15019
+
15020
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
15021
+
15022
+ /**
15023
+ * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
15024
+ * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
15025
+ * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
15026
+ * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
15027
+ *
15028
+ * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
15029
+ * of another plugin, only users that have the right role can access its sub-submenus since we will use the
15030
+ * capability needed to access the parent menu as the capability for the submenus that we will add.
15031
+ */
15032
+ if ( empty( $submenu[ $menu_slug ] ) ) {
15033
+ return;
15034
+ }
15035
+
15036
+ $top_level_menu = &$submenu[ $menu_slug ];
15037
+
15038
+ $all_submenu_items_after = array();
15039
+
15040
+ $found_submenu_item = false;
15041
+
15042
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
15043
+ if ( $found_submenu_item ) {
15044
+ // Remove all submenu items after the plugin's submenu item.
15045
+ $all_submenu_items_after[] = $meta;
15046
+ unset( $top_level_menu[ $submenu_id ] );
15047
+ }
15048
+
15049
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
15050
+ // Found the submenu item, put all below.
15051
+ $found_submenu_item = true;
15052
+ continue;
15053
+ }
15054
+ }
15055
+
15056
+ // Embed all plugin's new submenu items.
15057
+ $this->embed_submenu_items();
15058
+
15059
+ // Start with specially high number to make sure it's appended.
15060
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
15061
+ foreach ( $all_submenu_items_after as $meta ) {
15062
+ $top_level_menu[ $i ] = $meta;
15063
+ $i ++;
15064
+ }
15065
+
15066
+ // Sort submenu items.
15067
+ ksort( $top_level_menu );
15068
+ }
15069
+
15070
+ /**
15071
+ * Helper method to return the module's support forum URL.
15072
+ *
15073
+ * @author Vova Feldman (@svovaf)
15074
+ * @since 1.2.2.7
15075
+ *
15076
+ * @return string
15077
+ */
15078
+ function get_support_forum_url() {
15079
+ return $this->apply_filters( 'support_forum_url', "https://wordpress.org/support/{$this->_module_type}/{$this->_slug}" );
15080
+ }
15081
+
15082
+ /**
15083
+ * Displays the Support Forum link when enabled.
15084
+ *
15085
+ * Can be filtered like so:
15086
+ *
15087
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
15088
+ * if ( 'support' === $menu_id ) {
15089
+ * return _fs->is_registered();
15090
+ * }
15091
+ * return $is_visible;
15092
+ * }
15093
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
15094
+ *
15095
+ */
15096
+ function _add_default_submenu_items() {
15097
+ if ( ! $this->is_on() ) {
15098
+ return;
15099
+ }
15100
+
15101
+ if ( ! $this->is_activation_mode() &&
15102
+ ( ( $this->_is_network_active && fs_is_network_admin() ) ||
15103
+ ( ! $this->_is_network_active && is_admin() ) )
15104
+ ) {
15105
+ $this->add_submenu_link_item(
15106
+ $this->apply_filters( 'support_forum_submenu', $this->get_text_inline( 'Support Forum', 'support-forum' ) ),
15107
+ $this->get_support_forum_url(),
15108
+ 'wp-support-forum',
15109
+ null,
15110
+ 50,
15111
+ $this->is_submenu_item_visible( 'support' )
15112
+ );
15113
+ }
15114
+ }
15115
+
15116
+ /**
15117
+ * @author Vova Feldman (@svovaf)
15118
+ * @since 1.0.1
15119
+ *
15120
+ * @param string $menu_title
15121
+ * @param callable $render_function
15122
+ * @param bool|string $page_title
15123
+ * @param string $capability
15124
+ * @param bool|string $menu_slug
15125
+ * @param bool|callable $before_render_function
15126
+ * @param int $priority
15127
+ * @param bool $show_submenu
15128
+ * @param string $class Since 1.2.1.5 can add custom classes to menu items.
15129
+ */
15130
+ function add_submenu_item(
15131
+ $menu_title,
15132
+ $render_function,
15133
+ $page_title = false,
15134
+ $capability = 'manage_options',
15135
+ $menu_slug = false,
15136
+ $before_render_function = false,
15137
+ $priority = WP_FS__DEFAULT_PRIORITY,
15138
+ $show_submenu = true,
15139
+ $class = ''
15140
+ ) {
15141
+ $this->_logger->entrance( 'Title = ' . $menu_title );
15142
+
15143
+ if ( $this->is_addon() ) {
15144
+ $parent_fs = $this->get_parent_instance();
15145
+
15146
+ if ( is_object( $parent_fs ) ) {
15147
+ $parent_fs->add_submenu_item(
15148
+ $menu_title,
15149
+ $render_function,
15150
+ $page_title,
15151
+ $capability,
15152
+ $menu_slug,
15153
+ $before_render_function,
15154
+ $priority,
15155
+ $show_submenu,
15156
+ $class
15157
+ );
15158
+
15159
+ return;
15160
+ }
15161
+ }
15162
+
15163
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
15164
+ $this->_menu_items[ $priority ] = array();
15165
+ }
15166
+
15167
+ $this->_menu_items[ $priority ][] = array(
15168
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
15169
+ 'menu_title' => $menu_title,
15170
+ 'capability' => $capability,
15171
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
15172
+ 'render_function' => $render_function,
15173
+ 'before_render_function' => $before_render_function,
15174
+ 'show_submenu' => $show_submenu,
15175
+ 'class' => $class,
15176
+ );
15177
+ }
15178
+
15179
+ /**
15180
+ * @author Vova Feldman (@svovaf)
15181
+ * @since 1.0.1
15182
+ *
15183
+ * @param string $menu_title
15184
+ * @param string $url
15185
+ * @param bool $menu_slug
15186
+ * @param string $capability
15187
+ * @param int $priority
15188
+ * @param bool $show_submenu
15189
+ */
15190
+ function add_submenu_link_item(
15191
+ $menu_title,
15192
+ $url,
15193
+ $menu_slug = false,
15194
+ $capability = 'read',
15195
+ $priority = WP_FS__DEFAULT_PRIORITY,
15196
+ $show_submenu = true
15197
+ ) {
15198
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
15199
+
15200
+ if ( $this->is_addon() ) {
15201
+ $parent_fs = $this->get_parent_instance();
15202
+
15203
+ if ( is_object( $parent_fs ) ) {
15204
+ $parent_fs->add_submenu_link_item(
15205
+ $menu_title,
15206
+ $url,
15207
+ $menu_slug,
15208
+ $capability,
15209
+ $priority,
15210
+ $show_submenu
15211
+ );
15212
+
15213
+ return;
15214
+ }
15215
+ }
15216
+
15217
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
15218
+ $this->_menu_items[ $priority ] = array();
15219
+ }
15220
+
15221
+ $this->_menu_items[ $priority ][] = array(
15222
+ 'menu_title' => $menu_title,
15223
+ 'capability' => $capability,
15224
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
15225
+ 'url' => $url,
15226
+ 'page_title' => $menu_title,
15227
+ 'render_function' => 'fs_dummy',
15228
+ 'before_render_function' => '',
15229
+ 'show_submenu' => $show_submenu,
15230
+ );
15231
+ }
15232
+
15233
+ #endregion ------------------------------------------------------------------
15234
+
15235
+
15236
+ #--------------------------------------------------------------------------------
15237
+ #region Actions / Hooks / Filters
15238
+ #--------------------------------------------------------------------------------
15239
+
15240
+ /**
15241
+ * @author Vova Feldman (@svovaf)
15242
+ * @since 1.1.7
15243
+ *
15244
+ * @param string $tag
15245
+ *
15246
+ * @return string
15247
+ */
15248
+ public function get_action_tag( $tag ) {
15249
+ return self::get_action_tag_static( $tag, $this->_slug, $this->is_plugin() );
15250
+ }
15251
+
15252
+ /**
15253
+ * @author Vova Feldman (@svovaf)
15254
+ * @since 1.2.1.6
15255
+ *
15256
+ * @param string $tag
15257
+ * @param string $slug
15258
+ * @param bool $is_plugin
15259
+ *
15260
+ * @return string
15261
+ */
15262
+ static function get_action_tag_static( $tag, $slug = '', $is_plugin = true ) {
15263
+ $action = "fs_{$tag}";
15264
+
15265
+ if ( ! empty( $slug ) ) {
15266
+ $action .= '_' . self::get_module_unique_affix( $slug, $is_plugin );
15267
+ }
15268
+
15269
+ return $action;
15270
+ }
15271
+
15272
+ /**
15273
+ * Returns a string that can be used to generate a unique action name,
15274
+ * option name, HTML element ID, or HTML element class.
15275
+ *
15276
+ * @author Leo Fajardo (@leorw)
15277
+ * @since 1.2.2
15278
+ *
15279
+ * @return string
15280
+ */
15281
+ public function get_unique_affix() {
15282
+ return self::get_module_unique_affix( $this->_slug, $this->is_plugin() );
15283
+ }
15284
+
15285
+ /**
15286
+ * Returns a string that can be used to generate a unique action name,
15287
+ * option name, HTML element ID, or HTML element class.
15288
+ *
15289
+ * @author Vova Feldman (@svovaf)
15290
+ * @since 1.2.2.5
15291
+ *
15292
+ * @param string $slug
15293
+ * @param bool $is_plugin
15294
+ *
15295
+ * @return string
15296
+ */
15297
+ static function get_module_unique_affix( $slug, $is_plugin = true ) {
15298
+ $affix = $slug;
15299
+
15300
+ if ( ! $is_plugin ) {
15301
+ $affix .= '-' . WP_FS__MODULE_TYPE_THEME;
15302
+ }
15303
+
15304
+ return $affix;
15305
+ }
15306
+
15307
+ /**
15308
+ * @author Vova Feldman (@svovaf)
15309
+ * @since 1.2.1
15310
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
15311
+ * based on the slug for backward compatibility.
15312
+ *
15313
+ * @param string $tag
15314
+ *
15315
+ * @return string
15316
+ */
15317
+ function get_ajax_action( $tag ) {
15318
+ return self::get_ajax_action_static( $tag, $this->_module_id );
15319
+ }
15320
+
15321
+ /**
15322
+ * @author Vova Feldman (@svovaf)
15323
+ * @since 1.2.1.7
15324
+ *
15325
+ * @param string $tag
15326
+ *
15327
+ * @return string
15328
+ */
15329
+ function get_ajax_security( $tag ) {
15330
+ return wp_create_nonce( $this->get_ajax_action( $tag ) );
15331
+ }
15332
+
15333
+ /**
15334
+ * @author Vova Feldman (@svovaf)
15335
+ * @since 1.2.1.7
15336
+ *
15337
+ * @param string $tag
15338
+ */
15339
+ function check_ajax_referer( $tag ) {
15340
+ check_ajax_referer( $this->get_ajax_action( $tag ), 'security' );
15341
+ }
15342
+
15343
+ /**
15344
+ * @author Vova Feldman (@svovaf)
15345
+ * @since 1.2.1.6
15346
+ * @since 1.2.2.5 The AJAX action names are based on the module ID, not like the non-AJAX actions that are
15347
+ * based on the slug for backward compatibility.
15348
+ *
15349
+ * @param string $tag
15350
+ * @param number|null $module_id
15351
+ *
15352
+ * @return string
15353
+ */
15354
+ private static function get_ajax_action_static( $tag, $module_id = null ) {
15355
+ $action = "fs_{$tag}";
15356
+
15357
+ if ( ! empty( $module_id ) ) {
15358
+ $action .= "_{$module_id}";
15359
+ }
15360
+
15361
+ return $action;
15362
+ }
15363
+
15364
+ /**
15365
+ * Do action, specific for the current context plugin.
15366
+ *
15367
+ * @author Vova Feldman (@svovaf)
15368
+ * @since 1.0.1
15369
+ *
15370
+ * @param string $tag The name of the action to be executed.
15371
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
15372
+ * functions hooked to the action. Default empty.
15373
+ *
15374
+ * @uses do_action()
15375
+ */
15376
+ function do_action( $tag, $arg = '' ) {
15377
+ $this->_logger->entrance( $tag );
15378
+
15379
+ $args = func_get_args();
15380
+
15381
+ call_user_func_array( 'do_action', array_merge(
15382
+ array( $this->get_action_tag( $tag ) ),
15383
+ array_slice( $args, 1 ) )
15384
+ );
15385
+ }
15386
+
15387
+ /**
15388
+ * Add action, specific for the current context plugin.
15389
+ *
15390
+ * @author Vova Feldman (@svovaf)
15391
+ * @since 1.0.1
15392
+ *
15393
+ * @param string $tag
15394
+ * @param callable $function_to_add
15395
+ * @param int $priority
15396
+ * @param int $accepted_args
15397
+ *
15398
+ * @uses add_action()
15399
+ */
15400
+ function add_action(
15401
+ $tag,
15402
+ $function_to_add,
15403
+ $priority = WP_FS__DEFAULT_PRIORITY,
15404
+ $accepted_args = 1
15405
+ ) {
15406
+ $this->_logger->entrance( $tag );
15407
+
15408
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
15409
+ }
15410
+
15411
+ /**
15412
+ * Add AJAX action, specific for the current context plugin.
15413
+ *
15414
+ * @author Vova Feldman (@svovaf)
15415
+ * @since 1.2.1
15416
+ *
15417
+ * @param string $tag
15418
+ * @param callable $function_to_add
15419
+ * @param int $priority
15420
+ *
15421
+ * @uses add_action()
15422
+ *
15423
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
15424
+ */
15425
+ function add_ajax_action(
15426
+ $tag,
15427
+ $function_to_add,
15428
+ $priority = WP_FS__DEFAULT_PRIORITY
15429
+ ) {
15430
+ $this->_logger->entrance( $tag );
15431
+
15432
+ return self::add_ajax_action_static(
15433
+ $tag,
15434
+ $function_to_add,
15435
+ $priority,
15436
+ $this->_module_id
15437
+ );
15438
+ }
15439
+
15440
+ /**
15441
+ * Add AJAX action.
15442
+ *
15443
+ * @author Vova Feldman (@svovaf)
15444
+ * @since 1.2.1.6
15445
+ *
15446
+ * @param string $tag
15447
+ * @param callable $function_to_add
15448
+ * @param int $priority
15449
+ * @param number|null $module_id
15450
+ *
15451
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
15452
+ * @uses add_action()
15453
+ *
15454
+ */
15455
+ static function add_ajax_action_static(
15456
+ $tag,
15457
+ $function_to_add,
15458
+ $priority = WP_FS__DEFAULT_PRIORITY,
15459
+ $module_id = null
15460
+ ) {
15461
+ self::$_static_logger->entrance( $tag );
15462
+
15463
+ if ( ! self::is_ajax_action_static( $tag, $module_id ) ) {
15464
+ return false;
15465
+ }
15466
+
15467
+ add_action(
15468
+ 'wp_ajax_' . self::get_ajax_action_static( $tag, $module_id ),
15469
+ $function_to_add,
15470
+ $priority,
15471
+ 0
15472
+ );
15473
+
15474
+ self::$_static_logger->info( "$tag AJAX callback action added." );
15475
+
15476
+ return true;
15477
+ }
15478
+
15479
+ /**
15480
+ * Send a JSON response back to an Ajax request.
15481
+ *
15482
+ * @author Vova Feldman (@svovaf)
15483
+ * @since 1.2.1.5
15484
+ *
15485
+ * @param mixed $response
15486
+ */
15487
+ static function shoot_ajax_response( $response ) {
15488
+ wp_send_json( $response );
15489
+ }
15490
+
15491
+ /**
15492
+ * Send a JSON response back to an Ajax request, indicating success.
15493
+ *
15494
+ * @author Vova Feldman (@svovaf)
15495
+ * @since 1.2.1.5
15496
+ *
15497
+ * @param mixed $data Data to encode as JSON, then print and exit.
15498
+ */
15499
+ static function shoot_ajax_success( $data = null ) {
15500
+ wp_send_json_success( $data );
15501
+ }
15502
+
15503
+ /**
15504
+ * Send a JSON response back to an Ajax request, indicating failure.
15505
+ *
15506
+ * @author Vova Feldman (@svovaf)
15507
+ * @since 1.2.1.5
15508
+ *
15509
+ * @param mixed $error Optional error message.
15510
+ */
15511
+ static function shoot_ajax_failure( $error = '' ) {
15512
+ $result = array( 'success' => false );
15513
+ if ( ! empty( $error ) ) {
15514
+ $result['error'] = $error;
15515
+ }
15516
+
15517
+ wp_send_json( $result );
15518
+ }
15519
+
15520
+ /**
15521
+ * Apply filter, specific for the current context plugin.
15522
+ *
15523
+ * @author Vova Feldman (@svovaf)
15524
+ * @since 1.0.9
15525
+ *
15526
+ * @param string $tag The name of the filter hook.
15527
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
15528
+ *
15529
+ * @return mixed The filtered value after all hooked functions are applied to it.
15530
+ *
15531
+ * @uses apply_filters()
15532
+ */
15533
+ function apply_filters( $tag, $value ) {
15534
+ $this->_logger->entrance( $tag );
15535
+
15536
+ $args = func_get_args();
15537
+ array_unshift( $args, $this->get_unique_affix() );
15538
+
15539
+ return call_user_func_array( 'fs_apply_filter', $args );
15540
+ }
15541
+
15542
+ /**
15543
+ * Add filter, specific for the current context plugin.
15544
+ *
15545
+ * @author Vova Feldman (@svovaf)
15546
+ * @since 1.0.9
15547
+ *
15548
+ * @param string $tag
15549
+ * @param callable $function_to_add
15550
+ * @param int $priority
15551
+ * @param int $accepted_args
15552
+ *
15553
+ * @uses add_filter()
15554
+ */
15555
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
15556
+ $this->_logger->entrance( $tag );
15557
+
15558
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
15559
+ }
15560
+
15561
+ /**
15562
+ * Check if has filter.
15563
+ *
15564
+ * @author Vova Feldman (@svovaf)
15565
+ * @since 1.1.4
15566
+ *
15567
+ * @param string $tag
15568
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
15569
+ *
15570
+ * @return false|int
15571
+ *
15572
+ * @uses has_filter()
15573
+ */
15574
+ function has_filter( $tag, $function_to_check = false ) {
15575
+ $this->_logger->entrance( $tag );
15576
+
15577
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
15578
+ }
15579
+
15580
+ #endregion
15581
+
15582
+ /**
15583
+ * Override default i18n text phrases.
15584
+ *
15585
+ * @author Vova Feldman (@svovaf)
15586
+ * @since 1.1.6
15587
+ *
15588
+ * @param string[] string $key_value
15589
+ *
15590
+ * @uses fs_override_i18n()
15591
+ */
15592
+ function override_i18n( $key_value ) {
15593
+ fs_override_i18n( $key_value, $this->_slug );
15594
+ }
15595
+
15596
+ /* Account Page
15597
+ ------------------------------------------------------------------------------------------------------------------*/
15598
+ /**
15599
+ * Update site information.
15600
+ *
15601
+ * @author Vova Feldman (@svovaf)
15602
+ * @since 1.0.1
15603
+ *
15604
+ * @param bool $store Flush to Database if true.
15605
+ * @param null|int $network_level_or_blog_id Since 2.0.0
15606
+ * @param \FS_Site $site Since 2.0.0
15607
+ */
15608
+ private function _store_site( $store = true, $network_level_or_blog_id = null, FS_Site $site = null ) {
15609
+ $this->_logger->entrance();
15610
+
15611
+ if ( empty( $this->_site->id ) ) {
15612
+ $this->_logger->error( "Empty install ID, can't store site." );
15613
+
15614
+ return;
15615
+ }
15616
+
15617
+ $site_clone = is_object( $site ) ? $site : $this->_site;
15618
+ $encrypted_site = clone $site_clone;
15619
+
15620
+ $sites = self::get_all_sites( $this->_module_type, $network_level_or_blog_id );
15621
+
15622
+ $prev_stored_user_id = $this->_storage->get( 'prev_user_id', false, $network_level_or_blog_id );
15623
+
15624
+ if ( empty( $prev_stored_user_id ) &&
15625
+ $this->_user->id != $this->_site->user_id
15626
+ ) {
15627
+ /**
15628
+ * Store the current user ID as the previous user ID so that the previous user can be used
15629
+ * as the install's owner while the new owner's details are not yet available.
15630
+ *
15631
+ * This will be executed only in the `replica` site. For example, there are 2 sites, namely `original`
15632
+ * and `replica`, then an ownership change was initiated and completed in the `original`, the `replica`
15633
+ * will be using the previous user until it is updated again (e.g.: until the next clone of `original`
15634
+ * into `replica`.
15635
+ *
15636
+ * @author Leo Fajardo (@leorw)
15637
+ */
15638
+ $this->_storage->store( 'prev_user_id', $sites[ $this->_slug ]->user_id, $network_level_or_blog_id );
15639
+ }
15640
+
15641
+ $sites[ $this->_slug ] = $encrypted_site;
15642
+
15643
+ $this->set_account_option( 'sites', $sites, $store, $network_level_or_blog_id );
15644
+ }
15645
+
15646
+ /**
15647
+ * Update plugin's plans information.
15648
+ *
15649
+ * @author Vova Feldman (@svovaf)
15650
+ * @since 1.0.2
15651
+ *
15652
+ * @param bool $store Flush to Database if true.
15653
+ */
15654
+ private function _store_plans( $store = true ) {
15655
+ $this->_logger->entrance();
15656
+
15657
+ $plans = self::get_all_plans( $this->_module_type );
15658
+
15659
+ // Copy plans.
15660
+ $encrypted_plans = array();
15661
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
15662
+ $encrypted_plans[] = self::_encrypt_entity( $this->_plans[ $i ] );
15663
+ }
15664
+
15665
+ $plans[ $this->_slug ] = $encrypted_plans;
15666
+
15667
+ $this->set_account_option( 'plans', $plans, $store );
15668
+ }
15669
+
15670
+ /**
15671
+ * Update user's plugin licenses.
15672
+ *
15673
+ * @author Vova Feldman (@svovaf)
15674
+ * @since 1.0.5
15675
+ *
15676
+ * @param bool $store
15677
+ * @param number|bool $module_id
15678
+ * @param FS_Plugin_License[] $licenses
15679
+ */
15680
+ private function _store_licenses( $store = true, $module_id = false, $licenses = array() ) {
15681
+ $this->_logger->entrance();
15682
+
15683
+ $all_licenses = self::get_all_licenses();
15684
+
15685
+ if ( ! FS_Plugin::is_valid_id( $module_id ) ) {
15686
+ $module_id = $this->_module_id;
15687
+
15688
+ $user_licenses = is_array( $this->_licenses ) ?
15689
+ $this->_licenses :
15690
+ array();
15691
+
15692
+ if ( empty( $user_licenses ) ) {
15693
+ // If the context user doesn't have any license, don't update the licenses collection.
15694
+ return;
15695
+ }
15696
+
15697
+ $new_user_licenses_map = array();
15698
+ foreach ( $user_licenses as $user_license ) {
15699
+ $new_user_licenses_map[ $user_license->id ] = $user_license;
15700
+ }
15701
+
15702
+ self::store_user_id_license_ids_map( array_keys( $new_user_licenses_map ), $this->_module_id, $this->_user->id );
15703
+
15704
+ // Update user licenses.
15705
+ $licenses_to_update_count = count( $new_user_licenses_map );
15706
+ foreach ( $all_licenses[ $module_id ] as $key => $license ) {
15707
+ if ( 0 === $licenses_to_update_count ) {
15708
+ break;
15709
+ }
15710
+
15711
+ if ( isset( $new_user_licenses_map[ $license->id ] ) ) {
15712
+ // Update license.
15713
+ $all_licenses[ $module_id ][ $key ] = $new_user_licenses_map[ $license->id ];
15714
+ unset( $new_user_licenses_map[ $license->id ] );
15715
+
15716
+ $licenses_to_update_count --;
15717
+ }
15718
+ }
15719
+
15720
+ if ( ! empty( $new_user_licenses_map ) ) {
15721
+ // Add new licenses.
15722
+ $all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
15723
+ }
15724
+
15725
+ $licenses = $all_licenses[ $module_id ];
15726
+ }
15727
+
15728
+ if ( ! isset( $all_licenses[ $module_id ] ) ) {
15729
+ $all_licenses[ $module_id ] = array();
15730
+ }
15731
+
15732
+ $all_licenses[ $module_id ] = $licenses;
15733
+
15734
+ self::$_accounts->set_option( 'all_licenses', $all_licenses, $store );
15735
+ }
15736
+
15737
+ /**
15738
+ * Update user information.
15739
+ *
15740
+ * @author Vova Feldman (@svovaf)
15741
+ * @since 1.0.1
15742
+ *
15743
+ * @param bool $store Flush to Database if true.
15744
+ */
15745
+ private function _store_user( $store = true ) {
15746
+ $this->_logger->entrance();
15747
+
15748
+ if ( empty( $this->_user->id ) ) {
15749
+ $this->_logger->error( "Empty user ID, can't store user." );
15750
+
15751
+ return;
15752
+ }
15753
+
15754
+ $users = self::get_all_users();
15755
+ $users[ $this->_user->id ] = $this->_user;
15756
+ self::$_accounts->set_option( 'users', $users, $store );
15757
+ }
15758
+
15759
+ /**
15760
+ * Update new updates information.
15761
+ *
15762
+ * @author Vova Feldman (@svovaf)
15763
+ * @since 1.0.4
15764
+ *
15765
+ * @param FS_Plugin_Tag|null $update
15766
+ * @param bool $store Flush to Database if true.
15767
+ * @param bool|number $plugin_id
15768
+ */
15769
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
15770
+ $this->_logger->entrance();
15771
+
15772
+ if ( $update instanceof FS_Plugin_Tag ) {
15773
+ $update->updated = time();
15774
+ }
15775
+
15776
+ if ( ! is_numeric( $plugin_id ) ) {
15777
+ $plugin_id = $this->_plugin->id;
15778
+ }
15779
+
15780
+ $updates = self::get_all_updates();
15781
+ $updates[ $plugin_id ] = $update;
15782
+ self::$_accounts->set_option( 'updates', $updates, $store );
15783
+ }
15784
+
15785
+ /**
15786
+ * Update new updates information.
15787
+ *
15788
+ * @author Vova Feldman (@svovaf)
15789
+ * @since 1.0.6
15790
+ *
15791
+ * @param FS_Plugin[] $plugin_addons
15792
+ * @param bool $store Flush to Database if true.
15793
+ */
15794
+ private function _store_addons( $plugin_addons, $store = true ) {
15795
+ $this->_logger->entrance();
15796
+
15797
+ $addons = self::get_all_addons();
15798
+ $addons[ $this->_plugin->id ] = $plugin_addons;
15799
+ self::$_accounts->set_option( 'addons', $addons, $store );
15800
+ }
15801
+
15802
+ /**
15803
+ * Delete plugin's associated add-ons.
15804
+ *
15805
+ * @author Vova Feldman (@svovaf)
15806
+ * @since 1.0.8
15807
+ *
15808
+ * @param bool $store
15809
+ *
15810
+ * @return bool
15811
+ */
15812
+ private function _delete_account_addons( $store = true ) {
15813
+ $all_addons = self::get_all_account_addons();
15814
+
15815
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
15816
+ return false;
15817
+ }
15818
+
15819
+ unset( $all_addons[ $this->_plugin->id ] );
15820
+
15821
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
15822
+
15823
+ return true;
15824
+ }
15825
+
15826
+ /**
15827
+ * Update account add-ons list.
15828
+ *
15829
+ * @author Vova Feldman (@svovaf)
15830
+ * @since 1.0.6
15831
+ *
15832
+ * @param FS_Plugin[] $addons
15833
+ * @param bool $store Flush to Database if true.
15834
+ */
15835
+ private function _store_account_addons( $addons, $store = true ) {
15836
+ $this->_logger->entrance();
15837
+
15838
+ $all_addons = self::get_all_account_addons();
15839
+ $all_addons[ $this->_plugin->id ] = $addons;
15840
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
15841
+ }
15842
+
15843
+ /**
15844
+ * Store account params in the Database.
15845
+ *
15846
+ * @author Vova Feldman (@svovaf)
15847
+ * @since 1.0.1
15848
+ *
15849
+ * @param null|int $blog_id Since 2.0.0
15850
+ */
15851
+ private function _store_account( $blog_id = null ) {
15852
+ $this->_logger->entrance();
15853
+
15854
+ $this->_store_site( false, $blog_id );
15855
+ $this->_store_user( false );
15856
+ $this->_store_plans( false );
15857
+ $this->_store_licenses( false );
15858
+
15859
+ self::$_accounts->store( $blog_id );
15860
+ }
15861
+
15862
+ /**
15863
+ * Sync user's information.
15864
+ *
15865
+ * @author Vova Feldman (@svovaf)
15866
+ * @since 1.0.3
15867
+ * @uses FS_Api
15868
+ */
15869
+ private function _handle_account_user_sync() {
15870
+ $this->_logger->entrance();
15871
+
15872
+ $api = $this->get_api_user_scope();
15873
+
15874
+ // Get user's information.
15875
+ $user = $api->get( '/', true );
15876
+
15877
+ if ( isset( $user->id ) ) {
15878
+ $this->_user->first = $user->first;
15879
+ $this->_user->last = $user->last;
15880
+ $this->_user->email = $user->email;
15881
+
15882
+ $is_menu_item_account_visible = $this->is_submenu_item_visible( 'account' );
15883
+
15884
+ if ( $user->is_verified &&
15885
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
15886
+ ) {
15887
+ $this->_user->is_verified = true;
15888
+
15889
+ $this->do_action( 'account_email_verified', $user->email );
15890
+
15891
+ $this->_admin_notices->add(
15892
+ $this->get_text_inline( 'Your email has been successfully verified - you are AWESOME!', 'email-verified-message' ),
15893
+ $this->get_text_x_inline( 'Right on', 'a positive response', 'right-on' ) . '!',
15894
+ 'success',
15895
+ // Make admin sticky if account menu item is invisible,
15896
+ // since the page will be auto redirected to the plugin's
15897
+ // main settings page, and the non-sticky message
15898
+ // will disappear.
15899
+ ! $is_menu_item_account_visible,
15900
+ 'email_verified'
15901
+ );
15902
+ }
15903
+
15904
+ // Flush user details to DB.
15905
+ $this->_store_user();
15906
+
15907
+ $this->do_action( 'after_account_user_sync', $user );
15908
+
15909
+ /**
15910
+ * If account menu item is hidden, redirect to plugin's main settings page.
15911
+ *
15912
+ * @author Vova Feldman (@svovaf)
15913
+ * @since 1.1.6
15914
+ *
15915
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
15916
+ */
15917
+ if ( ! $is_menu_item_account_visible ) {
15918
+ fs_redirect( $this->_get_admin_page_url() );
15919
+ }
15920
+ }
15921
+ }
15922
+
15923
+ /**
15924
+ * @author Vova Feldman (@svovaf)
15925
+ * @since 1.0.9
15926
+ * @uses FS_Api
15927
+ *
15928
+ * @param number|bool $license_id
15929
+ *
15930
+ * @return FS_Subscription|object|bool
15931
+ */
15932
+ private function _fetch_site_license_subscription( $license_id = false ) {
15933
+ $this->_logger->entrance();
15934
+ $api = $this->get_api_site_scope();
15935
+
15936
+ if ( ! is_numeric( $license_id ) ) {
15937
+ $license_id = $this->_license->id;
15938
+ }
15939
+
15940
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
15941
+
15942
+ return ! isset( $result->error ) ?
15943
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
15944
+ new FS_Subscription( $result->subscriptions[0] ) :
15945
+ false
15946
+ ) :
15947
+ $result;
15948
+ }
15949
+
15950
+ /**
15951
+ * @author Vova Feldman (@svovaf)
15952
+ * @since 1.0.4
15953
+ * @uses FS_Api
15954
+ *
15955
+ * @param number|bool $plan_id
15956
+ *
15957
+ * @return FS_Plugin_Plan|object
15958
+ */
15959
+ private function _fetch_site_plan( $plan_id = false ) {
15960
+ $this->_logger->entrance();
15961
+ $api = $this->get_api_site_scope();
15962
+
15963
+ if ( ! is_numeric( $plan_id ) ) {
15964
+ $plan_id = $this->_site->plan_id;
15965
+ }
15966
+
15967
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
15968
+
15969
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
15970
+ }
15971
+
15972
+ /**
15973
+ * @author Vova Feldman (@svovaf)
15974
+ * @since 1.0.5
15975
+ * @uses FS_Api
15976
+ *
15977
+ * @return FS_Plugin_Plan[]|object
15978
+ */
15979
+ private function _fetch_plugin_plans() {
15980
+ $this->_logger->entrance();
15981
+ $api = $this->get_current_or_network_user_api_scope();
15982
+
15983
+ /**
15984
+ * @since 1.2.3 When running in DEV mode, retrieve pending plans as well.
15985
+ */
15986
+ $result = $api->get( $this->add_show_pending( "/plugins/{$this->_module_id}/plans.json" ), true );
15987
+
15988
+ if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
15989
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
15990
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
15991
+ }
15992
+
15993
+ $result = $result->plans;
15994
+ }
15995
+
15996
+ return $result;
15997
+ }
15998
+
15999
+ /**
16000
+ * @author Vova Feldman (@svovaf)
16001
+ * @since 2.0.0
16002
+ *
16003
+ * @param number $plan_id
16004
+ *
16005
+ * @return \FS_Plugin_Plan|object
16006
+ */
16007
+ private function fetch_plan_by_id( $plan_id ) {
16008
+ $this->_logger->entrance();
16009
+ $api = $this->get_current_or_network_user_api_scope();
16010
+
16011
+ $result = $api->get( "/plugins/{$this->_module_id}/plans/{$plan_id}.json", true );
16012
+
16013
+ return $this->is_api_result_entity( $result ) ?
16014
+ new FS_Plugin_Plan( $result ) :
16015
+ $result;
16016
+ }
16017
+
16018
+ /**
16019
+ * @author Vova Feldman (@svovaf)
16020
+ * @since 1.0.5
16021
+ * @uses FS_Api
16022
+ *
16023
+ * @param number|bool $plugin_id
16024
+ * @param number|bool $site_license_id
16025
+ * @param array $foreign_licenses @since 2.0.0. This is used by network-activated plugins.
16026
+ * @param number|null $blog_id
16027
+ *
16028
+ * @return FS_Plugin_License[]|object
16029
+ */
16030
+ private function _fetch_licenses(
16031
+ $plugin_id = false,
16032
+ $site_license_id = false,
16033
+ $foreign_licenses = array(),
16034
+ $blog_id = null
16035
+ ) {
16036
+ $this->_logger->entrance();
16037
+
16038
+ $api = $this->get_api_user_scope();
16039
+
16040
+ if ( ! is_numeric( $plugin_id ) ) {
16041
+ $plugin_id = $this->_plugin->id;
16042
+ }
16043
+
16044
+ $user_licenses_endpoint = "/plugins/{$plugin_id}/licenses.json";
16045
+ if ( ! empty ( $foreign_licenses ) ) {
16046
+ $foreign_licenses = array(
16047
+ // Prefix with `+` to tell the server to include foreign licenses in the licenses collection.
16048
+ 'ids' => ( urlencode( '+' ) . implode( ',', $foreign_licenses['ids'] ) ),
16049
+ 'license_keys' => implode( ',', array_map( 'urlencode', $foreign_licenses['license_keys'] ) )
16050
+ );
16051
+
16052
+ $user_licenses_endpoint = add_query_arg( $foreign_licenses, $user_licenses_endpoint );
16053
+ }
16054
+
16055
+ $result = $api->get( $user_licenses_endpoint, true );
16056
+
16057
+ $is_site_license_synced = false;
16058
+
16059
+ $api_errors = array();
16060
+
16061
+ if ( $this->is_api_result_object( $result, 'licenses' ) &&
16062
+ is_array( $result->licenses )
16063
+ ) {
16064
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
16065
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
16066
+
16067
+ if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
16068
+ $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
16069
+ }
16070
+ }
16071
+
16072
+ $result = $result->licenses;
16073
+ } else {
16074
+ $api_errors[] = $result;
16075
+ $result = array();
16076
+ }
16077
+
16078
+ if ( ! $is_site_license_synced ) {
16079
+ if ( ! is_null( $blog_id ) ) {
16080
+ /**
16081
+ * If blog ID is not null, the request is for syncing of the license of a single site via the
16082
+ * network-level "Account" page.
16083
+ *
16084
+ * @author Leo Fajardo (@leorw)
16085
+ */
16086
+ $this->switch_to_blog( $blog_id );
16087
+ }
16088
+
16089
+ $api = $this->get_api_site_scope();
16090
+
16091
+ if ( is_numeric( $site_license_id ) ) {
16092
+ // Try to retrieve a foreign license that is linked to the install.
16093
+ $api_result = $api->call( '/licenses.json' );
16094
+
16095
+ if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
16096
+ is_array( $api_result->licenses )
16097
+ ) {
16098
+ $licenses = $api_result->licenses;
16099
+
16100
+ if ( ! empty( $licenses ) ) {
16101
+ $result[] = new FS_Plugin_License( $licenses[0] );
16102
+ }
16103
+ } else {
16104
+ $api_errors[] = $api_result;
16105
+ }
16106
+ } else if ( is_object( $this->_license ) ) {
16107
+ $is_license_in_result = false;
16108
+ if ( ! empty( $result ) ) {
16109
+ foreach ( $result as $license ) {
16110
+ if ( $license->id == $this->_license->id ) {
16111
+ $is_license_in_result = true;
16112
+ break;
16113
+ }
16114
+ }
16115
+ }
16116
+
16117
+ if ( ! $is_license_in_result ) {
16118
+ // Fetch foreign license by ID and license key.
16119
+ $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
16120
+ urlencode( $this->_license->secret_key ) );
16121
+
16122
+ if ( $this->is_api_result_entity( $license ) ) {
16123
+ $result[] = new FS_Plugin_License( $license );
16124
+ } else {
16125
+ $api_errors[] = $license;
16126
+ }
16127
+ }
16128
+ }
16129
+
16130
+ if ( ! is_null( $blog_id ) ) {
16131
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
16132
+ }
16133
+ }
16134
+
16135
+ if ( is_array( $result ) && 0 < count( $result ) ) {
16136
+ // If found at least one license, return license collection even if there are errors.
16137
+ return $result;
16138
+ }
16139
+
16140
+ if ( ! empty( $api_errors ) ) {
16141
+ // If found any errors and no licenses, return first error.
16142
+ return $api_errors[0];
16143
+ }
16144
+
16145
+ // Fallback to empty licenses list.
16146
+ return $result;
16147
+ }
16148
+
16149
+ /**
16150
+ * @author Vova Feldman (@svovaf)
16151
+ * @since 2.0.0
16152
+ *
16153
+ * @param number $license_id
16154
+ * @param string $license_key
16155
+ *
16156
+ * @return \FS_Plugin_License|object
16157
+ */
16158
+ private function fetch_license_by_key( $license_id, $license_key ) {
16159
+ $this->_logger->entrance();
16160
+
16161
+ $api = $this->get_current_or_network_user_api_scope();
16162
+
16163
+ $result = $api->get( "/licenses/{$license_id}.json?license_key=" . urlencode( $license_key ) );
16164
+
16165
+ return $this->is_api_result_entity( $result ) ?
16166
+ new FS_Plugin_License( $result ) :
16167
+ $result;
16168
+ }
16169
+
16170
+ /**
16171
+ * @author Vova Feldman (@svovaf)
16172
+ * @since 1.2.0
16173
+ * @uses FS_Api
16174
+ *
16175
+ * @param number|bool $plugin_id
16176
+ * @param bool $flush
16177
+ *
16178
+ * @return FS_Payment[]|object
16179
+ */
16180
+ function _fetch_payments( $plugin_id = false, $flush = false ) {
16181
+ $this->_logger->entrance();
16182
+
16183
+ $api = $this->get_api_user_scope();
16184
+
16185
+ if ( ! is_numeric( $plugin_id ) ) {
16186
+ $plugin_id = $this->_plugin->id;
16187
+ }
16188
+
16189
+ $result = $api->get( "/plugins/{$plugin_id}/payments.json?include_addons=true", $flush );
16190
+
16191
+ if ( ! isset( $result->error ) ) {
16192
+ for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
16193
+ $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
16194
+ }
16195
+ $result = $result->payments;
16196
+ }
16197
+
16198
+ return $result;
16199
+ }
16200
+
16201
+ /**
16202
+ * @author Vova Feldman (@svovaf)
16203
+ * @since 1.2.1.5
16204
+ * @uses FS_Api
16205
+ *
16206
+ * @param bool $flush
16207
+ *
16208
+ * @return \FS_Billing|mixed
16209
+ */
16210
+ function _fetch_billing( $flush = false ) {
16211
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
16212
+
16213
+ $billing = $this->get_api_user_scope()->get( 'billing.json', $flush );
16214
+
16215
+ if ( $this->is_api_result_entity( $billing ) ) {
16216
+ $billing = new FS_Billing( $billing );
16217
+ }
16218
+
16219
+ return $billing;
16220
+ }
16221
+
16222
+ /**
16223
+ * @author Vova Feldman (@svovaf)
16224
+ * @since 1.0.5
16225
+ *
16226
+ * @param FS_Plugin_License[] $licenses
16227
+ * @param number $module_id
16228
+ */
16229
+ private function _update_licenses( $licenses, $module_id ) {
16230
+ $this->_logger->entrance();
16231
+
16232
+ if ( is_array( $licenses ) ) {
16233
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
16234
+ $licenses[ $i ]->updated = time();
16235
+ }
16236
+ }
16237
+
16238
+ $this->_store_licenses( true, $module_id, $licenses );
16239
+ }
16240
+
16241
+ /**
16242
+ * @author Vova Feldman (@svovaf)
16243
+ * @since 1.0.4
16244
+ *
16245
+ * @param bool|number $plugin_id
16246
+ * @param bool $flush Since 1.1.7.3
16247
+ * @param int $expiration Since 1.2.2.7
16248
+ *
16249
+ * @return object|false New plugin tag info if exist.
16250
+ */
16251
+ private function _fetch_newer_version( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
16252
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush, $expiration );
16253
+
16254
+ if ( ! is_object( $latest_tag ) ) {
16255
+ return false;
16256
+ }
16257
+
16258
+ // Check if version is actually newer.
16259
+ $has_new_version =
16260
+ // If it's an non-installed add-on then always return latest.
16261
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
16262
+ // Compare versions.
16263
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
16264
+
16265
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
16266
+
16267
+ return $has_new_version ? $latest_tag : false;
16268
+ }
16269
+
16270
+ /**
16271
+ * @author Vova Feldman (@svovaf)
16272
+ * @since 1.0.5
16273
+ *
16274
+ * @param bool|number $plugin_id
16275
+ * @param bool $flush Since 1.1.7.3
16276
+ * @param int $expiration Since 1.2.2.7
16277
+ *
16278
+ * @return bool|FS_Plugin_Tag
16279
+ */
16280
+ function get_update( $plugin_id = false, $flush = true, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
16281
+ $this->_logger->entrance();
16282
+
16283
+ if ( ! is_numeric( $plugin_id ) ) {
16284
+ $plugin_id = $this->_plugin->id;
16285
+ }
16286
+
16287
+ $this->check_updates( true, $plugin_id, $flush, $expiration );
16288
+ $updates = $this->get_all_updates();
16289
+
16290
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
16291
+ }
16292
+
16293
+ /**
16294
+ * Check if site assigned with active license.
16295
+ *
16296
+ * @author Vova Feldman (@svovaf)
16297
+ * @since 1.0.6
16298
+ *
16299
+ * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
16300
+ */
16301
+ function has_active_license() {
16302
+ return (
16303
+ is_object( $this->_license ) &&
16304
+ is_numeric( $this->_license->id ) &&
16305
+ ! $this->_license->is_expired()
16306
+ );
16307
+ }
16308
+
16309
+ /**
16310
+ * Check if site assigned with active & valid (not expired) license.
16311
+ *
16312
+ * @author Vova Feldman (@svovaf)
16313
+ * @since 1.2.1
16314
+ */
16315
+ function has_active_valid_license() {
16316
+ return self::is_active_valid_license( $this->_license );
16317
+ }
16318
+
16319
+ /**
16320
+ * Check if a given license is active & valid (not expired).
16321
+ *
16322
+ * @author Vova Feldman (@svovaf)
16323
+ * @since 2.1.3
16324
+ *
16325
+ * @param FS_Plugin_License $license
16326
+ *
16327
+ * @return bool
16328
+ */
16329
+ private static function is_active_valid_license( $license ) {
16330
+ return (
16331
+ is_object( $license ) &&
16332
+ FS_Plugin_License::is_valid_id( $license->id ) &&
16333
+ $license->is_active() &&
16334
+ $license->is_valid()
16335
+ );
16336
+ }
16337
+
16338
+ /**
16339
+ * Checks if there's any site that is associated with an active & valid license.
16340
+ * This logic is used to determine if the admin can download the premium code base from a network level admin.
16341
+ *
16342
+ * @author Vova Feldman (@svovaf)
16343
+ * @since 2.1.3
16344
+ *
16345
+ * @return bool
16346
+ */
16347
+ function has_any_active_valid_license() {
16348
+ if ( ! fs_is_network_admin() ) {
16349
+ return $this->has_active_valid_license();
16350
+ }
16351
+
16352
+ $installs = $this->get_blog_install_map();
16353
+ $all_plugin_licenses = self::get_all_licenses( $this->_module_id );
16354
+
16355
+ foreach ( $installs as $blog_id => $install ) {
16356
+ if ( ! FS_Plugin_License::is_valid_id( $install->license_id ) ) {
16357
+ continue;
16358
+ }
16359
+
16360
+ foreach ( $all_plugin_licenses as $license ) {
16361
+ if ( $license->id == $install->license_id ) {
16362
+ if ( self::is_active_valid_license( $license ) ) {
16363
+ return true;
16364
+ }
16365
+ }
16366
+ }
16367
+ }
16368
+
16369
+ return false;
16370
+ }
16371
+
16372
+ /**
16373
+ * Check if site assigned with license with enabled features.
16374
+ *
16375
+ * @author Vova Feldman (@svovaf)
16376
+ * @since 1.0.6
16377
+ *
16378
+ * @return bool
16379
+ */
16380
+ function has_features_enabled_license() {
16381
+ return (
16382
+ is_object( $this->_license ) &&
16383
+ is_numeric( $this->_license->id ) &&
16384
+ $this->_license->is_features_enabled()
16385
+ );
16386
+ }
16387
+
16388
+ /**
16389
+ * Check if user is a trial or have feature enabled license.
16390
+ *
16391
+ * @author Vova Feldman (@svovaf)
16392
+ * @since 1.1.7
16393
+ *
16394
+ * @return bool
16395
+ */
16396
+ function can_use_premium_code() {
16397
+ return $this->is_trial() || $this->has_features_enabled_license();
16398
+ }
16399
+
16400
+ /**
16401
+ * Checks if the current user can activate plugins or switch themes. Note that this method should only be used
16402
+ * after the `init` action is triggered because it is using `current_user_can()` which is only functional after
16403
+ * the context user is authenticated.
16404
+ *
16405
+ * @author Leo Fajardo (@leorw)
16406
+ * @since 1.2.2
16407
+ *
16408
+ * @return bool
16409
+ */
16410
+ function is_user_admin() {
16411
+ /**
16412
+ * Require a super-admin when network activated, running from the network level OR if
16413
+ * running from the site level but not delegated the opt-in.
16414
+ *
16415
+ * @author Vova Feldman (@svovaf)
16416
+ * @since 2.0.0
16417
+ */
16418
+ if ( $this->_is_network_active &&
16419
+ ( fs_is_network_admin() || ! $this->is_delegated_connection() )
16420
+ ) {
16421
+ return is_super_admin();
16422
+ }
16423
+
16424
+ return ( $this->is_plugin() && current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) )
16425
+ || ( $this->is_theme() && current_user_can( 'switch_themes' ) );
16426
+ }
16427
+
16428
+ /**
16429
+ * Sync site's plan.
16430
+ *
16431
+ * @author Vova Feldman (@svovaf)
16432
+ * @since 1.0.3
16433
+ *
16434
+ * @uses FS_Api
16435
+ *
16436
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
16437
+ * the admin.
16438
+ * @param bool $is_context_single_site @since 2.0.0. This is used when syncing a license for a single install from the
16439
+ * network-level "Account" page.
16440
+ */
16441
+ private function _sync_license( $background = false, $is_context_single_site = false ) {
16442
+ $this->_logger->entrance();
16443
+
16444
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
16445
+
16446
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
16447
+
16448
+ if ( $is_addon_sync ) {
16449
+ $this->_sync_addon_license( $plugin_id, $background );
16450
+ } else {
16451
+ $this->_sync_plugin_license( $background, true, $is_context_single_site );
16452
+ }
16453
+
16454
+ $this->do_action( 'after_account_plan_sync', $this->get_plan_name() );
16455
+ }
16456
+
16457
+ /**
16458
+ * Sync plugin's add-on license.
16459
+ *
16460
+ * @author Vova Feldman (@svovaf)
16461
+ * @since 1.0.6
16462
+ * @uses FS_Api
16463
+ *
16464
+ * @param number $addon_id
16465
+ * @param bool $background
16466
+ */
16467
+ private function _sync_addon_license( $addon_id, $background ) {
16468
+ $this->_logger->entrance();
16469
+
16470
+ if ( $this->is_addon_activated( $addon_id ) ) {
16471
+ // If already installed, use add-on sync.
16472
+ $fs_addon = self::get_instance_by_id( $addon_id );
16473
+ $fs_addon->_sync_license( $background );
16474
+
16475
+ return;
16476
+ }
16477
+
16478
+ // Validate add-on exists.
16479
+ $addon = $this->get_addon( $addon_id );
16480
+
16481
+ if ( ! is_object( $addon ) ) {
16482
+ return;
16483
+ }
16484
+
16485
+ // Add add-on into account add-ons.
16486
+ $account_addons = $this->get_account_addons();
16487
+ if ( ! is_array( $account_addons ) ) {
16488
+ $account_addons = array();
16489
+ }
16490
+ $account_addons[] = $addon->id;
16491
+ $account_addons = array_unique( $account_addons );
16492
+ $this->_store_account_addons( $account_addons );
16493
+
16494
+ // Load add-on licenses.
16495
+ $licenses = $this->_fetch_licenses( $addon->id );
16496
+
16497
+ // Sync add-on licenses.
16498
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
16499
+ $this->_update_licenses( $licenses, $addon->id );
16500
+
16501
+ if ( ! $this->is_addon_installed( $addon->id ) && FS_License_Manager::has_premium_license( $licenses ) ) {
16502
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( $this->add_show_pending( "/addons/{$addon_id}/plans.json" ) );
16503
+
16504
+ if ( ! isset( $plans_result->error ) ) {
16505
+ $plans = array();
16506
+ foreach ( $plans_result->plans as $plan ) {
16507
+ $plans[] = new FS_Plugin_Plan( $plan );
16508
+ }
16509
+
16510
+ $this->_admin_notices->add_sticky(
16511
+ sprintf(
16512
+ ( FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
16513
+ $this->get_text_inline( 'Your %s Add-on plan was successfully upgraded.', 'addon-successfully-upgraded-message' ) :
16514
+ /* translators: %s:product name, e.g. Facebook add-on was successfully... */
16515
+ $this->get_text_inline( '%s Add-on was successfully purchased.', 'addon-successfully-purchased-message' ) ),
16516
+ $addon->title
16517
+ ) . ' ' . $this->get_latest_download_link(
16518
+ $this->get_text_inline( 'Download the latest version', 'download-latest-version' ),
16519
+ $addon_id
16520
+ ),
16521
+ 'addon_plan_upgraded_' . $addon->slug,
16522
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
16523
+ );
16524
+ }
16525
+ }
16526
+ }
16527
+ }
16528
+
16529
+ /**
16530
+ * Sync site's plugin plan.
16531
+ *
16532
+ * @author Vova Feldman (@svovaf)
16533
+ * @since 1.0.6
16534
+ * @uses FS_Api
16535
+ *
16536
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by the admin.
16537
+ * @param bool $send_installs_update Since 2.0.0
16538
+ * @param bool $is_context_single_site Since 2.0.0. This is used when sending an update for a single install and
16539
+ * syncing its license from the network-level "Account" page (e.g.: after
16540
+ * activating a license only for the single install).
16541
+ */
16542
+ private function _sync_plugin_license(
16543
+ $background = false,
16544
+ $send_installs_update = true,
16545
+ $is_context_single_site = false
16546
+ ) {
16547
+ $this->_logger->entrance();
16548
+
16549
+ $plan_change = 'none';
16550
+
16551
+ $is_site_level_sync = ( $is_context_single_site || fs_is_blog_admin() || ! $this->_is_network_active );
16552
+
16553
+ if ( ! $send_installs_update ) {
16554
+ $site = $this->_site;
16555
+ } else {
16556
+ /**
16557
+ * Sync site info.
16558
+ *
16559
+ * @todo This line will execute install sync on a daily basis, even if running the free version (for opted-in users). The reason we want to keep it that way is for cases when the user was a paying customer, then there was a failure in subscription payment, and then after some time the payment was successful. This could be heavily optimized. For example, we can skip the $flush if the current install was never associated with a paid version.
16560
+ */
16561
+ if ( $is_site_level_sync ) {
16562
+ $result = $this->send_install_update( array(), true );
16563
+ $is_valid = $this->is_api_result_entity( $result );
16564
+ } else {
16565
+ $result = $this->send_installs_update( array(), true );
16566
+ $is_valid = $this->is_api_result_object( $result, 'installs' );
16567
+ }
16568
+
16569
+ if ( ! $is_valid ) {
16570
+ if ( $is_context_single_site ) {
16571
+ // Switch back to the main blog so that the following logic will have the right entities.
16572
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
16573
+ }
16574
+
16575
+ // Show API messages only if not background sync or if paying customer.
16576
+ if ( ! $background || $this->is_paying() ) {
16577
+ // Try to ping API to see if not blocked.
16578
+ if ( ! FS_Api::test() ) {
16579
+ /**
16580
+ * Failed to ping API - blocked!
16581
+ *
16582
+ * @author Vova Feldman (@svovaf)
16583
+ * @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.
16584
+ */
16585
+ $api = $this->get_api_site_scope();
16586
+
16587
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
16588
+ self::$_global_admin_notices->add(
16589
+ sprintf(
16590
+ $this->get_text_x_inline( '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', 'server-blocking-access' ),
16591
+ $this->get_plugin_name(),
16592
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
16593
+ ) . '<br> ' . $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . var_export( $result->error, true ),
16594
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
16595
+ 'error',
16596
+ $background,
16597
+ 'api_blocked'
16598
+ );
16599
+ }
16600
+ } else {
16601
+ // Authentication params are broken.
16602
+ $this->_admin_notices->add(
16603
+ $this->get_text_inline( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'wrong-authentication-param-message' ),
16604
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
16605
+ 'error'
16606
+ );
16607
+ }
16608
+ }
16609
+
16610
+ // No reason to continue with license sync while there are API issues.
16611
+ return;
16612
+ }
16613
+
16614
+ if ( $is_site_level_sync ) {
16615
+ $site = new FS_Site( $result );
16616
+ } else {
16617
+ // Map site addresses to their blog IDs.
16618
+ $address_to_blog_map = $this->get_address_to_blog_map();
16619
+
16620
+ // Find the current context install.
16621
+ $site = null;
16622
+ foreach ( $result->installs as $install ) {
16623
+ if ( $install->id == $this->_site->id ) {
16624
+ $site = new FS_Site( $install );
16625
+ } else {
16626
+ $address = trailingslashit( fs_strip_url_protocol( $install->url ) );
16627
+ $blog_id = $address_to_blog_map[ $address ];
16628
+
16629
+ $this->_store_site( true, $blog_id, new FS_Site( $install ) );
16630
+ }
16631
+ }
16632
+ }
16633
+
16634
+ // Sync plans.
16635
+ $this->_sync_plans();
16636
+ }
16637
+
16638
+ // Remove sticky API connectivity message.
16639
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
16640
+
16641
+ if ( ! $this->has_paid_plan() ) {
16642
+ $this->_site = $site;
16643
+ $this->_store_site(
16644
+ true,
16645
+ $is_site_level_sync ?
16646
+ null :
16647
+ $this->get_network_install_blog_id()
16648
+ );
16649
+ } else {
16650
+ $context_blog_id = 0;
16651
+
16652
+ if ( $is_context_single_site ) {
16653
+ $context_blog_id = get_current_blog_id();
16654
+
16655
+ // Switch back to the main blog in order to properly sync the license.
16656
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
16657
+ }
16658
+
16659
+ /**
16660
+ * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
16661
+ * associated with that ID is not included in the user's licenses collection.
16662
+ */
16663
+ $this->_sync_licenses(
16664
+ $site->license_id,
16665
+ ( $is_context_single_site ?
16666
+ $context_blog_id :
16667
+ null
16668
+ )
16669
+ );
16670
+
16671
+ if ( $is_context_single_site ) {
16672
+ $this->switch_to_blog( $context_blog_id );
16673
+ }
16674
+
16675
+ // Check if plan / license changed.
16676
+ if ( $site->plan_id != $this->_site->plan_id ||
16677
+ // Check if trial started.
16678
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
16679
+ $site->trial_ends != $this->_site->trial_ends ||
16680
+ // Check if license changed.
16681
+ $site->license_id != $this->_site->license_id
16682
+ ) {
16683
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
16684
+ // New trial started.
16685
+ $this->_site = $site;
16686
+ $plan_change = 'trial_started';
16687
+
16688
+ // For trial with subscription use-case.
16689
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
16690
+
16691
+ if ( is_object( $new_license ) && $new_license->is_valid() ) {
16692
+ $this->_site = $site;
16693
+ $this->_update_site_license( $new_license );
16694
+ $this->_store_licenses();
16695
+
16696
+ $this->_sync_site_subscription( $this->_license );
16697
+ }
16698
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
16699
+ // Was in trial, but now trial expired and no license ID.
16700
+ // New trial started.
16701
+ $this->_site = $site;
16702
+ $plan_change = 'trial_expired';
16703
+ } else {
16704
+ $is_free = $this->is_free_plan();
16705
+
16706
+ // Make sure license exist and not expired.
16707
+ $new_license = is_null( $site->license_id ) ?
16708
+ null :
16709
+ $this->_get_license_by_id( $site->license_id );
16710
+
16711
+ if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
16712
+ // License cancelled.
16713
+ $this->_site = $site;
16714
+ $this->_update_site_license( $new_license );
16715
+ $this->_store_licenses();
16716
+
16717
+ $plan_change = 'cancelled';
16718
+ } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
16719
+ // The license is expired, so ignore upgrade method.
16720
+ $this->_site = $site;
16721
+ } else {
16722
+ // License changed.
16723
+ $this->_site = $site;
16724
+
16725
+ /**
16726
+ * IMPORTANT:
16727
+ * The line below should be executed before trying to activate the license on the rest of the network, otherwise, the license' activation counters may be out of sync + there's no need to activate the license on the context site since it's already activated on it.
16728
+ *
16729
+ * @author Vova Feldman (@svovaf)
16730
+ * @since 2.0.0
16731
+ */
16732
+ $this->_update_site_license( $new_license );
16733
+
16734
+ if ( ! $is_context_single_site &&
16735
+ fs_is_network_admin() &&
16736
+ $this->_is_network_active &&
16737
+ $new_license->quota > 1 &&
16738
+ get_blog_count() > 1
16739
+ ) {
16740
+ // See if license can activated on all sites.
16741
+ if ( ! $this->try_activate_license_on_network( $this->_user, $new_license ) ) {
16742
+ if ( ! fs_request_get_bool( 'auto_install' ) ) {
16743
+ // Open the license activation dialog box on the account page.
16744
+ add_action( 'admin_footer', array(
16745
+ &$this,
16746
+ '_open_license_activation_dialog_box'
16747
+ ) );
16748
+ }
16749
+ }
16750
+ }
16751
+
16752
+ $this->_store_licenses();
16753
+
16754
+ $plan_change = $is_free ?
16755
+ 'upgraded' :
16756
+ ( is_object( $new_license ) ?
16757
+ 'changed' :
16758
+ 'downgraded' );
16759
+ }
16760
+ }
16761
+
16762
+ // Store updated site info.
16763
+ $this->_store_site(
16764
+ true,
16765
+ $is_site_level_sync ?
16766
+ null :
16767
+ $this->get_network_install_blog_id()
16768
+ );
16769
+ } else {
16770
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
16771
+ if ( ! $this->has_features_enabled_license() ) {
16772
+ $this->_deactivate_license();
16773
+ $plan_change = 'downgraded';
16774
+ } else {
16775
+ $plan_change = 'expired';
16776
+ }
16777
+ }
16778
+
16779
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
16780
+ $this->_sync_site_subscription( $this->_license );
16781
+ }
16782
+ }
16783
+ }
16784
+
16785
+ $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
16786
+
16787
+ if ( $this->has_paid_plan() ) {
16788
+ switch ( $plan_change ) {
16789
+ case 'none':
16790
+ if ( ! $background && is_admin() ) {
16791
+ $plan = $this->is_trial() ?
16792
+ $this->get_trial_plan() :
16793
+ $this->get_plan();
16794
+
16795
+ if ( $plan->is_free() ) {
16796
+ $this->_admin_notices->add(
16797
+ sprintf(
16798
+ $this->get_text_inline( '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.', 'plan-did-not-change-message' ),
16799
+ '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . $this->get_text_x_inline( 'Trial', 'trial period', 'trial' ) : '' ) . '</b></i>'
16800
+ ) . ' ' . sprintf(
16801
+ '<a href="%s">%s</a>',
16802
+ $this->contact_url(
16803
+ 'bug',
16804
+ sprintf( $this->get_text_inline( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'plan-did-not-change-email-message' ),
16805
+ strtoupper( $plan->name )
16806
+ )
16807
+ ),
16808
+ $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
16809
+ ),
16810
+ $hmm_text
16811
+ );
16812
+ }
16813
+ }
16814
+ break;
16815
+ case 'upgraded':
16816
+ $this->_admin_notices->add_sticky(
16817
+ sprintf(
16818
+ $this->get_text_inline( 'Your plan was successfully upgraded.', 'plan-upgraded-message' ),
16819
+ '<i>' . $this->get_plugin_name() . '</i>'
16820
+ ) . $this->get_complete_upgrade_instructions(),
16821
+ 'plan_upgraded',
16822
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
16823
+ );
16824
+
16825
+ $this->_admin_notices->remove_sticky( array(
16826
+ 'trial_started',
16827
+ 'trial_promotion',
16828
+ 'trial_expired',
16829
+ 'activation_complete',
16830
+ 'license_expired',
16831
+ ) );
16832
+ break;
16833
+ case 'changed':
16834
+ $this->_admin_notices->add_sticky(
16835
+ sprintf(
16836
+ $this->get_text_inline( 'Your plan was successfully changed to %s.', 'plan-changed-to-x-message' ),
16837
+ $this->get_plan_title()
16838
+ ),
16839
+ 'plan_changed'
16840
+ );
16841
+
16842
+ $this->_admin_notices->remove_sticky( array(
16843
+ 'trial_started',
16844
+ 'trial_promotion',
16845
+ 'trial_expired',
16846
+ 'activation_complete',
16847
+ ) );
16848
+ break;
16849
+ case 'downgraded':
16850
+ $this->_admin_notices->add_sticky(
16851
+ ($this->has_free_plan() ?
16852
+ sprintf( $this->get_text_inline( 'Your license has expired. You can still continue using the free %s forever.', 'license-expired-blocking-message' ), $this->_module_type ) :
16853
+ /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
16854
+ sprintf( $this->get_text_inline( 'Your license has expired. %1$sUpgrade now%2$s to continue using the %3$s without interruptions.', 'license-expired-blocking-message_premium-only' ), sprintf('<a href="%s">', $this->pricing_url()), '</a>', $this->get_module_label(true) ) ),
16855
+ 'license_expired',
16856
+ $hmm_text
16857
+ );
16858
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
16859
+ break;
16860
+ case 'cancelled':
16861
+ $this->_admin_notices->add(
16862
+ $this->get_text_inline( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.', 'license-cancelled' ) . ' ' .
16863
+ sprintf(
16864
+ '<a href="%s">%s</a>',
16865
+ $this->contact_url( 'bug' ),
16866
+ $this->get_text_inline( 'Please contact us here', 'contact-us-here' )
16867
+ ),
16868
+ $hmm_text,
16869
+ 'error'
16870
+ );
16871
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
16872
+ break;
16873
+ case 'expired':
16874
+ $this->_admin_notices->add_sticky(
16875
+ sprintf( $this->get_text_inline( '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.', 'license-expired-non-blocking-message' ), $this->get_plan()->title ),
16876
+ 'license_expired',
16877
+ $hmm_text
16878
+ );
16879
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
16880
+ break;
16881
+ case 'trial_started':
16882
+ $this->_admin_notices->add_sticky(
16883
+ sprintf(
16884
+ $this->get_text_inline( 'Your trial has been successfully started.', 'trial-started-message' ),
16885
+ '<i>' . $this->get_plugin_name() . '</i>'
16886
+ ) . $this->get_complete_upgrade_instructions( $this->get_trial_plan()->title ),
16887
+ 'trial_started',
16888
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
16889
+ );
16890
+
16891
+ $this->_admin_notices->remove_sticky( array(
16892
+ 'trial_promotion',
16893
+ ) );
16894
+ break;
16895
+ case 'trial_expired':
16896
+ $this->_admin_notices->add_sticky(
16897
+ ($this->has_free_plan() ?
16898
+ $this->get_text_inline( 'Your free trial has expired. You can still continue using all our free features.', 'trial-expired-message' ) :
16899
+ /* translators: %1$s: product title; %2$s, %3$s: wrapping HTML anchor element; %4$s: 'plugin', 'theme', or 'add-on'. */
16900
+ sprintf( $this->get_text_inline( 'Your free trial has expired. %1$sUpgrade now%2$s to continue using the %3$s without interruptions.', 'trial-expired-message_premium-only' ), sprintf('<a href="%s">', $this->pricing_url()), '</a>', $this->get_module_label(true))),
16901
+ 'trial_expired',
16902
+ $hmm_text
16903
+ );
16904
+ $this->_admin_notices->remove_sticky( array(
16905
+ 'trial_started',
16906
+ 'trial_promotion',
16907
+ 'plan_upgraded',
16908
+ ) );
16909
+ break;
16910
+ }
16911
+ }
16912
+
16913
+ if ( 'none' !== $plan_change ) {
16914
+ $this->do_action( 'after_license_change', $plan_change, $this->get_plan() );
16915
+ }
16916
+ }
16917
+
16918
+ /**
16919
+ * Include the required JS at the footer of the admin to trigger the license activation dialog box.
16920
+ *
16921
+ * @author Vova Feldman (@svovaf)
16922
+ * @since 2.0.0
16923
+ */
16924
+ public function _open_license_activation_dialog_box() {
16925
+ $vars = array( 'license_id' => $this->_site->license_id );
16926
+ fs_require_once_template( 'js/open-license-activation.php', $vars );
16927
+ }
16928
+
16929
+ /**
16930
+ * @author Vova Feldman (@svovaf)
16931
+ * @since 1.0.5
16932
+ *
16933
+ * @param bool $background
16934
+ */
16935
+ protected function _activate_license( $background = false ) {
16936
+ $this->_logger->entrance();
16937
+
16938
+ $license_id = fs_request_get( 'license_id' );
16939
+
16940
+ if ( is_object( $this->_site ) &&
16941
+ FS_Plugin_License::is_valid_id( $license_id ) &&
16942
+ $license_id == $this->_site->license_id
16943
+ ) {
16944
+ // License is already activated.
16945
+ return;
16946
+ }
16947
+
16948
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
16949
+ $this->_get_license_by_id( $license_id ) :
16950
+ $this->_get_available_premium_license();
16951
+
16952
+ if ( ! is_object( $premium_license ) ) {
16953
+ return;
16954
+ }
16955
+
16956
+ if ( ! is_object( $this->_site ) ) {
16957
+ // Not yet opted-in.
16958
+ $user = $this->get_current_or_network_user();
16959
+ if ( ! is_object( $user ) ) {
16960
+ $user = self::_get_user_by_id( $premium_license->user_id );
16961
+ }
16962
+
16963
+ if ( is_object( $user ) ) {
16964
+ $this->install_with_user( $user, $premium_license->secret_key, false, false, false );
16965
+ } else {
16966
+ $this->opt_in(
16967
+ false,
16968
+ false,
16969
+ false,
16970
+ $premium_license->secret_key
16971
+ );
16972
+
16973
+ return;
16974
+ }
16975
+ }
16976
+
16977
+
16978
+ /**
16979
+ * If the premium license is already associated with the install, just
16980
+ * update the license reference (activation is not required).
16981
+ *
16982
+ * @since 1.1.9
16983
+ */
16984
+ if ( $premium_license->id == $this->_site->license_id ) {
16985
+ // License is already activated.
16986
+ $this->_update_site_license( $premium_license );
16987
+ $this->_store_account();
16988
+
16989
+ return;
16990
+ }
16991
+
16992
+ if ( $this->_site->user_id != $premium_license->user_id ) {
16993
+ $api_request_params = array( 'license_key' => $premium_license->secret_key );
16994
+ } else {
16995
+ $api_request_params = array();
16996
+ }
16997
+
16998
+ $api = $this->get_api_site_scope();
16999
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
17000
+
17001
+ if ( ! $this->is_api_result_entity( $license ) ) {
17002
+ if ( ! $background ) {
17003
+ $this->_admin_notices->add( sprintf(
17004
+ '%s %s',
17005
+ $this->get_text_inline( 'It looks like the license could not be activated.', 'license-activation-failed-message' ),
17006
+ ( is_object( $license ) && isset( $license->error ) ?
17007
+ $license->error->message :
17008
+ sprintf( '%s<br><code>%s</code>',
17009
+ $this->get_text_inline( 'Error received from the server:', 'server-error-message' ),
17010
+ var_export( $license, true )
17011
+ )
17012
+ )
17013
+ ),
17014
+ $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...',
17015
+ 'error'
17016
+ );
17017
+ }
17018
+
17019
+ return;
17020
+ }
17021
+
17022
+ $premium_license = new FS_Plugin_License( $license );
17023
+
17024
+ // Updated site plan.
17025
+ $site = $this->get_api_site_scope()->get( '/', true );
17026
+ if ( $this->is_api_result_entity( $site ) ) {
17027
+ $this->_site = new FS_Site( $site );
17028
+ }
17029
+ $this->_update_site_license( $premium_license );
17030
+
17031
+ $this->_store_account();
17032
+
17033
+ if ( ! $background ) {
17034
+ $this->_admin_notices->add_sticky(
17035
+ $this->get_text_inline( 'Your license was successfully activated.', 'license-activated-message' ) .
17036
+ $this->get_complete_upgrade_instructions(),
17037
+ 'license_activated',
17038
+ $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
17039
+ );
17040
+ }
17041
+
17042
+ $this->_admin_notices->remove_sticky( array(
17043
+ 'trial_promotion',
17044
+ 'license_expired',
17045
+ ) );
17046
+ }
17047
+
17048
+ /**
17049
+ * @author Vova Feldman (@svovaf)
17050
+ * @since 1.0.5
17051
+ *
17052
+ * @param bool $show_notice
17053
+ */
17054
+ protected function _deactivate_license( $show_notice = true ) {
17055
+ $this->_logger->entrance();
17056
+
17057
+ $hmm_text = $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...';
17058
+
17059
+ if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
17060
+ $this->_admin_notices->add(
17061
+ sprintf( $this->get_text_inline( 'It looks like your site currently doesn\'t have an active license.', 'no-active-license-message' ), $this->get_plan_title() ),
17062
+ $hmm_text
17063
+ );
17064
+
17065
+ return;
17066
+ }
17067
+
17068
+ $api = $this->get_api_site_scope();
17069
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
17070
+
17071
+ if ( isset( $license->error ) ) {
17072
+ $this->_admin_notices->add(
17073
+ $this->get_text_inline( 'It looks like the license deactivation failed.', 'license-deactivation-failed-message' ) . '<br> ' .
17074
+ $this->get_text_inline( 'Error received from the server:', 'server-error-message' ) . ' ' . var_export( $license->error, true ),
17075
+ $hmm_text,
17076
+ 'error'
17077
+ );
17078
+
17079
+ return;
17080
+ }
17081
+
17082
+ // Update license cache.
17083
+ if ( is_array( $this->_licenses ) ) {
17084
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
17085
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
17086
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
17087
+ }
17088
+ }
17089
+ }
17090
+
17091
+ // Updated site plan to default.
17092
+ $this->_sync_plans();
17093
+ $this->_site->plan_id = $this->_plans[0]->id;
17094
+ // Unlink license from site.
17095
+ $this->_update_site_license( null );
17096
+
17097
+ $this->_store_account();
17098
+
17099
+ if ( $show_notice ) {
17100
+ $this->_admin_notices->add(
17101
+ sprintf( $this->get_text_inline( 'Your license was successfully deactivated, you are back to the %s plan.', 'license-deactivation-message' ), $this->get_plan_title() ),
17102
+ $this->get_text_inline( 'O.K', 'ok' )
17103
+ );
17104
+ }
17105
+
17106
+ $this->_admin_notices->remove_sticky( array(
17107
+ 'plan_upgraded',
17108
+ 'license_activated',
17109
+ ) );
17110
+ }
17111
+
17112
+ /**
17113
+ * Site plan downgrade.
17114
+ *
17115
+ * @author Vova Feldman (@svovaf)
17116
+ * @since 1.0.4
17117
+ *
17118
+ * @uses FS_Api
17119
+ */
17120
+ private function _downgrade_site() {
17121
+ $this->_logger->entrance();
17122
+
17123
+ $api = $this->get_api_site_scope();
17124
+ $site = $api->call( 'downgrade.json', 'put' );
17125
+
17126
+ $plan_downgraded = false;
17127
+ $plan = false;
17128
+ if ( $this->is_api_result_entity( $site ) ) {
17129
+ $prev_plan_id = $this->_site->plan_id;
17130
+
17131
+ // Update new site plan id.
17132
+ $this->_site->plan_id = $site->plan_id;
17133
+
17134
+ $plan = $this->get_plan();
17135
+ $subscription = $this->_sync_site_subscription( $this->_license );
17136
+
17137
+ // Plan downgraded if plan was changed or subscription was cancelled.
17138
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
17139
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
17140
+ } else {
17141
+ // handle different error cases.
17142
+
17143
+ }
17144
+
17145
+ if ( $plan_downgraded ) {
17146
+ // Remove previous sticky message about upgrade (if exist).
17147
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
17148
+
17149
+ $this->_admin_notices->add(
17150
+ sprintf( $this->get_text_inline( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'plan-x-downgraded-message' ),
17151
+ $plan->title,
17152
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
17153
+ )
17154
+ );
17155
+
17156
+ // Store site updates.
17157
+ $this->_store_site();
17158
+ } else {
17159
+ $this->_admin_notices->add(
17160
+ $this->get_text_inline( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'plan-downgraded-failure-message' ),
17161
+ $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...',
17162
+ 'error'
17163
+ );
17164
+ }
17165
+ }
17166
+
17167
+ /**
17168
+ * @author Vova Feldman (@svovaf)
17169
+ * @since 1.1.8.1
17170
+ *
17171
+ * @param bool|string $plan_name
17172
+ *
17173
+ * @return bool If trial was successfully started.
17174
+ */
17175
+ function start_trial( $plan_name = false ) {
17176
+ $this->_logger->entrance();
17177
+
17178
+ // Alias.
17179
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
17180
+
17181
+ if ( $this->is_trial() ) {
17182
+ // Already in trial mode.
17183
+ $this->_admin_notices->add(
17184
+ sprintf( $this->get_text_inline( 'You are already running the %s in a trial mode.', 'in-trial-mode' ), $this->_module_type ),
17185
+ $oops_text,
17186
+ 'error'
17187
+ );
17188
+
17189
+ return false;
17190
+ }
17191
+
17192
+ if ( $this->_site->is_trial_utilized() ) {
17193
+ // Trial was already utilized.
17194
+ $this->_admin_notices->add(
17195
+ $this->get_text_inline( 'You already utilized a trial before.', 'trial-utilized' ),
17196
+ $oops_text,
17197
+ 'error'
17198
+ );
17199
+
17200
+ return false;
17201
+ }
17202
+
17203
+ if ( false !== $plan_name ) {
17204
+ $plan = $this->get_plan_by_name( $plan_name );
17205
+
17206
+ if ( false === $plan ) {
17207
+ // Plan doesn't exist.
17208
+ $this->_admin_notices->add(
17209
+ sprintf( $this->get_text_inline( 'Plan %s do not exist, therefore, can\'t start a trial.', 'trial-plan-x-not-exist' ), $plan_name ),
17210
+ $oops_text,
17211
+ 'error'
17212
+ );
17213
+
17214
+ return false;
17215
+ }
17216
+
17217
+ if ( ! $plan->has_trial() ) {
17218
+ // Plan doesn't exist.
17219
+ $this->_admin_notices->add(
17220
+ sprintf( $this->get_text_inline( 'Plan %s does not support a trial period.', 'plan-x-no-trial' ), $plan_name ),
17221
+ $oops_text,
17222
+ 'error'
17223
+ );
17224
+
17225
+ return false;
17226
+ }
17227
+ } else {
17228
+ if ( ! $this->has_trial_plan() ) {
17229
+ // None of the plans have a trial.
17230
+ $this->_admin_notices->add(
17231
+ sprintf( $this->get_text_inline( 'None of the %s\'s plans supports a trial period.', 'no-trials' ), $this->_module_type ),
17232
+ $oops_text,
17233
+ 'error'
17234
+ );
17235
+
17236
+ return false;
17237
+ }
17238
+
17239
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
17240
+
17241
+ $plan = $plans_with_trial[0];
17242
+ }
17243
+
17244
+ $api = $this->get_api_site_scope();
17245
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
17246
+
17247
+ if ( ! $this->is_api_result_entity( $plan ) ) {
17248
+ // Some API error while trying to start the trial.
17249
+ $this->_admin_notices->add(
17250
+ sprintf( $this->get_text_inline( 'Unexpected API error. Please contact the %s\'s author with the following error.', 'unexpected-api-error' ), $this->_module_type )
17251
+ . ' ' . var_export( $plan, true ),
17252
+ $oops_text,
17253
+ 'error'
17254
+ );
17255
+
17256
+ return false;
17257
+ }
17258
+
17259
+ // Sync license.
17260
+ $this->_sync_license();
17261
+
17262
+ return $this->is_trial();
17263
+ }
17264
+
17265
+ /**
17266
+ * Cancel site trial.
17267
+ *
17268
+ * @author Vova Feldman (@svovaf)
17269
+ * @since 1.0.9
17270
+ *
17271
+ * @uses FS_Api
17272
+ */
17273
+ private function _cancel_trial() {
17274
+ $this->_logger->entrance();
17275
+
17276
+ // Alias.
17277
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
17278
+
17279
+ if ( ! $this->is_trial() ) {
17280
+ $this->_admin_notices->add(
17281
+ $this->get_text_inline( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'trial-cancel-no-trial-message' ),
17282
+ $oops_text,
17283
+ 'error'
17284
+ );
17285
+
17286
+ return;
17287
+ }
17288
+
17289
+ $trial_plan = $this->get_trial_plan();
17290
+
17291
+ $api = $this->get_api_site_scope();
17292
+ $site = $api->call( 'trials.json', 'delete' );
17293
+
17294
+ $trial_cancelled = false;
17295
+
17296
+ if ( $this->is_api_result_entity( $site ) ) {
17297
+ $prev_trial_ends = $this->_site->trial_ends;
17298
+
17299
+ if ( $this->is_paid_trial() ) {
17300
+ $this->_license->expiration = $site->trial_ends;
17301
+ $this->_license->is_cancelled = true;
17302
+ $this->_update_site_license( $this->_license );
17303
+ $this->_store_licenses();
17304
+
17305
+ // Clear subscription reference.
17306
+ $this->_sync_site_subscription( null );
17307
+ }
17308
+
17309
+ // Update site info.
17310
+ $this->_site = new FS_Site( $site );
17311
+
17312
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
17313
+ } else {
17314
+ // @todo handle different error cases.
17315
+ }
17316
+
17317
+ if ( $trial_cancelled ) {
17318
+ // Remove previous sticky messages about upgrade or trial (if exist).
17319
+ $this->_admin_notices->remove_sticky( array(
17320
+ 'trial_started',
17321
+ 'trial_promotion',
17322
+ 'plan_upgraded',
17323
+ ) );
17324
+
17325
+ // Store site updates.
17326
+ $this->_store_site();
17327
+
17328
+ if ( ! $this->is_addon() ||
17329
+ ! $this->deactivate_premium_only_addon_without_license( true )
17330
+ ) {
17331
+ $this->_admin_notices->add(
17332
+ sprintf( $this->get_text_inline( 'Your %s free trial was successfully cancelled.', 'trial-cancel-message' ), $trial_plan->title )
17333
+ );
17334
+ }
17335
+ } else {
17336
+ $this->_admin_notices->add(
17337
+ $this->get_text_inline( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'trial-cancel-failure-message' ),
17338
+ $oops_text,
17339
+ 'error'
17340
+ );
17341
+ }
17342
+ }
17343
+
17344
+ /**
17345
+ * @author Vova Feldman (@svovaf)
17346
+ * @since 1.0.6
17347
+ *
17348
+ * @param bool|number $plugin_id
17349
+ *
17350
+ * @return bool
17351
+ */
17352
+ private function _is_addon_id( $plugin_id ) {
17353
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
17354
+ }
17355
+
17356
+ /**
17357
+ * Check if user eligible to download premium version updates.
17358
+ *
17359
+ * @author Vova Feldman (@svovaf)
17360
+ * @since 1.0.6
17361
+ *
17362
+ * @return bool
17363
+ */
17364
+ private function _can_download_premium() {
17365
+ return $this->has_any_active_valid_license() ||
17366
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
17367
+ }
17368
+
17369
+ /**
17370
+ *
17371
+ * @author Vova Feldman (@svovaf)
17372
+ * @since 1.0.6
17373
+ *
17374
+ * @param bool|number $addon_id
17375
+ * @param string $type "json" or "zip"
17376
+ *
17377
+ * @return string
17378
+ */
17379
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
17380
+
17381
+ $is_addon = $this->_is_addon_id( $addon_id );
17382
+
17383
+ $is_premium = null;
17384
+ if ( ! $is_addon ) {
17385
+ $is_premium = ( $this->is_premium() || $this->_can_download_premium() );
17386
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
17387
+ $fs_addon = self::get_instance_by_id( $addon_id );
17388
+ $is_premium = ( $fs_addon->is_premium() || $fs_addon->_can_download_premium() );
17389
+ }
17390
+
17391
+ // If add-on, then append add-on ID.
17392
+ $endpoint = ( $is_addon ? "/addons/$addon_id" : '' ) .
17393
+ '/updates/latest.' . $type;
17394
+
17395
+ // If add-on and not yet activated, try to fetch based on server licensing.
17396
+ if ( is_bool( $is_premium ) ) {
17397
+ $endpoint = add_query_arg( 'is_premium', json_encode( $is_premium ), $endpoint );
17398
+ }
17399
+
17400
+ if ( $this->has_secret_key() ) {
17401
+ $endpoint = add_query_arg( 'type', 'all', $endpoint );
17402
+ }
17403
+
17404
+ return $endpoint;
17405
+ }
17406
+
17407
+ /**
17408
+ * @author Vova Feldman (@svovaf)
17409
+ * @since 1.0.4
17410
+ *
17411
+ * @param bool|number $addon_id
17412
+ * @param bool $flush Since 1.1.7.3
17413
+ * @param int $expiration Since 1.2.2.7
17414
+ *
17415
+ * @return object|false Plugin latest tag info.
17416
+ */
17417
+ function _fetch_latest_version(
17418
+ $addon_id = false,
17419
+ $flush = true,
17420
+ $expiration = WP_FS__TIME_24_HOURS_IN_SEC
17421
+ ) {
17422
+ $this->_logger->entrance();
17423
+
17424
+ $switch_to_blog_id = null;
17425
+
17426
+ /**
17427
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
17428
+ * @since 1.1.7.4 Also check updates for add-ons.
17429
+ */
17430
+ if ( ! $this->is_registered() &&
17431
+ ! $this->_is_addon_id( $addon_id )
17432
+ ) {
17433
+ if ( ! is_multisite() ) {
17434
+ return false;
17435
+ }
17436
+
17437
+ $installs_map = $this->get_blog_install_map();
17438
+
17439
+ foreach ( $installs_map as $blog_id => $install ) {
17440
+ /**
17441
+ * @var FS_Site $install
17442
+ */
17443
+ if ( $install->is_trial() ) {
17444
+ $switch_to_blog_id = $blog_id;
17445
+ break;
17446
+ }
17447
+
17448
+ if ( FS_Plugin_License::is_valid_id( $install->license_id ) ) {
17449
+ $license = $this->get_license_by_id( $install->license_id );
17450
+
17451
+ if ( is_object( $license ) && $license->is_features_enabled() ) {
17452
+ $switch_to_blog_id = $blog_id;
17453
+ break;
17454
+ }
17455
+ }
17456
+ }
17457
+
17458
+ if ( is_null( $switch_to_blog_id ) ) {
17459
+ return false;
17460
+ }
17461
+ }
17462
+
17463
+ $current_blog_id = is_numeric( $switch_to_blog_id ) ?
17464
+ get_current_blog_id() :
17465
+ 0;
17466
+
17467
+ if ( is_numeric( $switch_to_blog_id ) ) {
17468
+ $this->switch_to_blog( $switch_to_blog_id );
17469
+ }
17470
+
17471
+ $tag = $this->get_api_site_or_plugin_scope()->get(
17472
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
17473
+ $flush,
17474
+ $expiration
17475
+ );
17476
+
17477
+ if ( is_numeric( $switch_to_blog_id ) ) {
17478
+ $this->switch_to_blog( $current_blog_id );
17479
+ }
17480
+
17481
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
17482
+
17483
+ $this->_logger->departure( 'Latest version ' . $latest_version );
17484
+
17485
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
17486
+ }
17487
+
17488
+ #----------------------------------------------------------------------------------
17489
+ #region Download Plugin
17490
+ #----------------------------------------------------------------------------------
17491
+
17492
+ /**
17493
+ * Download latest plugin version, based on plan.
17494
+ *
17495
+ * Not like _download_latest(), this will redirect the page
17496
+ * to secure download url to prevent dual download (from FS to WP server,
17497
+ * and then from WP server to the client / browser).
17498
+ *
17499
+ * @author Vova Feldman (@svovaf)
17500
+ * @since 1.0.9
17501
+ *
17502
+ * @param bool|number $plugin_id
17503
+ *
17504
+ * @uses FS_Api
17505
+ * @uses wp_redirect()
17506
+ */
17507
+ private function download_latest_directly( $plugin_id = false ) {
17508
+ $this->_logger->entrance();
17509
+
17510
+ wp_redirect( $this->get_latest_download_api_url( $plugin_id ) );
17511
+ }
17512
+
17513
+ /**
17514
+ * Get latest plugin FS API download URL.
17515
+ *
17516
+ * @author Vova Feldman (@svovaf)
17517
+ * @since 1.0.9
17518
+ *
17519
+ * @param bool|number $plugin_id
17520
+ *
17521
+ * @return string
17522
+ */
17523
+ private function get_latest_download_api_url( $plugin_id = false ) {
17524
+ $this->_logger->entrance();
17525
+
17526
+ return $this->get_api_site_scope()->get_signed_url(
17527
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
17528
+ );
17529
+ }
17530
+
17531
+ /**
17532
+ * Get payment invoice URL.
17533
+ *
17534
+ * @author Vova Feldman (@svovaf)
17535
+ * @since 1.2.0
17536
+ *
17537
+ * @param bool|number $payment_id
17538
+ *
17539
+ * @return string
17540
+ */
17541
+ function _get_invoice_api_url( $payment_id = false ) {
17542
+ $this->_logger->entrance();
17543
+
17544
+ return $this->get_api_user_scope()->get_signed_url(
17545
+ "/payments/{$payment_id}/invoice.pdf"
17546
+ );
17547
+ }
17548
+
17549
+ /**
17550
+ * Get latest plugin download link.
17551
+ *
17552
+ * @author Vova Feldman (@svovaf)
17553
+ * @since 1.0.9
17554
+ *
17555
+ * @param string $label
17556
+ * @param bool|number $plugin_id
17557
+ *
17558
+ * @return string
17559
+ */
17560
+ private function get_latest_download_link( $label, $plugin_id = false ) {
17561
+ return sprintf(
17562
+ '<a target="_blank" href="%s">%s</a>',
17563
+ $this->_get_latest_download_local_url( $plugin_id ),
17564
+ $label
17565
+ );
17566
+ }
17567
+
17568
+ /**
17569
+ * Get latest plugin download local URL.
17570
+ *
17571
+ * @author Vova Feldman (@svovaf)
17572
+ * @since 1.0.9
17573
+ *
17574
+ * @param bool|number $plugin_id
17575
+ *
17576
+ * @return string
17577
+ */
17578
+ function _get_latest_download_local_url( $plugin_id = false ) {
17579
+ // Add timestamp to protect from caching.
17580
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
17581
+
17582
+ if ( ! empty( $plugin_id ) ) {
17583
+ $params['plugin_id'] = $plugin_id;
17584
+ } else if ( $this->is_addon() ) {
17585
+ $params['plugin_id'] = $this->get_id();
17586
+ }
17587
+
17588
+ $fs = $this->is_addon() ?
17589
+ $this->get_parent_instance() :
17590
+ $this;
17591
+
17592
+ return $fs->get_account_url( 'download_latest', $params );
17593
+ }
17594
+
17595
+ #endregion Download Plugin ------------------------------------------------------------------
17596
+
17597
+ /**
17598
+ * @author Vova Feldman (@svovaf)
17599
+ * @since 1.0.4
17600
+ *
17601
+ * @uses FS_Api
17602
+ *
17603
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
17604
+ * was initiated by the admin.
17605
+ * @param bool|number $plugin_id
17606
+ * @param bool $flush Since 1.1.7.3
17607
+ * @param int $expiration Since 1.2.2.7
17608
+ */
17609
+ private function check_updates(
17610
+ $background = false,
17611
+ $plugin_id = false,
17612
+ $flush = true,
17613
+ $expiration = WP_FS__TIME_24_HOURS_IN_SEC
17614
+ ) {
17615
+ $this->_logger->entrance();
17616
+
17617
+ // Check if there's a newer version for download.
17618
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush, $expiration );
17619
+
17620
+ $update = null;
17621
+ if ( is_object( $new_version ) ) {
17622
+ $update = new FS_Plugin_Tag( $new_version );
17623
+
17624
+ if ( ! $background ) {
17625
+ $this->_admin_notices->add(
17626
+ sprintf(
17627
+ /* translators: %s: Numeric version number (e.g. '2.1.9' */
17628
+ $this->get_text_inline( 'Version %s was released.', 'version-x-released' ) . ' ' . $this->get_text_inline( 'Please download %s.', 'please-download-x' ),
17629
+ $update->version,
17630
+ sprintf(
17631
+ '<a href="%s" target="_blank">%s</a>',
17632
+ $this->get_account_url( 'download_latest' ),
17633
+ sprintf(
17634
+ /* translators: %s: plan name (e.g. latest "Professional" version) */
17635
+ $this->get_text_inline( 'the latest %s version here', 'latest-x-version' ),
17636
+ $this->get_plan_title()
17637
+ )
17638
+ )
17639
+ ),
17640
+ $this->get_text_inline( 'New', 'new' ) . '!'
17641
+ );
17642
+ }
17643
+ } else if ( false === $new_version && ! $background ) {
17644
+ $this->_admin_notices->add(
17645
+ $this->get_text_inline( 'Seems like you got the latest release.', 'you-have-latest' ),
17646
+ $this->get_text_inline( 'You are all good!', 'you-are-good' )
17647
+ );
17648
+ }
17649
+
17650
+ $this->_store_update( $update, true, $plugin_id );
17651
+ }
17652
+
17653
+ /**
17654
+ * @author Vova Feldman (@svovaf)
17655
+ * @since 1.0.4
17656
+ *
17657
+ * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
17658
+ *
17659
+ * @return FS_Plugin[]
17660
+ *
17661
+ * @uses FS_Api
17662
+ */
17663
+ private function sync_addons( $flush = false ) {
17664
+ $this->_logger->entrance();
17665
+
17666
+ $api = $this->get_api_site_or_plugin_scope();
17667
+
17668
+ $path = $this->add_show_pending( '/addons.json?enriched=true' );
17669
+
17670
+ /**
17671
+ * @since 1.2.1
17672
+ *
17673
+ * If there's a cached version of the add-ons and not asking
17674
+ * for a flush, just use the currently stored add-ons.
17675
+ */
17676
+ if ( ! $flush && $api->is_cached( $path ) ) {
17677
+ $addons = self::get_all_addons();
17678
+
17679
+ return $addons[ $this->_plugin->id ];
17680
+ }
17681
+
17682
+ $result = $api->get( $path, $flush );
17683
+
17684
+ $addons = array();
17685
+ if ( $this->is_api_result_object( $result, 'plugins' ) &&
17686
+ is_array( $result->plugins )
17687
+ ) {
17688
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
17689
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
17690
+ }
17691
+
17692
+ $this->_store_addons( $addons, true );
17693
+ }
17694
+
17695
+ return $addons;
17696
+ }
17697
+
17698
+ /**
17699
+ * Handle user email update.
17700
+ *
17701
+ * @author Vova Feldman (@svovaf)
17702
+ * @since 1.0.3
17703
+ * @uses FS_Api
17704
+ *
17705
+ * @param string $new_email
17706
+ *
17707
+ * @return object
17708
+ */
17709
+ private function update_email( $new_email ) {
17710
+ $this->_logger->entrance();
17711
+
17712
+
17713
+ $api = $this->get_api_user_scope();
17714
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
17715
+ 'email' => $new_email,
17716
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
17717
+ 'account',
17718
+ array( 'fs_action' => 'sync_user' )
17719
+ ),
17720
+ ) );
17721
+
17722
+ if ( ! isset( $user->error ) ) {
17723
+ $this->_user->email = $user->email;
17724
+ $this->_user->is_verified = $user->is_verified;
17725
+ $this->_store_user();
17726
+ } else {
17727
+ // handle different error cases.
17728
+
17729
+ }
17730
+
17731
+ return $user;
17732
+ }
17733
+
17734
+ #----------------------------------------------------------------------------------
17735
+ #region API Error Handling
17736
+ #----------------------------------------------------------------------------------
17737
+
17738
+ /**
17739
+ * @author Vova Feldman (@svovaf)
17740
+ * @since 1.1.1
17741
+ *
17742
+ * @param mixed $result
17743
+ *
17744
+ * @return bool Is API result contains an error.
17745
+ */
17746
+ private function is_api_error( $result ) {
17747
+ return FS_Api::is_api_error( $result );
17748
+ }
17749
+
17750
+ /**
17751
+ * Checks if given API result is a non-empty and not an error object.
17752
+ *
17753
+ * @author Vova Feldman (@svovaf)
17754
+ * @since 1.2.1.5
17755
+ *
17756
+ * @param mixed $result
17757
+ * @param string|null $required_property Optional property we want to verify that is set.
17758
+ *
17759
+ * @return bool
17760
+ */
17761
+ function is_api_result_object( $result, $required_property = null ) {
17762
+ return FS_Api::is_api_result_object( $result, $required_property );
17763
+ }
17764
+
17765
+ /**
17766
+ * Checks if given API result is a non-empty entity object with non-empty ID.
17767
+ *
17768
+ * @author Vova Feldman (@svovaf)
17769
+ * @since 1.2.1.5
17770
+ *
17771
+ * @param mixed $result
17772
+ *
17773
+ * @return bool
17774
+ */
17775
+ private function is_api_result_entity( $result ) {
17776
+ return FS_Api::is_api_result_entity( $result );
17777
+ }
17778
+
17779
+ #endregion
17780
+
17781
+ /**
17782
+ * Make sure a given argument is an array of a specific type.
17783
+ *
17784
+ * @author Vova Feldman (@svovaf)
17785
+ * @since 1.2.1.5
17786
+ *
17787
+ * @param mixed $array
17788
+ * @param string $class
17789
+ *
17790
+ * @return bool
17791
+ */
17792
+ private function is_array_instanceof( $array, $class ) {
17793
+ return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
17794
+ }
17795
+
17796
+ /**
17797
+ * Start install ownership change.
17798
+ *
17799
+ * @author Vova Feldman (@svovaf)
17800
+ * @since 1.1.1
17801
+ * @uses FS_Api
17802
+ *
17803
+ * @param string $candidate_email
17804
+ *
17805
+ * @return bool Is ownership change successfully initiated.
17806
+ */
17807
+ private function init_change_owner( $candidate_email ) {
17808
+ $this->_logger->entrance();
17809
+
17810
+ $api = $this->get_api_site_scope();
17811
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
17812
+ 'email' => $candidate_email,
17813
+ 'after_confirm_url' => $this->_get_admin_page_url(
17814
+ 'account',
17815
+ array( 'fs_action' => 'change_owner' )
17816
+ ),
17817
+ ) );
17818
+
17819
+ return ! $this->is_api_error( $result );
17820
+ }
17821
+
17822
+ /**
17823
+ * Handle install ownership change.
17824
+ *
17825
+ * @author Vova Feldman (@svovaf)
17826
+ * @since 1.1.1
17827
+ * @uses FS_Api
17828
+ *
17829
+ * @return bool Was ownership change successfully complete.
17830
+ */
17831
+ private function complete_change_owner() {
17832
+ $this->_logger->entrance();
17833
+
17834
+ $site_result = $this->get_api_site_scope( true )->get();
17835
+ $site = new FS_Site( $site_result );
17836
+ $this->_site = $site;
17837
+
17838
+ $user = new FS_User();
17839
+ $user->id = fs_request_get( 'user_id' );
17840
+
17841
+ // Validate install's user and given user.
17842
+ if ( $user->id != $this->_site->user_id ) {
17843
+ return false;
17844
+ }
17845
+
17846
+ $user->public_key = fs_request_get( 'user_public_key' );
17847
+ $user->secret_key = fs_request_get( 'user_secret_key' );
17848
+
17849
+ // Fetch new user information.
17850
+ $this->_user = $user;
17851
+ $user_result = $this->get_api_user_scope( true )->get();
17852
+ $user = new FS_User( $user_result );
17853
+ $this->_user = $user;
17854
+
17855
+ $this->_set_account( $user, $site );
17856
+
17857
+ return true;
17858
+ }
17859
+
17860
+ /**
17861
+ * Handle user name update.
17862
+ *
17863
+ * @author Vova Feldman (@svovaf)
17864
+ * @since 1.0.9
17865
+ * @uses FS_Api
17866
+ *
17867
+ * @return object
17868
+ */
17869
+ private function update_user_name() {
17870
+ $this->_logger->entrance();
17871
+ $name = fs_request_get( 'fs_user_name_' . $this->get_unique_affix(), '' );
17872
+
17873
+ $api = $this->get_api_user_scope();
17874
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
17875
+ 'name' => $name,
17876
+ ) );
17877
+
17878
+ if ( ! isset( $user->error ) ) {
17879
+ $this->_user->first = $user->first;
17880
+ $this->_user->last = $user->last;
17881
+ $this->_store_user();
17882
+ } else {
17883
+ // handle different error cases.
17884
+
17885
+ }
17886
+
17887
+ return $user;
17888
+ }
17889
+
17890
+ /**
17891
+ * Verify user email.
17892
+ *
17893
+ * @author Vova Feldman (@svovaf)
17894
+ * @since 1.0.3
17895
+ * @uses FS_Api
17896
+ */
17897
+ private function verify_email() {
17898
+ $this->_handle_account_user_sync();
17899
+
17900
+ if ( $this->_user->is_verified() ) {
17901
+ return;
17902
+ }
17903
+
17904
+ $api = $this->get_api_site_scope();
17905
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
17906
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
17907
+ 'account',
17908
+ array( 'fs_action' => 'sync_user' )
17909
+ )
17910
+ ) );
17911
+
17912
+ if ( ! isset( $result->error ) ) {
17913
+ $this->_admin_notices->add( sprintf(
17914
+ $this->get_text_inline( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'verification-email-sent-message' ),
17915
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
17916
+ ) );
17917
+ } else {
17918
+ // handle different error cases.
17919
+
17920
+ }
17921
+ }
17922
+
17923
+ /**
17924
+ * @author Vova Feldman (@svovaf)
17925
+ * @since 1.1.2
17926
+ *
17927
+ * @param array $params
17928
+ * @param bool|null $network
17929
+ *
17930
+ * @return string
17931
+ */
17932
+ function get_activation_url( $params = array(), $network = null ) {
17933
+ if ( $this->is_addon() && $this->has_free_plan() ) {
17934
+ /**
17935
+ * @author Vova Feldman (@svovaf)
17936
+ * @since 1.2.1.7 Add-on's activation is the parent's module activation.
17937
+ */
17938
+ return $this->get_parent_instance()->get_activation_url( $params );
17939
+ }
17940
+
17941
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params, $network ) );
17942
+ }
17943
+
17944
+ /**
17945
+ * @author Vova Feldman (@svovaf)
17946
+ * @since 1.2.1.5
17947
+ *
17948
+ * @param array $params
17949
+ *
17950
+ * @return string
17951
+ */
17952
+ function get_reconnect_url( $params = array() ) {
17953
+ $params['fs_action'] = 'reset_anonymous_mode';
17954
+ $params['fs_unique_affix'] = $this->get_unique_affix();
17955
+
17956
+ return $this->get_activation_url( $params );
17957
+ }
17958
+
17959
+ /**
17960
+ * Get the URL of the page that should be loaded after the user connect
17961
+ * or skip in the opt-in screen.
17962
+ *
17963
+ * @author Vova Feldman (@svovaf)
17964
+ * @since 1.1.3
17965
+ *
17966
+ * @param string $filter Filter name.
17967
+ * @param array $params Since 1.2.2.7
17968
+ * @param bool|null $network
17969
+ *
17970
+ * @return string
17971
+ */
17972
+ function get_after_activation_url( $filter, $params = array(), $network = null ) {
17973
+ if ( $this->is_free_wp_org_theme() &&
17974
+ fs_request_has( 'pending_activation' )
17975
+ ) {
17976
+ $first_time_path = '';
17977
+ } else {
17978
+ $first_time_path = $this->_menu->get_first_time_path();
17979
+ }
17980
+
17981
+ if ( $this->_is_network_active &&
17982
+ fs_is_network_admin() &&
17983
+ ! $this->_menu->has_network_menu() &&
17984
+ $this->is_network_registered()
17985
+ ) {
17986
+ $target_url = $this->get_account_url();
17987
+ } else {
17988
+ // Default plugin's page.
17989
+ $target_url = $this->_get_admin_page_url( '', array(), $network );
17990
+ }
17991
+
17992
+ return add_query_arg( $params, $this->apply_filters(
17993
+ $filter,
17994
+ empty( $first_time_path ) ?
17995
+ $target_url :
17996
+ $first_time_path
17997
+ ) );
17998
+ }
17999
+
18000
+ /**
18001
+ * Handle account page updates / edits / actions.
18002
+ *
18003
+ * @author Vova Feldman (@svovaf)
18004
+ * @since 1.0.2
18005
+ *
18006
+ */
18007
+ private function _handle_account_edits() {
18008
+ if ( ! $this->is_user_admin() ) {
18009
+ return;
18010
+ }
18011
+
18012
+ $action = fs_get_action();
18013
+
18014
+ if ( empty( $action ) ) {
18015
+ return;
18016
+ }
18017
+
18018
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
18019
+ $install_id = fs_request_get( 'install_id', '' );
18020
+
18021
+ // Alias.
18022
+ $oops_text = $this->get_text_x_inline( 'Oops', 'exclamation', 'oops' ) . '...';
18023
+
18024
+ $is_network_action = $this->is_network_level_action();
18025
+ $blog_id = $this->is_network_level_site_specific_action();
18026
+
18027
+ if ( is_numeric( $blog_id ) ) {
18028
+ $this->switch_to_blog( $blog_id );
18029
+ } else {
18030
+ $blog_id = '';
18031
+ }
18032
+
18033
+ switch ( $action ) {
18034
+ case 'opt_in':
18035
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18036
+
18037
+ if ( $plugin_id == $this->get_id() ) {
18038
+ if ( $is_network_action && ! empty( $blog_id ) ) {
18039
+ if ( ! $this->is_registered() ) {
18040
+ $this->install_with_user(
18041
+ $this->get_network_user(),
18042
+ false,
18043
+ false,
18044
+ false,
18045
+ false
18046
+ );
18047
+
18048
+ $this->_admin_notices->add(
18049
+ $this->get_text_inline( 'Site successfully opted in.', 'successful-opt-in' ),
18050
+ $this->get_text_inline( 'Awesome', 'awesome' )
18051
+ );
18052
+ }
18053
+ }
18054
+ }
18055
+ break;
18056
+
18057
+ case 'toggle_tracking':
18058
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18059
+
18060
+ if ( $plugin_id == $this->get_id() ) {
18061
+ if ( $is_network_action && ! empty( $blog_id ) ) {
18062
+ if ( $this->is_registered() ) {
18063
+ if ( $this->is_tracking_prohibited() ) {
18064
+ if ( $this->allow_site_tracking() ) {
18065
+ $this->_admin_notices->add(
18066
+ sprintf( $this->get_text_inline( 'We appreciate your help in making the %s better by letting us track some usage data.', 'opt-out-message-appreciation' ), $this->_module_type ),
18067
+ $this->get_text_inline( 'Thank you!', 'thank-you' )
18068
+ );
18069
+ }
18070
+ } else {
18071
+ if ( $this->stop_site_tracking() ) {
18072
+ $this->_admin_notices->add(
18073
+ sprintf(
18074
+ $this->get_text_inline( 'We will no longer be sending any usage data of %s on %s to %s.', 'opted-out-successfully' ),
18075
+ $this->get_plugin_title(),
18076
+ fs_strip_url_protocol( get_site_url( $blog_id ) ),
18077
+ sprintf(
18078
+ '<a href="%s" target="_blank">%s</a>',
18079
+ 'https://freemius.com',
18080
+ 'freemius.com'
18081
+ )
18082
+ )
18083
+ );
18084
+ }
18085
+ }
18086
+ }
18087
+ }
18088
+ }
18089
+
18090
+ break;
18091
+
18092
+ case 'delete_account':
18093
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18094
+
18095
+ if ( $plugin_id == $this->get_id() ) {
18096
+ if ( $is_network_action && empty( $blog_id ) ) {
18097
+ $this->delete_network_account_event();
18098
+ } else {
18099
+ $this->delete_account_event();
18100
+ }
18101
+
18102
+ // Clear user and site.
18103
+ $this->_site = null;
18104
+ $this->_user = null;
18105
+
18106
+ fs_redirect( $this->get_activation_url() );
18107
+ } else {
18108
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18109
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18110
+ $fs_addon->delete_account_event();
18111
+
18112
+ fs_redirect( $this->_get_admin_page_url( 'account' ) );
18113
+ }
18114
+ }
18115
+
18116
+ return;
18117
+
18118
+ case 'downgrade_account':
18119
+ if ( is_numeric( $blog_id ) ) {
18120
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18121
+ } else {
18122
+ check_admin_referer( $action );
18123
+ }
18124
+
18125
+ if ( $plugin_id == $this->get_id() ) {
18126
+ $this->_downgrade_site();
18127
+
18128
+ if ( is_numeric( $blog_id ) ) {
18129
+ $this->switch_to_blog( $this->_storage->network_install_blog_id );
18130
+ }
18131
+ } else if ( $this->is_addon_activated( $plugin_id ) ) {
18132
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18133
+ $fs_addon->_downgrade_site();
18134
+ }
18135
+
18136
+ return;
18137
+
18138
+ case 'activate_license':
18139
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18140
+
18141
+ $fs = $this;
18142
+ if ( $plugin_id != $this->get_id() ) {
18143
+ $fs = $this->is_addon_activated( $plugin_id ) ?
18144
+ self::get_instance_by_id( $plugin_id ) :
18145
+ null;
18146
+ }
18147
+
18148
+ if ( is_object( $fs ) ) {
18149
+ $fs->_activate_license();
18150
+ }
18151
+
18152
+ return;
18153
+
18154
+ case 'deactivate_license':
18155
+ check_admin_referer( trim( "{$action}:{$blog_id}:{$install_id}", ':' ) );
18156
+
18157
+ if ( $plugin_id == $this->get_id() ) {
18158
+ $this->_deactivate_license();
18159
+
18160
+ if ( $this->is_only_premium() ) {
18161
+ // Clear user and site.
18162
+ $this->_site = null;
18163
+ $this->_user = null;
18164
+
18165
+ fs_redirect( $this->get_activation_url() );
18166
+ }
18167
+ } else {
18168
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18169
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18170
+ $fs_addon->_deactivate_license();
18171
+ }
18172
+ }
18173
+
18174
+ return;
18175
+
18176
+ case 'check_updates':
18177
+ check_admin_referer( $action );
18178
+ $this->check_updates();
18179
+
18180
+ return;
18181
+
18182
+ case 'change_owner':
18183
+ $state = fs_request_get( 'state', 'init' );
18184
+ switch ( $state ) {
18185
+ case 'init':
18186
+ $candidate_email = fs_request_get( 'candidate_email', '' );
18187
+
18188
+ if ( $this->init_change_owner( $candidate_email ) ) {
18189
+ $this->_admin_notices->add( sprintf( $this->get_text_inline( '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.', 'change-owner-request-sent-x' ), '<b>' . $this->_user->email . '</b>' ) );
18190
+ }
18191
+ break;
18192
+ case 'owner_confirmed':
18193
+ $candidate_email = fs_request_get( 'candidate_email', '' );
18194
+
18195
+ $this->_admin_notices->add( sprintf( $this->get_text_inline( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'change-owner-request_owner-confirmed' ), '<b>' . $candidate_email . '</b>' ) );
18196
+ break;
18197
+ case 'candidate_confirmed':
18198
+ if ( $this->complete_change_owner() ) {
18199
+ $this->_admin_notices->add_sticky(
18200
+ sprintf( $this->get_text_inline( '%s is the new owner of the account.', 'change-owner-request_candidate-confirmed' ), '<b>' . $this->_user->email . '</b>' ),
18201
+ 'ownership_changed',
18202
+ $this->get_text_x_inline( 'Congrats', 'as congratulations', 'congrats' ) . '!'
18203
+ );
18204
+ } else {
18205
+ // @todo Handle failed ownership change message.
18206
+ }
18207
+ break;
18208
+ }
18209
+
18210
+ return;
18211
+
18212
+ case 'update_email':
18213
+ check_admin_referer( 'update_email' );
18214
+
18215
+ $new_email = fs_request_get( 'fs_email_' . $this->get_unique_affix(), '' );
18216
+ $result = $this->update_email( $new_email );
18217
+
18218
+ if ( isset( $result->error ) ) {
18219
+ switch ( $result->error->code ) {
18220
+ case 'user_exist':
18221
+ $this->_admin_notices->add(
18222
+ $this->get_text_inline( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'user-exist-message' ) . ' ' .
18223
+ sprintf( $this->get_text_inline( 'If you would like to give up the ownership of the %s\'s account to %s click the Change Ownership button.', 'user-exist-message_ownership' ), $this->_module_type, '<b>' . $new_email . '</b>' ) .
18224
+ sprintf(
18225
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
18226
+ $this->get_account_url( 'change_owner', array(
18227
+ 'state' => 'init',
18228
+ 'candidate_email' => $new_email
18229
+ ) ),
18230
+ $this->get_text_inline( 'Change Ownership', 'change-ownership' )
18231
+ ),
18232
+ $oops_text,
18233
+ 'error'
18234
+ );
18235
+ break;
18236
+ }
18237
+ } else {
18238
+ $this->_admin_notices->add( $this->get_text_inline( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'email-updated-message' ) );
18239
+ }
18240
+
18241
+ return;
18242
+
18243
+ case 'update_user_name':
18244
+ check_admin_referer( 'update_user_name' );
18245
+
18246
+ $result = $this->update_user_name();
18247
+
18248
+ if ( isset( $result->error ) ) {
18249
+ $this->_admin_notices->add(
18250
+ $this->get_text_inline( 'Please provide your full name.', 'name-update-failed-message' ),
18251
+ $oops_text,
18252
+ 'error'
18253
+ );
18254
+ } else {
18255
+ $this->_admin_notices->add( $this->get_text_inline( 'Your name was successfully updated.', 'name-updated-message' ) );
18256
+ }
18257
+
18258
+ return;
18259
+
18260
+ #region Actions that might be called from external links (e.g. email)
18261
+
18262
+ case 'cancel_trial':
18263
+ if ( $plugin_id == $this->get_id() ) {
18264
+ $this->_cancel_trial();
18265
+ } else {
18266
+ if ( $this->is_addon_activated( $plugin_id ) ) {
18267
+ $fs_addon = self::get_instance_by_id( $plugin_id );
18268
+ $fs_addon->_cancel_trial();
18269
+ }
18270
+ }
18271
+
18272
+ return;
18273
+
18274
+ case 'verify_email':
18275
+ $this->verify_email();
18276
+
18277
+ return;
18278
+
18279
+ case 'sync_user':
18280
+ $this->_handle_account_user_sync();
18281
+
18282
+ return;
18283
+
18284
+ case $this->get_unique_affix() . '_sync_license':
18285
+ $this->_sync_license();
18286
+
18287
+ return;
18288
+
18289
+ case 'download_latest':
18290
+ $this->download_latest_directly( $plugin_id );
18291
+
18292
+ return;
18293
+
18294
+ #endregion
18295
+ }
18296
+
18297
+ if ( WP_FS__IS_POST_REQUEST ) {
18298
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
18299
+ foreach ( $properties as $p ) {
18300
+ if ( 'update_' . $p === $action ) {
18301
+ check_admin_referer( $action );
18302
+
18303
+ $this->_logger->log( $action );
18304
+
18305
+ $site_property = substr( $p, strlen( 'site_' ) );
18306
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->get_unique_affix(), '' );
18307
+ $this->get_site()->{$site_property} = $site_property_value;
18308
+
18309
+ // Store account after modification.
18310
+ $this->_store_site();
18311
+
18312
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
18313
+
18314
+ $this->_admin_notices->add( sprintf(
18315
+ /* translators: %s: User's account property (e.g. email address, name) */
18316
+ $this->get_text_inline( 'You have successfully updated your %s.', 'x-updated' ),
18317
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>'
18318
+ ) );
18319
+
18320
+ return;
18321
+ }
18322
+ }
18323
+ }
18324
+ }
18325
+
18326
+ /**
18327
+ * Account page resources load.
18328
+ *
18329
+ * @author Vova Feldman (@svovaf)
18330
+ * @since 1.0.6
18331
+ */
18332
+ function _account_page_load() {
18333
+ $this->_logger->entrance();
18334
+
18335
+ $this->_logger->info( var_export( $_REQUEST, true ) );
18336
+
18337
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
18338
+
18339
+ if ( $this->has_addons() ) {
18340
+ wp_enqueue_script( 'plugin-install' );
18341
+ add_thickbox();
18342
+
18343
+ function fs_addons_body_class( $classes ) {
18344
+ $classes .= ' plugins-php';
18345
+
18346
+ return $classes;
18347
+ }
18348
+
18349
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
18350
+ }
18351
+
18352
+ if ( $this->has_paid_plan() &&
18353
+ ! $this->has_any_license() &&
18354
+ ! $this->is_sync_executed() &&
18355
+ $this->is_tracking_allowed()
18356
+ ) {
18357
+ /**
18358
+ * If no licenses found and no sync job was executed during the last 24 hours,
18359
+ * just execute the sync job right away (blocking execution).
18360
+ *
18361
+ * @since 1.1.7.3
18362
+ */
18363
+ $this->run_manual_sync();
18364
+ }
18365
+
18366
+ $this->_handle_account_edits();
18367
+
18368
+ $this->do_action( 'account_page_load_before_departure' );
18369
+ }
18370
+
18371
+ /**
18372
+ * Renders the "Affiliation" page.
18373
+ *
18374
+ * @author Leo Fajardo (@leorw)
18375
+ * @since 1.2.3
18376
+ */
18377
+ function _affiliation_page_render() {
18378
+ $this->_logger->entrance();
18379
+
18380
+ $this->fetch_affiliate_and_terms();
18381
+
18382
+ fs_enqueue_local_style( 'fs_affiliation', '/admin/affiliation.css' );
18383
+
18384
+ $vars = array( 'id' => $this->_module_id );
18385
+ echo $this->apply_filters( "/forms/affiliation.php", fs_get_template( '/forms/affiliation.php', $vars ) );
18386
+ }
18387
+
18388
+
18389
+ /**
18390
+ * Render account page.
18391
+ *
18392
+ * @author Vova Feldman (@svovaf)
18393
+ * @since 1.0.0
18394
+ */
18395
+ function _account_page_render() {
18396
+ $this->_logger->entrance();
18397
+
18398
+ $template = 'account.php';
18399
+ $vars = array( 'id' => $this->_module_id );
18400
+
18401
+ /**
18402
+ * Added filter to the template to allow developers wrapping the template
18403
+ * in custom HTML (e.g. within a wizard/tabs).
18404
+ *
18405
+ * @author Vova Feldman (@svovaf)
18406
+ * @since 1.2.1.6
18407
+ */
18408
+ echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
18409
+ }
18410
+
18411
+ /**
18412
+ * Render account connect page.
18413
+ *
18414
+ * @author Vova Feldman (@svovaf)
18415
+ * @since 1.0.7
18416
+ */
18417
+ function _connect_page_render() {
18418
+ $this->_logger->entrance();
18419
+
18420
+ $vars = array( 'id' => $this->_module_id );
18421
+
18422
+ /**
18423
+ * Added filter to the template to allow developers wrapping the template
18424
+ * in custom HTML (e.g. within a wizard/tabs).
18425
+ *
18426
+ * @author Vova Feldman (@svovaf)
18427
+ * @since 1.2.1.6
18428
+ */
18429
+ echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
18430
+ }
18431
+
18432
+ /**
18433
+ * Load required resources before add-ons page render.
18434
+ *
18435
+ * @author Vova Feldman (@svovaf)
18436
+ * @since 1.0.6
18437
+ */
18438
+ function _addons_page_load() {
18439
+ $this->_logger->entrance();
18440
+
18441
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
18442
+
18443
+ wp_enqueue_script( 'plugin-install' );
18444
+ add_thickbox();
18445
+
18446
+ function fs_addons_body_class( $classes ) {
18447
+ $classes .= ' plugins-php';
18448
+
18449
+ return $classes;
18450
+ }
18451
+
18452
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
18453
+
18454
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
18455
+ $this->_admin_notices->add(
18456
+ sprintf( $this->get_text_inline( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
18457
+ $this->get_text_x_inline( 'Heads up', 'advance notice of something that will need attention.', 'heads-up' ),
18458
+ 'update-nag'
18459
+ );
18460
+ }
18461
+ }
18462
+
18463
+ /**
18464
+ * Render add-ons page.
18465
+ *
18466
+ * @author Vova Feldman (@svovaf)
18467
+ * @since 1.0.6
18468
+ */
18469
+ function _addons_page_render() {
18470
+ $this->_logger->entrance();
18471
+
18472
+ $vars = array( 'id' => $this->_module_id );
18473
+
18474
+ /**
18475
+ * Added filter to the template to allow developers wrapping the template
18476
+ * in custom HTML (e.g. within a wizard/tabs).
18477
+ *
18478
+ * @author Vova Feldman (@svovaf)
18479
+ * @since 1.2.1.6
18480
+ */
18481
+ echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
18482
+ }
18483
+
18484
+ /* Pricing & Upgrade
18485
+ ------------------------------------------------------------------------------------------------------------------*/
18486
+ /**
18487
+ * Render pricing page.
18488
+ *
18489
+ * @author Vova Feldman (@svovaf)
18490
+ * @since 1.0.0
18491
+ */
18492
+ function _pricing_page_render() {
18493
+ $this->_logger->entrance();
18494
+
18495
+ $vars = array( 'id' => $this->_module_id );
18496
+
18497
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
18498
+ echo $this->apply_filters( 'templates/checkout.php', fs_get_template( 'checkout.php', $vars ) );
18499
+ } else {
18500
+ echo $this->apply_filters( 'templates/pricing.php', fs_get_template( 'pricing.php', $vars ) );
18501
+ }
18502
+ }
18503
+
18504
+ #----------------------------------------------------------------------------------
18505
+ #region Contact Us
18506
+ #----------------------------------------------------------------------------------
18507
+
18508
+ /**
18509
+ * Render contact-us page.
18510
+ *
18511
+ * @author Vova Feldman (@svovaf)
18512
+ * @since 1.0.3
18513
+ */
18514
+ function _contact_page_render() {
18515
+ $this->_logger->entrance();
18516
+
18517
+ $vars = array( 'id' => $this->_module_id );
18518
+
18519
+ /**
18520
+ * Added filter to the template to allow developers wrapping the template
18521
+ * in custom HTML (e.g. within a wizard/tabs).
18522
+ *
18523
+ * @author Vova Feldman (@svovaf)
18524
+ * @since 2.1.3
18525
+ */
18526
+ echo $this->apply_filters( 'templates/contact.php', fs_get_template( 'contact.php', $vars ) );
18527
+ }
18528
+
18529
+ #endregion ------------------------------------------------------------------------
18530
+
18531
+ /**
18532
+ * Hide all admin notices to prevent distractions.
18533
+ *
18534
+ * @author Vova Feldman (@svovaf)
18535
+ * @since 1.0.3
18536
+ *
18537
+ * @uses remove_all_actions()
18538
+ */
18539
+ private static function _hide_admin_notices() {
18540
+ remove_all_actions( 'admin_notices' );
18541
+ remove_all_actions( 'network_admin_notices' );
18542
+ remove_all_actions( 'all_admin_notices' );
18543
+ remove_all_actions( 'user_admin_notices' );
18544
+ }
18545
+
18546
+ static function _clean_admin_content_section_hook() {
18547
+ self::_hide_admin_notices();
18548
+
18549
+ // Hide footer.
18550
+ echo '<style>#wpfooter { display: none !important; }</style>';
18551
+ }
18552
+
18553
+ /**
18554
+ * Attach to admin_head hook to hide all admin notices.
18555
+ *
18556
+ * @author Vova Feldman (@svovaf)
18557
+ * @since 1.0.3
18558
+ */
18559
+ static function _clean_admin_content_section() {
18560
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
18561
+ }
18562
+
18563
+ /* CSS & JavaScript
18564
+ ------------------------------------------------------------------------------------------------------------------*/
18565
+ /* function _enqueue_script($handle, $src) {
18566
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
18567
+
18568
+ $this->_logger->entrance( 'script = ' . $url );
18569
+
18570
+ wp_enqueue_script( $handle, $url );
18571
+ }*/
18572
+
18573
+ /* SDK
18574
+ ------------------------------------------------------------------------------------------------------------------*/
18575
+ private $_user_api;
18576
+
18577
+ /**
18578
+ *
18579
+ * @author Vova Feldman (@svovaf)
18580
+ * @since 1.0.2
18581
+ *
18582
+ * @param bool $flush
18583
+ *
18584
+ * @return FS_Api
18585
+ */
18586
+ private function get_api_user_scope( $flush = false ) {
18587
+ if ( ! isset( $this->_user_api ) || $flush ) {
18588
+ $this->_user_api = $this->get_api_user_scope_by_user( $this->_user );
18589
+ }
18590
+
18591
+ return $this->_user_api;
18592
+ }
18593
+
18594
+ /**
18595
+ * @author Vova Feldman (@svovaf)
18596
+ * @since 2.0.0
18597
+ *
18598
+ * @param \FS_User $user
18599
+ *
18600
+ * @return \FS_Api
18601
+ */
18602
+ private function get_api_user_scope_by_user( FS_User $user ) {
18603
+ return FS_Api::instance(
18604
+ $this->_module_id,
18605
+ 'user',
18606
+ $user->id,
18607
+ $user->public_key,
18608
+ ! $this->is_live(),
18609
+ $user->secret_key
18610
+ );
18611
+ }
18612
+
18613
+ /**
18614
+ *
18615
+ * @author Leo Fajardo (@leorw)
18616
+ * @since 2.0.0
18617
+ *
18618
+ * @param bool $flush
18619
+ *
18620
+ * @return FS_Api
18621
+ */
18622
+ private function get_current_or_network_user_api_scope( $flush = false ) {
18623
+ if ( ! $this->_is_network_active ||
18624
+ ( isset( $this->_user ) && $this->_user instanceof FS_User )
18625
+ ) {
18626
+ return $this->get_api_user_scope( $flush );
18627
+ }
18628
+
18629
+ $user = $this->get_current_or_network_user();
18630
+
18631
+ $this->_user_api = FS_Api::instance(
18632
+ $this->_module_id,
18633
+ 'user',
18634
+ $user->id,
18635
+ $user->public_key,
18636
+ ! $this->is_live(),
18637
+ $user->secret_key
18638
+ );
18639
+
18640
+ return $this->_user_api;
18641
+ }
18642
+
18643
+ private $_site_api;
18644
+
18645
+ /**
18646
+ *
18647
+ * @author Vova Feldman (@svovaf)
18648
+ * @since 1.0.2
18649
+ *
18650
+ * @param bool $flush
18651
+ *
18652
+ * @return FS_Api
18653
+ */
18654
+ private function get_api_site_scope( $flush = false ) {
18655
+ if ( ! isset( $this->_site_api ) || $flush ) {
18656
+ $this->_site_api = FS_Api::instance(
18657
+ $this->_module_id,
18658
+ 'install',
18659
+ $this->_site->id,
18660
+ $this->_site->public_key,
18661
+ ! $this->is_live(),
18662
+ $this->_site->secret_key
18663
+ );
18664
+ }
18665
+
18666
+ return $this->_site_api;
18667
+ }
18668
+
18669
+ private $_plugin_api;
18670
+
18671
+ /**
18672
+ * Get plugin public API scope.
18673
+ *
18674
+ * @author Vova Feldman (@svovaf)
18675
+ * @since 1.0.7
18676
+ *
18677
+ * @return FS_Api
18678
+ */
18679
+ function get_api_plugin_scope() {
18680
+ if ( ! isset( $this->_plugin_api ) ) {
18681
+ $this->_plugin_api = FS_Api::instance(
18682
+ $this->_module_id,
18683
+ 'plugin',
18684
+ $this->_plugin->id,
18685
+ $this->_plugin->public_key,
18686
+ ! $this->is_live()
18687
+ );
18688
+ }
18689
+
18690
+ return $this->_plugin_api;
18691
+ }
18692
+
18693
+ /**
18694
+ * Get site API scope object (fallback to public plugin scope when not registered).
18695
+ *
18696
+ * @author Vova Feldman (@svovaf)
18697
+ * @since 1.0.7
18698
+ *
18699
+ * @return FS_Api
18700
+ */
18701
+ function get_api_site_or_plugin_scope() {
18702
+ return $this->is_registered() ?
18703
+ $this->get_api_site_scope() :
18704
+ $this->get_api_plugin_scope();
18705
+ }
18706
+
18707
+ /**
18708
+ * Show trial promotional notice (if any trial exist).
18709
+ *
18710
+ * @author Vova Feldman (@svovaf)
18711
+ * @since 1.0.9
18712
+ *
18713
+ * @param FS_Plugin_Plan[] $plans
18714
+ */
18715
+ function _check_for_trial_plans( $plans ) {
18716
+ /**
18717
+ * For some reason core's do_action() flattens arrays when it has a single object item. Therefore, we need to restructure the array as expected.
18718
+ *
18719
+ * @author Vova Feldman (@svovaf)
18720
+ * @since 2.1.2
18721
+ */
18722
+ if ( ! is_array( $plans ) && is_object( $plans ) ) {
18723
+ $plans = array( $plans );
18724
+ }
18725
+
18726
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
18727
+ }
18728
+
18729
+ /**
18730
+ * During trial promotion the "upgrade" submenu item turns to
18731
+ * "start trial" to encourage the trial. Since we want to keep
18732
+ * the same menu item handler and there's no robust way to
18733
+ * add new arguments to the menu item link's querystring,
18734
+ * use JavaScript to find the menu item and update the href of
18735
+ * the link.
18736
+ *
18737
+ * @author Vova Feldman (@svovaf)
18738
+ * @since 1.2.1.5
18739
+ */
18740
+ function _fix_start_trial_menu_item_url() {
18741
+ $template_args = array( 'id' => $this->_module_id );
18742
+ fs_require_template( 'add-trial-to-pricing.php', $template_args );
18743
+ }
18744
+
18745
+ /**
18746
+ * Check if module is currently in a trial promotion mode.
18747
+ *
18748
+ * @author Vova Feldman (@svovaf)
18749
+ * @since 1.2.2.7
18750
+ *
18751
+ * @return bool
18752
+ */
18753
+ function is_in_trial_promotion() {
18754
+ return $this->_admin_notices->has_sticky( 'trial_promotion' );
18755
+ }
18756
+
18757
+ /**
18758
+ * Show trial promotional notice (if any trial exist).
18759
+ *
18760
+ * @author Vova Feldman (@svovaf)
18761
+ * @since 1.0.9
18762
+ *
18763
+ * @return bool If trial notice added.
18764
+ */
18765
+ function _add_trial_notice() {
18766
+ if ( ! $this->is_user_admin() ) {
18767
+ return false;
18768
+ }
18769
+
18770
+ if ( ! $this->is_user_in_admin() ) {
18771
+ return false;
18772
+ }
18773
+
18774
+ if ( $this->_is_network_active ) {
18775
+ if ( fs_is_network_admin() ) {
18776
+ // Network level trial is disabled at the moment.
18777
+ return false;
18778
+ }
18779
+
18780
+ if ( ! $this->is_delegated_connection() ) {
18781
+ // Only delegated sites should support trials.
18782
+ return false;
18783
+ }
18784
+ }
18785
+
18786
+ // Check if trial message is already shown.
18787
+ if ( $this->is_in_trial_promotion() ) {
18788
+ add_action( 'admin_footer', array( &$this, '_fix_start_trial_menu_item_url' ) );
18789
+
18790
+ $this->_menu->add_counter_to_menu_item( 1, 'fs-trial' );
18791
+
18792
+ return false;
18793
+ }
18794
+
18795
+ if ( $this->is_premium() && ! WP_FS__DEV_MODE ) {
18796
+ // Don't show trial if running the premium code, unless running in DEV mode.
18797
+ return false;
18798
+ }
18799
+
18800
+ if ( ! $this->has_trial_plan() ) {
18801
+ // No plans with trial.
18802
+ return false;
18803
+ }
18804
+
18805
+ if ( ! $this->apply_filters( 'show_trial', true ) ) {
18806
+ // Developer explicitly asked not to show the trial promo.
18807
+ return false;
18808
+ }
18809
+
18810
+ if ( $this->is_registered() ) {
18811
+ // Check if trial already utilized.
18812
+ if ( $this->_site->is_trial_utilized() ) {
18813
+ return false;
18814
+ }
18815
+
18816
+ if ( $this->is_paying_or_trial() ) {
18817
+ // Don't show trial if paying or already in trial.
18818
+ return false;
18819
+ }
18820
+ }
18821
+
18822
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
18823
+ // If not yet opted-in/skipped, or pending activation, don't show trial.
18824
+ return false;
18825
+ }
18826
+
18827
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
18828
+ $was_promotion_shown_before = ( false !== $last_time_trial_promotion_shown );
18829
+
18830
+ // Show promotion if never shown before and 24 hours after initial activation with FS.
18831
+ if ( ! $was_promotion_shown_before &&
18832
+ $this->_storage->install_timestamp > ( time() - $this->apply_filters( 'show_first_trial_after_n_sec', WP_FS__TIME_24_HOURS_IN_SEC ) )
18833
+ ) {
18834
+ return false;
18835
+ }
18836
+
18837
+ // OR if promotion was shown before, try showing it every 30 days.
18838
+ if ( $was_promotion_shown_before &&
18839
+ $this->apply_filters( 'reshow_trial_after_every_n_sec', 30 * WP_FS__TIME_24_HOURS_IN_SEC ) > time() - $last_time_trial_promotion_shown
18840
+ ) {
18841
+ return false;
18842
+ }
18843
+
18844
+ $trial_period = $this->_trial_days;
18845
+ $require_payment = $this->_is_trial_require_payment;
18846
+ $trial_url = $this->get_trial_url();
18847
+ $plans_string = strtolower( $this->get_text_inline( 'Awesome', 'awesome' ) );
18848
+
18849
+ if ( $this->is_registered() ) {
18850
+ // If opted-in, override trial with up to date data from API.
18851
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
18852
+ $trial_plans_count = count( $trial_plans );
18853
+
18854
+ if ( 0 === $trial_plans_count ) {
18855
+ // If there's no plans with a trial just exit.
18856
+ return false;
18857
+ }
18858
+
18859
+ /**
18860
+ * @var FS_Plugin_Plan $paid_plan
18861
+ */
18862
+ $paid_plan = $trial_plans[0];
18863
+ $require_payment = $paid_plan->is_require_subscription;
18864
+ $trial_period = $paid_plan->trial_period;
18865
+
18866
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
18867
+
18868
+ if ( $total_paid_plans !== $trial_plans_count ) {
18869
+ // Not all paid plans have a trial - generate a string of those that have it.
18870
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
18871
+ $plans_string .= sprintf(
18872
+ ' <a href="%s">%s</a>',
18873
+ $trial_url,
18874
+ $trial_plans[ $i ]->title
18875
+ );
18876
+
18877
+ if ( $i < $trial_plans_count - 2 ) {
18878
+ $plans_string .= ', ';
18879
+ } else if ( $i == $trial_plans_count - 2 ) {
18880
+ $plans_string .= ' and ';
18881
+ }
18882
+ }
18883
+ }
18884
+ }
18885
+
18886
+ $message = sprintf(
18887
+ $this->get_text_x_inline( 'Hey', 'exclamation', 'hey' ) . '! ' . $this->get_text_inline( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'trial-x-promotion-message' ),
18888
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
18889
+ $plans_string,
18890
+ $trial_period
18891
+ );
18892
+
18893
+ // "No Credit-Card Required" or "No Commitment for N Days".
18894
+ $cc_string = $require_payment ?
18895
+ sprintf( $this->get_text_inline( 'No commitment for %s days - cancel anytime!', 'no-commitment-for-x-days' ), $trial_period ) :
18896
+ $this->get_text_inline( 'No credit card required', 'no-cc-required' ) . '!';
18897
+
18898
+
18899
+ // Start trial button.
18900
+ $button = ' ' . sprintf(
18901
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
18902
+ $trial_url,
18903
+ $this->get_text_x_inline( 'Start free trial', 'call to action', 'start-free-trial' )
18904
+ );
18905
+
18906
+ $this->_admin_notices->add_sticky(
18907
+ $this->apply_filters( 'trial_promotion_message', "{$message} {$cc_string} {$button}" ),
18908
+ 'trial_promotion',
18909
+ '',
18910
+ 'promotion'
18911
+ );
18912
+
18913
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
18914
+
18915
+ return true;
18916
+ }
18917
+
18918
+ /**
18919
+ * Lets users/customers know that the product has an affiliate program.
18920
+ *
18921
+ * @author Leo Fajardo (@leorw)
18922
+ * @since 1.2.2.11
18923
+ *
18924
+ * @return bool Returns true if the notice has been added.
18925
+ */
18926
+ function _add_affiliate_program_notice() {
18927
+ if ( ! $this->is_user_admin() ) {
18928
+ return false;
18929
+ }
18930
+
18931
+ if ( ! $this->is_user_in_admin() ) {
18932
+ return false;
18933
+ }
18934
+
18935
+ // Check if the notice is already shown.
18936
+ if ( $this->_admin_notices->has_sticky( 'affiliate_program' ) ) {
18937
+ return false;
18938
+ }
18939
+
18940
+ if (
18941
+ // Product has no affiliate program.
18942
+ ! $this->has_affiliate_program() ||
18943
+ // User has applied for an affiliate account.
18944
+ ! empty( $this->_storage->affiliate_application_data )
18945
+ ) {
18946
+ return false;
18947
+ }
18948
+
18949
+ if ( ! $this->apply_filters( 'show_affiliate_program_notice', true ) ) {
18950
+ // Developer explicitly asked not to show the notice about the affiliate program.
18951
+ return false;
18952
+ }
18953
+
18954
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
18955
+ // If not yet opted in/skipped, or pending activation, don't show the notice.
18956
+ return false;
18957
+ }
18958
+
18959
+ $last_time_notice_was_shown = $this->_storage->get( 'affiliate_program_notice_shown', false );
18960
+ $was_notice_shown_before = ( false !== $last_time_notice_was_shown );
18961
+
18962
+ /**
18963
+ * Do not show the notice if it was already shown before or less than 30 days have passed since the initial
18964
+ * activation with FS.
18965
+ */
18966
+ if ( $was_notice_shown_before ||
18967
+ $this->_storage->install_timestamp > ( time() - ( WP_FS__TIME_24_HOURS_IN_SEC * 30 ) )
18968
+ ) {
18969
+ return false;
18970
+ }
18971
+
18972
+ if ( ! $this->is_paying() &&
18973
+ FS_Plugin::AFFILIATE_MODERATION_CUSTOMERS == $this->_plugin->affiliate_moderation
18974
+ ) {
18975
+ // If the user is not a customer and the affiliate program is only for customers, don't show the notice.
18976
+ return false;
18977
+ }
18978
+
18979
+ $message = sprintf(
18980
+ $this->get_text_inline( 'Hey there, did you know that %s has an affiliate program? If you like the %s you can become our ambassador and earn some cash!', 'become-an-ambassador-admin-notice' ),
18981
+ sprintf( '<strong>%s</strong>', $this->get_plugin_name() ),
18982
+ $this->get_module_label( true )
18983
+ );
18984
+
18985
+ // HTML code for the "Learn more..." button.
18986
+ $button = ' ' . sprintf(
18987
+ '<a style="display: block; margin-top: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
18988
+ $this->_get_admin_page_url( 'affiliation' ),
18989
+ $this->get_text_inline( 'Learn more', 'learn-more' ) . '...'
18990
+ );
18991
+
18992
+ $this->_admin_notices->add_sticky(
18993
+ $this->apply_filters( 'affiliate_program_notice', "{$message} {$button}" ),
18994
+ 'affiliate_program',
18995
+ '',
18996
+ 'promotion'
18997
+ );
18998
+
18999
+ $this->_storage->affiliate_program_notice_shown = WP_FS__SCRIPT_START_TIME;
19000
+
19001
+ return true;
19002
+ }
19003
+
19004
+ /**
19005
+ * @author Vova Feldman (@svovaf)
19006
+ * @since 1.2.1.5
19007
+ */
19008
+ function _enqueue_common_css() {
19009
+ if ( $this->has_paid_plan() && ! $this->is_paying() ) {
19010
+ // Add basic CSS for admin-notices and menu-item colors.
19011
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
19012
+ }
19013
+ }
19014
+
19015
+ /**
19016
+ * @author Leo Fajardo (@leorw)
19017
+ * @since 1.2.2
19018
+ */
19019
+ function _show_theme_activation_optin_dialog() {
19020
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
19021
+
19022
+ add_action( 'admin_footer-themes.php', array( &$this, '_add_fs_theme_activation_dialog' ) );
19023
+ }
19024
+
19025
+ /**
19026
+ * @author Leo Fajardo (@leorw)
19027
+ * @since 1.2.2
19028
+ */
19029
+ function _add_fs_theme_activation_dialog() {
19030
+ $vars = array( 'id' => $this->_module_id );
19031
+ fs_require_once_template( 'connect.php', $vars );
19032
+ }
19033
+
19034
+ /* Action Links
19035
+ ------------------------------------------------------------------------------------------------------------------*/
19036
+ private $_action_links_hooked = false;
19037
+ private $_action_links = array();
19038
+
19039
+ /**
19040
+ * Hook to plugin action links filter.
19041
+ *
19042
+ * @author Vova Feldman (@svovaf)
19043
+ * @since 1.0.0
19044
+ */
19045
+ private function hook_plugin_action_links() {
19046
+ $this->_logger->entrance();
19047
+
19048
+ $this->_action_links_hooked = true;
19049
+
19050
+ $this->_logger->log( 'Adding action links hooks.' );
19051
+
19052
+ // Add action link to settings page.
19053
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
19054
+ &$this,
19055
+ '_modify_plugin_action_links_hook'
19056
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
19057
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
19058
+ &$this,
19059
+ '_modify_plugin_action_links_hook'
19060
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
19061
+ }
19062
+
19063
+ /**
19064
+ * Add plugin action link.
19065
+ *
19066
+ * @author Vova Feldman (@svovaf)
19067
+ * @since 1.0.0
19068
+ *
19069
+ * @param $label
19070
+ * @param $url
19071
+ * @param bool $external
19072
+ * @param int $priority
19073
+ * @param bool $key
19074
+ */
19075
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
19076
+ $this->_logger->entrance();
19077
+
19078
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
19079
+ $this->_action_links[ $priority ] = array();
19080
+ }
19081
+
19082
+ if ( false === $key ) {
19083
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
19084
+ }
19085
+
19086
+ $this->_action_links[ $priority ][] = array(
19087
+ 'label' => $label,
19088
+ 'href' => $url,
19089
+ 'key' => $key,
19090
+ 'external' => $external
19091
+ );
19092
+ }
19093
+
19094
+ /**
19095
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
19096
+ *
19097
+ * @author Vova Feldman (@svovaf)
19098
+ * @since 1.0.0
19099
+ */
19100
+ function _add_upgrade_action_link() {
19101
+ $this->_logger->entrance();
19102
+
19103
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
19104
+ $this->add_plugin_action_link(
19105
+ $this->get_text_inline( 'Upgrade', 'upgrade' ),
19106
+ $this->get_upgrade_url(),
19107
+ false,
19108
+ 7,
19109
+ 'upgrade'
19110
+ );
19111
+ }
19112
+
19113
+ if ( $this->has_addons() ) {
19114
+ $this->add_plugin_action_link(
19115
+ $this->get_text_inline( 'Add-Ons', 'add-ons' ),
19116
+ $this->_get_admin_page_url( 'addons' ),
19117
+ false,
19118
+ 9,
19119
+ 'addons'
19120
+ );
19121
+ }
19122
+ }
19123
+
19124
+ /**
19125
+ * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
19126
+ *
19127
+ * @author Leo Fajardo (@leorw)
19128
+ * @since 1.1.9
19129
+ */
19130
+ function _add_license_action_link() {
19131
+ $this->_logger->entrance();
19132
+
19133
+ if ( ! self::is_ajax() ) {
19134
+ // Inject license activation dialog UI and client side code.
19135
+ add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
19136
+ }
19137
+
19138
+ $link_text = $this->is_free_plan() ?
19139
+ $this->get_text_inline( 'Activate License', 'activate-license' ) :
19140
+ $this->get_text_inline( 'Change License', 'change-license' );
19141
+
19142
+ $this->add_plugin_action_link(
19143
+ $link_text,
19144
+ '#',
19145
+ false,
19146
+ 11,
19147
+ ( 'activate-license ' . $this->get_unique_affix() )
19148
+ );
19149
+ }
19150
+
19151
+ /**
19152
+ * @author Leo Fajardo (@leorw)
19153
+ * @since 2.0.2
19154
+ */
19155
+ function _add_premium_version_upgrade_selection_action() {
19156
+ $this->_logger->entrance();
19157
+
19158
+ if ( ! self::is_ajax() ) {
19159
+ add_action( 'admin_footer', array( &$this, '_add_premium_version_upgrade_selection_dialog_box' ) );
19160
+ }
19161
+ }
19162
+
19163
+ /**
19164
+ * Adds "Opt in" or "Opt out" link to the main "Plugins" page link actions collection.
19165
+ *
19166
+ * @author Leo Fajardo (@leorw)
19167
+ * @since 1.2.1.5
19168
+ */
19169
+ function _add_tracking_links() {
19170
+ if ( ! current_user_can( 'manage_options' ) ) {
19171
+ return;
19172
+ }
19173
+
19174
+ $this->_logger->entrance();
19175
+
19176
+ /**
19177
+ * If the activation has been delegated to site admins, no tracking-related actions for now.
19178
+ *
19179
+ * @author Leo Fajardo (@leorw)
19180
+ */
19181
+ if ( $this->_is_network_active && $this->is_network_delegated_connection() ) {
19182
+ return;
19183
+ }
19184
+
19185
+ if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
19186
+ if ( ! $this->is_registered() && $this->is_anonymous() ) {
19187
+ $this->connect_again();
19188
+
19189
+ return;
19190
+ }
19191
+ }
19192
+
19193
+ if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
19194
+ ( $this->is_theme() && ! self::is_themes_page() )
19195
+ ) {
19196
+ // Only show tracking links on the plugins and themes pages.
19197
+ return;
19198
+ }
19199
+
19200
+ if ( ! $this->is_enable_anonymous() ) {
19201
+ // Don't allow to opt-out if anonymous mode is disabled.
19202
+ return;
19203
+ }
19204
+
19205
+ if ( ! $this->is_free_plan() ) {
19206
+ // Don't allow to opt-out if running in paid plan.
19207
+ return;
19208
+ }
19209
+
19210
+ if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
19211
+ return;
19212
+ }
19213
+
19214
+ if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
19215
+ return;
19216
+ }
19217
+
19218
+ $url = '#';
19219
+
19220
+ if ( $this->is_registered() ) {
19221
+ if ( $this->is_tracking_allowed() ) {
19222
+ $link_text_id = $this->get_text_inline( 'Opt Out', 'opt-out' );
19223
+ } else {
19224
+ $link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
19225
+ }
19226
+
19227
+ add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
19228
+ } else {
19229
+ $link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
19230
+
19231
+ $params = ! $this->is_anonymous() ?
19232
+ array() :
19233
+ array(
19234
+ 'nonce' => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
19235
+ 'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
19236
+ );
19237
+
19238
+ $url = $this->get_activation_url( $params );
19239
+ }
19240
+
19241
+ if ( $this->is_plugin() && self::is_plugins_page() ) {
19242
+ $this->add_plugin_action_link(
19243
+ $link_text_id,
19244
+ $url,
19245
+ false,
19246
+ 13,
19247
+ "opt-in-or-opt-out {$this->_slug}"
19248
+ );
19249
+ }
19250
+ }
19251
+
19252
+ /**
19253
+ * Get the URL of the page that should be loaded right after the plugin activation.
19254
+ *
19255
+ * @author Vova Feldman (@svovaf)
19256
+ * @since 1.1.7.4
19257
+ *
19258
+ * @return string
19259
+ */
19260
+ function get_after_plugin_activation_redirect_url() {
19261
+ $url = false;
19262
+
19263
+ if ( ! $this->is_addon() || ! $this->has_free_plan() ) {
19264
+ $first_time_path = $this->_menu->get_first_time_path();
19265
+ $url = $this->is_activation_mode() ?
19266
+ $this->get_activation_url() :
19267
+ ( empty( $first_time_path ) ?
19268
+ $this->_get_admin_page_url() :
19269
+ $first_time_path );
19270
+ } else {
19271
+ $plugin_fs = false;
19272
+
19273
+ if ( $this->is_parent_plugin_installed() ) {
19274
+ $plugin_fs = self::get_parent_instance();
19275
+ }
19276
+
19277
+ if ( is_object( $plugin_fs ) ) {
19278
+ if ( ! $plugin_fs->is_registered() ) {
19279
+ // Forward to parent plugin connect when parent not registered.
19280
+ $url = $plugin_fs->get_activation_url();
19281
+ } else {
19282
+ // Forward to account page.
19283
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
19284
+ }
19285
+ }
19286
+ }
19287
+
19288
+ return $url;
19289
+ }
19290
+
19291
+ /**
19292
+ * Forward page to activation page.
19293
+ *
19294
+ * @author Vova Feldman (@svovaf)
19295
+ * @since 1.0.3
19296
+ */
19297
+ function _redirect_on_activation_hook() {
19298
+ $url = $this->get_after_plugin_activation_redirect_url();
19299
+
19300
+ if ( is_string( $url ) ) {
19301
+ fs_redirect( $url );
19302
+ }
19303
+ }
19304
+
19305
+ /**
19306
+ * Modify plugin's page action links collection.
19307
+ *
19308
+ * @author Vova Feldman (@svovaf)
19309
+ * @since 1.0.0
19310
+ *
19311
+ * @param array $links
19312
+ * @param $file
19313
+ *
19314
+ * @return array
19315
+ */
19316
+ function _modify_plugin_action_links_hook( $links, $file ) {
19317
+ $this->_logger->entrance();
19318
+
19319
+ $passed_deactivate = false;
19320
+ $deactivate_link = '';
19321
+ $before_deactivate = array();
19322
+ $after_deactivate = array();
19323
+ foreach ( $links as $key => $link ) {
19324
+ if ( 'deactivate' === $key ) {
19325
+ $deactivate_link = $link;
19326
+ $passed_deactivate = true;
19327
+ continue;
19328
+ }
19329
+
19330
+ if ( ! $passed_deactivate ) {
19331
+ $before_deactivate[ $key ] = $link;
19332
+ } else {
19333
+ $after_deactivate[ $key ] = $link;
19334
+ }
19335
+ }
19336
+
19337
+ ksort( $this->_action_links );
19338
+
19339
+ foreach ( $this->_action_links as $new_links ) {
19340
+ foreach ( $new_links as $link ) {
19341
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
19342
+ }
19343
+ }
19344
+
19345
+ if ( ! empty( $deactivate_link ) ) {
19346
+ /**
19347
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
19348
+ *
19349
+ * @since 1.2.1.6 Always show the deactivation feedback form since we added automatic free version deactivation upon premium code activation.
19350
+ */
19351
+ $deactivate_link .= '<i class="fs-module-id" data-module-id="' . $this->_module_id . '"></i>';
19352
+
19353
+ // Append deactivation link.
19354
+ $before_deactivate['deactivate'] = $deactivate_link;
19355
+ }
19356
+
19357
+ return array_merge( $before_deactivate, $after_deactivate );
19358
+ }
19359
+
19360
+ /**
19361
+ * Adds admin message.
19362
+ *
19363
+ * @author Vova Feldman (@svovaf)
19364
+ * @since 1.0.4
19365
+ *
19366
+ * @param string $message
19367
+ * @param string $title
19368
+ * @param string $type
19369
+ */
19370
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
19371
+ $this->_admin_notices->add( $message, $title, $type );
19372
+ }
19373
+
19374
+ /**
19375
+ * Adds sticky admin message.
19376
+ *
19377
+ * @author Vova Feldman (@svovaf)
19378
+ * @since 1.1.0
19379
+ *
19380
+ * @param string $message
19381
+ * @param string $id
19382
+ * @param string $title
19383
+ * @param string $type
19384
+ */
19385
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
19386
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
19387
+ }
19388
+
19389
+ /**
19390
+ * Helper function that returns the final steps for the upgrade completion.
19391
+ *
19392
+ * If the module is already running the premium code, returns an empty string.
19393
+ *
19394
+ * @author Vova Feldman (@svovaf)
19395
+ * @since 1.2.1
19396
+ *
19397
+ * @param string $plan_title
19398
+ *
19399
+ * @return string
19400
+ */
19401
+ private function get_complete_upgrade_instructions( $plan_title = '' ) {
19402
+ $this->_logger->entrance();
19403
+
19404
+ $activate_license_string = $this->get_license_network_activation_notice();
19405
+
19406
+ if ( ! $this->has_premium_version() || $this->is_premium() ) {
19407
+ return '' . $activate_license_string;
19408
+ }
19409
+
19410
+ if ( empty( $plan_title ) ) {
19411
+ $plan_title = $this->get_plan_title();
19412
+ }
19413
+
19414
+ // @since 1.2.1.5 The free version is auto deactivated.
19415
+ $deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
19416
+ ( '<li>' . $this->esc_html_inline( 'Deactivate the free version', 'deactivate-free-version' ) . '.</li>' ) :
19417
+ '';
19418
+
19419
+ return sprintf(
19420
+ ' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
19421
+ $this->get_text_inline( 'Please follow these steps to complete the upgrade', 'follow-steps-to-complete-upgrade' ),
19422
+ ( empty( $activate_license_string ) ? '' : $activate_license_string . '</li><li>' ) .
19423
+ $this->get_latest_download_link( sprintf(
19424
+ /* translators: %s: Plan title */
19425
+ $this->get_text_inline( 'Download the latest %s version', 'download-latest-x-version' ),
19426
+ $plan_title
19427
+ ) ),
19428
+ $deactivation_step,
19429
+ $this->get_text_inline( 'Upload and activate the downloaded version', 'upload-and-activate' ),
19430
+ '//bit.ly/upload-wp-' . $this->_module_type . 's',
19431
+ $this->get_text_inline( 'How to upload and activate?', 'howto-upload-activate' )
19432
+ );
19433
+ }
19434
+
19435
+ /**
19436
+ * @author Leo Fajardo (@leorw)
19437
+ * @since 2.1.0
19438
+ *
19439
+ * @param string $url
19440
+ * @param array $request
19441
+ */
19442
+ private static function enrich_request_for_debug( &$url, &$request ) {
19443
+ if ( WP_FS__DEBUG_SDK || isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
19444
+ $url = add_query_arg( 'XDEBUG_SESSION_START', rand( 0, 9999999 ), $url );
19445
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
19446
+
19447
+ $request['cookies'] = array(
19448
+ new WP_Http_Cookie( array(
19449
+ 'name' => 'XDEBUG_SESSION',
19450
+ 'value' => 'PHPSTORM',
19451
+ ) )
19452
+ );
19453
+ }
19454
+ }
19455
+
19456
+ /**
19457
+ * @author Leo Fajardo (@leorw)
19458
+ * @since 2.1.0
19459
+ *
19460
+ * @param string $url
19461
+ * @param array $request
19462
+ * @param int $success_cache_expiration
19463
+ * @param int $failure_cache_expiration
19464
+ * @param bool $maybe_enrich_request_for_debug
19465
+ *
19466
+ * @return WP_Error|array
19467
+ */
19468
+ static function safe_remote_post(
19469
+ &$url,
19470
+ $request,
19471
+ $success_cache_expiration = 0,
19472
+ $failure_cache_expiration = 0,
19473
+ $maybe_enrich_request_for_debug = true
19474
+ ) {
19475
+ $should_cache = ($success_cache_expiration + $failure_cache_expiration > 0);
19476
+
19477
+ $cache_key = $should_cache ? md5( fs_strip_url_protocol($url) . json_encode( $request ) ) : false;
19478
+
19479
+ $response = (!WP_FS__DEBUG_SDK && ( false !== $cache_key )) ?
19480
+ get_transient( $cache_key ) :
19481
+ false;
19482
+
19483
+ if ( false === $response ) {
19484
+ if ( $maybe_enrich_request_for_debug ) {
19485
+ self::enrich_request_for_debug( $url, $request );
19486
+ }
19487
+
19488
+ $response = wp_remote_post( $url, $request );
19489
+
19490
+ if ( $response instanceof WP_Error ) {
19491
+ if ( 'https://' === substr( $url, 0, 8 ) &&
19492
+ isset( $response->errors ) &&
19493
+ isset( $response->errors['http_request_failed'] )
19494
+ ) {
19495
+ $http_error = strtolower( $response->errors['http_request_failed'][0] );
19496
+
19497
+ if ( false !== strpos( $http_error, 'ssl' ) ||
19498
+ false !== strpos( $http_error, 'curl error 35' )
19499
+ ) {
19500
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
19501
+ $url = 'http://' . substr( $url, 8 );
19502
+
19503
+ $request['timeout'] = 15;
19504
+ $response = wp_remote_post( $url, $request );
19505
+ }
19506
+ }
19507
+ }
19508
+
19509
+ if ( false !== $cache_key ) {
19510
+ set_transient(
19511
+ $cache_key,
19512
+ $response,
19513
+ ( ( $response instanceof WP_Error ) ?
19514
+ $failure_cache_expiration :
19515
+ $success_cache_expiration )
19516
+ );
19517
+ }
19518
+ }
19519
+
19520
+ return $response;
19521
+ }
19522
+
19523
+ /**
19524
+ * This method is used to enrich the after upgrade notice instructions when the upgraded
19525
+ * license cannot be activated network wide (license quota isn't large enough).
19526
+ *
19527
+ * @author Vova Feldman (@svovaf)
19528
+ * @since 2.0.0
19529
+ *
19530
+ * @return string
19531
+ */
19532
+ private function get_license_network_activation_notice() {
19533
+ if ( ! $this->_is_network_active ) {
19534
+ // Module isn't network level activated.
19535
+ return '';
19536
+ }
19537
+
19538
+ if ( ! fs_is_network_admin() ) {
19539
+ // Not network level admin.
19540
+ return '';
19541
+ }
19542
+
19543
+ if ( get_blog_count() == 1 ) {
19544
+ // There's only a single site in the network so if there's a context license it was already activated.
19545
+ return '';
19546
+ }
19547
+
19548
+ if ( ! is_object( $this->_license ) ) {
19549
+ // No context license.
19550
+ return '';
19551
+ }
19552
+
19553
+ if ( $this->_license->is_single_site() && 0 < $this->_license->activated ) {
19554
+ // License was already utilized (this is not 100% the case if all the network is localhost sites and the license can be utilized on unlimited localhost sites).
19555
+ return '';
19556
+ }
19557
+
19558
+ if ( $this->can_activate_license_on_network( $this->_license ) ) {
19559
+ // License can be activated on all the network, so probably, the license is already activate on all the network (that's how the after upgrade sync works).
19560
+ return '';
19561
+ }
19562
+
19563
+ return sprintf(
19564
+ $this->get_text_inline( '%sClick here%s to choose the sites where you\'d like to activate the license on.', 'network-choose-sites-for-license' ),
19565
+ '<a href="' . $this->get_account_url( false, array( 'activate_license' => 'true' ) ) . '">',
19566
+ '</a>'
19567
+ );
19568
+ }
19569
+
19570
+ /**
19571
+ * @author Vova Feldman (@svovaf)
19572
+ * @since 1.2.1.7
19573
+ *
19574
+ * @param string $key
19575
+ *
19576
+ * @return string
19577
+ */
19578
+ function get_text( $key ) {
19579
+ return fs_text( $key, $this->_slug );
19580
+ }
19581
+
19582
+ /**
19583
+ * @author Vova Feldman (@svovaf)
19584
+ * @since 1.2.3
19585
+ *
19586
+ * @param string $text Translatable string.
19587
+ * @param string $key String key for overrides.
19588
+ *
19589
+ * @return string
19590
+ */
19591
+ function get_text_inline( $text, $key = '' ) {
19592
+ return _fs_text_inline( $text, $key, $this->_slug );
19593
+ }
19594
+
19595
+ /**
19596
+ * @author Vova Feldman (@svovaf)
19597
+ * @since 1.2.3
19598
+ *
19599
+ * @param string $text Translatable string.
19600
+ * @param string $context Context information for the translators.
19601
+ * @param string $key String key for overrides.
19602
+ *
19603
+ * @return string
19604
+ */
19605
+ function get_text_x_inline( $text, $context, $key ) {
19606
+ return _fs_text_x_inline( $text, $context, $key, $this->_slug );
19607
+ }
19608
+
19609
+ /**
19610
+ * @author Vova Feldman (@svovaf)
19611
+ * @since 1.2.3
19612
+ *
19613
+ * @param string $text Translatable string.
19614
+ * @param string $key String key for overrides.
19615
+ *
19616
+ * @return string
19617
+ */
19618
+ function esc_html_inline( $text, $key ) {
19619
+ return esc_html( _fs_text_inline( $text, $key, $this->_slug ) );
19620
+ }
19621
+
19622
+ #----------------------------------------------------------------------------------
19623
+ #region Versioning
19624
+ #----------------------------------------------------------------------------------
19625
+
19626
+ /**
19627
+ * Check if Freemius in SDK upgrade mode.
19628
+ *
19629
+ * @author Vova Feldman (@svovaf)
19630
+ * @since 1.0.9
19631
+ *
19632
+ * @return bool
19633
+ */
19634
+ function is_sdk_upgrade_mode() {
19635
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
19636
+ $this->_storage->sdk_upgrade_mode :
19637
+ false;
19638
+ }
19639
+
19640
+ /**
19641
+ * Turn SDK upgrade mode off.
19642
+ *
19643
+ * @author Vova Feldman (@svovaf)
19644
+ * @since 1.0.9
19645
+ */
19646
+ function set_sdk_upgrade_complete() {
19647
+ $this->_storage->sdk_upgrade_mode = false;
19648
+ }
19649
+
19650
+ /**
19651
+ * Check if plugin upgrade mode.
19652
+ *
19653
+ * @author Vova Feldman (@svovaf)
19654
+ * @since 1.0.9
19655
+ *
19656
+ * @return bool
19657
+ */
19658
+ function is_plugin_upgrade_mode() {
19659
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
19660
+ $this->_storage->plugin_upgrade_mode :
19661
+ false;
19662
+ }
19663
+
19664
+ /**
19665
+ * Turn plugin upgrade mode off.
19666
+ *
19667
+ * @author Vova Feldman (@svovaf)
19668
+ * @since 1.0.9
19669
+ */
19670
+ function set_plugin_upgrade_complete() {
19671
+ $this->_storage->plugin_upgrade_mode = false;
19672
+ }
19673
+
19674
+ #endregion
19675
+
19676
+ #----------------------------------------------------------------------------------
19677
+ #region Permissions
19678
+ #----------------------------------------------------------------------------------
19679
+
19680
+ /**
19681
+ * Check if specific permission requested.
19682
+ *
19683
+ * @author Vova Feldman (@svovaf)
19684
+ * @since 1.1.6
19685
+ *
19686
+ * @param string $permission
19687
+ *
19688
+ * @return bool
19689
+ */
19690
+ function is_permission_requested( $permission ) {
19691
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
19692
+ }
19693
+
19694
+ #endregion
19695
+
19696
+ #----------------------------------------------------------------------------------
19697
+ #region Auto Activation
19698
+ #----------------------------------------------------------------------------------
19699
+
19700
+ /**
19701
+ * Hints the SDK if running an auto-installation.
19702
+ *
19703
+ * @var bool
19704
+ */
19705
+ private $_isAutoInstall = false;
19706
+
19707
+ /**
19708
+ * After upgrade callback to install and auto activate a plugin.
19709
+ * This code will only be executed on explicit request from the user,
19710
+ * following the practice Jetpack are using with their theme installations.
19711
+ *
19712
+ * @link https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/
19713
+ *
19714
+ * @author Vova Feldman (@svovaf)
19715
+ * @since 1.2.1.7
19716
+ */
19717
+ function _install_premium_version_ajax_action() {
19718
+ $this->_logger->entrance();
19719
+
19720
+ $this->check_ajax_referer( 'install_premium_version' );
19721
+
19722
+ if ( ! $this->is_registered() ) {
19723
+ // Not registered.
19724
+ self::shoot_ajax_failure( array(
19725
+ 'message' => $this->get_text_inline( 'Auto installation only works for opted-in users.', 'auto-install-error-not-opted-in' ),
19726
+ 'code' => 'premium_installed',
19727
+ ) );
19728
+ }
19729
+
19730
+ $plugin_id = fs_request_get( 'target_module_id', $this->get_id() );
19731
+
19732
+ if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
19733
+ // Invalid ID.
19734
+ self::shoot_ajax_failure( array(
19735
+ 'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
19736
+ 'code' => 'invalid_module_id',
19737
+ ) );
19738
+ }
19739
+
19740
+ if ( $plugin_id == $this->get_id() ) {
19741
+ if ( $this->is_premium() ) {
19742
+ // Already using the premium code version.
19743
+ self::shoot_ajax_failure( array(
19744
+ 'message' => $this->get_text_inline( 'Premium version already active.', 'auto-install-error-premium-activated' ),
19745
+ 'code' => 'premium_installed',
19746
+ ) );
19747
+ }
19748
+ if ( ! $this->can_use_premium_code() ) {
19749
+ // Don't have access to the premium code.
19750
+ self::shoot_ajax_failure( array(
19751
+ 'message' => $this->get_text_inline( 'You do not have a valid license to access the premium version.', 'auto-install-error-invalid-license' ),
19752
+ 'code' => 'invalid_license',
19753
+ ) );
19754
+ }
19755
+ if ( ! $this->has_release_on_freemius() ) {
19756
+ // Plugin is a serviceware, no premium code version.
19757
+ self::shoot_ajax_failure( array(
19758
+ 'message' => $this->get_text_inline( 'Plugin is a "Serviceware" which means it does not have a premium code version.', 'auto-install-error-serviceware' ),
19759
+ 'code' => 'premium_version_missing',
19760
+ ) );
19761
+ }
19762
+ } else {
19763
+ $addon = $this->get_addon( $plugin_id );
19764
+
19765
+ if ( ! is_object( $addon ) ) {
19766
+ // Invalid add-on ID.
19767
+ self::shoot_ajax_failure( array(
19768
+ 'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
19769
+ 'code' => 'invalid_module_id',
19770
+ ) );
19771
+ }
19772
+
19773
+ if ( $this->is_addon_activated( $plugin_id, true ) ) {
19774
+ // Premium add-on version is already activated.
19775
+ self::shoot_ajax_failure( array(
19776
+ 'message' => $this->get_text_inline( 'Premium add-on version already installed.', 'auto-install-error-premium-addon-activated' ),
19777
+ 'code' => 'premium_installed',
19778
+ ) );
19779
+ }
19780
+ }
19781
+
19782
+ $this->_isAutoInstall = true;
19783
+
19784
+ // Try to install and activate.
19785
+ $updater = FS_Plugin_Updater::instance( $this );
19786
+ $result = $updater->install_and_activate_plugin( $plugin_id );
19787
+
19788
+ if ( is_array( $result ) && ! empty( $result['message'] ) ) {
19789
+ self::shoot_ajax_failure( array(
19790
+ 'message' => $result['message'],
19791
+ 'code' => $result['code'],
19792
+ ) );
19793
+ }
19794
+
19795
+ self::shoot_ajax_success( $result );
19796
+ }
19797
+
19798
+ /**
19799
+ * Displays module activation dialog box after a successful upgrade
19800
+ * where the user explicitly requested to auto download and install
19801
+ * the premium version.
19802
+ *
19803
+ * @author Vova Feldman (@svovaf)
19804
+ * @since 1.2.1.7
19805
+ */
19806
+ function _add_auto_installation_dialog_box() {
19807
+ $this->_logger->entrance();
19808
+
19809
+ if ( ! $this->is_registered() ) {
19810
+ // Not registered.
19811
+ return;
19812
+ }
19813
+
19814
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
19815
+
19816
+ if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
19817
+ // Invalid module ID.
19818
+ return;
19819
+ }
19820
+
19821
+ if ( $plugin_id == $this->get_id() ) {
19822
+ if ( $this->is_premium() ) {
19823
+ // Already using the premium code version.
19824
+ return;
19825
+ }
19826
+ if ( ! $this->can_use_premium_code() ) {
19827
+ // Don't have access to the premium code.
19828
+ return;
19829
+ }
19830
+ if ( ! $this->has_release_on_freemius() ) {
19831
+ // Plugin is a serviceware, no premium code version.
19832
+ return;
19833
+ }
19834
+ } else {
19835
+ $addon = $this->get_addon( $plugin_id );
19836
+
19837
+ if ( ! is_object( $addon ) ) {
19838
+ // Invalid add-on ID.
19839
+ return;
19840
+ }
19841
+
19842
+ if ( $this->is_addon_activated( $plugin_id, true ) ) {
19843
+ // Premium add-on version is already activated.
19844
+ return;
19845
+ }
19846
+ }
19847
+
19848
+ $vars = array(
19849
+ 'id' => $this->_module_id,
19850
+ 'target_module_id' => $plugin_id,
19851
+ 'slug' => $this->_slug,
19852
+ );
19853
+
19854
+ fs_require_template( 'auto-installation.php', $vars );
19855
+ }
19856
+
19857
+ #endregion
19858
+
19859
+ #--------------------------------------------------------------------------------
19860
+ #region Tabs Integration
19861
+ #--------------------------------------------------------------------------------
19862
+
19863
+ #region Module's Original Tabs
19864
+
19865
+ /**
19866
+ * Inject a JavaScript logic to capture the theme tabs HTML.
19867
+ *
19868
+ * @author Vova Feldman (@svovaf)
19869
+ * @since 1.2.2.7
19870
+ */
19871
+ function _tabs_capture() {
19872
+ $this->_logger->entrance();
19873
+
19874
+ if ( ! $this->is_theme_settings_page() ||
19875
+ ! $this->is_matching_url( $this->main_menu_url() )
19876
+ ) {
19877
+ return;
19878
+ }
19879
+
19880
+ $params = array(
19881
+ 'id' => $this->_module_id,
19882
+ );
19883
+
19884
+ fs_require_once_template( 'tabs-capture-js.php', $params );
19885
+ }
19886
+
19887
+ /**
19888
+ * Cache theme's tabs HTML for a week. The cache will also be set as expired
19889
+ * after version and type (free/premium) changes, in addition to the week period.
19890
+ *
19891
+ * @author Vova Feldman (@svovaf)
19892
+ * @since 1.2.2.7
19893
+ */
19894
+ function _store_tabs_ajax_action() {
19895
+ $this->_logger->entrance();
19896
+
19897
+ $this->check_ajax_referer( 'store_tabs' );
19898
+
19899
+ // Init filesystem if not yet initiated.
19900
+ WP_Filesystem();
19901
+
19902
+ // Get POST body HTML data.
19903
+ global $wp_filesystem;
19904
+ $tabs_html = $wp_filesystem->get_contents( "php://input" );
19905
+
19906
+ if ( is_string( $tabs_html ) ) {
19907
+ $tabs_html = trim( $tabs_html );
19908
+ }
19909
+
19910
+ if ( ! is_string( $tabs_html ) || empty( $tabs_html ) ) {
19911
+ self::shoot_ajax_failure();
19912
+ }
19913
+
19914
+ $this->_cache->set( 'tabs', $tabs_html, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
19915
+
19916
+ self::shoot_ajax_success();
19917
+ }
19918
+
19919
+ /**
19920
+ * Cache theme's settings page custom styles. The cache will also be set as expired
19921
+ * after version and type (free/premium) changes, in addition to the week period.
19922
+ *
19923
+ * @author Vova Feldman (@svovaf)
19924
+ * @since 1.2.2.7
19925
+ */
19926
+ function _store_tabs_styles() {
19927
+ $this->_logger->entrance();
19928
+
19929
+ if ( ! $this->is_theme_settings_page() ||
19930
+ ! $this->is_matching_url( $this->main_menu_url() )
19931
+ ) {
19932
+ return;
19933
+ }
19934
+
19935
+ $wp_styles = wp_styles();
19936
+
19937
+ $theme_styles_url = get_template_directory_uri();
19938
+
19939
+ $stylesheets = array();
19940
+ foreach ( $wp_styles->queue as $handler ) {
19941
+ if ( fs_starts_with( $handler, 'fs_' ) ) {
19942
+ // Assume that stylesheets that their handler starts with "fs_" belong to the SDK.
19943
+ continue;
19944
+ }
19945
+
19946
+ /**
19947
+ * @var _WP_Dependency $stylesheet
19948
+ */
19949
+ $stylesheet = $wp_styles->registered[ $handler ];
19950
+
19951
+ if ( fs_starts_with( $stylesheet->src, $theme_styles_url ) ) {
19952
+ $stylesheets[] = $stylesheet->src;
19953
+ }
19954
+ }
19955
+
19956
+ if ( ! empty( $stylesheets ) ) {
19957
+ $this->_cache->set( 'tabs_stylesheets', $stylesheets, 7 * WP_FS__TIME_24_HOURS_IN_SEC );
19958
+ }
19959
+ }
19960
+
19961
+ /**
19962
+ * Check if module's original settings page has any tabs.
19963
+ *
19964
+ * @author Vova Feldman (@svovaf)
19965
+ * @since 1.2.2.7
19966
+ *
19967
+ * @return bool
19968
+ */
19969
+ private function has_tabs() {
19970
+ return $this->_cache->has( 'tabs' );
19971
+ }
19972
+
19973
+ /**
19974
+ * Get module's settings page HTML content, starting
19975
+ * from the beginning of the <div class="wrap"> element,
19976
+ * until the tabs HTML (including).
19977
+ *
19978
+ * @author Vova Feldman (@svovaf)
19979
+ * @since 1.2.2.7
19980
+ *
19981
+ * @return string
19982
+ */
19983
+ private function get_tabs_html() {
19984
+ $this->_logger->entrance();
19985
+
19986
+ return $this->_cache->get( 'tabs' );
19987
+ }
19988
+
19989
+ /**
19990
+ * Check if page should include tabs.
19991
+ *
19992
+ * @author Vova Feldman (@svovaf)
19993
+ * @since 1.2.2.7
19994
+ *
19995
+ * @return bool
19996
+ */
19997
+ private function should_page_include_tabs() {
19998
+ if ( ! $this->has_settings_menu() ) {
19999
+ // Don't add tabs if no settings at all.
20000
+ return false;
20001
+ }
20002
+
20003
+ if ( ! $this->is_theme() ) {
20004
+ // Only add tabs to themes for now.
20005
+ return false;
20006
+ }
20007
+
20008
+ if ( ! $this->has_paid_plan() && ! $this->has_addons() ) {
20009
+ // Only add tabs to monetizing themes.
20010
+ return false;
20011
+ }
20012
+
20013
+ if ( ! $this->is_theme_settings_page() ) {
20014
+ // Only add tabs if browsing one of the theme's setting pages.
20015
+ return false;
20016
+ }
20017
+
20018
+ if ( $this->is_admin_page( 'pricing' ) && fs_request_get_bool( 'checkout' ) ) {
20019
+ // Don't add tabs on checkout page, we want to reduce distractions
20020
+ // as much as possible.
20021
+ return false;
20022
+ }
20023
+
20024
+ return true;
20025
+ }
20026
+
20027
+ /**
20028
+ * Add the tabs HTML before the setting's page content and
20029
+ * enqueue any required stylesheets.
20030
+ *
20031
+ * @author Vova Feldman (@svovaf)
20032
+ * @since 1.2.2.7
20033
+ *
20034
+ * @return bool If tabs were included.
20035
+ */
20036
+ function _add_tabs_before_content() {
20037
+ $this->_logger->entrance();
20038
+
20039
+ if ( ! $this->should_page_include_tabs() ) {
20040
+ return false;
20041
+ }
20042
+
20043
+ /**
20044
+ * Enqueue the original stylesheets that are included in the
20045
+ * theme settings page. That way, if the theme settings has
20046
+ * some custom _styled_ content above the tabs UI, this
20047
+ * will make sure that the styling is preserved.
20048
+ */
20049
+ $stylesheets = $this->_cache->get( 'tabs_stylesheets', array() );
20050
+ if ( is_array( $stylesheets ) ) {
20051
+ for ( $i = 0, $len = count( $stylesheets ); $i < $len; $i ++ ) {
20052
+ wp_enqueue_style( "fs_{$this->_module_id}_tabs_{$i}", $stylesheets[ $i ] );
20053
+ }
20054
+ }
20055
+
20056
+ // Cut closing </div> tag.
20057
+ echo substr( trim( $this->get_tabs_html() ), 0, - 6 );
20058
+
20059
+ return true;
20060
+ }
20061
+
20062
+ /**
20063
+ * Add the tabs closing HTML after the setting's page content.
20064
+ *
20065
+ * @author Vova Feldman (@svovaf)
20066
+ * @since 1.2.2.7
20067
+ *
20068
+ * @return bool If tabs closing HTML was included.
20069
+ */
20070
+ function _add_tabs_after_content() {
20071
+ $this->_logger->entrance();
20072
+
20073
+ if ( ! $this->should_page_include_tabs() ) {
20074
+ return false;
20075
+ }
20076
+
20077
+ echo '</div>';
20078
+
20079
+ return true;
20080
+ }
20081
+
20082
+ #endregion
20083
+
20084
+ /**
20085
+ * Add in-page JavaScript to inject the Freemius tabs into
20086
+ * the module's setting tabs section.
20087
+ *
20088
+ * @author Vova Feldman (@svovaf)
20089
+ * @since 1.2.2.7
20090
+ */
20091
+ function _add_freemius_tabs() {
20092
+ $this->_logger->entrance();
20093
+
20094
+ if ( ! $this->should_page_include_tabs() ) {
20095
+ return;
20096
+ }
20097
+
20098
+ $params = array( 'id' => $this->_module_id );
20099
+ fs_require_once_template( 'tabs.php', $params );
20100
+ }
20101
+
20102
+ #endregion
20103
+
20104
+ #--------------------------------------------------------------------------------
20105
+ #region Customizer Integration for Themes
20106
+ #--------------------------------------------------------------------------------
20107
+
20108
+ /**
20109
+ * @author Vova Feldman (@svovaf)
20110
+ * @since 1.2.2.7
20111
+ *
20112
+ * @param WP_Customize_Manager $customizer
20113
+ */
20114
+ function _customizer_register( $customizer ) {
20115
+ $this->_logger->entrance();
20116
+
20117
+ if ( $this->is_pricing_page_visible() ) {
20118
+ require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-upsell-control.php';
20119
+
20120
+ $customizer->add_section( 'freemius_upsell', array(
20121
+ 'title' => '&#9733; ' . $this->get_text_inline( 'View paid features', 'view-paid-features' ),
20122
+ 'priority' => 1,
20123
+ ) );
20124
+ $customizer->add_setting( 'freemius_upsell', array(
20125
+ 'sanitize_callback' => 'esc_html',
20126
+ ) );
20127
+
20128
+ $customizer->add_control( new FS_Customizer_Upsell_Control( $customizer, 'freemius_upsell', array(
20129
+ 'fs' => $this,
20130
+ 'section' => 'freemius_upsell',
20131
+ 'priority' => 100,
20132
+ ) ) );
20133
+ }
20134
+
20135
+ if ( $this->is_page_visible( 'contact' ) || $this->is_page_visible( 'support' ) ) {
20136
+ require_once WP_FS__DIR_INCLUDES . '/customizer/class-fs-customizer-support-section.php';
20137
+
20138
+ // Main Documentation Link In Customizer Root.
20139
+ $customizer->add_section( new FS_Customizer_Support_Section( $customizer, 'freemius_support', array(
20140
+ 'fs' => $this,
20141
+ 'priority' => 1000,
20142
+ ) ) );
20143
+ }