Widgets for SiteOrigin - Version 1.2.3

Version Description

  • July 26 2016 =
  • Recoded most widgets making them light weight and quicker.
  • Major work on CSS and JS files. Sizes significantly lowered.
  • Updated Alert widget.
  • Added deep-linking to Tabs, Accordion and Filter Accordion widgets.
  • Added option to disable animation in Bar and Circle counter widgets.
  • Improved navigation, added pagination and added option to make all posts equal height.
  • Added option to remove All link in Portfolio and Filter Accordion widgets.
  • Added option to use oEmbed in Media Box Widget.
  • Added gallery layout to Portfolio widget.
  • Fixed issue with using multiple Portfolio widgets on the same page.
  • Added Pricing Table Widget.
  • A number of other fixes.
Download this release

Release Info

Developer iamadi
Plugin Icon 128x128 Widgets for SiteOrigin
Version 1.2.3
Comparing to
See all releases

Code changes from version 1.2.2 to 1.2.3

Files changed (174) hide show
  1. {statics → css}/admin.css +0 -0
  2. css/defaults.css +67 -0
  3. css/defaults.scss +102 -0
  4. freemius/LICENSE.txt +340 -0
  5. freemius/README.md +250 -0
  6. freemius/assets/css/admin/account.css +1 -0
  7. freemius/assets/css/admin/add-ons.css +2 -0
  8. freemius/assets/css/admin/common.css +1 -0
  9. freemius/assets/css/admin/connect.css +1 -0
  10. freemius/assets/css/admin/deactivation-feedback.css +1 -0
  11. freemius/assets/css/admin/debug.css +1 -0
  12. freemius/assets/css/admin/license-activation.css +1 -0
  13. freemius/assets/css/common.css +1 -0
  14. freemius/assets/img/plugin-icon.png +0 -0
  15. freemius/assets/scss/_colors.scss +58 -0
  16. freemius/assets/scss/_functions.scss +0 -0
  17. freemius/assets/scss/_load.scss +4 -0
  18. freemius/assets/scss/_mixins.scss +224 -0
  19. freemius/assets/scss/_start.scss +4 -0
  20. freemius/assets/scss/_vars.scss +5 -0
  21. freemius/assets/scss/admin/account.scss +171 -0
  22. freemius/assets/scss/admin/add-ons.scss +449 -0
  23. freemius/assets/scss/admin/common.scss +134 -0
  24. freemius/assets/scss/admin/connect.scss +471 -0
  25. freemius/assets/scss/admin/deactivation-feedback.scss +120 -0
  26. freemius/assets/scss/admin/debug.scss +91 -0
  27. freemius/assets/scss/admin/license-activation.scss +99 -0
  28. freemius/composer.json +10 -0
  29. freemius/config.php +229 -0
  30. freemius/includes/class-freemius-abstract.php +454 -0
  31. freemius/includes/class-freemius.php +9762 -0
  32. freemius/includes/class-fs-api.php +455 -0
  33. freemius/includes/class-fs-logger.php +179 -0
  34. freemius/includes/class-fs-plugin-updater.php +334 -0
  35. freemius/includes/class-fs-security.php +61 -0
  36. freemius/includes/debug/class-fs-debug-bar-panel.php +64 -0
  37. freemius/includes/debug/debug-bar-start.php +52 -0
  38. freemius/includes/entities/class-fs-entity.php +149 -0
  39. freemius/includes/entities/class-fs-plugin-info.php +34 -0
  40. freemius/includes/entities/class-fs-plugin-license.php +172 -0
  41. freemius/includes/entities/class-fs-plugin-plan.php +124 -0
  42. freemius/includes/entities/class-fs-plugin-tag.php +24 -0
  43. freemius/includes/entities/class-fs-plugin.php +90 -0
  44. freemius/includes/entities/class-fs-pricing.php +141 -0
  45. freemius/includes/entities/class-fs-scope-entity.php +29 -0
  46. freemius/includes/entities/class-fs-site.php +127 -0
  47. freemius/includes/entities/class-fs-subscription.php +125 -0
  48. freemius/includes/entities/class-fs-user.php +62 -0
  49. freemius/includes/fs-core-functions.php +453 -0
  50. freemius/includes/fs-essential-functions.php +412 -0
  51. freemius/includes/fs-plugin-info-dialog.php +936 -0
  52. freemius/includes/i18n.php +365 -0
  53. freemius/includes/managers/class-fs-admin-menu-manager.php +549 -0
  54. freemius/includes/managers/class-fs-admin-notice-manager.php +310 -0
  55. freemius/includes/managers/class-fs-cache-manager.php +237 -0
  56. freemius/includes/managers/class-fs-key-value-storage.php +295 -0
  57. freemius/includes/managers/class-fs-license-manager.php +101 -0
  58. freemius/includes/managers/class-fs-option-manager.php +302 -0
  59. freemius/includes/managers/class-fs-plan-manager.php +162 -0
  60. freemius/includes/managers/class-fs-plugin-manager.php +154 -0
  61. freemius/includes/sdk/Exceptions/ArgumentNotExistException.php +6 -0
  62. freemius/includes/sdk/Exceptions/EmptyArgumentException.php +6 -0
  63. freemius/includes/sdk/Exceptions/Exception.php +75 -0
  64. freemius/includes/sdk/Exceptions/InvalidArgumentException.php +6 -0
  65. freemius/includes/sdk/Exceptions/OAuthException.php +12 -0
  66. freemius/includes/sdk/Freemius.php +576 -0
  67. freemius/includes/sdk/FreemiusBase.php +178 -0
  68. freemius/includes/sdk/LICENSE.txt +340 -0
  69. freemius/includes/supplements/fs-essential-functions-1.1.7.1.php +45 -0
  70. freemius/start.php +342 -0
  71. freemius/templates/account.php +625 -0
  72. freemius/templates/add-ons.php +144 -0
  73. freemius/templates/admin-notice.php +46 -0
  74. freemius/templates/all-admin-notice.php +35 -0
  75. freemius/templates/checkout.php +260 -0
  76. freemius/templates/connect.php +333 -0
  77. freemius/templates/contact.php +77 -0
  78. freemius/templates/deactivation-feedback-modal.php +282 -0
  79. freemius/templates/debug.php +250 -0
  80. freemius/templates/debug/api-calls.php +138 -0
  81. freemius/templates/debug/logger.php +60 -0
  82. freemius/templates/debug/plugins-themes-sync.php +68 -0
  83. freemius/templates/debug/scheduled-crons.php +100 -0
  84. freemius/templates/email.php +46 -0
  85. freemius/templates/firewall-issues-js.php +60 -0
  86. freemius/templates/license-activation-modal.php +177 -0
  87. freemius/templates/plugin-icon.php +93 -0
  88. freemius/templates/plugin-info/description.php +75 -0
  89. freemius/templates/plugin-info/features.php +97 -0
  90. freemius/templates/plugin-info/screenshots.php +33 -0
  91. freemius/templates/powered-by.php +41 -0
  92. freemius/templates/pricing.php +100 -0
  93. freemius/templates/sticky-admin-notice-js.php +40 -0
  94. {statics → img}/bigplay-dark.svg +0 -0
  95. {statics → img}/controls-dark.svg +0 -0
  96. inc/enqueue.php +20 -15
  97. inc/functions.php +124 -20
  98. inc/visibility.php +43 -39
  99. {statics → js}/countto.js +13 -13
  100. js/countto.min.js +1 -0
  101. {widgets/ink-crlc-widget/scripts → js}/easypie.js +15 -15
  102. js/easypie.min.js +1 -0
  103. js/match-height.js +385 -0
  104. js/match-height.min.js +1 -0
  105. js/mixitup.js +2098 -0
  106. js/mixitup.min.js +1 -0
  107. {statics → js}/waypoints.js +14 -14
  108. js/waypoints.min.js +1 -0
  109. languages/wpinked-widgets-en.po +5 -5
  110. mixins/less/custom.less +0 -0
  111. mixins/less/elements.less +156 -0
  112. mixins/less/lesshat.less +891 -0
  113. mixins/less/mixins.less +3 -0
  114. mixins/sass/bourbon/_bourbon-deprecated-upcoming.scss +411 -0
  115. mixins/sass/bourbon/_bourbon.scss +87 -0
  116. mixins/sass/bourbon/addons/_border-color.scss +26 -0
  117. mixins/sass/bourbon/addons/_border-radius.scss +48 -0
  118. mixins/sass/bourbon/addons/_border-style.scss +25 -0
  119. mixins/sass/bourbon/addons/_border-width.scss +25 -0
  120. mixins/sass/bourbon/addons/_buttons.scss +64 -0
  121. mixins/sass/bourbon/addons/_clearfix.scss +25 -0
  122. mixins/sass/bourbon/addons/_ellipsis.scss +30 -0
  123. mixins/sass/bourbon/addons/_font-stacks.scss +31 -0
  124. mixins/sass/bourbon/addons/_hide-text.scss +27 -0
  125. mixins/sass/bourbon/addons/_margin.scss +26 -0
  126. mixins/sass/bourbon/addons/_padding.scss +26 -0
  127. mixins/sass/bourbon/addons/_position.scss +48 -0
  128. mixins/sass/bourbon/addons/_prefixer.scss +66 -0
  129. mixins/sass/bourbon/addons/_retina-image.scss +25 -0
  130. mixins/sass/bourbon/addons/_size.scss +51 -0
  131. mixins/sass/bourbon/addons/_text-inputs.scss +113 -0
  132. mixins/sass/bourbon/addons/_timing-functions.scss +34 -0
  133. mixins/sass/bourbon/addons/_triangle.scss +63 -0
  134. mixins/sass/bourbon/addons/_word-wrap.scss +29 -0
  135. mixins/sass/bourbon/css3/_animation.scss +43 -0
  136. mixins/sass/bourbon/css3/_appearance.scss +3 -0
  137. mixins/sass/bourbon/css3/_backface-visibility.scss +3 -0
  138. mixins/sass/bourbon/css3/_background-image.scss +42 -0
  139. mixins/sass/bourbon/css3/_background.scss +55 -0
  140. mixins/sass/bourbon/css3/_border-image.scss +59 -0
  141. mixins/sass/bourbon/css3/_calc.scss +4 -0
  142. mixins/sass/bourbon/css3/_columns.scss +47 -0
  143. mixins/sass/bourbon/css3/_filter.scss +4 -0
  144. mixins/sass/bourbon/css3/_flex-box.scss +287 -0
  145. mixins/sass/bourbon/css3/_font-face.scss +24 -0
  146. mixins/sass/bourbon/css3/_font-feature-settings.scss +4 -0
  147. mixins/sass/bourbon/css3/_hidpi-media-query.scss +10 -0
  148. mixins/sass/bourbon/css3/_hyphens.scss +4 -0
  149. mixins/sass/bourbon/css3/_image-rendering.scss +14 -0
  150. mixins/sass/bourbon/css3/_keyframes.scss +36 -0
  151. mixins/sass/bourbon/css3/_linear-gradient.scss +38 -0
  152. mixins/sass/bourbon/css3/_perspective.scss +8 -0
  153. mixins/sass/bourbon/css3/_placeholder.scss +8 -0
  154. mixins/sass/bourbon/css3/_radial-gradient.scss +39 -0
  155. mixins/sass/bourbon/css3/_selection.scss +42 -0
  156. mixins/sass/bourbon/css3/_text-decoration.scss +19 -0
  157. mixins/sass/bourbon/css3/_transform.scss +15 -0
  158. mixins/sass/bourbon/css3/_transition.scss +71 -0
  159. mixins/sass/bourbon/css3/_user-select.scss +3 -0
  160. mixins/sass/bourbon/functions/_assign-inputs.scss +11 -0
  161. mixins/sass/bourbon/functions/_contains-falsy.scss +20 -0
  162. mixins/sass/bourbon/functions/_contains.scss +26 -0
  163. mixins/sass/bourbon/functions/_is-length.scss +11 -0
  164. mixins/sass/bourbon/functions/_is-light.scss +21 -0
  165. mixins/sass/bourbon/functions/_is-number.scss +11 -0
  166. mixins/sass/bourbon/functions/_is-size.scss +13 -0
  167. mixins/sass/bourbon/functions/_modular-scale.scss +69 -0
  168. mixins/sass/bourbon/functions/_px-to-em.scss +13 -0
  169. mixins/sass/bourbon/functions/_px-to-rem.scss +15 -0
  170. mixins/sass/bourbon/functions/_shade.scss +24 -0
  171. mixins/sass/bourbon/functions/_strip-units.scss +17 -0
  172. mixins/sass/bourbon/functions/_tint.scss +24 -0
  173. mixins/sass/bourbon/functions/_transition-property-name.scss +22 -0
  174. mixins/sass/bourbon/functions/_unpack.scss +7 -0
{statics → css}/admin.css RENAMED
File without changes
css/defaults.css ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* text alignments */
2
+ .iw-text-left {
3
+ text-align: left !important; }
4
+
5
+ .iw-text-right {
6
+ text-align: right !important; }
7
+
8
+ .iw-text-center {
9
+ text-align: center !important; }
10
+
11
+ .iw-text-justify {
12
+ text-align: justify !important; }
13
+
14
+ /* small displays */
15
+ @media only screen {
16
+ .iw-small,
17
+ .iw-med-dw {
18
+ display: inherit !important; }
19
+ .iw-med-up,
20
+ .iw-medium,
21
+ .iw-large {
22
+ display: none !important; } }
23
+
24
+ /* medium displays */
25
+ @media only screen and (min-width: 640px) {
26
+ .iw-med-dw,
27
+ .iw-med-up,
28
+ .iw-medium {
29
+ display: inherit !important; }
30
+ .iw-small,
31
+ .iw-large {
32
+ display: none !important; } }
33
+
34
+ /* large displays */
35
+ @media only screen and (min-width: 1024px) {
36
+ .iw-med-up,
37
+ .iw-large {
38
+ display: inherit !important; }
39
+ .iw-small,
40
+ .iw-med-dw,
41
+ .iw-medium {
42
+ display: none !important; } }
43
+
44
+ /* Orientation targeting */
45
+ .iw-show-l,
46
+ .iw-hide-p {
47
+ display: inherit !important; }
48
+
49
+ .iw-hide-l,
50
+ .iw-show-p {
51
+ display: none !important; }
52
+
53
+ @media only screen and (orientation: landscape) {
54
+ .iw-show-l,
55
+ .iw-hide-p {
56
+ display: inherit !important; }
57
+ .iw-hide-l,
58
+ .iw-show-p {
59
+ display: none !important; } }
60
+
61
+ @media only screen and (orientation: portrait) {
62
+ .iw-show-p,
63
+ .iw-hide-l {
64
+ display: inherit !important; }
65
+ .iw-hide-p,
66
+ .iw-show-l {
67
+ display: none !important; } }
css/defaults.scss ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* text alignments */
2
+ .iw-text-left {
3
+ text-align: left !important;
4
+ }
5
+
6
+ .iw-text-right {
7
+ text-align: right !important;
8
+ }
9
+
10
+ .iw-text-center {
11
+ text-align: center !important;
12
+ }
13
+
14
+ .iw-text-justify {
15
+ text-align: justify !important;
16
+ }
17
+
18
+ /* small displays */
19
+ @media only screen {
20
+
21
+ .iw-small,
22
+ .iw-med-dw {
23
+ display: inherit !important;
24
+ }
25
+
26
+ .iw-med-up,
27
+ .iw-medium,
28
+ .iw-large {
29
+ display: none !important;
30
+ }
31
+
32
+ }
33
+
34
+ /* medium displays */
35
+ @media only screen and ( min-width: 640px ) {
36
+
37
+ .iw-med-dw,
38
+ .iw-med-up,
39
+ .iw-medium {
40
+ display: inherit !important;
41
+ }
42
+
43
+ .iw-small,
44
+ .iw-large {
45
+ display: none !important;
46
+ }
47
+
48
+ }
49
+
50
+ /* large displays */
51
+ @media only screen and ( min-width: 1024px ) {
52
+
53
+ .iw-med-up,
54
+ .iw-large {
55
+ display: inherit !important;
56
+ }
57
+
58
+ .iw-small,
59
+ .iw-med-dw,
60
+ .iw-medium {
61
+ display: none !important;
62
+ }
63
+
64
+ }
65
+
66
+ /* Orientation targeting */
67
+ .iw-show-l,
68
+ .iw-hide-p {
69
+ display: inherit !important;
70
+ }
71
+
72
+ .iw-hide-l,
73
+ .iw-show-p {
74
+ display: none !important;
75
+ }
76
+
77
+ @media only screen and ( orientation: landscape ) {
78
+
79
+ .iw-show-l,
80
+ .iw-hide-p {
81
+ display: inherit !important;
82
+ }
83
+
84
+ .iw-hide-l,
85
+ .iw-show-p {
86
+ display: none !important;
87
+ }
88
+
89
+ }
90
+ @media only screen and ( orientation: portrait ) {
91
+
92
+ .iw-show-p,
93
+ .iw-hide-l {
94
+ display: inherit !important;
95
+ }
96
+
97
+ .iw-hide-p,
98
+ .iw-show-l {
99
+ display: none !important;
100
+ }
101
+
102
+ }
freemius/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
freemius/README.md ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Freemius WordPress SDK
2
+ ======================
3
+
4
+ Freemius is an [analytics](https://freemius.com/wordpress/insights/) & [monetization](https://freemius.com/wordpress/) platform for plugin developers. Freemius empower developers with advanced real-time analytics and helps turning any plugin into a commercial product in less than 10 min.
5
+
6
+ The platform is fully functional and running in production. Having said that, the monetization platform is still in closed beta.
7
+ If you are a WordPress plugin developer and you are interested to monetize with Freemius [apply to our closed beta here](http://bit.ly/freemius-beta):
8
+
9
+ http://bit.ly/freemius-beta
10
+
11
+ **Below you'll find the integration instructions for our WordPress SDK.**
12
+
13
+ ## Code Documentation
14
+
15
+ You can find the SDK's PHP-Doc documentation here:
16
+ https://codedoc.pub/freemius/wordpress-sdk/master/
17
+
18
+ ## Initializing the SDK
19
+
20
+ Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
21
+
22
+ ```php
23
+ <?php
24
+ // Create a helper function for easy SDK access.
25
+ function my_prefix_fs() {
26
+ global $my_prefix_fs;
27
+ if ( ! isset( $my_prefix_fs ) ) {
28
+ // Include Freemius SDK.
29
+ require_once dirname(__FILE__) . '/freemius/start.php';
30
+
31
+ $my_prefix_fs = fs_dynamic_init( array(
32
+ 'id' => '1234',
33
+ 'slug' => 'my-plugin-slug',
34
+ 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
35
+ 'public_key' => 'pk_MY_PUBLIC_KEY',
36
+ 'is_live' => true,
37
+ 'is_premium' => true,
38
+ 'has_addons' => false,
39
+ 'has_paid_plans' => false,
40
+ // Set the SDK to work in a sandbox mode (for development & testing).
41
+ // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
42
+ 'secret_key' => 'sk_MY_SECRET_KEY',
43
+ ) );
44
+ }
45
+
46
+ return $my_prefix_fs;
47
+ }
48
+
49
+ // Init Freemius.
50
+ my_prefix_fs();
51
+ ?>
52
+ ```
53
+
54
+ - **1234** - Replace with your plugin's ID.
55
+ - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
56
+ - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
57
+ - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
58
+ - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
59
+
60
+
61
+ ## Usage example
62
+
63
+ You can call the SDK by using the shortcode function:
64
+
65
+ ```php
66
+ <?php my_prefix_fs()->get_upgrade_url(); ?>
67
+ ```
68
+
69
+ Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
70
+
71
+ ```php
72
+ <?php
73
+ global $my_prefix_fs;
74
+ $my_prefix_fs->get_account_url();
75
+ ?>
76
+ ```
77
+
78
+ ## Adding license based logic examples
79
+
80
+ Add marketing content to encourage your users to upgrade for your paid version:
81
+
82
+ ```php
83
+ <?php
84
+ if ( my_prefix_fs()->is_not_paying() ) {
85
+ echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
86
+ echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
87
+ esc_html__('Upgrade Now!', 'my-plugin-slug') .
88
+ '</a>';
89
+ echo '</section>';
90
+ }
91
+ ?>
92
+ ```
93
+
94
+ Add logic which will only be available in your premium plugin version:
95
+
96
+ ```php
97
+ <?php
98
+ // This "if" block will be auto removed from the Free version.
99
+ if ( my_prefix_fs()->is__premium_only() ) {
100
+
101
+ // ... premium only logic ...
102
+
103
+ }
104
+ ?>
105
+ ```
106
+
107
+ To add a function which will only be available in your premium plugin version, simply add __premium_only as the suffix of the function name. Just make sure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:
108
+
109
+ ```php
110
+ <?php
111
+ class My_Plugin {
112
+ function init() {
113
+ ...
114
+
115
+ // This "if" block will be auto removed from the free version.
116
+ if ( my_prefix_fs()->is__premium_only() ) {
117
+ // Init premium version.
118
+ $this->admin_init__premium_only();
119
+
120
+ add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
121
+ }
122
+
123
+ ...
124
+ }
125
+
126
+ // This method will be only included in the premium version.
127
+ function admin_init__premium_only() {
128
+ ...
129
+ }
130
+
131
+ // This method will be only included in the premium version.
132
+ function admin_init_hook__premium_only() {
133
+ ...
134
+ }
135
+ }
136
+ ?>
137
+ ```
138
+
139
+ Add logic which will only be executed for customers in your 'professional' plan:
140
+
141
+ ```php
142
+ <?php
143
+ if ( my_prefix_fs()->is_plan('professional', true) ) {
144
+ // .. logic related to Professional plan only ...
145
+ }
146
+ ?>
147
+ ```
148
+
149
+ Add logic which will only be executed for customers in your 'professional' plan or higher plans:
150
+
151
+ ```php
152
+ <?php
153
+ if ( my_prefix_fs()->is_plan('professional') ) {
154
+ // ... logic related to Professional plan and higher plans ...
155
+ }
156
+ ?>
157
+ ```
158
+
159
+ Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):
160
+
161
+ ```php
162
+ <?php
163
+ // This "if" block will be auto removed from the Free version.
164
+ if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
165
+ // ... logic related to Professional plan and higher plans ...
166
+ }
167
+ ?>
168
+ ```
169
+
170
+ Add logic only for users in trial:
171
+
172
+ ```php
173
+ <?php
174
+ if ( my_prefix_fs()->is_trial() ) {
175
+ // ... logic for users in trial ...
176
+ }
177
+ ?>
178
+ ```
179
+
180
+ Add logic for specified paid plan:
181
+
182
+ ```php
183
+ <?php
184
+ // This "if" block will be auto removed from the Free version.
185
+ if ( my_prefix_fs()->is__premium_only() ) {
186
+ if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
187
+
188
+ // ... logic related to Professional plan only ...
189
+
190
+ } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
191
+
192
+ // ... logic related to Business plan and higher plans ...
193
+
194
+ }
195
+ }
196
+ ?>
197
+ ```
198
+
199
+ ## Excluding files and folders from the free plugin version
200
+ There are two ways to exclude files from your free version.
201
+
202
+ 1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included in the premium plugin version. This works for all type of files, not only PHP.
203
+ 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
204
+ ```php
205
+ <?php
206
+ /**
207
+ * Plugin Name: My Very Awesome Plugin
208
+ * Plugin URI: http://my-awesome-plugin.com
209
+ * Description: Create and manage Awesomeness right in WordPress.
210
+ * Version: 1.0.0
211
+ * Author: Awesomattic
212
+ * Author URI: http://my-awesome-plugin.com/me/
213
+ * License: GPLv2
214
+ * Text Domain: myplugin
215
+ * Domain Path: /langs
216
+ *
217
+ * @fs_premium_only /lib/functions.php, /premium-files/
218
+ */
219
+
220
+ if ( ! defined( 'ABSPATH' ) ) {
221
+ exit;
222
+ }
223
+
224
+ // ... my code ...
225
+ ?>
226
+ ```
227
+ The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
228
+
229
+ # WordPress.org Compliance
230
+ Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
231
+ > All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers.
232
+
233
+ Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with `if ( my_prefix_fs()->{{ method }}__premium_only() )` or the other methods provided to exclude premium features & files from the free version.
234
+
235
+ ## Deployment
236
+ Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
237
+ The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
238
+
239
+ 1. **Premium version**: Identical to your uploaded version, including all code (except your `secret_key`). Will be enabled for download ONLY for your paying or in trial customers.
240
+ 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
241
+
242
+ The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org complaint and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo.
243
+
244
+ ## Reporting Bugs
245
+ Email dev [at] freemius [dot] com
246
+
247
+ ## FAQ
248
+
249
+ ## Copyright
250
+ Freemius, Inc.
freemius/assets/css/admin/account.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_account .postbox,#fs_account .widefat{max-width:700px}#fs_account h3{font-size:1.3em;padding:12px 15px;margin:0 0 12px 0;line-height:1.4;border-bottom:1px solid #F1F1F1}#fs_account i.dashicons{font-size:1.2em;height:1.2em;width:1.2em}#fs_account .button i.dashicons{vertical-align:middle}#fs_account .fs-header-actions{position:absolute;top:17px;right:15px;font-size:0.9em}#fs_account .fs-header-actions ul{margin:0}#fs_account .fs-header-actions li{float:left}#fs_account .fs-header-actions li form{display:inline-block}#fs_account .fs-header-actions li a{text-decoration:none}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table var,.fs-key-value-table code{color:#0073AA;font-size:16px;background:none}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}
freemius/assets/css/admin/add-ons.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ #fs_addons .fs-cards-list{list-style:none}#fs_addons .fs-cards-list .fs-card{float:left;height:152px;width:310px;padding:0;margin:0 0 30px 30px;font-size:14px;list-style:none;border:1px solid #ddd;cursor:pointer;position:relative}#fs_addons .fs-cards-list .fs-card .fs-overlay{position:absolute;left:0;right:0;bottom:0;top:0;z-index:9}#fs_addons .fs-cards-list .fs-card .fs-inner{background-color:#fff;overflow:hidden;height:100%;position:relative}#fs_addons .fs-cards-list .fs-card .fs-inner ul{-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s;left:0;right:0;top:0;position:absolute}#fs_addons .fs-cards-list .fs-card .fs-inner li{list-style:none;line-height:18px;padding:0 15px;width:100%;display:block;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-card-banner{padding:0;margin:0;line-height:0;display:block;height:100px;background-repeat:repeat-x;background-size:100% 100%;-moz-transition:all,0.15s;-o-transition:all,0.15s;-ms-transition:all,0.15s;-webkit-transition:all,0.15s;transition:all,0.15s}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-title{margin:10px 0 0 0;height:18px;overflow:hidden;color:#000;white-space:nowrap;text-overflow:ellipsis;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-offer{font-size:0.9em}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-description{background-color:#f9f9f9;padding:10px 15px 100px 15px;border-top:1px solid #eee;margin:0 0 10px 0;color:#777}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-tag{position:absolute;top:10px;right:0px;background:greenyellow;display:block;padding:2px 10px;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.3);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.3);box-shadow:1px 1px 1px rgba(0,0,0,0.3);text-transform:uppercase;font-size:0.9em;font-weight:bold}#fs_addons .fs-cards-list .fs-card .fs-inner .fs-cta .button{position:absolute;top:112px;right:10px}@media screen and (min-width: 960px){#fs_addons .fs-cards-list .fs-card:hover .fs-overlay{border:2px solid #29abe1;margin-left:-1px;margin-top:-1px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner ul{top:-100px}#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-title,#fs_addons .fs-cards-list .fs-card:hover .fs-inner .fs-offer{color:#29abe1}}
2
+ #TB_window,#TB_window iframe{width:772px !important}#plugin-information #section-description h2,#plugin-information #section-description h3,#plugin-information #section-description p,#plugin-information #section-description b,#plugin-information #section-description i,#plugin-information #section-description blockquote,#plugin-information #section-description li,#plugin-information #section-description ul,#plugin-information #section-description ol{clear:none}#plugin-information #section-description .fs-selling-points{padding-bottom:10px;border-bottom:1px solid #ddd}#plugin-information #section-description .fs-selling-points ul{margin:0}#plugin-information #section-description .fs-selling-points ul li{padding:0;list-style:none outside none}#plugin-information #section-description .fs-selling-points ul li i.dashicons{color:#71ae00;font-size:3em;vertical-align:middle;line-height:30px;float:left;margin:0 0 0 -15px}#plugin-information #section-description .fs-selling-points ul li h3{margin:1em 30px !important}#plugin-information #section-description .fs-screenshots:after{content:"";display:table;clear:both}#plugin-information #section-description .fs-screenshots ul{list-style:none;margin:0}#plugin-information #section-description .fs-screenshots ul li{width:225px;height:225px;float:left;margin-bottom:20px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}#plugin-information #section-description .fs-screenshots ul li a{display:block;width:100%;height:100%;border:1px solid;-moz-box-shadow:1px 1px 1px rgba(0,0,0,0.2);-webkit-box-shadow:1px 1px 1px rgba(0,0,0,0.2);box-shadow:1px 1px 1px rgba(0,0,0,0.2);background-size:cover}#plugin-information #section-description .fs-screenshots ul li.odd{margin-right:20px}#plugin-information .plugin-information-pricing{margin:-16px;border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan h3{margin-top:0;padding:20px;font-size:16px}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper{border-bottom:1px solid #ddd}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab{cursor:pointer;position:relative;padding:0 10px;font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab label{text-transform:uppercase;color:green;background:greenyellow;position:absolute;left:-1px;right:-1px;bottom:100%;border:1px solid darkgreen;padding:2px;text-align:center;font-size:0.9em;line-height:1em}#plugin-information .plugin-information-pricing .fs-plan .nav-tab-wrapper .nav-tab.nav-tab-active{cursor:default;background:#fffeec;border-bottom-color:#fffeec}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle h3{background:#fffeec;margin:0;padding-bottom:0;color:#0073aa}#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .nav-tab-wrapper,#plugin-information .plugin-information-pricing .fs-plan.fs-single-cycle .fs-billing-frequency{display:none}#plugin-information .plugin-information-pricing .fs-plan .fs-pricing-body{background:#fffeec;padding:20px}#plugin-information .plugin-information-pricing .fs-plan .button{width:100%;text-align:center;font-weight:bold;text-transform:uppercase;font-size:1.1em}#plugin-information .plugin-information-pricing .fs-plan label{white-space:nowrap}#plugin-information .plugin-information-pricing .fs-plan var{font-style:normal}#plugin-information .plugin-information-pricing .fs-plan .fs-billing-frequency,#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-align:center;display:block;font-weight:bold;margin-bottom:10px;text-transform:uppercase;background:#F3F3F3;padding:2px;border:1px solid #ccc}#plugin-information .plugin-information-pricing .fs-plan .fs-annual-discount{text-transform:none;color:green;background:greenyellow}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms{font-size:0.9em}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms i{float:left;margin:0 0 0 -15px}#plugin-information .plugin-information-pricing .fs-plan ul.fs-trial-terms li{margin:10px 0 0 0}#plugin-information #section-features .fs-features{margin:-20px -26px}#plugin-information #section-features table{width:100%;border-spacing:0;border-collapse:separate}#plugin-information #section-features table thead th{padding:10px 0}#plugin-information #section-features table thead .fs-price{color:#71ae00;font-weight:normal;display:block;text-align:center}#plugin-information #section-features table tbody td{border-top:1px solid #ccc;padding:10px 0;text-align:center;width:100px;color:#71ae00}#plugin-information #section-features table tbody td:first-child{text-align:left;width:auto;color:inherit;padding-left:26px}#plugin-information #section-features table tbody tr.fs-odd td{background:#fefefe}#plugin-information #section-features .dashicons-yes{width:30px;height:30px;font-size:30px}@media screen and (max-width: 961px){#fs_addons .fs-cards-list .fs-card{height:265px}}
freemius/assets/css/admin/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice{position:relative}.fs-notice.fs-has-title{margin-bottom:30px !important}.fs-notice.success{color:green}.fs-notice.promotion{border-color:#00a0d2 !important;background-color:#f2fcff !important}.fs-notice .fs-notice-body{margin:.5em 0;padding:2px}.fs-notice .fs-close{cursor:pointer;color:#aaa;float:right}.fs-notice .fs-close:hover{color:#666}.fs-notice .fs-close>*{margin-top:7px;display:inline-block}.fs-notice label.fs-plugin-title{background:rgba(0,0,0,0.3);color:#fff;padding:2px 10px;position:absolute;top:100%;bottom:auto;right:auto;-moz-border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;border-radius:0 0 3px 3px;left:10px;font-size:12px;font-weight:bold;cursor:auto}.rtl .fs-notice .fs-close{float:left}.fs-secure-notice{position:fixed;top:32px;left:160px;right:0;background:#ebfdeb;padding:10px 20px;color:green;z-index:9999;box-shadow:0px 2px 2px rgba(6,113,6,0.3);opacity:0.95;filter:alpha(opacity=95)}.fs-secure-notice:hover{opacity:1;filter:alpha(opacity=100)}@media screen and (max-width: 960px){.fs-secure-notice{left:36px}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}
freemius/assets/css/admin/connect.css ADDED
@@ -0,0 +1 @@
 
1
+ #fs_connect{width:480px;-moz-box-shadow:0px 1px 2px rgba(0,0,0,0.3);-webkit-box-shadow:0px 1px 2px rgba(0,0,0,0.3);box-shadow:0px 1px 2px rgba(0,0,0,0.3);margin:20px 0}@media screen and (max-width: 479px){#fs_connect{-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;width:auto;margin:0 0 0 -10px}}#fs_connect .fs-content{background:#fff;padding:15px 20px}#fs_connect .fs-content .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 .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}.rtl #fs_connect .fs-actions{padding:10px 20px;background:#C0C7CA}.rtl #fs_connect .fs-actions .button .dashicons{font-size:37px;margin-left:-8px;margin-right:12px}.rtl #fs_connect .fs-actions .button.button-primary:after{content:' \000bb'}.rtl #fs_connect .fs-actions .button.button-primary.fs-loading:after{content:''}.rtl #fs_connect .fs-actions .button.button-secondary{float:left}.rtl #fs_connect .fs-permissions ul li div{margin-right:55px;margin-left:0}.rtl #fs_connect .fs-permissions ul li i.dashicons{float:right}.rtl #fs_connect .fs-visual .fs-site-icon{right:20px;left:auto}.rtl #fs_connect .fs-visual .fs-connect-logo{right:auto;left:20px}.wp-pointer-content #fs_connect{margin:0;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none}.fs-opt-in-pointer .wp-pointer-content{padding:0}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow{border-bottom-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-top .wp-pointer-arrow-inner{border-bottom-color:#fafafa}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow{border-top-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-bottom .wp-pointer-arrow-inner{border-top-color:#fafafa}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow{border-right-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-left .wp-pointer-arrow-inner{border-right-color:#fafafa}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow{border-left-color:#dfdfdf}.fs-opt-in-pointer.wp-pointer-right .wp-pointer-arrow-inner{border-left-color:#fafafa}
freemius/assets/css/admin/deactivation-feedback.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input{margin-left:29px}.fs-modal .fs-modal-dialog li.reason label{display:table}.fs-modal .fs-modal-dialog li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}.fs-modal .reason-input{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea{width:100%}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
freemius/assets/css/admin/debug.css ADDED
@@ -0,0 +1 @@
 
1
+ .switch{position:relative;display:inline-block;font-size:1.6em;font-weight:bold;color:#ccc;text-shadow:0px 1px 1px rgba(255,255,255,0.8);height:18px;padding:6px 6px 5px 6px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:4px;background:#ececec;box-shadow:0px 0px 4px rgba(0,0,0,0.1),inset 0px 1px 3px 0px rgba(0,0,0,0.1);cursor:pointer}.switch span{display:inline-block;width:35px;text-transform:uppercase}.switch span.on{color:#6bc406}.switch .toggle{position:absolute;top:1px;width:37px;height:25px;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.3);border-radius:4px;background:#fff;background:-moz-linear-gradient(top, #ececec 0%, #fff 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));background:-webkit-linear-gradient(top, #ececec 0%, #fff 100%);background:-o-linear-gradient(top, #ececec 0%, #fff 100%);background:-ms-linear-gradient(top, #ececec 0%, #fff 100%);background:linear-gradient(top, #ececec 0%, #fff 100%);box-shadow:inset 0px 1px 0px 0px rgba(255,255,255,0.5);z-index:999;-moz-transition:all 0.15s ease-in-out;-o-transition:all 0.15s ease-in-out;-ms-transition:all 0.15s ease-in-out;-webkit-transition:all 0.15s ease-in-out;transition:all 0.15s ease-in-out}.switch.on .toggle{left:2%}.switch.off .toggle{left:54%}.switch.round{padding:0px 20px;border-radius:40px}.switch.round .toggle{border-radius:40px;width:14px;height:14px}.switch.round.on .toggle{left:3%;background:#6bc406}.switch.round.off .toggle{left:58%}.switch-label{font-size:20px;line-height:31px;margin:0 5px}
freemius/assets/css/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 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}
freemius/assets/css/common.css ADDED
@@ -0,0 +1 @@
 
1
+ .fs-notice.success{color:green;font-weight:700}
freemius/assets/img/plugin-icon.png ADDED
Binary file
freemius/assets/scss/_colors.scss ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $menu-hover-color: #333;
2
+ $darkest-color: #000;
3
+ $fms-live-color: #71ae00;
4
+ $fms-test-color: #f7941d;
5
+ $fms-link-color: #29abe1;
6
+ $fms-link-hover-color: darken(#29abe1, 10%);
7
+ $body-bkg: #111;
8
+ $special-color: #d3135a;
9
+ $body-color: #f1f1f1;
10
+ $fms-white: #f1f1f1;
11
+ $container-bkg: #222;
12
+ $container-bkg-odd: #262626;
13
+ $container-border-color: #333;
14
+ $table-head-bkg: #333;
15
+ $table-head-color: #999;
16
+ $info-color: #999;
17
+ $error-color: #ff0000;
18
+
19
+ $fs-logo-blue-color: #29abe1;
20
+ $fs-logo-green-color: #71ae00;
21
+ $fs-logo-magenta-color: #d3135a;
22
+
23
+ $fs-notice-promotion-border-color: #00a0d2;
24
+ $fs-notice-promotion-bkg: #f2fcff;
25
+
26
+ // WordPress colors.
27
+ $page-header-bkg: #333;
28
+ $page-header-color: $fms-white;
29
+ $text-dark-color: #333;
30
+ $text-light-color: #666;
31
+ $text-lightest-color: #999;
32
+
33
+ // WP Buttons.
34
+ $button-primary-bkg: #6bc406;
35
+ $button-primary-color: $fms-white;
36
+ $button-secondary-bkg: #333;
37
+ $button-secondary-color: $fms-white;
38
+ $featured-color: #6bc406;
39
+ $wp-selected-color: #0074a3;
40
+
41
+ $wordpress_color: #01749A;
42
+ $blogger_color: #ff8100;
43
+ $wix_color: #fac102;
44
+ $shopify_color: #80d100;
45
+ $addthis_color: #fe6d4e;
46
+ $tumblr_color: #34506b;
47
+ $zepo_color: #00baf2;
48
+ $jquery_color: #000919;
49
+ $javascript_color: #00baf2;
50
+ $squarespace_color: #000;
51
+
52
+ $blog_color: #ff6600;
53
+ $facebook_color: #3b5998;
54
+ $twitter_color: #4099ff;
55
+ $linkedin_color: #4875b4;
56
+ $youtube_color: #ff3333;
57
+ $gplus_color: #c63d2d;
58
+
freemius/assets/scss/_functions.scss ADDED
File without changes
freemius/assets/scss/_load.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import 'mixins';
2
+ @import "vars";
3
+ @import "functions";
4
+ @import "colors";
freemius/assets/scss/_mixins.scss ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ---- CSS3 SASS MIXINS ----
2
+ // https://github.com/madr/css3-sass-mixins
3
+ //
4
+ // Copyright (C) 2011 by Anders Ytterström
5
+ //
6
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ // of this software and associated documentation files (the "Software"), to deal
8
+ // in the Software without restriction, including without limitation the rights
9
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ // copies of the Software, and to permit persons to whom the Software is
11
+ // furnished to do so, subject to the following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included in
14
+ // all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ // THE SOFTWARE.
23
+ //
24
+
25
+ // ---- LEGACY IE SUPPORT USING FILTERS ----
26
+ // Should IE filters be used or not?
27
+ // PROS: gradients, drop shadows etc will be handled by css.
28
+ // CONS: will harm the site performance badly,
29
+ // especially on sites with heavy rendering and scripting.
30
+ $useIEFilters: 0;
31
+ // might be 0 or 1. disabled by default.
32
+ // ---- /LEGACY IE SUPPORT USING FILTERS ----
33
+
34
+
35
+ @mixin background-size ($value) {
36
+ -webkit-background-size: $value;
37
+ background-size: $value;
38
+ }
39
+
40
+ @mixin border-image ($path, $offsets, $repeats) {
41
+ -moz-border-image: $path $offsets $repeats;
42
+ -o-border-image: $path $offsets $repeats;
43
+ -webkit-border-image: $path $offsets $repeats;
44
+ border-image: $path $offsets $repeats;
45
+ }
46
+
47
+ @mixin border-radius ($values...) {
48
+ -moz-border-radius: $values;
49
+ -webkit-border-radius: $values;
50
+ border-radius: $values;
51
+ /*-moz-background-clip: padding;
52
+ -webkit-background-clip: padding-box;
53
+ background-clip: padding-box;*/
54
+ }
55
+
56
+ @mixin box-shadow ($values...) {
57
+ -moz-box-shadow: $values;
58
+ -webkit-box-shadow: $values;
59
+ box-shadow: $values;
60
+ }
61
+
62
+ //@mixin box-shadow ($x, $y, $offset, $hex, $ie: $useIEFilters, $inset: null, $spread:null) {
63
+ // -moz-box-shadow: $x $y $offset $spread $hex $inset;
64
+ // -webkit-box-shadow: $x $y $offset $spread $hex $inset;
65
+ // box-shadow: $x $y $offset $spread $hex $inset;
66
+ //
67
+ // @if $ie == 1 {
68
+ // $iecolor: '#' + red($hex) + green($hex) + blue($hex);
69
+ // filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}');
70
+ // -ms-filter: quote(progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$iecolor}'));
71
+ // }
72
+ //}
73
+
74
+ @mixin box-sizing($value) {
75
+ -moz-box-sizing: $value;
76
+ -webkit-box-sizing: $value;
77
+ box-sizing: $value;
78
+ }
79
+
80
+ // requires sass 3.2
81
+ //@mixin keyframes {
82
+ // @-moz-keyframes { @content; }
83
+ // @-ms-keyframes { @content; }
84
+ // @-o-keyframes { @content; }
85
+ // @-webkit-keyframes { @content; }
86
+ // @keyframes { @content; }
87
+ //}
88
+
89
+ @mixin linear-gradient($from, $to, $ie: $useIEFilters) {
90
+ @if $ie != 1 { background-color: $to; }
91
+
92
+ background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0, $from),color-stop(1, $to));
93
+ background-image: -webkit-linear-gradient(top, $from, $to);
94
+ background-image: -moz-linear-gradient(top, $from, $to);
95
+ background-image: -ms-linear-gradient(top, $from, $to);
96
+ background-image: -o-linear-gradient(top, $from, $to);
97
+ background-image: linear-gradient(top, bottom, $from, $to);
98
+
99
+ @if $ie == 1 {
100
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}');
101
+ }
102
+ }
103
+
104
+ @mixin horizontal-gradient($startColor: #555, $endColor: #333, $ie: $useIEFilters) {
105
+ @if $ie != 1 { background-color: $endColor; }
106
+
107
+ background-color: $endColor;
108
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
109
+ background-image: -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
110
+ background-image: -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
111
+ background-image: -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
112
+ background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
113
+ background-repeat: repeat-x;
114
+ @if $ie == 1 {
115
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$startColor}', endColorstr='#{$endColor}', GradientType=1);
116
+ }
117
+ }
118
+
119
+ @mixin radial-gradient($from, $to, $ie: $useIEFilters) {
120
+ @if $ie != 1 { background-color: $to; }
121
+
122
+ background: -moz-radial-gradient(center, circle cover, $from 0%, $to 100%);
123
+ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, $from), color-stop(100%, $to));
124
+ background: -webkit-radial-gradient(center, circle cover, $from 0%, $to 100%);
125
+ background: -o-radial-gradient(center, circle cover, $from 0%, $to 100%);
126
+ background: -ms-radial-gradient(center, circle cover, $from 0%, $to 100%);
127
+ background: radial-gradient(center, circle cover, $from 0%, $to 100%);
128
+ background-color: $from;
129
+
130
+ @if $ie == 1 {
131
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{$from}', endColorstr='#{$to}', GradientType=1); /* IE6-9 fallback on horizontal gradient */
132
+ }
133
+ }
134
+
135
+ /*@mixin rgba-bg ($hex, $alpha, $ie: $useIEFilters) {
136
+ @if $ie == 1 {
137
+ background-color: none;
138
+ $hexopac: ie-hex-str(rgba($hex, $alpha));
139
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}}');
140
+ -ms-filter: quote(progid:DXImageTransform.Microsoft.gradient(startColorStr='#{$hexopac}',EndColorStr='#{$hexopac}'));
141
+ }
142
+ @else {
143
+ background-color: $hex;
144
+ background-color: rgba($hex, $alpha);
145
+ }
146
+ }*/
147
+
148
+ @mixin perspective($perspective) {
149
+ -moz-perspective: $perspective;
150
+ -ms-perspective: $perspective;
151
+ -webkit-perspective: $perspective;
152
+ perspective: $perspective;
153
+ -moz-transform-style: preserve-3d;
154
+ -ms-transform-style: preserve-3d;
155
+ -webkit-transform-style: preserve-3d;
156
+ transform-style: preserve-3d;
157
+ }
158
+
159
+ @mixin transform ($transforms) {
160
+ -moz-transform: $transforms;
161
+ -o-transform: $transforms;
162
+ -ms-transform: $transforms;
163
+ -webkit-transform: $transforms;
164
+ transform: $transforms;
165
+ }
166
+
167
+ @mixin matrix ($a, $b, $c, $d, $e, $f) {
168
+ -moz-transform: matrix($a, $b, $c, $d, #{$e}px, #{$f}px);
169
+ -o-transform: matrix($a, $b, $c, $d, $e, $f);
170
+ -ms-transform: matrix($a, $b, $c, $d, $e, $f);
171
+ -webkit-transform: matrix($a, $b, $c, $d, $e, $f);
172
+ transform: matrix($a, $b, $c, $d, $e, $f);
173
+ }
174
+
175
+ @mixin rotate ($deg) {
176
+ @include transform(rotate(#{$deg}deg));
177
+ }
178
+
179
+ @mixin scale ($size) {
180
+ @include transform(scale(#{$size}));
181
+ }
182
+
183
+ @mixin translate ($x, $y) {
184
+ @include transform(translate($x, $y));
185
+ }
186
+
187
+ @mixin transition ($value...) {
188
+ -moz-transition: $value;
189
+ -o-transition: $value;
190
+ -ms-transition: $value;
191
+ -webkit-transition: $value;
192
+ transition: $value;
193
+ }
194
+
195
+ // ==== /CSS3 SASS MIXINS ====
196
+
197
+ @mixin opacity($opacity) {
198
+ opacity: $opacity;
199
+ $opacity-ie: $opacity * 100;
200
+ filter: alpha(opacity=$opacity-ie); //IE8
201
+ }
202
+
203
+ @mixin sprite($img, $width, $height: $width, $display: block)
204
+ {
205
+ display: $display;
206
+ background-image: url('#{$img}');
207
+
208
+ @include size($width, $height);
209
+ }
210
+
211
+ @mixin size($width, $height: $width)
212
+ {
213
+ width: $width;
214
+ height: $height;
215
+ }
216
+
217
+ @mixin clearfix
218
+ {
219
+ &:after {
220
+ content: "";
221
+ display: table;
222
+ clear: both;
223
+ }
224
+ }
freemius/assets/scss/_start.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @import "vars";
2
+ @import "colors";
3
+ @import "mixins";
4
+ @import "functions";
freemius/assets/scss/_vars.scss ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ $is_production: true;
2
+
3
+ $img_common: if($is_production == true, '//img.freemius.com', 'http://img.freemius:8080');
4
+
5
+ $layout_width: 960px;
freemius/assets/scss/admin/account.scss ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #fs_account
2
+ {
3
+ .postbox,
4
+ .widefat
5
+ {
6
+ max-width: 700px;
7
+ }
8
+
9
+ h3
10
+ {
11
+ font-size: 1.3em;
12
+ padding: 12px 15px;
13
+ margin: 0 0 12px 0;
14
+ line-height: 1.4;
15
+ border-bottom: 1px solid #F1F1F1;
16
+ }
17
+
18
+ i.dashicons
19
+ {
20
+ font-size: 1.2em;
21
+ height: 1.2em;
22
+ width: 1.2em;
23
+ }
24
+
25
+ .button
26
+ {
27
+ i.dashicons
28
+ {
29
+ vertical-align: middle;
30
+ }
31
+ }
32
+
33
+ .fs-header-actions
34
+ {
35
+ position: absolute;
36
+ top: 17px;
37
+ right: 15px;
38
+ font-size: 0.9em;
39
+
40
+ ul
41
+ {
42
+ margin: 0;
43
+ }
44
+
45
+ li
46
+ {
47
+ form
48
+ {
49
+ display: inline-block;
50
+ }
51
+
52
+ float: left;
53
+ a
54
+ {
55
+ text-decoration: none;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ .rtl #fs_account .fs-header-actions
62
+ {
63
+ left: 15px;
64
+ right: auto;
65
+ }
66
+
67
+ .fs-key-value-table
68
+ {
69
+ width: 100%;
70
+
71
+ form
72
+ {
73
+ display: inline-block;
74
+ }
75
+
76
+ tr
77
+ {
78
+ td:first-child
79
+ {
80
+ nobr
81
+ {
82
+ font-weight: bold;
83
+ }
84
+
85
+ text-align: right;
86
+
87
+ form
88
+ {
89
+ display: block;
90
+ }
91
+ }
92
+
93
+ td.fs-right
94
+ {
95
+ text-align: right;
96
+ }
97
+
98
+ &.fs-odd
99
+ {
100
+ background: #ebebeb;
101
+ }
102
+ }
103
+
104
+ td, th
105
+ {
106
+ padding: 10px;
107
+ }
108
+
109
+ var, code
110
+ {
111
+ color: #0073AA;
112
+ font-size: 16px;
113
+ background: none;
114
+ }
115
+ }
116
+
117
+ label.fs-tag
118
+ {
119
+ background: #ffba00;
120
+ color: #fff;
121
+ display: inline-block;
122
+ border-radius: 3px;
123
+ padding: 5px;
124
+ font-size: 11px;
125
+ line-height: 11px;
126
+ vertical-align: baseline;
127
+
128
+ &.fs-warn
129
+ {
130
+ background: #ffba00;
131
+ }
132
+ &.fs-success
133
+ {
134
+ background: #46b450;
135
+ }
136
+ &.fs-error
137
+ {
138
+ background: #dc3232;
139
+ }
140
+ }
141
+
142
+ #fs_addons
143
+ {
144
+ h3
145
+ {
146
+ border: none;
147
+ margin-bottom: 0;
148
+ padding: 4px 5px;
149
+ }
150
+
151
+ td
152
+ {
153
+ vertical-align: middle;
154
+ }
155
+
156
+ td:first-child,
157
+ th:first-child
158
+ {
159
+ text-align: left;
160
+ font-weight: bold;
161
+ }
162
+ td:last-child,
163
+ th:last-child
164
+ {
165
+ text-align: right;
166
+ }
167
+ th
168
+ {
169
+ font-weight: bold;
170
+ }
171
+ }
freemius/assets/scss/admin/add-ons.scss ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ #fs_addons
4
+ {
5
+ .fs-cards-list
6
+ {
7
+ list-style: none;
8
+
9
+ .fs-card
10
+ {
11
+ float: left;
12
+ // height: 185px; // With reviews/ratings
13
+ height: 152px;
14
+ width: 310px;
15
+ padding: 0;
16
+ margin: 0 0 30px 30px;
17
+ font-size: 14px;
18
+ list-style: none;
19
+ border: 1px solid #ddd;
20
+ cursor: pointer;
21
+ position: relative;
22
+
23
+ .fs-overlay
24
+ {
25
+ position: absolute;
26
+ left: 0;
27
+ right: 0;
28
+ bottom: 0;
29
+ top: 0;
30
+ z-index: 9;
31
+ }
32
+
33
+ .fs-inner
34
+ {
35
+ background-color: #fff;
36
+ overflow: hidden;
37
+ height: 100%;
38
+ position: relative;
39
+
40
+ ul
41
+ {
42
+ @include transition(all, 0.15s);
43
+ left: 0;
44
+ right: 0;
45
+ top: 0;
46
+ position: absolute;
47
+ }
48
+
49
+ li
50
+ {
51
+ list-style: none;
52
+ line-height: 18px;
53
+ padding: 0 15px;
54
+ width: 100%;
55
+ display: block;
56
+ @include box-sizing(border-box);
57
+ }
58
+
59
+ .fs-card-banner
60
+ {
61
+ padding: 0;
62
+ margin: 0;
63
+ line-height: 0;
64
+ display: block;
65
+ height: 100px;
66
+ background-repeat: repeat-x;
67
+ background-size: 100% 100%;
68
+ @include transition(all, 0.15s);
69
+ }
70
+
71
+ .fs-title
72
+ {
73
+ margin: 10px 0 0 0;
74
+ height: 18px;
75
+ overflow: hidden;
76
+ color: #000;
77
+ white-space: nowrap;
78
+ text-overflow: ellipsis;
79
+ font-weight: bold;
80
+ }
81
+
82
+ .fs-offer
83
+ {
84
+ font-size: 0.9em;
85
+ }
86
+
87
+ .fs-description
88
+ {
89
+ background-color: #f9f9f9;
90
+ padding: 10px 15px 100px 15px;
91
+ border-top: 1px solid #eee;
92
+ margin: 0 0 10px 0;
93
+ color: #777;
94
+ }
95
+
96
+ .fs-tag
97
+ {
98
+ position: absolute;
99
+ top: 10px;
100
+ right: 0px;
101
+ background: greenyellow;
102
+ display: block;
103
+ padding: 2px 10px;
104
+ @include box-shadow(1px 1px 1px rgba(0,0,0,0.3));
105
+ text-transform: uppercase;
106
+ font-size: 0.9em;
107
+ font-weight: bold;
108
+ }
109
+
110
+ .fs-cta
111
+ {
112
+ .button
113
+ {
114
+ position: absolute;
115
+ top: 112px;
116
+ right: 10px;
117
+ }
118
+ }
119
+ }
120
+
121
+ @media screen and (min-width: 960px) {
122
+ &:hover
123
+ {
124
+ .fs-overlay
125
+ {
126
+ border: 2px solid $fms-link-color;
127
+ margin-left: -1px;
128
+ margin-top: -1px;
129
+ }
130
+
131
+ .fs-inner
132
+ {
133
+ ul
134
+ {
135
+ top: -100px;
136
+ }
137
+
138
+ .fs-card-banner
139
+ {
140
+ // background-position: 50% -100px;
141
+ }
142
+
143
+ .fs-title,
144
+ .fs-offer
145
+ {
146
+ color: $fms-link-color;
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ #TB_window
156
+ {
157
+ &, iframe
158
+ {
159
+ width: 772px !important;
160
+ }
161
+ }
162
+
163
+ #plugin-information
164
+ {
165
+ #section-description
166
+ {
167
+ h2, h3, p, b, i, blockquote, li, ul, ol
168
+ {
169
+ clear: none;
170
+ }
171
+
172
+ .fs-selling-points
173
+ {
174
+ padding-bottom: 10px;
175
+ border-bottom: 1px solid #ddd;
176
+
177
+ ul
178
+ {
179
+ margin: 0;
180
+
181
+ li
182
+ {
183
+ padding: 0;
184
+ list-style: none outside none;
185
+
186
+ i.dashicons
187
+ {
188
+ color: $fs-logo-green-color;
189
+ font-size: 3em;
190
+ vertical-align: middle;
191
+ line-height: 30px;
192
+ float: left;
193
+ margin: 0 0 0 -15px;
194
+ }
195
+
196
+ h3
197
+ {
198
+ margin: 1em 30px !important;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ .fs-screenshots
205
+ {
206
+ @include clearfix();
207
+ ul
208
+ {
209
+ list-style: none;
210
+ margin: 0;
211
+
212
+ li
213
+ {
214
+ width: 225px;
215
+ height: 225px;
216
+ float: left;
217
+ margin-bottom: 20px;
218
+ @include box-sizing(content-box);
219
+
220
+ a
221
+ {
222
+ display: block;
223
+ width: 100%;
224
+ height: 100%;
225
+ border: 1px solid;
226
+ @include box-shadow(1px 1px 1px rgba(0, 0, 0, 0.2));
227
+ background-size: cover;
228
+ }
229
+
230
+ &.odd
231
+ {
232
+ margin-right: 20px;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ .plugin-information-pricing
240
+ {
241
+ $pricing_color: #FFFEEC;
242
+ $borders_color: #DDD;
243
+ margin: -16px;
244
+ // padding: 20px;
245
+ border-bottom: 1px solid $borders_color;
246
+
247
+ .fs-plan
248
+ {
249
+
250
+ h3
251
+ {
252
+ margin-top: 0;
253
+ padding: 20px;
254
+ font-size: 16px;
255
+ }
256
+
257
+ .nav-tab-wrapper
258
+ {
259
+ border-bottom: 1px solid $borders_color;
260
+
261
+ .nav-tab
262
+ {
263
+ cursor: pointer;
264
+ position: relative;
265
+ padding: 0 10px;
266
+ font-size: 0.9em;
267
+
268
+ label
269
+ {
270
+ text-transform: uppercase;
271
+ color: green;
272
+ background: greenyellow;
273
+ position: absolute;
274
+ left: -1px;
275
+ right: -1px;
276
+ bottom: 100%;
277
+ border: 1px solid darkgreen;
278
+ padding: 2px;
279
+ text-align: center;
280
+ font-size: 0.9em;
281
+ line-height: 1em;
282
+ }
283
+
284
+ &.nav-tab-active
285
+ {
286
+ cursor: default;
287
+ background: $pricing_color;
288
+ border-bottom-color: $pricing_color;
289
+ }
290
+ }
291
+ }
292
+
293
+ &.fs-single-cycle
294
+ {
295
+ h3
296
+ {
297
+ background: $pricing_color;
298
+ margin: 0;
299
+ padding-bottom: 0;
300
+ color: #0073aa;
301
+ }
302
+
303
+ .nav-tab-wrapper,
304
+ .fs-billing-frequency
305
+ {
306
+ display: none;
307
+ }
308
+ }
309
+
310
+ .fs-pricing-body
311
+ {
312
+ background: $pricing_color;
313
+ padding: 20px;
314
+ }
315
+
316
+ .button
317
+ {
318
+ width: 100%;
319
+ text-align: center;
320
+ font-weight: bold;
321
+ text-transform: uppercase;
322
+ font-size: 1.1em;
323
+ }
324
+
325
+ label
326
+ {
327
+ white-space: nowrap;
328
+ }
329
+
330
+ var {
331
+ font-style: normal;
332
+ }
333
+
334
+ .fs-billing-frequency,
335
+ .fs-annual-discount
336
+ {
337
+ text-align: center;
338
+ display: block;
339
+ font-weight: bold;
340
+ margin-bottom: 10px;
341
+ text-transform: uppercase;
342
+ background: #F3F3F3;
343
+ padding: 2px;
344
+ border: 1px solid #ccc;
345
+ }
346
+
347
+ .fs-annual-discount
348
+ {
349
+ text-transform: none;
350
+ color: green;
351
+ background: greenyellow;
352
+ }
353
+
354
+ ul.fs-trial-terms
355
+ {
356
+ font-size: 0.9em;
357
+
358
+ i
359
+ {
360
+ float: left;
361
+ margin: 0 0 0 -15px;
362
+ }
363
+
364
+ li
365
+ {
366
+ margin: 10px 0 0 0;
367
+ }
368
+ }
369
+ }
370
+ }
371
+
372
+ #section-features
373
+ {
374
+ .fs-features
375
+ {
376
+ margin: -20px -26px;
377
+ }
378
+
379
+ table
380
+ {
381
+ width: 100%;
382
+ border-spacing: 0;
383
+ border-collapse: separate;
384
+
385
+ thead
386
+ {
387
+ th
388
+ {
389
+ padding: 10px 0;
390
+ }
391
+
392
+ .fs-price
393
+ {
394
+ color: $fs-logo-green-color;
395
+ font-weight: normal;
396
+ display: block;
397
+ text-align: center;
398
+ }
399
+ }
400
+
401
+ tbody
402
+ {
403
+ td
404
+ {
405
+ border-top: 1px solid #ccc;
406
+ padding: 10px 0;
407
+ text-align: center;
408
+ width: 100px;
409
+ color: $fs-logo-green-color;
410
+
411
+ &:first-child
412
+ {
413
+ text-align: left;
414
+ width: auto;
415
+ color: inherit;
416
+ padding-left: 26px;
417
+ }
418
+ }
419
+ tr.fs-odd
420
+ {
421
+ td
422
+ {
423
+ background: #fefefe;
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ .dashicons-yes
430
+ {
431
+ width: 30px;
432
+ height: 30px;
433
+ font-size: 30px;
434
+ }
435
+ }
436
+ }
437
+
438
+ @media screen and (max-width: 961px) {
439
+ #fs_addons
440
+ {
441
+ .fs-cards-list
442
+ {
443
+ .fs-card
444
+ {
445
+ height: 265px;
446
+ }
447
+ }
448
+ }
449
+ }
freemius/assets/scss/admin/common.scss ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .fs-notice
4
+ {
5
+ position: relative;
6
+
7
+ &.fs-has-title
8
+ {
9
+ margin-bottom: 30px !important;
10
+ }
11
+
12
+ &.success
13
+ {
14
+ color: green;
15
+ // font-weight: normal;
16
+ }
17
+
18
+ &.promotion
19
+ {
20
+ border-color: $fs-notice-promotion-border-color !important;
21
+ background-color: $fs-notice-promotion-bkg !important;
22
+ }
23
+
24
+ .fs-notice-body
25
+ {
26
+ margin: .5em 0;
27
+ padding: 2px;
28
+ }
29
+
30
+ .fs-close
31
+ {
32
+ // position: absolute;
33
+ // top: 2px;
34
+ // bottom: 2px;
35
+ // right: 2px;
36
+ // min-width: 100px;
37
+ // text-align: center;
38
+ // padding-right: 2px;
39
+ cursor: pointer;
40
+ color: #aaa;
41
+ float: right;
42
+
43
+ &:hover
44
+ {
45
+ color: #666;
46
+ // background: #A9A9A9;
47
+ }
48
+
49
+ > *
50
+ {
51
+ margin-top: 7px;
52
+ display: inline-block;
53
+ }
54
+ }
55
+
56
+ label.fs-plugin-title
57
+ {
58
+ background: rgba(0, 0, 0, 0.3);
59
+ color: #fff;
60
+ padding: 2px 10px;
61
+ position: absolute;
62
+ top: 100%;
63
+ bottom: auto;
64
+ right: auto;
65
+ @include border-radius(0 0 3px 3px);
66
+ left: 10px;
67
+ font-size: 12px;
68
+ font-weight: bold;
69
+ cursor: auto;
70
+ }
71
+ }
72
+
73
+ .rtl .fs-notice
74
+ {
75
+ .fs-close
76
+ {
77
+ // left: 2px;
78
+ // right: auto;
79
+ // padding-right: 0;
80
+ // padding-left: 2px;
81
+ float: left;
82
+ }
83
+ }
84
+
85
+ .fs-secure-notice
86
+ {
87
+ position: fixed;
88
+ top: 32px;
89
+ left: 160px;
90
+ right: 0;
91
+ background: rgb(235, 253, 235);
92
+ padding: 10px 20px;
93
+ color: green;
94
+ z-index: 9999;
95
+ box-shadow: 0px 2px 2px rgba(6, 113, 6, 0.3);
96
+ @include opacity(0.95);
97
+
98
+ &:hover
99
+ {
100
+ @include opacity(1);
101
+ }
102
+ }
103
+
104
+ @media screen and (max-width: 960px) {
105
+ .fs-secure-notice
106
+ {
107
+ left: 36px;
108
+ }
109
+ }
110
+
111
+ @media screen and (max-width: 782px) {
112
+ .fs-secure-notice
113
+ {
114
+ left: 0;
115
+ top: 46px;
116
+ text-align: center;
117
+ }
118
+ }
119
+
120
+ span.fs-submenu-item.fs-sub:before
121
+ {
122
+ // Add small arrow.
123
+ content: '\21B3';
124
+ padding: 0 5px;
125
+ }
126
+
127
+ .rtl
128
+ {
129
+ span.fs-submenu-item.fs-sub:before
130
+ {
131
+ // Add small RTL arrow.
132
+ content: '\21B2';
133
+ }
134
+ }
freemius/assets/scss/admin/connect.scss ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ .fs-actions
57
+ {
58
+ padding: 10px 20px;
59
+ background: #C0C7CA;
60
+
61
+ .button
62
+ {
63
+ padding: 0 10px 1px;
64
+ line-height: 35px;
65
+ height: 37px;
66
+ font-size: 16px;
67
+ margin-bottom: 0;
68
+
69
+ .dashicons
70
+ {
71
+ font-size: 37px;
72
+ margin-left: -8px;
73
+ margin-right: 12px;
74
+ }
75
+
76
+ &.button-primary
77
+ {
78
+ padding-right: 15px;
79
+ padding-left: 15px;
80
+
81
+ &:after
82
+ {
83
+ content: ' \279C';
84
+ }
85
+
86
+ &.fs-loading
87
+ {
88
+ &:after
89
+ {
90
+ content: '';
91
+ }
92
+ }
93
+ }
94
+
95
+ &.button-secondary
96
+ {
97
+ float: right;
98
+ }
99
+ }
100
+
101
+ // .fs-skip
102
+ // {
103
+ // line-height: 38px;
104
+ // vertical-align: middle;
105
+ // text-decoration: none;
106
+ // margin-left: 10px;
107
+ // }
108
+ }
109
+
110
+ &.fs-anonymous-disabled
111
+ {
112
+ .fs-actions
113
+ {
114
+ .button.button-primary
115
+ {
116
+ width: 100%;
117
+ }
118
+ }
119
+ }
120
+
121
+ .fs-permissions
122
+ {
123
+ padding: 10px 20px;
124
+ background: #FEFEFE;
125
+ // background: #F1F1F1;
126
+ @include transition(background 0.5s ease);
127
+
128
+ .fs-license-sync-disclaimer {
129
+ text-align: center;
130
+ margin-top: 0;
131
+ }
132
+
133
+ .fs-trigger
134
+ {
135
+ font-size: 0.9em;
136
+ text-decoration: none;
137
+ text-align: center;
138
+ display: block;
139
+ }
140
+
141
+ ul
142
+ {
143
+ height: 0;
144
+ overflow: hidden;
145
+ margin: 0;
146
+
147
+ li
148
+ {
149
+ margin-bottom: 12px;
150
+
151
+ &:last-child
152
+ {
153
+ margin-bottom: 0;
154
+ }
155
+
156
+ i.dashicons
157
+ {
158
+ float: left;
159
+ font-size: 40px;
160
+ width: 40px;
161
+ height: 40px;
162
+ }
163
+
164
+ div
165
+ {
166
+ margin-left: 55px;
167
+
168
+ span
169
+ {
170
+ font-weight: bold;
171
+ text-transform: uppercase;
172
+ color: #23282d;
173
+ }
174
+
175
+ p
176
+ {
177
+ margin: 2px 0 0 0;
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ &.fs-open
184
+ {
185
+ background: #fff;
186
+
187
+ ul
188
+ {
189
+ height: auto;
190
+ margin: 20px 20px 10px 20px;
191
+ }
192
+ }
193
+
194
+ @media screen and (max-width: ($form_width - 1)) {
195
+ background: #fff;
196
+
197
+ .fs-trigger
198
+ {
199
+ display: none;
200
+ }
201
+
202
+ ul
203
+ {
204
+ height: auto;
205
+ margin: 20px;
206
+ }
207
+ }
208
+ }
209
+
210
+ .fs-freemium-licensing {
211
+ padding: 8px;
212
+ // background: #0085BA;
213
+ background: #777;
214
+ color: #fff;
215
+
216
+ p {
217
+ text-align: center;
218
+ display: block;
219
+ margin: 0;
220
+ padding: 0;
221
+ }
222
+
223
+ a {
224
+ color: #C2EEFF;
225
+ text-decoration: underline;
226
+ }
227
+ }
228
+
229
+ $icon_size: 80px;
230
+ $wp_logo_padding: $icon_size / 10;
231
+ $icons_top: 10px;
232
+
233
+ .fs-visual
234
+ {
235
+ padding: 12px;
236
+ line-height: 0;
237
+ background: #fafafa;
238
+ height: $icon_size;
239
+ position: relative;
240
+
241
+ .fs-site-icon
242
+ {
243
+ position: absolute;
244
+ left: 20px;
245
+ top: $icons_top;
246
+ }
247
+
248
+ .fs-connect-logo
249
+ {
250
+ position: absolute;
251
+ right: 20px;
252
+ top: $icons_top;
253
+ }
254
+
255
+ .fs-plugin-icon
256
+ {
257
+ position: absolute;
258
+ top: $icons_top;
259
+ left: 50%;
260
+ margin-left: - ($icon_size / 2);
261
+ }
262
+
263
+ .fs-plugin-icon,
264
+ .fs-site-icon,
265
+ img,
266
+ object
267
+ {
268
+ width: $icon_size;
269
+ height: $icon_size;
270
+ }
271
+
272
+ .dashicons-wordpress
273
+ {
274
+ font-size: $icon_size - ($wp_logo_padding * 2);
275
+ background: $wordpress_color;
276
+ color: #fff;
277
+ width: $icon_size - ($wp_logo_padding * 2);
278
+ height: $icon_size - ($wp_logo_padding * 2);
279
+ padding: $wp_logo_padding;
280
+ }
281
+
282
+ .dashicons-plus
283
+ {
284
+ position: absolute;
285
+ top: 50%;
286
+ font-size: 30px;
287
+ margin-top: -10px;
288
+ color: #bbb;
289
+
290
+ &.fs-first
291
+ {
292
+ left: 28%;
293
+ }
294
+ &.fs-second
295
+ {
296
+ left: 65%;
297
+ }
298
+ }
299
+
300
+ .fs-plugin-icon,
301
+ .fs-connect-logo,
302
+ .fs-site-icon
303
+ {
304
+ border: 1px solid #ccc;
305
+ padding: 1px;
306
+ background: #fff;
307
+ }
308
+ }
309
+
310
+ .fs-terms
311
+ {
312
+ text-align: center;
313
+ font-size: 0.85em;
314
+ padding: 5px;
315
+ background: rgba(0, 0, 0, 0.05);
316
+
317
+ &, a
318
+ {
319
+ color: #999;
320
+ }
321
+
322
+ a
323
+ {
324
+ text-decoration: none;
325
+ }
326
+ }
327
+ }
328
+
329
+ .rtl
330
+ {
331
+ #fs_connect
332
+ {
333
+ .fs-actions
334
+ {
335
+ padding: 10px 20px;
336
+ background: #C0C7CA;
337
+
338
+ .button
339
+ {
340
+ .dashicons
341
+ {
342
+ font-size: 37px;
343
+ margin-left: -8px;
344
+ margin-right: 12px;
345
+ }
346
+
347
+ &.button-primary
348
+ {
349
+ &:after
350
+ {
351
+ content: ' \000bb';
352
+ }
353
+
354
+ &.fs-loading
355
+ {
356
+ &:after
357
+ {
358
+ content: '';
359
+ }
360
+ }
361
+ }
362
+
363
+ &.button-secondary
364
+ {
365
+ float: left;
366
+ }
367
+ }
368
+ }
369
+
370
+ .fs-permissions
371
+ {
372
+ ul
373
+ {
374
+ li
375
+ {
376
+ div
377
+ {
378
+ margin-right: 55px;
379
+ margin-left: 0;
380
+ }
381
+
382
+ i.dashicons
383
+ {
384
+ float: right;
385
+ }
386
+
387
+ }
388
+ }
389
+ }
390
+
391
+ .fs-visual
392
+ {
393
+ .fs-site-icon
394
+ {
395
+ right: 20px;
396
+ left: auto;
397
+ }
398
+
399
+ .fs-connect-logo
400
+ {
401
+ right: auto;
402
+ left: 20px;
403
+ }
404
+ }
405
+ }
406
+ }
407
+
408
+ .wp-pointer-content
409
+ {
410
+ #fs_connect
411
+ {
412
+ margin: 0;
413
+ @include box-shadow(none);
414
+ }
415
+ }
416
+
417
+ .fs-opt-in-pointer
418
+ {
419
+ .wp-pointer-content
420
+ {
421
+ padding: 0;
422
+ }
423
+
424
+ &.wp-pointer-top
425
+ {
426
+ .wp-pointer-arrow
427
+ {
428
+ border-bottom-color: #dfdfdf;
429
+ }
430
+ .wp-pointer-arrow-inner
431
+ {
432
+ border-bottom-color: #fafafa;
433
+ }
434
+ }
435
+
436
+ &.wp-pointer-bottom
437
+ {
438
+ .wp-pointer-arrow
439
+ {
440
+ border-top-color: #dfdfdf;
441
+ }
442
+ .wp-pointer-arrow-inner
443
+ {
444
+ border-top-color: #fafafa;
445
+ }
446
+ }
447
+
448
+ &.wp-pointer-left
449
+ {
450
+ .wp-pointer-arrow
451
+ {
452
+ border-right-color: #dfdfdf;
453
+ }
454
+ .wp-pointer-arrow-inner
455
+ {
456
+ border-right-color: #fafafa;
457
+ }
458
+ }
459
+
460
+ &.wp-pointer-right
461
+ {
462
+ .wp-pointer-arrow
463
+ {
464
+ border-left-color: #dfdfdf;
465
+ }
466
+ .wp-pointer-arrow-inner
467
+ {
468
+ border-left-color: #fafafa;
469
+ }
470
+ }
471
+ }
freemius/assets/scss/admin/deactivation-feedback.scss ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal {
2
+ position: fixed;
3
+ overflow: auto;
4
+ height: 100%;
5
+ width: 100%;
6
+ top: 0;
7
+ z-index: 100000;
8
+ display: none;
9
+ background: rgba(0, 0, 0, 0.6);
10
+
11
+ .fs-modal-dialog {
12
+ background: transparent;
13
+ position: absolute;
14
+ left: 50%;
15
+ margin-left: -298px;
16
+ padding-bottom: 30px;
17
+ top: -100%;
18
+ z-index: 100001;
19
+ width: 596px;
20
+
21
+ @media (max-width: 650px) {
22
+ margin-left: -50%;
23
+ box-sizing: border-box;
24
+ padding-left: 10px;
25
+ padding-right: 10px;
26
+ width: 100%;
27
+
28
+ .fs-modal-panel > h3 > strong {
29
+ font-size: 1.3em;
30
+ }
31
+
32
+ li.reason {
33
+ margin-bottom: 10px;
34
+
35
+ .reason-input {
36
+ margin-left: 29px;
37
+ }
38
+
39
+ label {
40
+ display: table;
41
+
42
+ > span {
43
+ display: table-cell;
44
+ font-size: 1.3em;
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ &.active {
52
+ display: block;
53
+
54
+ &:before {
55
+ display: block;
56
+ }
57
+
58
+ .fs-modal-dialog {
59
+ top: 10%;
60
+ }
61
+ }
62
+
63
+ .fs-modal-body,
64
+ .fs-modal-footer {
65
+ border: 0;
66
+ background: #fefefe;
67
+ padding: 20px;
68
+ }
69
+
70
+ .fs-modal-body {
71
+ border-bottom: 0;
72
+
73
+ h2 {
74
+ font-size: 20px;
75
+ }
76
+
77
+ > div {
78
+ margin-top: 10px;
79
+
80
+ h2 {
81
+ font-weight: bold;
82
+ font-size: 20px;
83
+ margin-top: 0;
84
+ }
85
+ }
86
+ }
87
+
88
+ .fs-modal-footer {
89
+ border-top: #eeeeee solid 1px;
90
+ text-align: right;
91
+
92
+ > .button {
93
+ margin: 0 7px;
94
+
95
+ &:first-child {
96
+ margin: 0;
97
+ }
98
+ }
99
+ }
100
+
101
+ .fs-modal-panel:not(.active) {
102
+ display: none;
103
+ }
104
+
105
+ .reason-input {
106
+ margin: 3px 0 3px 22px;
107
+
108
+ input, textarea {
109
+ width: 100%;
110
+ }
111
+ }
112
+ }
113
+
114
+ body.has-fs-modal {
115
+ overflow: hidden;
116
+ }
117
+
118
+ #the-list .deactivate > .fs-slug {
119
+ display: none;
120
+ }
freemius/assets/scss/admin/debug.scss ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../start";
2
+
3
+ .switch
4
+ {
5
+ position: relative;
6
+ display: inline-block;
7
+ font-size: 1.6em;
8
+ font-weight: bold;
9
+ color: #ccc;
10
+ text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8);
11
+ height: 18px;
12
+ padding: 6px 6px 5px 6px;
13
+ border: 1px solid #ccc;
14
+ border: 1px solid rgba(0, 0, 0, 0.2);
15
+ border-radius: 4px;
16
+ background: #ececec;
17
+ box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1), inset 0px 1px 3px 0px rgba(0, 0, 0, 0.1);
18
+ cursor: pointer;
19
+
20
+ span
21
+ {
22
+ display: inline-block; width: 35px;
23
+ text-transform: uppercase;
24
+
25
+ &.on
26
+ {
27
+ color: $button-primary-bkg;
28
+ }
29
+ }
30
+
31
+ .toggle
32
+ {
33
+ position: absolute;
34
+ top: 1px;
35
+ width: 37px;
36
+ height: 25px;
37
+ border: 1px solid #ccc;
38
+ border: 1px solid rgba(0, 0, 0, 0.3);
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ background: -moz-linear-gradient(top, #ececec 0%, #fff 100%);
42
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ececec), color-stop(100%, #fff));
43
+ background: -webkit-linear-gradient(top, #ececec 0%, #fff 100%);
44
+ background: -o-linear-gradient(top, #ececec 0%, #fff 100%);
45
+ background: -ms-linear-gradient(top, #ececec 0%, #fff 100%);
46
+ background: linear-gradient(top, #ececec 0%, #fff 100%);
47
+ box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, 0.5);
48
+ z-index: 999;
49
+ @include transition(all 0.15s ease-in-out);
50
+ }
51
+
52
+ &.on .toggle
53
+ {
54
+ left: 2%;
55
+ }
56
+ &.off .toggle
57
+ {
58
+ left: 54%;
59
+ }
60
+
61
+ /* Round switch */
62
+ &.round
63
+ {
64
+ padding: 0px 20px;
65
+ border-radius: 40px;
66
+
67
+ .toggle
68
+ {
69
+ border-radius: 40px;
70
+ width: 14px;
71
+ height: 14px;
72
+ }
73
+
74
+ &.on .toggle
75
+ {
76
+ left: 3%;
77
+ background: $button-primary-bkg;
78
+ }
79
+ &.off .toggle
80
+ {
81
+ left: 58%;
82
+ }
83
+ }
84
+ }
85
+
86
+ .switch-label
87
+ {
88
+ font-size: 20px;
89
+ line-height: 31px;
90
+ margin: 0 5px;
91
+ }
freemius/assets/scss/admin/license-activation.scss ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .fs-modal {
2
+ position: fixed;
3
+ overflow: auto;
4
+ height: 100%;
5
+ width: 100%;
6
+ top: 0;
7
+ z-index: 100000;
8
+ display: none;
9
+ background: rgba(0, 0, 0, 0.6);
10
+
11
+ .fs-modal-dialog {
12
+ background: transparent;
13
+ position: absolute;
14
+ left: 50%;
15
+ margin-left: -298px;
16
+ padding-bottom: 30px;
17
+ top: -100%;
18
+ z-index: 100001;
19
+ width: 596px;
20
+
21
+ @media (max-width: 650px) {
22
+ margin-left: -50%;
23
+ box-sizing: border-box;
24
+ padding-left: 10px;
25
+ padding-right: 10px;
26
+ width: 100%;
27
+
28
+ .fs-modal-panel > h3 > strong {
29
+ font-size: 1.3em;
30
+ }
31
+ }
32
+ }
33
+
34
+ &.active {
35
+ display: block;
36
+
37
+ &:before {
38
+ display: block;
39
+ }
40
+
41
+ .fs-modal-dialog {
42
+ top: 10%;
43
+ }
44
+ }
45
+
46
+ .fs-modal-body,
47
+ .fs-modal-footer {
48
+ border: 0;
49
+ background: #fefefe;
50
+ padding: 20px;
51
+ }
52
+
53
+ .fs-modal-body {
54
+ border-bottom: 0;
55
+
56
+ input.license_key {
57
+ width: 100%;
58
+ }
59
+
60
+ p {
61
+ font-size: 14px;
62
+ }
63
+
64
+ h2 {
65
+ font-size: 20px;
66
+ }
67
+
68
+ > div {
69
+ margin-top: 10px;
70
+
71
+ h2 {
72
+ font-weight: bold;
73
+ font-size: 20px;
74
+ margin-top: 0;
75
+ }
76
+ }
77
+ }
78
+
79
+ .fs-modal-footer {
80
+ border-top: #eeeeee solid 1px;
81
+ text-align: right;
82
+
83
+ > .button {
84
+ margin: 0 7px;
85
+
86
+ &:first-child {
87
+ margin: 0;
88
+ }
89
+ }
90
+ }
91
+
92
+ .fs-modal-panel:not(.active) {
93
+ display: none;
94
+ }
95
+ }
96
+
97
+ body.has-fs-modal {
98
+ overflow: hidden;
99
+ }
freemius/composer.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "freemius/wordpress-sdk",
3
+ "description": "Freemius WordPress SDK",
4
+ "keywords": ["freemius", "wordpress", "plugin", "sdk"],
5
+ "homepage": "https://freemius.com",
6
+ "license": "GPL-2.0+",
7
+ "require": {
8
+ "php": ">=5.2"
9
+ }
10
+ }
freemius/config.php ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SLUG', 'freemius' );
14
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
15
+ define( 'WP_FS__DEV_MODE', false );
16
+ }
17
+
18
+ /**
19
+ * API Connectivity Simulation
20
+ */
21
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
22
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
23
+ }
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
+ }
33
+ if ( WP_FS__SIMULATE_NO_CURL ) {
34
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
37
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
41
+ }
42
+
43
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
44
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
45
+ }
46
+
47
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
48
+ /**
49
+ * @since 1.1.7.3
50
+ * @author Vova Feldman (@svovaf)
51
+ *
52
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
53
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
54
+ * between domains on a daily basis. Therefore, to eliminate the risk of
55
+ * multiple unwanted connectivity test pings, temporary ignore domain or
56
+ * server IP changes.
57
+ */
58
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
59
+ }
60
+
61
+ /**
62
+ * If your dev environment supports custom public network IP setup
63
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
64
+ * and uncomment it during dev.
65
+ */
66
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
67
+ // VVV default public network IP.
68
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
69
+
70
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
71
+ }
72
+
73
+ /**
74
+ * If true and running with secret key, the opt-in process
75
+ * will skip the email activation process which is invoked
76
+ * when the email of the context user already exist in Freemius
77
+ * database (as a security precaution, to prevent sharing user
78
+ * secret with unauthorized entity).
79
+ *
80
+ * IMPORTANT:
81
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
82
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
83
+ * CLOCK IS SYNCED.
84
+ */
85
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
86
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
87
+ }
88
+
89
+
90
+ /**
91
+ * Directories
92
+ */
93
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
94
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
95
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
96
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
97
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
98
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
99
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
100
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
101
+
102
+
103
+ /**
104
+ * Domain / URL / Address
105
+ */
106
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
107
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
108
+
109
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
110
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
111
+ }
112
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
113
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
114
+ }
115
+
116
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
117
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
118
+ }
119
+
120
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
121
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
122
+ }
123
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
124
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
125
+ }
126
+
127
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
128
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
129
+
130
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
131
+ // By default, run with Freemius production servers.
132
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
133
+ }
134
+
135
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
136
+
137
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
138
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
139
+ } else {
140
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
141
+ is_string( WP_FS__REMOTE_ADDR ) &&
142
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) == '127.' ||
143
+ WP_FS__REMOTE_ADDR == '::1' )
144
+ );
145
+ }
146
+
147
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
148
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
149
+
150
+ // Set API address for local testing.
151
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
152
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
153
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
154
+ }
155
+
156
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
157
+
158
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
159
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
160
+ }
161
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
162
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
163
+ }
164
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
165
+
166
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
167
+ // Checks if CloudFlare's HTTPS (Flexible SSL support)
168
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) ||
169
+ // Check if HTTPS request.
170
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
171
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
172
+ );
173
+
174
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
175
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
176
+
177
+ /**
178
+ * Billing Frequencies
179
+ */
180
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
181
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
182
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
183
+
184
+ /**
185
+ * Plans
186
+ */
187
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
188
+ define( 'WP_FS__PLAN_FREE', 'free' );
189
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
190
+
191
+ /**
192
+ * Times in seconds
193
+ */
194
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
195
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
196
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
197
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
198
+
199
+ /**
200
+ * Debugging
201
+ */
202
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
203
+ $debug_mode = get_option( 'fs_debug_mode', null );
204
+
205
+ if ( $debug_mode === null ) {
206
+ $debug_mode = false;
207
+ add_option( 'fs_debug_mode', $debug_mode );
208
+ }
209
+
210
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
211
+ }
212
+
213
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
214
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-n-d H:i:s' );
215
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
216
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
217
+ }
218
+
219
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
220
+ error_reporting( E_ALL );
221
+ ini_set( 'error_reporting', E_ALL );
222
+ ini_set( 'display_errors', true );
223
+ ini_set( 'html_errors', true );
224
+ }
225
+
226
+
227
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
228
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
229
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
freemius/includes/class-freemius-abstract.php ADDED
@@ -0,0 +1,454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+
13
+ /**
14
+ * - Each instance of Freemius class represents a single plugin
15
+ * install by a single user (the installer of the plugin).
16
+ *
17
+ * - Each website can only have one install of the same plugin.
18
+ *
19
+ * - Install entity is only created after a user connects his account with Freemius.
20
+ *
21
+ * Class Freemius_Abstract
22
+ */
23
+ abstract class Freemius_Abstract {
24
+
25
+ #region Identity ------------------------------------------------------------------
26
+
27
+ /**
28
+ * Check if user registered with Freemius by connecting his account.
29
+ *
30
+ * @since 1.0.1
31
+ * @return bool
32
+ */
33
+ abstract function is_registered();
34
+
35
+ /**
36
+ * Check if the user skipped connecting the account with Freemius.
37
+ *
38
+ * @since 1.0.7
39
+ *
40
+ * @return bool
41
+ */
42
+ abstract function is_anonymous();
43
+
44
+ /**
45
+ * Check if the user currently in activation mode.
46
+ *
47
+ * @since 1.0.7
48
+ *
49
+ * @return bool
50
+ */
51
+ abstract function is_activation_mode();
52
+
53
+ #endregion Identity ------------------------------------------------------------------
54
+
55
+ #region Permissions ------------------------------------------------------------------
56
+
57
+ /**
58
+ * Check if plugin must be WordPress.org compliant.
59
+ *
60
+ * @since 1.0.7
61
+ *
62
+ * @return bool
63
+ */
64
+ abstract function is_org_repo_compliant();
65
+
66
+ /**
67
+ * Check if plugin is allowed to install executable files.
68
+ *
69
+ * @author Vova Feldman (@svovaf)
70
+ * @since 1.0.5
71
+ *
72
+ * @return bool
73
+ */
74
+ function is_allowed_to_install() {
75
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
76
+ }
77
+
78
+ #endregion Permissions ------------------------------------------------------------------
79
+
80
+ /**
81
+ * Check if user in trial or in free plan (not paying).
82
+ *
83
+ * @author Vova Feldman (@svovaf)
84
+ * @since 1.0.4
85
+ *
86
+ * @return bool
87
+ */
88
+ function is_not_paying() {
89
+ return ( $this->is_trial() || $this->is_free_plan() );
90
+ }
91
+
92
+ /**
93
+ * Check if the user has an activated and valid paid license on current plugin's install.
94
+ *
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ abstract function is_paying();
100
+
101
+ /**
102
+ * Check if the user is paying or in trial.
103
+ *
104
+ * @since 1.0.9
105
+ *
106
+ * @return bool
107
+ */
108
+ function is_paying_or_trial() {
109
+ return ( $this->is_paying() || $this->is_trial() );
110
+ }
111
+
112
+ /**
113
+ * Check if user in a trial or have feature enabled license.
114
+ *
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.1.7
117
+ *
118
+ * @return bool
119
+ */
120
+ abstract function can_use_premium_code();
121
+
122
+ #region Premium Only ------------------------------------------------------------------
123
+
124
+ /**
125
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
126
+ * included in the premium code.
127
+ *
128
+ * Example:
129
+ * if ( freemius()->is__premium_only() ) {
130
+ * ...
131
+ * }
132
+ */
133
+
134
+ /**
135
+ * Returns true when running premium plugin code.
136
+ *
137
+ * @since 1.0.9
138
+ *
139
+ * @return bool
140
+ */
141
+ function is__premium_only() {
142
+ return $this->is_premium();
143
+ }
144
+
145
+ /**
146
+ * Check if the user has an activated and valid paid license on current plugin's install.
147
+ *
148
+ * @since 1.0.9
149
+ *
150
+ * @return bool
151
+ *
152
+ */
153
+ function is_paying__premium_only() {
154
+ return ( $this->is__premium_only() && $this->is_paying() );
155
+ }
156
+
157
+ /**
158
+ * All code wrapped in this statement will be only included in the premium code.
159
+ *
160
+ * @since 1.0.9
161
+ *
162
+ * @param string $plan Plan name
163
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
164
+ *
165
+ * @return bool
166
+ */
167
+ function is_plan__premium_only( $plan, $exact = false ) {
168
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
169
+ }
170
+
171
+ /**
172
+ * Check if plan matches active license' plan or active trial license' plan.
173
+ *
174
+ * All code wrapped in this statement will be only included in the premium code.
175
+ *
176
+ * @since 1.0.9
177
+ *
178
+ * @param string $plan Plan name
179
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
180
+ *
181
+ * @return bool
182
+ */
183
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
184
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
185
+ }
186
+
187
+ /**
188
+ * Check if the user is paying or in trial.
189
+ *
190
+ * All code wrapped in this statement will be only included in the premium code.
191
+ *
192
+ * @since 1.0.9
193
+ *
194
+ * @return bool
195
+ */
196
+ function is_paying_or_trial__premium_only() {
197
+ return $this->is_premium() && $this->is_paying_or_trial();
198
+ }
199
+
200
+ /**
201
+ * Check if the user has an activated and valid paid license on current plugin's install.
202
+ *
203
+ * @since 1.0.4
204
+ *
205
+ * @return bool
206
+ *
207
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
208
+ * @using Alias to is_paying__premium_only()
209
+ */
210
+ function is_paying__fs__() {
211
+ return $this->is_paying__premium_only();
212
+ }
213
+
214
+ /**
215
+ * Check if user in a trial or have feature enabled license.
216
+ *
217
+ * All code wrapped in this statement will be only included in the premium code.
218
+ *
219
+ * @author Vova Feldman (@svovaf)
220
+ * @since 1.1.9
221
+ *
222
+ * @return bool
223
+ */
224
+ function can_use_premium_code__premium_only() {
225
+ return $this->is_premium() && $this->can_use_premium_code();
226
+ }
227
+
228
+ #endregion Premium Only ------------------------------------------------------------------
229
+
230
+ #region Trial ------------------------------------------------------------------
231
+
232
+ /**
233
+ * Check if the user in a trial.
234
+ *
235
+ * @since 1.0.3
236
+ *
237
+ * @return bool
238
+ */
239
+ abstract function is_trial();
240
+
241
+ /**
242
+ * Check if trial already utilized.
243
+ *
244
+ * @since 1.0.9
245
+ *
246
+ * @return bool
247
+ */
248
+ abstract function is_trial_utilized();
249
+
250
+ #endregion Trial ------------------------------------------------------------------
251
+
252
+ #region Plans ------------------------------------------------------------------
253
+
254
+ /**
255
+ * Check if plugin using the free plan.
256
+ *
257
+ * @since 1.0.4
258
+ *
259
+ * @return bool
260
+ */
261
+ abstract function is_free_plan();
262
+
263
+ /**
264
+ * @since 1.0.2
265
+ *
266
+ * @param string $plan Plan name
267
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
268
+ *
269
+ * @return bool
270
+ */
271
+ abstract function is_plan( $plan, $exact = false );
272
+
273
+ /**
274
+ * Check if plan based on trial. If not in trial mode, should return false.
275
+ *
276
+ * @since 1.0.9
277
+ *
278
+ * @param string $plan Plan name
279
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
280
+ *
281
+ * @return bool
282
+ */
283
+ abstract function is_trial_plan( $plan, $exact = false );
284
+
285
+ /**
286
+ * Check if plan matches active license' plan or active trial license' plan.
287
+ *
288
+ * @since 1.0.9
289
+ *
290
+ * @param string $plan Plan name
291
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
292
+ *
293
+ * @return bool
294
+ */
295
+ function is_plan_or_trial( $plan, $exact = false ) {
296
+ return $this->is_plan( $plan, $exact ) ||
297
+ $this->is_trial_plan( $plan, $exact );
298
+ }
299
+
300
+ /**
301
+ * Check if plugin has any paid plans.
302
+ *
303
+ * @author Vova Feldman (@svovaf)
304
+ * @since 1.0.7
305
+ *
306
+ * @return bool
307
+ */
308
+ abstract function has_paid_plan();
309
+
310
+ /**
311
+ * Check if plugin has any free plan, or is it premium only.
312
+ *
313
+ * Note: If no plans configured, assume plugin is free.
314
+ *
315
+ * @author Vova Feldman (@svovaf)
316
+ * @since 1.0.7
317
+ *
318
+ * @return bool
319
+ */
320
+ abstract function has_free_plan();
321
+
322
+ /**
323
+ * Check if plugin is premium only (no free plans).
324
+ *
325
+ * NOTE: is__premium_only() is very different method, don't get confused.
326
+ *
327
+ * @author Vova Feldman (@svovaf)
328
+ * @since 1.1.9
329
+ *
330
+ * @return bool
331
+ */
332
+ abstract function is_only_premium();
333
+
334
+ /**
335
+ * Checks if it's a freemium plugin.
336
+ *
337
+ * @author Vova Feldman (@svovaf)
338
+ * @since 1.1.9
339
+ *
340
+ * @return bool
341
+ */
342
+ function is_freemium() {
343
+ return ! $this->is_only_premium() &&
344
+ $this->has_paid_plan() &&
345
+ $this->has_free_plan();
346
+ }
347
+
348
+ #endregion Plans ------------------------------------------------------------------
349
+
350
+ /**
351
+ * Check if running payments in sandbox mode.
352
+ *
353
+ * @since 1.0.4
354
+ *
355
+ * @return bool
356
+ */
357
+ abstract function is_payments_sandbox();
358
+
359
+ /**
360
+ * Check if running test vs. live plugin.
361
+ *
362
+ * @since 1.0.5
363
+ *
364
+ * @return bool
365
+ */
366
+ abstract function is_live();
367
+
368
+ /**
369
+ * Check if running premium plugin code.
370
+ *
371
+ * @since 1.0.5
372
+ *
373
+ * @return bool
374
+ */
375
+ abstract function is_premium();
376
+
377
+ /**
378
+ * Get upgrade URL.
379
+ *
380
+ * @author Vova Feldman (@svovaf)
381
+ * @since 1.0.2
382
+ *
383
+ * @param string $period Billing cycle
384
+ *
385
+ * @return string
386
+ */
387
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
388
+
389
+ /**
390
+ * Check if Freemius was first added in a plugin update.
391
+ *
392
+ * @author Vova Feldman (@svovaf)
393
+ * @since 1.1.5
394
+ *
395
+ * @return bool
396
+ */
397
+ function is_plugin_update() {
398
+ return ! $this->is_plugin_new_install();
399
+ }
400
+
401
+ /**
402
+ * Check if Freemius was part of the plugin when the user installed it first.
403
+ *
404
+ * @author Vova Feldman (@svovaf)
405
+ * @since 1.1.5
406
+ *
407
+ * @return bool
408
+ */
409
+ abstract function is_plugin_new_install();
410
+
411
+ #region Marketing ------------------------------------------------------------------
412
+
413
+ /**
414
+ * Check if current user purchased any other plugins before.
415
+ *
416
+ * @author Vova Feldman (@svovaf)
417
+ * @since 1.0.9
418
+ *
419
+ * @return bool
420
+ */
421
+ abstract function has_purchased_before();
422
+
423
+ /**
424
+ * Check if current user classified as an agency.
425
+ *
426
+ * @author Vova Feldman (@svovaf)
427
+ * @since 1.0.9
428
+ *
429
+ * @return bool
430
+ */
431
+ abstract function is_agency();
432
+
433
+ /**
434
+ * Check if current user classified as a developer.
435
+ *
436
+ * @author Vova Feldman (@svovaf)
437
+ * @since 1.0.9
438
+ *
439
+ * @return bool
440
+ */
441
+ abstract function is_developer();
442
+
443
+ /**
444
+ * Check if current user classified as a business.
445
+ *
446
+ * @author Vova Feldman (@svovaf)
447
+ * @since 1.0.9
448
+ *
449
+ * @return bool
450
+ */
451
+ abstract function is_business();
452
+
453
+ #endregion ------------------------------------------------------------------
454
+ }
freemius/includes/class-freemius.php ADDED
@@ -0,0 +1,9762 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ // "final class"
13
+ class Freemius extends Freemius_Abstract {
14
+ /**
15
+ * SDK Version
16
+ *
17
+ * @var string
18
+ */
19
+ public $version = WP_FS__SDK_VERSION;
20
+
21
+ #region Plugin Info
22
+
23
+ /**
24
+ * @since 1.0.1
25
+ *
26
+ * @var string
27
+ */
28
+ private $_slug;
29
+
30
+ /**
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ private $_plugin_basename;
36
+ /**
37
+ * @since 1.0.0
38
+ *
39
+ * @var string
40
+ */
41
+ private $_free_plugin_basename;
42
+ /**
43
+ * @since 1.0.0
44
+ *
45
+ * @var string
46
+ */
47
+ private $_plugin_dir_path;
48
+ /**
49
+ * @since 1.0.0
50
+ *
51
+ * @var string
52
+ */
53
+ private $_plugin_dir_name;
54
+ /**
55
+ * @since 1.0.0
56
+ *
57
+ * @var string
58
+ */
59
+ private $_plugin_main_file_path;
60
+ /**
61
+ * @var string[]
62
+ */
63
+ private $_plugin_data;
64
+ /**
65
+ * @since 1.0.9
66
+ *
67
+ * @var string
68
+ */
69
+ private $_plugin_name;
70
+
71
+ #endregion Plugin Info
72
+
73
+ /**
74
+ * @since 1.0.9
75
+ *
76
+ * @var bool If false, don't turn Freemius on.
77
+ */
78
+ private $_is_on;
79
+
80
+ /**
81
+ * @since 1.1.3
82
+ *
83
+ * @var bool If false, don't turn Freemius on.
84
+ */
85
+ private $_is_anonymous;
86
+
87
+ /**
88
+ * @since 1.0.9
89
+ * @var bool If false, issues with connectivity to Freemius API.
90
+ */
91
+ private $_has_api_connection;
92
+
93
+ /**
94
+ * @since 1.0.9
95
+ * @var bool Hints the SDK if plugin can support anonymous mode (if skip connect is visible).
96
+ */
97
+ private $_enable_anonymous;
98
+
99
+ /**
100
+ * @since 1.1.7.5
101
+ * @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
102
+ */
103
+ private $_anonymous_mode;
104
+
105
+ /**
106
+ * @since 1.1.9
107
+ * @var bool Hints the SDK if plugin have any free plans.
108
+ */
109
+ private $_is_premium_only;
110
+
111
+ /**
112
+ * @since 1.0.8
113
+ * @var bool Hints the SDK if the plugin has any paid plans.
114
+ */
115
+ private $_has_paid_plans;
116
+
117
+ /**
118
+ * @since 1.0.7
119
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
120
+ */
121
+ private $_is_org_compliant;
122
+
123
+ /**
124
+ * @since 1.0.7
125
+ * @var bool Hints the SDK if the plugin is has add-ons.
126
+ */
127
+ private $_has_addons;
128
+
129
+ /**
130
+ * @since 1.1.6
131
+ * @var string[]bool.
132
+ */
133
+ private $_permissions;
134
+
135
+ /**
136
+ * @var FS_Key_Value_Storage
137
+ */
138
+ private $_storage;
139
+
140
+ /**
141
+ * @since 1.0.0
142
+ *
143
+ * @var FS_Logger
144
+ */
145
+ private $_logger;
146
+ /**
147
+ * @since 1.0.4
148
+ *
149
+ * @var FS_Plugin
150
+ */
151
+ private $_plugin = false;
152
+ /**
153
+ * @since 1.0.4
154
+ *
155
+ * @var FS_Plugin|false
156
+ */
157
+ private $_parent_plugin = false;
158
+ /**
159
+ * @since 1.1.1
160
+ *
161
+ * @var Freemius
162
+ */
163
+ private $_parent = false;
164
+ /**
165
+ * @since 1.0.1
166
+ *
167
+ * @var FS_User
168
+ */
169
+ private $_user = false;
170
+ /**
171
+ * @since 1.0.1
172
+ *
173
+ * @var FS_Site
174
+ */
175
+ private $_site = false;
176
+ /**
177
+ * @since 1.0.1
178
+ *
179
+ * @var FS_Plugin_License
180
+ */
181
+ private $_license;
182
+ /**
183
+ * @since 1.0.2
184
+ *
185
+ * @var FS_Plugin_Plan[]
186
+ */
187
+ private $_plans = false;
188
+ /**
189
+ * @var FS_Plugin_License[]
190
+ * @since 1.0.5
191
+ */
192
+ private $_licenses = false;
193
+
194
+ /**
195
+ * @since 1.0.1
196
+ *
197
+ * @var FS_Admin_Menu_Manager
198
+ */
199
+ private $_menu;
200
+
201
+ /**
202
+ * @var FS_Admin_Notice_Manager
203
+ */
204
+ private $_admin_notices;
205
+
206
+ /**
207
+ * @since 1.1.6
208
+ *
209
+ * @var FS_Admin_Notice_Manager
210
+ */
211
+ private static $_global_admin_notices;
212
+
213
+ /**
214
+ * @var FS_Logger
215
+ * @since 1.0.0
216
+ */
217
+ private static $_static_logger;
218
+
219
+ /**
220
+ * @var FS_Option_Manager
221
+ * @since 1.0.2
222
+ */
223
+ private static $_accounts;
224
+
225
+ /**
226
+ * @var Freemius[]
227
+ */
228
+ private static $_instances = array();
229
+
230
+
231
+ /* Ctor
232
+ ------------------------------------------------------------------------------------------------------------------*/
233
+
234
+ private function __construct( $slug ) {
235
+ $this->_slug = $slug;
236
+
237
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
238
+
239
+ $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
240
+
241
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file();
242
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
243
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
244
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
245
+
246
+ $base_name_split = explode( '/', $this->_plugin_basename );
247
+ $this->_plugin_dir_name = $base_name_split[0];
248
+
249
+ if ( $this->_logger->is_on() ) {
250
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
251
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
252
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
253
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
254
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
255
+ }
256
+
257
+ // Remember link between file to slug.
258
+ $this->store_file_slug_map();
259
+
260
+ // Store plugin's initial install timestamp.
261
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
262
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
263
+ }
264
+
265
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
266
+
267
+ $this->_admin_notices = FS_Admin_Notice_Manager::instance(
268
+ $slug,
269
+ is_object( $this->_plugin ) ? $this->_plugin->title : ''
270
+ );
271
+
272
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
273
+ 'true' === fs_request_is_action( 'restart_freemius' )
274
+ ) {
275
+ FS_Api::clear_cache();
276
+ }
277
+
278
+ $this->_register_hooks();
279
+
280
+ $this->_load_account();
281
+
282
+ $this->_version_updates_handler();
283
+ }
284
+
285
+ /**
286
+ * @author Vova Feldman (@svovaf)
287
+ * @since 1.0.9
288
+ */
289
+ private function _version_updates_handler() {
290
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
291
+ // Freemius version upgrade mode.
292
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
293
+ $this->_storage->sdk_version = $this->version;
294
+
295
+ if ( empty( $this->_storage->sdk_last_version ) ||
296
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
297
+ ) {
298
+ $this->_storage->sdk_upgrade_mode = true;
299
+ $this->_storage->sdk_downgrade_mode = false;
300
+ } else {
301
+ $this->_storage->sdk_downgrade_mode = true;
302
+ $this->_storage->sdk_upgrade_mode = false;
303
+
304
+ }
305
+
306
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
307
+ }
308
+
309
+ $plugin_version = $this->get_plugin_version();
310
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
311
+ // Plugin version upgrade mode.
312
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
313
+ $this->_storage->plugin_version = $plugin_version;
314
+
315
+ if ( empty( $this->_storage->plugin_last_version ) ||
316
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
317
+ ) {
318
+ $this->_storage->plugin_upgrade_mode = true;
319
+ $this->_storage->plugin_downgrade_mode = false;
320
+ } else {
321
+ $this->_storage->plugin_downgrade_mode = true;
322
+ $this->_storage->plugin_upgrade_mode = false;
323
+ }
324
+
325
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
326
+ // Different version of the plugin was installed before, therefore it's an update.
327
+ $this->_storage->is_plugin_new_install = false;
328
+ }
329
+
330
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
331
+ }
332
+ }
333
+
334
+ /**
335
+ * @author Vova Feldman (@svovaf)
336
+ * @since 1.1.5
337
+ *
338
+ * @param string $sdk_prev_version
339
+ * @param string $sdk_version
340
+ */
341
+ function _data_migration( $sdk_prev_version, $sdk_version ) {
342
+ /**
343
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
344
+ */
345
+ if ( empty( $sdk_prev_version ) ) {
346
+ return;
347
+ }
348
+
349
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
350
+ version_compare( $sdk_version, '1.1.5', '>=' )
351
+ ) {
352
+ // On version 1.1.5 merged connectivity and is_on data.
353
+ if ( isset( $this->_storage->connectivity_test ) ) {
354
+ if ( ! isset( $this->_storage->is_on ) ) {
355
+ unset( $this->_storage->connectivity_test );
356
+ } else {
357
+ $connectivity_data = $this->_storage->connectivity_test;
358
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
359
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
360
+
361
+ // Override.
362
+ $this->_storage->connectivity_test = $connectivity_data;
363
+
364
+ // Remove previous structure.
365
+ unset( $this->_storage->is_on );
366
+ }
367
+
368
+ }
369
+ }
370
+ }
371
+
372
+ /**
373
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
374
+ * if this is a new plugin installation or a plugin update.
375
+ *
376
+ * There are 3 different use-cases:
377
+ * 1) New plugin installation right with Freemius:
378
+ * 1.1 _activate_plugin_event_hook() will be executed first
379
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
380
+ * and $this->_storage->plugin_last_version is not set,
381
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
382
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
383
+ * be already set to TRUE.
384
+ *
385
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
386
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
387
+ * the activation hook do NOT fires on updates since WP 3.1.
388
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
389
+ * be empty, therefore, it will be set to FALSE.
390
+ *
391
+ * 3) Plugin update, had Freemius in prev version as well:
392
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
393
+ * before, $this->_storage->plugin_last_version will NOT be empty,
394
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
395
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
396
+ * already set, therefore, it will not be modified.
397
+ *
398
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
399
+ *
400
+ * NOTE:
401
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
402
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
403
+ * show the opt-in right away. The reason it will happen is because Freemius execution
404
+ * will be turned off till the plugin is fully loaded at least once
405
+ * (till $this->_storage->was_plugin_loaded is TRUE).
406
+ *
407
+ * @author Vova Feldman (@svovaf)
408
+ * @since 1.1.9
409
+ *
410
+ */
411
+ function _plugins_loaded() {
412
+ // Update flag that plugin was loaded with Freemius at least once.
413
+ $this->_storage->was_plugin_loaded = true;
414
+
415
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
416
+ $this->_storage->is_plugin_new_install = false;
417
+ }
418
+ }
419
+
420
+ /**
421
+ * @author Vova Feldman (@svovaf)
422
+ * @since 1.0.9
423
+ */
424
+ private function _register_hooks() {
425
+ if ( is_admin() ) {
426
+ // Hook to plugin activation
427
+ register_activation_hook( $this->_plugin_main_file_path, array(
428
+ &$this,
429
+ '_activate_plugin_event_hook'
430
+ ) );
431
+
432
+ /**
433
+ * Part of the mechanism to identify new plugin install vs. plugin update.
434
+ *
435
+ * @author Vova Feldman (@svovaf)
436
+ * @since 1.1.9
437
+ */
438
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
439
+ if ( $this->is_activation_mode( false ) ) {
440
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
441
+ } else {
442
+ // If was activated before, then it was already loaded before.
443
+ $this->_plugins_loaded();
444
+ }
445
+ }
446
+
447
+ // Hook to plugin uninstall.
448
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
449
+
450
+ if ( ! $this->is_ajax() ) {
451
+ if ( ! $this->is_addon() ) {
452
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
453
+ add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
454
+ }
455
+ }
456
+ }
457
+
458
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
459
+
460
+ add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
461
+
462
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
463
+
464
+ $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
465
+ }
466
+
467
+ /**
468
+ * @author Vova Feldman (@svovaf)
469
+ * @since 1.0.9
470
+ */
471
+ private function _register_account_hooks() {
472
+ if ( is_admin() ) {
473
+ if ( ! $this->is_ajax() ) {
474
+ if ( $this->apply_filters( 'show_trial', true ) && $this->has_trial_plan() ) {
475
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
476
+ if ( ! $this->_site->is_trial_utilized() &&
477
+ (
478
+ // Show promotion if never shown it yet and 24 hours after initial activation.
479
+ ( false === $last_time_trial_promotion_shown && $this->_storage->activation_timestamp < ( time() - WP_FS__TIME_24_HOURS_IN_SEC ) ) ||
480
+ // Show promotion in every 30 days.
481
+ ( is_numeric( $last_time_trial_promotion_shown ) && 30 * WP_FS__TIME_24_HOURS_IN_SEC < time() - $last_time_trial_promotion_shown ) )
482
+ ) {
483
+ $this->add_action( 'after_init_plugin_registered', array( &$this, '_add_trial_notice' ) );
484
+ }
485
+ }
486
+ }
487
+
488
+ // If user is paying or in trial and have the free version installed,
489
+ // assume that the deactivation is for the upgrade process.
490
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
491
+ add_action( 'wp_ajax_submit-uninstall-reason', array( &$this, '_submit_uninstall_reason_action' ) );
492
+
493
+ global $pagenow;
494
+ if ( 'plugins.php' === $pagenow ) {
495
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
496
+ }
497
+ }
498
+ }
499
+ }
500
+
501
+ /**
502
+ * Leverage backtrace to find caller plugin file path.
503
+ *
504
+ * @author Vova Feldman (@svovaf)
505
+ * @since 1.0.6
506
+ *
507
+ * @return string
508
+ *
509
+ * @uses fs_find_caller_plugin_file
510
+ */
511
+ private function _find_caller_plugin_file() {
512
+ // Try to load the cached value of the file path.
513
+ if ( isset( $this->_storage->plugin_main_file ) ) {
514
+ if ( file_exists( $this->_storage->plugin_main_file->path ) ) {
515
+ return $this->_storage->plugin_main_file->path;
516
+ }
517
+ }
518
+
519
+ $plugin_file = fs_find_caller_plugin_file();
520
+
521
+ $this->_storage->plugin_main_file = (object) array(
522
+ 'path' => fs_normalize_path( $plugin_file ),
523
+ );
524
+
525
+ return $plugin_file;
526
+ }
527
+
528
+
529
+ #region Deactivation Feedback Form ------------------------------------------------------------------
530
+
531
+ /**
532
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
533
+ * page.
534
+ *
535
+ * @author Vova Feldman (@svovaf)
536
+ * @author Leo Fajardo (@leorw)
537
+ * @since 1.1.2
538
+ */
539
+ function _add_deactivation_feedback_dialog_box() {
540
+ fs_enqueue_local_style( 'fs_deactivation_feedback', '/admin/deactivation-feedback.css' );
541
+
542
+ /* Check the type of user:
543
+ * 1. Long-term (long-term)
544
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
545
+ * 3. Short-term (short-term)
546
+ */
547
+ $is_long_term_user = true;
548
+
549
+ // Check if the site is at least 2 days old.
550
+ $time_installed = $this->_storage->install_timestamp;
551
+
552
+ // Difference in seconds.
553
+ $date_diff = time() - $time_installed;
554
+
555
+ // Convert seconds to days.
556
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
557
+
558
+ if ( $date_diff_days < 2 ) {
559
+ $is_long_term_user = false;
560
+ }
561
+
562
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
563
+
564
+ if ( $is_long_term_user ) {
565
+ $user_type = 'long-term';
566
+ } else {
567
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
568
+ $user_type = 'non-registered-and-non-anonymous-short-term';
569
+ } else {
570
+ $user_type = 'short-term';
571
+ }
572
+ }
573
+
574
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
575
+
576
+ // Load the HTML template for the deactivation feedback dialog box.
577
+ $vars = array(
578
+ 'reasons' => $uninstall_reasons,
579
+ 'slug' => $this->_slug
580
+ );
581
+
582
+ /**
583
+ * @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.
584
+ */
585
+ fs_require_template( 'deactivation-feedback-modal.php', $vars );
586
+ }
587
+
588
+ /**
589
+ * @author Leo Fajardo (leorw)
590
+ * @since 1.1.2
591
+ *
592
+ * @param string $user_type
593
+ *
594
+ * @return array The uninstall reasons for the specified user type.
595
+ */
596
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
597
+ $reason_found_better_plugin = array(
598
+ 'id' => 2,
599
+ 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
600
+ 'input_type' => 'textfield',
601
+ 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
602
+ );
603
+
604
+ $reason_temporary_deactivation = array(
605
+ 'id' => 15,
606
+ 'text' => __fs( 'reason-temporary-deactivation', $this->_slug ),
607
+ 'input_type' => '',
608
+ 'input_placeholder' => ''
609
+ );
610
+
611
+ $reason_other = array(
612
+ 'id' => 7,
613
+ 'text' => __fs( 'reason-other', $this->_slug ),
614
+ 'input_type' => 'textfield',
615
+ 'input_placeholder' => ''
616
+ );
617
+
618
+ $long_term_user_reasons = array(
619
+ array(
620
+ 'id' => 1,
621
+ 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
622
+ 'input_type' => '',
623
+ 'input_placeholder' => ''
624
+ ),
625
+ $reason_found_better_plugin,
626
+ array(
627
+ 'id' => 3,
628
+ 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
629
+ 'input_type' => '',
630
+ 'input_placeholder' => ''
631
+ ),
632
+ array(
633
+ 'id' => 4,
634
+ 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
635
+ 'input_type' => '',
636
+ 'input_placeholder' => ''
637
+ ),
638
+ array(
639
+ 'id' => 5,
640
+ 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
641
+ 'input_type' => '',
642
+ 'input_placeholder' => ''
643
+ )
644
+ );
645
+
646
+ if ( $this->is_paying() ) {
647
+ $long_term_user_reasons[] = array(
648
+ 'id' => 6,
649
+ 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
650
+ 'input_type' => 'textfield',
651
+ 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
652
+ );
653
+ }
654
+
655
+ $long_term_user_reasons[] = $reason_temporary_deactivation;
656
+ $long_term_user_reasons[] = $reason_other;
657
+
658
+ $uninstall_reasons = array(
659
+ 'long-term' => $long_term_user_reasons,
660
+ 'non-registered-and-non-anonymous-short-term' => array(
661
+ array(
662
+ 'id' => 8,
663
+ 'text' => __fs( 'reason-didnt-work', $this->_slug ),
664
+ 'input_type' => '',
665
+ 'input_placeholder' => ''
666
+ ),
667
+ array(
668
+ 'id' => 9,
669
+ 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
670
+ 'input_type' => '',
671
+ 'input_placeholder' => ''
672
+ ),
673
+ $reason_found_better_plugin,
674
+ $reason_temporary_deactivation,
675
+ $reason_other
676
+ ),
677
+ 'short-term' => array(
678
+ array(
679
+ 'id' => 10,
680
+ 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
681
+ 'input_type' => '',
682
+ 'input_placeholder' => ''
683
+ ),
684
+ $reason_found_better_plugin,
685
+ array(
686
+ 'id' => 11,
687
+ 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
688
+ 'input_type' => 'textarea',
689
+ 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
690
+ ),
691
+ array(
692
+ 'id' => 12,
693
+ 'text' => __fs( 'reason-not-working', $this->_slug ),
694
+ 'input_type' => 'textarea',
695
+ 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
696
+ ),
697
+ array(
698
+ 'id' => 13,
699
+ 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
700
+ 'input_type' => 'textarea',
701
+ 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
702
+ ),
703
+ array(
704
+ 'id' => 14,
705
+ 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
706
+ 'input_type' => 'textarea',
707
+ 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
708
+ ),
709
+ $reason_temporary_deactivation,
710
+ $reason_other
711
+ )
712
+ );
713
+
714
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
715
+
716
+ return $uninstall_reasons[ $user_type ];
717
+ }
718
+
719
+ /**
720
+ * Called after the user has submitted his reason for deactivating the plugin.
721
+ *
722
+ * @author Leo Fajardo (@leorw)
723
+ * @since 1.1.2
724
+ */
725
+ function _submit_uninstall_reason_action() {
726
+ if ( ! isset( $_POST['reason_id'] ) ) {
727
+ exit;
728
+ }
729
+
730
+ $reason_info = isset( $_REQUEST['reason_info'] ) ? trim( stripslashes( $_REQUEST['reason_info'] ) ) : '';
731
+
732
+ $reason = (object) array(
733
+ 'id' => $_POST['reason_id'],
734
+ 'info' => substr( $reason_info, 0, 128 )
735
+ );
736
+
737
+ $this->_storage->store( 'uninstall_reason', $reason );
738
+
739
+ // Print '1' for successful operation.
740
+ echo 1;
741
+ exit;
742
+ }
743
+
744
+ #endregion Deactivation Feedback Form ------------------------------------------------------------------
745
+
746
+ #region Instance ------------------------------------------------------------------
747
+
748
+ /**
749
+ * Main singleton instance.
750
+ *
751
+ * @author Vova Feldman (@svovaf)
752
+ * @since 1.0.0
753
+ *
754
+ * @param $slug
755
+ *
756
+ * @return Freemius
757
+ */
758
+ static function instance( $slug ) {
759
+ $slug = strtolower( $slug );
760
+
761
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
762
+ if ( 0 === count( self::$_instances ) ) {
763
+ self::_load_required_static();
764
+ }
765
+
766
+ self::$_instances[ $slug ] = new Freemius( $slug );
767
+ }
768
+
769
+ return self::$_instances[ $slug ];
770
+ }
771
+
772
+ /**
773
+ * @author Vova Feldman (@svovaf)
774
+ * @since 1.0.6
775
+ *
776
+ * @param string|number $slug_or_id
777
+ *
778
+ * @return bool
779
+ */
780
+ private static function has_instance( $slug_or_id ) {
781
+ return ! is_numeric( $slug_or_id ) ?
782
+ isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
783
+ ( false !== self::get_instance_by_id( $slug_or_id ) );
784
+ }
785
+
786
+ /**
787
+ * @author Vova Feldman (@svovaf)
788
+ * @since 1.0.6
789
+ *
790
+ * @param $id
791
+ *
792
+ * @return false|Freemius
793
+ */
794
+ static function get_instance_by_id( $id ) {
795
+ foreach ( self::$_instances as $slug => $instance ) {
796
+ if ( $id == $instance->get_id() ) {
797
+ return $instance;
798
+ }
799
+ }
800
+
801
+ return false;
802
+ }
803
+
804
+ /**
805
+ *
806
+ * @author Vova Feldman (@svovaf)
807
+ * @since 1.0.1
808
+ *
809
+ * @param $plugin_file
810
+ *
811
+ * @return false|Freemius
812
+ */
813
+ static function get_instance_by_file( $plugin_file ) {
814
+ $slug = self::find_slug_by_basename( $plugin_file );
815
+
816
+ return ( false !== $slug ) ?
817
+ self::instance( $slug ) :
818
+ false;
819
+ }
820
+
821
+ /**
822
+ * @author Vova Feldman (@svovaf)
823
+ * @since 1.0.6
824
+ *
825
+ * @return false|Freemius
826
+ */
827
+ function get_parent_instance() {
828
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
829
+ }
830
+
831
+ /**
832
+ * @author Vova Feldman (@svovaf)
833
+ * @since 1.0.6
834
+ *
835
+ * @param $slug_or_id
836
+ *
837
+ * @return bool|Freemius
838
+ */
839
+ function get_addon_instance( $slug_or_id ) {
840
+ return ! is_numeric( $slug_or_id ) ?
841
+ self::instance( strtolower( $slug_or_id ) ) :
842
+ self::get_instance_by_id( $slug_or_id );
843
+ }
844
+
845
+ #endregion ------------------------------------------------------------------
846
+
847
+ /**
848
+ * @author Vova Feldman (@svovaf)
849
+ * @since 1.0.6
850
+ *
851
+ * @return bool
852
+ */
853
+ function is_parent_plugin_installed() {
854
+ return self::has_instance( $this->_plugin->parent_plugin_id );
855
+ }
856
+
857
+ /**
858
+ * Check if add-on parent plugin in activation mode.
859
+ *
860
+ * @author Vova Feldman (@svovaf)
861
+ * @since 1.0.7
862
+ *
863
+ * @return bool
864
+ */
865
+ function is_parent_in_activation() {
866
+ $parent_fs = $this->get_parent_instance();
867
+ if ( ! is_object( $parent_fs ) ) {
868
+ return false;
869
+ }
870
+
871
+ return ( $parent_fs->is_activation_mode() );
872
+ }
873
+
874
+ /**
875
+ * Is plugin in activation mode.
876
+ *
877
+ * @author Vova Feldman (@svovaf)
878
+ * @since 1.0.7
879
+ *
880
+ * @param bool $and_on
881
+ *
882
+ * @return bool
883
+ */
884
+ function is_activation_mode( $and_on = true ) {
885
+ return (
886
+ ( $this->is_on() || ! $and_on ) &&
887
+ ! $this->is_registered() &&
888
+ ( ! $this->is_enable_anonymous() ||
889
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
890
+ );
891
+ }
892
+
893
+ /**
894
+ * Get collection of all active plugins.
895
+ *
896
+ * @author Vova Feldman (@svovaf)
897
+ * @since 1.0.9
898
+ *
899
+ * @return array[string]array
900
+ */
901
+ private static function get_active_plugins() {
902
+ self::require_plugin_essentials();
903
+
904
+ $active_plugin = array();
905
+ $all_plugins = get_plugins();
906
+ $active_plugins_basenames = get_option( 'active_plugins' );
907
+
908
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
909
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
910
+ }
911
+
912
+ return $active_plugin;
913
+ }
914
+
915
+ /**
916
+ * Get collection of all plugins.
917
+ *
918
+ * @author Vova Feldman (@svovaf)
919
+ * @since 1.1.8
920
+ *
921
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
922
+ */
923
+ private static function get_all_plugins() {
924
+ self::require_plugin_essentials();
925
+
926
+ $all_plugins = get_plugins();
927
+ $active_plugins_basenames = get_option( 'active_plugins' );
928
+
929
+ foreach ( $all_plugins as $basename => &$data ) {
930
+ // By default set to inactive (next foreach update the active plugins).
931
+ $data['is_active'] = false;
932
+ // Enrich with plugin slug.
933
+ $data['slug'] = self::get_plugin_slug( $basename );
934
+ }
935
+
936
+ // Flag active plugins.
937
+ foreach ( $active_plugins_basenames as $basename ) {
938
+ if ( isset( $all_plugins[ $basename ] ) ) {
939
+ $all_plugins[ $basename ]['is_active'] = true;
940
+ }
941
+ }
942
+
943
+ return $all_plugins;
944
+ }
945
+
946
+
947
+ /**
948
+ * Cached result of get_site_transient( 'update_plugins' )
949
+ *
950
+ * @author Vova Feldman (@svovaf)
951
+ * @since 1.1.8
952
+ *
953
+ * @var object
954
+ */
955
+ private static $_plugins_info;
956
+
957
+ /**
958
+ * Helper function to get specified plugin's slug.
959
+ *
960
+ * @author Vova Feldman (@svovaf)
961
+ * @since 1.1.8
962
+ *
963
+ * @param $basename
964
+ *
965
+ * @return string
966
+ */
967
+ private static function get_plugin_slug( $basename ) {
968
+ if ( ! isset( self::$_plugins_info ) ) {
969
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
970
+ }
971
+
972
+ $slug = '';
973
+
974
+ if ( is_object( self::$_plugins_info ) ) {
975
+ if ( isset( self::$_plugins_info->no_update ) &&
976
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
977
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
978
+ ) {
979
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
980
+ } else if ( isset( self::$_plugins_info->response ) &&
981
+ isset( self::$_plugins_info->response[ $basename ] ) &&
982
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
983
+ ) {
984
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
985
+ }
986
+ }
987
+
988
+ if ( empty( $slug ) ) {
989
+ // Try to find slug from FS data.
990
+ $slug = self::find_slug_by_basename( $basename );
991
+ }
992
+
993
+ if ( empty( $slug ) ) {
994
+ // Fallback to plugin's folder name.
995
+ $slug = dirname( $basename );
996
+ }
997
+
998
+ return $slug;
999
+ }
1000
+
1001
+ private static $_statics_loaded = false;
1002
+
1003
+ /**
1004
+ * Load static resources.
1005
+ *
1006
+ * @author Vova Feldman (@svovaf)
1007
+ * @since 1.0.1
1008
+ */
1009
+ private static function _load_required_static() {
1010
+ if ( self::$_statics_loaded ) {
1011
+ return;
1012
+ }
1013
+
1014
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
1015
+
1016
+ self::$_static_logger->entrance();
1017
+
1018
+ self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
1019
+
1020
+ self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
1021
+
1022
+ // Configure which Freemius powered plugins should be auto updated.
1023
+ // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
1024
+
1025
+ add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
1026
+
1027
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
1028
+
1029
+ self::$_statics_loaded = true;
1030
+ }
1031
+
1032
+ #region Debugging ------------------------------------------------------------------
1033
+
1034
+ /**
1035
+ * @author Vova Feldman (@svovaf)
1036
+ * @since 1.0.8
1037
+ */
1038
+ static function add_debug_page() {
1039
+ if ( ! current_user_can( 'activate_plugins' ) ) {
1040
+ return;
1041
+ }
1042
+
1043
+ self::$_static_logger->entrance();
1044
+
1045
+ $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
1046
+
1047
+ if ( WP_FS__DEV_MODE ) {
1048
+ // Add top-level debug menu item.
1049
+ $hook = add_menu_page(
1050
+ $title,
1051
+ $title,
1052
+ 'manage_options',
1053
+ 'freemius',
1054
+ array( 'Freemius', '_debug_page_render' )
1055
+ );
1056
+ } else {
1057
+ // Add hidden debug page.
1058
+ $hook = add_submenu_page(
1059
+ null,
1060
+ $title,
1061
+ $title,
1062
+ 'manage_options',
1063
+ 'freemius',
1064
+ array( 'Freemius', '_debug_page_render' )
1065
+ );
1066
+ }
1067
+
1068
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
1069
+ }
1070
+
1071
+ /**
1072
+ * @author Vova Feldman (@svovaf)
1073
+ * @since 1.1.7.3
1074
+ */
1075
+ static function _toggle_debug_mode() {
1076
+ if ( in_array( $_POST['is_on'], array( 0, 1 ) ) ) {
1077
+ update_option( 'fs_debug_mode', $_POST['is_on'] );
1078
+ }
1079
+
1080
+ exit;
1081
+ }
1082
+
1083
+ /**
1084
+ * @author Vova Feldman (@svovaf)
1085
+ * @since 1.0.8
1086
+ */
1087
+ static function _debug_page_actions() {
1088
+ self::_clean_admin_content_section();
1089
+
1090
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
1091
+ check_admin_referer( 'restart_freemius' );
1092
+
1093
+ self::$_accounts->clear( true );
1094
+
1095
+
1096
+ return;
1097
+ }
1098
+ }
1099
+
1100
+ /**
1101
+ * @author Vova Feldman (@svovaf)
1102
+ * @since 1.0.8
1103
+ */
1104
+ static function _debug_page_render() {
1105
+ self::$_static_logger->entrance();
1106
+
1107
+ $sites = self::get_all_sites();
1108
+ $users = self::get_all_users();
1109
+ $addons = self::get_all_addons();
1110
+ $account_addons = self::get_all_account_addons();
1111
+
1112
+ // $plans = self::get_all_plans();
1113
+ // $licenses = self::get_all_licenses();
1114
+
1115
+ $vars = array(
1116
+ 'sites' => $sites,
1117
+ 'users' => $users,
1118
+ 'addons' => $addons,
1119
+ 'account_addons' => $account_addons,
1120
+ );
1121
+
1122
+ fs_enqueue_local_style( 'fs_account', '/admin/debug.css' );
1123
+ fs_require_once_template( 'debug.php', $vars );
1124
+ }
1125
+
1126
+ #endregion ------------------------------------------------------------------
1127
+
1128
+ #region Connectivity Issues ------------------------------------------------------------------
1129
+
1130
+ /**
1131
+ * Check if Freemius should be turned on for the current plugin install.
1132
+ *
1133
+ * Note:
1134
+ * $this->_is_on is updated in has_api_connectivity()
1135
+ *
1136
+ * @author Vova Feldman (@svovaf)
1137
+ * @since 1.0.9
1138
+ *
1139
+ * @return bool
1140
+ */
1141
+ function is_on() {
1142
+ self::$_static_logger->entrance();
1143
+
1144
+ if ( isset( $this->_is_on ) ) {
1145
+ return $this->_is_on;
1146
+ }
1147
+
1148
+ // If already installed or pending then sure it's on :)
1149
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
1150
+ $this->_is_on = true;
1151
+
1152
+ return true;
1153
+ }
1154
+
1155
+ return false;
1156
+ }
1157
+
1158
+ /**
1159
+ * @author Vova Feldman (@svovaf)
1160
+ * @since 1.1.7.3
1161
+ *
1162
+ * @param bool $flush_if_no_connectivity
1163
+ *
1164
+ * @return bool
1165
+ */
1166
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1167
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
1168
+ // Connectivity test was never executed, or cache was cleared.
1169
+ return true;
1170
+ }
1171
+
1172
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1173
+ if ( WP_FS__IS_HTTP_REQUEST ) {
1174
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1175
+ // Domain changed.
1176
+ return true;
1177
+ }
1178
+
1179
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1180
+ // Server IP changed.
1181
+ return true;
1182
+ }
1183
+ }
1184
+ }
1185
+
1186
+ if ( $this->_storage->connectivity_test['is_connected'] &&
1187
+ $this->_storage->connectivity_test['is_active']
1188
+ ) {
1189
+ // API connected and Freemius is active - no need to run connectivity check.
1190
+ return false;
1191
+ }
1192
+
1193
+ if ( $flush_if_no_connectivity ) {
1194
+ /**
1195
+ * If explicitly asked to flush when no connectivity - do it only
1196
+ * if at least 10 sec passed from the last API connectivity test.
1197
+ */
1198
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
1199
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
1200
+ }
1201
+
1202
+ /**
1203
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
1204
+ */
1205
+ $version = $this->get_plugin_version();
1206
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
1207
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
1208
+ return true;
1209
+ }
1210
+
1211
+ return false;
1212
+ }
1213
+
1214
+ /**
1215
+ * @author Vova Feldman (@svovaf)
1216
+ * @since 1.1.7.4
1217
+ *
1218
+ * @return object|false
1219
+ */
1220
+ private function ping() {
1221
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
1222
+ return false;
1223
+ }
1224
+
1225
+ $version = $this->get_plugin_version();
1226
+
1227
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
1228
+
1229
+ return $this->get_api_plugin_scope()->ping(
1230
+ $this->get_anonymous_id(),
1231
+ array(
1232
+ 'is_update' => json_encode( $is_update ),
1233
+ 'version' => $version,
1234
+ 'sdk' => $this->version,
1235
+ 'is_admin' => json_encode( is_admin() ),
1236
+ 'is_ajax' => json_encode( $this->is_ajax() ),
1237
+ 'is_cron' => json_encode( $this->is_cron() ),
1238
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
1239
+ )
1240
+ );
1241
+ }
1242
+
1243
+ /**
1244
+ * Check if there's any connectivity issue to Freemius API.
1245
+ *
1246
+ * @author Vova Feldman (@svovaf)
1247
+ * @since 1.0.9
1248
+ *
1249
+ * @param bool $flush_if_no_connectivity
1250
+ *
1251
+ * @return bool
1252
+ */
1253
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
1254
+ $this->_logger->entrance();
1255
+
1256
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
1257
+ return $this->_has_api_connection;
1258
+ }
1259
+
1260
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
1261
+ isset( $this->_storage->connectivity_test ) &&
1262
+ true === $this->_storage->connectivity_test['is_connected']
1263
+ ) {
1264
+ unset( $this->_storage->connectivity_test );
1265
+ }
1266
+
1267
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
1268
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
1269
+ /**
1270
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
1271
+ */
1272
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
1273
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1274
+
1275
+ return $this->_has_api_connection;
1276
+ }
1277
+
1278
+ $pong = $this->ping();
1279
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1280
+
1281
+ if ( ! $is_connected ) {
1282
+ // API failure.
1283
+ $this->_add_connectivity_issue_message( $pong );
1284
+ }
1285
+
1286
+ $this->store_connectivity_info( $pong, $is_connected );
1287
+
1288
+ return $this->_has_api_connection;
1289
+ }
1290
+
1291
+ /**
1292
+ * @author Vova Feldman (@svovaf)
1293
+ * @since 1.1.7.4
1294
+ *
1295
+ * @param object $pong
1296
+ * @param bool $is_connected
1297
+ */
1298
+ private function store_connectivity_info( $pong, $is_connected ) {
1299
+ $this->_logger->entrance();
1300
+
1301
+ $version = $this->get_plugin_version();
1302
+
1303
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
1304
+ $is_active = false;
1305
+ } else {
1306
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
1307
+ }
1308
+
1309
+ $is_active = $this->apply_filters(
1310
+ 'is_on',
1311
+ $is_active,
1312
+ $this->is_plugin_update(),
1313
+ $version
1314
+ );
1315
+
1316
+ $this->_storage->connectivity_test = array(
1317
+ 'is_connected' => $is_connected,
1318
+ 'host' => $_SERVER['HTTP_HOST'],
1319
+ 'server_ip' => WP_FS__REMOTE_ADDR,
1320
+ 'is_active' => $is_active,
1321
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
1322
+ // Last version with connectivity attempt.
1323
+ 'version' => $version,
1324
+ );
1325
+
1326
+ $this->_has_api_connection = $is_connected;
1327
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1328
+ }
1329
+
1330
+ /**
1331
+ * Force turning Freemius on.
1332
+ *
1333
+ * @author Vova Feldman (@svovaf)
1334
+ * @since 1.1.8.1
1335
+ *
1336
+ * @return bool TRUE if successfully turned on.
1337
+ */
1338
+ private function turn_on() {
1339
+ $this->_logger->entrance();
1340
+
1341
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
1342
+ return false;
1343
+ }
1344
+
1345
+ $updated_connectivity = $this->_storage->connectivity_test;
1346
+ $updated_connectivity['is_active'] = true;
1347
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
1348
+ $this->_storage->connectivity_test = $updated_connectivity;
1349
+
1350
+ $this->_is_on = true;
1351
+
1352
+ return true;
1353
+ }
1354
+
1355
+ /**
1356
+ * Anonymous and unique site identifier (Hash).
1357
+ *
1358
+ * @author Vova Feldman (@svovaf)
1359
+ * @since 1.1.0
1360
+ *
1361
+ * @return string
1362
+ */
1363
+ function get_anonymous_id() {
1364
+ $unique_id = self::$_accounts->get_option( 'unique_id' );
1365
+
1366
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
1367
+ $key = get_site_url();
1368
+
1369
+ // If localhost, assign microtime instead of domain.
1370
+ if ( WP_FS__IS_LOCALHOST ||
1371
+ false !== strpos( $key, 'localhost' ) ||
1372
+ false === strpos( $key, '.' )
1373
+ ) {
1374
+ $key = microtime();
1375
+ }
1376
+
1377
+ $unique_id = md5( $key );
1378
+
1379
+ self::$_accounts->set_option( 'unique_id', $unique_id, true );
1380
+ }
1381
+
1382
+ $this->_logger->departure( $unique_id );
1383
+
1384
+ return $unique_id;
1385
+ }
1386
+
1387
+ /**
1388
+ * @author Vova Feldman (@svovaf)
1389
+ * @since 1.1.7.4
1390
+ *
1391
+ * @return \WP_User
1392
+ */
1393
+ static function _get_current_wp_user() {
1394
+ self::require_pluggable_essentials();
1395
+
1396
+ return wp_get_current_user();
1397
+ }
1398
+
1399
+ /**
1400
+ * Generate API connectivity issue message.
1401
+ *
1402
+ * @author Vova Feldman (@svovaf)
1403
+ * @since 1.0.9
1404
+ *
1405
+ * @param mixed $api_result
1406
+ * @param bool $is_first_failure
1407
+ */
1408
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
1409
+ if ( $this->_enable_anonymous ) {
1410
+ // Don't add message if can run anonymously.
1411
+ return;
1412
+ }
1413
+
1414
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
1415
+ require_once( ABSPATH . 'wp-includes/functions.php' );
1416
+ }
1417
+
1418
+ $current_user = self::_get_current_wp_user();
1419
+ // $admin_email = get_option( 'admin_email' );
1420
+ $admin_email = $current_user->user_email;
1421
+
1422
+ $message = false;
1423
+ if ( is_object( $api_result ) &&
1424
+ isset( $api_result->error ) &&
1425
+ isset( $api_result->error->code )
1426
+ ) {
1427
+ switch ( $api_result->error->code ) {
1428
+ case 'curl_missing':
1429
+ $message = sprintf(
1430
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1431
+ __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1432
+ ' %s',
1433
+ '<b>' . $this->get_plugin_name() . '</b>',
1434
+ sprintf(
1435
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1436
+ sprintf(
1437
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1438
+ __fs( 'curl-missing-no-clue-title', $this->_slug ),
1439
+ ' - ' . sprintf(
1440
+ __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1441
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1442
+ )
1443
+ ),
1444
+ sprintf(
1445
+ '<b>%s</b> - %s',
1446
+ __fs( 'sysadmin-title', $this->_slug ),
1447
+ __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1448
+ ),
1449
+ sprintf(
1450
+ '<a href="%s"><b>%s</b></a>%s',
1451
+ 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 ),
1452
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1453
+ ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1454
+ )
1455
+ )
1456
+ );
1457
+ break;
1458
+ case 'cloudflare_ddos_protection':
1459
+ $message = sprintf(
1460
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1461
+ __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1462
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1463
+ ' %s',
1464
+ '<b>' . $this->get_plugin_name() . '</b>',
1465
+ sprintf(
1466
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1467
+ sprintf(
1468
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1469
+ __fs( 'fix-issue-title', $this->_slug ),
1470
+ ' - ' . sprintf(
1471
+ __fs( 'fix-issue-desc', $this->_slug ),
1472
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1473
+ )
1474
+ ),
1475
+ sprintf(
1476
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1477
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1478
+ __fs( 'install-previous-title', $this->_slug ),
1479
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1480
+ ),
1481
+ sprintf(
1482
+ '<a href="%s"><b>%s</b></a>%s',
1483
+ 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 ),
1484
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1485
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1486
+ )
1487
+ )
1488
+ );
1489
+ break;
1490
+ case 'squid_cache_block':
1491
+ $message = sprintf(
1492
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1493
+ __fs( 'squid-blocks-connection-message', $this->_slug ) .
1494
+ ' %s',
1495
+ '<b>' . $this->get_plugin_name() . '</b>',
1496
+ sprintf(
1497
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1498
+ sprintf(
1499
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1500
+ __fs( 'squid-no-clue-title', $this->_slug ),
1501
+ ' - ' . sprintf(
1502
+ __fs( 'squid-no-clue-desc', $this->_slug ),
1503
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1504
+ )
1505
+ ),
1506
+ sprintf(
1507
+ '<b>%s</b> - %s',
1508
+ __fs( 'sysadmin-title', $this->_slug ),
1509
+ sprintf(
1510
+ __fs( 'squid-sysadmin-desc', $this->_slug ),
1511
+ // We use a filter since the plugin might require additional API connectivity.
1512
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1513
+ ),
1514
+ sprintf(
1515
+ '<a href="%s"><b>%s</b></a>%s',
1516
+ 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 ),
1517
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1518
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1519
+ )
1520
+ )
1521
+ );
1522
+ break;
1523
+ // default:
1524
+ // $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1525
+ // break;
1526
+ }
1527
+ }
1528
+
1529
+ $message_id = 'failed_connect_api';
1530
+ $type = 'error';
1531
+
1532
+ if ( false === $message ) {
1533
+ if ( $is_first_failure ) {
1534
+ // First attempt failed.
1535
+ $message = sprintf(
1536
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1537
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1538
+ __fs( 'connectivity-test-maybe-temporary', $this->_slug ) . '<br><br>' .
1539
+ '%s',
1540
+ '<b>' . $this->get_plugin_name() . '</b>',
1541
+ sprintf(
1542
+ '<div id="fs_firewall_issue_options">%s %s</div>',
1543
+ sprintf(
1544
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
1545
+ __fs( 'yes-do-your-thing', $this->_slug )
1546
+ ),
1547
+ sprintf(
1548
+ '<a href="%s" class="button">%s</a>',
1549
+ 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 ),
1550
+ __fs( 'no-deactivate', $this->_slug )
1551
+ )
1552
+ )
1553
+ );
1554
+
1555
+ $message_id = 'failed_connect_api_first';
1556
+ $type = 'promotion';
1557
+ } else {
1558
+ // Second connectivity attempt failed.
1559
+ $message = sprintf(
1560
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1561
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1562
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1563
+ ' %s',
1564
+ '<b>' . $this->get_plugin_name() . '</b>',
1565
+ sprintf(
1566
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1567
+ sprintf(
1568
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1569
+ __fs( 'fix-issue-title', $this->_slug ),
1570
+ ' - ' . sprintf(
1571
+ __fs( 'fix-issue-desc', $this->_slug ),
1572
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1573
+ )
1574
+ ),
1575
+ sprintf(
1576
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1577
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1578
+ __fs( 'install-previous-title', $this->_slug ),
1579
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1580
+ ),
1581
+ sprintf(
1582
+ '<a href="%s"><b>%s</b></a>%s',
1583
+ 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 ),
1584
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1585
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1586
+ )
1587
+ )
1588
+ );
1589
+ }
1590
+ }
1591
+
1592
+ $this->_admin_notices->add_sticky(
1593
+ $message,
1594
+ $message_id,
1595
+ __fs( 'oops', $this->_slug ) . '...',
1596
+ $type
1597
+ );
1598
+ }
1599
+
1600
+ /**
1601
+ * Handle user request to resolve connectivity issue.
1602
+ * This method will send an email to Freemius API technical staff for resolution.
1603
+ * The email will contain server's info and installed plugins (might be caching issue).
1604
+ *
1605
+ * @author Vova Feldman (@svovaf)
1606
+ * @since 1.0.9
1607
+ */
1608
+ function _email_about_firewall_issue() {
1609
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1610
+
1611
+ $pong = $this->ping();
1612
+
1613
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1614
+
1615
+ if ( $is_connected ) {
1616
+ $this->store_connectivity_info( $pong, $is_connected );
1617
+
1618
+ echo $this->get_after_plugin_activation_redirect_url();
1619
+ exit;
1620
+ }
1621
+
1622
+ $current_user = self::_get_current_wp_user();
1623
+ $admin_email = $current_user->user_email;
1624
+
1625
+ $error_type = fs_request_get( 'error_type', 'general' );
1626
+
1627
+ switch ( $error_type ) {
1628
+ case 'squid':
1629
+ $title = 'Squid ACL Blocking Issue';
1630
+ break;
1631
+ case 'cloudflare':
1632
+ $title = 'CloudFlare Blocking Issue';
1633
+ break;
1634
+ default:
1635
+ $title = 'API Connectivity Issue';
1636
+ break;
1637
+ }
1638
+
1639
+ $custom_email_sections = array();
1640
+
1641
+ if ( 'squid' === $error_type ) {
1642
+ // Override the 'Site' email section.
1643
+ $custom_email_sections['site'] = array(
1644
+ 'rows' => array(
1645
+ 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1646
+ )
1647
+ );
1648
+ }
1649
+
1650
+ // Add 'API Error' custom email section.
1651
+ $custom_email_sections['api_error'] = array(
1652
+ 'title' => 'API Error',
1653
+ 'rows' => array(
1654
+ 'ping' => array( is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong ) )
1655
+ )
1656
+ );
1657
+
1658
+ // Add PHP info for deeper investigation.
1659
+ ob_start();
1660
+ phpinfo();
1661
+ $php_info = ob_get_clean();
1662
+ $custom_email_sections['php_info'] = array(
1663
+ 'title' => 'PHP Info',
1664
+ 'rows' => array(
1665
+ 'info' => array( $php_info )
1666
+ )
1667
+ );
1668
+
1669
+ // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1670
+ $this->send_email(
1671
+ 'api@freemius.com', // recipient
1672
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
1673
+ $custom_email_sections,
1674
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
1675
+ );
1676
+
1677
+ $this->_admin_notices->add_sticky(
1678
+ sprintf(
1679
+ __fs( 'fix-request-sent-message', $this->_slug ),
1680
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1681
+ ),
1682
+ 'server_details_sent'
1683
+ );
1684
+
1685
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
1686
+
1687
+ echo "1";
1688
+ exit;
1689
+ }
1690
+
1691
+ /**
1692
+ * Handle connectivity test retry approved by the user.
1693
+ *
1694
+ * @author Vova Feldman (@svovaf)
1695
+ * @since 1.1.7.4
1696
+ */
1697
+ function _retry_connectivity_test() {
1698
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
1699
+
1700
+ $pong = $this->ping();
1701
+
1702
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1703
+
1704
+ if ( $is_connected ) {
1705
+ $this->store_connectivity_info( $pong, $is_connected );
1706
+
1707
+ echo $this->get_after_plugin_activation_redirect_url();
1708
+ } else {
1709
+ // Add connectivity issue message after 2nd failed attempt.
1710
+ $this->_add_connectivity_issue_message( $pong, false );
1711
+
1712
+ echo "1";
1713
+ }
1714
+
1715
+ exit;
1716
+ }
1717
+
1718
+ static function _add_firewall_issues_javascript() {
1719
+ $params = array();
1720
+ fs_require_once_template( 'firewall-issues-js.php', $params );
1721
+ }
1722
+
1723
+ #endregion Connectivity Issues ------------------------------------------------------------------
1724
+
1725
+ #region Email ------------------------------------------------------------------
1726
+
1727
+ /**
1728
+ * Generates and sends an HTML email with customizable sections.
1729
+ *
1730
+ * @author Leo Fajardo (@leorw)
1731
+ * @since 1.1.2
1732
+ *
1733
+ * @param string $to_address
1734
+ * @param string $subject
1735
+ * @param array $sections
1736
+ * @param array $headers
1737
+ *
1738
+ * @return bool Whether the email contents were sent successfully.
1739
+ */
1740
+ private function send_email(
1741
+ $to_address,
1742
+ $subject,
1743
+ $sections = array(),
1744
+ $headers = array()
1745
+ ) {
1746
+ $default_sections = $this->get_email_sections();
1747
+
1748
+ // Insert new sections or replace the default email sections.
1749
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
1750
+ foreach ( $sections as $section_id => $custom_section ) {
1751
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
1752
+ // If the section does not exist, add it.
1753
+ $default_sections[ $section_id ] = $custom_section;
1754
+ } else {
1755
+ // If the section already exists, override it.
1756
+ $current_section = $default_sections[ $section_id ];
1757
+
1758
+ // Replace the current section's title if a custom section title exists.
1759
+ if ( isset( $custom_section['title'] ) ) {
1760
+ $current_section['title'] = $custom_section['title'];
1761
+ }
1762
+
1763
+ // Insert new rows under the current section or replace the default rows.
1764
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1765
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
1766
+ $current_section['rows'][ $row_id ] = $row;
1767
+ }
1768
+ }
1769
+
1770
+ $default_sections[ $section_id ] = $current_section;
1771
+ }
1772
+ }
1773
+ }
1774
+
1775
+ $vars = array( 'sections' => $default_sections );
1776
+ $message = fs_get_template( 'email.php', $vars );
1777
+
1778
+ // Set the type of email to HTML.
1779
+ $headers[] = 'Content-type: text/html';
1780
+
1781
+ $header_string = implode( "\r\n", $headers );
1782
+
1783
+ return wp_mail(
1784
+ $to_address,
1785
+ $subject,
1786
+ $message,
1787
+ $header_string
1788
+ );
1789
+ }
1790
+
1791
+ /**
1792
+ * Generates the data for the sections of the email content.
1793
+ *
1794
+ * @author Leo Fajardo (@leorw)
1795
+ * @since 1.1.2
1796
+ *
1797
+ * @return array
1798
+ */
1799
+ private function get_email_sections() {
1800
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
1801
+ $current_user = self::_get_current_wp_user();
1802
+
1803
+ // Retrieve the cURL version information so that we can get the version number below.
1804
+ $curl_version_information = curl_version();
1805
+
1806
+ $active_plugin = self::get_active_plugins();
1807
+
1808
+ // Generate the list of active plugins separated by new line.
1809
+ $active_plugin_string = '';
1810
+ foreach ( $active_plugin as $plugin ) {
1811
+ $active_plugin_string .= sprintf(
1812
+ '<a href="%s">%s</a> [v%s]<br>',
1813
+ $plugin['PluginURI'],
1814
+ $plugin['Name'],
1815
+ $plugin['Version']
1816
+ );
1817
+ }
1818
+
1819
+ $server_ip = WP_FS__REMOTE_ADDR;
1820
+
1821
+ // Generate the default email sections.
1822
+ $sections = array(
1823
+ 'sdk' => array(
1824
+ 'title' => 'SDK',
1825
+ 'rows' => array(
1826
+ 'fs_version' => array( 'FS Version', $this->version ),
1827
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
1828
+ )
1829
+ ),
1830
+ 'plugin' => array(
1831
+ 'title' => 'Plugin',
1832
+ 'rows' => array(
1833
+ 'name' => array( 'Name', $this->get_plugin_name() ),
1834
+ 'version' => array( 'Version', $this->get_plugin_version() )
1835
+ )
1836
+ ),
1837
+ 'site' => array(
1838
+ 'title' => 'Site',
1839
+ 'rows' => array(
1840
+ 'unique_id' => array( 'Address', $this->get_anonymous_id() ),
1841
+ 'address' => array( 'Address', site_url() ),
1842
+ 'host' => array(
1843
+ 'HTTP_HOST',
1844
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
1845
+ ),
1846
+ 'server_addr' => array(
1847
+ 'SERVER_ADDR',
1848
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
1849
+ )
1850
+ )
1851
+ ),
1852
+ 'user' => array(
1853
+ 'title' => 'User',
1854
+ 'rows' => array(
1855
+ 'email' => array( 'Email', $current_user->user_email ),
1856
+ 'first' => array( 'First', $current_user->user_firstname ),
1857
+ 'last' => array( 'Last', $current_user->user_lastname )
1858
+ )
1859
+ ),
1860
+ 'plugins' => array(
1861
+ 'title' => 'Plugins',
1862
+ 'rows' => array(
1863
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
1864
+ )
1865
+ ),
1866
+ );
1867
+
1868
+ // Allow the sections to be modified by other code.
1869
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
1870
+
1871
+ return $sections;
1872
+ }
1873
+
1874
+ #endregion Email ------------------------------------------------------------------
1875
+
1876
+ #region Initialization ------------------------------------------------------------------
1877
+
1878
+ /**
1879
+ * Init plugin's Freemius instance.
1880
+ *
1881
+ * @author Vova Feldman (@svovaf)
1882
+ * @since 1.0.1
1883
+ *
1884
+ * @param number $id
1885
+ * @param string $public_key
1886
+ * @param bool $is_live
1887
+ * @param bool $is_premium
1888
+ */
1889
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
1890
+ $this->_logger->entrance();
1891
+
1892
+ $this->dynamic_init( array(
1893
+ 'id' => $id,
1894
+ 'public_key' => $public_key,
1895
+ 'is_live' => $is_live,
1896
+ 'is_premium' => $is_premium,
1897
+ ) );
1898
+ }
1899
+
1900
+ /**
1901
+ * Dynamic initiator, originally created to support initiation
1902
+ * with parent_id for add-ons.
1903
+ *
1904
+ * @author Vova Feldman (@svovaf)
1905
+ * @since 1.0.6
1906
+ *
1907
+ * @param array $plugin_info
1908
+ *
1909
+ * @throws Freemius_Exception
1910
+ */
1911
+ function dynamic_init( array $plugin_info ) {
1912
+ $this->_logger->entrance();
1913
+
1914
+ $this->parse_settings( $plugin_info );
1915
+
1916
+ if ( $this->should_stop_execution() ) {
1917
+ return;
1918
+ }
1919
+
1920
+ if ( ! $this->is_registered() ) {
1921
+ if ( $this->is_anonymous() ) {
1922
+ // If user skipped, no need to test connectivity.
1923
+ $this->_has_api_connection = true;
1924
+ $this->_is_on = true;
1925
+ } else {
1926
+ if ( ! $this->has_api_connectivity() ) {
1927
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
1928
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
1929
+ ) {
1930
+ if ( ! $this->_enable_anonymous ) {
1931
+ // If anonymous mode is disabled, add firewall admin-notice message.
1932
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
1933
+
1934
+ add_action( "wp_ajax_{$this->_slug}_resolve_firewall_issues", array(
1935
+ &$this,
1936
+ '_email_about_firewall_issue'
1937
+ ) );
1938
+
1939
+ add_action( "wp_ajax_{$this->_slug}_retry_connectivity_test", array(
1940
+ &$this,
1941
+ '_retry_connectivity_test'
1942
+ ) );
1943
+ }
1944
+ }
1945
+
1946
+ return;
1947
+ } else {
1948
+ $this->_admin_notices->remove_sticky( array(
1949
+ 'failed_connect_api_first',
1950
+ 'failed_connect_api',
1951
+ ) );
1952
+
1953
+ if ( $this->_anonymous_mode ) {
1954
+ // Simulate anonymous mode.
1955
+ $this->_is_anonymous = true;
1956
+ }
1957
+ }
1958
+ }
1959
+
1960
+ // Check if Freemius is on for the current plugin.
1961
+ // This MUST be executed after all the plugin variables has been loaded.
1962
+ if ( ! $this->is_on() ) {
1963
+ return;
1964
+ }
1965
+ }
1966
+
1967
+ if ( $this->has_api_connectivity() && $this->is_user_in_admin() ) {
1968
+ /**
1969
+ * Schedule daily data sync cron if:
1970
+ *
1971
+ * 1. User opted-in (for tracking).
1972
+ * 2. If plugin has add-ons (update add-ons data).
1973
+ * 3. If skipped, but later upgraded (opted-in via upgrade).
1974
+ *
1975
+ * @author Vova Feldman (@svovaf)
1976
+ * @since 1.1.7.3
1977
+ *
1978
+ */
1979
+ if ( $this->is_registered() ||
1980
+ ( ! $this->is_activation_mode() && $this->_has_addons )
1981
+ ) {
1982
+
1983
+ $this->hook_callback_to_sync_cron();
1984
+
1985
+ if ( ! $this->is_sync_cron_on() ) {
1986
+ $this->schedule_sync_cron();
1987
+ }
1988
+ }
1989
+
1990
+ /**
1991
+ * Check if requested for manual blocking background sync.
1992
+ */
1993
+ if ( fs_request_has( 'background_sync' ) ) {
1994
+ $this->run_manual_sync();
1995
+ }
1996
+ }
1997
+
1998
+ if ( $this->is_registered() ) {
1999
+ $this->hook_callback_to_install_sync();
2000
+ }
2001
+
2002
+ if ( $this->is_addon() ) {
2003
+ if ( $this->is_parent_plugin_installed() ) {
2004
+ // Link to parent FS.
2005
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2006
+
2007
+ // Get parent plugin reference.
2008
+ $this->_parent_plugin = $this->_parent->get_plugin();
2009
+ }
2010
+ }
2011
+
2012
+ if ( $this->is_user_in_admin() ) {
2013
+ global $pagenow;
2014
+ if ( 'plugins.php' === $pagenow ) {
2015
+ $this->hook_plugin_action_links();
2016
+ }
2017
+
2018
+ if ( $this->is_addon() ) {
2019
+ if ( ! $this->is_parent_plugin_installed() ) {
2020
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2021
+
2022
+ if ( isset( $plugin_info['parent'] ) ) {
2023
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2024
+ }
2025
+
2026
+ $this->_admin_notices->add(
2027
+ ( ! empty( $parent_name ) ?
2028
+ sprintf( __fs( 'addon-x-cannot-run-without-y', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
2029
+ sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
2030
+ ),
2031
+ __fs( 'oops', $this->_slug ) . '...',
2032
+ 'error'
2033
+ );
2034
+
2035
+ return;
2036
+ } else {
2037
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
2038
+ // If parent plugin activated, automatically install add-on for the user.
2039
+ $this->_activate_addon_account( $this->_parent );
2040
+ }
2041
+
2042
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
2043
+ if ( $this->is_premium() ) {
2044
+ // Remove add-on download admin-notice.
2045
+ $this->_parent->_admin_notices->remove_sticky( array(
2046
+ 'addon_plan_upgraded_' . $this->_slug,
2047
+ 'no_addon_license_' . $this->_slug,
2048
+ ) );
2049
+ }
2050
+
2051
+ $this->deactivate_premium_only_addon_without_license();
2052
+ }
2053
+ } else {
2054
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
2055
+
2056
+ if ( $this->has_addons() &&
2057
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
2058
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
2059
+ ) {
2060
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
2061
+
2062
+ new FS_Plugin_Info_Dialog( $this );
2063
+ }
2064
+ }
2065
+
2066
+ if ( $this->is_premium() ) {
2067
+ new FS_Plugin_Updater( $this );
2068
+ }
2069
+
2070
+ // if ( $this->is_registered() ||
2071
+ // $this->is_anonymous() ||
2072
+ // $this->is_pending_activation()
2073
+ // ) {
2074
+ // $this->_init_admin();
2075
+ // }
2076
+ }
2077
+
2078
+ $this->do_action( 'initiated' );
2079
+
2080
+ if ( ! $this->is_addon() ) {
2081
+ if ( $this->is_registered() ) {
2082
+ // Fix for upgrade from versions < 1.0.9.
2083
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
2084
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
2085
+ }
2086
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
2087
+ if ( isset( $this->_storage->prev_is_premium ) ) {
2088
+ add_action( is_admin() ? 'admin_init' : 'init', array(
2089
+ &$this,
2090
+ '_plugin_code_type_changed'
2091
+ ) );
2092
+ } else {
2093
+ // Set for code type for the first time.
2094
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2095
+ }
2096
+ }
2097
+
2098
+ $this->do_action( 'after_init_plugin_registered' );
2099
+ } else if ( $this->is_anonymous() ) {
2100
+ $this->do_action( 'after_init_plugin_anonymous' );
2101
+ } else if ( $this->is_pending_activation() ) {
2102
+ $this->do_action( 'after_init_plugin_pending_activations' );
2103
+ }
2104
+ } else {
2105
+ if ( $this->is_registered() ) {
2106
+ $this->do_action( 'after_init_addon_registered' );
2107
+ } else if ( $this->is_anonymous() ) {
2108
+ $this->do_action( 'after_init_addon_anonymous' );
2109
+ } else if ( $this->is_pending_activation() ) {
2110
+ $this->do_action( 'after_init_addon_pending_activations' );
2111
+ }
2112
+ }
2113
+
2114
+ // Add license activation link and AJAX request handler.
2115
+ if ( $this->has_paid_plan() ) {
2116
+ $this->_add_license_action_link();
2117
+
2118
+ global $pagenow;
2119
+ if ( 'plugins.php' === $pagenow ) {
2120
+ add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
2121
+ }
2122
+
2123
+ add_action( 'wp_ajax_activate-license', array( &$this, '_activate_license_ajax_action' ) );
2124
+ }
2125
+ }
2126
+
2127
+ /**
2128
+ * Parse plugin's settings (as defined by the plugin dev).
2129
+ *
2130
+ * @author Vova Feldman (@svovaf)
2131
+ * @since 1.1.7.3
2132
+ *
2133
+ * @param array $plugin_info
2134
+ *
2135
+ * @throws \Freemius_Exception
2136
+ */
2137
+ private function parse_settings( &$plugin_info ) {
2138
+ $this->_logger->entrance();
2139
+
2140
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
2141
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
2142
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
2143
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
2144
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2145
+
2146
+ /**
2147
+ * @author Vova Feldman (@svovaf)
2148
+ * @since 1.1.9 Try to pull secret key from external config.
2149
+ */
2150
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
2151
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
2152
+ }
2153
+
2154
+ if ( isset( $plugin_info['parent'] ) ) {
2155
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
2156
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
2157
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
2158
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2159
+ }
2160
+
2161
+ if ( false === $id ) {
2162
+ throw new Freemius_Exception( 'Plugin id parameter is not set.' );
2163
+ }
2164
+ if ( false === $public_key ) {
2165
+ throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
2166
+ }
2167
+
2168
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
2169
+ $this->_plugin :
2170
+ new FS_Plugin();
2171
+
2172
+ $plugin->update( array(
2173
+ 'id' => $id,
2174
+ 'public_key' => $public_key,
2175
+ 'slug' => $this->_slug,
2176
+ 'parent_plugin_id' => $parent_id,
2177
+ 'version' => $this->get_plugin_version(),
2178
+ 'title' => $this->get_plugin_name(),
2179
+ 'file' => $this->_plugin_basename,
2180
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
2181
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
2182
+ // 'secret_key' => $secret_key,
2183
+ ) );
2184
+
2185
+ if ( $plugin->is_updated() ) {
2186
+ // Update plugin details.
2187
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
2188
+ }
2189
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
2190
+ $this->_plugin->secret_key = $secret_key;
2191
+
2192
+ if ( ! isset( $plugin_info['menu'] ) ) {
2193
+ // Back compatibility to 1.1.2
2194
+ $plugin_info['menu'] = array(
2195
+ 'slug' => isset( $plugin_info['menu_slug'] ) ?
2196
+ $plugin_info['menu_slug'] :
2197
+ $this->_slug
2198
+ );
2199
+ }
2200
+
2201
+ $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
2202
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
2203
+
2204
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
2205
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
2206
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
2207
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
2208
+ if ( $this->_is_premium_only ) {
2209
+ // If premium only plugin, disable anonymous mode.
2210
+ $this->_enable_anonymous = false;
2211
+ $this->_anonymous_mode = false;
2212
+ } else {
2213
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
2214
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
2215
+ }
2216
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
2217
+ }
2218
+
2219
+ /**
2220
+ * @param string[] $options
2221
+ * @param string $key
2222
+ * @param mixed $default
2223
+ *
2224
+ * @return bool
2225
+ */
2226
+ private function get_option( &$options, $key, $default = false ) {
2227
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
2228
+ }
2229
+
2230
+ private function get_bool_option( &$options, $key, $default = false ) {
2231
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
2232
+ }
2233
+
2234
+ private function get_numeric_option( &$options, $key, $default = false ) {
2235
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
2236
+ }
2237
+
2238
+ /**
2239
+ * Gate keeper.
2240
+ *
2241
+ * @author Vova Feldman (@svovaf)
2242
+ * @since 1.1.7.3
2243
+ *
2244
+ * @return bool
2245
+ */
2246
+ private function should_stop_execution() {
2247
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
2248
+ /**
2249
+ * Don't execute Freemius until plugin was fully loaded at least once,
2250
+ * to give the opportunity for the activation hook to run before pinging
2251
+ * the API for connectivity test. This logic is relevant for the
2252
+ * identification of new plugin install vs. plugin update.
2253
+ *
2254
+ * @author Vova Feldman (@svovaf)
2255
+ * @since 1.1.9
2256
+ */
2257
+ return true;
2258
+ }
2259
+
2260
+ if ( $this->is_activation_mode() ) {
2261
+ if ( ! is_admin() ) {
2262
+ /**
2263
+ * If in activation mode, don't execute Freemius outside of the
2264
+ * admin dashboard.
2265
+ *
2266
+ * @author Vova Feldman (@svovaf)
2267
+ * @since 1.1.7.3
2268
+ */
2269
+ return true;
2270
+ }
2271
+
2272
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
2273
+ /**
2274
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
2275
+ * then don't start Freemius.
2276
+ *
2277
+ * @author Vova Feldman (@svovaf)
2278
+ * @since 1.1.6.3
2279
+ *
2280
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
2281
+ */
2282
+ return true;
2283
+ }
2284
+
2285
+ if ( $this->is_cron() ) {
2286
+ /**
2287
+ * If in activation mode, don't execute Freemius during wp crons
2288
+ * (wp crons have HTTP context - called as HTTP request).
2289
+ *
2290
+ * @author Vova Feldman (@svovaf)
2291
+ * @since 1.1.7.3
2292
+ */
2293
+ return true;
2294
+ }
2295
+
2296
+ if ( $this->is_ajax() &&
2297
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
2298
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
2299
+ ) {
2300
+ /**
2301
+ * During activation, if running in AJAX mode, unless there's a sticky
2302
+ * connectivity issue notice, don't run Freemius.
2303
+ *
2304
+ * @author Vova Feldman (@svovaf)
2305
+ * @since 1.1.7.3
2306
+ */
2307
+ return true;
2308
+ }
2309
+ }
2310
+
2311
+ return false;
2312
+ }
2313
+
2314
+ /**
2315
+ * Handles plugin's code type change (free <--> premium).
2316
+ *
2317
+ * @author Vova Feldman (@svovaf)
2318
+ * @since 1.0.9
2319
+ */
2320
+ function _plugin_code_type_changed() {
2321
+ // Schedule code type changes event.
2322
+ // $this->sync_install();
2323
+ $this->schedule_install_sync();
2324
+
2325
+ if ( $this->is_premium() ) {
2326
+ // Activated premium code.
2327
+ $this->do_action( 'after_premium_version_activation' );
2328
+
2329
+ // Remove all sticky messages related to download of the premium version.
2330
+ $this->_admin_notices->remove_sticky( array(
2331
+ 'trial_started',
2332
+ 'plan_upgraded',
2333
+ 'plan_changed',
2334
+ ) );
2335
+
2336
+ $this->_admin_notices->add_sticky(
2337
+ __fs( 'premium-activated-message', $this->_slug ),
2338
+ 'premium_activated',
2339
+ __fs( 'woot', $this->_slug ) . '!'
2340
+ );
2341
+ } else {
2342
+ // Activated free code (after had the premium before).
2343
+ $this->do_action( 'after_free_version_reactivation' );
2344
+
2345
+ if ( $this->is_paying() && ! $this->is_premium() ) {
2346
+ $this->_admin_notices->add_sticky(
2347
+ sprintf(
2348
+ __fs( 'you-have-x-license', $this->_slug ),
2349
+ $this->_site->plan->title
2350
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
2351
+ __fs( 'download-x-version-now', $this->_slug ),
2352
+ $this->_site->plan->title
2353
+ ) ),
2354
+ 'plan_upgraded',
2355
+ __fs( 'yee-haw', $this->_slug ) . '!'
2356
+ );
2357
+ }
2358
+ }
2359
+
2360
+ // Update is_premium of latest version.
2361
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2362
+ }
2363
+
2364
+ #endregion Initialization ------------------------------------------------------------------
2365
+
2366
+ #region Add-ons -------------------------------------------------------------------------
2367
+
2368
+ /**
2369
+ * Check if add-on installed and activated on site.
2370
+ *
2371
+ * @author Vova Feldman (@svovaf)
2372
+ * @since 1.0.6
2373
+ *
2374
+ * @param string|number $slug_or_id
2375
+ *
2376
+ * @return bool
2377
+ */
2378
+ function is_addon_activated( $slug_or_id ) {
2379
+ return self::has_instance( $slug_or_id );
2380
+ }
2381
+
2382
+ /**
2383
+ * Check if add-on was connected to install
2384
+ *
2385
+ * @author Vova Feldman (@svovaf)
2386
+ * @since 1.1.7
2387
+ *
2388
+ * @param string $slug
2389
+ *
2390
+ * @return bool
2391
+ */
2392
+ function is_addon_connected( $slug ) {
2393
+ $sites = self::get_all_sites();
2394
+
2395
+ if ( ! isset( $sites[ $slug ] ) ) {
2396
+ return false;
2397
+ }
2398
+
2399
+ $site = $sites[ $slug ];
2400
+
2401
+ $plugin = FS_Plugin_Manager::instance( $slug )->get();
2402
+
2403
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
2404
+ // The given slug do NOT belong to any of the plugin's add-ons.
2405
+ return false;
2406
+ }
2407
+
2408
+ return ( is_object( $site ) &&
2409
+ is_numeric( $site->id ) &&
2410
+ is_numeric( $site->user_id ) &&
2411
+ is_object( $site->plan )
2412
+ );
2413
+ }
2414
+
2415
+ /**
2416
+ * Determines if add-on installed.
2417
+ *
2418
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
2419
+ *
2420
+ * @author Vova Feldman (@svovaf)
2421
+ * @since 1.0.6
2422
+ *
2423
+ * @param string $slug
2424
+ *
2425
+ * @return bool
2426
+ */
2427
+ function is_addon_installed( $slug ) {
2428
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
2429
+ }
2430
+
2431
+ /**
2432
+ * Get add-on basename.
2433
+ *
2434
+ * @author Vova Feldman (@svovaf)
2435
+ * @since 1.0.6
2436
+ *
2437
+ * @param string $slug
2438
+ *
2439
+ * @return string
2440
+ */
2441
+ function get_addon_basename( $slug ) {
2442
+ if ( $this->is_addon_activated( $slug ) ) {
2443
+ self::instance( $slug )->get_plugin_basename();
2444
+ }
2445
+
2446
+ $premium_basename = $slug . '-premium/' . $slug . '.php';
2447
+
2448
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
2449
+ return $premium_basename;
2450
+ }
2451
+
2452
+ $free_basename = $slug . '/' . $slug . '.php';
2453
+
2454
+ return $free_basename;
2455
+ }
2456
+
2457
+ /**
2458
+ * Get installed add-ons instances.
2459
+ *
2460
+ * @author Vova Feldman (@svovaf)
2461
+ * @since 1.0.6
2462
+ *
2463
+ * @return Freemius[]
2464
+ */
2465
+ function get_installed_addons() {
2466
+ $installed_addons = array();
2467
+ foreach ( self::$_instances as $slug => $instance ) {
2468
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2469
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2470
+ $installed_addons[] = $instance;
2471
+ }
2472
+ }
2473
+ }
2474
+
2475
+ return $installed_addons;
2476
+ }
2477
+
2478
+ /**
2479
+ * Check if any add-ons of the plugin are installed.
2480
+ *
2481
+ * @author Leo Fajardo (@leorw)
2482
+ * @since 1.1.1
2483
+ *
2484
+ * @return bool
2485
+ */
2486
+ function has_installed_addons() {
2487
+ if ( ! $this->has_addons() ) {
2488
+ return false;
2489
+ }
2490
+
2491
+ foreach ( self::$_instances as $slug => $instance ) {
2492
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2493
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2494
+ return true;
2495
+ }
2496
+ }
2497
+ }
2498
+
2499
+ return false;
2500
+ }
2501
+
2502
+ /**
2503
+ * Tell Freemius that the current plugin is an add-on.
2504
+ *
2505
+ * @author Vova Feldman (@svovaf)
2506
+ * @since 1.0.6
2507
+ *
2508
+ * @param number $parent_plugin_id The parent plugin ID
2509
+ */
2510
+ function init_addon( $parent_plugin_id ) {
2511
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
2512
+ }
2513
+
2514
+ /**
2515
+ * @author Vova Feldman (@svovaf)
2516
+ * @since 1.0.6
2517
+ *
2518
+ * @return bool
2519
+ */
2520
+ function is_addon() {
2521
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2522
+ }
2523
+
2524
+ /**
2525
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
2526
+ *
2527
+ * @param bool $is_after_trial_cancel
2528
+ *
2529
+ * @return bool If add-on was deactivated.
2530
+ */
2531
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
2532
+ if ( ! $this->has_free_plan() &&
2533
+ ! $this->has_features_enabled_license() &&
2534
+ ! $this->_has_premium_license()
2535
+ ) {
2536
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
2537
+ // if (empty($this->_storage->activation_timestamp) ||
2538
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
2539
+ // ) {
2540
+ /**
2541
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
2542
+ *
2543
+ * Retry syncing the user add-on licenses.
2544
+ */
2545
+ // Sync licenses.
2546
+ $this->_sync_licenses();
2547
+ // }
2548
+
2549
+ // Try to activate premium license.
2550
+ $this->_activate_license( true );
2551
+
2552
+ if ( ! $this->has_free_plan() &&
2553
+ ! $this->has_features_enabled_license() &&
2554
+ ! $this->_has_premium_license()
2555
+ ) {
2556
+ // @todo Check if deactivate plugins also call the deactivation hook.
2557
+
2558
+ deactivate_plugins( array( $this->_plugin_basename ), true );
2559
+
2560
+ $this->_parent->_admin_notices->add_sticky(
2561
+ sprintf(
2562
+ __fs( ( $is_after_trial_cancel ?
2563
+ 'addon-trial-cancelled-message' :
2564
+ 'addon-no-license-message' ),
2565
+ $this->_parent->_slug
2566
+ ),
2567
+ '<b>' . $this->_plugin->title . '</b>'
2568
+ ) . ' ' . sprintf(
2569
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
2570
+ $this->_parent->addon_url( $this->_slug ),
2571
+ esc_attr( sprintf( __fs( 'more-information-about-x', $this->_parent->_slug ), $this->_plugin->title ) ),
2572
+ __fs( 'purchase-license', $this->_parent->_slug )
2573
+ ),
2574
+ 'no_addon_license_' . $this->_slug,
2575
+ ( $is_after_trial_cancel ? '' : __fs( 'oops', $this->_parent->_slug ) . '...' ),
2576
+ ( $is_after_trial_cancel ? 'success' : 'error' )
2577
+ );
2578
+
2579
+ return true;
2580
+ }
2581
+ }
2582
+
2583
+ return false;
2584
+ }
2585
+
2586
+ #endregion ------------------------------------------------------------------
2587
+
2588
+ #region Sandbox ------------------------------------------------------------------
2589
+
2590
+ /**
2591
+ * Set Freemius into sandbox mode for debugging.
2592
+ *
2593
+ * @author Vova Feldman (@svovaf)
2594
+ * @since 1.0.4
2595
+ *
2596
+ * @param string $secret_key
2597
+ */
2598
+ function init_sandbox( $secret_key ) {
2599
+ $this->_plugin->secret_key = $secret_key;
2600
+
2601
+ // Update plugin details.
2602
+ FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
2603
+ }
2604
+
2605
+ /**
2606
+ * Check if running payments in sandbox mode.
2607
+ *
2608
+ * @author Vova Feldman (@svovaf)
2609
+ * @since 1.0.4
2610
+ *
2611
+ * @return bool
2612
+ */
2613
+ function is_payments_sandbox() {
2614
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
2615
+ }
2616
+
2617
+ #endregion Sandbox ------------------------------------------------------------------
2618
+
2619
+ /**
2620
+ * Check if running test vs. live plugin.
2621
+ *
2622
+ * @author Vova Feldman (@svovaf)
2623
+ * @since 1.0.5
2624
+ *
2625
+ * @return bool
2626
+ */
2627
+ function is_live() {
2628
+ return $this->_plugin->is_live;
2629
+ }
2630
+
2631
+ /**
2632
+ * Check if the user skipped connecting the account with Freemius.
2633
+ *
2634
+ * @author Vova Feldman (@svovaf)
2635
+ * @since 1.0.7
2636
+ *
2637
+ * @return bool
2638
+ */
2639
+ function is_anonymous() {
2640
+ if ( ! isset( $this->_is_anonymous ) ) {
2641
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
2642
+ // Not skipped.
2643
+ $this->_is_anonymous = false;
2644
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
2645
+ // For back compatibility, since the variable was boolean before.
2646
+ $this->_is_anonymous = $this->_storage->is_anonymous;
2647
+
2648
+ // Upgrade stored data format to 1.1.3 format.
2649
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
2650
+ } else {
2651
+ // Version 1.1.3 and later.
2652
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
2653
+ }
2654
+ }
2655
+
2656
+ return $this->_is_anonymous;
2657
+ }
2658
+
2659
+ /**
2660
+ * Check if user connected his account and install pending email activation.
2661
+ *
2662
+ * @author Vova Feldman (@svovaf)
2663
+ * @since 1.0.7
2664
+ *
2665
+ * @return bool
2666
+ */
2667
+ function is_pending_activation() {
2668
+ return $this->_storage->get( 'is_pending_activation', false );
2669
+ }
2670
+
2671
+ /**
2672
+ * Check if plugin must be WordPress.org compliant.
2673
+ *
2674
+ * @since 1.0.7
2675
+ *
2676
+ * @return bool
2677
+ */
2678
+ function is_org_repo_compliant() {
2679
+ return $this->_is_org_compliant;
2680
+ }
2681
+
2682
+ #region Daily Sync Cron ------------------------------------------------------------------
2683
+
2684
+ /**
2685
+ * @author Vova Feldman (@svovaf)
2686
+ * @since 1.1.7.3
2687
+ */
2688
+ private function run_manual_sync() {
2689
+ $this->require_pluggable_essentials();
2690
+
2691
+ if ( ! current_user_can( 'activate_plugins' ) ) {
2692
+ return;
2693
+ }
2694
+
2695
+ // Run manual sync.
2696
+ $this->_sync_cron();
2697
+
2698
+ // Reschedule next cron to run 24 hours from now (performance optimization).
2699
+ $this->clear_sync_cron();
2700
+
2701
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
2702
+ }
2703
+
2704
+ /**
2705
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
2706
+ * that doesn't halt page loading.
2707
+ *
2708
+ * @author Vova Feldman (@svovaf)
2709
+ * @since 1.1.7.3
2710
+ */
2711
+ function _sync_cron() {
2712
+ $this->_logger->entrance();
2713
+
2714
+ // Store the last time data sync was executed.
2715
+ $this->_storage->sync_timestamp = time();
2716
+
2717
+ // Check if API is temporary down.
2718
+ if ( FS_Api::is_temporary_down() ) {
2719
+ return;
2720
+ }
2721
+
2722
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
2723
+
2724
+ if ( $this->is_registered() ) {
2725
+ if ( $this->has_paid_plan() ) {
2726
+ // Initiate background plan sync.
2727
+ $this->_sync_license( true );
2728
+
2729
+ if ( $this->is_paying() ) {
2730
+ // Check for premium plugin updates.
2731
+ $this->_check_updates( true );
2732
+ }
2733
+ } else {
2734
+ // Sync install (only if something changed locally).
2735
+ $this->sync_install();
2736
+ }
2737
+ }
2738
+
2739
+ if ( ! $this->is_addon() && $this->_has_addons ) {
2740
+ // Sync add-ons collection.
2741
+ $this->_sync_addons( true );
2742
+ }
2743
+ }
2744
+
2745
+ /**
2746
+ * Check if sync was executed in the last $period of seconds.
2747
+ *
2748
+ * @author Vova Feldman (@svovaf)
2749
+ * @since 1.1.7.3
2750
+ *
2751
+ * @param int $period In seconds
2752
+ *
2753
+ * @return bool
2754
+ */
2755
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
2756
+ if ( ! isset( $this->_storage->sync_timestamp ) ) {
2757
+ return false;
2758
+ }
2759
+
2760
+ return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
2761
+ }
2762
+
2763
+ /**
2764
+ * @author Vova Feldman (@svovaf)
2765
+ * @since 1.1.7.3
2766
+ *
2767
+ * @return bool
2768
+ */
2769
+ private function is_sync_cron_on() {
2770
+ /**
2771
+ * @var object $sync_cron_data
2772
+ */
2773
+ $sync_cron_data = $this->_storage->get( 'sync_cron', null );
2774
+
2775
+ return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
2776
+ }
2777
+
2778
+ /**
2779
+ * @author Vova Feldman (@svovaf)
2780
+ * @since 1.1.7.3
2781
+ *
2782
+ * @param int $start_at Defaults to now.
2783
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
2784
+ * schedule job to start right away.
2785
+ */
2786
+ private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
2787
+ $this->_logger->entrance();
2788
+
2789
+ if ( $randomize_start ) {
2790
+ // Schedule first sync with a random 12 hour time range from now.
2791
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
2792
+ }
2793
+
2794
+ // Schedule daily WP cron.
2795
+ wp_schedule_event(
2796
+ $start_at,
2797
+ 'daily',
2798
+ $this->get_action_tag( 'data_sync' )
2799
+ );
2800
+
2801
+ $this->_storage->store( 'sync_cron', (object) array(
2802
+ 'version' => $this->get_plugin_version(),
2803
+ 'sdk_version' => $this->version,
2804
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2805
+ 'on' => true,
2806
+ ) );
2807
+ }
2808
+
2809
+ /**
2810
+ * Add the actual sync function to the cron job hook.
2811
+ *
2812
+ * @author Vova Feldman (@svovaf)
2813
+ * @since 1.1.7.3
2814
+ */
2815
+ private function hook_callback_to_sync_cron() {
2816
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
2817
+ }
2818
+
2819
+ /**
2820
+ * @author Vova Feldman (@svovaf)
2821
+ * @since 1.1.7.3
2822
+ */
2823
+ private function clear_sync_cron() {
2824
+ $this->_logger->entrance();
2825
+
2826
+ if ( ! $this->is_sync_cron_on() ) {
2827
+ return;
2828
+ }
2829
+
2830
+ $this->_storage->remove( 'sync_cron' );
2831
+
2832
+ wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
2833
+ }
2834
+
2835
+ /**
2836
+ * Unix timestamp for next sync cron execution or false if not scheduled.
2837
+ *
2838
+ * @author Vova Feldman (@svovaf)
2839
+ * @since 1.1.7.3
2840
+ *
2841
+ * @return int|false
2842
+ */
2843
+ function next_sync_cron() {
2844
+ $this->_logger->entrance();
2845
+
2846
+ if ( ! $this->is_sync_cron_on() ) {
2847
+ return false;
2848
+ }
2849
+
2850
+ return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
2851
+ }
2852
+
2853
+ /**
2854
+ * Unix timestamp for previous sync cron execution or false if never executed.
2855
+ *
2856
+ * @author Vova Feldman (@svovaf)
2857
+ * @since 1.1.7.3
2858
+ *
2859
+ * @return int|false
2860
+ */
2861
+ function last_sync_cron() {
2862
+ $this->_logger->entrance();
2863
+
2864
+ return $this->_storage->get( 'sync_timestamp' );
2865
+ }
2866
+
2867
+ #endregion Daily Sync Cron ------------------------------------------------------------------
2868
+
2869
+ #region Async Install Sync ------------------------------------------------------------------
2870
+
2871
+ /**
2872
+ * @author Vova Feldman (@svovaf)
2873
+ * @since 1.1.7.3
2874
+ *
2875
+ * @return bool
2876
+ */
2877
+ private function is_install_sync_scheduled() {
2878
+ /**
2879
+ * @var object $cron_data
2880
+ */
2881
+ $cron_data = $this->_storage->get( 'install_sync_cron', null );
2882
+
2883
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
2884
+ }
2885
+
2886
+ /**
2887
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
2888
+ *
2889
+ * @author Vova Feldman (@svovaf)
2890
+ * @since 1.1.7.3
2891
+ */
2892
+ private function schedule_install_sync() {
2893
+ $this->_logger->entrance();
2894
+
2895
+ $this->clear_install_sync_cron();
2896
+
2897
+ // Schedule immediate install sync.
2898
+ wp_schedule_single_event(
2899
+ WP_FS__SCRIPT_START_TIME,
2900
+ $this->get_action_tag( 'install_sync' )
2901
+ );
2902
+
2903
+ $this->_storage->store( 'install_sync_cron', (object) array(
2904
+ 'version' => $this->get_plugin_version(),
2905
+ 'sdk_version' => $this->version,
2906
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
2907
+ 'on' => true,
2908
+ ) );
2909
+ }
2910
+
2911
+ /**
2912
+ * Unix timestamp for previous install sync cron execution or false if never executed.
2913
+ *
2914
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
2915
+ * updated. But for sure the sync event is working.
2916
+ *
2917
+ * @author Vova Feldman (@svovaf)
2918
+ * @since 1.1.7.3
2919
+ *
2920
+ * @return int|false
2921
+ */
2922
+ function last_install_sync() {
2923
+ $this->_logger->entrance();
2924
+
2925
+ return $this->_storage->get( 'install_sync_timestamp' );
2926
+ }
2927
+
2928
+ /**
2929
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
2930
+ *
2931
+ * @author Vova Feldman (@svovaf)
2932
+ * @since 1.1.7.3
2933
+ *
2934
+ * @return int|false
2935
+ */
2936
+ function next_install_sync() {
2937
+ $this->_logger->entrance();
2938
+
2939
+ if ( ! $this->is_install_sync_scheduled() ) {
2940
+ return false;
2941
+ }
2942
+
2943
+ return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
2944
+ }
2945
+
2946
+ /**
2947
+ * Add the actual install sync function to the cron job hook.
2948
+ *
2949
+ * @author Vova Feldman (@svovaf)
2950
+ * @since 1.1.7.3
2951
+ */
2952
+ private function hook_callback_to_install_sync() {
2953
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
2954
+ }
2955
+
2956
+ /**
2957
+ * @author Vova Feldman (@svovaf)
2958
+ * @since 1.1.7.3
2959
+ */
2960
+ private function clear_install_sync_cron() {
2961
+ $this->_logger->entrance();
2962
+
2963
+ if ( ! $this->is_install_sync_scheduled() ) {
2964
+ return;
2965
+ }
2966
+
2967
+ $this->_storage->remove( 'install_sync_cron' );
2968
+
2969
+ wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
2970
+ }
2971
+
2972
+ /**
2973
+ * @author Vova Feldman (@svovaf)
2974
+ * @since 1.1.7.3
2975
+ */
2976
+ public function _run_sync_install() {
2977
+ $this->_logger->entrance();
2978
+
2979
+ // Update last install sync timestamp.
2980
+ $this->_storage->install_sync_timestamp = time();
2981
+
2982
+ $this->sync_install( array(), true );
2983
+ }
2984
+
2985
+ #endregion Async Install Sync ------------------------------------------------------------------
2986
+
2987
+ /**
2988
+ * Show a notice that activation is currently pending.
2989
+ *
2990
+ * @author Vova Feldman (@svovaf)
2991
+ * @since 1.0.7
2992
+ *
2993
+ * @param bool|string $email
2994
+ */
2995
+ function _add_pending_activation_notice( $email = false ) {
2996
+ if ( ! is_string( $email ) ) {
2997
+ $current_user = self::_get_current_wp_user();
2998
+ $email = $current_user->user_email;
2999
+ }
3000
+
3001
+ $this->_admin_notices->add_sticky(
3002
+ sprintf(
3003
+ __fs( 'pending-activation-message', $this->_slug ),
3004
+ '<b>' . $this->get_plugin_name() . '</b>',
3005
+ '<b>' . $email . '</b>'
3006
+ ),
3007
+ 'activation_pending',
3008
+ 'Thanks!'
3009
+ );
3010
+ }
3011
+
3012
+ /**
3013
+ * Check if currently in plugin activation.
3014
+ *
3015
+ * @author Vova Feldman (@svovaf)
3016
+ * @since 1.1.4
3017
+ *
3018
+ * @return bool
3019
+ */
3020
+ function is_plugin_activation() {
3021
+ return get_option( "fs_{$this->_slug}_activated", false );
3022
+ }
3023
+
3024
+ /**
3025
+ *
3026
+ * NOTE: admin_menu action executed before admin_init.
3027
+ *
3028
+ * @author Vova Feldman (@svovaf)
3029
+ * @since 1.0.7
3030
+ */
3031
+ function _admin_init_action() {
3032
+ /**
3033
+ * Automatically redirect to connect/activation page after plugin activation.
3034
+ *
3035
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
3036
+ */
3037
+ if ( $this->is_plugin_activation() ) {
3038
+ delete_option( "fs_{$this->_slug}_activated" );
3039
+
3040
+ if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
3041
+ $this->_redirect_on_activation_hook();
3042
+
3043
+ return;
3044
+ }
3045
+ }
3046
+
3047
+ if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
3048
+ check_admin_referer( $this->_slug . '_skip_activation' );
3049
+
3050
+ $this->skip_connection();
3051
+
3052
+ if ( fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) ) ) {
3053
+ exit();
3054
+ }
3055
+ }
3056
+
3057
+ if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
3058
+ if ( ! $this->is_pending_activation() ) {
3059
+ if ( ! $this->_menu->is_activation_page() ) {
3060
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
3061
+ // Show notice for new plugin installations.
3062
+ $this->_admin_notices->add(
3063
+ sprintf(
3064
+ __fs( 'you-are-step-away', $this->_slug ),
3065
+ sprintf( '<b><a href="%s">%s</a></b>',
3066
+ $this->get_activation_url(),
3067
+ sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
3068
+ )
3069
+ ),
3070
+ '',
3071
+ 'update-nag'
3072
+ );
3073
+ } else {
3074
+ if ( ! isset( $this->_storage->sticky_optin_added ) ) {
3075
+ $this->_storage->sticky_optin_added = true;
3076
+
3077
+ // Show notice for new plugin installations.
3078
+ $this->_admin_notices->add_sticky(
3079
+ sprintf(
3080
+ __fs( 'few-plugin-tweaks', $this->_slug ),
3081
+ sprintf( '<b><a href="%s">%s</a></b>',
3082
+ $this->get_activation_url(),
3083
+ sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
3084
+ )
3085
+ ),
3086
+ 'connect_account',
3087
+ '',
3088
+ 'update-nag'
3089
+ );
3090
+ }
3091
+
3092
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
3093
+ // Don't show admin nag if plugin update.
3094
+ wp_enqueue_script( 'wp-pointer' );
3095
+ wp_enqueue_style( 'wp-pointer' );
3096
+
3097
+ $this->_enqueue_connect_essentials();
3098
+
3099
+ add_action( 'admin_print_footer_scripts', array(
3100
+ $this,
3101
+ '_add_connect_pointer_script'
3102
+ ) );
3103
+ }
3104
+
3105
+ }
3106
+ }
3107
+ }
3108
+ }
3109
+
3110
+ $this->_add_upgrade_action_link();
3111
+ }
3112
+
3113
+ /**
3114
+ * Enqueue connect requires scripts and styles.
3115
+ *
3116
+ * @author Vova Feldman (@svovaf)
3117
+ * @since 1.1.4
3118
+ */
3119
+ function _enqueue_connect_essentials() {
3120
+ wp_enqueue_script( 'jquery' );
3121
+ wp_enqueue_script( 'json2' );
3122
+
3123
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
3124
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
3125
+
3126
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
3127
+ }
3128
+
3129
+ /**
3130
+ * Add connect / opt-in pointer.
3131
+ *
3132
+ * @author Vova Feldman (@svovaf)
3133
+ * @since 1.1.4
3134
+ */
3135
+ function _add_connect_pointer_script() {
3136
+ $vars = array( 'slug' => $this->_slug );
3137
+ $pointer_content = fs_get_template( 'connect.php', $vars );
3138
+ ?>
3139
+ <script type="text/javascript">// <![CDATA[
3140
+ jQuery(document).ready(function ($) {
3141
+ if ('undefined' !== typeof(jQuery().pointer)) {
3142
+
3143
+ var element = <?php echo $this->apply_filters('optin_pointer_element', '$("#non_existing_element");') ?>;
3144
+
3145
+ if (element.length > 0) {
3146
+ var optin = $(element).pointer($.extend(true, {}, {
3147
+ content : <?php echo json_encode($pointer_content) ?>,
3148
+ position : {
3149
+ edge : 'left',
3150
+ align: 'center'
3151
+ },
3152
+ buttons : function () {
3153
+ // Don't show pointer buttons.
3154
+ return '';
3155
+ },
3156
+ pointerWidth: 482
3157
+ }, <?php echo $this->apply_filters('optin_pointer_options_json', '{}') ?>));
3158
+
3159
+ <?php
3160
+ echo $this->apply_filters('optin_pointer_execute', "
3161
+
3162
+ optin.pointer('open');
3163
+
3164
+ // Tag the opt-in pointer with custom class.
3165
+ $('.wp-pointer #fs_connect')
3166
+ .parents('.wp-pointer.wp-pointer-top')
3167
+ .addClass('fs-opt-in-pointer');
3168
+
3169
+ ", 'element', 'optin') ?>
3170
+ }
3171
+ }
3172
+ });
3173
+ // ]]></script>
3174
+ <?php
3175
+ }
3176
+
3177
+ /**
3178
+ * Return current page's URL.
3179
+ *
3180
+ * @author Vova Feldman (@svovaf)
3181
+ * @since 1.0.7
3182
+ *
3183
+ * @return string
3184
+ */
3185
+ function current_page_url() {
3186
+ $url = 'http';
3187
+
3188
+ if ( isset( $_SERVER["HTTPS"] ) ) {
3189
+ if ( $_SERVER["HTTPS"] == "on" ) {
3190
+ $url .= "s";
3191
+ }
3192
+ }
3193
+ $url .= "://";
3194
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
3195
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
3196
+ } else {
3197
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
3198
+ }
3199
+
3200
+ return esc_url( $url );
3201
+ }
3202
+
3203
+ /**
3204
+ * Check if the current page is the plugin's main admin settings page.
3205
+ *
3206
+ * @author Vova Feldman (@svovaf)
3207
+ * @since 1.0.7
3208
+ *
3209
+ * @return bool
3210
+ */
3211
+ function _is_plugin_page() {
3212
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
3213
+ fs_is_plugin_page( $this->_slug );
3214
+ }
3215
+
3216
+ /* Events
3217
+ ------------------------------------------------------------------------------------------------------------------*/
3218
+ /**
3219
+ * Delete site install from Database.
3220
+ *
3221
+ * @author Vova Feldman (@svovaf)
3222
+ * @since 1.0.1
3223
+ *
3224
+ * @param bool $store
3225
+ */
3226
+ function _delete_site( $store = true ) {
3227
+ $sites = self::get_all_sites();
3228
+
3229
+ if ( isset( $sites[ $this->_slug ] ) ) {
3230
+ unset( $sites[ $this->_slug ] );
3231
+ }
3232
+
3233
+ self::$_accounts->set_option( 'sites', $sites, $store );
3234
+ }
3235
+
3236
+ /**
3237
+ * Delete plugin's plans information.
3238
+ *
3239
+ * @param bool $store Flush to Database if true.
3240
+ *
3241
+ * @author Vova Feldman (@svovaf)
3242
+ * @since 1.0.9
3243
+ */
3244
+ private function _delete_plans( $store = true ) {
3245
+ $this->_logger->entrance();
3246
+
3247
+ $plans = self::get_all_plans();
3248
+
3249
+ unset( $plans[ $this->_slug ] );
3250
+
3251
+ self::$_accounts->set_option( 'plans', $plans, $store );
3252
+ }
3253
+
3254
+ /**
3255
+ * Delete all plugin licenses.
3256
+ *
3257
+ * @author Vova Feldman (@svovaf)
3258
+ * @since 1.0.9
3259
+ *
3260
+ * @param bool $store
3261
+ * @param string|bool $plugin_slug
3262
+ */
3263
+ private function _delete_licenses( $store = true, $plugin_slug = false ) {
3264
+ $this->_logger->entrance();
3265
+
3266
+ $all_licenses = self::get_all_licenses();
3267
+
3268
+ if ( ! is_string( $plugin_slug ) ) {
3269
+ $plugin_slug = $this->_slug;
3270
+ }
3271
+
3272
+ unset( $all_licenses[ $plugin_slug ] );
3273
+
3274
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
3275
+ }
3276
+
3277
+ /**
3278
+ * Check if Freemius was added on new plugin installation.
3279
+ *
3280
+ * @author Vova Feldman (@svovaf)
3281
+ * @since 1.1.5
3282
+ *
3283
+ * @return bool
3284
+ */
3285
+ function is_plugin_new_install() {
3286
+ return isset( $this->_storage->is_plugin_new_install ) &&
3287
+ $this->_storage->is_plugin_new_install;
3288
+ }
3289
+
3290
+ /**
3291
+ * Plugin activated hook.
3292
+ *
3293
+ * @author Vova Feldman (@svovaf)
3294
+ * @since 1.0.1
3295
+ *
3296
+ * @uses FS_Api
3297
+ */
3298
+ function _activate_plugin_event_hook() {
3299
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3300
+
3301
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3302
+ return;
3303
+ }
3304
+
3305
+ // Clear API cache on activation.
3306
+ FS_Api::clear_cache();
3307
+
3308
+ if ( $this->is_registered() ) {
3309
+ // Schedule re-activation event and sync.
3310
+ // $this->sync_install( array(), true );
3311
+ $this->schedule_install_sync();
3312
+
3313
+ /**
3314
+ * @todo Work on automatic deactivation of the Free plugin version. It doesn't work since the slug of the free & premium versions is identical. Therefore, only one instance of Freemius is created and the activation hook of the premium version is not being added.
3315
+ */
3316
+ if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
3317
+ // Deactivate Free plugin version on premium plugin activation.
3318
+ deactivate_plugins( $this->_free_plugin_basename );
3319
+
3320
+ $this->_admin_notices->add(
3321
+ sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
3322
+ __fs( 'woot', $this->_slug ) . '!'
3323
+ );
3324
+ }
3325
+ } else if ( $this->is_anonymous() ) {
3326
+ /**
3327
+ * Reset "skipped" click cache on the following:
3328
+ * 1. Development mode.
3329
+ * 2. If the user skipped the exact same version before.
3330
+ *
3331
+ * @todo 3. If explicitly asked to retry after every activation.
3332
+ */
3333
+ if ( WP_FS__DEV_MODE ||
3334
+ $this->get_plugin_version() == $this->_storage->is_anonymous['version']
3335
+ ) {
3336
+ $this->reset_anonymous_mode();
3337
+ }
3338
+ }
3339
+
3340
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3341
+ /**
3342
+ * If no previous version of plugin's version exist, it means that it's either
3343
+ * the first time that the plugin installed on the site, or the plugin was installed
3344
+ * before but didn't have Freemius integrated.
3345
+ *
3346
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
3347
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
3348
+ * only after immediate activation.
3349
+ *
3350
+ * @since 1.1.4
3351
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
3352
+ */
3353
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
3354
+ }
3355
+
3356
+ if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
3357
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
3358
+ add_option( "fs_{$this->_slug}_activated", true );
3359
+ }
3360
+
3361
+ /**
3362
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
3363
+ * after the plugin was loaded. The logic is located at activate_plugin()
3364
+ * ./wp-admin/includes/plugin.php.
3365
+ *
3366
+ * @author Vova Feldman (@svovaf)
3367
+ * @since 1.1.9
3368
+ */
3369
+ $this->_storage->was_plugin_loaded = true;
3370
+ }
3371
+
3372
+ /**
3373
+ * Delete account.
3374
+ *
3375
+ * @author Vova Feldman (@svovaf)
3376
+ * @since 1.0.3
3377
+ *
3378
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3379
+ */
3380
+ function delete_account_event( $check_user = true ) {
3381
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3382
+
3383
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3384
+ return;
3385
+ }
3386
+
3387
+ $this->do_action( 'before_account_delete' );
3388
+
3389
+ // Clear all admin notices.
3390
+ $this->_admin_notices->clear_all_sticky();
3391
+
3392
+ $this->_delete_site( false );
3393
+
3394
+ $this->_delete_plans( false );
3395
+
3396
+ $this->_delete_licenses( false );
3397
+
3398
+ // Delete add-ons related to plugin's account.
3399
+ $this->_delete_account_addons( false );
3400
+
3401
+ // @todo Delete plans and licenses of add-ons.
3402
+
3403
+ self::$_accounts->store();
3404
+
3405
+ /**
3406
+ * IMPORTANT:
3407
+ * Clear crons must be executed before clearing all storage.
3408
+ * Otherwise, the cron will not be cleared.
3409
+ */
3410
+ $this->clear_sync_cron();
3411
+ $this->clear_install_sync_cron();
3412
+
3413
+ // Clear all storage data.
3414
+ $this->_storage->clear_all( true, array(
3415
+ 'connectivity_test',
3416
+ 'is_on',
3417
+ ) );
3418
+
3419
+ // Send delete event.
3420
+ $this->get_api_site_scope()->call( '/', 'delete' );
3421
+
3422
+ $this->do_action( 'after_account_delete' );
3423
+ }
3424
+
3425
+ /**
3426
+ * Plugin deactivation hook.
3427
+ *
3428
+ * @author Vova Feldman (@svovaf)
3429
+ * @since 1.0.1
3430
+ */
3431
+ function _deactivate_plugin_hook() {
3432
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3433
+
3434
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3435
+ return;
3436
+ }
3437
+
3438
+ $this->_admin_notices->clear_all_sticky();
3439
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
3440
+ unset( $this->_storage->sticky_optin_added );
3441
+ }
3442
+
3443
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3444
+ // Remember that plugin was already installed.
3445
+ $this->_storage->is_plugin_new_install = false;
3446
+ }
3447
+
3448
+ $this->clear_sync_cron();
3449
+ $this->clear_install_sync_cron();
3450
+
3451
+ if ( $this->is_registered() ) {
3452
+ // Send deactivation event.
3453
+ $this->sync_install( array(
3454
+ 'is_active' => false,
3455
+ ) );
3456
+ } else {
3457
+ if ( ! $this->has_api_connectivity() ) {
3458
+ // Reset connectivity test cache.
3459
+ unset( $this->_storage->connectivity_test );
3460
+ }
3461
+ }
3462
+
3463
+ // Clear API cache on deactivation.
3464
+ FS_Api::clear_cache();
3465
+
3466
+ $this->remove_sdk_reference();
3467
+ }
3468
+
3469
+ /**
3470
+ * @author Vova Feldman (@svovaf)
3471
+ * @since 1.1.6
3472
+ */
3473
+ private function remove_sdk_reference() {
3474
+ global $fs_active_plugins;
3475
+
3476
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
3477
+ if ( $this->_plugin_basename == $data->plugin_path ) {
3478
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
3479
+ break;
3480
+ }
3481
+ }
3482
+
3483
+ fs_fallback_to_newest_active_sdk();
3484
+ }
3485
+
3486
+ /**
3487
+ * @author Vova Feldman (@svovaf)
3488
+ * @since 1.1.3
3489
+ *
3490
+ * @param bool $is_anonymous
3491
+ */
3492
+ private function set_anonymous_mode( $is_anonymous = true ) {
3493
+ // Store information regarding skip to try and opt-in the user
3494
+ // again in the future.
3495
+ $this->_storage->is_anonymous = array(
3496
+ 'is' => $is_anonymous,
3497
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3498
+ 'version' => $this->get_plugin_version(),
3499
+ );
3500
+
3501
+ // Update anonymous mode cache.
3502
+ $this->_is_anonymous = $is_anonymous;
3503
+ }
3504
+
3505
+ /**
3506
+ * @author Vova Feldman (@svovaf)
3507
+ * @since 1.1.3
3508
+ */
3509
+ private function reset_anonymous_mode() {
3510
+ unset( $this->_storage->is_anonymous );
3511
+ }
3512
+
3513
+ /**
3514
+ * Clears the anonymous mode and redirects to the opt-in screen.
3515
+ *
3516
+ * @author Vova Feldman (@svovaf)
3517
+ * @since 1.1.7
3518
+ */
3519
+ function connect_again() {
3520
+ if ( ! $this->is_anonymous() ) {
3521
+ return;
3522
+ }
3523
+
3524
+ $this->reset_anonymous_mode();
3525
+
3526
+ if ( fs_redirect( $this->get_activation_url() ) ) {
3527
+ exit();
3528
+ }
3529
+ }
3530
+
3531
+ /**
3532
+ * Skip account connect, and set anonymous mode.
3533
+ *
3534
+ * @author Vova Feldman (@svovaf)
3535
+ * @since 1.1.1
3536
+ */
3537
+ private function skip_connection() {
3538
+ $this->_logger->entrance();
3539
+
3540
+ $this->_admin_notices->remove_sticky( 'connect_account' );
3541
+
3542
+ $this->set_anonymous_mode();
3543
+
3544
+ // Send anonymous skip event.
3545
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
3546
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
3547
+ 'uid' => $this->get_anonymous_id(),
3548
+ ) );
3549
+ }
3550
+
3551
+ /**
3552
+ * Plugin version update hook.
3553
+ *
3554
+ * @author Vova Feldman (@svovaf)
3555
+ * @since 1.0.4
3556
+ */
3557
+ private function update_plugin_version_event() {
3558
+ $this->_logger->entrance();
3559
+
3560
+ if ( ! $this->is_registered() ) {
3561
+ return;
3562
+ }
3563
+
3564
+ $this->schedule_install_sync();
3565
+ // $this->sync_install( array(), true );
3566
+ }
3567
+
3568
+ /**
3569
+ * Return a list of modified plugins since the last sync.
3570
+ *
3571
+ * Note:
3572
+ * There's no point to store a plugins counter since even if the number of
3573
+ * plugins didn't change, we still need to check if the versions are all the
3574
+ * same and the activity state is similar.
3575
+ *
3576
+ * @author Vova Feldman (@svovaf)
3577
+ * @since 1.1.8
3578
+ *
3579
+ * @return array|false
3580
+ */
3581
+ private function get_plugins_data_for_api() {
3582
+ // Alias.
3583
+ $option_name = 'all_plugins';
3584
+
3585
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3586
+
3587
+ if ( ! is_object( $all_cached_plugins ) ) {
3588
+ $all_cached_plugins = (object) array(
3589
+ 'timestamp' => '',
3590
+ 'md5' => '',
3591
+ 'plugins' => array(),
3592
+ );
3593
+ }
3594
+
3595
+ $time = time();
3596
+
3597
+ if ( ! empty( $all_cached_plugins->timestamp ) &&
3598
+ ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3599
+ ) {
3600
+ // Don't send plugin updates if last update was in the past 5 min.
3601
+ return false;
3602
+ }
3603
+
3604
+ // Write timestamp to lock the logic.
3605
+ $all_cached_plugins->timestamp = $time;
3606
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3607
+
3608
+ // Reload options from DB.
3609
+ self::$_accounts->load( true );
3610
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
3611
+
3612
+ if ( $time != $all_cached_plugins->timestamp ) {
3613
+ // If timestamp is different, then another thread captured the lock.
3614
+ return false;
3615
+ }
3616
+
3617
+ // Check if there's a change in plugins.
3618
+ $all_plugins = self::get_all_plugins();
3619
+
3620
+ // Check if plugins changed.
3621
+ ksort( $all_plugins );
3622
+
3623
+ $plugins_signature = '';
3624
+ foreach ( $all_plugins as $basename => $data ) {
3625
+ $plugins_signature .= $data['slug'] . ',' .
3626
+ $data['Version'] . ',' .
3627
+ ( $data['is_active'] ? '1' : '0' ) . ';';
3628
+ }
3629
+
3630
+ // Check if plugins status changed (version or active/inactive).
3631
+ $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
3632
+
3633
+ $plugins_update_data = array();
3634
+
3635
+ if ( $plugins_changed ) {
3636
+ // Change in plugins, report changes.
3637
+
3638
+ // Update existing plugins info.
3639
+ foreach ( $all_cached_plugins->plugins as $basename => $data ) {
3640
+ if ( ! isset( $all_plugins[ $basename ] ) ) {
3641
+ // Plugin uninstalled.
3642
+ $uninstalled_plugin_data = $data;
3643
+ $uninstalled_plugin_data['is_active'] = false;
3644
+ $uninstalled_plugin_data['is_uninstalled'] = true;
3645
+ $plugins_update_data[] = $uninstalled_plugin_data;
3646
+
3647
+ unset( $all_plugins[ $basename ] );
3648
+ unset( $all_cached_plugins->plugins[ $basename ] );
3649
+ } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
3650
+ $data['version'] !== $all_plugins[ $basename ]['Version']
3651
+ ) {
3652
+ // Plugin activated or deactivated, or version changed.
3653
+ $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
3654
+ $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
3655
+
3656
+ $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
3657
+ }
3658
+ }
3659
+
3660
+ // Find new plugins that weren't yet seen before.
3661
+ foreach ( $all_plugins as $basename => $data ) {
3662
+ if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
3663
+ // New plugin.
3664
+ $new_plugin = array(
3665
+ 'slug' => $data['slug'],
3666
+ 'version' => $data['Version'],
3667
+ 'title' => $data['Name'],
3668
+ 'is_active' => $data['is_active'],
3669
+ 'is_uninstalled' => false,
3670
+ );
3671
+
3672
+ $plugins_update_data[] = $new_plugin;
3673
+ $all_cached_plugins->plugins[ $basename ] = $new_plugin;
3674
+ }
3675
+ }
3676
+
3677
+ $all_cached_plugins->md5 = md5( $plugins_signature );
3678
+ $all_cached_plugins->timestamp = $time;
3679
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3680
+ }
3681
+
3682
+ return $plugins_update_data;
3683
+ }
3684
+
3685
+ /**
3686
+ * Return a list of modified themes since the last sync.
3687
+ *
3688
+ * Note:
3689
+ * There's no point to store a themes counter since even if the number of
3690
+ * themes didn't change, we still need to check if the versions are all the
3691
+ * same and the activity state is similar.
3692
+ *
3693
+ * @author Vova Feldman (@svovaf)
3694
+ * @since 1.1.8
3695
+ *
3696
+ * @return array|false
3697
+ */
3698
+ private function get_themes_data_for_api() {
3699
+ // Alias.
3700
+ $option_name = 'all_themes';
3701
+
3702
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3703
+
3704
+ if ( ! is_object( $all_cached_themes ) ) {
3705
+ $all_cached_themes = (object) array(
3706
+ 'timestamp' => '',
3707
+ 'md5' => '',
3708
+ 'themes' => array(),
3709
+ );
3710
+ }
3711
+
3712
+ $time = time();
3713
+
3714
+ if ( ! empty( $all_cached_themes->timestamp ) &&
3715
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3716
+ ) {
3717
+ // Don't send theme updates if last update was in the past 5 min.
3718
+ return false;
3719
+ }
3720
+
3721
+ // Write timestamp to lock the logic.
3722
+ $all_cached_themes->timestamp = $time;
3723
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3724
+
3725
+ // Reload options from DB.
3726
+ self::$_accounts->load( true );
3727
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
3728
+
3729
+ if ( $time != $all_cached_themes->timestamp ) {
3730
+ // If timestamp is different, then another thread captured the lock.
3731
+ return false;
3732
+ }
3733
+
3734
+ // Get active theme.
3735
+ $active_theme = wp_get_theme();
3736
+
3737
+ // Check if there's a change in themes.
3738
+ $all_themes = wp_get_themes();
3739
+
3740
+ // Check if themes changed.
3741
+ ksort( $all_themes );
3742
+
3743
+ $themes_signature = '';
3744
+ foreach ( $all_themes as $slug => $data ) {
3745
+ $is_active = ( $slug === $active_theme->stylesheet );
3746
+ $themes_signature .= $slug . ',' .
3747
+ $data->version . ',' .
3748
+ ( $is_active ? '1' : '0' ) . ';';
3749
+ }
3750
+
3751
+ // Check if themes status changed (version or active/inactive).
3752
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
3753
+
3754
+ $themes_update_data = array();
3755
+
3756
+ if ( $themes_changed ) {
3757
+ // Change in themes, report changes.
3758
+
3759
+ // Update existing themes info.
3760
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
3761
+ $is_active = ( $slug === $active_theme->stylesheet );
3762
+
3763
+ if ( ! isset( $all_themes[ $slug ] ) ) {
3764
+ // Plugin uninstalled.
3765
+ $uninstalled_theme_data = $data;
3766
+ $uninstalled_theme_data['is_active'] = false;
3767
+ $uninstalled_theme_data['is_uninstalled'] = true;
3768
+ $themes_update_data[] = $uninstalled_theme_data;
3769
+
3770
+ unset( $all_themes[ $slug ] );
3771
+ unset( $all_cached_themes->themes[ $slug ] );
3772
+ } else if ( $data['is_active'] !== $is_active ||
3773
+ $data['version'] !== $all_themes[ $slug ]->version
3774
+ ) {
3775
+ // Plugin activated or deactivated, or version changed.
3776
+
3777
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
3778
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
3779
+
3780
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
3781
+ }
3782
+ }
3783
+
3784
+ // Find new themes that weren't yet seen before.
3785
+ foreach ( $all_themes as $slug => $data ) {
3786
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
3787
+ $is_active = ( $slug === $active_theme->stylesheet );
3788
+
3789
+ // New plugin.
3790
+ $new_plugin = array(
3791
+ 'slug' => $slug,
3792
+ 'version' => $data->version,
3793
+ 'title' => $data->name,
3794
+ 'is_active' => $is_active,
3795
+ 'is_uninstalled' => false,
3796
+ );
3797
+
3798
+ $themes_update_data[] = $new_plugin;
3799
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
3800
+ }
3801
+ }
3802
+
3803
+ $all_cached_themes->md5 = md5( $themes_signature );
3804
+ $all_cached_themes->timestamp = time();
3805
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3806
+ }
3807
+
3808
+ return $themes_update_data;
3809
+ }
3810
+
3811
+ /**
3812
+ * Update install details.
3813
+ *
3814
+ * @author Vova Feldman (@svovaf)
3815
+ * @since 1.1.2
3816
+ *
3817
+ * @param string[] string $override
3818
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
3819
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
3820
+ *
3821
+ * @return array
3822
+ */
3823
+ private function get_install_data_for_api(
3824
+ array $override,
3825
+ $include_plugins = true,
3826
+ $include_themes = true
3827
+ ) {
3828
+ /**
3829
+ * @since 1.1.8 Also send plugin updates.
3830
+ */
3831
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
3832
+ $plugins = $this->get_plugins_data_for_api();
3833
+ if ( ! empty( $plugins ) ) {
3834
+ $override['plugins'] = $plugins;
3835
+ }
3836
+ }
3837
+ /**
3838
+ * @since 1.1.8 Also send themes updates.
3839
+ */
3840
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
3841
+ $themes = $this->get_themes_data_for_api();
3842
+ if ( ! empty( $themes ) ) {
3843
+ $override['themes'] = $themes;
3844
+ }
3845
+ }
3846
+
3847
+ return array_merge( array(
3848
+ 'version' => $this->get_plugin_version(),
3849
+ 'is_premium' => $this->is_premium(),
3850
+ 'language' => get_bloginfo( 'language' ),
3851
+ 'charset' => get_bloginfo( 'charset' ),
3852
+ 'platform_version' => get_bloginfo( 'version' ),
3853
+ 'programming_language_version' => phpversion(),
3854
+ 'title' => get_bloginfo( 'name' ),
3855
+ 'url' => get_site_url(),
3856
+ // Special params.
3857
+ 'is_active' => true,
3858
+ 'is_uninstalled' => false,
3859
+ ), $override );
3860
+ }
3861
+
3862
+ /**
3863
+ * Update install only if changed.
3864
+ *
3865
+ * @author Vova Feldman (@svovaf)
3866
+ * @since 1.0.9
3867
+ *
3868
+ * @param string[] string $override
3869
+ * @param bool $flush
3870
+ *
3871
+ * @return false|object|string
3872
+ */
3873
+ private function send_install_update( $override = array(), $flush = false ) {
3874
+ $this->_logger->entrance();
3875
+
3876
+ $check_properties = $this->get_install_data_for_api( $override );
3877
+
3878
+ if ( $flush ) {
3879
+ $params = $check_properties;
3880
+ } else {
3881
+ $params = array();
3882
+ $special = array();
3883
+ $special_override = false;
3884
+
3885
+ foreach ( $check_properties as $p => $v ) {
3886
+ if ( property_exists( $this->_site, $p ) ) {
3887
+ if ( ! empty( $this->_site->{$p} ) &&
3888
+ $this->_site->{$p} != $v
3889
+ ) {
3890
+ $this->_site->{$p} = $v;
3891
+ $params[ $p ] = $v;
3892
+ }
3893
+ } else {
3894
+ $special[ $p ] = $v;
3895
+
3896
+ if ( isset( $override[ $p ] ) ||
3897
+ 'plugins' === $p ||
3898
+ 'themes' === $p
3899
+ ) {
3900
+ $special_override = true;
3901
+ }
3902
+ }
3903
+ }
3904
+
3905
+ if ( $special_override || 0 < count( $params ) ) {
3906
+ // Add special params only if has at least one
3907
+ // standard param, or if explicitly requested to
3908
+ // override a special param or a param which is not exist
3909
+ // in the install object.
3910
+ $params = array_merge( $params, $special );
3911
+ }
3912
+ }
3913
+
3914
+ if ( 0 < count( $params ) ) {
3915
+ // Update last install sync timestamp.
3916
+ $this->_storage->install_sync_timestamp = time();
3917
+
3918
+ $params['uid'] = $this->get_anonymous_id();
3919
+
3920
+ // Send updated values to FS.
3921
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
3922
+
3923
+ if ( ! $this->is_api_error( $site ) ) {
3924
+ // I successfully sent install update, clear scheduled sync if exist.
3925
+ $this->clear_install_sync_cron();
3926
+ }
3927
+
3928
+ return $site;
3929
+ }
3930
+
3931
+ return false;
3932
+ }
3933
+
3934
+ /**
3935
+ * Update install only if changed.
3936
+ *
3937
+ * @author Vova Feldman (@svovaf)
3938
+ * @since 1.0.9
3939
+ *
3940
+ * @param string[] string $override
3941
+ * @param bool $flush
3942
+ *
3943
+ * @return false|object|string
3944
+ */
3945
+ private function sync_install( $override = array(), $flush = false ) {
3946
+ $this->_logger->entrance();
3947
+
3948
+ $site = $this->send_install_update( $override, $flush );
3949
+
3950
+ if ( false === $site ) {
3951
+ // No sync required.
3952
+ return;
3953
+ }
3954
+
3955
+ if ( $this->is_api_error( $site ) ) {
3956
+ // Failed to sync, don't update locally.
3957
+ return;
3958
+ }
3959
+
3960
+ $plan = $this->get_plan();
3961
+ $this->_site = new FS_Site( $site );
3962
+ $this->_site->plan = $plan;
3963
+
3964
+ $this->_store_site( true );
3965
+ }
3966
+
3967
+ /**
3968
+ * Plugin uninstall hook.
3969
+ *
3970
+ * @author Vova Feldman (@svovaf)
3971
+ * @since 1.0.1
3972
+ *
3973
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3974
+ */
3975
+ function _uninstall_plugin_event( $check_user = true ) {
3976
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3977
+
3978
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3979
+ return;
3980
+ }
3981
+
3982
+ $params = array();
3983
+ if ( isset( $this->_storage->uninstall_reason ) ) {
3984
+ $params['reason_id'] = $this->_storage->uninstall_reason->id;
3985
+ $params['reason_info'] = $this->_storage->uninstall_reason->info;
3986
+ }
3987
+
3988
+ if ( ! $this->is_registered() && isset( $this->_storage->uninstall_reason ) ) {
3989
+ // Send anonymous uninstall event only if user submitted a feedback.
3990
+ $params['uid'] = $this->get_anonymous_id();
3991
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
3992
+ } else {
3993
+ // Send uninstall event.
3994
+ $this->send_install_update( array_merge( $params, array(
3995
+ 'is_active' => false,
3996
+ 'is_uninstalled' => true,
3997
+ ) ) );
3998
+ }
3999
+
4000
+ // @todo Decide if we want to delete plugin information from db.
4001
+ }
4002
+
4003
+ /**
4004
+ * @author Vova Feldman (@svovaf)
4005
+ * @since 1.1.1
4006
+ *
4007
+ * @return string
4008
+ */
4009
+ private function premium_plugin_basename() {
4010
+ return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
4011
+ }
4012
+
4013
+ /**
4014
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
4015
+ *
4016
+ * @author Vova Feldman (@svovaf)
4017
+ * @since 1.0.2
4018
+ */
4019
+ public static function _uninstall_plugin_hook() {
4020
+ self::_load_required_static();
4021
+
4022
+ self::$_static_logger->entrance();
4023
+
4024
+ if ( ! current_user_can( 'activate_plugins' ) ) {
4025
+ return;
4026
+ }
4027
+
4028
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
4029
+
4030
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
4031
+
4032
+ define( 'WP_FS__UNINSTALL_MODE', true );
4033
+
4034
+ $fs = self::get_instance_by_file( $plugin_file );
4035
+
4036
+ if ( is_object( $fs ) ) {
4037
+ self::require_plugin_essentials();
4038
+
4039
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
4040
+ is_plugin_active( $fs->premium_plugin_basename() )
4041
+ ) {
4042
+ // Deleting Free or Premium plugin version while the other version still installed.
4043
+ return;
4044
+ }
4045
+
4046
+ $fs->_uninstall_plugin_event();
4047
+
4048
+ $fs->do_action( 'after_uninstall' );
4049
+ }
4050
+ }
4051
+
4052
+ #region Plugin Information ------------------------------------------------------------------
4053
+
4054
+ /**
4055
+ * Load WordPress core plugin.php essential module.
4056
+ *
4057
+ * @author Vova Feldman (@svovaf)
4058
+ * @since 1.1.1
4059
+ */
4060
+ private static function require_plugin_essentials() {
4061
+ if ( ! function_exists( 'get_plugins' ) ) {
4062
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
4063
+ }
4064
+ }
4065
+
4066
+ /**
4067
+ * Load WordPress core pluggable.php module.
4068
+ *
4069
+ * @author Vova Feldman (@svovaf)
4070
+ * @since 1.1.2
4071
+ */
4072
+ private static function require_pluggable_essentials() {
4073
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
4074
+ require_once( ABSPATH . 'wp-includes/pluggable.php' );
4075
+ }
4076
+ }
4077
+
4078
+ /**
4079
+ * Return plugin data.
4080
+ *
4081
+ * @author Vova Feldman (@svovaf)
4082
+ * @since 1.0.1
4083
+ *
4084
+ * @return array
4085
+ */
4086
+ function get_plugin_data() {
4087
+ if ( ! isset( $this->_plugin_data ) ) {
4088
+ self::require_plugin_essentials();
4089
+
4090
+ $this->_plugin_data = get_plugin_data( $this->_plugin_main_file_path );
4091
+ }
4092
+
4093
+ return $this->_plugin_data;
4094
+ }
4095
+
4096
+ /**
4097
+ * @author Vova Feldman (@svovaf)
4098
+ * @since 1.0.1
4099
+ *
4100
+ * @return string Plugin slug.
4101
+ */
4102
+ function get_slug() {
4103
+ return $this->_slug;
4104
+ }
4105
+
4106
+ /**
4107
+ * @author Vova Feldman (@svovaf)
4108
+ * @since 1.0.1
4109
+ *
4110
+ * @return number Plugin ID.
4111
+ */
4112
+ function get_id() {
4113
+ return $this->_plugin->id;
4114
+ }
4115
+
4116
+ /**
4117
+ * @author Vova Feldman (@svovaf)
4118
+ * @since 1.0.1
4119
+ *
4120
+ * @return string Plugin public key.
4121
+ */
4122
+ function get_public_key() {
4123
+ return $this->_plugin->public_key;
4124
+ }
4125
+
4126
+ /**
4127
+ * Will be available only on sandbox mode.
4128
+ *
4129
+ * @author Vova Feldman (@svovaf)
4130
+ * @since 1.0.4
4131
+ *
4132
+ * @return mixed Plugin secret key.
4133
+ */
4134
+ function get_secret_key() {
4135
+ return $this->_plugin->secret_key;
4136
+ }
4137
+
4138
+ /**
4139
+ * @author Vova Feldman (@svovaf)
4140
+ * @since 1.1.1
4141
+ *
4142
+ * @return bool
4143
+ */
4144
+ function has_secret_key() {
4145
+ return ! empty( $this->_plugin->secret_key );
4146
+ }
4147
+
4148
+ /**
4149
+ * @author Vova Feldman (@svovaf)
4150
+ * @since 1.0.9
4151
+ *
4152
+ * @return string
4153
+ */
4154
+ function get_plugin_name() {
4155
+ $this->_logger->entrance();
4156
+
4157
+ if ( ! isset( $this->_plugin_name ) ) {
4158
+ $plugin_data = $this->get_plugin_data();
4159
+
4160
+ // Get name.
4161
+ $this->_plugin_name = $plugin_data['Name'];
4162
+
4163
+ // Check if plugin name contains [Premium] suffix and remove it.
4164
+ $suffix = '[premium]';
4165
+ $suffix_len = strlen( $suffix );
4166
+
4167
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
4168
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
4169
+ ) {
4170
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
4171
+ }
4172
+
4173
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
4174
+ }
4175
+
4176
+ return $this->_plugin_name;
4177
+ }
4178
+
4179
+ /**
4180
+ * @author Vova Feldman (@svovaf)
4181
+ * @since 1.0.0
4182
+ *
4183
+ * @return string
4184
+ */
4185
+ function get_plugin_version() {
4186
+ $this->_logger->entrance();
4187
+
4188
+ $plugin_data = $this->get_plugin_data();
4189
+
4190
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
4191
+
4192
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
4193
+ }
4194
+
4195
+ /**
4196
+ * @author Vova Feldman (@svovaf)
4197
+ * @since 1.0.4
4198
+ *
4199
+ * @return string
4200
+ */
4201
+ function get_plugin_basename() {
4202
+ return $this->_plugin_basename;
4203
+ }
4204
+
4205
+ function get_plugin_folder_name() {
4206
+ $this->_logger->entrance();
4207
+
4208
+ $plugin_folder = $this->_plugin_basename;
4209
+
4210
+ while ( '.' !== dirname( $plugin_folder ) ) {
4211
+ $plugin_folder = dirname( $plugin_folder );
4212
+ }
4213
+
4214
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
4215
+
4216
+ return $plugin_folder;
4217
+ }
4218
+
4219
+ #endregion ------------------------------------------------------------------
4220
+
4221
+ /* Account
4222
+ ------------------------------------------------------------------------------------------------------------------*/
4223
+
4224
+ /**
4225
+ * Find plugin's slug by plugin's basename.
4226
+ *
4227
+ * @author Vova Feldman (@svovaf)
4228
+ * @since 1.0.9
4229
+ *
4230
+ * @param string $plugin_base_name
4231
+ *
4232
+ * @return false|string
4233
+ */
4234
+ private static function find_slug_by_basename( $plugin_base_name ) {
4235
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4236
+
4237
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
4238
+ return false;
4239
+ }
4240
+
4241
+ return $file_slug_map[ $plugin_base_name ];
4242
+ }
4243
+
4244
+ /**
4245
+ * Store the map between the plugin's basename to the slug.
4246
+ *
4247
+ * @author Vova Feldman (@svovaf)
4248
+ * @since 1.0.9
4249
+ */
4250
+ private function store_file_slug_map() {
4251
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4252
+
4253
+ if ( ! array( $file_slug_map ) ) {
4254
+ $file_slug_map = array();
4255
+ }
4256
+
4257
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
4258
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
4259
+ ) {
4260
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
4261
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
4262
+ }
4263
+ }
4264
+
4265
+ /**
4266
+ * @return FS_User[]
4267
+ */
4268
+ static function get_all_users() {
4269
+ $users = self::$_accounts->get_option( 'users', array() );
4270
+
4271
+ if ( ! is_array( $users ) ) {
4272
+ $users = array();
4273
+ }
4274
+
4275
+ return $users;
4276
+ }
4277
+
4278
+ /**
4279
+ * @return FS_Site[]
4280
+ */
4281
+ private static function get_all_sites() {
4282
+ $sites = self::$_accounts->get_option( 'sites', array() );
4283
+
4284
+ if ( ! is_array( $sites ) ) {
4285
+ $sites = array();
4286
+ }
4287
+
4288
+ return $sites;
4289
+ }
4290
+
4291
+ /**
4292
+ * @author Vova Feldman (@svovaf)
4293
+ * @since 1.0.6
4294
+ *
4295
+ * @return FS_Plugin_License[]
4296
+ */
4297
+ private static function get_all_licenses() {
4298
+ $licenses = self::$_accounts->get_option( 'licenses', array() );
4299
+
4300
+ if ( ! is_array( $licenses ) ) {
4301
+ $licenses = array();
4302
+ }
4303
+
4304
+ return $licenses;
4305
+ }
4306
+
4307
+ /**
4308
+ * @return FS_Plugin_Plan[]
4309
+ */
4310
+ private static function get_all_plans() {
4311
+ $plans = self::$_accounts->get_option( 'plans', array() );
4312
+
4313
+ if ( ! is_array( $plans ) ) {
4314
+ $plans = array();
4315
+ }
4316
+
4317
+ return $plans;
4318
+ }
4319
+
4320
+ /**
4321
+ * @author Vova Feldman (@svovaf)
4322
+ * @since 1.0.4
4323
+ *
4324
+ * @return FS_Plugin_Tag[]
4325
+ */
4326
+ private static function get_all_updates() {
4327
+ $updates = self::$_accounts->get_option( 'updates', array() );
4328
+
4329
+ if ( ! is_array( $updates ) ) {
4330
+ $updates = array();
4331
+ }
4332
+
4333
+ return $updates;
4334
+ }
4335
+
4336
+ /**
4337
+ * @author Vova Feldman (@svovaf)
4338
+ * @since 1.0.6
4339
+ *
4340
+ * @return FS_Plugin[]|false
4341
+ */
4342
+ private static function get_all_addons() {
4343
+ $addons = self::$_accounts->get_option( 'addons', array() );
4344
+
4345
+ if ( ! is_array( $addons ) ) {
4346
+ $addons = array();
4347
+ }
4348
+
4349
+ return $addons;
4350
+ }
4351
+
4352
+ /**
4353
+ * @author Vova Feldman (@svovaf)
4354
+ * @since 1.0.6
4355
+ *
4356
+ * @return FS_Plugin[]|false
4357
+ */
4358
+ private static function get_all_account_addons() {
4359
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
4360
+
4361
+ if ( ! is_array( $addons ) ) {
4362
+ $addons = array();
4363
+ }
4364
+
4365
+ return $addons;
4366
+ }
4367
+
4368
+ /**
4369
+ * Check if user is registered.
4370
+ *
4371
+ * @author Vova Feldman (@svovaf)
4372
+ * @since 1.0.1
4373
+ * @return bool
4374
+ */
4375
+ function is_registered() {
4376
+ return is_object( $this->_user );
4377
+ }
4378
+
4379
+ /**
4380
+ * @author Vova Feldman (@svovaf)
4381
+ * @since 1.0.4
4382
+ *
4383
+ * @return FS_Plugin
4384
+ */
4385
+ function get_plugin() {
4386
+ return $this->_plugin;
4387
+ }
4388
+
4389
+ /**
4390
+ * @author Vova Feldman (@svovaf)
4391
+ * @since 1.0.3
4392
+ *
4393
+ * @return FS_User
4394
+ */
4395
+ function get_user() {
4396
+ return $this->_user;
4397
+ }
4398
+
4399
+ /**
4400
+ * @author Vova Feldman (@svovaf)
4401
+ * @since 1.0.3
4402
+ *
4403
+ * @return FS_Site
4404
+ */
4405
+ function get_site() {
4406
+ return $this->_site;
4407
+ }
4408
+
4409
+ /**
4410
+ * Get plugin add-ons.
4411
+ *
4412
+ * @author Vova Feldman (@svovaf)
4413
+ * @since 1.0.6
4414
+ *
4415
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4416
+ *
4417
+ * @return FS_Plugin[]|false
4418
+ */
4419
+ function get_addons() {
4420
+ $this->_logger->entrance();
4421
+
4422
+ $all_addons = self::get_all_addons();
4423
+
4424
+ /**
4425
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4426
+ */
4427
+ if ( ! is_array( $all_addons ) ||
4428
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4429
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4430
+ empty( $all_addons[ $this->_plugin->id ] )
4431
+ ) {
4432
+ if ( $this->_has_addons ) {
4433
+ $addons = $this->_sync_addons();
4434
+
4435
+ if ( ! empty( $addons ) ) {
4436
+ $all_addons = self::get_all_addons();
4437
+ }
4438
+ }
4439
+ }
4440
+
4441
+ if ( ! is_array( $all_addons ) ||
4442
+ ! isset( $all_addons[ $this->_plugin->id ] ) ||
4443
+ ! is_array( $all_addons[ $this->_plugin->id ] ) ||
4444
+ empty( $all_addons[ $this->_plugin->id ] )
4445
+ ) {
4446
+ return false;
4447
+ }
4448
+
4449
+ return $all_addons[ $this->_plugin->id ];
4450
+ }
4451
+
4452
+ /**
4453
+ * @author Vova Feldman (@svovaf)
4454
+ * @since 1.0.6
4455
+ *
4456
+ * @return FS_Plugin[]|false
4457
+ */
4458
+ function get_account_addons() {
4459
+ $this->_logger->entrance();
4460
+
4461
+ $addons = self::get_all_account_addons();
4462
+
4463
+ if ( ! is_array( $addons ) ||
4464
+ ! isset( $addons[ $this->_plugin->id ] ) ||
4465
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
4466
+ 0 === count( $addons[ $this->_plugin->id ] )
4467
+ ) {
4468
+ return false;
4469
+ }
4470
+
4471
+ return $addons[ $this->_plugin->id ];
4472
+ }
4473
+
4474
+ /**
4475
+ * Check if user has any
4476
+ *
4477
+ * @author Vova Feldman (@svovaf)
4478
+ * @since 1.1.6
4479
+ *
4480
+ * @return bool
4481
+ */
4482
+ function has_account_addons() {
4483
+ $addons = $this->get_account_addons();
4484
+
4485
+ return is_array( $addons ) && ( 0 < count( $addons ) );
4486
+ }
4487
+
4488
+
4489
+ /**
4490
+ * Get add-on by ID (from local data).
4491
+ *
4492
+ * @author Vova Feldman (@svovaf)
4493
+ * @since 1.0.6
4494
+ *
4495
+ * @param number $id
4496
+ *
4497
+ * @return FS_Plugin|false
4498
+ */
4499
+ function get_addon( $id ) {
4500
+ $this->_logger->entrance();
4501
+
4502
+ $addons = $this->get_addons();
4503
+
4504
+ if ( is_array( $addons ) ) {
4505
+ foreach ( $addons as $addon ) {
4506
+ if ( $id == $addon->id ) {
4507
+ return $addon;
4508
+ }
4509
+ }
4510
+ }
4511
+
4512
+ return false;
4513
+ }
4514
+
4515
+ /**
4516
+ * Get add-on by slug (from local data).
4517
+ *
4518
+ * @author Vova Feldman (@svovaf)
4519
+ * @since 1.0.6
4520
+ *
4521
+ * @param string $slug
4522
+ *
4523
+ * @return FS_Plugin|false
4524
+ */
4525
+ function get_addon_by_slug( $slug ) {
4526
+ $this->_logger->entrance();
4527
+
4528
+ $addons = $this->get_addons();
4529
+
4530
+ if ( is_array( $addons ) ) {
4531
+ foreach ( $addons as $addon ) {
4532
+ if ( $slug == $addon->slug ) {
4533
+ return $addon;
4534
+ }
4535
+ }
4536
+ }
4537
+
4538
+ return false;
4539
+ }
4540
+
4541
+ #region Plans & Licensing ------------------------------------------------------------------
4542
+
4543
+ /**
4544
+ * Check if running premium plugin code.
4545
+ *
4546
+ * @author Vova Feldman (@svovaf)
4547
+ * @since 1.0.5
4548
+ *
4549
+ * @return bool
4550
+ */
4551
+ function is_premium() {
4552
+ return $this->_plugin->is_premium;
4553
+ }
4554
+
4555
+ /**
4556
+ * Get site's plan ID.
4557
+ *
4558
+ * @author Vova Feldman (@svovaf)
4559
+ * @since 1.0.2
4560
+ *
4561
+ * @return number
4562
+ */
4563
+ function get_plan_id() {
4564
+ return $this->_site->plan->id;
4565
+ }
4566
+
4567
+ /**
4568
+ * Get site's plan title.
4569
+ *
4570
+ * @author Vova Feldman (@svovaf)
4571
+ * @since 1.0.2
4572
+ *
4573
+ * @return string
4574
+ */
4575
+ function get_plan_title() {
4576
+ return $this->_site->plan->title;
4577
+ }
4578
+
4579
+ /**
4580
+ * @author Vova Feldman (@svovaf)
4581
+ * @since 1.0.9
4582
+ *
4583
+ * @return FS_Plugin_Plan
4584
+ */
4585
+ function get_plan() {
4586
+ return is_object( $this->_site->plan ) ? $this->_site->plan : false;
4587
+ }
4588
+
4589
+ /**
4590
+ * @author Vova Feldman (@svovaf)
4591
+ * @since 1.0.3
4592
+ *
4593
+ * @return bool
4594
+ */
4595
+ function is_trial() {
4596
+ $this->_logger->entrance();
4597
+
4598
+ if ( ! $this->is_registered() ) {
4599
+ return false;
4600
+ }
4601
+
4602
+ return $this->_site->is_trial();
4603
+ }
4604
+
4605
+ /**
4606
+ * Check if currently in a trial with payment method (credit card or paypal).
4607
+ *
4608
+ * @author Vova Feldman (@svovaf)
4609
+ * @since 1.1.7
4610
+ *
4611
+ * @return bool
4612
+ */
4613
+ function is_paid_trial() {
4614
+ $this->_logger->entrance();
4615
+
4616
+ if ( ! $this->is_trial() ) {
4617
+ return false;
4618
+ }
4619
+
4620
+ return $this->has_active_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
4621
+ }
4622
+
4623
+ /**
4624
+ * Check if trial already utilized.
4625
+ *
4626
+ * @since 1.0.9
4627
+ *
4628
+ * @return bool
4629
+ */
4630
+ function is_trial_utilized() {
4631
+ $this->_logger->entrance();
4632
+
4633
+ if ( ! $this->is_registered() ) {
4634
+ return false;
4635
+ }
4636
+
4637
+ return $this->_site->is_trial_utilized();
4638
+ }
4639
+
4640
+ /**
4641
+ * Get trial plan information (if in trial).
4642
+ *
4643
+ * @author Vova Feldman (@svovaf)
4644
+ * @since 1.0.9
4645
+ *
4646
+ * @return bool|FS_Plugin_Plan
4647
+ */
4648
+ function get_trial_plan() {
4649
+ $this->_logger->entrance();
4650
+
4651
+ if ( ! $this->is_trial() ) {
4652
+ return false;
4653
+ }
4654
+
4655
+ return $this->_storage->trial_plan;
4656
+ }
4657
+
4658
+ /**
4659
+ * Check if the user has an activated and valid paid license on current plugin's install.
4660
+ *
4661
+ * @since 1.0.9
4662
+ *
4663
+ * @return bool
4664
+ */
4665
+ function is_paying() {
4666
+ $this->_logger->entrance();
4667
+
4668
+ if ( ! $this->is_registered() ) {
4669
+ return false;
4670
+ }
4671
+
4672
+ if ( ! $this->has_paid_plan() ) {
4673
+ return false;
4674
+ }
4675
+
4676
+ return (
4677
+ ! $this->is_trial() &&
4678
+ 'free' !== $this->_site->plan->name &&
4679
+ $this->has_features_enabled_license()
4680
+ );
4681
+ }
4682
+
4683
+ /**
4684
+ * @author Vova Feldman (@svovaf)
4685
+ * @since 1.0.4
4686
+ *
4687
+ * @return bool
4688
+ */
4689
+ function is_free_plan() {
4690
+ if ( ! $this->is_registered() ) {
4691
+ return true;
4692
+ }
4693
+
4694
+ if ( ! $this->has_paid_plan() ) {
4695
+ return true;
4696
+ }
4697
+
4698
+ return (
4699
+ 'free' === $this->_site->plan->name ||
4700
+ ! $this->has_features_enabled_license()
4701
+ );
4702
+ }
4703
+
4704
+ /**
4705
+ * @author Vova Feldman (@svovaf)
4706
+ * @since 1.0.5
4707
+ *
4708
+ * @return bool
4709
+ */
4710
+ function _has_premium_license() {
4711
+ $this->_logger->entrance();
4712
+
4713
+ $premium_license = $this->_get_available_premium_license();
4714
+
4715
+ return ( false !== $premium_license );
4716
+ }
4717
+
4718
+ /**
4719
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
4720
+ *
4721
+ * @author Vova Feldman (@svovaf)
4722
+ * @since 1.1.7.3
4723
+ *
4724
+ * @return bool
4725
+ */
4726
+ private function has_any_license() {
4727
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
4728
+ }
4729
+
4730
+ /**
4731
+ * @author Vova Feldman (@svovaf)
4732
+ * @since 1.0.5
4733
+ *
4734
+ * @return FS_Plugin_License
4735
+ */
4736
+ function _get_available_premium_license() {
4737
+ $this->_logger->entrance();
4738
+
4739
+ if ( ! $this->has_paid_plan() ) {
4740
+ return false;
4741
+ }
4742
+
4743
+ if ( is_array( $this->_licenses ) ) {
4744
+ foreach ( $this->_licenses as $license ) {
4745
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
4746
+ return $license;
4747
+ }
4748
+ }
4749
+ }
4750
+
4751
+ return false;
4752
+ }
4753
+
4754
+ /**
4755
+ * Sync local plugin plans with remote server.
4756
+ *
4757
+ * @author Vova Feldman (@svovaf)
4758
+ * @since 1.0.5
4759
+ *
4760
+ * @return FS_Plugin_Plan[]|object
4761
+ */
4762
+ function _sync_plans() {
4763
+ $plans = $this->_fetch_plugin_plans();
4764
+ if ( ! $this->is_api_error( $plans ) ) {
4765
+ $this->_plans = $plans;
4766
+ $this->_store_plans();
4767
+ }
4768
+
4769
+ $this->do_action( 'after_plans_sync', $plans );
4770
+
4771
+ return $this->_plans;
4772
+ }
4773
+
4774
+ /**
4775
+ * @author Vova Feldman (@svovaf)
4776
+ * @since 1.0.5
4777
+ *
4778
+ * @param number $id
4779
+ *
4780
+ * @return FS_Plugin_Plan
4781
+ */
4782
+ function _get_plan_by_id( $id ) {
4783
+ $this->_logger->entrance();
4784
+
4785
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4786
+ $this->_sync_plans();
4787
+ }
4788
+
4789
+ foreach ( $this->_plans as $plan ) {
4790
+ if ( $id == $plan->id ) {
4791
+ return $plan;
4792
+ }
4793
+ }
4794
+
4795
+ return false;
4796
+ }
4797
+
4798
+ /**
4799
+ * @author Vova Feldman (@svovaf)
4800
+ * @since 1.1.8.1
4801
+ *
4802
+ * @param string $name
4803
+ *
4804
+ * @return FS_Plugin_Plan|false
4805
+ */
4806
+ private function get_plan_by_name( $name ) {
4807
+ $this->_logger->entrance();
4808
+
4809
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
4810
+ $this->_sync_plans();
4811
+ }
4812
+
4813
+ foreach ( $this->_plans as $plan ) {
4814
+ if ( $name == $plan->name ) {
4815
+ return $plan;
4816
+ }
4817
+ }
4818
+
4819
+ return false;
4820
+ }
4821
+
4822
+ /**
4823
+ * Sync local plugin plans with remote server.
4824
+ *
4825
+ * @author Vova Feldman (@svovaf)
4826
+ * @since 1.0.6
4827
+ *
4828
+ * @return FS_Plugin_License[]|object
4829
+ */
4830
+ function _sync_licenses() {
4831
+ $licenses = $this->_fetch_licenses();
4832
+ if ( ! $this->is_api_error( $licenses ) ) {
4833
+ $this->_licenses = $licenses;
4834
+ $this->_store_licenses();
4835
+ }
4836
+
4837
+ // Update current license.
4838
+ if ( is_object( $this->_license ) ) {
4839
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
4840
+ }
4841
+
4842
+ return $this->_licenses;
4843
+ }
4844
+
4845
+ /**
4846
+ * @author Vova Feldman (@svovaf)
4847
+ * @since 1.0.5
4848
+ *
4849
+ * @param number $id
4850
+ *
4851
+ * @return FS_Plugin_License
4852
+ */
4853
+ function _get_license_by_id( $id ) {
4854
+ $this->_logger->entrance();
4855
+
4856
+ if ( ! is_numeric( $id ) ) {
4857
+ return false;
4858
+ }
4859
+
4860
+ if ( ! is_array( $this->_licenses ) || 0 === count( $this->_licenses ) ) {
4861
+ $this->_sync_licenses();
4862
+ }
4863
+
4864
+ foreach ( $this->_licenses as $license ) {
4865
+ if ( $id == $license->id ) {
4866
+ return $license;
4867
+ }
4868
+ }
4869
+
4870
+ return false;
4871
+ }
4872
+
4873
+ /**
4874
+ * Sync site's license with user licenses.
4875
+ *
4876
+ * @author Vova Feldman (@svovaf)
4877
+ * @since 1.0.6
4878
+ *
4879
+ * @param FS_Plugin_License|null $new_license
4880
+ */
4881
+ function _update_site_license( $new_license ) {
4882
+ $this->_logger->entrance();
4883
+
4884
+ $this->_license = $new_license;
4885
+
4886
+ if ( ! is_object( $new_license ) ) {
4887
+ $this->_site->license_id = null;
4888
+ $this->_sync_site_subscription( null );
4889
+
4890
+ return;
4891
+ }
4892
+
4893
+ $this->_site->license_id = $this->_license->id;
4894
+
4895
+ if ( ! is_array( $this->_licenses ) ) {
4896
+ $this->_licenses = array();
4897
+ }
4898
+
4899
+ $is_license_found = false;
4900
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
4901
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
4902
+ $this->_licenses[ $i ] = $new_license;
4903
+
4904
+ $is_license_found = true;
4905
+ break;
4906
+ }
4907
+ }
4908
+
4909
+ // If new license just append.
4910
+ if ( ! $is_license_found ) {
4911
+ $this->_licenses[] = $new_license;
4912
+ }
4913
+
4914
+ $this->_sync_site_subscription( $new_license );
4915
+ }
4916
+
4917
+ /**
4918
+ * Sync site's subscription.
4919
+ *
4920
+ * @author Vova Feldman (@svovaf)
4921
+ * @since 1.0.9
4922
+ *
4923
+ * @param FS_Plugin_License|null $license
4924
+ *
4925
+ * @return bool|\FS_Subscription
4926
+ */
4927
+ private function _sync_site_subscription( $license ) {
4928
+ if ( ! is_object( $license ) ) {
4929
+ unset( $this->_storage->subscription );
4930
+
4931
+ return false;
4932
+ }
4933
+
4934
+ // Load subscription details if not lifetime.
4935
+ $subscription = $license->is_lifetime() ?
4936
+ false :
4937
+ $this->_fetch_site_license_subscription();
4938
+
4939
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
4940
+ $this->_storage->subscription = $subscription;
4941
+ } else {
4942
+ unset( $this->_storage->subscription );
4943
+ }
4944
+
4945
+ return $subscription;
4946
+ }
4947
+
4948
+ /**
4949
+ * @author Vova Feldman (@svovaf)
4950
+ * @since 1.0.6
4951
+ *
4952
+ * @return bool|\FS_Plugin_License
4953
+ */
4954
+ function _get_license() {
4955
+ return $this->_license;
4956
+ }
4957
+
4958
+ /**
4959
+ * @return bool|\FS_Subscription
4960
+ */
4961
+ function _get_subscription() {
4962
+ return isset( $this->_storage->subscription ) ?
4963
+ $this->_storage->subscription :
4964
+ false;
4965
+ }
4966
+
4967
+ /**
4968
+ * @author Vova Feldman (@svovaf)
4969
+ * @since 1.0.2
4970
+ *
4971
+ * @param string $plan Plan name
4972
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
4973
+ *
4974
+ * @return bool
4975
+ */
4976
+ function is_plan( $plan, $exact = false ) {
4977
+ $this->_logger->entrance();
4978
+
4979
+ if ( ! $this->is_registered() ) {
4980
+ return false;
4981
+ }
4982
+
4983
+ $plan = strtolower( $plan );
4984
+
4985
+ if ( $this->_site->plan->name === $plan ) // Exact plan.
4986
+ {
4987
+ return true;
4988
+ } else if ( $exact ) // Required exact, but plans are different.
4989
+ {
4990
+ return false;
4991
+ }
4992
+
4993
+ $current_plan_order = - 1;
4994
+ $required_plan_order = - 1;
4995
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
4996
+ if ( $plan === $this->_plans[ $i ]->name ) {
4997
+ $required_plan_order = $i;
4998
+ } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
4999
+ $current_plan_order = $i;
5000
+ }
5001
+ }
5002
+
5003
+ return ( $current_plan_order > $required_plan_order );
5004
+ }
5005
+
5006
+ /**
5007
+ * Check if plan based on trial. If not in trial mode, should return false.
5008
+ *
5009
+ * @since 1.0.9
5010
+ *
5011
+ * @param string $plan Plan name
5012
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
5013
+ *
5014
+ * @return bool
5015
+ */
5016
+ function is_trial_plan( $plan, $exact = false ) {
5017
+ $this->_logger->entrance();
5018
+
5019
+ if ( ! $this->is_registered() ) {
5020
+ return false;
5021
+ }
5022
+
5023
+ if ( ! $this->is_trial() ) {
5024
+ return false;
5025
+ }
5026
+
5027
+ if ( ! isset( $this->_storage->trial_plan ) ) {
5028
+ // Store trial plan information.
5029
+ $this->_enrich_site_trial_plan( true );
5030
+ }
5031
+
5032
+ if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
5033
+ {
5034
+ return true;
5035
+ } else if ( $exact ) // Required exact, but plans are different.
5036
+ {
5037
+ return false;
5038
+ }
5039
+
5040
+ $current_plan_order = - 1;
5041
+ $required_plan_order = - 1;
5042
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5043
+ if ( $plan === $this->_plans[ $i ]->name ) {
5044
+ $required_plan_order = $i;
5045
+ } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
5046
+ $current_plan_order = $i;
5047
+ }
5048
+ }
5049
+
5050
+ return ( $current_plan_order > $required_plan_order );
5051
+ }
5052
+
5053
+ /**
5054
+ * Check if plugin has any paid plans.
5055
+ *
5056
+ * @author Vova Feldman (@svovaf)
5057
+ * @since 1.0.7
5058
+ *
5059
+ * @return bool
5060
+ */
5061
+ function has_paid_plan() {
5062
+ return $this->_has_paid_plans || FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
5063
+ }
5064
+
5065
+ /**
5066
+ * Check if plugin has any plan with a trail.
5067
+ *
5068
+ * @author Vova Feldman (@svovaf)
5069
+ * @since 1.0.9
5070
+ *
5071
+ * @return bool
5072
+ */
5073
+ function has_trial_plan() {
5074
+ if ( ! $this->is_registered() ) {
5075
+ return false;
5076
+ }
5077
+
5078
+ return $this->_storage->get( 'has_trial_plan', false );
5079
+ }
5080
+
5081
+ /**
5082
+ * Check if plugin has any free plan, or is it premium only.
5083
+ *
5084
+ * Note: If no plans configured, assume plugin is free.
5085
+ *
5086
+ * @author Vova Feldman (@svovaf)
5087
+ * @since 1.0.7
5088
+ *
5089
+ * @return bool
5090
+ */
5091
+ function has_free_plan() {
5092
+ return ! $this->is_only_premium() && FS_Plan_Manager::instance()->has_free_plan( $this->_plans );
5093
+ }
5094
+
5095
+ /**
5096
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
5097
+ * or "Change License" link on the plugins
5098
+ * page.
5099
+ *
5100
+ * @author Leo Fajardo (@leorw)
5101
+ * @since 1.1.9
5102
+ */
5103
+ function _add_license_activation_dialog_box() {
5104
+ fs_enqueue_local_style( 'fs_license_action', '/admin/license-activation.css' );
5105
+
5106
+ $vars = array(
5107
+ 'slug' => $this->_slug
5108
+ );
5109
+
5110
+ fs_require_template( 'license-activation-modal.php', $vars );
5111
+ }
5112
+
5113
+ /**
5114
+ * @author Leo Fajardo (@leorw)
5115
+ * @since 1.1.9
5116
+ */
5117
+ function _activate_license_ajax_action() {
5118
+ if ( ! isset( $_POST['license-key'] ) ) {
5119
+ exit;
5120
+ }
5121
+
5122
+ $license_key = trim( $_POST['license-key'] );
5123
+ if ( empty( $license_key ) ) {
5124
+ exit;
5125
+ }
5126
+
5127
+ if ( $this->is_registered() ) {
5128
+ $api = $this->get_api_site_scope();
5129
+ $api->call( '/', 'put',
5130
+ array(
5131
+ 'license_key' => $license_key
5132
+ )
5133
+ );
5134
+ } else {
5135
+ $this->opt_in( false, false, false, $license_key );
5136
+ }
5137
+
5138
+ // Print '1' for successful operation.
5139
+ echo 1;
5140
+ exit;
5141
+ }
5142
+
5143
+ #region URL Generators
5144
+
5145
+ /**
5146
+ * Alias to pricing_url().
5147
+ *
5148
+ * @author Vova Feldman (@svovaf)
5149
+ * @since 1.0.2
5150
+ *
5151
+ * @uses pricing_url()
5152
+ *
5153
+ * @param string $period Billing cycle
5154
+ * @param bool $is_trial
5155
+ *
5156
+ * @return string
5157
+ */
5158
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
5159
+ return $this->pricing_url( $period, $is_trial );
5160
+ }
5161
+
5162
+ /**
5163
+ * @author Vova Feldman (@svovaf)
5164
+ * @since 1.0.9
5165
+ *
5166
+ * @uses get_upgrade_url()
5167
+ *
5168
+ * @return string
5169
+ */
5170
+ function get_trial_url() {
5171
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
5172
+ }
5173
+
5174
+ /**
5175
+ * Plugin's pricing URL.
5176
+ *
5177
+ * @author Vova Feldman (@svovaf)
5178
+ * @since 1.0.4
5179
+ *
5180
+ * @param string $billing_cycle Billing cycle
5181
+ *
5182
+ * @param bool $is_trial
5183
+ *
5184
+ * @return string
5185
+ */
5186
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
5187
+ $this->_logger->entrance();
5188
+
5189
+ $params = array(
5190
+ 'billing_cycle' => $billing_cycle
5191
+ );
5192
+
5193
+ if ( $is_trial ) {
5194
+ $params['trial'] = 'true';
5195
+ }
5196
+
5197
+ return $this->_get_admin_page_url( 'pricing', $params );
5198
+ }
5199
+
5200
+ /**
5201
+ * Checkout page URL.
5202
+ *
5203
+ * @author Vova Feldman (@svovaf)
5204
+ * @since 1.0.6
5205
+ *
5206
+ * @param string $billing_cycle Billing cycle
5207
+ * @param bool $is_trial
5208
+ * @param array $extra (optional) Extra parameters, override other query params.
5209
+ *
5210
+ * @return string
5211
+ */
5212
+ function checkout_url(
5213
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5214
+ $is_trial = false,
5215
+ $extra = array()
5216
+ ) {
5217
+ $this->_logger->entrance();
5218
+
5219
+ $params = array(
5220
+ 'checkout' => 'true',
5221
+ 'billing_cycle' => $billing_cycle,
5222
+ );
5223
+
5224
+ if ( $is_trial ) {
5225
+ $params['trial'] = 'true';
5226
+ }
5227
+
5228
+ /**
5229
+ * Params in extra override other params.
5230
+ */
5231
+ $params = array_merge( $params, $extra );
5232
+
5233
+ return $this->_get_admin_page_url( 'pricing', $params );
5234
+ }
5235
+
5236
+ /**
5237
+ * Add-on checkout URL.
5238
+ *
5239
+ * @author Vova Feldman (@svovaf)
5240
+ * @since 1.1.7
5241
+ *
5242
+ * @param number $addon_id
5243
+ * @param number $pricing_id
5244
+ * @param string $billing_cycle
5245
+ * @param bool $is_trial
5246
+ *
5247
+ * @return string
5248
+ */
5249
+ function addon_checkout_url(
5250
+ $addon_id,
5251
+ $pricing_id,
5252
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5253
+ $is_trial = false
5254
+ ) {
5255
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
5256
+ 'plugin_id' => $addon_id,
5257
+ 'pricing_id' => $pricing_id,
5258
+ ) );
5259
+ }
5260
+
5261
+ #endregion
5262
+
5263
+ #endregion ------------------------------------------------------------------
5264
+
5265
+ /**
5266
+ * Check if plugin has any add-ons.
5267
+ *
5268
+ * @author Vova Feldman (@svovaf)
5269
+ * @since 1.0.5
5270
+ *
5271
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
5272
+ *
5273
+ * @return bool
5274
+ */
5275
+ function has_addons() {
5276
+ $this->_logger->entrance();
5277
+
5278
+ return $this->_has_addons;
5279
+ }
5280
+
5281
+ /**
5282
+ * Check if plugin can work in anonymous mode.
5283
+ *
5284
+ * @author Vova Feldman (@svovaf)
5285
+ * @since 1.0.9
5286
+ *
5287
+ * @return bool
5288
+ *
5289
+ * @deprecated Please use is_enable_anonymous() instead
5290
+ */
5291
+ function enable_anonymous() {
5292
+ return $this->_enable_anonymous;
5293
+ }
5294
+
5295
+ /**
5296
+ * Check if plugin can work in anonymous mode.
5297
+ *
5298
+ * @author Vova Feldman (@svovaf)
5299
+ * @since 1.1.9
5300
+ *
5301
+ * @return bool
5302
+ */
5303
+ function is_enable_anonymous() {
5304
+ return $this->_enable_anonymous;
5305
+ }
5306
+
5307
+ /**
5308
+ * Check if plugin is premium only (no free plans).
5309
+ *
5310
+ * @author Vova Feldman (@svovaf)
5311
+ * @since 1.1.9
5312
+ *
5313
+ * @return bool
5314
+ */
5315
+ function is_only_premium() {
5316
+ return $this->_is_premium_only;
5317
+ }
5318
+
5319
+ /**
5320
+ * Check if feature supported with current site's plan.
5321
+ *
5322
+ * @author Vova Feldman (@svovaf)
5323
+ * @since 1.0.1
5324
+ *
5325
+ * @todo IMPLEMENT
5326
+ *
5327
+ * @param number $feature_id
5328
+ *
5329
+ * @throws Exception
5330
+ */
5331
+ function is_feature_supported( $feature_id ) {
5332
+ throw new Exception( 'not implemented' );
5333
+ }
5334
+
5335
+ /**
5336
+ * @author Vova Feldman (@svovaf)
5337
+ * @since 1.0.1
5338
+ *
5339
+ * @return bool Is running in SSL/HTTPS
5340
+ */
5341
+ function is_ssl() {
5342
+ return WP_FS__IS_HTTPS;
5343
+ }
5344
+
5345
+ /**
5346
+ * @author Vova Feldman (@svovaf)
5347
+ * @since 1.0.9
5348
+ *
5349
+ * @return bool Is running in AJAX call.
5350
+ *
5351
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
5352
+ */
5353
+ function is_ajax() {
5354
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
5355
+ }
5356
+
5357
+ /**
5358
+ * @author Vova Feldman (@svovaf)
5359
+ * @since 1.1.7
5360
+ *
5361
+ * @return bool
5362
+ */
5363
+ function is_cron() {
5364
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
5365
+ }
5366
+
5367
+ /**
5368
+ * Check if a real user is visiting the admin dashboard.
5369
+ *
5370
+ * @author Vova Feldman (@svovaf)
5371
+ * @since 1.1.7
5372
+ *
5373
+ * @return bool
5374
+ */
5375
+ function is_user_in_admin() {
5376
+ return is_admin() && ! $this->is_ajax() && ! $this->is_cron();
5377
+ }
5378
+
5379
+ /**
5380
+ * Check if running in HTTPS and if site's plan matching the specified plan.
5381
+ *
5382
+ * @param string $plan
5383
+ * @param bool $exact
5384
+ *
5385
+ * @return bool
5386
+ */
5387
+ function is_ssl_and_plan( $plan, $exact = false ) {
5388
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
5389
+ }
5390
+
5391
+ /**
5392
+ * Construct plugin's settings page URL.
5393
+ *
5394
+ * @author Vova Feldman (@svovaf)
5395
+ * @since 1.0.4
5396
+ *
5397
+ * @param string $page
5398
+ * @param array $params
5399
+ *
5400
+ * @return string
5401
+ */
5402
+ function _get_admin_page_url( $page = '', $params = array() ) {
5403
+ if ( ! $this->_menu->is_top_level() ) {
5404
+ $parent_slug = $this->_menu->get_parent_slug();
5405
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
5406
+ $parent_slug :
5407
+ 'admin.php';
5408
+
5409
+ return add_query_arg( array_merge( $params, array(
5410
+ 'page' => $this->_menu->get_slug( $page ),
5411
+ ) ), admin_url( $menu_file, 'admin' ) );
5412
+ }
5413
+
5414
+ if ( $this->_menu->is_cpt() ) {
5415
+ if ( empty( $page ) && $this->is_activation_mode() ) {
5416
+ return add_query_arg( array_merge( $params, array(
5417
+ 'page' => $this->_menu->get_slug()
5418
+ ) ), admin_url( 'admin.php', 'admin' ) );
5419
+ } else {
5420
+ if ( ! empty( $page ) ) {
5421
+ $params['page'] = $this->_menu->get_slug( $page );
5422
+ }
5423
+
5424
+ return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
5425
+ }
5426
+ } else {
5427
+ return add_query_arg( array_merge( $params, array(
5428
+ 'page' => $this->_menu->get_slug( $page ),
5429
+ ) ), admin_url( 'admin.php', 'admin' ) );
5430
+ }
5431
+ }
5432
+
5433
+
5434
+ /**
5435
+ * Plugin's account URL.
5436
+ *
5437
+ * @author Vova Feldman (@svovaf)
5438
+ * @since 1.0.4
5439
+ *
5440
+ * @param bool|string $action
5441
+ * @param array $params
5442
+ *
5443
+ * @param bool $add_action_nonce
5444
+ *
5445
+ * @return string
5446
+ */
5447
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
5448
+ if ( is_string( $action ) ) {
5449
+ $params['fs_action'] = $action;
5450
+ }
5451
+
5452
+ self::require_pluggable_essentials();
5453
+
5454
+ return ( $add_action_nonce && is_string( $action ) ) ?
5455
+ wp_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
5456
+ $this->_get_admin_page_url( 'account', $params );
5457
+ }
5458
+
5459
+ /**
5460
+ * Plugin's account URL.
5461
+ *
5462
+ * @author Vova Feldman (@svovaf)
5463
+ * @since 1.0.4
5464
+ *
5465
+ * @param bool|string $topic
5466
+ * @param bool|string $message
5467
+ *
5468
+ * @return string
5469
+ */
5470
+ function contact_url( $topic = false, $message = false ) {
5471
+ $params = array();
5472
+ if ( is_string( $topic ) ) {
5473
+ $params['topic'] = $topic;
5474
+ }
5475
+ if ( is_string( $message ) ) {
5476
+ $params['message'] = $message;
5477
+ }
5478
+
5479
+ if ( $this->is_addon() ) {
5480
+ $params['addon_id'] = $this->get_id();
5481
+
5482
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
5483
+ } else {
5484
+ return $this->_get_admin_page_url( 'contact', $params );
5485
+ }
5486
+ }
5487
+
5488
+ /**
5489
+ * Add-on direct info URL.
5490
+ *
5491
+ * @author Vova Feldman (@svovaf)
5492
+ * @since 1.1.0
5493
+ *
5494
+ * @param string $slug
5495
+ *
5496
+ * @return string
5497
+ */
5498
+ function addon_url( $slug ) {
5499
+ return $this->_get_admin_page_url( 'addons', array(
5500
+ 'slug' => $slug
5501
+ ) );
5502
+ }
5503
+
5504
+ /* Logger
5505
+ ------------------------------------------------------------------------------------------------------------------*/
5506
+ /**
5507
+ * @param string $id
5508
+ * @param bool $prefix_slug
5509
+ *
5510
+ * @return FS_Logger
5511
+ */
5512
+ function get_logger( $id = '', $prefix_slug = true ) {
5513
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
5514
+ }
5515
+
5516
+ /**
5517
+ * @param $id
5518
+ * @param bool $load_options
5519
+ * @param bool $prefix_slug
5520
+ *
5521
+ * @return FS_Option_Manager
5522
+ */
5523
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
5524
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
5525
+ }
5526
+
5527
+ /* Security
5528
+ ------------------------------------------------------------------------------------------------------------------*/
5529
+ private function _encrypt( $str ) {
5530
+ if ( is_null( $str ) ) {
5531
+ return null;
5532
+ }
5533
+
5534
+ return base64_encode( $str );
5535
+ }
5536
+
5537
+ private function _decrypt( $str ) {
5538
+ if ( is_null( $str ) ) {
5539
+ return null;
5540
+ }
5541
+
5542
+ return base64_decode( $str );
5543
+ }
5544
+
5545
+ /**
5546
+ * @author Vova Feldman (@svovaf)
5547
+ * @since 1.0.5
5548
+ *
5549
+ * @param FS_Entity $entity
5550
+ *
5551
+ * @return FS_Entity Return an encrypted clone entity.
5552
+ */
5553
+ private function _encrypt_entity( FS_Entity $entity ) {
5554
+ $clone = clone $entity;
5555
+ $props = get_object_vars( $entity );
5556
+
5557
+ foreach ( $props as $key => $val ) {
5558
+ $clone->{$key} = $this->_encrypt( $val );
5559
+ }
5560
+
5561
+ return $clone;
5562
+ }
5563
+
5564
+ /**
5565
+ * @author Vova Feldman (@svovaf)
5566
+ * @since 1.0.5
5567
+ *
5568
+ * @param FS_Entity $entity
5569
+ *
5570
+ * @return FS_Entity Return an decrypted clone entity.
5571
+ */
5572
+ private function _decrypt_entity( FS_Entity $entity ) {
5573
+ $clone = clone $entity;
5574
+ $props = get_object_vars( $entity );
5575
+
5576
+ foreach ( $props as $key => $val ) {
5577
+ $clone->{$key} = $this->_decrypt( $val );
5578
+ }
5579
+
5580
+ return $clone;
5581
+ }
5582
+
5583
+ /**
5584
+ * Tries to activate account based on POST params.
5585
+ *
5586
+ * @author Vova Feldman (@svovaf)
5587
+ * @since 1.0.2
5588
+ */
5589
+ function _activate_account() {
5590
+ if ( $this->is_registered() ) {
5591
+ // Already activated.
5592
+ return;
5593
+ }
5594
+
5595
+ self::_clean_admin_content_section();
5596
+
5597
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
5598
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
5599
+
5600
+ // Verify matching plugin details.
5601
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
5602
+ return;
5603
+ }
5604
+
5605
+ $user = new FS_User();
5606
+ $user->id = fs_request_get( 'user_id' );
5607
+ $user->public_key = fs_request_get( 'user_public_key' );
5608
+ $user->secret_key = fs_request_get( 'user_secret_key' );
5609
+ $user->email = fs_request_get( 'user_email' );
5610
+ $user->first = fs_request_get( 'user_first' );
5611
+ $user->last = fs_request_get( 'user_last' );
5612
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
5613
+
5614
+ $site = new FS_Site();
5615
+ $site->id = fs_request_get( 'install_id' );
5616
+ $site->public_key = fs_request_get( 'install_public_key' );
5617
+ $site->secret_key = fs_request_get( 'install_secret_key' );
5618
+ $site->plan->id = fs_request_get( 'plan_id' );
5619
+ $site->plan->title = fs_request_get( 'plan_title' );
5620
+ $site->plan->name = fs_request_get( 'plan_name' );
5621
+
5622
+ $plans = array();
5623
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
5624
+ foreach ( $plans_data as $p ) {
5625
+ $plans[] = new FS_Plugin_Plan( $p );
5626
+ }
5627
+
5628
+ $this->_set_account( $user, $site, $plans );
5629
+
5630
+ // Reload the page with the keys.
5631
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
5632
+ exit();
5633
+ }
5634
+ }
5635
+ }
5636
+
5637
+ /**
5638
+ * @author Vova Feldman (@svovaf)
5639
+ * @since 1.0.7
5640
+ *
5641
+ * @param string $email
5642
+ *
5643
+ * @return FS_User|bool
5644
+ */
5645
+ static function _get_user_by_email( $email ) {
5646
+ self::$_static_logger->entrance();
5647
+
5648
+ $email = trim( strtolower( $email ) );
5649
+ $users = self::get_all_users();
5650
+ if ( is_array( $users ) ) {
5651
+ foreach ( $users as $u ) {
5652
+ if ( $email === trim( strtolower( $u->email ) ) ) {
5653
+ return $u;
5654
+ }
5655
+ }
5656
+ }
5657
+
5658
+ return false;
5659
+ }
5660
+
5661
+ #region Account (Loading, Updates & Activation) ------------------------------------------------------------------
5662
+
5663
+ /***
5664
+ * Load account information (user + site).
5665
+ *
5666
+ * @author Vova Feldman (@svovaf)
5667
+ * @since 1.0.1
5668
+ */
5669
+ private function _load_account() {
5670
+ $this->_logger->entrance();
5671
+
5672
+ $this->do_action( 'before_account_load' );
5673
+
5674
+ $sites = self::get_all_sites();
5675
+ $users = self::get_all_users();
5676
+ $plans = self::get_all_plans();
5677
+ $licenses = self::get_all_licenses();
5678
+
5679
+ if ( $this->_logger->is_on() && is_admin() ) {
5680
+ $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
5681
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
5682
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
5683
+ $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
5684
+ }
5685
+
5686
+ $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
5687
+
5688
+ if ( is_object( $site ) &&
5689
+ is_numeric( $site->id ) &&
5690
+ is_numeric( $site->user_id ) &&
5691
+ is_object( $site->plan )
5692
+ ) {
5693
+ // Load site.
5694
+ $this->_site = clone $site;
5695
+ $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
5696
+
5697
+ // Load relevant user.
5698
+ $this->_user = clone $users[ $this->_site->user_id ];
5699
+
5700
+ // Load plans.
5701
+ $this->_plans = $plans[ $this->_slug ];
5702
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
5703
+ $this->_sync_plans( true );
5704
+ } else {
5705
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5706
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
5707
+ $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
5708
+ } else {
5709
+ unset( $this->_plans[ $i ] );
5710
+ }
5711
+ }
5712
+ }
5713
+
5714
+ // Load licenses.
5715
+ $this->_licenses = array();
5716
+ if ( is_array( $licenses ) &&
5717
+ isset( $licenses[ $this->_slug ] ) &&
5718
+ isset( $licenses[ $this->_slug ][ $this->_user->id ] )
5719
+ ) {
5720
+ $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
5721
+ }
5722
+
5723
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
5724
+
5725
+ if ( $this->_site->version != $this->get_plugin_version() ) {
5726
+ // If stored install version is different than current installed plugin version,
5727
+ // then update plugin version event.
5728
+ $this->update_plugin_version_event();
5729
+ }
5730
+ }
5731
+
5732
+ $this->_register_account_hooks();
5733
+ }
5734
+
5735
+ /**
5736
+ * @author Vova Feldman (@svovaf)
5737
+ * @since 1.0.1
5738
+ *
5739
+ * @param FS_User $user
5740
+ * @param FS_Site $site
5741
+ * @param bool|array $plans
5742
+ */
5743
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
5744
+ $site->slug = $this->_slug;
5745
+ $site->user_id = $user->id;
5746
+
5747
+ $this->_site = $site;
5748
+ $this->_user = $user;
5749
+ if ( false !== $plans ) {
5750
+ $this->_plans = $plans;
5751
+ }
5752
+
5753
+ $this->send_install_update();
5754
+
5755
+ $this->_store_account();
5756
+
5757
+ }
5758
+
5759
+ /**
5760
+ * @author Vova Feldman (@svovaf)
5761
+ * @since 1.1.7.4
5762
+ *
5763
+ * @param array $override_with
5764
+ *
5765
+ * @return array
5766
+ */
5767
+ function get_opt_in_params( $override_with = array() ) {
5768
+ $this->_logger->entrance();
5769
+
5770
+ $current_user = self::_get_current_wp_user();
5771
+
5772
+ $params = array(
5773
+ 'user_firstname' => $current_user->user_firstname,
5774
+ 'user_lastname' => $current_user->user_lastname,
5775
+ 'user_nickname' => $current_user->user_nicename,
5776
+ 'user_email' => $current_user->user_email,
5777
+ 'user_ip' => WP_FS__REMOTE_ADDR,
5778
+ 'plugin_slug' => $this->_slug,
5779
+ 'plugin_id' => $this->get_id(),
5780
+ 'plugin_public_key' => $this->get_public_key(),
5781
+ 'plugin_version' => $this->get_plugin_version(),
5782
+ 'return_url' => wp_nonce_url( $this->_get_admin_page_url(
5783
+ '',
5784
+ array( 'fs_action' => $this->_slug . '_activate_new' )
5785
+ ), $this->_slug . '_activate_new' ),
5786
+ 'account_url' => wp_nonce_url( $this->_get_admin_page_url(
5787
+ 'account',
5788
+ array( 'fs_action' => 'sync_user' )
5789
+ ), 'sync_user' ),
5790
+ 'site_uid' => $this->get_anonymous_id(),
5791
+ 'site_url' => get_site_url(),
5792
+ 'site_name' => get_bloginfo( 'name' ),
5793
+ 'platform_version' => get_bloginfo( 'version' ),
5794
+ 'php_version' => phpversion(),
5795
+ 'language' => get_bloginfo( 'language' ),
5796
+ 'charset' => get_bloginfo( 'charset' ),
5797
+ );
5798
+
5799
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
5800
+ // Even though rand() is known for its security issues,
5801
+ // the timestamp adds another layer of protection.
5802
+ // It would be very hard for an attacker to get the secret key form here.
5803
+ // Plus, this should never run in production since the secret should never
5804
+ // be included in the production version.
5805
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
5806
+ $params['salt'] = md5( uniqid( rand() ) );
5807
+ $params['secure'] = md5(
5808
+ $params['ts'] .
5809
+ $params['salt'] .
5810
+ $this->get_secret_key()
5811
+ );
5812
+ }
5813
+
5814
+ return array_merge( $params, $override_with );
5815
+ }
5816
+
5817
+ /**
5818
+ * @author Vova Feldman (@svovaf)
5819
+ * @since 1.1.7.4
5820
+ *
5821
+ * @param string|bool $email
5822
+ * @param string|bool $first
5823
+ * @param string|bool $last
5824
+ * @param string|bool $license_key
5825
+ *
5826
+ * @return bool Is successful opt-in (or set to pending).
5827
+ */
5828
+ function opt_in( $email = false, $first = false, $last = false, $license_secret_key = false ) {
5829
+ $this->_logger->entrance();
5830
+
5831
+ if ( false === $email ) {
5832
+ $current_user = self::_get_current_wp_user();
5833
+ $email = $current_user->user_email;
5834
+ }
5835
+
5836
+ $fs_user = Freemius::_get_user_by_email( $email );
5837
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
5838
+ $this->install_with_current_user( false );
5839
+
5840
+ return true;
5841
+ }
5842
+
5843
+ $user_info = array();
5844
+ if ( ! empty( $email ) ) {
5845
+ $user_info['user_email'] = $email;
5846
+ }
5847
+ if ( ! empty( $first ) ) {
5848
+ $user_info['user_firstname'] = $first;
5849
+ }
5850
+ if ( ! empty( $last ) ) {
5851
+ $user_info['user_lastname'] = $last;
5852
+ }
5853
+
5854
+ $params = $this->get_opt_in_params( $user_info );
5855
+
5856
+ if ( is_string( $license_secret_key ) ) {
5857
+ $params['license_secret_key'] = $license_secret_key;
5858
+ }
5859
+
5860
+ $params['format'] = 'json';
5861
+
5862
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
5863
+ if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
5864
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
5865
+ }
5866
+
5867
+ $response = wp_remote_post( $url, array(
5868
+ 'method' => 'POST',
5869
+ 'body' => $params,
5870
+ 'timeout' => 15,
5871
+ ) );
5872
+
5873
+ if ( $response instanceof WP_Error ) {
5874
+ if ( 'https://' === substr( $url, 0, 8 ) &&
5875
+ isset( $response->errors ) &&
5876
+ isset( $response->errors['http_request_failed'] ) &&
5877
+ false !== strpos( $response->errors['http_request_failed'][0], 'sslv3 alert handshake' )
5878
+ ) {
5879
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
5880
+ $url = 'http://' . substr( $url, 8 );
5881
+
5882
+ $response = wp_remote_post( $url, array(
5883
+ 'method' => 'POST',
5884
+ 'body' => $params,
5885
+ 'timeout' => 15,
5886
+ ) );
5887
+ }
5888
+
5889
+ if ( $response instanceof WP_Error ) {
5890
+ return false;
5891
+ }
5892
+ }
5893
+
5894
+ if ( is_wp_error( $response ) ) {
5895
+ return false;
5896
+ }
5897
+
5898
+ $decoded = @json_decode( $response['body'] );
5899
+
5900
+ if ( empty( $decoded ) ) {
5901
+ return false;
5902
+ }
5903
+
5904
+ if ( isset( $decoded->error ) ) {
5905
+ return false;
5906
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
5907
+ // Pending activation, add message.
5908
+ $this->set_pending_confirmation( false, false );
5909
+
5910
+ return true;
5911
+ } else if ( isset( $decoded->install_secret_key ) ) {
5912
+ $this->install_with_new_user(
5913
+ $decoded->user_id,
5914
+ $decoded->user_public_key,
5915
+ $decoded->user_secret_key,
5916
+ $decoded->install_id,
5917
+ $decoded->install_public_key,
5918
+ $decoded->install_secret_key,
5919
+ false
5920
+ );
5921
+
5922
+ return true;
5923
+ }
5924
+
5925
+ return false;
5926
+ }
5927
+
5928
+ /**
5929
+ * Set user and site identities.
5930
+ *
5931
+ * @author Vova Feldman (@svovaf)
5932
+ * @since 1.0.9
5933
+ *
5934
+ * @param FS_User $user
5935
+ * @param FS_Site $site
5936
+ * @param bool $redirect
5937
+ *
5938
+ * @return bool False if account already set.
5939
+ */
5940
+ function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
5941
+ $this->_user = $user;
5942
+ $this->_site = $site;
5943
+
5944
+ $this->_sync_plans();
5945
+
5946
+ $this->_enrich_site_plan( false );
5947
+
5948
+ $this->_set_account( $user, $site );
5949
+
5950
+ if ( $this->is_trial() ) {
5951
+ // Store trial plan information.
5952
+ $this->_enrich_site_trial_plan( true );
5953
+ }
5954
+
5955
+ // If Freemius was OFF before, turn it on.
5956
+ $this->turn_on();
5957
+
5958
+ $this->do_action( 'after_account_connection', $user, $site );
5959
+
5960
+ if ( is_numeric( $site->license_id ) ) {
5961
+ $this->_license = $this->_get_license_by_id( $site->license_id );
5962
+ }
5963
+
5964
+ if ( $this->is_pending_activation() ) {
5965
+ // Remove pending activation sticky notice (if still exist).
5966
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
5967
+
5968
+ // Remove plugin from pending activation mode.
5969
+ unset( $this->_storage->is_pending_activation );
5970
+
5971
+ if ( ! $this->is_paying() ) {
5972
+ $this->_admin_notices->add_sticky(
5973
+ sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
5974
+ 'activation_complete'
5975
+ );
5976
+ }
5977
+ }
5978
+
5979
+ if ( $this->is_paying() && ! $this->is_premium() ) {
5980
+ $this->_admin_notices->add_sticky(
5981
+ sprintf(
5982
+ __fs( 'activation-with-plan-x-message', $this->_slug ),
5983
+ $this->_site->plan->title
5984
+ ) . ' ' . $this->_get_latest_download_link( sprintf(
5985
+ __fs( 'download-latest-x-version', $this->_slug ),
5986
+ $this->_site->plan->title
5987
+ ) ),
5988
+ 'plan_upgraded',
5989
+ __fs( 'yee-haw', $this->_slug ) . '!'
5990
+ );
5991
+ }
5992
+
5993
+ $plugin_id = fs_request_get( 'plugin_id', false );
5994
+
5995
+ // Store activation time ONLY for plugins (not add-ons).
5996
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
5997
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
5998
+ }
5999
+
6000
+ if ( is_numeric( $plugin_id ) ) {
6001
+ if ( $plugin_id != $this->_plugin->id ) {
6002
+ // Add-on was installed - sync license right after install.
6003
+ if ( $redirect && fs_redirect( fs_nonce_url( $this->_get_admin_page_url(
6004
+ 'account',
6005
+ array(
6006
+ 'fs_action' => $this->_slug . '_sync_license',
6007
+ 'plugin_id' => $plugin_id
6008
+ )
6009
+ ), $this->_slug . '_sync_license' ) )
6010
+ ) {
6011
+ exit();
6012
+ }
6013
+
6014
+ }
6015
+ } else {
6016
+ /**
6017
+ * @author Vova Feldman (@svovaf)
6018
+ * @since 1.1.9 If site installed with a valid license, sync license.
6019
+ */
6020
+ if ( $this->is_paying() ) {
6021
+ $this->_sync_plugin_license( true );
6022
+ }
6023
+
6024
+ // Reload the page with the keys.
6025
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_connect_url' ) ) ) {
6026
+ exit();
6027
+ }
6028
+ }
6029
+ }
6030
+
6031
+ /**
6032
+ * Install plugin with new user information after approval.
6033
+ *
6034
+ * @author Vova Feldman (@svovaf)
6035
+ * @since 1.0.7
6036
+ */
6037
+ function _install_with_new_user() {
6038
+ $this->_logger->entrance();
6039
+
6040
+ if ( $this->is_registered() ) {
6041
+ return;
6042
+ }
6043
+
6044
+ if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6045
+ // check_admin_referer( $this->_slug . '_activate_new' );
6046
+
6047
+ $this->_admin_notices->remove_sticky( 'connect_account' );
6048
+
6049
+ if ( fs_request_has( 'user_secret_key' ) ) {
6050
+ $this->install_with_new_user(
6051
+ fs_request_get( 'user_id' ),
6052
+ fs_request_get( 'user_public_key' ),
6053
+ fs_request_get( 'user_secret_key' ),
6054
+ fs_request_get( 'install_id' ),
6055
+ fs_request_get( 'install_public_key' ),
6056
+ fs_request_get( 'install_secret_key' )
6057
+ );
6058
+ } else if ( fs_request_has( 'pending_activation' ) ) {
6059
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
6060
+ }
6061
+ }
6062
+ }
6063
+
6064
+ /**
6065
+ * Install plugin with new user.
6066
+ *
6067
+ * @author Vova Feldman (@svovaf)
6068
+ * @since 1.1.7.4
6069
+ *
6070
+ * @param number $user_id
6071
+ * @param string $user_public_key
6072
+ * @param string $user_secret_key
6073
+ * @param number $install_id
6074
+ * @param string $install_public_key
6075
+ * @param string $install_secret_key
6076
+ * @param bool $redirect
6077
+ */
6078
+ private function install_with_new_user(
6079
+ $user_id,
6080
+ $user_public_key,
6081
+ $user_secret_key,
6082
+ $install_id,
6083
+ $install_public_key,
6084
+ $install_secret_key,
6085
+ $redirect = true
6086
+ ) {
6087
+ $user = new FS_User();
6088
+ $user->id = $user_id;
6089
+ $user->public_key = $user_public_key;
6090
+ $user->secret_key = $user_secret_key;
6091
+
6092
+ $this->_user = $user;
6093
+ $user_result = $this->get_api_user_scope()->get();
6094
+ $user = new FS_User( $user_result );
6095
+ $this->_user = $user;
6096
+
6097
+ $site = new FS_Site();
6098
+ $site->id = $install_id;
6099
+ $site->public_key = $install_public_key;
6100
+ $site->secret_key = $install_secret_key;
6101
+
6102
+ $this->_site = $site;
6103
+ $site_result = $this->get_api_site_scope()->get();
6104
+ $site = new FS_Site( $site_result );
6105
+ $this->_site = $site;
6106
+
6107
+ $this->setup_account( $this->_user, $this->_site, $redirect );
6108
+ }
6109
+
6110
+ /**
6111
+ * @author Vova Feldman (@svovaf)
6112
+ * @since 1.1.7.4
6113
+ *
6114
+ * @param bool $email
6115
+ * @param bool $redirect
6116
+ */
6117
+ private function set_pending_confirmation( $email = false, $redirect = true ) {
6118
+ // Install must be activated via email since
6119
+ // user with the same email already exist.
6120
+ $this->_storage->is_pending_activation = true;
6121
+ $this->_add_pending_activation_notice( $email );
6122
+
6123
+ // Reload the page with with pending activation message.
6124
+ if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_pending_connect_url' ) ) ) {
6125
+ exit();
6126
+ }
6127
+ }
6128
+
6129
+ /**
6130
+ * Install plugin with current logged WP user info.
6131
+ *
6132
+ * @author Vova Feldman (@svovaf)
6133
+ * @since 1.0.7
6134
+ */
6135
+ function _install_with_current_user() {
6136
+ $this->_logger->entrance();
6137
+
6138
+ if ( $this->is_registered() ) {
6139
+ return;
6140
+ }
6141
+
6142
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
6143
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
6144
+
6145
+ $this->install_with_current_user();
6146
+ }
6147
+ }
6148
+
6149
+
6150
+ /**
6151
+ * @author Vova Feldman (@svovaf)
6152
+ * @since 1.1.7.4
6153
+ *
6154
+ * @param bool $redirect
6155
+ */
6156
+ private function install_with_current_user( $redirect = true ) {
6157
+ $this->_admin_notices->remove_sticky( 'connect_account' );
6158
+
6159
+ // Get current logged WP user.
6160
+ $current_user = self::_get_current_wp_user();
6161
+
6162
+ // Find the relevant FS user by the email.
6163
+ $user = self::_get_user_by_email( $current_user->user_email );
6164
+
6165
+ // We have to set the user before getting user scope API handler.
6166
+ $this->_user = $user;
6167
+
6168
+ $extra_install_params = array(
6169
+ 'uid' => $this->get_anonymous_id(),
6170
+ );
6171
+
6172
+ /**
6173
+ * @author Vova Feldman (@svovaf)
6174
+ * @since 1.1.9 Add license key if given.
6175
+ */
6176
+ $license_key = fs_request_get( 'license_secret_key' );
6177
+
6178
+ if ( ! empty( $license_key ) ) {
6179
+ $extra_install_params['license_secret_key'] = $license_key;
6180
+ }
6181
+
6182
+ // Install the plugin.
6183
+ $install = $this->get_api_user_scope()->call(
6184
+ "/plugins/{$this->get_id()}/installs.json",
6185
+ 'post',
6186
+ $this->get_install_data_for_api( $extra_install_params, false, false )
6187
+ );
6188
+
6189
+ if ( isset( $install->error ) ) {
6190
+ $this->_admin_notices->add(
6191
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
6192
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
6193
+ __fs( 'oops', $this->_slug ) . '...',
6194
+ 'error'
6195
+ );
6196
+
6197
+ return;
6198
+ }
6199
+
6200
+ $site = new FS_Site( $install );
6201
+ $this->_site = $site;
6202
+ // $this->_enrich_site_plan( false );
6203
+
6204
+ // $this->_set_account( $user, $site );
6205
+ // $this->_sync_plans();
6206
+
6207
+ $this->setup_account( $this->_user, $this->_site, $redirect );
6208
+ }
6209
+
6210
+ /**
6211
+ * Tries to activate add-on account based on parent plugin info.
6212
+ *
6213
+ * @author Vova Feldman (@svovaf)
6214
+ * @since 1.0.6
6215
+ *
6216
+ * @param Freemius $parent_fs
6217
+ */
6218
+ private function _activate_addon_account( Freemius $parent_fs ) {
6219
+ if ( $this->is_registered() ) {
6220
+ // Already activated.
6221
+ return;
6222
+ }
6223
+
6224
+ // Activate add-on with parent plugin credentials.
6225
+ $addon_install = $parent_fs->get_api_site_scope()->call(
6226
+ "/addons/{$this->_plugin->id}/installs.json",
6227
+ 'post',
6228
+ $this->get_install_data_for_api( array(
6229
+ 'uid' => $this->get_anonymous_id(),
6230
+ ), false, false )
6231
+ );
6232
+
6233
+ if ( isset( $addon_install->error ) ) {
6234
+ $this->_admin_notices->add(
6235
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
6236
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
6237
+ __fs( 'oops', $this->_slug ) . '...',
6238
+ 'error'
6239
+ );
6240
+
6241
+ return;
6242
+ }
6243
+
6244
+ // First of all, set site info - otherwise we won't
6245
+ // be able to invoke API calls.
6246
+ $this->_site = new FS_Site( $addon_install );
6247
+
6248
+ // Sync add-on plans.
6249
+ $this->_sync_plans();
6250
+
6251
+ // Get site's current plan.
6252
+ $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
6253
+
6254
+ // Get user information based on parent's plugin.
6255
+ $user = $parent_fs->get_user();
6256
+
6257
+ $this->_set_account( $user, $this->_site );
6258
+
6259
+ // Sync licenses.
6260
+ $this->_sync_licenses();
6261
+
6262
+ // Try to activate premium license.
6263
+ $this->_activate_license( true );
6264
+ }
6265
+
6266
+ #endregion ------------------------------------------------------------------
6267
+
6268
+ #region Admin Menu Items ------------------------------------------------------------------
6269
+
6270
+ private $_menu_items = array();
6271
+
6272
+ /**
6273
+ * @author Vova Feldman (@svovaf)
6274
+ * @since 1.0.7
6275
+ *
6276
+ * @return string
6277
+ */
6278
+ function get_menu_slug() {
6279
+ return $this->_menu->get_slug();
6280
+ }
6281
+
6282
+ /**
6283
+ * @author Vova Feldman (@svovaf)
6284
+ * @since 1.0.9
6285
+ */
6286
+ function _prepare_admin_menu() {
6287
+ // if ( ! $this->is_on() ) {
6288
+ // return;
6289
+ // }
6290
+
6291
+ if ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) {
6292
+ $this->_menu->remove_menu_item();
6293
+ } else {
6294
+ $this->add_menu_action();
6295
+ $this->add_submenu_items();
6296
+ }
6297
+ }
6298
+
6299
+ /**
6300
+ * Admin dashboard menu items modifications.
6301
+ *
6302
+ * NOTE: admin_menu action executed before admin_init.
6303
+ *
6304
+ * @author Vova Feldman (@svovaf)
6305
+ * @since 1.0.7
6306
+ *
6307
+ */
6308
+ private function add_menu_action() {
6309
+ if ( $this->is_activation_mode() ) {
6310
+ $this->override_plugin_menu_with_activation();
6311
+ } else {
6312
+ // If not registered try to install user.
6313
+ if ( ! $this->is_registered() &&
6314
+ fs_request_is_action( $this->_slug . '_activate_new' )
6315
+ ) {
6316
+ $this->_install_with_new_user();
6317
+ }
6318
+ }
6319
+ }
6320
+
6321
+ /**
6322
+ * @author Vova Feldman (@svovaf)
6323
+ * @since 1.0.1
6324
+ *
6325
+ * @return string
6326
+ */
6327
+ function _redirect_on_clicked_menu_link() {
6328
+ $this->_logger->entrance();
6329
+
6330
+ $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
6331
+
6332
+ $this->_logger->log( 'page = ' . $page );
6333
+
6334
+ foreach ( $this->_menu_items as $priority => $items ) {
6335
+ foreach ( $items as $item ) {
6336
+ if ( isset( $item['url'] ) ) {
6337
+ if ( $page === strtolower( $item['menu_slug'] ) ) {
6338
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
6339
+
6340
+ fs_redirect( $item['url'] );
6341
+ }
6342
+ }
6343
+ }
6344
+ }
6345
+ }
6346
+
6347
+ /**
6348
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
6349
+ *
6350
+ * @author Vova Feldman (@svovaf)
6351
+ * @since 1.0.1
6352
+ */
6353
+ private function override_plugin_menu_with_activation() {
6354
+ $this->_logger->entrance();
6355
+
6356
+ $hook = false;
6357
+
6358
+ if ( $this->_menu->is_top_level() ) {
6359
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
6360
+
6361
+ if ( false === $hook ) {
6362
+ // Create new menu item just for the opt-in.
6363
+ $hook = add_menu_page(
6364
+ $this->get_plugin_name(),
6365
+ $this->get_plugin_name(),
6366
+ 'manage_options',
6367
+ $this->_menu->get_slug(),
6368
+ array( &$this, '_connect_page_render' )
6369
+ );
6370
+ }
6371
+ } else {
6372
+ $menus = array( $this->_menu->get_parent_slug() );
6373
+
6374
+ if ( $this->_menu->is_override_exact() ) {
6375
+ // Make sure the current page is matching the activation page.
6376
+ $activation_url = strtolower( $this->get_activation_url() );
6377
+ $request_url = strtolower( $_SERVER['REQUEST_URI'] );
6378
+
6379
+ if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
6380
+ // Different path - DO NOT OVERRIDE PAGE.
6381
+ return;
6382
+ }
6383
+
6384
+ $activation_url_params = array();
6385
+ parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
6386
+
6387
+ $request_url_params = array();
6388
+ parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
6389
+
6390
+
6391
+ foreach ( $activation_url_params as $key => $val ) {
6392
+ if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
6393
+ // Not matching query string - DO NOT OVERRIDE PAGE.
6394
+ return;
6395
+ }
6396
+ }
6397
+ }
6398
+
6399
+ foreach ( $menus as $parent_slug ) {
6400
+ $hook = $this->_menu->override_submenu_action(
6401
+ $parent_slug,
6402
+ $this->_menu->get_raw_slug(),
6403
+ array( &$this, '_connect_page_render' )
6404
+ );
6405
+
6406
+ if ( false !== $hook ) {
6407
+ // Found plugin's submenu item.
6408
+ break;
6409
+ }
6410
+ }
6411
+ }
6412
+
6413
+ if ( $this->_menu->is_activation_page() ) {
6414
+ // Clean admin page from distracting content.
6415
+ self::_clean_admin_content_section();
6416
+ }
6417
+
6418
+ if ( false !== $hook ) {
6419
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
6420
+ add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
6421
+ } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6422
+ add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
6423
+ }
6424
+ }
6425
+ }
6426
+
6427
+ /**
6428
+ * @author Vova Feldman (@svovaf)
6429
+ * @since 1.0.0
6430
+ *
6431
+ * @return string
6432
+ */
6433
+ private function get_top_level_menu_slug() {
6434
+ return ( $this->is_addon() ?
6435
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
6436
+ $this->_menu->get_top_level_menu_slug() );
6437
+ }
6438
+
6439
+ /**
6440
+ * Add default Freemius menu items.
6441
+ *
6442
+ * @author Vova Feldman (@svovaf)
6443
+ * @since 1.0.0
6444
+ */
6445
+ private function add_submenu_items() {
6446
+ $this->_logger->entrance();
6447
+
6448
+ $this->do_action( 'before_admin_menu_init' );
6449
+
6450
+ if ( ! $this->is_addon() ) {
6451
+ if ( ! $this->is_activation_mode() ) {
6452
+ if ( $this->is_registered() ) {
6453
+ // Add user account page.
6454
+ $this->add_submenu_item(
6455
+ __fs( 'account', $this->_slug ),
6456
+ array( &$this, '_account_page_render' ),
6457
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
6458
+ 'manage_options',
6459
+ 'account',
6460
+ array( &$this, '_account_page_load' ),
6461
+ WP_FS__DEFAULT_PRIORITY,
6462
+ $this->_menu->is_submenu_item_visible( 'account' )
6463
+ );
6464
+ }
6465
+
6466
+ // Add contact page.
6467
+ $this->add_submenu_item(
6468
+ __fs( 'contact-us', $this->_slug ),
6469
+ array( &$this, '_contact_page_render' ),
6470
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
6471
+ 'manage_options',
6472
+ 'contact',
6473
+ 'Freemius::_clean_admin_content_section',
6474
+ WP_FS__DEFAULT_PRIORITY,
6475
+ $this->_menu->is_submenu_item_visible( 'contact' )
6476
+ );
6477
+
6478
+ if ( $this->has_addons() ) {
6479
+ $this->add_submenu_item(
6480
+ __fs( 'add-ons', $this->_slug ),
6481
+ array( &$this, '_addons_page_render' ),
6482
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
6483
+ 'manage_options',
6484
+ 'addons',
6485
+ array( &$this, '_addons_page_load' ),
6486
+ WP_FS__LOWEST_PRIORITY - 1,
6487
+ $this->_menu->is_submenu_item_visible( 'addons' )
6488
+ );
6489
+ }
6490
+
6491
+ $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
6492
+ // If user don't have paid plans, add pricing page
6493
+ // to support add-ons checkout but don't add the submenu item.
6494
+ // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
6495
+
6496
+ // Add upgrade/pricing page.
6497
+ $this->add_submenu_item(
6498
+ ( $this->is_paying() ? __fs( 'pricing', $this->_slug ) : __fs( 'upgrade', $this->_slug ) . '&nbsp;&nbsp;&#x27a4;' ),
6499
+ array( &$this, '_pricing_page_render' ),
6500
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
6501
+ 'manage_options',
6502
+ 'pricing',
6503
+ 'Freemius::_clean_admin_content_section',
6504
+ WP_FS__LOWEST_PRIORITY,
6505
+ $show_pricing
6506
+ );
6507
+ }
6508
+ }
6509
+
6510
+
6511
+ if ( 0 < count( $this->_menu_items ) ) {
6512
+ if ( ! $this->_menu->is_top_level() ) {
6513
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
6514
+
6515
+ // Append submenu items right after the plugin's submenu item.
6516
+ $this->order_sub_submenu_items();
6517
+ } else {
6518
+ // Append submenu items.
6519
+ $this->embed_submenu_items();
6520
+ }
6521
+ }
6522
+ }
6523
+
6524
+ /**
6525
+ * Moved the actual submenu item additions to a separated function,
6526
+ * in order to support sub-submenu items when the plugin's settings
6527
+ * only have a submenu and not top-level menu item.
6528
+ *
6529
+ * @author Vova Feldman (@svovaf)
6530
+ * @since 1.1.4
6531
+ */
6532
+ private function embed_submenu_items() {
6533
+ $item_template = $this->_menu->is_top_level() ?
6534
+ '<span class="fs-submenu-item">%s</span>' :
6535
+ '<span class="fs-submenu-item fs-sub">%s</span>';
6536
+
6537
+ ksort( $this->_menu_items );
6538
+
6539
+ foreach ( $this->_menu_items as $priority => $items ) {
6540
+ foreach ( $items as $item ) {
6541
+ if ( ! isset( $item['url'] ) ) {
6542
+ $hook = add_submenu_page(
6543
+ $item['show_submenu'] ?
6544
+ $this->get_top_level_menu_slug() :
6545
+ null,
6546
+ $item['page_title'],
6547
+ sprintf( $item_template, $item['menu_title'] ),
6548
+ $item['capability'],
6549
+ $item['menu_slug'],
6550
+ $item['render_function']
6551
+ );
6552
+
6553
+ if ( false !== $item['before_render_function'] ) {
6554
+ add_action( "load-$hook", $item['before_render_function'] );
6555
+ }
6556
+ } else {
6557
+ add_submenu_page(
6558
+ $this->get_top_level_menu_slug(),
6559
+ $item['page_title'],
6560
+ sprintf( $item_template, $item['menu_title'] ),
6561
+ $item['capability'],
6562
+ $item['menu_slug'],
6563
+ array( $this, '' )
6564
+ );
6565
+ }
6566
+ }
6567
+ }
6568
+ }
6569
+
6570
+ /**
6571
+ * Re-order the submenu items so all Freemius added new submenu items
6572
+ * are added right after the plugin's settings submenu item.
6573
+ *
6574
+ * @author Vova Feldman (@svovaf)
6575
+ * @since 1.1.4
6576
+ */
6577
+ private function order_sub_submenu_items() {
6578
+ global $submenu;
6579
+
6580
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
6581
+
6582
+ if ( empty( $submenu[ $menu_slug ] ) ) {
6583
+ return;
6584
+ }
6585
+
6586
+ $top_level_menu = &$submenu[ $menu_slug ];
6587
+
6588
+ $all_submenu_items_after = array();
6589
+
6590
+ $found_submenu_item = false;
6591
+
6592
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
6593
+ if ( $found_submenu_item ) {
6594
+ // Remove all submenu items after the plugin's submenu item.
6595
+ $all_submenu_items_after[] = $meta;
6596
+ unset( $top_level_menu[ $submenu_id ] );
6597
+ }
6598
+
6599
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
6600
+ // Found the submenu item, put all below.
6601
+ $found_submenu_item = true;
6602
+ continue;
6603
+ }
6604
+ }
6605
+
6606
+ // Embed all plugin's new submenu items.
6607
+ $this->embed_submenu_items();
6608
+
6609
+ // Start with specially high number to make sure it's appended.
6610
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
6611
+ foreach ( $all_submenu_items_after as $meta ) {
6612
+ $top_level_menu[ $i ] = $meta;
6613
+ $i ++;
6614
+ }
6615
+
6616
+ // Sort submenu items.
6617
+ ksort( $top_level_menu );
6618
+ }
6619
+
6620
+ /**
6621
+ * Displays the Support Forum link when enabled.
6622
+ *
6623
+ * Can be filtered like so:
6624
+ *
6625
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
6626
+ * if ( 'support' === $menu_id ) {
6627
+ * return _fs->is_registered();
6628
+ * }
6629
+ * return $is_visible;
6630
+ * }
6631
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
6632
+ *
6633
+ */
6634
+ function _add_default_submenu_items() {
6635
+ if ( ! $this->is_on() ) {
6636
+ return;
6637
+ }
6638
+
6639
+ if ( ! $this->is_activation_mode() ) {
6640
+ if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
6641
+ $this->add_submenu_link_item(
6642
+ $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
6643
+ $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
6644
+ 'wp-support-forum',
6645
+ 'read',
6646
+ 50
6647
+ );
6648
+ }
6649
+ }
6650
+ }
6651
+
6652
+ /**
6653
+ * @author Vova Feldman (@svovaf)
6654
+ * @since 1.0.1
6655
+ *
6656
+ * @param string $menu_title
6657
+ * @param callable $render_function
6658
+ * @param bool|string $page_title
6659
+ * @param string $capability
6660
+ * @param bool|string $menu_slug
6661
+ * @param bool|callable $before_render_function
6662
+ * @param int $priority
6663
+ * @param bool $show_submenu
6664
+ */
6665
+ function add_submenu_item(
6666
+ $menu_title,
6667
+ $render_function,
6668
+ $page_title = false,
6669
+ $capability = 'manage_options',
6670
+ $menu_slug = false,
6671
+ $before_render_function = false,
6672
+ $priority = WP_FS__DEFAULT_PRIORITY,
6673
+ $show_submenu = true
6674
+ ) {
6675
+ $this->_logger->entrance( 'Title = ' . $menu_title );
6676
+
6677
+ if ( $this->is_addon() ) {
6678
+ $parent_fs = $this->get_parent_instance();
6679
+
6680
+ if ( is_object( $parent_fs ) ) {
6681
+ $parent_fs->add_submenu_item(
6682
+ $menu_title,
6683
+ $render_function,
6684
+ $page_title,
6685
+ $capability,
6686
+ $menu_slug,
6687
+ $before_render_function,
6688
+ $priority,
6689
+ $show_submenu
6690
+ );
6691
+
6692
+ return;
6693
+ }
6694
+ }
6695
+
6696
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6697
+ $this->_menu_items[ $priority ] = array();
6698
+ }
6699
+
6700
+ $this->_menu_items[ $priority ][] = array(
6701
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
6702
+ 'menu_title' => $menu_title,
6703
+ 'capability' => $capability,
6704
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6705
+ 'render_function' => $render_function,
6706
+ 'before_render_function' => $before_render_function,
6707
+ 'show_submenu' => $show_submenu,
6708
+ );
6709
+ }
6710
+
6711
+ /**
6712
+ * @author Vova Feldman (@svovaf)
6713
+ * @since 1.0.1
6714
+ *
6715
+ * @param string $menu_title
6716
+ * @param string $url
6717
+ * @param bool $menu_slug
6718
+ * @param string $capability
6719
+ * @param int $priority
6720
+ *
6721
+ */
6722
+ function add_submenu_link_item(
6723
+ $menu_title,
6724
+ $url,
6725
+ $menu_slug = false,
6726
+ $capability = 'read',
6727
+ $priority = WP_FS__DEFAULT_PRIORITY
6728
+ ) {
6729
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
6730
+
6731
+ if ( $this->is_addon() ) {
6732
+ $parent_fs = $this->get_parent_instance();
6733
+
6734
+ if ( is_object( $parent_fs ) ) {
6735
+ $parent_fs->add_submenu_link_item(
6736
+ $menu_title,
6737
+ $url,
6738
+ $menu_slug,
6739
+ $capability,
6740
+ $priority
6741
+ );
6742
+
6743
+ return;
6744
+ }
6745
+ }
6746
+
6747
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
6748
+ $this->_menu_items[ $priority ] = array();
6749
+ }
6750
+
6751
+ $this->_menu_items[ $priority ][] = array(
6752
+ 'menu_title' => $menu_title,
6753
+ 'capability' => $capability,
6754
+ 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
6755
+ 'url' => $url,
6756
+ 'page_title' => $menu_title,
6757
+ 'render_function' => 'fs_dummy',
6758
+ 'before_render_function' => '',
6759
+ );
6760
+ }
6761
+
6762
+ #endregion ------------------------------------------------------------------
6763
+
6764
+ /* Actions / Hooks / Filters
6765
+ ------------------------------------------------------------------------------------------------------------------*/
6766
+ /**
6767
+ * @author Vova Feldman (@svovaf)
6768
+ * @since 1.1.7
6769
+ *
6770
+ * @param string $tag
6771
+ *
6772
+ * @return string
6773
+ */
6774
+ private function get_action_tag( $tag ) {
6775
+ return 'fs_' . $tag . '_' . $this->_slug;
6776
+ }
6777
+
6778
+ /**
6779
+ * Do action, specific for the current context plugin.
6780
+ *
6781
+ * @author Vova Feldman (@svovaf)
6782
+ * @since 1.0.1
6783
+ *
6784
+ * @param string $tag The name of the action to be executed.
6785
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
6786
+ * functions hooked to the action. Default empty.
6787
+ *
6788
+ * @uses do_action()
6789
+ */
6790
+ function do_action( $tag, $arg = '' ) {
6791
+ $this->_logger->entrance( $tag );
6792
+
6793
+ $args = func_get_args();
6794
+
6795
+ call_user_func_array( 'do_action', array_merge(
6796
+ array( $this->get_action_tag( $tag ) ),
6797
+ array_slice( $args, 1 ) )
6798
+ );
6799
+ }
6800
+
6801
+ /**
6802
+ * Add action, specific for the current context plugin.
6803
+ *
6804
+ * @author Vova Feldman (@svovaf)
6805
+ * @since 1.0.1
6806
+ *
6807
+ * @param string $tag
6808
+ * @param callable $function_to_add
6809
+ * @param int $priority
6810
+ * @param int $accepted_args
6811
+ *
6812
+ * @uses add_action()
6813
+ */
6814
+ function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6815
+ $this->_logger->entrance( $tag );
6816
+
6817
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6818
+ }
6819
+
6820
+ /**
6821
+ * Apply filter, specific for the current context plugin.
6822
+ *
6823
+ * @author Vova Feldman (@svovaf)
6824
+ * @since 1.0.9
6825
+ *
6826
+ * @param string $tag The name of the filter hook.
6827
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
6828
+ *
6829
+ * @return mixed The filtered value after all hooked functions are applied to it.
6830
+ *
6831
+ * @uses apply_filters()
6832
+ */
6833
+ function apply_filters( $tag, $value ) {
6834
+ $this->_logger->entrance( $tag );
6835
+
6836
+ $args = func_get_args();
6837
+ array_unshift( $args, $this->_slug );
6838
+
6839
+ return call_user_func_array( 'fs_apply_filter', $args );
6840
+ }
6841
+
6842
+ /**
6843
+ * Add filter, specific for the current context plugin.
6844
+ *
6845
+ * @author Vova Feldman (@svovaf)
6846
+ * @since 1.0.9
6847
+ *
6848
+ * @param string $tag
6849
+ * @param callable $function_to_add
6850
+ * @param int $priority
6851
+ * @param int $accepted_args
6852
+ *
6853
+ * @uses add_filter()
6854
+ */
6855
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
6856
+ $this->_logger->entrance( $tag );
6857
+
6858
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
6859
+ }
6860
+
6861
+ /**
6862
+ * Check if has filter.
6863
+ *
6864
+ * @author Vova Feldman (@svovaf)
6865
+ * @since 1.1.4
6866
+ *
6867
+ * @param string $tag
6868
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
6869
+ *
6870
+ * @return false|int
6871
+ *
6872
+ * @uses has_filter()
6873
+ */
6874
+ function has_filter( $tag, $function_to_check = false ) {
6875
+ $this->_logger->entrance( $tag );
6876
+
6877
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
6878
+ }
6879
+
6880
+ /**
6881
+ * Override default i18n text phrases.
6882
+ *
6883
+ * @author Vova Feldman (@svovaf)
6884
+ * @since 1.1.6
6885
+ *
6886
+ * @param string[] string $key_value
6887
+ *
6888
+ * @uses fs_override_i18n()
6889
+ */
6890
+ function override_i18n( $key_value ) {
6891
+ fs_override_i18n( $key_value, $this->_slug );
6892
+ }
6893
+
6894
+ /* Account Page
6895
+ ------------------------------------------------------------------------------------------------------------------*/
6896
+ /**
6897
+ * Update site information.
6898
+ *
6899
+ * @author Vova Feldman (@svovaf)
6900
+ * @since 1.0.1
6901
+ *
6902
+ * @param bool $store Flush to Database if true.
6903
+ */
6904
+ private function _store_site( $store = true ) {
6905
+ $this->_logger->entrance();
6906
+
6907
+ $encrypted_site = clone $this->_site;
6908
+ $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
6909
+
6910
+ $sites = self::get_all_sites();
6911
+ $sites[ $this->_slug ] = $encrypted_site;
6912
+ self::$_accounts->set_option( 'sites', $sites, $store );
6913
+ }
6914
+
6915
+ /**
6916
+ * Update plugin's plans information.
6917
+ *
6918
+ * @author Vova Feldman (@svovaf)
6919
+ * @since 1.0.2
6920
+ *
6921
+ * @param bool $store Flush to Database if true.
6922
+ */
6923
+ private function _store_plans( $store = true ) {
6924
+ $this->_logger->entrance();
6925
+
6926
+ $plans = self::get_all_plans();
6927
+
6928
+ // Copy plans.
6929
+ $encrypted_plans = array();
6930
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6931
+ $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
6932
+ }
6933
+
6934
+ $plans[ $this->_slug ] = $encrypted_plans;
6935
+ self::$_accounts->set_option( 'plans', $plans, $store );
6936
+ }
6937
+
6938
+ /**
6939
+ * Update user's plugin licenses.
6940
+ *
6941
+ * @author Vova Feldman (@svovaf)
6942
+ * @since 1.0.5
6943
+ *
6944
+ * @param bool $store
6945
+ * @param string|bool $plugin_slug
6946
+ * @param FS_Plugin_License[] $licenses
6947
+ */
6948
+ private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
6949
+ $this->_logger->entrance();
6950
+
6951
+ $all_licenses = self::get_all_licenses();
6952
+
6953
+ if ( ! is_string( $plugin_slug ) ) {
6954
+ $plugin_slug = $this->_slug;
6955
+ $licenses = $this->_licenses;
6956
+ }
6957
+
6958
+ if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
6959
+ $all_licenses[ $plugin_slug ] = array();
6960
+ }
6961
+
6962
+ $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
6963
+
6964
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
6965
+ }
6966
+
6967
+ /**
6968
+ * Update user information.
6969
+ *
6970
+ * @author Vova Feldman (@svovaf)
6971
+ * @since 1.0.1
6972
+ *
6973
+ * @param bool $store Flush to Database if true.
6974
+ */
6975
+ private function _store_user( $store = true ) {
6976
+ $this->_logger->entrance();
6977
+
6978
+ $users = self::get_all_users();
6979
+ $users[ $this->_user->id ] = $this->_user;
6980
+ self::$_accounts->set_option( 'users', $users, $store );
6981
+ }
6982
+
6983
+ /**
6984
+ * Update new updates information.
6985
+ *
6986
+ * @author Vova Feldman (@svovaf)
6987
+ * @since 1.0.4
6988
+ *
6989
+ * @param FS_Plugin_Tag|null $update
6990
+ * @param bool $store Flush to Database if true.
6991
+ * @param bool|number $plugin_id
6992
+ */
6993
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
6994
+ $this->_logger->entrance();
6995
+
6996
+ if ( $update instanceof FS_Plugin_Tag ) {
6997
+ $update->updated = time();
6998
+ }
6999
+
7000
+ if ( ! is_numeric( $plugin_id ) ) {
7001
+ $plugin_id = $this->_plugin->id;
7002
+ }
7003
+
7004
+ $updates = self::get_all_updates();
7005
+ $updates[ $plugin_id ] = $update;
7006
+ self::$_accounts->set_option( 'updates', $updates, $store );
7007
+ }
7008
+
7009
+ /**
7010
+ * Update new updates information.
7011
+ *
7012
+ * @author Vova Feldman (@svovaf)
7013
+ * @since 1.0.6
7014
+ *
7015
+ * @param FS_Plugin[] $plugin_addons
7016
+ * @param bool $store Flush to Database if true.
7017
+ */
7018
+ private function _store_addons( $plugin_addons, $store = true ) {
7019
+ $this->_logger->entrance();
7020
+
7021
+ $addons = self::get_all_addons();
7022
+ $addons[ $this->_plugin->id ] = $plugin_addons;
7023
+ self::$_accounts->set_option( 'addons', $addons, $store );
7024
+ }
7025
+
7026
+ /**
7027
+ * Delete plugin's associated add-ons.
7028
+ *
7029
+ * @author Vova Feldman (@svovaf)
7030
+ * @since 1.0.8
7031
+ *
7032
+ * @param bool $store
7033
+ *
7034
+ * @return bool
7035
+ */
7036
+ private function _delete_account_addons( $store = true ) {
7037
+ $all_addons = self::get_all_account_addons();
7038
+
7039
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
7040
+ return false;
7041
+ }
7042
+
7043
+ unset( $all_addons[ $this->_plugin->id ] );
7044
+
7045
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
7046
+
7047
+ return true;
7048
+ }
7049
+
7050
+ /**
7051
+ * Update account add-ons list.
7052
+ *
7053
+ * @author Vova Feldman (@svovaf)
7054
+ * @since 1.0.6
7055
+ *
7056
+ * @param FS_Plugin[] $addons
7057
+ * @param bool $store Flush to Database if true.
7058
+ */
7059
+ private function _store_account_addons( $addons, $store = true ) {
7060
+ $this->_logger->entrance();
7061
+
7062
+ $all_addons = self::get_all_account_addons();
7063
+ $all_addons[ $this->_plugin->id ] = $addons;
7064
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
7065
+ }
7066
+
7067
+ /**
7068
+ * Store account params in the Database.
7069
+ *
7070
+ * @author Vova Feldman (@svovaf)
7071
+ * @since 1.0.1
7072
+ */
7073
+ private function _store_account() {
7074
+ $this->_logger->entrance();
7075
+
7076
+ $this->_store_site( false );
7077
+ $this->_store_user( false );
7078
+ $this->_store_plans( false );
7079
+ $this->_store_licenses( false );
7080
+
7081
+ self::$_accounts->store();
7082
+ }
7083
+
7084
+ /**
7085
+ * Sync user's information.
7086
+ *
7087
+ * @author Vova Feldman (@svovaf)
7088
+ * @since 1.0.3
7089
+ * @uses FS_Api
7090
+ */
7091
+ private function _handle_account_user_sync() {
7092
+ $this->_logger->entrance();
7093
+
7094
+ $api = $this->get_api_user_scope();
7095
+
7096
+ // Get user's information.
7097
+ $user = $api->get( '/', true );
7098
+
7099
+ if ( isset( $user->id ) ) {
7100
+ $this->_user->first = $user->first;
7101
+ $this->_user->last = $user->last;
7102
+ $this->_user->email = $user->email;
7103
+
7104
+ $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
7105
+
7106
+ if ( $user->is_verified &&
7107
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
7108
+ ) {
7109
+ $this->_user->is_verified = true;
7110
+
7111
+ $this->do_action( 'account_email_verified', $user->email );
7112
+
7113
+ $this->_admin_notices->add(
7114
+ __fs( 'email-verified-message', $this->_slug ),
7115
+ __fs( 'right-on', $this->_slug ) . '!',
7116
+ 'success',
7117
+ // Make admin sticky if account menu item is invisible,
7118
+ // since the page will be auto redirected to the plugin's
7119
+ // main settings page, and the non-sticky message
7120
+ // will disappear.
7121
+ ! $is_menu_item_account_visible,
7122
+ false,
7123
+ 'email_verified'
7124
+ );
7125
+ }
7126
+
7127
+ // Flush user details to DB.
7128
+ $this->_store_user();
7129
+
7130
+ $this->do_action( 'after_account_user_sync', $user );
7131
+
7132
+ /**
7133
+ * If account menu item is hidden, redirect to plugin's main settings page.
7134
+ *
7135
+ * @author Vova Feldman (@svovaf)
7136
+ * @since 1.1.6
7137
+ *
7138
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
7139
+ */
7140
+ if ( ! $is_menu_item_account_visible ) {
7141
+ if ( fs_redirect( $this->_get_admin_page_url() ) ) {
7142
+ exit();
7143
+ }
7144
+ }
7145
+ }
7146
+ }
7147
+
7148
+ /**
7149
+ * @author Vova Feldman (@svovaf)
7150
+ * @since 1.0.5
7151
+ * @uses FS_Api
7152
+ *
7153
+ * @param bool $flush
7154
+ *
7155
+ * @return object|\FS_Site
7156
+ */
7157
+ private function _fetch_site( $flush = false ) {
7158
+ $this->_logger->entrance();
7159
+ $api = $this->get_api_site_scope();
7160
+
7161
+ $site = $api->get( '/', $flush );
7162
+
7163
+ if ( ! isset( $site->error ) ) {
7164
+ $site = new FS_Site( $site );
7165
+ $site->slug = $this->_slug;
7166
+ $site->version = $this->get_plugin_version();
7167
+ }
7168
+
7169
+ return $site;
7170
+ }
7171
+
7172
+ /**
7173
+ * @param bool $store
7174
+ *
7175
+ * @return FS_Plugin_Plan|object|false
7176
+ */
7177
+ private function _enrich_site_plan( $store = true ) {
7178
+ // Try to load plan from local cache.
7179
+ $plan = $this->_get_plan_by_id( $this->_site->plan->id );
7180
+
7181
+ if ( false === $plan ) {
7182
+ $plan = $this->_fetch_site_plan();
7183
+ }
7184
+
7185
+ if ( $plan instanceof FS_Plugin_Plan ) {
7186
+ $this->_update_plan( $plan, $store );
7187
+ }
7188
+
7189
+ return $plan;
7190
+ }
7191
+
7192
+ /**
7193
+ * @author Vova Feldman (@svovaf)
7194
+ * @since 1.0.9
7195
+ * @uses FS_Api
7196
+ *
7197
+ * @param bool $store
7198
+ *
7199
+ * @return FS_Plugin_Plan|object|false
7200
+ */
7201
+ private function _enrich_site_trial_plan( $store = true ) {
7202
+ // Try to load plan from local cache.
7203
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
7204
+
7205
+ if ( false === $trial_plan ) {
7206
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
7207
+ }
7208
+
7209
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
7210
+ $this->_storage->store( 'trial_plan', $trial_plan, $store );
7211
+ }
7212
+
7213
+ return $trial_plan;
7214
+ }
7215
+
7216
+ /**
7217
+ * @author Vova Feldman (@svovaf)
7218
+ * @since 1.0.9
7219
+ * @uses FS_Api
7220
+ *
7221
+ * @param number|bool $license_id
7222
+ *
7223
+ * @return FS_Subscription|object|bool
7224
+ */
7225
+ private function _fetch_site_license_subscription( $license_id = false ) {
7226
+ $this->_logger->entrance();
7227
+ $api = $this->get_api_site_scope();
7228
+
7229
+ if ( ! is_numeric( $license_id ) ) {
7230
+ $license_id = $this->_license->id;
7231
+ }
7232
+
7233
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
7234
+
7235
+ return ! isset( $result->error ) ?
7236
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
7237
+ new FS_Subscription( $result->subscriptions[0] ) :
7238
+ false
7239
+ ) :
7240
+ $result;
7241
+ }
7242
+
7243
+ /**
7244
+ * @author Vova Feldman (@svovaf)
7245
+ * @since 1.0.4
7246
+ * @uses FS_Api
7247
+ *
7248
+ * @param number|bool $plan_id
7249
+ *
7250
+ * @return FS_Plugin_Plan|object
7251
+ */
7252
+ private function _fetch_site_plan( $plan_id = false ) {
7253
+ $this->_logger->entrance();
7254
+ $api = $this->get_api_site_scope();
7255
+
7256
+ if ( ! is_numeric( $plan_id ) ) {
7257
+ $plan_id = $this->_site->plan->id;
7258
+ }
7259
+
7260
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
7261
+
7262
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
7263
+ }
7264
+
7265
+ /**
7266
+ * @author Vova Feldman (@svovaf)
7267
+ * @since 1.0.5
7268
+ * @uses FS_Api
7269
+ *
7270
+ * @return FS_Plugin_Plan[]|object
7271
+ */
7272
+ private function _fetch_plugin_plans() {
7273
+ $this->_logger->entrance();
7274
+ $api = $this->get_api_site_scope();
7275
+
7276
+ $result = $api->get( '/plans.json', true );
7277
+
7278
+ if ( ! $this->is_api_error( $result ) ) {
7279
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
7280
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
7281
+ }
7282
+
7283
+ $result = $result->plans;
7284
+ }
7285
+
7286
+ return $result;
7287
+ }
7288
+
7289
+ /**
7290
+ * @author Vova Feldman (@svovaf)
7291
+ * @since 1.0.5
7292
+ * @uses FS_Api
7293
+ *
7294
+ * @param number|bool $plugin_id
7295
+ *
7296
+ * @return FS_Plugin_License[]|object
7297
+ */
7298
+ private function _fetch_licenses( $plugin_id = false ) {
7299
+ $this->_logger->entrance();
7300
+
7301
+ $api = $this->get_api_user_scope();
7302
+
7303
+ if ( ! is_numeric( $plugin_id ) ) {
7304
+ $plugin_id = $this->_plugin->id;
7305
+ }
7306
+
7307
+ $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
7308
+
7309
+ if ( ! isset( $result->error ) ) {
7310
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
7311
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
7312
+ }
7313
+
7314
+ $result = $result->licenses;
7315
+ }
7316
+
7317
+ return $result;
7318
+ }
7319
+
7320
+ /**
7321
+ * @author Vova Feldman (@svovaf)
7322
+ * @since 1.0.4
7323
+ *
7324
+ * @param FS_Plugin_Plan $plan
7325
+ * @param bool $store
7326
+ */
7327
+ private function _update_plan( $plan, $store = false ) {
7328
+ $this->_logger->entrance();
7329
+
7330
+ $this->_site->plan = $plan;
7331
+ $this->_store_site( $store );
7332
+ }
7333
+
7334
+ /**
7335
+ * @author Vova Feldman (@svovaf)
7336
+ * @since 1.0.5
7337
+ *
7338
+ * @param FS_Plugin_License[] $licenses
7339
+ * @param string|bool $plugin_slug
7340
+ */
7341
+ private function _update_licenses( $licenses, $plugin_slug = false ) {
7342
+ $this->_logger->entrance();
7343
+
7344
+ if ( is_array( $licenses ) ) {
7345
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
7346
+ $licenses[ $i ]->updated = time();
7347
+ }
7348
+ }
7349
+
7350
+ if ( ! is_string( $plugin_slug ) ) {
7351
+ $this->_licenses = $licenses;
7352
+ }
7353
+
7354
+ $this->_store_licenses( true, $plugin_slug, $licenses );
7355
+ }
7356
+
7357
+ /**
7358
+ * @author Vova Feldman (@svovaf)
7359
+ * @since 1.0.4
7360
+ *
7361
+ * @param bool|number $plugin_id
7362
+ * @param bool $flush Since 1.1.7.3
7363
+ *
7364
+ * @return object|false New plugin tag info if exist.
7365
+ */
7366
+ private function _fetch_newer_version( $plugin_id = false, $flush = true ) {
7367
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush );
7368
+
7369
+ if ( ! is_object( $latest_tag ) ) {
7370
+ return false;
7371
+ }
7372
+
7373
+ // Check if version is actually newer.
7374
+ $has_new_version =
7375
+ // If it's an non-installed add-on then always return latest.
7376
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
7377
+ // Compare versions.
7378
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
7379
+
7380
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
7381
+
7382
+ return $has_new_version ? $latest_tag : false;
7383
+ }
7384
+
7385
+ /**
7386
+ * @author Vova Feldman (@svovaf)
7387
+ * @since 1.0.5
7388
+ *
7389
+ * @param bool|number $plugin_id
7390
+ * @param bool $flush Since 1.1.7.3
7391
+ *
7392
+ * @return bool|FS_Plugin_Tag
7393
+ */
7394
+ function get_update( $plugin_id = false, $flush = true ) {
7395
+ $this->_logger->entrance();
7396
+
7397
+ if ( ! is_numeric( $plugin_id ) ) {
7398
+ $plugin_id = $this->_plugin->id;
7399
+ }
7400
+
7401
+ $this->_check_updates( true, $plugin_id, $flush );
7402
+ $updates = $this->get_all_updates();
7403
+
7404
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
7405
+ }
7406
+
7407
+ /**
7408
+ * Check if site assigned with active license.
7409
+ *
7410
+ * @author Vova Feldman (@svovaf)
7411
+ * @since 1.0.6
7412
+ */
7413
+ function has_active_license() {
7414
+ return (
7415
+ is_object( $this->_license ) &&
7416
+ is_numeric( $this->_license->id ) &&
7417
+ ! $this->_license->is_expired()
7418
+ );
7419
+ }
7420
+
7421
+ /**
7422
+ * Check if site assigned with license with enabled features.
7423
+ *
7424
+ * @author Vova Feldman (@svovaf)
7425
+ * @since 1.0.6
7426
+ *
7427
+ * @return bool
7428
+ */
7429
+ function has_features_enabled_license() {
7430
+ return (
7431
+ is_object( $this->_license ) &&
7432
+ is_numeric( $this->_license->id ) &&
7433
+ $this->_license->is_features_enabled()
7434
+ );
7435
+ }
7436
+
7437
+ /**
7438
+ * Check if user is a trial or have feature enabled license.
7439
+ *
7440
+ * @author Vova Feldman (@svovaf)
7441
+ * @since 1.1.7
7442
+ *
7443
+ * @return bool
7444
+ */
7445
+ function can_use_premium_code() {
7446
+ return $this->is_trial() || $this->has_features_enabled_license();
7447
+ }
7448
+
7449
+ /**
7450
+ * Sync site's plan.
7451
+ *
7452
+ * @author Vova Feldman (@svovaf)
7453
+ * @since 1.0.3
7454
+ *
7455
+ * @uses FS_Api
7456
+ *
7457
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7458
+ * the admin.
7459
+ */
7460
+ private function _sync_license( $background = false ) {
7461
+ $this->_logger->entrance();
7462
+
7463
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
7464
+
7465
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
7466
+
7467
+ if ( $is_addon_sync ) {
7468
+ $this->_sync_addon_license( $plugin_id, $background );
7469
+ } else {
7470
+ $this->_sync_plugin_license( $background );
7471
+ }
7472
+
7473
+ $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
7474
+ }
7475
+
7476
+ /**
7477
+ * Sync plugin's add-on license.
7478
+ *
7479
+ * @author Vova Feldman (@svovaf)
7480
+ * @since 1.0.6
7481
+ * @uses FS_Api
7482
+ *
7483
+ * @param number $addon_id
7484
+ * @param bool $background
7485
+ */
7486
+ private function _sync_addon_license( $addon_id, $background ) {
7487
+ $this->_logger->entrance();
7488
+
7489
+ if ( $this->is_addon_activated( $addon_id ) ) {
7490
+ // If already installed, use add-on sync.
7491
+ $fs_addon = self::get_instance_by_id( $addon_id );
7492
+ $fs_addon->_sync_license( $background );
7493
+
7494
+ return;
7495
+ }
7496
+
7497
+ // Validate add-on exists.
7498
+ $addon = $this->get_addon( $addon_id );
7499
+
7500
+ if ( ! is_object( $addon ) ) {
7501
+ return;
7502
+ }
7503
+
7504
+ // Add add-on into account add-ons.
7505
+ $account_addons = $this->get_account_addons();
7506
+ if ( ! is_array( $account_addons ) ) {
7507
+ $account_addons = array();
7508
+ }
7509
+ $account_addons[] = $addon->id;
7510
+ $account_addons = array_unique( $account_addons );
7511
+ $this->_store_account_addons( $account_addons );
7512
+
7513
+ // Load add-on licenses.
7514
+ $licenses = $this->_fetch_licenses( $addon->id );
7515
+
7516
+ // Sync add-on licenses.
7517
+ if ( ! isset( $licenses->error ) ) {
7518
+ $this->_update_licenses( $licenses, $addon->slug );
7519
+
7520
+ if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
7521
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
7522
+
7523
+ if ( ! isset( $plans_result->error ) ) {
7524
+ $plans = array();
7525
+ foreach ( $plans_result->plans as $plan ) {
7526
+ $plans[] = new FS_Plugin_Plan( $plan );
7527
+ }
7528
+
7529
+ $this->_admin_notices->add_sticky(
7530
+ FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
7531
+ sprintf(
7532
+ __fs( 'addon-successfully-upgraded-message', $this->_slug ),
7533
+ $addon->title
7534
+ ) . ' ' . $this->_get_latest_download_link(
7535
+ __fs( 'download-latest-version', $this->_slug ),
7536
+ $addon_id
7537
+ )
7538
+ :
7539
+ sprintf(
7540
+ __fs( 'addon-successfully-purchased-message', $this->_slug ),
7541
+ $addon->title
7542
+ ) . ' ' . $this->_get_latest_download_link(
7543
+ __fs( 'download-latest-version', $this->_slug ),
7544
+ $addon_id
7545
+ ),
7546
+ 'addon_plan_upgraded_' . $addon->slug,
7547
+ __fs( 'yee-haw', $this->_slug ) . '!'
7548
+ );
7549
+ }
7550
+ }
7551
+ }
7552
+ }
7553
+
7554
+ /**
7555
+ * Sync site's plugin plan.
7556
+ *
7557
+ * @author Vova Feldman (@svovaf)
7558
+ * @since 1.0.6
7559
+ * @uses FS_Api
7560
+ *
7561
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
7562
+ * the admin.
7563
+ */
7564
+ private function _sync_plugin_license( $background = false ) {
7565
+ $this->_logger->entrance();
7566
+
7567
+ // Sync site info.
7568
+ $site = $this->send_install_update( array(), true );
7569
+
7570
+ $plan_change = 'none';
7571
+
7572
+ if ( $this->is_api_error( $site ) ) {
7573
+ // Show API messages only if not background sync or if paying customer.
7574
+ if ( ! $background || $this->is_paying() ) {
7575
+ // Try to ping API to see if not blocked.
7576
+ if ( ! FS_Api::test() ) {
7577
+ /**
7578
+ * Failed to ping API - blocked!
7579
+ *
7580
+ * @author Vova Feldman (@svovaf)
7581
+ * @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.
7582
+ */
7583
+ $api = $this->get_api_site_scope();
7584
+
7585
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
7586
+ self::$_global_admin_notices->add(
7587
+ sprintf(
7588
+ __fs( 'server-blocking-access', $this->_slug ),
7589
+ $this->get_plugin_name(),
7590
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
7591
+ ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
7592
+ __fs( 'oops', $this->_slug ) . '...',
7593
+ 'error',
7594
+ $background,
7595
+ false,
7596
+ 'api_blocked'
7597
+ );
7598
+ }
7599
+ } else {
7600
+ // Authentication params are broken.
7601
+ $this->_admin_notices->add(
7602
+ __fs( 'wrong-authentication-param-message', $this->_slug ),
7603
+ __fs( 'oops', $this->_slug ) . '...',
7604
+ 'error'
7605
+ );
7606
+ }
7607
+ }
7608
+
7609
+ // No reason to continue with license sync while there are API issues.
7610
+ return;
7611
+ }
7612
+
7613
+ // Remove sticky API connectivity message.
7614
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
7615
+
7616
+ $site = new FS_Site( $site );
7617
+
7618
+ // Sync plans.
7619
+ $this->_sync_plans();
7620
+
7621
+ if ( ! $this->has_paid_plan() ) {
7622
+ $this->_site = $site;
7623
+ $this->_enrich_site_plan( true );
7624
+ $this->_store_site();
7625
+ } else {
7626
+ // Sync licenses.
7627
+ $this->_sync_licenses();
7628
+
7629
+ // Check if plan / license changed.
7630
+ if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
7631
+ // Check if trial started.
7632
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
7633
+ $site->trial_ends != $this->_site->trial_ends ||
7634
+ // Check if license changed.
7635
+ $site->license_id != $this->_site->license_id
7636
+ ) {
7637
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
7638
+ // New trial started.
7639
+ $this->_site = $site;
7640
+ $plan_change = 'trial_started';
7641
+
7642
+ // Store trial plan information.
7643
+ $this->_enrich_site_trial_plan( true );
7644
+
7645
+ // For trial with subscription use-case.
7646
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
7647
+
7648
+ if ( is_object( $new_license ) && ! $new_license->is_expired() ) {
7649
+ $this->_site = $site;
7650
+ $this->_update_site_license( $new_license );
7651
+ $this->_store_licenses();
7652
+ $this->_enrich_site_plan( true );
7653
+
7654
+ $this->_sync_site_subscription( $this->_license );
7655
+ }
7656
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
7657
+ // Was in trial, but now trial expired and no license ID.
7658
+ // New trial started.
7659
+ $this->_site = $site;
7660
+ $plan_change = 'trial_expired';
7661
+
7662
+ // Clear trial plan information.
7663
+ $this->_storage->trial_plan = null;
7664
+
7665
+ } else {
7666
+ $is_free = $this->is_free_plan();
7667
+
7668
+ // Make sure license exist and not expired.
7669
+ $new_license = is_null( $site->license_id ) ?
7670
+ null :
7671
+ $this->_get_license_by_id( $site->license_id );
7672
+
7673
+ if ( $is_free && is_null( $new_license ) && $this->has_license() && $this->_license->is_cancelled ) {
7674
+ // License cancelled.
7675
+ $this->_site = $site;
7676
+ $this->_update_site_license( $new_license );
7677
+ $this->_store_licenses();
7678
+ $this->_enrich_site_plan( true );
7679
+
7680
+ $plan_change = 'cancelled';
7681
+ } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
7682
+ // The license is expired, so ignore upgrade method.
7683
+ } else {
7684
+ // License changed.
7685
+ $this->_site = $site;
7686
+ $this->_update_site_license( $new_license );
7687
+ $this->_store_licenses();
7688
+ $this->_enrich_site_plan( true );
7689
+
7690
+ $plan_change = $is_free ?
7691
+ 'upgraded' :
7692
+ ( is_object( $new_license ) ?
7693
+ 'changed' :
7694
+ 'downgraded' );
7695
+ }
7696
+ }
7697
+
7698
+ // Store updated site info.
7699
+ $this->_store_site();
7700
+ } else {
7701
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
7702
+ if ( ! $this->has_features_enabled_license() ) {
7703
+ $this->_deactivate_license();
7704
+ $plan_change = 'downgraded';
7705
+ } else {
7706
+ $plan_change = 'expired';
7707
+ }
7708
+ }
7709
+
7710
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
7711
+ $this->_sync_site_subscription( $this->_license );
7712
+ }
7713
+ }
7714
+ }
7715
+
7716
+ if ( $this->has_paid_plan() ) {
7717
+ switch ( $plan_change ) {
7718
+ case 'none':
7719
+ if ( ! $background && is_admin() ) {
7720
+ $plan = $this->is_trial() ?
7721
+ $this->_storage->trial_plan :
7722
+ $this->_site->plan;
7723
+
7724
+ $this->_admin_notices->add(
7725
+ sprintf(
7726
+ __fs( 'plan-did-not-change-message', $this->_slug ) . ' ' .
7727
+ sprintf(
7728
+ '<a href="%s">%s</a>',
7729
+ $this->contact_url(
7730
+ 'bug',
7731
+ sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
7732
+ strtoupper( $plan->name )
7733
+ )
7734
+ ),
7735
+ __fs( 'contact-us-here', $this->_slug )
7736
+ ),
7737
+ '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . __fs( 'trial', $this->_slug ) : '' ) . '</b></i>'
7738
+ ),
7739
+ __fs( 'hmm', $this->_slug ) . '...'
7740
+ );
7741
+ }
7742
+ break;
7743
+ case 'upgraded':
7744
+ $this->_admin_notices->add_sticky(
7745
+ sprintf(
7746
+ __fs( 'plan-upgraded-message', $this->_slug ),
7747
+ '<i>' . $this->get_plugin_name() . '</i>'
7748
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7749
+ __fs( 'download-latest-x-version', $this->_slug ),
7750
+ $this->_site->plan->title
7751
+ ) )
7752
+ ),
7753
+ 'plan_upgraded',
7754
+ __fs( 'yee-haw', $this->_slug ) . '!'
7755
+ );
7756
+
7757
+ $this->_admin_notices->remove_sticky( array(
7758
+ 'trial_started',
7759
+ 'trial_promotion',
7760
+ 'trial_expired',
7761
+ 'activation_complete',
7762
+ ) );
7763
+ break;
7764
+ case 'changed':
7765
+ $this->_admin_notices->add_sticky(
7766
+ sprintf(
7767
+ __fs( 'plan-changed-to-x-message', $this->_slug ),
7768
+ $this->_site->plan->title
7769
+ ),
7770
+ 'plan_changed'
7771
+ );
7772
+
7773
+ $this->_admin_notices->remove_sticky( array(
7774
+ 'trial_started',
7775
+ 'trial_promotion',
7776
+ 'trial_expired',
7777
+ 'activation_complete',
7778
+ ) );
7779
+ break;
7780
+ case 'downgraded':
7781
+ $this->_admin_notices->add_sticky(
7782
+ sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
7783
+ 'license_expired',
7784
+ __fs( 'hmm', $this->_slug ) . '...'
7785
+ );
7786
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7787
+ break;
7788
+ case 'cancelled':
7789
+ $this->_admin_notices->add(
7790
+ __fs( 'license-cancelled', $this->_slug ) . ' ' .
7791
+ sprintf(
7792
+ '<a href="%s">%s</a>',
7793
+ $this->contact_url( 'bug' ),
7794
+ __fs( 'contact-us-here', $this->_slug )
7795
+ ),
7796
+ __fs( 'hmm', $this->_slug ) . '...',
7797
+ 'error'
7798
+ );
7799
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7800
+ break;
7801
+ case 'expired':
7802
+ $this->_admin_notices->add_sticky(
7803
+ sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
7804
+ 'license_expired',
7805
+ __fs( 'hmm', $this->_slug ) . '...'
7806
+ );
7807
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
7808
+ break;
7809
+ case 'trial_started':
7810
+ $this->_admin_notices->add_sticky(
7811
+ sprintf(
7812
+ __fs( 'trial-started-message', $this->_slug ),
7813
+ '<i>' . $this->get_plugin_name() . '</i>'
7814
+ ) . ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7815
+ __fs( 'download-latest-x-version', $this->_slug ),
7816
+ $this->_storage->trial_plan->title
7817
+ ) ) ),
7818
+ 'trial_started',
7819
+ __fs( 'yee-haw', $this->_slug ) . '!'
7820
+ );
7821
+
7822
+ $this->_admin_notices->remove_sticky( array(
7823
+ 'trial_promotion',
7824
+ ) );
7825
+ break;
7826
+ case 'trial_expired':
7827
+ $this->_admin_notices->add_sticky(
7828
+ __fs( 'trial-expired-message', $this->_slug ),
7829
+ 'trial_expired',
7830
+ __fs( 'hmm', $this->_slug ) . '...'
7831
+ );
7832
+ $this->_admin_notices->remove_sticky( array(
7833
+ 'trial_started',
7834
+ 'trial_promotion',
7835
+ 'plan_upgraded',
7836
+ ) );
7837
+ break;
7838
+ }
7839
+ }
7840
+
7841
+ if ( 'none' !== $plan_change ) {
7842
+ $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
7843
+ }
7844
+ }
7845
+
7846
+ /**
7847
+ * @author Vova Feldman (@svovaf)
7848
+ * @since 1.0.5
7849
+ *
7850
+ * @param bool $background
7851
+ */
7852
+ protected function _activate_license( $background = false ) {
7853
+ $this->_logger->entrance();
7854
+
7855
+ $license_id = fs_request_get( 'license_id' );
7856
+
7857
+ if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
7858
+ // License is already activated.
7859
+ return;
7860
+ }
7861
+
7862
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
7863
+ $this->_get_license_by_id( $license_id ) :
7864
+ $this->_get_available_premium_license();
7865
+
7866
+ if ( ! is_object( $premium_license ) ) {
7867
+ return;
7868
+ }
7869
+
7870
+ /**
7871
+ * If the premium license is already associated with the install, just
7872
+ * update the license reference (activation is not required).
7873
+ *
7874
+ * @since 1.1.9
7875
+ */
7876
+ if ( $premium_license->id == $this->_site->license_id ) {
7877
+ // License is already activated.
7878
+ $this->_update_site_license( $premium_license );
7879
+ $this->_enrich_site_plan( false );
7880
+ $this->_store_account();
7881
+
7882
+ return;
7883
+ }
7884
+
7885
+ $api = $this->get_api_site_scope();
7886
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put' );
7887
+
7888
+ if ( $this->is_api_error( $license ) ) {
7889
+ if ( ! $background ) {
7890
+ $this->_admin_notices->add(
7891
+ __fs( 'license-activation-failed-message', $this->_slug ) . '<br> ' .
7892
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license, true ),
7893
+ __fs( 'hmm', $this->_slug ) . '...',
7894
+ 'error'
7895
+ );
7896
+ }
7897
+
7898
+ return;
7899
+ }
7900
+
7901
+ $premium_license = new FS_Plugin_License( $license );
7902
+
7903
+ // Updated site plan.
7904
+ $site = $this->get_api_site_scope()->get( '/', true );
7905
+ if ( ! $this->is_api_error( $site ) ) {
7906
+ $this->_site = new FS_Site( $site );
7907
+ }
7908
+ $this->_update_site_license( $premium_license );
7909
+ $this->_enrich_site_plan( false );
7910
+
7911
+ $this->_store_account();
7912
+
7913
+ if ( ! $background ) {
7914
+ $this->_admin_notices->add_sticky(
7915
+ __fs( 'license-activated-message', $this->_slug ) .
7916
+ ( $this->is_premium() ? '' : ' ' . $this->_get_latest_download_link( sprintf(
7917
+ __fs( 'download-latest-x-version', $this->_slug ),
7918
+ $this->_site->plan->title
7919
+ ) ) ),
7920
+ 'license_activated',
7921
+ __fs( 'yee-haw', $this->_slug ) . '!'
7922
+ );
7923
+ }
7924
+
7925
+ $this->_admin_notices->remove_sticky( array(
7926
+ 'trial_promotion',
7927
+ 'license_expired',
7928
+ ) );
7929
+ }
7930
+
7931
+ /**
7932
+ * @author Vova Feldman (@svovaf)
7933
+ * @since 1.0.5
7934
+ *
7935
+ * @param bool $show_notice
7936
+ */
7937
+ protected function _deactivate_license( $show_notice = true ) {
7938
+ $this->_logger->entrance();
7939
+
7940
+ if ( ! is_object( $this->_license ) ) {
7941
+ $this->_admin_notices->add(
7942
+ sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
7943
+ __fs( 'hmm', $this->_slug ) . '...'
7944
+ );
7945
+
7946
+ return;
7947
+ }
7948
+
7949
+ $api = $this->get_api_site_scope();
7950
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
7951
+
7952
+ if ( isset( $license->error ) ) {
7953
+ $this->_admin_notices->add(
7954
+ __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
7955
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
7956
+ __fs( 'hmm', $this->_slug ) . '...',
7957
+ 'error'
7958
+ );
7959
+
7960
+ return;
7961
+ }
7962
+
7963
+ // Update license cache.
7964
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
7965
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
7966
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
7967
+ }
7968
+ }
7969
+
7970
+ // Updated site plan to default.
7971
+ $this->_sync_plans();
7972
+ $this->_site->plan->id = $this->_plans[0]->id;
7973
+ // Unlink license from site.
7974
+ $this->_update_site_license( null );
7975
+ $this->_enrich_site_plan( false );
7976
+
7977
+ $this->_store_account();
7978
+
7979
+ if ( $show_notice ) {
7980
+ $this->_admin_notices->add(
7981
+ sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
7982
+ __fs( 'ok', $this->_slug )
7983
+ );
7984
+ }
7985
+
7986
+ $this->_admin_notices->remove_sticky( array(
7987
+ 'plan_upgraded',
7988
+ 'license_activated',
7989
+ ) );
7990
+ }
7991
+
7992
+ /**
7993
+ * Site plan downgrade.
7994
+ *
7995
+ * @author Vova Feldman (@svovaf)
7996
+ * @since 1.0.4
7997
+ *
7998
+ * @uses FS_Api
7999
+ */
8000
+ private function _downgrade_site() {
8001
+ $this->_logger->entrance();
8002
+
8003
+ $api = $this->get_api_site_scope();
8004
+ $site = $api->call( 'downgrade.json', 'put' );
8005
+
8006
+ $plan_downgraded = false;
8007
+ $plan = false;
8008
+ if ( ! isset( $site->error ) ) {
8009
+ $prev_plan_id = $this->_site->plan->id;
8010
+
8011
+ // Update new site plan id.
8012
+ $this->_site->plan->id = $site->plan_id;
8013
+
8014
+ $plan = $this->_enrich_site_plan();
8015
+ $subscription = $this->_sync_site_subscription( $this->_license );
8016
+
8017
+ // Plan downgraded if plan was changed or subscription was cancelled.
8018
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
8019
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
8020
+ } else {
8021
+ // handle different error cases.
8022
+
8023
+ }
8024
+
8025
+ if ( $plan_downgraded ) {
8026
+ // Remove previous sticky message about upgrade (if exist).
8027
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8028
+
8029
+ $this->_admin_notices->add(
8030
+ sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
8031
+ $plan->title,
8032
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
8033
+ )
8034
+ );
8035
+
8036
+ // Store site updates.
8037
+ $this->_store_site();
8038
+ } else {
8039
+ $this->_admin_notices->add(
8040
+ __fs( 'plan-downgraded-failure-message', $this->_slug ),
8041
+ __fs( 'oops', $this->_slug ) . '...',
8042
+ 'error'
8043
+ );
8044
+ }
8045
+ }
8046
+
8047
+ /**
8048
+ * @author Vova Feldman (@svovaf)
8049
+ * @since 1.1.8.1
8050
+ *
8051
+ * @param bool|string $plan_name
8052
+ *
8053
+ * @return bool If trial was successfully started.
8054
+ */
8055
+ function start_trial( $plan_name = false ) {
8056
+ $this->_logger->entrance();
8057
+
8058
+ if ( $this->is_trial() ) {
8059
+ // Already in trial mode.
8060
+ $this->_admin_notices->add(
8061
+ __fs( 'in-trial-mode', $this->_slug ),
8062
+ __fs( 'oops', $this->_slug ) . '...',
8063
+ 'error'
8064
+ );
8065
+
8066
+ return false;
8067
+ }
8068
+
8069
+ if ( $this->_site->is_trial_utilized() ) {
8070
+ // Trial was already utilized.
8071
+ $this->_admin_notices->add(
8072
+ __fs( 'trial-utilized', $this->_slug ),
8073
+ __fs( 'oops', $this->_slug ) . '...',
8074
+ 'error'
8075
+ );
8076
+
8077
+ return false;
8078
+ }
8079
+
8080
+ if ( false !== $plan_name ) {
8081
+ $plan = $this->get_plan_by_name( $plan_name );
8082
+
8083
+ if ( false === $plan ) {
8084
+ // Plan doesn't exist.
8085
+ $this->_admin_notices->add(
8086
+ sprintf( __fs( 'trial-plan-x-not-exist', $this->_slug ), $plan_name ),
8087
+ __fs( 'oops', $this->_slug ) . '...',
8088
+ 'error'
8089
+ );
8090
+
8091
+ return false;
8092
+ }
8093
+
8094
+ if ( ! $plan->has_trial() ) {
8095
+ // Plan doesn't exist.
8096
+ $this->_admin_notices->add(
8097
+ sprintf( __fs( 'plan-x-no-trial', $this->_slug ), $plan_name ),
8098
+ __fs( 'oops', $this->_slug ) . '...',
8099
+ 'error'
8100
+ );
8101
+
8102
+ return false;
8103
+ }
8104
+ } else {
8105
+ if ( ! $this->has_trial_plan() ) {
8106
+ // None of the plans have a trial.
8107
+ $this->_admin_notices->add(
8108
+ __fs( 'no-trials', $this->_slug ),
8109
+ __fs( 'oops', $this->_slug ) . '...',
8110
+ 'error'
8111
+ );
8112
+
8113
+ return false;
8114
+ }
8115
+
8116
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
8117
+
8118
+ $plan = $plans_with_trial[0];
8119
+ }
8120
+
8121
+ $api = $this->get_api_site_scope();
8122
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
8123
+
8124
+ if ( $this->is_api_error( $plan ) ) {
8125
+ // Some API error while trying to start the trial.
8126
+ $this->_admin_notices->add(
8127
+ __fs( 'unexpected-api-error', $this->_slug ) . ' ' . var_export( $plan, true ),
8128
+ __fs( 'oops', $this->_slug ) . '...',
8129
+ 'error'
8130
+ );
8131
+
8132
+ return false;
8133
+ }
8134
+
8135
+ // Sync license.
8136
+ $this->_sync_license();
8137
+
8138
+ return $this->is_trial();
8139
+ }
8140
+
8141
+ /**
8142
+ * Cancel site trial.
8143
+ *
8144
+ * @author Vova Feldman (@svovaf)
8145
+ * @since 1.0.9
8146
+ *
8147
+ * @uses FS_Api
8148
+ */
8149
+ private function _cancel_trial() {
8150
+ $this->_logger->entrance();
8151
+
8152
+ if ( ! $this->is_trial() ) {
8153
+ $this->_admin_notices->add(
8154
+ __fs( 'trial-cancel-no-trial-message', $this->_slug ),
8155
+ __fs( 'oops', $this->_slug ) . '...',
8156
+ 'error'
8157
+ );
8158
+
8159
+ return;
8160
+ }
8161
+
8162
+ $api = $this->get_api_site_scope();
8163
+ $site = $api->call( 'trials.json', 'delete' );
8164
+
8165
+ $trial_cancelled = false;
8166
+
8167
+ if ( ! $this->is_api_error( $site ) ) {
8168
+ $prev_trial_ends = $this->_site->trial_ends;
8169
+
8170
+ if ( $this->is_paid_trial() ) {
8171
+ $this->_license->expiration = $site->trial_ends;
8172
+ $this->_license->is_cancelled = true;
8173
+ $this->_update_site_license( $this->_license );
8174
+ $this->_store_licenses();
8175
+
8176
+ // Clear subscription reference.
8177
+ $this->_sync_site_subscription( null );
8178
+ }
8179
+
8180
+ // Update site info.
8181
+ $this->_site = new FS_Site( $site );
8182
+ $this->_enrich_site_plan();
8183
+
8184
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
8185
+ } else {
8186
+ // handle different error cases.
8187
+
8188
+ }
8189
+
8190
+ if ( $trial_cancelled ) {
8191
+ // Remove previous sticky messages about upgrade or trial (if exist).
8192
+ $this->_admin_notices->remove_sticky( array(
8193
+ 'trial_started',
8194
+ 'trial_promotion',
8195
+ 'plan_upgraded',
8196
+ ) );
8197
+
8198
+ // Store site updates.
8199
+ $this->_store_site();
8200
+
8201
+ // Clear trial plan information.
8202
+ unset( $this->_storage->trial_plan );
8203
+
8204
+ if ( ! $this->is_addon() ||
8205
+ ! $this->deactivate_premium_only_addon_without_license( true )
8206
+ ) {
8207
+ $this->_admin_notices->add(
8208
+ sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
8209
+ );
8210
+ }
8211
+ } else {
8212
+ $this->_admin_notices->add(
8213
+ __fs( 'trial-cancel-failure-message', $this->_slug ),
8214
+ __fs( 'oops', $this->_slug ) . '...',
8215
+ 'error'
8216
+ );
8217
+ }
8218
+ }
8219
+
8220
+ /**
8221
+ * @author Vova Feldman (@svovaf)
8222
+ * @since 1.0.6
8223
+ *
8224
+ * @param bool|number $plugin_id
8225
+ *
8226
+ * @return bool
8227
+ */
8228
+ private function _is_addon_id( $plugin_id ) {
8229
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
8230
+ }
8231
+
8232
+ /**
8233
+ * Check if user eligible to download premium version updates.
8234
+ *
8235
+ * @author Vova Feldman (@svovaf)
8236
+ * @since 1.0.6
8237
+ *
8238
+ * @return bool
8239
+ */
8240
+ private function _can_download_premium() {
8241
+ return $this->has_active_license() ||
8242
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
8243
+ }
8244
+
8245
+ /**
8246
+ *
8247
+ * @author Vova Feldman (@svovaf)
8248
+ * @since 1.0.6
8249
+ *
8250
+ * @param bool|number $addon_id
8251
+ * @param string $type "json" or "zip"
8252
+ *
8253
+ * @return string
8254
+ */
8255
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
8256
+
8257
+ $is_addon = $this->_is_addon_id( $addon_id );
8258
+
8259
+ $is_premium = null;
8260
+ if ( ! $is_addon ) {
8261
+ $is_premium = $this->_can_download_premium();
8262
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
8263
+ $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
8264
+ }
8265
+
8266
+ return // If add-on, then append add-on ID.
8267
+ ( $is_addon ? "/addons/$addon_id" : '' ) .
8268
+ '/updates/latest.' . $type .
8269
+ // If add-on and not yet activated, try to fetch based on server licensing.
8270
+ ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
8271
+ }
8272
+
8273
+ /**
8274
+ * @author Vova Feldman (@svovaf)
8275
+ * @since 1.0.4
8276
+ *
8277
+ * @param bool|number $addon_id
8278
+ * @param bool $flush Since 1.1.7.3
8279
+ *
8280
+ * @return object|false Plugin latest tag info.
8281
+ */
8282
+ function _fetch_latest_version( $addon_id = false, $flush = true ) {
8283
+ $this->_logger->entrance();
8284
+
8285
+ /**
8286
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
8287
+ * @since 1.1.7.4 Also check updates for add-ons.
8288
+ */
8289
+ if ( ! $this->is_registered() &&
8290
+ ! $this->_is_addon_id( $addon_id )
8291
+ ) {
8292
+ return false;
8293
+ }
8294
+
8295
+ $tag = $this->get_api_site_or_plugin_scope()->get(
8296
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
8297
+ $flush
8298
+ );
8299
+
8300
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
8301
+
8302
+ $this->_logger->departure( 'Latest version ' . $latest_version );
8303
+
8304
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
8305
+ }
8306
+
8307
+ #region Download Plugin ------------------------------------------------------------------
8308
+
8309
+ /**
8310
+ * Download latest plugin version, based on plan.
8311
+ * The download will be fetched via the API first.
8312
+ *
8313
+ * @author Vova Feldman (@svovaf)
8314
+ * @since 1.0.4
8315
+ *
8316
+ * @param bool|number $plugin_id
8317
+ *
8318
+ * @uses FS_Api
8319
+ *
8320
+ * @deprecated
8321
+ */
8322
+ private function _download_latest( $plugin_id = false ) {
8323
+ $this->_logger->entrance();
8324
+
8325
+ $is_addon = $this->_is_addon_id( $plugin_id );
8326
+
8327
+ $is_premium = $this->_can_download_premium();
8328
+
8329
+ $latest = $this->get_api_site_scope()->call(
8330
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8331
+ );
8332
+
8333
+ $slug = $this->_slug;
8334
+ if ( $is_addon ) {
8335
+ $addon = $this->get_addon( $plugin_id );
8336
+ $slug = is_object( $addon ) ? $addon->slug : 'addon';
8337
+ }
8338
+
8339
+ if ( ! is_object( $latest ) ) {
8340
+ header( "Content-Type: application/zip" );
8341
+ header( "Content-Disposition: attachment; filename={$slug}" . ( ! $is_addon && $is_premium ? '-premium' : '' ) . ".zip" );
8342
+ header( "Content-Length: " . strlen( $latest ) );
8343
+ echo $latest;
8344
+
8345
+ exit();
8346
+ }
8347
+ }
8348
+
8349
+ /**
8350
+ * Download latest plugin version, based on plan.
8351
+ *
8352
+ * Not like _download_latest(), this will redirect the page
8353
+ * to secure download url to prevent dual download (from FS to WP server,
8354
+ * and then from WP server to the client / browser).
8355
+ *
8356
+ * @author Vova Feldman (@svovaf)
8357
+ * @since 1.0.9
8358
+ *
8359
+ * @param bool|number $plugin_id
8360
+ *
8361
+ * @uses FS_Api
8362
+ * @uses wp_redirect()
8363
+ */
8364
+ private function _download_latest_directly( $plugin_id = false ) {
8365
+ $this->_logger->entrance();
8366
+
8367
+ wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
8368
+ }
8369
+
8370
+ /**
8371
+ * Get latest plugin FS API download URL.
8372
+ *
8373
+ * @author Vova Feldman (@svovaf)
8374
+ * @since 1.0.9
8375
+ *
8376
+ * @param bool|number $plugin_id
8377
+ *
8378
+ * @return string
8379
+ */
8380
+ private function _get_latest_download_api_url( $plugin_id = false ) {
8381
+ $this->_logger->entrance();
8382
+
8383
+ return $this->get_api_site_scope()->get_signed_url(
8384
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8385
+ );
8386
+ }
8387
+
8388
+ /**
8389
+ * Get latest plugin download link.
8390
+ *
8391
+ * @author Vova Feldman (@svovaf)
8392
+ * @since 1.0.9
8393
+ *
8394
+ * @param string $label
8395
+ * @param bool|number $plugin_id
8396
+ *
8397
+ * @return string
8398
+ */
8399
+ private function _get_latest_download_link( $label, $plugin_id = false ) {
8400
+ return sprintf(
8401
+ '<a target="_blank" href="%s">%s</a>',
8402
+ $this->_get_latest_download_local_url( $plugin_id ),
8403
+ $label
8404
+ );
8405
+ }
8406
+
8407
+ /**
8408
+ * Get latest plugin download local URL.
8409
+ *
8410
+ * @author Vova Feldman (@svovaf)
8411
+ * @since 1.0.9
8412
+ *
8413
+ * @param bool|number $plugin_id
8414
+ *
8415
+ * @return string
8416
+ */
8417
+ function _get_latest_download_local_url( $plugin_id = false ) {
8418
+ // Add timestamp to protect from caching.
8419
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
8420
+
8421
+ if ( ! empty( $plugin_id ) ) {
8422
+ $params['plugin_id'] = $plugin_id;
8423
+ }
8424
+
8425
+ return $this->get_account_url( 'download_latest', $params );
8426
+ }
8427
+
8428
+ #endregion Download Plugin ------------------------------------------------------------------
8429
+
8430
+ /**
8431
+ * @author Vova Feldman (@svovaf)
8432
+ * @since 1.0.4
8433
+ *
8434
+ * @uses FS_Api
8435
+ *
8436
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
8437
+ * was initiated by the admin.
8438
+ * @param bool|number $plugin_id
8439
+ * @param bool $flush Since 1.1.7.3
8440
+ */
8441
+ private function _check_updates( $background = false, $plugin_id = false, $flush = true ) {
8442
+ $this->_logger->entrance();
8443
+
8444
+ // Check if there's a newer version for download.
8445
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush );
8446
+
8447
+ $update = null;
8448
+ if ( is_object( $new_version ) ) {
8449
+ $update = new FS_Plugin_Tag( $new_version );
8450
+
8451
+ if ( ! $background ) {
8452
+ $this->_admin_notices->add(
8453
+ sprintf(
8454
+ __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
8455
+ $update->version,
8456
+ sprintf(
8457
+ '<a href="%s" target="_blank">%s</a>',
8458
+ $this->get_account_url( 'download_latest' ),
8459
+ sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
8460
+ )
8461
+ ),
8462
+ __fs( 'new', $this->_slug ) . '!'
8463
+ );
8464
+ }
8465
+ } else if ( false === $new_version && ! $background ) {
8466
+ $this->_admin_notices->add(
8467
+ __fs( 'you-have-latest', $this->_slug ),
8468
+ __fs( 'you-are-good', $this->_slug )
8469
+ );
8470
+ }
8471
+
8472
+ $this->_store_update( $update, true, $plugin_id );
8473
+ }
8474
+
8475
+ /**
8476
+ * @author Vova Feldman (@svovaf)
8477
+ * @since 1.0.4
8478
+ *
8479
+ * @param bool $flush Since 1.1.7.3 by default add 24 hour cache.
8480
+ *
8481
+ * @return FS_Plugin[]
8482
+ *
8483
+ * @uses FS_Api
8484
+ */
8485
+ private function _sync_addons( $flush = false ) {
8486
+ $this->_logger->entrance();
8487
+
8488
+ $result = $this->get_api_site_or_plugin_scope()->get( '/addons.json?enriched=true', $flush );
8489
+
8490
+ $addons = array();
8491
+ if ( ! $this->is_api_error( $result ) ) {
8492
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
8493
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
8494
+ }
8495
+
8496
+ $this->_store_addons( $addons, true );
8497
+ }
8498
+
8499
+ return $addons;
8500
+ }
8501
+
8502
+ /**
8503
+ * Handle user email update.
8504
+ *
8505
+ * @author Vova Feldman (@svovaf)
8506
+ * @since 1.0.3
8507
+ * @uses FS_Api
8508
+ *
8509
+ * @param string $new_email
8510
+ *
8511
+ * @return object
8512
+ */
8513
+ private function _update_email( $new_email ) {
8514
+ $this->_logger->entrance();
8515
+
8516
+
8517
+ $api = $this->get_api_user_scope();
8518
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
8519
+ 'email' => $new_email,
8520
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
8521
+ 'account',
8522
+ array( 'fs_action' => 'sync_user' )
8523
+ ),
8524
+ ) );
8525
+
8526
+ if ( ! isset( $user->error ) ) {
8527
+ $this->_user->email = $user->email;
8528
+ $this->_user->is_verified = $user->is_verified;
8529
+ $this->_store_user();
8530
+ } else {
8531
+ // handle different error cases.
8532
+
8533
+ }
8534
+
8535
+ return $user;
8536
+ }
8537
+
8538
+ /**
8539
+ * @author Vova Feldman (@svovaf)
8540
+ * @since 1.1.1
8541
+ *
8542
+ * @param mixed $result
8543
+ *
8544
+ * @return bool Is API result contains an error.
8545
+ */
8546
+ private function is_api_error( $result ) {
8547
+ return ( is_object( $result ) && isset( $result->error ) ) ||
8548
+ is_string( $result );
8549
+ }
8550
+
8551
+ /**
8552
+ * Start install ownership change.
8553
+ *
8554
+ * @author Vova Feldman (@svovaf)
8555
+ * @since 1.1.1
8556
+ * @uses FS_Api
8557
+ *
8558
+ * @param string $candidate_email
8559
+ *
8560
+ * @return bool Is ownership change successfully initiated.
8561
+ */
8562
+ private function init_change_owner( $candidate_email ) {
8563
+ $this->_logger->entrance();
8564
+
8565
+ $api = $this->get_api_site_scope();
8566
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
8567
+ 'email' => $candidate_email,
8568
+ 'after_confirm_url' => $this->_get_admin_page_url(
8569
+ 'account',
8570
+ array( 'fs_action' => 'change_owner' )
8571
+ ),
8572
+ ) );
8573
+
8574
+ return ! $this->is_api_error( $result );
8575
+ }
8576
+
8577
+ /**
8578
+ * Handle install ownership change.
8579
+ *
8580
+ * @author Vova Feldman (@svovaf)
8581
+ * @since 1.1.1
8582
+ * @uses FS_Api
8583
+ *
8584
+ * @return bool Was ownership change successfully complete.
8585
+ */
8586
+ private function complete_change_owner() {
8587
+ $this->_logger->entrance();
8588
+
8589
+ $site_result = $this->get_api_site_scope( true )->get();
8590
+ $site = new FS_Site( $site_result );
8591
+ $this->_site = $site;
8592
+
8593
+ $user = new FS_User();
8594
+ $user->id = fs_request_get( 'user_id' );
8595
+
8596
+ // Validate install's user and given user.
8597
+ if ( $user->id != $this->_site->user_id ) {
8598
+ return false;
8599
+ }
8600
+
8601
+ $user->public_key = fs_request_get( 'user_public_key' );
8602
+ $user->secret_key = fs_request_get( 'user_secret_key' );
8603
+
8604
+ // Fetch new user information.
8605
+ $this->_user = $user;
8606
+ $user_result = $this->get_api_user_scope( true )->get();
8607
+ $user = new FS_User( $user_result );
8608
+ $this->_user = $user;
8609
+
8610
+ $this->_set_account( $user, $site );
8611
+
8612
+ return true;
8613
+ }
8614
+
8615
+ /**
8616
+ * Handle user name update.
8617
+ *
8618
+ * @author Vova Feldman (@svovaf)
8619
+ * @since 1.0.9
8620
+ * @uses FS_Api
8621
+ *
8622
+ * @return object
8623
+ */
8624
+ private function update_user_name() {
8625
+ $this->_logger->entrance();
8626
+ $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
8627
+
8628
+ $api = $this->get_api_user_scope();
8629
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
8630
+ 'name' => $name,
8631
+ ) );
8632
+
8633
+ if ( ! isset( $user->error ) ) {
8634
+ $this->_user->first = $user->first;
8635
+ $this->_user->last = $user->last;
8636
+ $this->_store_user();
8637
+ } else {
8638
+ // handle different error cases.
8639
+
8640
+ }
8641
+
8642
+ return $user;
8643
+ }
8644
+
8645
+ /**
8646
+ * Verify user email.
8647
+ *
8648
+ * @author Vova Feldman (@svovaf)
8649
+ * @since 1.0.3
8650
+ * @uses FS_Api
8651
+ */
8652
+ private function verify_email() {
8653
+ $this->_handle_account_user_sync();
8654
+
8655
+ if ( $this->_user->is_verified() ) {
8656
+ return;
8657
+ }
8658
+
8659
+ $api = $this->get_api_site_scope();
8660
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
8661
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
8662
+ 'account',
8663
+ array( 'fs_action' => 'sync_user' )
8664
+ )
8665
+ ) );
8666
+
8667
+ if ( ! isset( $result->error ) ) {
8668
+ $this->_admin_notices->add( sprintf(
8669
+ __fs( 'verification-email-sent-message', $this->_slug ),
8670
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
8671
+ ) );
8672
+ } else {
8673
+ // handle different error cases.
8674
+
8675
+ }
8676
+ }
8677
+
8678
+ /**
8679
+ * @author Vova Feldman (@svovaf)
8680
+ * @since 1.1.2
8681
+ *
8682
+ * @return string
8683
+ */
8684
+ private function get_activation_url() {
8685
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url() );
8686
+ }
8687
+
8688
+ /**
8689
+ * Get the URL of the page that should be loaded after the user connect or skip in the opt-in screen.
8690
+ *
8691
+ * @author Vova Feldman (@svovaf)
8692
+ * @since 1.1.3
8693
+ *
8694
+ * @param string $filter Filter name.
8695
+ *
8696
+ * @return string
8697
+ */
8698
+ private function get_after_activation_url( $filter ) {
8699
+ $first_time_path = $this->_menu->get_first_time_path();
8700
+
8701
+ return $this->apply_filters(
8702
+ $filter,
8703
+ empty( $first_time_path ) ?
8704
+ $this->_get_admin_page_url() :
8705
+ $first_time_path
8706
+ );
8707
+ }
8708
+
8709
+ /**
8710
+ * Handle account page updates / edits / actions.
8711
+ *
8712
+ * @author Vova Feldman (@svovaf)
8713
+ * @since 1.0.2
8714
+ *
8715
+ */
8716
+ private function _handle_account_edits() {
8717
+ if ( ! current_user_can( 'activate_plugins' ) ) {
8718
+ return;
8719
+ }
8720
+
8721
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
8722
+ $action = fs_get_action();
8723
+
8724
+ switch ( $action ) {
8725
+ case 'delete_account':
8726
+ check_admin_referer( $action );
8727
+
8728
+ if ( $plugin_id == $this->get_id() ) {
8729
+ $this->delete_account_event();
8730
+
8731
+ // Clear user and site.
8732
+ $this->_site = null;
8733
+ $this->_user = null;
8734
+
8735
+ if ( fs_redirect( $this->get_activation_url() ) ) {
8736
+ exit();
8737
+ }
8738
+ } else {
8739
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8740
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8741
+ $fs_addon->delete_account_event();
8742
+
8743
+ if ( fs_redirect( $this->_get_admin_page_url( 'account' ) ) ) {
8744
+ exit();
8745
+ }
8746
+ }
8747
+ }
8748
+
8749
+ return;
8750
+
8751
+ case 'downgrade_account':
8752
+ check_admin_referer( $action );
8753
+ $this->_downgrade_site();
8754
+
8755
+ return;
8756
+
8757
+ case 'activate_license':
8758
+ check_admin_referer( $action );
8759
+
8760
+ if ( $plugin_id == $this->get_id() ) {
8761
+ $this->_activate_license();
8762
+ } else {
8763
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8764
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8765
+ $fs_addon->_activate_license();
8766
+ }
8767
+ }
8768
+
8769
+ return;
8770
+
8771
+ case 'deactivate_license':
8772
+ check_admin_referer( $action );
8773
+
8774
+ if ( $plugin_id == $this->get_id() ) {
8775
+ $this->_deactivate_license();
8776
+ } else {
8777
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8778
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8779
+ $fs_addon->_deactivate_license();
8780
+ }
8781
+ }
8782
+
8783
+ return;
8784
+
8785
+ case 'check_updates':
8786
+ check_admin_referer( $action );
8787
+ $this->_check_updates();
8788
+
8789
+ return;
8790
+
8791
+ case 'change_owner':
8792
+ $state = fs_request_get( 'state', 'init' );
8793
+ switch ( $state ) {
8794
+ case 'init':
8795
+ $candidate_email = fs_request_get( 'candidate_email', '' );
8796
+
8797
+ if ( $this->init_change_owner( $candidate_email ) ) {
8798
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
8799
+ }
8800
+ break;
8801
+ case 'owner_confirmed':
8802
+ $candidate_email = fs_request_get( 'candidate_email', '' );
8803
+
8804
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
8805
+ break;
8806
+ case 'candidate_confirmed':
8807
+ if ( $this->complete_change_owner() ) {
8808
+ $this->_admin_notices->add_sticky(
8809
+ sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
8810
+ 'ownership_changed',
8811
+ __fs( 'congrats', $this->_slug ) . '!'
8812
+ );
8813
+ } else {
8814
+ // @todo Handle failed ownership change message.
8815
+ }
8816
+ break;
8817
+ }
8818
+
8819
+ return;
8820
+
8821
+ case 'update_email':
8822
+ check_admin_referer( 'update_email' );
8823
+
8824
+ $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
8825
+ $result = $this->_update_email( $new_email );
8826
+
8827
+ if ( isset( $result->error ) ) {
8828
+ switch ( $result->error->code ) {
8829
+ case 'user_exist':
8830
+ $this->_admin_notices->add(
8831
+ __fs( 'user-exist-message', $this->_slug ) . ' ' .
8832
+ sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
8833
+ sprintf(
8834
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
8835
+ $this->get_account_url( 'change_owner', array(
8836
+ 'state' => 'init',
8837
+ 'candidate_email' => $new_email
8838
+ ) ),
8839
+ __fs( 'change-ownership', $this->_slug )
8840
+ ),
8841
+ __fs( 'oops', $this->_slug ) . '...',
8842
+ 'error'
8843
+ );
8844
+ break;
8845
+ }
8846
+ } else {
8847
+ $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
8848
+ }
8849
+
8850
+ return;
8851
+
8852
+ case 'update_user_name':
8853
+ check_admin_referer( 'update_user_name' );
8854
+
8855
+ $result = $this->update_user_name();
8856
+
8857
+ if ( isset( $result->error ) ) {
8858
+ $this->_admin_notices->add(
8859
+ __fs( 'name-update-failed-message', $this->_slug ),
8860
+ __fs( 'oops', $this->_slug ) . '...',
8861
+ 'error'
8862
+ );
8863
+ } else {
8864
+ $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
8865
+ }
8866
+
8867
+ return;
8868
+
8869
+ #region Actions that might be called from external links (e.g. email)
8870
+
8871
+ case 'cancel_trial':
8872
+ if ( $plugin_id == $this->get_id() ) {
8873
+ $this->_cancel_trial();
8874
+ } else {
8875
+ if ( $this->is_addon_activated( $plugin_id ) ) {
8876
+ $fs_addon = self::get_instance_by_id( $plugin_id );
8877
+ $fs_addon->_cancel_trial();
8878
+ }
8879
+ }
8880
+
8881
+ return;
8882
+
8883
+ case 'verify_email':
8884
+ $this->verify_email();
8885
+
8886
+ return;
8887
+
8888
+ case 'sync_user':
8889
+ $this->_handle_account_user_sync();
8890
+
8891
+ return;
8892
+
8893
+ case $this->_slug . '_sync_license':
8894
+ $this->_sync_license();
8895
+
8896
+ return;
8897
+
8898
+ case 'download_latest':
8899
+ $this->_download_latest_directly( $plugin_id );
8900
+
8901
+ return;
8902
+
8903
+ #endregion
8904
+ }
8905
+
8906
+ if ( WP_FS__IS_POST_REQUEST ) {
8907
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
8908
+ foreach ( $properties as $p ) {
8909
+ if ( 'update_' . $p === $action ) {
8910
+ check_admin_referer( $action );
8911
+
8912
+ $this->_logger->log( $action );
8913
+
8914
+ $site_property = substr( $p, strlen( 'site_' ) );
8915
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
8916
+ $this->get_site()->{$site_property} = $site_property_value;
8917
+
8918
+ // Store account after modification.
8919
+ $this->_store_site();
8920
+
8921
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
8922
+
8923
+ $this->_admin_notices->add( sprintf(
8924
+ __fs( 'x-updated', $this->_slug ),
8925
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
8926
+
8927
+ return;
8928
+ }
8929
+ }
8930
+ }
8931
+ }
8932
+
8933
+ /**
8934
+ * Account page resources load.
8935
+ *
8936
+ * @author Vova Feldman (@svovaf)
8937
+ * @since 1.0.6
8938
+ */
8939
+ function _account_page_load() {
8940
+ $this->_logger->entrance();
8941
+
8942
+ $this->_logger->info( var_export( $_REQUEST, true ) );
8943
+
8944
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
8945
+
8946
+ if ( $this->has_addons() ) {
8947
+ wp_enqueue_script( 'plugin-install' );
8948
+ add_thickbox();
8949
+
8950
+ function fs_addons_body_class( $classes ) {
8951
+ $classes .= ' plugins-php';
8952
+
8953
+ return $classes;
8954
+ }
8955
+
8956
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
8957
+ }
8958
+
8959
+ if ( $this->has_paid_plan() &&
8960
+ ! $this->has_any_license() &&
8961
+ ! $this->is_sync_executed()
8962
+ ) {
8963
+ /**
8964
+ * If no licenses found and no sync job was executed during the last 24 hours,
8965
+ * just execute the sync job right away (blocking execution).
8966
+ *
8967
+ * @since 1.1.7.3
8968
+ */
8969
+ $this->run_manual_sync();
8970
+ }
8971
+
8972
+ $this->_handle_account_edits();
8973
+
8974
+ $this->do_action( 'account_page_load_before_departure' );
8975
+ }
8976
+
8977
+ /**
8978
+ * Render account page.
8979
+ *
8980
+ * @author Vova Feldman (@svovaf)
8981
+ * @since 1.0.0
8982
+ */
8983
+ function _account_page_render() {
8984
+ $this->_logger->entrance();
8985
+
8986
+ $vars = array( 'slug' => $this->_slug );
8987
+ fs_require_once_template( 'account.php', $vars );
8988
+ }
8989
+
8990
+ /**
8991
+ * Render account connect page.
8992
+ *
8993
+ * @author Vova Feldman (@svovaf)
8994
+ * @since 1.0.7
8995
+ */
8996
+ function _connect_page_render() {
8997
+ $this->_logger->entrance();
8998
+
8999
+ $vars = array( 'slug' => $this->_slug );
9000
+ fs_require_once_template( 'connect.php', $vars );
9001
+ }
9002
+
9003
+ /**
9004
+ * Load required resources before add-ons page render.
9005
+ *
9006
+ * @author Vova Feldman (@svovaf)
9007
+ * @since 1.0.6
9008
+ */
9009
+ function _addons_page_load() {
9010
+ $this->_logger->entrance();
9011
+
9012
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
9013
+
9014
+ wp_enqueue_script( 'plugin-install' );
9015
+ add_thickbox();
9016
+
9017
+ function fs_addons_body_class( $classes ) {
9018
+ $classes .= ' plugins-php';
9019
+
9020
+ return $classes;
9021
+ }
9022
+
9023
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
9024
+
9025
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
9026
+ $this->_admin_notices->add(
9027
+ sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
9028
+ __fs( 'heads-up', $this->_slug ),
9029
+ 'update-nag'
9030
+ );
9031
+ }
9032
+ }
9033
+
9034
+ /**
9035
+ * Render add-ons page.
9036
+ *
9037
+ * @author Vova Feldman (@svovaf)
9038
+ * @since 1.0.6
9039
+ */
9040
+ function _addons_page_render() {
9041
+ $this->_logger->entrance();
9042
+
9043
+ $vars = array( 'slug' => $this->_slug );
9044
+ fs_require_once_template( 'add-ons.php', $vars );
9045
+ }
9046
+
9047
+ /* Pricing & Upgrade
9048
+ ------------------------------------------------------------------------------------------------------------------*/
9049
+ /**
9050
+ * Render pricing page.
9051
+ *
9052
+ * @author Vova Feldman (@svovaf)
9053
+ * @since 1.0.0
9054
+ */
9055
+ function _pricing_page_render() {
9056
+ $this->_logger->entrance();
9057
+
9058
+ $vars = array( 'slug' => $this->_slug );
9059
+
9060
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
9061
+ fs_require_once_template( 'checkout.php', $vars );
9062
+ } else {
9063
+ fs_require_once_template( 'pricing.php', $vars );
9064
+ }
9065
+ }
9066
+
9067
+ #region Contact Us ------------------------------------------------------------------
9068
+
9069
+ /**
9070
+ * Render contact-us page.
9071
+ *
9072
+ * @author Vova Feldman (@svovaf)
9073
+ * @since 1.0.3
9074
+ */
9075
+ function _contact_page_render() {
9076
+ $this->_logger->entrance();
9077
+
9078
+ $vars = array( 'slug' => $this->_slug );
9079
+ fs_require_once_template( 'contact.php', $vars );
9080
+ }
9081
+
9082
+ #endregion ------------------------------------------------------------------
9083
+
9084
+ /**
9085
+ * Hide all admin notices to prevent distractions.
9086
+ *
9087
+ * @author Vova Feldman (@svovaf)
9088
+ * @since 1.0.3
9089
+ *
9090
+ * @uses remove_all_actions()
9091
+ */
9092
+ private static function _hide_admin_notices() {
9093
+ remove_all_actions( 'admin_notices' );
9094
+ remove_all_actions( 'network_admin_notices' );
9095
+ remove_all_actions( 'all_admin_notices' );
9096
+ remove_all_actions( 'user_admin_notices' );
9097
+ }
9098
+
9099
+ static function _clean_admin_content_section_hook() {
9100
+ self::_hide_admin_notices();
9101
+
9102
+ // Hide footer.
9103
+ echo '<style>#wpfooter { display: none !important; }</style>';
9104
+ }
9105
+
9106
+ /**
9107
+ * Attach to admin_head hook to hide all admin notices.
9108
+ *
9109
+ * @author Vova Feldman (@svovaf)
9110
+ * @since 1.0.3
9111
+ */
9112
+ static function _clean_admin_content_section() {
9113
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
9114
+ }
9115
+
9116
+ /* CSS & JavaScript
9117
+ ------------------------------------------------------------------------------------------------------------------*/
9118
+ /* function _enqueue_script($handle, $src) {
9119
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
9120
+
9121
+ $this->_logger->entrance( 'script = ' . $url );
9122
+
9123
+ wp_enqueue_script( $handle, $url );
9124
+ }*/
9125
+
9126
+ /* SDK
9127
+ ------------------------------------------------------------------------------------------------------------------*/
9128
+ private $_user_api;
9129
+
9130
+ /**
9131
+ *
9132
+ * @author Vova Feldman (@svovaf)
9133
+ * @since 1.0.2
9134
+ *
9135
+ * @param bool $flush
9136
+ *
9137
+ * @return FS_Api
9138
+ */
9139
+ function get_api_user_scope( $flush = false ) {
9140
+ if ( ! isset( $this->_user_api ) || $flush ) {
9141
+ $this->_user_api = FS_Api::instance(
9142
+ $this->_slug,
9143
+ 'user',
9144
+ $this->_user->id,
9145
+ $this->_user->public_key,
9146
+ ! $this->is_live(),
9147
+ $this->_user->secret_key
9148
+ );
9149
+ }
9150
+
9151
+ return $this->_user_api;
9152
+ }
9153
+
9154
+ private $_site_api;
9155
+
9156
+ /**
9157
+ *
9158
+ * @author Vova Feldman (@svovaf)
9159
+ * @since 1.0.2
9160
+ *
9161
+ * @param bool $flush
9162
+ *
9163
+ * @return FS_Api
9164
+ */
9165
+ function get_api_site_scope( $flush = false ) {
9166
+ if ( ! isset( $this->_site_api ) || $flush ) {
9167
+ $this->_site_api = FS_Api::instance(
9168
+ $this->_slug,
9169
+ 'install',
9170
+ $this->_site->id,
9171
+ $this->_site->public_key,
9172
+ ! $this->is_live(),
9173
+ $this->_site->secret_key
9174
+ );
9175
+ }
9176
+
9177
+ return $this->_site_api;
9178
+ }
9179
+
9180
+ private $_plugin_api;
9181
+
9182
+ /**
9183
+ * Get plugin public API scope.
9184
+ *
9185
+ * @author Vova Feldman (@svovaf)
9186
+ * @since 1.0.7
9187
+ *
9188
+ * @return FS_Api
9189
+ */
9190
+ function get_api_plugin_scope() {
9191
+ if ( ! isset( $this->_plugin_api ) ) {
9192
+ $this->_plugin_api = FS_Api::instance(
9193
+ $this->_slug,
9194
+ 'plugin',
9195
+ $this->_plugin->id,
9196
+ $this->_plugin->public_key,
9197
+ ! $this->is_live()
9198
+ );
9199
+ }
9200
+
9201
+ return $this->_plugin_api;
9202
+ }
9203
+
9204
+ /**
9205
+ * Get site API scope object (fallback to public plugin scope when not registered).
9206
+ *
9207
+ * @author Vova Feldman (@svovaf)
9208
+ * @since 1.0.7
9209
+ *
9210
+ * @return FS_Api
9211
+ */
9212
+ function get_api_site_or_plugin_scope() {
9213
+ return $this->is_registered() ?
9214
+ $this->get_api_site_scope() :
9215
+ $this->get_api_plugin_scope();
9216
+ }
9217
+
9218
+ /**
9219
+ * Show trial promotional notice (if any trial exist).
9220
+ *
9221
+ * @author Vova Feldman (@svovaf)
9222
+ * @since 1.0.9
9223
+ *
9224
+ * @param $plans
9225
+ */
9226
+ function _check_for_trial_plans( $plans ) {
9227
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
9228
+ }
9229
+
9230
+ /**
9231
+ * Show trial promotional notice (if any trial exist).
9232
+ *
9233
+ * @author Vova Feldman (@svovaf)
9234
+ * @since 1.0.9
9235
+ */
9236
+ function _add_trial_notice() {
9237
+ // Check if trial already utilized.
9238
+ if ( $this->_site->is_trial_utilized() ) {
9239
+ return;
9240
+ }
9241
+
9242
+ // Check if already paying.
9243
+ if ( $this->is_paying() ) {
9244
+ return;
9245
+ }
9246
+
9247
+ // Check if trial message is already shown.
9248
+ if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
9249
+ return;
9250
+ }
9251
+
9252
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
9253
+ $trial_plans_count = count( $trial_plans );
9254
+
9255
+ // Check if any of the plans contains trial.
9256
+ if ( 0 === $trial_plans_count ) {
9257
+ return;
9258
+ }
9259
+
9260
+ /**
9261
+ * @var FS_Plugin_Plan $paid_plan
9262
+ */
9263
+ $paid_plan = $trial_plans[0];
9264
+ $require_subscription = $paid_plan->is_require_subscription;
9265
+ $upgrade_url = $this->get_trial_url();
9266
+ $cc_string = $require_subscription ?
9267
+ sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $paid_plan->trial_period ) :
9268
+ __fs( 'no-cc-required', $this->_slug ) . '!';
9269
+
9270
+
9271
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
9272
+
9273
+ if ( $total_paid_plans === $trial_plans_count ) {
9274
+ // All paid plans have trials.
9275
+ $message = sprintf(
9276
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9277
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9278
+ strtolower( __fs( 'awesome', $this->_slug ) ),
9279
+ $paid_plan->trial_period
9280
+ );
9281
+ } else {
9282
+ $plans_string = '';
9283
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
9284
+ $plans_string .= sprintf( '<a href="%s">%s</a>', $upgrade_url, $trial_plans[ $i ]->title );
9285
+
9286
+ if ( $i < $trial_plans_count - 2 ) {
9287
+ $plans_string .= ', ';
9288
+ } else if ( $i == $trial_plans_count - 2 ) {
9289
+ $plans_string .= ' and ';
9290
+ }
9291
+ }
9292
+
9293
+ // Not all paid plans have trials.
9294
+ $message = sprintf(
9295
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9296
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9297
+ $plans_string,
9298
+ $paid_plan->trial_period
9299
+ );
9300
+ }
9301
+
9302
+ $message .= ' ' . $cc_string;
9303
+
9304
+ // Add start trial button.
9305
+ $message .= ' ' . sprintf(
9306
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9307
+ $upgrade_url,
9308
+ __fs( 'start-free-trial', $this->_slug )
9309
+ );
9310
+
9311
+ $this->_admin_notices->add_sticky(
9312
+ $this->apply_filters( 'trial_promotion_message', $message ),
9313
+ 'trial_promotion',
9314
+ '',
9315
+ 'promotion'
9316
+ );
9317
+
9318
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
9319
+ }
9320
+
9321
+ /* Action Links
9322
+ ------------------------------------------------------------------------------------------------------------------*/
9323
+ private $_action_links_hooked = false;
9324
+ private $_action_links = array();
9325
+
9326
+ /**
9327
+ * @author Vova Feldman (@svovaf)
9328
+ * @since 1.0.0
9329
+ *
9330
+ * @return bool
9331
+ */
9332
+ private function is_plugin_action_links_hooked() {
9333
+ $this->_logger->entrance( json_encode( $this->_action_links_hooked ) );
9334
+
9335
+ return $this->_action_links_hooked;
9336
+ }
9337
+
9338
+ /**
9339
+ * Hook to plugin action links filter.
9340
+ *
9341
+ * @author Vova Feldman (@svovaf)
9342
+ * @since 1.0.0
9343
+ */
9344
+ private function hook_plugin_action_links() {
9345
+ $this->_logger->entrance();
9346
+
9347
+ $this->_action_links_hooked = true;
9348
+
9349
+ $this->_logger->log( 'Adding action links hooks.' );
9350
+
9351
+ // Add action link to settings page.
9352
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
9353
+ &$this,
9354
+ '_modify_plugin_action_links_hook'
9355
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9356
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
9357
+ &$this,
9358
+ '_modify_plugin_action_links_hook'
9359
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
9360
+ }
9361
+
9362
+ /**
9363
+ * Add plugin action link.
9364
+ *
9365
+ * @author Vova Feldman (@svovaf)
9366
+ * @since 1.0.0
9367
+ *
9368
+ * @param $label
9369
+ * @param $url
9370
+ * @param bool $external
9371
+ * @param int $priority
9372
+ * @param bool $key
9373
+ */
9374
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
9375
+ $this->_logger->entrance();
9376
+
9377
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
9378
+ $this->_action_links[ $priority ] = array();
9379
+ }
9380
+
9381
+ if ( false === $key ) {
9382
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
9383
+ }
9384
+
9385
+ $this->_action_links[ $priority ][] = array(
9386
+ 'label' => $label,
9387
+ 'href' => $url,
9388
+ 'key' => $key,
9389
+ 'external' => $external
9390
+ );
9391
+ }
9392
+
9393
+ /**
9394
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
9395
+ *
9396
+ * @author Vova Feldman (@svovaf)
9397
+ * @since 1.0.0
9398
+ */
9399
+ function _add_upgrade_action_link() {
9400
+ $this->_logger->entrance();
9401
+
9402
+ if ( $this->is_registered() ) {
9403
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
9404
+ $this->add_plugin_action_link(
9405
+ __fs( 'upgrade', $this->_slug ),
9406
+ $this->get_upgrade_url(),
9407
+ false,
9408
+ 7,
9409
+ 'upgrade'
9410
+ );
9411
+ }
9412
+
9413
+ if ( $this->has_addons() ) {
9414
+ $this->add_plugin_action_link(
9415
+ __fs( 'add-ons', $this->_slug ),
9416
+ $this->_get_admin_page_url( 'addons' ),
9417
+ false,
9418
+ 9,
9419
+ 'addons'
9420
+ );
9421
+ }
9422
+ }
9423
+ }
9424
+
9425
+ /**
9426
+ * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
9427
+ *
9428
+ * @author Leo Fajardo (@leorw)
9429
+ * @since 1.1.9
9430
+ */
9431
+ function _add_license_action_link() {
9432
+ $this->_logger->entrance();
9433
+
9434
+ $link_text = __fs( $this->is_free_plan() ? 'activate-license' : 'change-license', $this->_slug );
9435
+
9436
+ $this->add_plugin_action_link(
9437
+ $link_text,
9438
+ '#',
9439
+ false,
9440
+ 11,
9441
+ ( 'activate-license ' . $this->_slug )
9442
+ );
9443
+ }
9444
+
9445
+ /**
9446
+ * Get the URL of the page that should be loaded right after the plugin activation.
9447
+ *
9448
+ * @author Vova Feldman (@svovaf)
9449
+ * @since 1.1.7.4
9450
+ *
9451
+ * @return string
9452
+ */
9453
+ function get_after_plugin_activation_redirect_url() {
9454
+ $url = false;
9455
+ $plugin_fs = false;
9456
+
9457
+ if ( ! $this->is_addon() ) {
9458
+ $first_time_path = $this->_menu->get_first_time_path();
9459
+ $plugin_fs = $this;
9460
+ $url = $plugin_fs->is_activation_mode() ?
9461
+ $plugin_fs->get_activation_url() :
9462
+ ( empty( $first_time_path ) ?
9463
+ $this->_get_admin_page_url() :
9464
+ $first_time_path );
9465
+ } else {
9466
+ if ( $this->is_parent_plugin_installed() ) {
9467
+ $plugin_fs = self::get_parent_instance();
9468
+ }
9469
+
9470
+ if ( is_object( $plugin_fs ) ) {
9471
+ if ( ! $plugin_fs->is_registered() ) {
9472
+ // Forward to parent plugin connect when parent not registered.
9473
+ $url = $plugin_fs->get_activation_url();
9474
+ } else {
9475
+ // Forward to account page.
9476
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
9477
+ }
9478
+ }
9479
+ }
9480
+
9481
+ return $url;
9482
+ }
9483
+
9484
+ /**
9485
+ * Forward page to activation page.
9486
+ *
9487
+ * @author Vova Feldman (@svovaf)
9488
+ * @since 1.0.3
9489
+ */
9490
+ function _redirect_on_activation_hook() {
9491
+ $url = $this->get_after_plugin_activation_redirect_url();
9492
+
9493
+ if ( is_string( $url ) ) {
9494
+ fs_redirect( $url );
9495
+ exit();
9496
+ }
9497
+ }
9498
+
9499
+ /**
9500
+ * Modify plugin's page action links collection.
9501
+ *
9502
+ * @author Vova Feldman (@svovaf)
9503
+ * @since 1.0.0
9504
+ *
9505
+ * @param array $links
9506
+ * @param $file
9507
+ *
9508
+ * @return array
9509
+ */
9510
+ function _modify_plugin_action_links_hook( $links, $file ) {
9511
+ $this->_logger->entrance();
9512
+
9513
+ $passed_deactivate = false;
9514
+ $deactivate_link = '';
9515
+ $before_deactivate = array();
9516
+ $after_deactivate = array();
9517
+ foreach ( $links as $key => $link ) {
9518
+ if ( 'deactivate' === $key ) {
9519
+ $deactivate_link = $link;
9520
+ $passed_deactivate = true;
9521
+ continue;
9522
+ }
9523
+
9524
+ if ( ! $passed_deactivate ) {
9525
+ $before_deactivate[ $key ] = $link;
9526
+ } else {
9527
+ $after_deactivate[ $key ] = $link;
9528
+ }
9529
+ }
9530
+
9531
+ ksort( $this->_action_links );
9532
+
9533
+ foreach ( $this->_action_links as $new_links ) {
9534
+ foreach ( $new_links as $link ) {
9535
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
9536
+ }
9537
+ }
9538
+
9539
+ if ( ! empty( $deactivate_link ) ) {
9540
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
9541
+ /*
9542
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
9543
+ *
9544
+ * If user is paying or in trial and have the free version installed,
9545
+ * assume that the deactivation is for the upgrade process, so this is not needed.
9546
+ */
9547
+ $deactivate_link .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
9548
+ }
9549
+
9550
+ // Append deactivation link.
9551
+ $before_deactivate['deactivate'] = $deactivate_link;
9552
+ }
9553
+
9554
+ return array_merge( $before_deactivate, $after_deactivate );
9555
+ }
9556
+
9557
+ /**
9558
+ * Adds admin message.
9559
+ *
9560
+ * @author Vova Feldman (@svovaf)
9561
+ * @since 1.0.4
9562
+ *
9563
+ * @param string $message
9564
+ * @param string $title
9565
+ * @param string $type
9566
+ */
9567
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
9568
+ $this->_admin_notices->add( $message, $title, $type );
9569
+ }
9570
+
9571
+ /**
9572
+ * Adds sticky admin message.
9573
+ *
9574
+ * @author Vova Feldman (@svovaf)
9575
+ * @since 1.1.0
9576
+ *
9577
+ * @param string $message
9578
+ * @param string $id
9579
+ * @param string $title
9580
+ * @param string $type
9581
+ */
9582
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
9583
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
9584
+ }
9585
+
9586
+ /* Plugin Auto-Updates (@since 1.0.4)
9587
+ ------------------------------------------------------------------------------------------------------------------*/
9588
+ /**
9589
+ * @var string[]
9590
+ */
9591
+ private static $_auto_updated_plugins;
9592
+
9593
+ /**
9594
+ * @todo TEST IF IT WORKS!!!
9595
+ *
9596
+ * Include plugins for automatic updates based on stored settings.
9597
+ *
9598
+ * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
9599
+ *
9600
+ * @author Vova Feldman (@svovaf)
9601
+ * @since 1.0.4
9602
+ *
9603
+ * @param bool $update Whether to update (not used for plugins)
9604
+ * @param object $item The plugin's info
9605
+ *
9606
+ * @return bool
9607
+ */
9608
+ static function _include_plugins_in_auto_update( $update, $item ) {
9609
+ // Before version 3.8.2 the $item was the file name of the plugin,
9610
+ // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
9611
+ $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
9612
+
9613
+ if ( ! isset( self::$_auto_updated_plugins ) ) {
9614
+ $plugins = self::$_accounts->get_option( 'plugins', array() );
9615
+
9616
+ $identifiers = array();
9617
+ foreach ( $plugins as $p ) {
9618
+ /**
9619
+ * @var FS_Plugin $p
9620
+ */
9621
+ if ( isset( $p->auto_update ) && $p->auto_update ) {
9622
+ $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
9623
+ }
9624
+ }
9625
+
9626
+ self::$_auto_updated_plugins = $identifiers;
9627
+ }
9628
+
9629
+ if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
9630
+ return true;
9631
+ }
9632
+
9633
+ // Pass update decision to next filters
9634
+ return $update;
9635
+ }
9636
+
9637
+ #region Versioning ------------------------------------------------------------------
9638
+
9639
+ /**
9640
+ * Check if Freemius in SDK upgrade mode.
9641
+ *
9642
+ * @author Vova Feldman (@svovaf)
9643
+ * @since 1.0.9
9644
+ *
9645
+ * @return bool
9646
+ */
9647
+ function is_sdk_upgrade_mode() {
9648
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
9649
+ $this->_storage->sdk_upgrade_mode :
9650
+ false;
9651
+ }
9652
+
9653
+ /**
9654
+ * Turn SDK upgrade mode off.
9655
+ *
9656
+ * @author Vova Feldman (@svovaf)
9657
+ * @since 1.0.9
9658
+ *
9659
+ * @return bool
9660
+ */
9661
+ function set_sdk_upgrade_complete() {
9662
+ $this->_storage->sdk_upgrade_mode = false;
9663
+ }
9664
+
9665
+ /**
9666
+ * Check if plugin upgrade mode.
9667
+ *
9668
+ * @author Vova Feldman (@svovaf)
9669
+ * @since 1.0.9
9670
+ *
9671
+ * @return bool
9672
+ */
9673
+ function is_plugin_upgrade_mode() {
9674
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
9675
+ $this->_storage->plugin_upgrade_mode :
9676
+ false;
9677
+ }
9678
+
9679
+ /**
9680
+ * Turn plugin upgrade mode off.
9681
+ *
9682
+ * @author Vova Feldman (@svovaf)
9683
+ * @since 1.0.9
9684
+ *
9685
+ * @return bool
9686
+ */
9687
+ function set_plugin_upgrade_complete() {
9688
+ $this->_storage->plugin_upgrade_mode = false;
9689
+ }
9690
+
9691
+ #endregion ------------------------------------------------------------------
9692
+
9693
+ #region Permissions ------------------------------------------------------------------
9694
+
9695
+ /**
9696
+ * Check if specific permission requested.
9697
+ *
9698
+ * @author Vova Feldman (@svovaf)
9699
+ * @since 1.1.6
9700
+ *
9701
+ * @param string $permission
9702
+ *
9703
+ * @return bool
9704
+ */
9705
+ function is_permission_requested( $permission ) {
9706
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
9707
+ }
9708
+
9709
+ #endregion Permissions ------------------------------------------------------------------
9710
+
9711
+ #region Marketing ------------------------------------------------------------------
9712
+
9713
+ /**
9714
+ * Check if current user purchased any other plugins before.
9715
+ *
9716
+ * @author Vova Feldman (@svovaf)
9717
+ * @since 1.0.9
9718
+ *
9719
+ * @return bool
9720
+ */
9721
+ function has_purchased_before() {
9722
+ // TODO: Implement has_purchased_before() method.
9723
+ }
9724
+
9725
+ /**
9726
+ * Check if current user classified as an agency.
9727
+ *
9728
+ * @author Vova Feldman (@svovaf)
9729
+ * @since 1.0.9
9730
+ *
9731
+ * @return bool
9732
+ */
9733
+ function is_agency() {
9734
+ // TODO: Implement is_agency() method.
9735
+ }
9736
+
9737
+ /**
9738
+ * Check if current user classified as a developer.
9739
+ *
9740
+ * @author Vova Feldman (@svovaf)
9741
+ * @since 1.0.9
9742
+ *
9743
+ * @return bool
9744
+ */
9745
+ function is_developer() {
9746
+ // TODO: Implement is_developer() method.
9747
+ }
9748
+
9749
+ /**
9750
+ * Check if current user classified as a business.
9751
+ *
9752
+ * @author Vova Feldman (@svovaf)
9753
+ * @since 1.0.9
9754
+ *
9755
+ * @return bool
9756
+ */
9757
+ function is_business() {
9758
+ // TODO: Implement is_business() method.
9759
+ }
9760
+
9761
+ #endregion ------------------------------------------------------------------
9762
+ }
freemius/includes/class-fs-api.php ADDED
@@ -0,0 +1,455 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Api
15
+ *
16
+ * Wraps Freemius API SDK to handle:
17
+ * 1. Clock sync.
18
+ * 2. Fallback to HTTP when HTTPS fails.
19
+ * 3. Adds caching layer to GET requests.
20
+ * 4. Adds consistency for failed requests by using last cached version.
21
+ */
22
+ class FS_Api {
23
+ /**
24
+ * @var FS_Api[]
25
+ */
26
+ private static $_instances = array();
27
+
28
+ /**
29
+ * @var FS_Option_Manager Freemius options, options-manager.
30
+ */
31
+ private static $_options;
32
+
33
+ /**
34
+ * @var FS_Cache_Manager API Caching layer
35
+ */
36
+ private static $_cache;
37
+
38
+ /**
39
+ * @var int Clock diff in seconds between current server to API server.
40
+ */
41
+ private static $_clock_diff;
42
+
43
+ /**
44
+ * @var Freemius_Api
45
+ */
46
+ private $_api;
47
+
48
+ /**
49
+ * @var string
50
+ */
51
+ private $_slug;
52
+
53
+ /**
54
+ * @var FS_Logger
55
+ * @since 1.0.4
56
+ */
57
+ private $_logger;
58
+
59
+ /**
60
+ * @param string $slug
61
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
62
+ * @param number $id Element's id.
63
+ * @param string $public_key Public key.
64
+ * @param bool $is_sandbox
65
+ * @param bool|string $secret_key Element's secret key.
66
+ *
67
+ * @return FS_Api
68
+ */
69
+ static function instance( $slug, $scope, $id, $public_key, $is_sandbox, $secret_key = false ) {
70
+ $identifier = md5( $slug . $scope . $id . $public_key . ( is_string( $secret_key ) ? $secret_key : '' ) . json_encode( $is_sandbox ) );
71
+
72
+ if ( ! isset( self::$_instances[ $identifier ] ) ) {
73
+ self::_init();
74
+
75
+ self::$_instances[ $identifier ] = new FS_Api( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox );
76
+ }
77
+
78
+ return self::$_instances[ $identifier ];
79
+ }
80
+
81
+ private static function _init() {
82
+ if ( isset( self::$_options ) ) {
83
+ return;
84
+ }
85
+
86
+ if ( ! class_exists( 'Freemius_Api' ) ) {
87
+ require_once( WP_FS__DIR_SDK . '/Freemius.php' );
88
+ }
89
+
90
+ self::$_options = FS_Option_Manager::get_manager( WP_FS__OPTIONS_OPTION_NAME, true );
91
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
92
+
93
+ self::$_clock_diff = self::$_options->get_option( 'api_clock_diff', 0 );
94
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
95
+
96
+ if ( self::$_options->get_option( 'api_force_http', false ) ) {
97
+ Freemius_Api::SetHttp();
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @param string $slug
103
+ * @param string $scope 'app', 'developer', 'user' or 'install'.
104
+ * @param number $id Element's id.
105
+ * @param string $public_key Public key.
106
+ * @param bool|string $secret_key Element's secret key.
107
+ * @param bool $is_sandbox
108
+ */
109
+ private function __construct( $slug, $scope, $id, $public_key, $secret_key, $is_sandbox ) {
110
+ $this->_api = new Freemius_Api( $scope, $id, $public_key, $secret_key, $is_sandbox );
111
+
112
+ $this->_slug = $slug;
113
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_api', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
114
+ }
115
+
116
+ /**
117
+ * Find clock diff between server and API server, and store the diff locally.
118
+ *
119
+ * @param bool|int $diff
120
+ *
121
+ * @return bool|int False if clock diff didn't change, otherwise returns the clock diff in seconds.
122
+ */
123
+ private function _sync_clock_diff( $diff = false ) {
124
+ $this->_logger->entrance();
125
+
126
+ // Sync clock and store.
127
+ $new_clock_diff = ( false === $diff ) ?
128
+ Freemius_Api::FindClockDiff() :
129
+ $diff;
130
+
131
+ if ( $new_clock_diff === self::$_clock_diff ) {
132
+ return false;
133
+ }
134
+
135
+ self::$_clock_diff = $new_clock_diff;
136
+
137
+ // Update API clock's diff.
138
+ Freemius_Api::SetClockDiff( self::$_clock_diff );
139
+
140
+ // Store new clock diff in storage.
141
+ self::$_options->set_option( 'api_clock_diff', self::$_clock_diff, true );
142
+
143
+ return $new_clock_diff;
144
+ }
145
+
146
+ /**
147
+ * Override API call to enable retry with servers' clock auto sync method.
148
+ *
149
+ * @param string $path
150
+ * @param string $method
151
+ * @param array $params
152
+ * @param bool $retry Is in retry or first call attempt.
153
+ *
154
+ * @return array|mixed|string|void
155
+ */
156
+ private function _call( $path, $method = 'GET', $params = array(), $retry = false ) {
157
+ $this->_logger->entrance( $method . ':' . $path );
158
+
159
+ if ( self::is_temporary_down() ) {
160
+ $result = $this->get_temporary_unavailable_error();
161
+ } else {
162
+ $result = $this->_api->Api( $path, $method, $params );
163
+
164
+ if ( null !== $result &&
165
+ isset( $result->error ) &&
166
+ isset( $result->error->code ) &&
167
+ 'request_expired' === $result->error->code
168
+ ) {
169
+ if ( ! $retry ) {
170
+ $diff = isset( $result->error->timestamp ) ?
171
+ ( time() - strtotime( $result->error->timestamp ) ) :
172
+ false;
173
+
174
+ // Try to sync clock diff.
175
+ if ( false !== $this->_sync_clock_diff( $diff ) ) {
176
+ // Retry call with new synced clock.
177
+ return $this->_call( $path, $method, $params, true );
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ if ( null !== $result && isset( $result->error ) && isset( $result->error->message ) ) {
184
+ // Log API errors.
185
+ $this->_logger->error( $result->error->message );
186
+ }
187
+
188
+ return $result;
189
+ }
190
+
191
+ /**
192
+ * Override API call to wrap it in servers' clock sync method.
193
+ *
194
+ * @param string $path
195
+ * @param string $method
196
+ * @param array $params
197
+ *
198
+ * @return array|mixed|string|void
199
+ * @throws Freemius_Exception
200
+ */
201
+ function call( $path, $method = 'GET', $params = array() ) {
202
+ return $this->_call( $path, $method, $params );
203
+ }
204
+
205
+ /**
206
+ * Get API request URL signed via query string.
207
+ *
208
+ * @param string $path
209
+ *
210
+ * @return string
211
+ */
212
+ function get_signed_url( $path ) {
213
+ return $this->_api->GetSignedUrl( $path );
214
+ }
215
+
216
+ /**
217
+ * @param string $path
218
+ * @param bool $flush
219
+ * @param int $expiration (optional) Time until expiration in seconds from now, defaults to 24 hours
220
+ *
221
+ * @return stdClass|mixed
222
+ */
223
+ function get( $path = '/', $flush = false, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
224
+ $this->_logger->entrance( $path );
225
+
226
+ $cache_key = $this->get_cache_key( $path );
227
+
228
+ // Always flush during development.
229
+ if ( WP_FS__DEV_MODE || $this->_api->IsSandbox() ) {
230
+ $flush = true;
231
+ }
232
+
233
+ $cached_result = self::$_cache->get( $cache_key );
234
+
235
+ if ( $flush || ! self::$_cache->has_valid( $cache_key ) ) {
236
+ $result = $this->call( $path );
237
+
238
+ if ( ! is_object( $result ) || isset( $result->error ) ) {
239
+ // Api returned an error.
240
+ if ( is_object( $cached_result ) &&
241
+ ! isset( $cached_result )
242
+ ) {
243
+ // If there was an error during a newer data fetch,
244
+ // fallback to older data version.
245
+ $result = $cached_result;
246
+ } else {
247
+ // If no older data version, return result without
248
+ // caching the error.
249
+ return $result;
250
+ }
251
+ }
252
+
253
+ self::$_cache->set( $cache_key, $result, $expiration );
254
+
255
+ $cached_result = $result;
256
+ }
257
+
258
+ return $cached_result;
259
+ }
260
+
261
+ private function get_cache_key( $path, $method = 'GET', $params = array() ) {
262
+ $canonized = $this->_api->CanonizePath( $path );
263
+ // $exploded = explode('/', $canonized);
264
+ // return $method . '_' . array_pop($exploded) . '_' . md5($canonized . json_encode($params));
265
+ return $method . ':' . $canonized . ( ! empty( $params ) ? '#' . md5( json_encode( $params ) ) : '' );
266
+ }
267
+
268
+ /**
269
+ * Test API connectivity.
270
+ *
271
+ * @author Vova Feldman (@svovaf)
272
+ * @since 1.0.9 If fails, try to fallback to HTTP.
273
+ * @since 1.1.6 Added a 5-min caching mechanism, to prevent from overloading the server if the API if
274
+ * temporary down.
275
+ *
276
+ * @return bool True if successful connectivity to the API.
277
+ */
278
+ static function test() {
279
+ self::_init();
280
+
281
+ $cache_key = 'ping_test';
282
+
283
+ $test = self::$_cache->get_valid( $cache_key, null );
284
+
285
+ if ( is_null( $test ) ) {
286
+ $test = Freemius_Api::Test();
287
+
288
+ if ( false === $test && Freemius_Api::IsHttps() ) {
289
+ // Fallback to HTTP, since HTTPS fails.
290
+ Freemius_Api::SetHttp();
291
+
292
+ self::$_options->set_option( 'api_force_http', true, true );
293
+
294
+ $test = Freemius_Api::Test();
295
+
296
+ if ( false === $test ) {
297
+ /**
298
+ * API connectivity test fail also in HTTP request, therefore,
299
+ * fallback to HTTPS to keep connection secure.
300
+ *
301
+ * @since 1.1.6
302
+ */
303
+ self::$_options->set_option( 'api_force_http', false, true );
304
+ }
305
+ }
306
+
307
+ self::$_cache->set( $cache_key, $test, WP_FS__TIME_5_MIN_IN_SEC );
308
+ }
309
+
310
+ return $test;
311
+ }
312
+
313
+ /**
314
+ * Check if API is temporary down.
315
+ *
316
+ * @author Vova Feldman (@svovaf)
317
+ * @since 1.1.6
318
+ *
319
+ * @return bool
320
+ */
321
+ static function is_temporary_down() {
322
+ self::_init();
323
+
324
+ $test = self::$_cache->get_valid( 'ping_test', null );
325
+
326
+ return ( false === $test );
327
+ }
328
+
329
+ /**
330
+ * @author Vova Feldman (@svovaf)
331
+ * @since 1.1.6
332
+ *
333
+ * @return object
334
+ */
335
+ private function get_temporary_unavailable_error() {
336
+ return (object) array(
337
+ 'error' => array(
338
+ 'type' => 'TemporaryUnavailable',
339
+ 'message' => 'API is temporary unavailable, please retry in ' . ( self::$_cache->get_record_expiration( 'ping_test' ) - WP_FS__SCRIPT_START_TIME ) . ' sec.',
340
+ 'code' => 'temporary_unavailable',
341
+ 'http' => 503
342
+ )
343
+ );
344
+ }
345
+
346
+ /**
347
+ * Ping API for connectivity test, and return result object.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.0.9
351
+ *
352
+ * @param null|string $unique_anonymous_id
353
+ * @param array $params
354
+ *
355
+ * @return object
356
+ */
357
+ function ping( $unique_anonymous_id = null, $params = array() ) {
358
+ $this->_logger->entrance();
359
+
360
+ if ( self::is_temporary_down() ) {
361
+ return $this->get_temporary_unavailable_error();
362
+ }
363
+
364
+ $pong = is_null( $unique_anonymous_id ) ?
365
+ Freemius_Api::Ping() :
366
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
367
+ array( 'uid' => $unique_anonymous_id ),
368
+ $params
369
+ ) ) );
370
+
371
+ if ( $this->is_valid_ping( $pong ) ) {
372
+ return $pong;
373
+ }
374
+
375
+ if ( self::should_try_with_http( $pong ) ) {
376
+ // Fallback to HTTP, since HTTPS fails.
377
+ Freemius_Api::SetHttp();
378
+
379
+ self::$_options->set_option( 'api_force_http', true, true );
380
+
381
+ $pong = is_null( $unique_anonymous_id ) ?
382
+ Freemius_Api::Ping() :
383
+ $this->_call( 'ping.json?' . http_build_query( array_merge(
384
+ array( 'uid' => $unique_anonymous_id ),
385
+ $params
386
+ ) ) );
387
+
388
+ if ( ! $this->is_valid_ping( $pong ) ) {
389
+ self::$_options->set_option( 'api_force_http', false, true );
390
+ }
391
+ }
392
+
393
+ return $pong;
394
+ }
395
+
396
+ /**
397
+ * Check if based on the API result we should try
398
+ * to re-run the same request with HTTP instead of HTTPS.
399
+ *
400
+ * @author Vova Feldman (@svovaf)
401
+ * @since 1.1.6
402
+ *
403
+ * @param $result
404
+ *
405
+ * @return bool
406
+ */
407
+ private static function should_try_with_http( $result ) {
408
+ if ( ! Freemius_Api::IsHttps() ) {
409
+ return false;
410
+ }
411
+
412
+ return ( ! is_object( $result ) ||
413
+ ! isset( $result->error ) ||
414
+ ! isset( $result->error->code ) ||
415
+ ! in_array( $result->error->code, array(
416
+ 'curl_missing',
417
+ 'cloudflare_ddos_protection',
418
+ 'maintenance_mode',
419
+ 'squid_cache_block',
420
+ 'too_many_requests',
421
+ ) ) );
422
+
423
+ }
424
+
425
+ /**
426
+ * Check if valid ping request result.
427
+ *
428
+ * @author Vova Feldman (@svovaf)
429
+ * @since 1.1.1
430
+ *
431
+ * @param mixed $pong
432
+ *
433
+ * @return bool
434
+ */
435
+ function is_valid_ping( $pong ) {
436
+ return Freemius_Api::Test( $pong );
437
+ }
438
+
439
+ function get_url( $path = '' ) {
440
+ return Freemius_Api::GetUrl( $path, $this->_api->IsSandbox() );
441
+ }
442
+
443
+ /**
444
+ * Clear API cache.
445
+ *
446
+ * @author Vova Feldman (@svovaf)
447
+ * @since 1.0.9
448
+ */
449
+ static function clear_cache() {
450
+ self::_init();
451
+
452
+ self::$_cache = FS_Cache_Manager::get_manager( WP_FS__API_CACHE_OPTION_NAME );
453
+ self::$_cache->clear( true );
454
+ }
455
+ }
freemius/includes/class-fs-logger.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Logger {
14
+ private $_id;
15
+ private $_on = false;
16
+ private $_echo = false;
17
+ private $_file_start = 0;
18
+
19
+ private static $LOGGERS = array();
20
+ private static $LOG = array();
21
+ private static $CNT = 0;
22
+ private static $_HOOKED_FOOTER = false;
23
+
24
+ private function __construct( $id, $on = false, $echo = false ) {
25
+ $this->_id = $id;
26
+
27
+ $bt = debug_backtrace();
28
+ $caller = $bt[2];
29
+
30
+ $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
31
+
32
+ if ( $on ) {
33
+ $this->on();
34
+ }
35
+ if ( $echo ) {
36
+ $this->echo_on();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @param string $id
42
+ * @param bool $on
43
+ * @param bool $echo
44
+ *
45
+ * @return FS_Logger
46
+ */
47
+ public static function get_logger( $id, $on = false, $echo = false ) {
48
+ $id = strtolower( $id );
49
+
50
+ if ( ! isset( self::$LOGGERS[ $id ] ) ) {
51
+ self::$LOGGERS[ $id ] = new FS_Logger( $id, $on, $echo );
52
+ }
53
+
54
+ return self::$LOGGERS[ $id ];
55
+ }
56
+
57
+ private static function _hook_footer() {
58
+ if ( self::$_HOOKED_FOOTER ) {
59
+ return;
60
+ }
61
+
62
+ if ( is_admin() ) {
63
+ add_action( 'admin_footer', 'FS_Logger::dump', 100 );
64
+ } else {
65
+ add_action( 'wp_footer', 'FS_Logger::dump', 100 );
66
+ }
67
+ }
68
+
69
+ function is_on() {
70
+ return $this->_on;
71
+ }
72
+
73
+ function on() {
74
+ $this->_on = true;
75
+
76
+ self::_hook_footer();
77
+ }
78
+
79
+ function echo_on() {
80
+ $this->on();
81
+
82
+ $this->_echo = true;
83
+ }
84
+
85
+ function is_echo_on() {
86
+ return $this->_echo;
87
+ }
88
+
89
+ function get_id() {
90
+ return $this->_id;
91
+ }
92
+
93
+ function get_file() {
94
+ return $this->_file_start;
95
+ }
96
+
97
+ private function _log( &$message, $type = 'log', $wrapper ) {
98
+ if ( ! $this->is_on() ) {
99
+ return;
100
+ }
101
+
102
+ $bt = debug_backtrace();
103
+ $depth = $wrapper ? 3 : 2;
104
+ while ( $depth < count( $bt ) - 1 && 'eval' === $bt[ $depth ]['function'] ) {
105
+ $depth ++;
106
+ }
107
+
108
+ $caller = $bt[ $depth ];
109
+
110
+ $log = array_merge( $caller, array(
111
+ 'cnt' => self::$CNT ++,
112
+ 'logger' => $this,
113
+ 'timestamp' => microtime(true),
114
+ 'type' => $type,
115
+ 'msg' => $message,
116
+ ) );
117
+
118
+ self::$LOG[] = $log;
119
+
120
+ if ( $this->is_echo_on() ) {
121
+ echo self::format_html( $log ) . "\n";
122
+ }
123
+ }
124
+
125
+ function log( $message, $wrapper = false ) {
126
+ $this->_log( $message, 'log', $wrapper );
127
+ }
128
+
129
+ function info( $message, $wrapper = false ) {
130
+ $this->_log( $message, 'info', $wrapper );
131
+ }
132
+
133
+ function warn( $message, $wrapper = false ) {
134
+ $this->_log( $message, 'warn', $wrapper );
135
+ }
136
+
137
+ function error( $message, $wrapper = false ) {
138
+ $this->_log( $message, 'error', $wrapper );
139
+ }
140
+
141
+ function entrance( $message = '', $wrapper = false ) {
142
+ $msg = 'Entrance' . ( empty( $message ) ? '' : ' > ' ) . $message;
143
+
144
+ $this->_log( $msg, 'log', $wrapper );
145
+ }
146
+
147
+ function departure( $message = '', $wrapper = false ) {
148
+ $msg = 'Departure' . ( empty( $message ) ? '' : ' > ' ) . $message;
149
+
150
+ $this->_log( $msg, 'log', $wrapper );
151
+ }
152
+
153
+ private static function format( $log, $show_type = true ) {
154
+ return '[' . str_pad( $log['cnt'], strlen( self::$CNT ), '0', STR_PAD_LEFT ) . '] [' . $log['logger']->_id . '] ' . ( $show_type ? '[' . $log['type'] . ']' : '' ) . $log['function'] . ' >> ' . $log['msg'] . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ') ' : '' ) . ' [' . $log['timestamp'] . ']';
155
+ }
156
+
157
+ private static function format_html( $log ) {
158
+ return '<div style="font-size: 11px; padding: 3px; background: #ccc; margin-bottom: 3px;">[' . $log['cnt'] . '] [' . $log['logger']->_id . '] [' . $log['type'] . '] <b><code style="color: blue;">' . $log['function'] . '</code> >> <b style="color: darkorange;">' . $log['msg'] . '</b></b>' . ( isset( $log['file'] ) ? ' (' . substr( $log['file'], $log['logger']->_file_start ) . ' ' . $log['line'] . ')' : '' ) . ' [' . $log['timestamp'] . ']</div>';
159
+ }
160
+
161
+ static function dump() {
162
+ ?>
163
+ <!-- BEGIN: Freemius PHP Console Log -->
164
+ <script type="text/javascript">
165
+ <?php
166
+ foreach (self::$LOG as $log)
167
+ {
168
+ echo 'console.' . $log['type'] . '(' . json_encode(self::format($log, false)) . ')' . "\n";
169
+ }
170
+ ?>
171
+ </script>
172
+ <!-- END: Freemius PHP Console Log -->
173
+ <?php
174
+ }
175
+
176
+ static function get_log() {
177
+ return self::$LOG;
178
+ }
179
+ }
freemius/includes/class-fs-plugin-updater.php ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ *
8
+ * @link https://github.com/easydigitaldownloads/EDD-License-handler/blob/master/EDD_SL_Plugin_Updater.php
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ // Uncomment this line for testing.
16
+ // set_site_transient( 'update_plugins', null );
17
+
18
+ class FS_Plugin_Updater {
19
+
20
+ /**
21
+ * @var Freemius
22
+ * @since 1.0.4
23
+ */
24
+ private $_fs;
25
+ /**
26
+ * @var FS_Logger
27
+ * @since 1.0.4
28
+ */
29
+ private $_logger;
30
+ /**
31
+ * @var object
32
+ * @since 1.1.8.1
33
+ */
34
+ private $_update_details;
35
+
36
+ function __construct( Freemius $freemius ) {
37
+ $this->_fs = $freemius;
38
+
39
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $freemius->get_slug() . '_updater', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
40
+
41
+ $this->_filters();
42
+ }
43
+
44
+ /**
45
+ * Initiate required filters.
46
+ *
47
+ * @author Vova Feldman (@svovaf)
48
+ * @since 1.0.4
49
+ */
50
+ private function _filters() {
51
+ // Override request for plugin information
52
+ add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
53
+
54
+ // WP 3.0+
55
+ add_filter( 'pre_set_site_transient_update_plugins', array(
56
+ &$this,
57
+ 'pre_set_site_transient_update_plugins_filter'
58
+ ) );
59
+
60
+ if ( ! $this->_fs->has_active_license() ) {
61
+ /**
62
+ * If user has the premium plugin's code but do NOT have an active license,
63
+ * encourage him to upgrade by showing that there's a new release, but instead
64
+ * of showing an update link, show upgrade link to the pricing page.
65
+ *
66
+ * @since 1.1.6
67
+ *
68
+ */
69
+ // WP 2.9+
70
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
71
+ &$this,
72
+ 'catch_plugin_update_row'
73
+ ), 9 );
74
+ add_action( "after_plugin_row_{$this->_fs->get_plugin_basename()}", array(
75
+ &$this,
76
+ 'edit_and_echo_plugin_update_row'
77
+ ), 11, 2 );
78
+ }
79
+
80
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
81
+ add_filter( 'http_request_host_is_external', array(
82
+ $this,
83
+ 'http_request_host_is_external_filter'
84
+ ), 10, 3 );
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Capture plugin update row by turning output buffering.
90
+ *
91
+ * @author Vova Feldman (@svovaf)
92
+ * @since 1.1.6
93
+ */
94
+ function catch_plugin_update_row() {
95
+ ob_start();
96
+ }
97
+
98
+ /**
99
+ * Overrides default update message format with "renew your license" message.
100
+ *
101
+ * @author Vova Feldman (@svovaf)
102
+ * @since 1.1.6
103
+ */
104
+ function edit_and_echo_plugin_update_row( $file, $plugin_data ) {
105
+ $plugin_update_row = ob_get_clean();
106
+
107
+ $current = get_site_transient( 'update_plugins' );
108
+ if ( ! isset( $current->response[ $file ] ) ) {
109
+ echo $plugin_update_row;
110
+
111
+ return false;
112
+ }
113
+
114
+ $r = $current->response[ $file ];
115
+
116
+ $plugin_update_row = preg_replace(
117
+ '/(\<div.+>)(.+)(\<a.+\<a.+)\<\/div\>/is',
118
+ '$1 $2 ' . sprintf(
119
+ __fs( 'renew-license-now' ),
120
+ '<a href="' . $this->_fs->pricing_url() . '">', '</a>',
121
+ $r->new_version ) .
122
+ '$4',
123
+ $plugin_update_row
124
+ );
125
+
126
+ echo $plugin_update_row;
127
+ }
128
+
129
+ /**
130
+ * Since WP version 3.6, a new security feature was added that denies access to repository with a local ip.
131
+ * During development mode we want to be able updating plugin versions via our localhost repository. This
132
+ * filter white-list all domains including "api.freemius".
133
+ *
134
+ * @link http://www.emanueletessore.com/wordpress-download-failed-valid-url-provided/
135
+ *
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.4
138
+ *
139
+ * @param bool $allow
140
+ * @param string $host
141
+ * @param string $url
142
+ *
143
+ * @return bool
144
+ */
145
+ function http_request_host_is_external_filter( $allow, $host, $url ) {
146
+ return ( false !== strpos( $host, 'freemius' ) ) ? true : $allow;
147
+ }
148
+
149
+ /**
150
+ * Check for Updates at the defined API endpoint and modify the update array.
151
+ *
152
+ * This function dives into the update api just when WordPress creates its update array,
153
+ * then adds a custom API call and injects the custom plugin data retrieved from the API.
154
+ * It is reassembled from parts of the native WordPress plugin update code.
155
+ * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
156
+ *
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.0.4
159
+ *
160
+ * @uses FS_Api
161
+ *
162
+ * @param stdClass $transient_data Update array build by WordPress.
163
+ *
164
+ * @return array Modified update array with custom plugin data.
165
+ */
166
+ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
167
+ $this->_logger->entrance();
168
+
169
+ if ( empty( $transient_data ) ||
170
+ defined( 'WP_FS__UNINSTALL_MODE' )
171
+ ) {
172
+ return $transient_data;
173
+ }
174
+
175
+ if ( ! isset( $this->_update_details ) ) {
176
+ // Get plugin's newest update.
177
+ $new_version = $this->_fs->get_update( false, false );
178
+
179
+ $this->_update_details = false;
180
+
181
+ if ( is_object( $new_version ) ) {
182
+ $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
183
+
184
+ $plugin_details = new stdClass();
185
+ $plugin_details->slug = $this->_fs->get_slug();
186
+ $plugin_details->new_version = $new_version->version;
187
+ $plugin_details->url = WP_FS__ADDRESS;
188
+ $plugin_details->package = $new_version->url;
189
+ $plugin_details->plugin = $this->_fs->get_plugin_basename();
190
+
191
+ /**
192
+ * Cache plugin details locally since set_site_transient( 'update_plugins' )
193
+ * called multiple times and the non wp.org plugins are filtered after the
194
+ * call to .org.
195
+ *
196
+ * @since 1.1.8.1
197
+ */
198
+ $this->_update_details = $plugin_details;
199
+ }
200
+ }
201
+
202
+ if ( is_object( $this->_update_details ) ) {
203
+ // Add plugin to transient data.
204
+ $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_update_details;
205
+ }
206
+
207
+ return $transient_data;
208
+ }
209
+
210
+ /**
211
+ * Try to fetch plugin's info from .org repository.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.0.5
215
+ *
216
+ * @param string $action
217
+ * @param object $args
218
+ *
219
+ * @return bool|mixed
220
+ */
221
+ static function _fetch_plugin_info_from_repository( $action, $args ) {
222
+ $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
223
+ if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
224
+ $url = set_url_scheme( $url, 'https' );
225
+ }
226
+
227
+ $args = array(
228
+ 'timeout' => 15,
229
+ 'body' => array(
230
+ 'action' => $action,
231
+ 'request' => serialize( $args )
232
+ )
233
+ );
234
+
235
+ $request = wp_remote_post( $url, $args );
236
+
237
+ if ( is_wp_error( $request ) ) {
238
+ return false;
239
+ }
240
+
241
+ $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
242
+
243
+ if ( ! is_object( $res ) && ! is_array( $res ) ) {
244
+ return false;
245
+ }
246
+
247
+ return $res;
248
+ }
249
+
250
+ /**
251
+ * Updates information on the "View version x.x details" page with custom data.
252
+ *
253
+ * @author Vova Feldman (@svovaf)
254
+ * @since 1.0.4
255
+ *
256
+ * @uses FS_Api
257
+ *
258
+ * @param object $data
259
+ * @param string $action
260
+ * @param mixed $args
261
+ *
262
+ * @return object
263
+ */
264
+ function plugins_api_filter( $data, $action = '', $args = null ) {
265
+ $this->_logger->entrance();
266
+
267
+ if ( ( 'plugin_information' !== $action ) ||
268
+ ! isset( $args->slug )
269
+ ) {
270
+ return $data;
271
+ }
272
+
273
+ $addon = false;
274
+ $is_addon = false;
275
+
276
+ if ( $this->_fs->get_slug() !== $args->slug ) {
277
+ $addon = $this->_fs->get_addon_by_slug( $args->slug );
278
+
279
+ if ( ! is_object( $addon ) ) {
280
+ return $data;
281
+ }
282
+
283
+ $is_addon = true;
284
+ }
285
+
286
+ $plugin_in_repo = false;
287
+ if ( ! $is_addon ) {
288
+ // Try to fetch info from .org repository.
289
+ $data = self::_fetch_plugin_info_from_repository( $action, $args );
290
+
291
+ $plugin_in_repo = ( false !== $data );
292
+ }
293
+
294
+ if ( ! $plugin_in_repo ) {
295
+ $data = $args;
296
+
297
+ // Fetch as much as possible info from local files.
298
+ $plugin_local_data = $this->_fs->get_plugin_data();
299
+ $data->name = $plugin_local_data['Name'];
300
+ $data->author = $plugin_local_data['Author'];
301
+ $data->sections = array(
302
+ 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
303
+ );
304
+
305
+ // @todo Store extra plugin info on Freemius or parse readme.txt markup.
306
+ /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
307
+
308
+ if ( !isset($info->error) ) {
309
+ $data = $info;
310
+ }*/
311
+ }
312
+
313
+ // Get plugin's newest update.
314
+ $new_version = $this->_fs->_fetch_latest_version( $is_addon ? $addon->id : false );
315
+
316
+ if ( $is_addon ) {
317
+ $data->name = $addon->title . ' ' . __fs( 'addon', $this->_fs->get_slug() );
318
+ $data->slug = $addon->slug;
319
+ $data->url = WP_FS__ADDRESS;
320
+ $data->package = $new_version->url;
321
+ }
322
+
323
+ if ( ! $plugin_in_repo ) {
324
+ $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
325
+ $data->requires = $new_version->requires_platform_version;
326
+ $data->tested = $new_version->tested_up_to_version;
327
+ }
328
+
329
+ $data->version = $new_version->version;
330
+ $data->download_link = $new_version->url;
331
+
332
+ return $data;
333
+ }
334
+ }
freemius/includes/class-fs-security.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ define( 'WP_FS__SECURITY_PARAMS_PREFIX', 's_' );
14
+
15
+ class FS_Security {
16
+ /**
17
+ * @var FS_Security
18
+ * @since 1.0.3
19
+ */
20
+ private static $_instance;
21
+ /**
22
+ * @var FS_Logger
23
+ * @since 1.0.3
24
+ */
25
+ private static $_logger;
26
+
27
+ public static function instance() {
28
+ if ( ! isset( self::$_instance ) ) {
29
+ self::$_instance = new FS_Security();
30
+ self::$_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
31
+ }
32
+
33
+ return self::$_instance;
34
+ }
35
+
36
+ private function __construct() {
37
+ }
38
+
39
+ function get_secure_token( FS_Scope_Entity $entity, $timestamp, $action = '' ) {
40
+ return md5(
41
+ $timestamp .
42
+ $entity->id .
43
+ $entity->secret_key .
44
+ $entity->public_key .
45
+ $action
46
+ );
47
+ }
48
+
49
+ function get_context_params( FS_Scope_Entity $entity, $timestamp = false, $action = '' ) {
50
+ if ( false === $timestamp ) {
51
+ $timestamp = time();
52
+ }
53
+
54
+ return array(
55
+ 's_ctx_type' => $entity->get_type(),
56
+ 's_ctx_id' => $entity->id,
57
+ 's_ctx_ts' => $timestamp,
58
+ 's_ctx_secure' => $this->get_secure_token( $entity, $timestamp, $action ),
59
+ );
60
+ }
61
+ }
freemius/includes/debug/class-fs-debug-bar-panel.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Extends Debug Bar plugin by adding a panel to show all Freemius API requests.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.3
18
+ *
19
+ * Class Freemius_Debug_Bar_Panel
20
+ */
21
+ class Freemius_Debug_Bar_Panel extends Debug_Bar_Panel {
22
+ function init() {
23
+ $this->title( 'Freemius' );
24
+ }
25
+
26
+ static function requests_count() {
27
+ if ( class_exists( 'Freemius_Api' ) ) {
28
+ $logger = Freemius_Api::GetLogger();
29
+ } else {
30
+ $logger = array();
31
+ }
32
+
33
+ return number_format( count( $logger ) );
34
+ }
35
+
36
+ static function total_time() {
37
+ if ( class_exists( 'Freemius_Api' ) ) {
38
+ $logger = Freemius_Api::GetLogger();
39
+ } else {
40
+ $logger = array();
41
+ }
42
+
43
+ $total_time = .0;
44
+ foreach ( $logger as $l ) {
45
+ $total_time += $l['total'];
46
+ }
47
+
48
+ return number_format( 100 * $total_time, 2 ) . ' ' . __fs( 'ms' );
49
+ }
50
+
51
+ function render() {
52
+ ?>
53
+ <div id='debug-bar-php'>
54
+ <?php fs_require_template( '/debug/api-calls.php' ) ?>
55
+ <br>
56
+ <?php fs_require_template( '/debug/scheduled-crons.php' ) ?>
57
+ <br>
58
+ <?php fs_require_template( '/debug/plugins-themes-sync.php' ) ?>
59
+ <br>
60
+ <?php fs_require_template( '/debug/logger.php' ) ?>
61
+ </div>
62
+ <?php
63
+ }
64
+ }
freemius/includes/debug/debug-bar-start.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! WP_FS__DEBUG_SDK ) {
14
+ return;
15
+ }
16
+
17
+ /**
18
+ * Initialize Freemius custom debug panels.
19
+ *
20
+ * @param array $panels Debug bar panels objects
21
+ *
22
+ * @return array Debug bar panels with your custom panels
23
+ */
24
+ function fs_custom_panels_init( $panels ) {
25
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
26
+ if ( FS_API__LOGGER_ON ) {
27
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
28
+ $panels[] = new Freemius_Debug_Bar_Panel();
29
+ }
30
+ }
31
+
32
+ return $panels;
33
+ }
34
+
35
+ function fs_custom_status_init( $statuses ) {
36
+ if ( class_exists( 'Debug_Bar_Panel' ) ) {
37
+ if ( FS_API__LOGGER_ON ) {
38
+ require_once dirname( __FILE__ ) . '/class-fs-debug-bar-panel.php';
39
+ $statuses[] = array(
40
+ 'fs_api_requests',
41
+ __fs( 'Freemius API' ),
42
+ Freemius_Debug_Bar_Panel::requests_count() . ' ' . __fs( 'Requests' ) .
43
+ ' (' . Freemius_Debug_Bar_Panel::total_time() . ')'
44
+ );
45
+ }
46
+ }
47
+
48
+ return $statuses;
49
+ }
50
+
51
+ add_filter( 'debug_bar_panels', 'fs_custom_panels_init' );
52
+ add_filter( 'debug_bar_statuses', 'fs_custom_status_init' );
freemius/includes/entities/class-fs-entity.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Get object's public variables.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.0.0
18
+ *
19
+ * @param object $object
20
+ *
21
+ * @return array
22
+ */
23
+ function fs_get_object_public_vars( $object ) {
24
+ return get_object_vars( $object );
25
+ }
26
+
27
+ class FS_Entity {
28
+ /**
29
+ * @var number
30
+ */
31
+ public $id;
32
+ /**
33
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
34
+ */
35
+ public $updated;
36
+ /**
37
+ * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format.
38
+ */
39
+ public $created;
40
+
41
+ /**
42
+ * @param bool|stdClass $entity
43
+ */
44
+ function __construct( $entity = false ) {
45
+ if ( ! ( $entity instanceof stdClass ) ) {
46
+ return;
47
+ }
48
+
49
+ $props = fs_get_object_public_vars( $this );
50
+
51
+ foreach ( $props as $key => $def_value ) {
52
+ $this->{$key} = isset( $entity->{$key} ) ?
53
+ $entity->{$key} :
54
+ $def_value;
55
+ }
56
+ }
57
+
58
+ static function get_type() {
59
+ return 'type';
60
+ }
61
+
62
+ /**
63
+ * @author Vova Feldman (@svovaf)
64
+ * @since 1.0.6
65
+ *
66
+ * @param FS_Entity $entity1
67
+ * @param FS_Entity $entity2
68
+ *
69
+ * @return bool
70
+ */
71
+ static function equals( $entity1, $entity2 ) {
72
+ if ( is_null( $entity1 ) && is_null( $entity2 ) ) {
73
+ return true;
74
+ } else if ( is_object( $entity1 ) && is_object( $entity2 ) ) {
75
+ return ( $entity1->id == $entity2->id );
76
+ } else if ( is_object( $entity1 ) ) {
77
+ return is_null( $entity1->id );
78
+ } else {
79
+ return is_null( $entity2->id );
80
+ }
81
+ }
82
+
83
+ private $_is_updated = false;
84
+
85
+ /**
86
+ * Update object property.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.9
90
+ *
91
+ * @param string|array[string]mixed $key
92
+ * @param string|bool $val
93
+ *
94
+ * @return bool
95
+ */
96
+ function update( $key, $val = false ) {
97
+ if ( ! is_array( $key ) ) {
98
+ $key = array( $key => $val );
99
+ }
100
+
101
+ $is_updated = false;
102
+
103
+ foreach ( $key as $k => $v ) {
104
+ if ( $this->{$k} === $v ) {
105
+ continue;
106
+ }
107
+
108
+ if ( ( is_string( $this->{$k} ) && is_numeric( $v ) ||
109
+ ( is_numeric( $this->{$k} ) && is_string( $v ) ) ) &&
110
+ $this->{$k} == $v
111
+ ) {
112
+ continue;
113
+ }
114
+
115
+ // Update value.
116
+ $this->{$k} = $v;
117
+
118
+ $is_updated = true;
119
+ }
120
+
121
+ $this->_is_updated = $is_updated;
122
+
123
+ return $is_updated;
124
+ }
125
+
126
+ /**
127
+ * Checks if entity was updated.
128
+ *
129
+ * @author Vova Feldman (@svovaf)
130
+ * @since 1.0.9
131
+ *
132
+ * @return bool
133
+ */
134
+ function is_updated() {
135
+ return $this->_is_updated;
136
+ }
137
+
138
+ /**
139
+ * @param $id
140
+ *
141
+ * @author Vova Feldman (@svovaf)
142
+ * @since 1.1.2
143
+ *
144
+ * @return bool
145
+ */
146
+ static function is_valid_id($id){
147
+ return is_numeric($id);
148
+ }
149
+ }
freemius/includes/entities/class-fs-plugin-info.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Info extends FS_Entity {
14
+ public $plugin_id;
15
+ public $description;
16
+ public $short_description;
17
+ public $banner_url;
18
+ public $card_banner_url;
19
+ public $selling_point_0;
20
+ public $selling_point_1;
21
+ public $selling_point_2;
22
+ public $screenshots;
23
+
24
+ /**
25
+ * @param stdClass|bool $plugin_info
26
+ */
27
+ function __construct( $plugin_info = false ) {
28
+ parent::__construct( $plugin_info );
29
+ }
30
+
31
+ static function get_type() {
32
+ return 'plugin';
33
+ }
34
+ }
freemius/includes/entities/class-fs-plugin-license.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_License extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $user_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $pricing_id;
33
+ /**
34
+ * @var int|null
35
+ */
36
+ public $quota;
37
+ /**
38
+ * @var int
39
+ */
40
+ public $activated;
41
+ /**
42
+ * @var int
43
+ */
44
+ public $activated_local;
45
+ /**
46
+ * @var string
47
+ */
48
+ public $expiration;
49
+ /**
50
+ * @var bool $is_free_localhost Defaults to true. If true, allow unlimited localhost installs with the same
51
+ * license.
52
+ */
53
+ public $is_free_localhost;
54
+ /**
55
+ * @var bool $is_block_features Defaults to true. If false, don't block features after license expiry - only
56
+ * block updates and support.
57
+ */
58
+ public $is_block_features;
59
+ /**
60
+ * @var bool
61
+ */
62
+ public $is_cancelled;
63
+
64
+ #endregion Properties
65
+
66
+ /**
67
+ * @param stdClass|bool $license
68
+ */
69
+ function __construct( $license = false ) {
70
+ parent::__construct( $license );
71
+ }
72
+
73
+ static function get_type() {
74
+ return 'license';
75
+ }
76
+
77
+ /**
78
+ * Check how many site activations left.
79
+ *
80
+ * @author Vova Feldman (@svovaf)
81
+ * @since 1.0.5
82
+ *
83
+ * @return int
84
+ */
85
+ function left() {
86
+ if ( $this->is_expired() ) {
87
+ return 0;
88
+ }
89
+
90
+ return ( $this->quota - $this->activated - ( $this->is_free_localhost ? 0 : $this->activated_local ) );
91
+ }
92
+
93
+ /**
94
+ * Check if single site license.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.8.1
98
+ *
99
+ * @return bool
100
+ */
101
+ function is_single_site() {
102
+ return ( is_numeric( $this->quota ) && 1 == $this->quota );
103
+ }
104
+
105
+ /**
106
+ * @author Vova Feldman (@svovaf)
107
+ * @since 1.0.5
108
+ *
109
+ * @return bool
110
+ */
111
+ function is_expired() {
112
+ return ! $this->is_lifetime() && ( strtotime( $this->expiration ) < WP_FS__SCRIPT_START_TIME );
113
+ }
114
+
115
+ /**
116
+ * @author Vova Feldman (@svovaf)
117
+ * @since 1.0.6
118
+ *
119
+ * @return bool
120
+ */
121
+ function is_lifetime() {
122
+ return is_null( $this->expiration );
123
+ }
124
+
125
+ /**
126
+ * Check if license is fully utilized.
127
+ *
128
+ * @author Vova Feldman (@svovaf)
129
+ * @since 1.0.6
130
+ *
131
+ * @param bool $is_localhost
132
+ *
133
+ * @return bool
134
+ */
135
+ function is_utilized( $is_localhost = null ) {
136
+ if ( is_null( $is_localhost ) ) {
137
+ $is_localhost = WP_FS__IS_LOCALHOST_FOR_SERVER;
138
+ }
139
+
140
+ return ! ( $this->is_free_localhost && $is_localhost ) &&
141
+ ( $this->quota <= $this->activated + ( $this->is_free_localhost ? 0 : $this->activated_local ) );
142
+ }
143
+
144
+ /**
145
+ * Check if license's plan features are enabled.
146
+ *
147
+ * - Either if plan not expired
148
+ * - If expired, based on the configuration to block features or not.
149
+ *
150
+ * @author Vova Feldman (@svovaf)
151
+ * @since 1.0.6
152
+ *
153
+ * @return bool
154
+ */
155
+ function is_features_enabled() {
156
+ return ( ! $this->is_block_features || ! $this->is_expired() );
157
+ }
158
+
159
+ /**
160
+ * Subscription considered to be new without any payments
161
+ * if the license expires in less than 24 hours
162
+ * from the license creation.
163
+ *
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.9
166
+ *
167
+ * @return bool
168
+ */
169
+ function is_first_payment_pending() {
170
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->expiration ) - strtotime( $this->created ) );
171
+ }
172
+ }
freemius/includes/entities/class-fs-plugin-plan.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Plan extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plugin_id;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $name;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $title;
29
+ /**
30
+ * @var string
31
+ */
32
+ public $description;
33
+ /**
34
+ * @var bool Defaults to true. If true, allow unlimited localhost installs with the same license.
35
+ */
36
+ public $is_free_localhost;
37
+ /**
38
+ * @var bool Defaults to true. If false, don't block features after license expiry - only block updates and
39
+ * support.
40
+ */
41
+ public $is_block_features;
42
+ /**
43
+ * @var int
44
+ */
45
+ public $license_type;
46
+ /**
47
+ * @var bool
48
+ */
49
+ public $is_https_support;
50
+ /**
51
+ * @var int Trial days.
52
+ */
53
+ public $trial_period;
54
+ /**
55
+ * @var string If true, require payment for trial.
56
+ */
57
+ public $is_require_subscription;
58
+ /**
59
+ * @var string Knowledge Base URL.
60
+ */
61
+ public $support_kb;
62
+ /**
63
+ * @var string Support Forum URL.
64
+ */
65
+ public $support_forum;
66
+ /**
67
+ * @var string Support email address.
68
+ */
69
+ public $support_email;
70
+ /**
71
+ * @var string Support phone.
72
+ */
73
+ public $support_phone;
74
+ /**
75
+ * @var string Support skype username.
76
+ */
77
+ public $support_skype;
78
+ /**
79
+ * @var bool Is personal success manager supported with the plan.
80
+ */
81
+ public $is_success_manager;
82
+ /**
83
+ * @var bool Is featured plan.
84
+ */
85
+ public $is_featured;
86
+
87
+ #endregion Properties
88
+
89
+ /**
90
+ * @param object|bool $plan
91
+ */
92
+ function __construct( $plan = false ) {
93
+ parent::__construct( $plan );
94
+
95
+ if ( is_object( $plan ) ) {
96
+ $this->name = strtolower( $plan->name );
97
+ }
98
+ }
99
+
100
+ static function get_type() {
101
+ return 'plan';
102
+ }
103
+
104
+ /**
105
+ * @author Vova Feldman (@svovaf)
106
+ * @since 1.0.9
107
+ *
108
+ * @return bool
109
+ */
110
+ function is_free() {
111
+ return ( 'free' === $this->name );
112
+ }
113
+
114
+ /**
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.0.9
117
+ *
118
+ * @return bool
119
+ */
120
+ function has_trial() {
121
+ return ! $this->is_free() &&
122
+ is_numeric( $this->trial_period ) && ( $this->trial_period > 0 );
123
+ }
124
+ }
freemius/includes/entities/class-fs-plugin-tag.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Tag extends FS_Entity {
14
+ public $version;
15
+ public $url;
16
+
17
+ function __construct( $tag = false ) {
18
+ parent::__construct( $tag );
19
+ }
20
+
21
+ static function get_type() {
22
+ return 'tag';
23
+ }
24
+ }
freemius/includes/entities/class-fs-plugin.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin extends FS_Scope_Entity {
14
+ /**
15
+ * @since 1.0.6
16
+ * @var null|number
17
+ */
18
+ public $parent_plugin_id;
19
+ /**
20
+ * @var string
21
+ */
22
+ public $title;
23
+ /**
24
+ * @var string
25
+ */
26
+ public $slug;
27
+
28
+ #region Install Specific Properties
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ public $file;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $version;
38
+ /**
39
+ * @var bool
40
+ */
41
+ public $auto_update;
42
+ /**
43
+ * @var FS_Plugin_Info
44
+ */
45
+ public $info;
46
+ /**
47
+ * @since 1.0.9
48
+ *
49
+ * @var bool
50
+ */
51
+ public $is_premium;
52
+ /**
53
+ * @since 1.0.9
54
+ *
55
+ * @var bool
56
+ */
57
+ public $is_live;
58
+
59
+ #endregion Install Specific Properties
60
+
61
+ /**
62
+ * @param stdClass|bool $plugin
63
+ */
64
+ function __construct( $plugin = false ) {
65
+ parent::__construct( $plugin );
66
+
67
+ $this->is_premium = false;
68
+ $this->is_live = true;
69
+
70
+ if ( isset( $plugin->info ) && is_object( $plugin->info ) ) {
71
+ $this->info = new FS_Plugin_Info( $plugin->info );
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Check if plugin is an add-on (has parent).
77
+ *
78
+ * @author Vova Feldman (@svovaf)
79
+ * @since 1.0.6
80
+ *
81
+ * @return bool
82
+ */
83
+ function is_addon() {
84
+ return isset( $this->parent_plugin_id ) && is_numeric( $this->parent_plugin_id );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'plugin';
89
+ }
90
+ }
freemius/includes/entities/class-fs-pricing.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius for EDD Add-On
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.0
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Pricing extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $plan_id;
21
+ /**
22
+ * @var int
23
+ */
24
+ public $licenses;
25
+ /**
26
+ * @var null|float
27
+ */
28
+ public $monthly_price;
29
+ /**
30
+ * @var null|float
31
+ */
32
+ public $annual_price;
33
+ /**
34
+ * @var null|float
35
+ */
36
+ public $lifetime_price;
37
+
38
+ #endregion Properties
39
+
40
+ /**
41
+ * @param object|bool $pricing
42
+ */
43
+ function __construct( $pricing = false ) {
44
+ parent::__construct( $pricing );
45
+ }
46
+
47
+ static function get_type() {
48
+ return 'pricing';
49
+ }
50
+
51
+ /**
52
+ * @author Vova Feldman (@svovaf)
53
+ * @since 1.1.8
54
+ *
55
+ * @return bool
56
+ */
57
+ function has_monthly() {
58
+ return ( is_numeric( $this->monthly_price ) && $this->monthly_price > 0 );
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.8
64
+ *
65
+ * @return bool
66
+ */
67
+ function has_annual() {
68
+ return ( is_numeric( $this->annual_price ) && $this->annual_price > 0 );
69
+ }
70
+
71
+ /**
72
+ * @author Vova Feldman (@svovaf)
73
+ * @since 1.1.8
74
+ *
75
+ * @return bool
76
+ */
77
+ function has_lifetime() {
78
+ return ( is_numeric( $this->lifetime_price ) && $this->lifetime_price > 0 );
79
+ }
80
+
81
+ /**
82
+ * Check if unlimited licenses pricing.
83
+ *
84
+ * @author Vova Feldman (@svovaf)
85
+ * @since 1.1.8
86
+ *
87
+ * @return bool
88
+ */
89
+ function is_unlimited() {
90
+ return is_null( $this->licenses );
91
+ }
92
+
93
+
94
+ /**
95
+ * Check if pricing has more than one billing cycle.
96
+ *
97
+ * @author Vova Feldman (@svovaf)
98
+ * @since 1.1.8
99
+ *
100
+ * @return bool
101
+ */
102
+ function is_multi_cycle() {
103
+ $cycles = 0;
104
+ if ( $this->has_monthly() ) {
105
+ $cycles ++;
106
+ }
107
+ if ( $this->has_annual() ) {
108
+ $cycles ++;
109
+ }
110
+ if ( $this->has_lifetime() ) {
111
+ $cycles ++;
112
+ }
113
+
114
+ return $cycles > 1;
115
+ }
116
+
117
+ /**
118
+ * Get annual over monthly discount.
119
+ *
120
+ * @author Vova Feldman (@svovaf)
121
+ * @since 1.1.8
122
+ *
123
+ * @return int
124
+ */
125
+ function annual_discount_percentage() {
126
+ return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
127
+ }
128
+
129
+ /**
130
+ * Get annual over monthly savings.
131
+ *
132
+ * @author Vova Feldman (@svovaf)
133
+ * @since 1.1.8
134
+ *
135
+ * @return float
136
+ */
137
+ function annual_savings() {
138
+ return ( $this->monthly_price * 12 - $this->annual_price ) * ( $this->is_unlimited() ? 1 : $this->licenses );
139
+ }
140
+
141
+ }
freemius/includes/entities/class-fs-scope-entity.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Scope_Entity extends FS_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $public_key;
18
+ /**
19
+ * @var string
20
+ */
21
+ public $secret_key;
22
+
23
+ /**
24
+ * @param bool|stdClass $scope_entity
25
+ */
26
+ function __construct( $scope_entity = false ) {
27
+ parent::__construct( $scope_entity );
28
+ }
29
+ }
freemius/includes/entities/class-fs-site.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Site extends FS_Scope_Entity {
14
+ /**
15
+ * @var string
16
+ */
17
+ public $slug;
18
+ /**
19
+ * @var number
20
+ */
21
+ public $site_id;
22
+ /**
23
+ * @var number
24
+ */
25
+ public $plugin_id;
26
+ /**
27
+ * @var number
28
+ */
29
+ public $user_id;
30
+ /**
31
+ * @var string
32
+ */
33
+ public $title;
34
+ /**
35
+ * @var string
36
+ */
37
+ public $url;
38
+ /**
39
+ * @var string
40
+ */
41
+ public $version;
42
+ /**
43
+ * @var string E.g. en-GB
44
+ */
45
+ public $language;
46
+ /**
47
+ * @var string E.g. UTF-8
48
+ */
49
+ public $charset;
50
+ /**
51
+ * @var string Platform version (e.g WordPress version).
52
+ */
53
+ public $platform_version;
54
+ /**
55
+ * @var string Programming language version (e.g PHP version).
56
+ */
57
+ public $programming_language_version;
58
+ /**
59
+ * @var FS_Plugin_Plan $plan
60
+ */
61
+ public $plan;
62
+ /**
63
+ * @var number|null
64
+ */
65
+ public $license_id;
66
+ /**
67
+ * @var number|null
68
+ */
69
+ public $trial_plan_id;
70
+ /**
71
+ * @var string|null
72
+ */
73
+ public $trial_ends;
74
+ /**
75
+ * @since 1.0.9
76
+ *
77
+ * @var bool
78
+ */
79
+ public $is_premium = false;
80
+
81
+ /**
82
+ * @param stdClass|bool $site
83
+ */
84
+ function __construct( $site = false ) {
85
+ $this->plan = new FS_Plugin_Plan();
86
+
87
+ parent::__construct( $site );
88
+
89
+ if ( is_object( $site ) ) {
90
+ $this->plan->id = $site->plan_id;
91
+ }
92
+ }
93
+
94
+ static function get_type() {
95
+ return 'install';
96
+ }
97
+
98
+ function is_localhost() {
99
+ // The server has no way to verify if localhost unless localhost appears in domain.
100
+ return WP_FS__IS_LOCALHOST_FOR_SERVER;
101
+ // return (substr($_SERVER['REMOTE_ADDR'], 0, 4) == '127.' || $_SERVER['REMOTE_ADDR'] == '::1');
102
+ }
103
+
104
+ /**
105
+ * Check if site in trial.
106
+ *
107
+ * @author Vova Feldman (@svovaf)
108
+ * @since 1.0.9
109
+ *
110
+ * @return bool
111
+ */
112
+ function is_trial() {
113
+ return is_numeric( $this->trial_plan_id ) && ( strtotime( $this->trial_ends ) > WP_FS__SCRIPT_START_TIME );
114
+ }
115
+
116
+ /**
117
+ * Check if user already utilized the trial with the current install.
118
+ *
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.0.9
121
+ *
122
+ * @return bool
123
+ */
124
+ function is_trial_utilized() {
125
+ return is_numeric( $this->trial_plan_id );
126
+ }
127
+ }
freemius/includes/entities/class-fs-subscription.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.9
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Subscription extends FS_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var number
19
+ */
20
+ public $user_id;
21
+ /**
22
+ * @var number
23
+ */
24
+ public $install_id;
25
+ /**
26
+ * @var number
27
+ */
28
+ public $plan_id;
29
+ /**
30
+ * @var number
31
+ */
32
+ public $license_id;
33
+ /**
34
+ * @var float
35
+ */
36
+ public $total_gross;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $amount_per_cycle;
41
+ /**
42
+ * @var int # of months
43
+ */
44
+ public $billing_cycle;
45
+ /**
46
+ * @var float
47
+ */
48
+ public $outstanding_balance;
49
+ /**
50
+ * @var int
51
+ */
52
+ public $failed_payments;
53
+ /**
54
+ * @var string
55
+ */
56
+ public $gateway;
57
+ /**
58
+ * @var string
59
+ */
60
+ public $external_id;
61
+ /**
62
+ * @var string|null
63
+ */
64
+ public $trial_ends;
65
+ /**
66
+ * @var string|null Datetime of the next payment, or null if cancelled
67
+ */
68
+ public $next_payment;
69
+ /**
70
+ * @var string|null
71
+ */
72
+ public $vat_id;
73
+ /**
74
+ * @var string Two characters country code
75
+ */
76
+ public $country_code;
77
+
78
+ #endregion Properties
79
+
80
+ /**
81
+ * @param object|bool $subscription
82
+ */
83
+ function __construct( $subscription = false ) {
84
+ parent::__construct( $subscription );
85
+ }
86
+
87
+ static function get_type() {
88
+ return 'subscription';
89
+ }
90
+
91
+ /**
92
+ * Check if subscription is active.
93
+ *
94
+ * @author Vova Feldman (@svovaf)
95
+ * @since 1.0.9
96
+ *
97
+ * @return bool
98
+ */
99
+ function is_active() {
100
+ return ! empty( $this->next_payment ) &&
101
+ ( strtotime( $this->next_payment ) > WP_FS__SCRIPT_START_TIME );
102
+ }
103
+
104
+ /**
105
+ * Subscription considered to be new without any payments
106
+ * if the next payment should be made within less than 24 hours
107
+ * from the subscription creation.
108
+ *
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.9
111
+ *
112
+ * @return bool
113
+ */
114
+ function is_first_payment_pending() {
115
+ return ( WP_FS__TIME_24_HOURS_IN_SEC >= strtotime( $this->next_payment ) - strtotime( $this->created ) );
116
+ }
117
+
118
+ /**
119
+ * @author Vova Feldman (@svovaf)
120
+ * @since 1.1.7
121
+ */
122
+ function has_trial() {
123
+ return ! is_null( $this->trial_ends );
124
+ }
125
+ }
freemius/includes/entities/class-fs-user.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_User extends FS_Scope_Entity {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ public $email;
21
+ /**
22
+ * @var string
23
+ */
24
+ public $first;
25
+ /**
26
+ * @var string
27
+ */
28
+ public $last;
29
+ /**
30
+ * @var bool
31
+ */
32
+ public $is_verified;
33
+ /**
34
+ * @var string|null
35
+ */
36
+ public $customer_id;
37
+ /**
38
+ * @var float
39
+ */
40
+ public $gross;
41
+
42
+ #endregion Properties
43
+
44
+ /**
45
+ * @param object|bool $user
46
+ */
47
+ function __construct( $user = false ) {
48
+ parent::__construct( $user );
49
+ }
50
+
51
+ function get_name() {
52
+ return trim( ucfirst( trim( is_string( $this->first ) ? $this->first : '' ) ) . ' ' . ucfirst( trim( is_string( $this->last ) ? $this->last : '' ) ) );
53
+ }
54
+
55
+ function is_verified() {
56
+ return ( isset( $this->is_verified ) && true === $this->is_verified );
57
+ }
58
+
59
+ static function get_type() {
60
+ return 'user';
61
+ }
62
+ }
freemius/includes/fs-core-functions.php ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ global $fs_core_logger;
14
+
15
+ $fs_core_logger = FS_Logger::get_logger( WP_FS__SLUG . '_core', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
16
+
17
+ if ( ! function_exists( 'fs_dummy' ) ) {
18
+ function fs_dummy() {
19
+ }
20
+ }
21
+
22
+ /* Url.
23
+ --------------------------------------------------------------------------------------------*/
24
+ function fs_get_url_daily_cache_killer() {
25
+ return date( '\YY\Mm\Dd' );
26
+ }
27
+
28
+ /* Templates / Views.
29
+ --------------------------------------------------------------------------------------------*/
30
+ if ( ! function_exists( 'fs_get_template_path' ) ) {
31
+ function fs_get_template_path( $path ) {
32
+ return WP_FS__DIR_TEMPLATES . '/' . trim( $path, '/' );
33
+ }
34
+
35
+ function fs_include_template( $path, &$params = null ) {
36
+ $VARS = &$params;
37
+ include( fs_get_template_path( $path ) );
38
+ }
39
+
40
+ function fs_include_once_template( $path, &$params = null ) {
41
+ $VARS = &$params;
42
+ include_once( fs_get_template_path( $path ) );
43
+ }
44
+
45
+ function fs_require_template( $path, &$params = null ) {
46
+ $VARS = &$params;
47
+ require( fs_get_template_path( $path ) );
48
+ }
49
+
50
+ function fs_require_once_template( $path, &$params = null ) {
51
+ $VARS = &$params;
52
+ require_once( fs_get_template_path( $path ) );
53
+ }
54
+
55
+ function fs_get_template( $path, &$params = null ) {
56
+ ob_start();
57
+
58
+ $VARS = &$params;
59
+ require_once( fs_get_template_path( $path ) );
60
+
61
+ return ob_get_clean();
62
+ }
63
+ }
64
+
65
+ /* Scripts and styles including.
66
+ --------------------------------------------------------------------------------------------*/
67
+ function fs_enqueue_local_style( $handle, $path, $deps = array(), $ver = false, $media = 'all' ) {
68
+ global $fs_core_logger;
69
+ if ( $fs_core_logger->is_on() ) {
70
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
71
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_CSS . trim( $path, '/' ) ) );
72
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ) );
73
+ }
74
+
75
+ wp_enqueue_style( $handle, plugins_url( plugin_basename( WP_FS__DIR_CSS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $media );
76
+ }
77
+
78
+ function fs_enqueue_local_script( $handle, $path, $deps = array(), $ver = false, $in_footer = 'all' ) {
79
+ global $fs_core_logger;
80
+ if ( $fs_core_logger->is_on() ) {
81
+ $fs_core_logger->info( 'handle = ' . $handle . '; path = ' . $path . ';' );
82
+ $fs_core_logger->info( 'plugin_basename = ' . plugins_url( WP_FS__DIR_JS . trim( $path, '/' ) ) );
83
+ $fs_core_logger->info( 'plugins_url = ' . plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ) );
84
+ }
85
+
86
+ wp_enqueue_script( $handle, plugins_url( plugin_basename( WP_FS__DIR_JS . '/' . trim( $path, '/' ) ) ), $deps, $ver, $in_footer );
87
+ }
88
+
89
+ function fs_img_url( $path, $img_dir = WP_FS__DIR_IMG ) {
90
+ return plugins_url( plugin_basename( $img_dir . '/' . trim( $path, '/' ) ) );
91
+ }
92
+
93
+ /* Request handlers.
94
+ --------------------------------------------------------------------------------------------*/
95
+ /**
96
+ * @param string $key
97
+ * @param mixed $def
98
+ *
99
+ * @return mixed
100
+ */
101
+ function fs_request_get( $key, $def = false ) {
102
+ return isset( $_REQUEST[ $key ] ) ? $_REQUEST[ $key ] : $def;
103
+ }
104
+
105
+ function fs_request_has( $key ) {
106
+ return isset( $_REQUEST[ $key ] );
107
+ }
108
+
109
+ function fs_request_get_bool( $key, $def = false ) {
110
+ if ( ! isset( $_REQUEST[ $key ] ) ) {
111
+ return $def;
112
+ }
113
+
114
+ if ( 1 == $_REQUEST[ $key ] || 'true' === strtolower( $_REQUEST[ $key ] ) ) {
115
+ return true;
116
+ }
117
+
118
+ if ( 0 == $_REQUEST[ $key ] || 'false' === strtolower( $_REQUEST[ $key ] ) ) {
119
+ return false;
120
+ }
121
+
122
+ return $def;
123
+ }
124
+
125
+ function fs_request_is_post() {
126
+ return ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
127
+ }
128
+
129
+ function fs_request_is_get() {
130
+ return ( 'get' === strtolower( $_SERVER['REQUEST_METHOD'] ) );
131
+ }
132
+
133
+ function fs_get_action( $action_key = 'action' ) {
134
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
135
+ return strtolower( $_REQUEST[ $action_key ] );
136
+ }
137
+
138
+ if ( 'action' == $action_key ) {
139
+ $action_key = 'fs_action';
140
+
141
+ if ( ! empty( $_REQUEST[ $action_key ] ) ) {
142
+ return strtolower( $_REQUEST[ $action_key ] );
143
+ }
144
+ }
145
+
146
+ return false;
147
+ }
148
+
149
+ function fs_request_is_action( $action, $action_key = 'action' ) {
150
+ return ( strtolower( $action ) === fs_get_action( $action_key ) );
151
+ }
152
+
153
+ function fs_is_plugin_page( $menu_slug ) {
154
+ return ( is_admin() && $_REQUEST['page'] === $menu_slug );
155
+ }
156
+
157
+ /* Core UI.
158
+ --------------------------------------------------------------------------------------------*/
159
+ /**
160
+ * @param string $slug
161
+ * @param string $page
162
+ * @param string $action
163
+ * @param string $title
164
+ * @param array $params
165
+ * @param bool $is_primary
166
+ * @param string|bool $icon_class Optional class for an icon (since 1.1.7).
167
+ * @param string|bool $confirmation Optional confirmation message before submit (since 1.1.7).
168
+ * @param string $method Since 1.1.7
169
+ *
170
+ * @uses fs_ui_get_action_button()
171
+ */
172
+ function fs_ui_action_button(
173
+ $slug,
174
+ $page,
175
+ $action,
176
+ $title,
177
+ $params = array(),
178
+ $is_primary = true,
179
+ $icon_class = false,
180
+ $confirmation = false,
181
+ $method = 'GET'
182
+ ) {
183
+ echo fs_ui_get_action_button(
184
+ $slug,
185
+ $page,
186
+ $action,
187
+ $title,
188
+ $params,
189
+ $is_primary,
190
+ $icon_class,
191
+ $confirmation,
192
+ $method
193
+ );
194
+ }
195
+
196
+ /**
197
+ * @author Vova Feldman (@svovaf)
198
+ * @since 1.1.7
199
+ *
200
+ * @param string $slug
201
+ * @param string $page
202
+ * @param string $action
203
+ * @param string $title
204
+ * @param array $params
205
+ * @param bool $is_primary
206
+ * @param string|bool $icon_class Optional class for an icon.
207
+ * @param string|bool $confirmation Optional confirmation message before submit.
208
+ * @param string $method
209
+ *
210
+ * @return string
211
+ */
212
+ function fs_ui_get_action_button(
213
+ $slug,
214
+ $page,
215
+ $action,
216
+ $title,
217
+ $params = array(),
218
+ $is_primary = true,
219
+ $icon_class = false,
220
+ $confirmation = false,
221
+ $method = 'GET'
222
+ ) {
223
+ // Prepend icon (if set).
224
+ $title = ( is_string( $icon_class ) ? '<i class="' . $icon_class . '"></i> ' : '' ) . $title;
225
+
226
+ if ( is_string( $confirmation ) ) {
227
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="if (confirm(\'%s\')) this.parentNode.submit(); return false;">%s</a></form>',
228
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
229
+ $method,
230
+ $action,
231
+ wp_nonce_field( $action, '_wpnonce', true, false ),
232
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
233
+ $confirmation,
234
+ $title
235
+ );
236
+ } else if ( 'GET' !== strtoupper( $method ) ) {
237
+ return sprintf( '<form action="%s" method="%s"><input type="hidden" name="fs_action" value="%s">%s<a href="#" class="%s" onclick="this.parentNode.submit(); return false;">%s</a></form>',
238
+ freemius( $slug )->_get_admin_page_url( $page, $params ),
239
+ $method,
240
+ $action,
241
+ wp_nonce_field( $action, '_wpnonce', true, false ),
242
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
243
+ $title
244
+ );
245
+ } else {
246
+ return sprintf( '<a href="%s" class="%s">%s</a></form>',
247
+ wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ),
248
+ 'button' . ( $is_primary ? ' button-primary' : '' ),
249
+ $title
250
+ );
251
+ }
252
+ }
253
+
254
+ function fs_ui_action_link( $slug, $page, $action, $title, $params = array() ) {
255
+ ?><a class=""
256
+ href="<?php echo wp_nonce_url( freemius( $slug )->_get_admin_page_url( $page, array_merge( $params, array( 'fs_action' => $action ) ) ), $action ) ?>"><?php echo $title ?></a><?php
257
+ }
258
+
259
+ /*function fs_error_handler($errno, $errstr, $errfile, $errline)
260
+ {
261
+ if (false === strpos($errfile, 'freemius/'))
262
+ {
263
+ // @todo Dump Freemius errors to local log.
264
+ }
265
+
266
+ // switch ($errno) {
267
+ // case E_USER_ERROR:
268
+ // break;
269
+ // case E_WARNING:
270
+ // case E_USER_WARNING:
271
+ // break;
272
+ // case E_NOTICE:
273
+ // case E_USER_NOTICE:
274
+ // break;
275
+ // default:
276
+ // break;
277
+ // }
278
+ }
279
+
280
+ set_error_handler('fs_error_handler');*/
281
+
282
+ function fs_nonce_url( $actionurl, $action = - 1, $name = '_wpnonce' ) {
283
+ // $actionurl = str_replace( '&amp;', '&', $actionurl );
284
+ return add_query_arg( $name, wp_create_nonce( $action ), $actionurl );
285
+ }
286
+
287
+ if ( ! function_exists( 'fs_starts_with' ) ) {
288
+ /**
289
+ * Check if string starts with.
290
+ *
291
+ * @author Vova Feldman (@svovaf)
292
+ * @since 1.1.3
293
+ *
294
+ * @param string $haystack
295
+ * @param string $needle
296
+ *
297
+ * @return bool
298
+ */
299
+ function fs_starts_with( $haystack, $needle ) {
300
+ $length = strlen( $needle );
301
+
302
+ return ( substr( $haystack, 0, $length ) === $needle );
303
+ }
304
+ }
305
+
306
+ #region Url Canonization ------------------------------------------------------------------
307
+
308
+ if ( ! function_exists( 'fs_canonize_url' ) ) {
309
+ /**
310
+ * @author Vova Feldman (@svovaf)
311
+ * @since 1.1.3
312
+ *
313
+ * @param string $url
314
+ * @param bool $omit_host
315
+ * @param array $ignore_params
316
+ *
317
+ * @return string
318
+ */
319
+ function fs_canonize_url( $url, $omit_host = false, $ignore_params = array() ) {
320
+ $parsed_url = parse_url( strtolower( $url ) );
321
+
322
+ // if ( ! isset( $parsed_url['host'] ) ) {
323
+ // return $url;
324
+ // }
325
+
326
+ $canonical = ( ( $omit_host || ! isset( $parsed_url['host'] ) ) ? '' : $parsed_url['host'] ) . $parsed_url['path'];
327
+
328
+ if ( isset( $parsed_url['query'] ) ) {
329
+ parse_str( $parsed_url['query'], $queryString );
330
+ $canonical .= '?' . fs_canonize_query_string( $queryString, $ignore_params );
331
+ }
332
+
333
+ return $canonical;
334
+ }
335
+ }
336
+
337
+ if ( ! function_exists( 'fs_canonize_query_string' ) ) {
338
+ /**
339
+ * @author Vova Feldman (@svovaf)
340
+ * @since 1.1.3
341
+ *
342
+ * @param array $params
343
+ * @param array $ignore_params
344
+ * @param bool $params_prefix
345
+ *
346
+ * @return string
347
+ */
348
+ function fs_canonize_query_string( array $params, array &$ignore_params, $params_prefix = false ) {
349
+ if ( ! is_array( $params ) || 0 === count( $params ) ) {
350
+ return '';
351
+ }
352
+
353
+ // Urlencode both keys and values
354
+ $keys = fs_urlencode_rfc3986( array_keys( $params ) );
355
+ $values = fs_urlencode_rfc3986( array_values( $params ) );
356
+ $params = array_combine( $keys, $values );
357
+
358
+ // Parameters are sorted by name, using lexicographical byte value ordering.
359
+ // Ref: Spec: 9.1.1 (1)
360
+ uksort( $params, 'strcmp' );
361
+
362
+ $pairs = array();
363
+ foreach ( $params as $parameter => $value ) {
364
+ $lower_param = strtolower( $parameter );
365
+
366
+ // Skip ignore params.
367
+ if ( in_array( $lower_param, $ignore_params ) || ( false !== $params_prefix && startsWith( $lower_param, $params_prefix ) ) ) {
368
+ continue;
369
+ }
370
+
371
+ if ( is_array( $value ) ) {
372
+ // If two or more parameters share the same name, they are sorted by their value
373
+ // Ref: Spec: 9.1.1 (1)
374
+ natsort( $value );
375
+ foreach ( $value as $duplicate_value ) {
376
+ $pairs[] = $lower_param . '=' . $duplicate_value;
377
+ }
378
+ } else {
379
+ $pairs[] = $lower_param . '=' . $value;
380
+ }
381
+ }
382
+
383
+ if ( 0 === count( $pairs ) ) {
384
+ return '';
385
+ }
386
+
387
+ return implode( "&", $pairs );
388
+ }
389
+ }
390
+
391
+ if ( ! function_exists( 'fs_urlencode_rfc3986' ) ) {
392
+ /**
393
+ * @author Vova Feldman (@svovaf)
394
+ * @since 1.1.3
395
+ *
396
+ * @param string|string[] $input
397
+ *
398
+ * @return array|mixed|string
399
+ */
400
+ function fs_urlencode_rfc3986( $input ) {
401
+ if ( is_array( $input ) ) {
402
+ return array_map( 'fs_urlencode_rfc3986', $input );
403
+ } else if ( is_scalar( $input ) ) {
404
+ return str_replace( '+', ' ', str_replace( '%7E', '~', rawurlencode( $input ) ) );
405
+ }
406
+
407
+ return '';
408
+ }
409
+ }
410
+
411
+ #endregion Url Canonization ------------------------------------------------------------------
412
+
413
+ function fs_download_image( $from, $to ) {
414
+ $ch = curl_init( $from );
415
+ $fp = fopen( fs_normalize_path( $to ), 'wb' );
416
+ curl_setopt( $ch, CURLOPT_FILE, $fp );
417
+ curl_setopt( $ch, CURLOPT_HEADER, 0 );
418
+ curl_exec( $ch );
419
+ curl_close( $ch );
420
+ fclose( $fp );
421
+ }
422
+
423
+ /* General Utilities
424
+ --------------------------------------------------------------------------------------------*/
425
+
426
+ /**
427
+ * Sorts an array by the value of the priority key.
428
+ *
429
+ * @author Daniel Iser (@danieliser)
430
+ * @since 1.1.7
431
+ *
432
+ * @param $a
433
+ * @param $b
434
+ *
435
+ * @return int
436
+ */
437
+ function fs_sort_by_priority( $a, $b ) {
438
+
439
+ // If b has a priority and a does not, b wins.
440
+ if ( ! isset( $a['priority'] ) && isset( $b['priority'] ) ) {
441
+ return 1;
442
+ } // If b has a priority and a does not, b wins.
443
+ elseif ( isset( $a['priority'] ) && ! isset( $b['priority'] ) ) {
444
+ return - 1;
445
+ } // If neither has a priority or both priorities are equal its a tie.
446
+ elseif ( ( ! isset( $a['priority'] ) && ! isset( $b['priority'] ) ) || $a['priority'] === $b['priority'] ) {
447
+ return 0;
448
+ }
449
+
450
+ // If both have priority return the winner.
451
+ return ( $a['priority'] < $b['priority'] ) ? - 1 : 1;
452
+ }
453
+
freemius/includes/fs-essential-functions.php ADDED
@@ -0,0 +1,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.5
7
+ */
8
+
9
+ if ( ! function_exists( 'fs_normalize_path' ) ) {
10
+ if ( function_exists( 'wp_normalize_path' ) ) {
11
+ /**
12
+ * Normalize a filesystem path.
13
+ *
14
+ * Replaces backslashes with forward slashes for Windows systems, and ensures
15
+ * no duplicate slashes exist.
16
+ *
17
+ * @param string $path Path to normalize.
18
+ *
19
+ * @return string Normalized path.
20
+ */
21
+ function fs_normalize_path( $path ) {
22
+ return wp_normalize_path( $path );
23
+ }
24
+ } else {
25
+ function fs_normalize_path( $path ) {
26
+ $path = str_replace( '\\', '/', $path );
27
+ $path = preg_replace( '|/+|', '/', $path );
28
+
29
+ return $path;
30
+ }
31
+ }
32
+ }
33
+
34
+ #region Core Redirect (copied from BuddyPress) -----------------------------------------
35
+
36
+ if ( ! function_exists( 'fs_redirect' ) ) {
37
+ /**
38
+ * Redirects to another page, with a workaround for the IIS Set-Cookie bug.
39
+ *
40
+ * @link http://support.microsoft.com/kb/q176113/
41
+ * @since 1.5.1
42
+ * @uses apply_filters() Calls 'wp_redirect' hook on $location and $status.
43
+ *
44
+ * @param string $location The path to redirect to
45
+ * @param int $status Status code to use
46
+ *
47
+ * @return bool False if $location is not set
48
+ */
49
+ function fs_redirect( $location, $status = 302 ) {
50
+ global $is_IIS;
51
+
52
+ if ( headers_sent() ) {
53
+ return false;
54
+ }
55
+
56
+ if ( ! $location ) // allows the wp_redirect filter to cancel a redirect
57
+ {
58
+ return false;
59
+ }
60
+
61
+ $location = fs_sanitize_redirect( $location );
62
+
63
+ if ( $is_IIS ) {
64
+ header( "Refresh: 0;url=$location" );
65
+ } else {
66
+ if ( php_sapi_name() != 'cgi-fcgi' ) {
67
+ status_header( $status );
68
+ } // This causes problems on IIS and some FastCGI setups
69
+ header( "Location: $location" );
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ if ( ! function_exists( 'fs_sanitize_redirect' ) ) {
76
+ /**
77
+ * Sanitizes a URL for use in a redirect.
78
+ *
79
+ * @since 2.3
80
+ *
81
+ * @param string $location
82
+ *
83
+ * @return string redirect-sanitized URL
84
+ */
85
+ function fs_sanitize_redirect( $location ) {
86
+ $location = preg_replace( '|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location );
87
+ $location = fs_kses_no_null( $location );
88
+
89
+ // remove %0d and %0a from location
90
+ $strip = array( '%0d', '%0a' );
91
+ $found = true;
92
+ while ( $found ) {
93
+ $found = false;
94
+ foreach ( (array) $strip as $val ) {
95
+ while ( strpos( $location, $val ) !== false ) {
96
+ $found = true;
97
+ $location = str_replace( $val, '', $location );
98
+ }
99
+ }
100
+ }
101
+
102
+ return $location;
103
+ }
104
+ }
105
+
106
+ if ( ! function_exists( 'fs_kses_no_null' ) ) {
107
+ /**
108
+ * Removes any NULL characters in $string.
109
+ *
110
+ * @since 1.0.0
111
+ *
112
+ * @param string $string
113
+ *
114
+ * @return string
115
+ */
116
+ function fs_kses_no_null( $string ) {
117
+ $string = preg_replace( '/\0+/', '', $string );
118
+ $string = preg_replace( '/(\\\\0)+/', '', $string );
119
+
120
+ return $string;
121
+ }
122
+ }
123
+ }
124
+
125
+ #endregion Core Redirect (copied from BuddyPress) -----------------------------------------
126
+
127
+ if ( ! function_exists( '__fs' ) ) {
128
+ global $fs_text_overrides;
129
+
130
+ if ( ! isset( $fs_text_overrides ) ) {
131
+ $fs_text_overrides = array();
132
+ }
133
+
134
+ /**
135
+ * Retrieve a translated text by key.
136
+ *
137
+ * @author Vova Feldman (@svovaf)
138
+ * @since 1.1.4
139
+ *
140
+ * @param string $key
141
+ * @param string $slug
142
+ *
143
+ * @return string
144
+ *
145
+ * @global $fs_text , $fs_text_overrides
146
+ */
147
+ function __fs( $key, $slug = 'freemius' ) {
148
+ global $fs_text, $fs_text_overrides;
149
+
150
+ if ( ! isset( $fs_text ) ) {
151
+ require_once( ( defined( 'WP_FS__DIR_INCLUDES' ) ? WP_FS__DIR_INCLUDES : dirname( __FILE__ ) ) . '/i18n.php' );
152
+ }
153
+
154
+ if ( isset( $fs_text_overrides[ $slug ] ) ) {
155
+ if ( isset( $fs_text_overrides[ $slug ][ $key ] ) ) {
156
+ return $fs_text_overrides[ $slug ][ $key ];
157
+ }
158
+
159
+ $lower_key = strtolower( $key );
160
+ if ( isset( $fs_text_overrides[ $slug ][ $lower_key ] ) ) {
161
+ return $fs_text_overrides[ $slug ][ $lower_key ];
162
+ }
163
+ }
164
+
165
+ return isset( $fs_text[ $key ] ) ?
166
+ $fs_text[ $key ] :
167
+ $key;
168
+ }
169
+
170
+ /**
171
+ * Display a translated text by key.
172
+ *
173
+ * @author Vova Feldman (@svovaf)
174
+ * @since 1.1.4
175
+ *
176
+ * @param string $key
177
+ * @param string $slug
178
+ */
179
+ function _efs( $key, $slug = 'freemius' ) {
180
+ echo __fs( $key, $slug );
181
+ }
182
+
183
+ /**
184
+ * Override default i18n text phrases.
185
+ *
186
+ * @author Vova Feldman (@svovaf)
187
+ * @since 1.1.6
188
+ *
189
+ * @param string[] $key_value
190
+ * @param string $slug
191
+ *
192
+ * @global $fs_text_overrides
193
+ */
194
+ function fs_override_i18n( array $key_value, $slug = 'freemius' ) {
195
+ global $fs_text_overrides;
196
+
197
+ if ( ! isset( $fs_text_overrides[ $slug ] ) ) {
198
+ $fs_text_overrides[ $slug ] = array();
199
+ }
200
+
201
+ foreach ( $key_value as $key => $value ) {
202
+ $fs_text_overrides[ $slug ][ $key ] = $value;
203
+ }
204
+ }
205
+ }
206
+
207
+ if ( ! function_exists( 'fs_get_ip' ) ) {
208
+ /**
209
+ * Get client IP.
210
+ *
211
+ * @author Vova Feldman (@svovaf)
212
+ * @since 1.1.2
213
+ *
214
+ * @return string|null
215
+ */
216
+ function fs_get_ip() {
217
+ $fields = array(
218
+ 'HTTP_CF_CONNECTING_IP',
219
+ 'HTTP_CLIENT_IP',
220
+ 'HTTP_X_FORWARDED_FOR',
221
+ 'HTTP_X_FORWARDED',
222
+ 'HTTP_FORWARDED_FOR',
223
+ 'HTTP_FORWARDED',
224
+ 'REMOTE_ADDR',
225
+ );
226
+
227
+ foreach ( $fields as $ip_field ) {
228
+ if ( ! empty( $_SERVER[ $ip_field ] ) ) {
229
+ return $_SERVER[ $ip_field ];
230
+ }
231
+ }
232
+
233
+ return null;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Leverage backtrace to find caller plugin main file path.
239
+ *
240
+ * @author Vova Feldman (@svovaf)
241
+ * @since 1.0.6
242
+ *
243
+ * @return string
244
+ */
245
+ function fs_find_caller_plugin_file() {
246
+ /**
247
+ * All the code below will be executed once on activation.
248
+ * If the user changes the main plugin's file name, the file_exists()
249
+ * will catch it.
250
+ */
251
+ if ( ! function_exists( 'get_plugins' ) ) {
252
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
253
+ }
254
+
255
+ $all_plugins = get_plugins();
256
+ $all_plugins_paths = array();
257
+
258
+ // Get active plugin's main files real full names (might be symlinks).
259
+ foreach ( $all_plugins as $relative_path => &$data ) {
260
+ $all_plugins_paths[] = fs_normalize_path( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) );
261
+ }
262
+
263
+ $plugin_file = null;
264
+ for ( $i = 1, $bt = debug_backtrace(), $len = count( $bt ); $i < $len; $i ++ ) {
265
+ if ( in_array( fs_normalize_path( $bt[ $i ]['file'] ), $all_plugins_paths ) ) {
266
+ $plugin_file = $bt[ $i ]['file'];
267
+ break;
268
+ }
269
+ }
270
+
271
+ if ( is_null( $plugin_file ) ) {
272
+ // Throw an error to the developer in case of some edge case dev environment.
273
+ wp_die( __fs( 'failed-finding-main-path' ), __fs( 'error' ), array( 'back_link' => true ) );
274
+ }
275
+
276
+ return $plugin_file;
277
+ }
278
+
279
+ require_once dirname( __FILE__ ) . '/supplements/fs-essential-functions-1.1.7.1.php';
280
+
281
+ /**
282
+ * Update SDK newest version reference.
283
+ *
284
+ * @author Vova Feldman (@svovaf)
285
+ * @since 1.1.6
286
+ *
287
+ * @param string $sdk_relative_path
288
+ * @param string|bool $plugin_file
289
+ *
290
+ * @global $fs_active_plugins
291
+ */
292
+ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false ) {
293
+ global $fs_active_plugins;
294
+
295
+ if ( ! is_string( $plugin_file ) ) {
296
+ $plugin_file = plugin_basename( fs_find_caller_plugin_file() );
297
+ }
298
+
299
+ $fs_active_plugins->newest = (object) array(
300
+ 'plugin_path' => $plugin_file,
301
+ 'sdk_path' => $sdk_relative_path,
302
+ 'version' => $fs_active_plugins->plugins[ $sdk_relative_path ]->version,
303
+ 'in_activation' => ! is_plugin_active( $plugin_file ),
304
+ 'timestamp' => time(),
305
+ );
306
+
307
+ // Update DB with latest SDK version and path.
308
+ update_option( 'fs_active_plugins', $fs_active_plugins );
309
+ }
310
+
311
+ /**
312
+ * Reorder the plugins load order so the plugin with the newest Freemius SDK is loaded first.
313
+ *
314
+ * @author Vova Feldman (@svovaf)
315
+ * @since 1.1.6
316
+ *
317
+ * @return bool Was plugin order changed. Return false if plugin was loaded first anyways.
318
+ *
319
+ * @global $fs_active_plugins
320
+ */
321
+ function fs_newest_sdk_plugin_first() {
322
+ global $fs_active_plugins;
323
+
324
+ /**
325
+ * @todo Multi-site network activated plugin are always loaded prior to site plugins so if there's a a plugin activated in the network mode that has an older version of the SDK of another plugin which is site activated that has new SDK version, the fs-essential-functions.php will be loaded from the older SDK. Same thing about MU plugins (loaded even before network activated plugins).
326
+ *
327
+ * @link https://github.com/Freemius/wordpress-sdk/issues/26
328
+ */
329
+ // $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
330
+
331
+ $active_plugins = get_option( 'active_plugins' );
332
+ $newest_sdk_plugin_key = array_search( $fs_active_plugins->newest->plugin_path, $active_plugins );
333
+ if ( 0 == $newest_sdk_plugin_key ) {
334
+ // if it's 0 it's the first plugin already, no need to continue
335
+ return false;
336
+ }
337
+
338
+ array_splice( $active_plugins, $newest_sdk_plugin_key, 1 );
339
+ array_unshift( $active_plugins, $fs_active_plugins->newest->plugin_path );
340
+ update_option( 'active_plugins', $active_plugins );
341
+
342
+ return true;
343
+ }
344
+
345
+ /**
346
+ * Go over all Freemius SDKs in the system and find and "remember"
347
+ * the newest SDK which is associated with an active plugin.
348
+ *
349
+ * @author Vova Feldman (@svovaf)
350
+ * @since 1.1.6
351
+ *
352
+ * @global $fs_active_plugins
353
+ */
354
+ function fs_fallback_to_newest_active_sdk() {
355
+ global $fs_active_plugins;
356
+
357
+ $newest_sdk_data = null;
358
+ $newest_sdk_path = null;
359
+
360
+ foreach ( $fs_active_plugins->plugins as $sdk_relative_path => $data ) {
361
+ if ( is_null( $newest_sdk_data ) || version_compare( $data->version, $newest_sdk_data->version, '>' )
362
+ ) {
363
+ // If plugin inactive or SDK starter file doesn't exist, remove SDK reference.
364
+ if ( ! is_plugin_active( $data->plugin_path ) ||
365
+ ! file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $sdk_relative_path . '/start.php' ) )
366
+ ) {
367
+ unset( $fs_active_plugins->plugins[ $sdk_relative_path ] );
368
+
369
+ // No need to store the data since it will be stored in fs_update_sdk_newest_version()
370
+ // or explicitly with update_option().
371
+ } else {
372
+ $newest_sdk_data = $data;
373
+ $newest_sdk_path = $sdk_relative_path;
374
+ }
375
+ }
376
+ }
377
+
378
+ if ( is_null( $newest_sdk_data ) ) {
379
+ // Couldn't find any SDK reference.
380
+ $fs_active_plugins = new stdClass();
381
+ update_option( 'fs_active_plugins', $fs_active_plugins );
382
+ } else {
383
+ fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
384
+ }
385
+ }
386
+
387
+ #region Actions / Filters -----------------------------------------
388
+
389
+ /**
390
+ * Apply filter for specific plugin.
391
+ *
392
+ * @author Vova Feldman (@svovaf)
393
+ * @since 1.0.9
394
+ *
395
+ * @param string $slug Plugin slug
396
+ * @param string $tag The name of the filter hook.
397
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
398
+ *
399
+ * @return mixed The filtered value after all hooked functions are applied to it.
400
+ *
401
+ * @uses apply_filters()
402
+ */
403
+ function fs_apply_filter( $slug, $tag, $value ) {
404
+ $args = func_get_args();
405
+
406
+ return call_user_func_array( 'apply_filters', array_merge(
407
+ array( 'fs_' . $tag . '_' . $slug ),
408
+ array_slice( $args, 2 ) )
409
+ );
410
+ }
411
+
412
+ #endregion Actions / Filters -----------------------------------------
freemius/includes/fs-plugin-info-dialog.php ADDED
@@ -0,0 +1,936 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Class FS_Plugin_Info_Dialog
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7
18
+ */
19
+ class FS_Plugin_Info_Dialog {
20
+ /**
21
+ * @since 1.1.7
22
+ *
23
+ * @var FS_Logger
24
+ */
25
+ private $_logger;
26
+
27
+ /**
28
+ * @since 1.1.7
29
+ *
30
+ * @var Freemius
31
+ */
32
+ private $_fs;
33
+
34
+ function __construct( Freemius $fs ) {
35
+ $this->_fs = $fs;
36
+
37
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $fs->get_slug() . '_info', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
38
+
39
+ // Remove default plugin information action.
40
+ remove_all_actions( 'install_plugins_pre_plugin-information' );
41
+
42
+ // Override action with custom plugins function for add-ons.
43
+ add_action( 'install_plugins_pre_plugin-information', array( &$this, 'install_plugin_information' ) );
44
+
45
+ // Override request for plugin information for Add-ons.
46
+ add_filter(
47
+ 'fs_plugins_api',
48
+ array( &$this, '_get_addon_info_filter' ),
49
+ WP_FS__DEFAULT_PRIORITY, 3 );
50
+ }
51
+
52
+ /**
53
+ * Generate add-on plugin information.
54
+ *
55
+ * @author Vova Feldman (@svovaf)
56
+ * @since 1.0.6
57
+ *
58
+ * @param array $data
59
+ * @param string $action
60
+ * @param object|null $args
61
+ *
62
+ * @return array|null
63
+ */
64
+ function _get_addon_info_filter( $data, $action = '', $args = null ) {
65
+ $this->_logger->entrance();
66
+
67
+ $parent_plugin_id = fs_request_get( 'parent_plugin_id', false );
68
+
69
+ if ( $this->_fs->get_id() != $parent_plugin_id ||
70
+ ( 'plugin_information' !== $action ) ||
71
+ ! isset( $args->slug )
72
+ ) {
73
+ return $data;
74
+ }
75
+
76
+ // Find add-on by slug.
77
+ $addons = $this->_fs->get_addons();
78
+ $selected_addon = false;
79
+ foreach ( $addons as $addon ) {
80
+ if ( $addon->slug == $args->slug ) {
81
+ $selected_addon = $addon;
82
+ break;
83
+ }
84
+ }
85
+
86
+ if ( false === $selected_addon ) {
87
+ return $data;
88
+ }
89
+
90
+ if ( ! isset( $selected_addon->info ) ) {
91
+ // Setup some default info.
92
+ $selected_addon->info = new stdClass();
93
+ $selected_addon->info->selling_point_0 = 'Selling Point 1';
94
+ $selected_addon->info->selling_point_1 = 'Selling Point 2';
95
+ $selected_addon->info->selling_point_2 = 'Selling Point 3';
96
+ $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
97
+ }
98
+
99
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
100
+
101
+ $data = $args;
102
+
103
+ $is_free = true;
104
+
105
+ // Load add-on pricing.
106
+ $has_pricing = false;
107
+ $has_features = false;
108
+ $plans = false;
109
+ $plans_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans.json" );
110
+ if ( ! isset( $plans_result->error ) ) {
111
+ $plans = $plans_result->plans;
112
+ if ( is_array( $plans ) ) {
113
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
114
+ $plans[ $i ] = new FS_Plugin_Plan( $plans[ $i ] );
115
+ $plan = $plans[ $i ];
116
+
117
+ $pricing_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/pricing.json" );
118
+ if ( ! isset( $pricing_result->error ) ) {
119
+ // Update plan's pricing.
120
+ $plan->pricing = $pricing_result->pricing;
121
+
122
+ if ( is_array( $plan->pricing ) && ! empty( $plan->pricing ) ) {
123
+ $is_free = false;
124
+
125
+ foreach ( $plan->pricing as &$pricing ) {
126
+ $pricing = new FS_Pricing( $pricing );
127
+ }
128
+ }
129
+
130
+ $has_pricing = true;
131
+ }
132
+
133
+ $features_result = $this->_fs->get_api_site_or_plugin_scope()->get( "/addons/{$selected_addon->id}/plans/{$plan->id}/features.json" );
134
+ if ( ! isset( $features_result->error ) &&
135
+ is_array( $features_result->features ) &&
136
+ 0 < count( $features_result->features )
137
+ ) {
138
+ // Update plan's pricing.
139
+ $plan->features = $features_result->features;
140
+
141
+ $has_features = true;
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ // Fetch latest version from Freemius.
148
+ $latest = $this->_fs->_fetch_latest_version( $selected_addon->id );
149
+
150
+ if ( ! $is_free ) {
151
+ // If paid add-on, then it's not on wordpress.org
152
+ $is_wordpress_org = false;
153
+ } else {
154
+ // If no versions found, then assume it's a .org plugin.
155
+ $is_wordpress_org = ( false === $latest );
156
+ }
157
+
158
+ if ( $is_wordpress_org ) {
159
+ $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository(
160
+ 'plugin_information', (object) array(
161
+ 'slug' => $selected_addon->slug,
162
+ 'is_ssl' => is_ssl(),
163
+ 'fields' => array(
164
+ 'banners' => true,
165
+ 'reviews' => true,
166
+ 'downloaded' => false,
167
+ 'active_installs' => true
168
+ )
169
+ ) );
170
+
171
+ if ( ! empty( $repo_data ) ) {
172
+ $data = $repo_data;
173
+ $data->wp_org_missing = false;
174
+ } else {
175
+ // Couldn't find plugin on .org.
176
+ $is_wordpress_org = false;
177
+
178
+ // Plugin is missing, not on Freemius nor WP.org.
179
+ $data->wp_org_missing = true;
180
+ }
181
+ }
182
+
183
+ if ( ! $is_wordpress_org ) {
184
+ $data->checkout_link = $this->_fs->checkout_url();
185
+ $data->fs_missing = ( false === $latest );
186
+
187
+ if ( $is_free ) {
188
+ $data->download_link = $this->_fs->_get_latest_download_local_url( $selected_addon->id );
189
+ }
190
+ }
191
+
192
+ if ( ! $is_wordpress_org ) {
193
+ // Fetch as much as possible info from local files.
194
+ $plugin_local_data = $this->_fs->get_plugin_data();
195
+ $data->name = $selected_addon->title;
196
+ $data->author = $plugin_local_data['Author'];
197
+ $view_vars = array( 'plugin' => $selected_addon );
198
+ $data->sections = array(
199
+ 'description' => fs_get_template( '/plugin-info/description.php', $view_vars ),
200
+ );
201
+
202
+ if ( ! empty( $selected_addon->info->banner_url ) ) {
203
+ $data->banners = array(
204
+ 'low' => $selected_addon->info->banner_url,
205
+ );
206
+ }
207
+
208
+ if ( ! empty( $selected_addon->info->screenshots ) ) {
209
+ $view_vars = array(
210
+ 'screenshots' => $selected_addon->info->screenshots,
211
+ 'plugin' => $selected_addon,
212
+ );
213
+ $data->sections['screenshots'] = fs_get_template( '/plugin-info/screenshots.php', $view_vars );
214
+ }
215
+
216
+ if ( is_object( $latest ) ) {
217
+ $data->version = $latest->version;
218
+ $data->last_updated = ! is_null( $latest->updated ) ? $latest->updated : $latest->created;
219
+ $data->requires = $latest->requires_platform_version;
220
+ $data->tested = $latest->tested_up_to_version;
221
+ } else {
222
+ // Add dummy version.
223
+ $data->version = '1.0.0';
224
+
225
+ // Add message to developer to deploy the plugin through Freemius.
226
+ }
227
+ }
228
+
229
+ if ( $has_pricing ) {
230
+ // Add plans to data.
231
+ $data->plans = $plans;
232
+
233
+ if ( $has_features ) {
234
+ $view_vars = array(
235
+ 'plans' => $plans,
236
+ 'plugin' => $selected_addon,
237
+ );
238
+ $data->sections['features'] = fs_get_template( '/plugin-info/features.php', $view_vars );
239
+ }
240
+ }
241
+
242
+ $data->is_paid = ! $is_free;
243
+ $data->external = ! $is_wordpress_org;
244
+
245
+ return $data;
246
+ }
247
+
248
+ /**
249
+ * @author Vova Feldman (@svovaf)
250
+ * @since 1.1.7
251
+ *
252
+ * @param FS_Plugin_Plan $plan
253
+ *
254
+ * @return string
255
+ */
256
+ private function get_billing_cycle( FS_Plugin_Plan $plan ) {
257
+ $billing_cycle = null;
258
+
259
+ if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) {
260
+ $pricing = $plan->pricing[0];
261
+ if ( isset( $pricing->annual_price ) ) {
262
+ $billing_cycle = 'annual';
263
+ } else if ( isset( $pricing->monthly_price ) ) {
264
+ $billing_cycle = 'monthly';
265
+ } else if ( isset( $pricing->lifetime_price ) ) {
266
+ $billing_cycle = 'lifetime';
267
+ }
268
+ } else {
269
+ foreach ( $plan->pricing as $pricing ) {
270
+ if ( isset( $pricing->annual_price ) ) {
271
+ $billing_cycle = 'annual';
272
+ } else if ( isset( $pricing->monthly_price ) ) {
273
+ $billing_cycle = 'monthly';
274
+ } else if ( isset( $pricing->lifetime_price ) ) {
275
+ $billing_cycle = 'lifetime';
276
+ }
277
+
278
+ if ( ! is_null( $billing_cycle ) ) {
279
+ break;
280
+ }
281
+ }
282
+ }
283
+
284
+ return $billing_cycle;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.7
290
+ *
291
+ * @param FS_Plugin_Plan $plan
292
+ * @param FS_Pricing $pricing
293
+ *
294
+ * @return float|null|string
295
+ */
296
+ private function get_price_tag( FS_Plugin_Plan $plan, FS_Pricing $pricing ) {
297
+ $price_tag = '';
298
+ if ( isset( $pricing->annual_price ) ) {
299
+ $price_tag = $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' );
300
+ } else if ( isset( $pricing->monthly_price ) ) {
301
+ $price_tag = $pricing->monthly_price . ' / mo';
302
+ } else if ( isset( $pricing->lifetime_price ) ) {
303
+ $price_tag = $pricing->lifetime_price;
304
+ }
305
+
306
+ return '$' . $price_tag;
307
+ }
308
+
309
+ /**
310
+ * @author Vova Feldman (@svovaf)
311
+ * @since 1.1.7
312
+ *
313
+ * @param object $api
314
+ * @param FS_Plugin_Plan|null $plan
315
+ *
316
+ * @return string
317
+ */
318
+ private function get_plugin_cta( $api, $plan = null ) {
319
+ if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) {
320
+
321
+ if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) {
322
+ if ( is_null( $plan ) ) {
323
+ $plan = $api->plans[0];
324
+ }
325
+
326
+ return ' <a class="button button-primary right" href="' . $this->_fs->addon_checkout_url(
327
+ $plan->plugin_id,
328
+ $plan->pricing[0]->id,
329
+ $this->get_billing_cycle( $plan ),
330
+ $plan->has_trial()
331
+ ) . '" target="_parent">' .
332
+ ( ! $plan->has_trial() ?
333
+ __fs( 'purchase', $api->slug ) :
334
+ sprintf( __fs( 'start-free-x', $api->slug ), $this->get_trial_period( $plan ) )
335
+ ) .
336
+ '</a>';
337
+
338
+ // @todo Add Cart concept.
339
+ // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>';
340
+
341
+ } else if ( ! empty( $api->download_link ) ) {
342
+ $status = install_plugin_install_status( $api );
343
+
344
+
345
+ // Hosted on WordPress.org.
346
+ switch ( $status['status'] ) {
347
+ case 'install':
348
+ if ( $api->external &&
349
+ $this->_fs->is_org_repo_compliant() ||
350
+ ! $this->_fs->is_premium()
351
+ ) {
352
+ /**
353
+ * Add-on hosted on Freemius, not yet installed, and core
354
+ * plugin is wordpress.org compliant. Therefore, require a download
355
+ * since installing external plugins is not allowed by the wp.org guidelines.
356
+ */
357
+ return ' <a class="button button-primary right" href="' . esc_url( $api->download_link ) . '" target="_blank">' . __fs( 'download-latest', $api->slug ) . '</a>';
358
+ } else {
359
+ if ( $status['url'] ) {
360
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>';
361
+ }
362
+ }
363
+ break;
364
+ case 'update_available':
365
+ if ( $status['url'] ) {
366
+ return '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>';
367
+ }
368
+ break;
369
+ case 'newer_installed':
370
+ return '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>';
371
+ break;
372
+ case 'latest_installed':
373
+ return '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>';
374
+ break;
375
+ }
376
+
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * @author Vova Feldman (@svovaf)
383
+ * @since 1.1.7
384
+ *
385
+ * @param FS_Plugin_Plan $plan
386
+ *
387
+ * @return string
388
+ */
389
+ private function get_trial_period( $plan ) {
390
+ $trial_period = (int) $plan->trial_period;
391
+
392
+ switch ( $trial_period ) {
393
+ case 30:
394
+ return 'month';
395
+ case 60:
396
+ return '2 months';
397
+ default:
398
+ return "{$plan->trial_period} days";
399
+ }
400
+ }
401
+
402
+ /**
403
+ * Display plugin information in dialog box form.
404
+ *
405
+ * Based on core install_plugin_information() function.
406
+ *
407
+ * @author Vova Feldman (@svovaf)
408
+ * @since 1.0.6
409
+ */
410
+ function install_plugin_information() {
411
+ global $tab;
412
+
413
+ if ( empty( $_REQUEST['plugin'] ) ) {
414
+ return;
415
+ }
416
+
417
+ $args = array(
418
+ 'slug' => wp_unslash( $_REQUEST['plugin'] ),
419
+ 'is_ssl' => is_ssl(),
420
+ 'fields' => array(
421
+ 'banners' => true,
422
+ 'reviews' => true,
423
+ 'downloaded' => false,
424
+ 'active_installs' => true
425
+ )
426
+ );
427
+
428
+ if ( is_array( $args ) ) {
429
+ $args = (object) $args;
430
+ }
431
+
432
+ if ( ! isset( $args->per_page ) ) {
433
+ $args->per_page = 24;
434
+ }
435
+
436
+ if ( ! isset( $args->locale ) ) {
437
+ $args->locale = get_locale();
438
+ }
439
+
440
+ $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args );
441
+
442
+ if ( is_wp_error( $api ) ) {
443
+ wp_die( $api );
444
+ }
445
+
446
+ $plugins_allowedtags = array(
447
+ 'a' => array(
448
+ 'href' => array(),
449
+ 'title' => array(),
450
+ 'target' => array(),
451
+ // Add image style for screenshots.
452
+ 'class' => array()
453
+ ),
454
+ 'style' => array(),
455
+ 'abbr' => array( 'title' => array() ),
456
+ 'acronym' => array( 'title' => array() ),
457
+ 'code' => array(),
458
+ 'pre' => array(),
459
+ 'em' => array(),
460
+ 'strong' => array(),
461
+ 'div' => array( 'class' => array() ),
462
+ 'span' => array( 'class' => array() ),
463
+ 'p' => array(),
464
+ 'ul' => array(),
465
+ 'ol' => array(),
466
+ 'li' => array( 'class' => array() ),
467
+ 'i' => array( 'class' => array() ),
468
+ 'h1' => array(),
469
+ 'h2' => array(),
470
+ 'h3' => array(),
471
+ 'h4' => array(),
472
+ 'h5' => array(),
473
+ 'h6' => array(),
474
+ 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
475
+ // 'table' => array(),
476
+ // 'td' => array(),
477
+ // 'tr' => array(),
478
+ // 'th' => array(),
479
+ // 'thead' => array(),
480
+ // 'tbody' => array(),
481
+ );
482
+
483
+ $plugins_section_titles = array(
484
+ 'description' => _x( 'Description', 'Plugin installer section title' ),
485
+ 'installation' => _x( 'Installation', 'Plugin installer section title' ),
486
+ 'faq' => _x( 'FAQ', 'Plugin installer section title' ),
487
+ 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ),
488
+ 'changelog' => _x( 'Changelog', 'Plugin installer section title' ),
489
+ 'reviews' => _x( 'Reviews', 'Plugin installer section title' ),
490
+ 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ),
491
+ );
492
+
493
+ // Sanitize HTML
494
+ // foreach ( (array) $api->sections as $section_name => $content ) {
495
+ // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags );
496
+ // }
497
+
498
+ foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) {
499
+ if ( isset( $api->$key ) ) {
500
+ $api->$key = wp_kses( $api->$key, $plugins_allowedtags );
501
+ }
502
+ }
503
+
504
+ // Add after $api->slug is ready.
505
+ $plugins_section_titles['features'] = __fs( 'features-and-pricing', $api->slug );
506
+
507
+ $_tab = esc_attr( $tab );
508
+
509
+ $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
510
+ if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
511
+ $section_titles = array_keys( (array) $api->sections );
512
+ $section = array_shift( $section_titles );
513
+ }
514
+
515
+ iframe_header( __( 'Plugin Install' ) );
516
+
517
+ $_with_banner = '';
518
+
519
+ // var_dump($api->banners);
520
+ if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) {
521
+ $_with_banner = 'with-banner';
522
+ $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low'];
523
+ $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high'];
524
+ ?>
525
+ <style type="text/css">
526
+ #plugin-information-title.with-banner
527
+ {
528
+ background-image: url( <?php echo esc_url( $low ); ?> );
529
+ }
530
+
531
+ @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 )
532
+ {
533
+ #plugin-information-title.with-banner
534
+ {
535
+ background-image: url( <?php echo esc_url( $high ); ?> );
536
+ }
537
+ }
538
+ </style>
539
+ <?php
540
+ }
541
+
542
+ echo '<div id="plugin-information-scrollable">';
543
+ echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>";
544
+ echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n";
545
+
546
+ foreach ( (array) $api->sections as $section_name => $content ) {
547
+ if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) {
548
+ continue;
549
+ }
550
+
551
+ if ( isset( $plugins_section_titles[ $section_name ] ) ) {
552
+ $title = $plugins_section_titles[ $section_name ];
553
+ } else {
554
+ $title = ucwords( str_replace( '_', ' ', $section_name ) );
555
+ }
556
+
557
+ $class = ( $section_name === $section ) ? ' class="current"' : '';
558
+ $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) );
559
+ $href = esc_url( $href );
560
+ $san_section = esc_attr( $section_name );
561
+ echo "\t<a name='$san_section' href='$href' $class>$title</a>\n";
562
+ }
563
+
564
+ echo "</div>\n";
565
+
566
+ ?>
567
+ <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'>
568
+ <div class="fyi">
569
+ <?php if ( $api->is_paid ) : ?>
570
+ <?php if ( isset( $api->plans ) ) : ?>
571
+ <div class="plugin-information-pricing">
572
+ <?php foreach ( $api->plans as $plan ) : ?>
573
+ <?php
574
+ /**
575
+ * @var FS_Plugin_Plan $plan
576
+ */
577
+ ?>
578
+ <?php $first_pricing = $plan->pricing[0] ?>
579
+ <?php $is_multi_cycle = $first_pricing->is_multi_cycle() ?>
580
+ <div class="fs-plan<?php if ( ! $is_multi_cycle ) {
581
+ echo ' fs-single-cycle';
582
+ } ?>" data-plan-id="<?php echo $plan->id ?>">
583
+ <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan', $api->slug ), $plan->title ) ?></h3>
584
+ <?php $has_annual = $first_pricing->has_annual() ?>
585
+ <?php $has_monthly = $first_pricing->has_monthly() ?>
586
+ <div class="nav-tab-wrapper">
587
+ <?php $billing_cycles = array( 'monthly', 'annual', 'lifetime' ) ?>
588
+ <?php $i = 0;
589
+ foreach ( $billing_cycles as $cycle ) : ?>
590
+ <?php $prop = "{$cycle}_price";
591
+ if ( isset( $first_pricing->{$prop} ) ) : ?>
592
+ <?php $is_featured = ( 'annual' === $cycle && $is_multi_cycle ) ?>
593
+ <?php
594
+ $prices = array();
595
+ foreach ( $plan->pricing as $pricing ) {
596
+ if ( isset( $pricing->{$prop} ) ) {
597
+ $prices[] = array(
598
+ 'id' => $pricing->id,
599
+ 'licenses' => $pricing->licenses,
600
+ 'price' => $pricing->{$prop}
601
+ );
602
+ }
603
+ }
604
+ ?>
605
+ <a class="nav-tab" data-billing-cycle="<?php echo $cycle ?>"
606
+ data-pricing="<?php esc_attr_e( json_encode( $prices ) ) ?>">
607
+ <?php if ( $is_featured ) : ?>
608
+ <label>&#9733; <?php _efs( 'best', $api->slug ) ?> &#9733;</label>
609
+ <?php endif ?>
610
+ <?php _efs( $cycle, $api->slug ) ?>
611
+ </a>
612
+ <?php endif ?>
613
+ <?php $i ++; endforeach ?>
614
+ <?php wp_enqueue_script( 'jquery' ) ?>
615
+ <script type="text/javascript">
616
+ (function ($, undef) {
617
+ var
618
+ _formatBillingFrequency = function (cycle) {
619
+ switch (cycle) {
620
+ case 'monthly':
621
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('monthly', $api->slug)) ?>';
622
+ case 'annual':
623
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('annually', $api->slug)) ?>';
624
+ case 'lifetime':
625
+ return '<?php printf(__fs('billed-x', $api->slug), __fs('once', $api->slug)) ?>';
626
+ }
627
+ },
628
+ _formatLicensesTitle = function (pricing) {
629
+ switch (pricing.licenses) {
630
+ case 1:
631
+ return '<?php _efs( 'license-single-site', $api->slug ) ?>';
632
+ case null:
633
+ return '<?php _efs( 'license-unlimited', $api->slug ) ?>';
634
+ default:
635
+ return '<?php _efs( 'license-x-sites', $api->slug ) ?>'.replace('%s', pricing.licenses);
636
+ }
637
+ },
638
+ _formatPrice = function (pricing, cycle, multipleLicenses) {
639
+ if (undef === multipleLicenses)
640
+ multipleLicenses = true;
641
+
642
+ var priceCycle;
643
+ switch (cycle) {
644
+ case 'monthly':
645
+ priceCycle = ' / <?php _efs('mo', $api->slug) ?>';
646
+ break;
647
+ case 'lifetime':
648
+ priceCycle = '';
649
+ break;
650
+ case 'annual':
651
+ default:
652
+ priceCycle = ' / <?php _efs('year', $api->slug) ?>';
653
+ break;
654
+ }
655
+
656
+ if (!multipleLicenses && 1 == pricing.licenses) {
657
+ return '$' + pricing.price + priceCycle;
658
+ }
659
+
660
+ return _formatLicensesTitle(pricing) + ' - <var class="fs-price">$' + pricing.price + priceCycle + '</var>';
661
+ },
662
+ _checkoutUrl = function (plan, pricing, cycle) {
663
+ return '<?php echo esc_url_raw(remove_query_arg('billing_cycle', add_query_arg(array('plugin_id' => $plan->plugin_id), $api->checkout_link))) ?>' +
664
+ '&plan_id=' + plan +
665
+ '&pricing_id=' + pricing +
666
+ '&billing_cycle=' + cycle<?php if ($plan->has_trial()) { echo " + '&trial=true'"; }?>;
667
+ },
668
+ _updateCtaUrl = function (plan, pricing, cycle) {
669
+ $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', _checkoutUrl(plan, pricing, cycle));
670
+ };
671
+
672
+ $(document).ready(function () {
673
+ var $plan = $('.plugin-information-pricing .fs-plan[data-plan-id=<?php echo $plan->id ?>]');
674
+ $plan.find('input[type=radio]').live('click', function () {
675
+ _updateCtaUrl(
676
+ $plan.attr('data-plan-id'),
677
+ $(this).val(),
678
+ $plan.find('.nav-tab-active').attr('data-billing-cycle')
679
+ );
680
+
681
+ $plan.find('.fs-trial-terms .fs-price').html(
682
+ $(this).parents('label').find('.fs-price').html()
683
+ );
684
+ });
685
+
686
+ $plan.find('.nav-tab').click(function () {
687
+ if ($(this).hasClass('nav-tab-active'))
688
+ return;
689
+
690
+ var $this = $(this),
691
+ billingCycle = $this.attr('data-billing-cycle'),
692
+ pricing = JSON.parse($this.attr('data-pricing')),
693
+ $pricesList = $this.parents('.fs-plan').find('.fs-pricing-body .fs-licenses'),
694
+ html = '';
695
+
696
+ // Un-select previously selected tab.
697
+ $plan.find('.nav-tab').removeClass('nav-tab-active');
698
+
699
+ // Select current tab.
700
+ $this.addClass('nav-tab-active');
701
+
702
+ // Render licenses prices.
703
+ if (1 == pricing.length) {
704
+ html = '<li><label><?php _efs( 'price', $api->slug ) ?>: ' + _formatPrice(pricing[0], billingCycle, false) + '</label></li>';
705
+ } else {
706
+ for (var i = 0; i < pricing.length; i++) {
707
+ html += '<li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" value="' + pricing[i].id + '">' + _formatPrice(pricing[i], billingCycle) + '</label></li>';
708
+ }
709
+ }
710
+ $pricesList.html(html);
711
+
712
+ if (1 < pricing.length) {
713
+ // Select first license option.
714
+ $pricesList.find('li:first input').click();
715
+ }
716
+ else {
717
+ _updateCtaUrl(
718
+ $plan.attr('data-plan-id'),
719
+ pricing[0].id,
720
+ billingCycle
721
+ );
722
+ }
723
+
724
+ // Update billing frequency.
725
+ $plan.find('.fs-billing-frequency').html(_formatBillingFrequency(billingCycle));
726
+
727
+ if ('annual' === billingCycle) {
728
+ $plan.find('.fs-annual-discount').show();
729
+ } else {
730
+ $plan.find('.fs-annual-discount').hide();
731
+ }
732
+ });
733
+
734
+ <?php if ( $has_annual ) : ?>
735
+ // Select annual by default.
736
+ $plan.find('.nav-tab[data-billing-cycle=annual]').click();
737
+ <?php else : ?>
738
+ // Select first tab.
739
+ $plan.find('.nav-tab:first').click();
740
+ <?php endif ?>
741
+ });
742
+ }(jQuery));
743
+ </script>
744
+ </div>
745
+ <div class="fs-pricing-body">
746
+ <span class="fs-billing-frequency"></span>
747
+ <?php $annual_discount = ( $has_annual && $has_monthly ) ? $plan->pricing[0]->annual_discount_percentage() : 0 ?>
748
+ <?php if ( $annual_discount > 0 ) : ?>
749
+ <span
750
+ class="fs-annual-discount"><?php printf( __fs( 'save-x', $api->slug ), $annual_discount . '%' ) ?></span>
751
+ <?php endif ?>
752
+ <ul class="fs-licenses">
753
+ </ul>
754
+ <?php echo $this->get_plugin_cta( $api, $plan ) ?>
755
+ <div style="clear:both"></div>
756
+ <?php if ( $plan->has_trial() ) : ?>
757
+ <?php $trial_period = $this->get_trial_period( $plan ) ?>
758
+ <ul class="fs-trial-terms">
759
+ <li>
760
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'no-commitment-x', $api->slug ), $trial_period ) ?>
761
+ </li>
762
+ <li>
763
+ <i class="dashicons dashicons-yes"></i><?php printf( __fs( 'after-x-pay-as-little-y', $api->slug ), $trial_period, '<var class="fs-price">' . $this->get_price_tag( $plan, $plan->pricing[0] ) . '</var>' ) ?>
764
+ </li>
765
+ </ul>
766
+ <?php endif ?>
767
+ </div>
768
+ </div>
769
+ </div>
770
+ <?php endforeach ?>
771
+ <?php endif ?>
772
+ <?php endif ?>
773
+ <div>
774
+ <h3><?php _efs( 'details', $api->slug ) ?></h3>
775
+ <ul>
776
+ <?php if ( ! empty( $api->version ) ) { ?>
777
+ <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li>
778
+ <?php
779
+ }
780
+ if ( ! empty( $api->author ) ) {
781
+ ?>
782
+ <li>
783
+ <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?>
784
+ </li>
785
+ <?php
786
+ }
787
+ if ( ! empty( $api->last_updated ) ) {
788
+ ?>
789
+ <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span
790
+ title="<?php echo $api->last_updated; ?>">
791
+ <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?>
792
+ </span></li>
793
+ <?php
794
+ }
795
+ if ( ! empty( $api->requires ) ) {
796
+ ?>
797
+ <li>
798
+ <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?>
799
+ </li>
800
+ <?php
801
+ }
802
+ if ( ! empty( $api->tested ) ) {
803
+ ?>
804
+ <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?>
805
+ </li>
806
+ <?php
807
+ }
808
+ if ( ! empty( $api->downloaded ) ) {
809
+ ?>
810
+ <li>
811
+ <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?>
812
+ </li>
813
+ <?php
814
+ }
815
+ if ( ! empty( $api->slug ) && empty( $api->external ) ) {
816
+ ?>
817
+ <li><a target="_blank"
818
+ href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page &#187;' ); ?></a>
819
+ </li>
820
+ <?php
821
+ }
822
+ if ( ! empty( $api->homepage ) ) {
823
+ ?>
824
+ <li><a target="_blank"
825
+ href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage &#187;' ); ?></a>
826
+ </li>
827
+ <?php
828
+ }
829
+ if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) {
830
+ ?>
831
+ <li><a target="_blank"
832
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
833
+ </li>
834
+ <?php } ?>
835
+ </ul>
836
+ </div>
837
+ <?php if ( ! empty( $api->rating ) ) { ?>
838
+ <h3><?php _e( 'Average Rating' ); ?></h3>
839
+ <?php wp_star_rating( array(
840
+ 'rating' => $api->rating,
841
+ 'type' => 'percent',
842
+ 'number' => $api->num_ratings
843
+ ) ); ?>
844
+ <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small>
845
+ <?php
846
+ }
847
+
848
+ if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) {
849
+ foreach ( $api->ratings as $key => $ratecount ) {
850
+ // Avoid div-by-zero.
851
+ $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0;
852
+ ?>
853
+ <div class="counter-container">
854
+ <span class="counter-label"><a
855
+ href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>"
856
+ target="_blank"
857
+ title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span>
858
+ <span class="counter-back">
859
+ <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span>
860
+ </span>
861
+ <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span>
862
+ </div>
863
+ <?php
864
+ }
865
+ }
866
+ if ( ! empty( $api->contributors ) ) {
867
+ ?>
868
+ <h3><?php _e( 'Contributors' ); ?></h3>
869
+ <ul class="contributors">
870
+ <?php
871
+ foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
872
+ if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
873
+ continue;
874
+ }
875
+ if ( empty( $contrib_username ) ) {
876
+ $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
877
+ }
878
+ $contrib_username = sanitize_user( $contrib_username );
879
+ if ( empty( $contrib_profile ) ) {
880
+ echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</li>";
881
+ } else {
882
+ echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' />{$contrib_username}</a></li>";
883
+ }
884
+ }
885
+ ?>
886
+ </ul>
887
+ <?php if ( ! empty( $api->donate_link ) ) { ?>
888
+ <a target="_blank"
889
+ href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin &#187;' ); ?></a>
890
+ <?php } ?>
891
+ <?php } ?>
892
+ </div>
893
+ <div id="section-holder" class="wrap">
894
+ <?php
895
+ if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) {
896
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>';
897
+ } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) {
898
+ echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been marked as compatible with your version of WordPress.' ) . '</p></div>';
899
+ }
900
+
901
+ foreach ( (array) $api->sections as $section_name => $content ) {
902
+ $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' );
903
+ $content = links_add_target( $content, '_blank' );
904
+
905
+ $san_section = esc_attr( $section_name );
906
+
907
+ $display = ( $section_name === $section ) ? 'block' : 'none';
908
+
909
+ if ( 'description' === $section_name &&
910
+ ( ( ! $api->external && $api->wp_org_missing ) ||
911
+ ( $api->external && $api->fs_missing ) )
912
+ ) {
913
+ $missing_notice = array(
914
+ 'type' => 'error',
915
+ 'id' => md5( microtime() ),
916
+ 'message' => __fs( ( $api->is_paid ? 'paid-addon-not-deployed' : 'free-addon-not-deployed' ), $api->slug ),
917
+ );
918
+ fs_require_template( 'admin-notice.php', $missing_notice );
919
+ }
920
+ echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n";
921
+ echo $content;
922
+ echo "\t</div>\n";
923
+ }
924
+ echo "</div>\n";
925
+ echo "</div>\n";
926
+ echo "</div>\n"; // #plugin-information-scrollable
927
+ echo "<div id='$tab-footer'>\n";
928
+
929
+ echo $this->get_plugin_cta( $api );
930
+
931
+ echo "</div>\n";
932
+
933
+ iframe_footer();
934
+ exit;
935
+ }
936
+ }
freemius/includes/i18n.php ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * All strings can now be overridden.
15
+ *
16
+ * For example, if we want to override:
17
+ * 'you-are-step-away' => 'You are just one step away - %s',
18
+ *
19
+ * We can use the filter:
20
+ * fs_override_i18n( array(
21
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
22
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
23
+ * ), '{plugin_slug}' );
24
+ *
25
+ * Or with the Freemius instance:
26
+ *
27
+ * my_freemius->override_i18n( array(
28
+ * 'opt-in-connect' => __( "Yes - I'm in!", '{your-text_domain}' ),
29
+ * 'skip' => __( 'Not today', '{your-text_domain}' ),
30
+ * );
31
+ */
32
+ global $fs_text;
33
+
34
+ $fs_text = array(
35
+ 'account' => __( 'Account', 'freemius' ),
36
+ 'addon' => __( 'Add On', 'freemius' ),
37
+ 'contact-us' => __( 'Contact Us', 'freemius' ),
38
+ 'change-ownership' => __( 'Change Ownership', 'freemius' ),
39
+ 'support' => __( 'Support', 'freemius' ),
40
+ 'support-forum' => __( 'Support Forum', 'freemius' ),
41
+ 'add-ons' => __( 'Add Ons', 'freemius' ),
42
+ 'upgrade' => _x( 'Upgrade', 'verb', 'freemius' ),
43
+ 'awesome' => __( 'Awesome', 'freemius' ),
44
+ 'pricing' => _x( 'Pricing', 'noun', 'freemius' ),
45
+ 'price' => _x( 'Price', 'noun', 'freemius' ),
46
+ 'unlimited-updates' => __( 'Unlimited Updates', 'freemius' ),
47
+ 'downgrade' => _x( 'Downgrade', 'verb', 'freemius' ),
48
+ 'cancel-trial' => __( 'Cancel Trial', 'freemius' ),
49
+ 'free-trial' => __( 'Free Trial', 'freemius' ),
50
+ 'start-free-x' => __( 'Start my free %s', 'freemius' ),
51
+ 'no-commitment-x' => __( 'No commitment for %s - cancel anytime', 'freemius' ),
52
+ 'after-x-pay-as-little-y' => __( 'After your free %s, pay as little as %s', 'freemius' ),
53
+ 'details' => __( 'Details', 'freemius' ),
54
+ 'account-details' => __( 'Account Details', 'freemius' ),
55
+ 'delete' => _x( 'Delete', 'verb', 'freemius' ),
56
+ 'delete-account' => __( 'Delete Account', 'freemius' ),
57
+ 'dismiss' => _x( 'Dismiss', 'as close a window', 'freemius' ),
58
+ 'plan' => _x( 'Plan', 'as product pricing plan', 'freemius' ),
59
+ 'change-plan' => __( 'Change Plan', 'freemius' ),
60
+ 'download-x-version' => _x( 'Download %s Version', 'as download professional version', 'freemius' ),
61
+ 'download-x-version-now' => _x( 'Download %s version now', 'as download professional version now', 'freemius' ),
62
+ 'download-latest' => _x( 'Download Latest', 'as download latest version', 'freemius' ),
63
+ 'you-have-x-license' => _x( 'You have a %s license.', 'E.g. you have a professional license.', 'freemius' ),
64
+ 'new' => __( 'New', 'freemius' ),
65
+ 'free' => __( 'Free', 'freemius' ),
66
+ 'trial' => _x( 'Trial', 'as trial plan', 'freemius' ),
67
+ 'purchase' => _x( 'Purchase', 'verb', 'freemius' ),
68
+ 'purchase-license' => __( 'Purchase License', 'freemius' ),
69
+ 'buy' => _x( 'Buy', 'verb', 'freemius' ),
70
+ 'buy-license' => __( 'Buy License', 'freemius' ),
71
+ 'license-single-site' => __( 'Single Site License', 'freemius' ),
72
+ 'license-unlimited' => __( 'Unlimited Licenses', 'freemius' ),
73
+ 'license-x-sites' => __( 'Up to %s Sites', 'freemius' ),
74
+ 'renew-license-now' => __( '%sRenew your license now%s to access version %s features and support.', 'freemius' ),
75
+ 'x-plan' => _x( '%s Plan', 'e.g. Professional Plan', 'freemius' ),
76
+ 'you-are-step-away' => __( 'You are just one step away - %s', 'freemius' ),
77
+ 'activate-x-now' => _x( 'Complete "%s" Activation Now', '%s - plugin name. As complete "Jetpack" activation now', 'freemius' ),
78
+ 'few-plugin-tweaks' => __( 'We made a few tweaks to the plugin, %s', 'freemius' ),
79
+ 'optin-x-now' => __( 'Opt-in to make "%s" Better!', 'freemius' ),
80
+ 'error' => __( 'Error', 'freemius' ),
81
+ 'failed-finding-main-path' => __( 'Freemius SDK couldn\'t find the plugin\'s main file. Please contact sdk@freemius.com with the current error.', 'freemius' ),
82
+ #region Account
83
+
84
+ 'expiration' => _x( 'Expiration', 'as expiration date', 'freemius' ),
85
+ 'license' => _x( 'License', 'as software license', 'freemius' ),
86
+ 'not-verified' => __( 'not verified', 'freemius' ),
87
+ 'verify-email' => __( 'Verify Email', 'freemius' ),
88
+ 'expires-in' => _x( 'Expires in %s', 'e.g. expires in 2 months', 'freemius' ),
89
+ 'renews-in' => _x( 'Auto renews in %s', 'e.g. auto renews in 2 months', 'freemius' ),
90
+ 'no-expiration' => __( 'No expiration', 'freemius' ),
91
+ 'expired' => __( 'Expired', 'freemius' ),
92
+ 'cancelled' => __( 'Cancelled', 'freemius' ),
93
+ 'in-x' => _x( 'In %s', 'e.g. In 2 hours', 'freemius' ),
94
+ 'x-ago' => _x( '%s ago', 'e.g. 2 min ago', 'freemius' ),
95
+ 'version' => _x( 'Version', 'as plugin version', 'freemius' ),
96
+ 'name' => __( 'Name', 'freemius' ),
97
+ 'email' => __( 'Email', 'freemius' ),
98
+ 'verified' => __( 'Verified', 'freemius' ),
99
+ 'plugin' => __( 'Plugin', 'freemius' ),
100
+ 'plugins' => __( 'Plugins', 'freemius' ),
101
+ 'themes' => __( 'Themes', 'freemius' ),
102
+ 'path' => _x( 'Path', 'as file/folder path', 'freemius' ),
103
+ 'title' => __( 'Title', 'freemius' ),
104
+ 'free-version' => __( 'Free version', 'freemius' ),
105
+ 'premium-version' => __( 'Premium version', 'freemius' ),
106
+ 'slug' => _x( 'Slug', 'as WP plugin slug', 'freemius' ),
107
+ 'id' => __( 'ID', 'freemius' ),
108
+ 'users' => __( 'Users', 'freemius' ),
109
+ 'plugin-installs' => __( 'Plugin Installs', 'freemius' ),
110
+ 'sites' => _x( 'Sites', 'like websites', 'freemius' ),
111
+ 'user-id' => __( 'User ID', 'freemius' ),
112
+ 'site-id' => __( 'Site ID', 'freemius' ),
113
+ 'public-key' => __( 'Public Key', 'freemius' ),
114
+ 'secret-key' => __( 'Secret Key', 'freemius' ),
115
+ 'no-secret' => _x( 'No Secret', 'as secret encryption key missing', 'freemius' ),
116
+ 'no-id' => __( 'No ID', 'freemius' ),
117
+ 'sync-license' => _x( 'Sync License', 'as synchronize license', 'freemius' ),
118
+ 'sync' => _x( 'Sync', 'as synchronize', 'freemius' ),
119
+ 'activate-license' => __( 'Activate License', 'freemius' ),
120
+ 'activate-free-version' => __( 'Activate Free Version', 'freemius' ),
121
+ 'activate-license-message' => __( 'Please enter the license key that you received in the email right after the purchase:', 'freemius' ),
122
+ 'activating-license' => __( 'Activating license...', 'freemius' ),
123
+ 'change-license' => __( 'Change License', 'freemius' ),
124
+ 'update-license' => __( 'Update License', 'freemius' ),
125
+ 'deactivate-license' => __( 'Deactivate License', 'freemius' ),
126
+ 'activate' => __( 'Activate', 'freemius' ),
127
+ 'deactivate' => __( 'Deactivate', 'freemius' ),
128
+ 'skip-deactivate' => __( 'Skip & Deactivate', 'freemius' ),
129
+ 'no-deactivate' => __( 'No - just deactivate', 'freemius' ),
130
+ 'yes-do-your-thing' => __( 'Yes - do your thing', 'freemius' ),
131
+ 'active' => _x( 'Active', 'active mode', 'freemius' ),
132
+ 'is-active' => _x( 'Is Active', 'is active mode?', 'freemius' ),
133
+ 'install-now' => __( 'Install Now', 'freemius' ),
134
+ 'install-update-now' => __( 'Install Update Now', 'freemius' ),
135
+ 'more-information-about-x' => __( 'More information about %s', 'freemius' ),
136
+ 'localhost' => __( 'Localhost', 'freemius' ),
137
+ 'activate-x-plan' => _x( 'Activate %s Plan', 'as activate Professional plan', 'freemius' ),
138
+ 'x-left' => _x( '%s left', 'as 5 licenses left', 'freemius' ),
139
+ 'last-license' => __( 'Last license', 'freemius' ),
140
+ 'what-is-your-x' => __( 'What is your %s?', 'freemius' ),
141
+ 'activate-this-addon' => __( 'Activate this add-on', 'freemius' ),
142
+ 'deactivate-license-confirm' => __( 'Deactivating your license will block all premium features, but will enable you to activate the license on another site. Are you sure you want to proceed?', 'freemius' ),
143
+ 'delete-account-x-confirm' => __( 'Deleting the account will automatically deactivate your %s plan license so you can use it on other sites. If you want to terminate the recurring payments as well, click the "Cancel" button, and first "Downgrade" your account. Are you sure you would like to continue with the deletion?', 'freemius' ),
144
+ 'delete-account-confirm' => __( 'Deletion is not temporary. Only delete if you no longer want to use this plugin anymore. Are you sure you would like to continue with the deletion?', 'freemius' ),
145
+ 'downgrade-x-confirm' => __( 'Downgrading your plan will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'freemius' ),
146
+ 'cancel-trial-confirm' => __( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'freemius' ),
147
+ 'after-downgrade-non-blocking' => __( 'You can still enjoy all %s features but you will not have access to plugin updates and support.', 'freemius' ),
148
+ 'after-downgrade-blocking' => __( 'Once your license expire you can still use the Free version but you will NOT have access to the %s features.', 'freemius' ),
149
+ 'proceed-confirmation' => __( 'Are you sure you want to proceed?', 'freemius' ),
150
+ #endregion Account
151
+
152
+ 'add-ons-for-x' => __( 'Add Ons for %s', 'freemius' ),
153
+ 'add-ons-missing' => __( 'We could\'nt load the add-ons list. It\'s probably an issue on our side, please try to come back in few minutes.', 'freemius' ),
154
+ #region Plugin Deactivation
155
+ 'deactivation-share-reason' => __( 'If you have a moment, please let us know why you are deactivating', 'freemius' ),
156
+ 'deactivation-modal-button-confirm' => __( 'Yes - Deactivate', 'freemius' ),
157
+ 'deactivation-modal-button-submit' => __( 'Submit & Deactivate', 'freemius' ),
158
+ 'deactivation-modal-button-cancel' => _x( 'Cancel', 'the text of the cancel button of the plugin deactivation dialog box.', 'freemius' ),
159
+ 'reason-no-longer-needed' => __( 'I no longer need the plugin', 'freemius' ),
160
+ 'reason-found-a-better-plugin' => __( 'I found a better plugin', 'freemius' ),
161
+ 'reason-needed-for-a-short-period' => __( 'I only needed the plugin for a short period', 'freemius' ),
162
+ 'reason-broke-my-site' => __( 'The plugin broke my site', 'freemius' ),
163
+ 'reason-suddenly-stopped-working' => __( 'The plugin suddenly stopped working', 'freemius' ),
164
+ 'reason-cant-pay-anymore' => __( "I can't pay for it anymore", 'freemius' ),
165
+ 'reason-temporary-deactivation' => __( "It's a temporary deactivation. I'm just debugging an issue.", 'freemius' ),
166
+ 'reason-other' => _x( 'Other', 'the text of the "other" reason for deactivating the plugin that is shown in the modal box.', 'freemius' ),
167
+ 'ask-for-reason-message' => __( 'Kindly tell us the reason so we can improve.', 'freemius' ),
168
+ 'placeholder-plugin-name' => __( "What's the plugin's name?", 'freemius' ),
169
+ 'placeholder-comfortable-price' => __( 'What price would you feel comfortable paying?', 'freemius' ),
170
+ 'reason-couldnt-make-it-work' => __( "I couldn't understand how to make it work", 'freemius' ),
171
+ 'reason-great-but-need-specific-feature' => __( "The plugin is great, but I need specific feature that you don't support", 'freemius' ),
172
+ 'reason-not-working' => __( 'The plugin is not working', 'freemius' ),
173
+ 'reason-not-what-i-was-looking-for' => __( "It's not what I was looking for", 'freemius' ),
174
+ 'reason-didnt-work-as-expected' => __( "The plugin didn't work as expected", 'freemius' ),
175
+ 'placeholder-feature' => __( 'What feature?', 'freemius' ),
176
+ 'placeholder-share-what-didnt-work' => __( "Kindly share what didn't work so we can fix it for future users...", 'freemius' ),
177
+ 'placeholder-what-youve-been-looking-for' => __( "What you've been looking for?", 'freemius' ),
178
+ 'placeholder-what-did-you-expect' => __( "What did you expect?", 'freemius' ),
179
+ 'reason-didnt-work' => __( "The plugin didn't work", 'freemius' ),
180
+ 'reason-dont-like-to-share-my-information' => __( "I don't like to share my information with you", 'freemius' ),
181
+ #endregion Plugin Deactivation
182
+
183
+ #region Connect
184
+ 'hey-x' => _x( 'Hey %s,', 'greeting', 'freemius' ),
185
+ 'thanks-x' => _x( 'Thanks %s!', 'a greeting. E.g. Thanks John!', 'freemius' ),
186
+ 'connect-message' => __( 'In order to enjoy all our features and functionality, %s needs to connect your user, %s at %s, to %s', 'freemius' ),
187
+ 'connect-message_on-update' => __( 'Please help us improve %2$s! If you opt-in, some data about your usage of %2$s will be sent to %5$s. If you skip this, that\'s okay! %2$s will still work just fine.', 'freemius' ),
188
+ 'pending-activation-message' => __( 'You should receive an activation email for %s to your mailbox at %s. Please make sure you click the activation button in that email to complete the install.', 'freemius' ),
189
+ 'thanks-for-purchasing' => __( 'Thanks for purchasing %s! To get started, please enter your license key:', 'freemius' ),
190
+ 'license-sync-disclaimer' => __( 'The plugin will be periodically sending data to %s to check for plugin updates and verify the validity of your license.', 'freemius' ),
191
+ 'what-permissions' => __( 'What permissions are being granted?', 'freemius' ),
192
+ 'permissions-profile' => __( 'Your Profile Overview', 'freemius' ),
193
+ 'permissions-profile_desc' => __( 'Name and email address', 'freemius' ),
194
+ 'permissions-site' => __( 'Your Site Overview', 'freemius' ),
195
+ 'permissions-site_desc' => __( 'Site URL, WP version, PHP info, plugins & themes', 'freemius' ),
196
+ 'permissions-events' => __( 'Current Plugin Events', 'freemius' ),
197
+ 'permissions-events_desc' => __( 'Activation, deactivation and uninstall', 'freemius' ),
198
+ 'permissions-plugins_themes' => __( 'Plugins & Themes', 'freemius' ),
199
+ 'permissions-plugins_themes_desc' => __( 'Titles, versions and state.', 'freemius' ),
200
+ 'permissions-newsletter' => __( 'Newsletter', 'freemius' ),
201
+ 'permissions-newsletter_desc' => __( 'Updates, announcements, marketing, no spam', 'freemius' ),
202
+ 'privacy-policy' => __( 'Privacy Policy', 'freemius' ),
203
+ 'tos' => __( 'Terms of Service', 'freemius' ),
204
+ 'activating' => _x( 'Activating', 'as activating plugin', 'freemius' ),
205
+ 'sending-email' => _x( 'Sending email', 'as in the process of sending an email', 'freemius' ),
206
+ 'opt-in-connect' => _x( 'Allow & Continue', 'button label', 'freemius' ),
207
+ 'agree-activate-license' => _x( 'Agree & Activate License', 'button label', 'freemius' ),
208
+ 'skip' => _x( 'Skip', 'verb', 'freemius' ),
209
+ 'resend-activation-email' => __( 'Re-send activation email', 'freemius' ),
210
+ 'license-key' => __( 'License key', 'freemius' ),
211
+ 'have-license-key' => __( 'Have a license key?', 'freemius' ),
212
+ 'dont-have-license-key' => __( 'Don\'t have a license key?', 'freemius' ),
213
+ #endregion Connect
214
+
215
+ #region Screenshots
216
+ 'screenshots' => __( 'Screenshots', 'freemius' ),
217
+ 'view-full-size-x' => __( 'Click to view full-size screenshot %d', 'freemius' ),
218
+ #endregion Screenshots
219
+
220
+ #region Debug
221
+ 'freemius-debug' => __( 'Freemius Debug', 'freemius' ),
222
+ 'on' => _x( 'On', 'as turned on', 'freemius' ),
223
+ 'off' => _x( 'Off', 'as turned off', 'freemius' ),
224
+ 'debugging' => _x( 'Debugging', 'as code debugging', 'freemius' ),
225
+ 'freemius-state' => __( 'Freemius State', 'freemius' ),
226
+ 'connected' => _x( 'Connected', 'as connection was successful', 'freemius' ),
227
+ 'blocked' => _x( 'Blocked', 'as connection blocked', 'freemius' ),
228
+ 'api' => _x( 'API', 'as application program interface', 'freemius' ),
229
+ 'sdk' => _x( 'SDK', 'as software development kit versions', 'freemius' ),
230
+ 'sdk-versions' => _x( 'SDK Versions', 'as software development kit versions', 'freemius' ),
231
+ 'plugin-path' => _x( 'Plugin Path', 'as plugin folder path', 'freemius' ),
232
+ 'sdk-path' => _x( 'SDK Path', 'as sdk path', 'freemius' ),
233
+ 'addons-of-x' => __( 'Add Ons of Plugin %s', 'freemius' ),
234
+ 'delete-all-confirm' => __( 'Are you sure you want to delete all Freemius data?', 'freemius' ),
235
+ 'actions' => __( 'Actions', 'freemius' ),
236
+ 'delete-all-accounts' => __( 'Delete All Accounts', 'freemius' ),
237
+ 'start-fresh' => __( 'Start Fresh', 'freemius' ),
238
+ 'clear-api-cache' => __( 'Clear API Cache', 'freemius' ),
239
+ 'sync-data-from-server' => __( 'Sync Data From Server', 'freemius' ),
240
+ 'scheduled-crons' => __( 'Scheduled Crons', 'freemius' ),
241
+ 'plugins-themes-sync' => __( 'Plugins & Themes Sync', 'freemius' ),
242
+ #endregion Debug
243
+
244
+ #region Expressions
245
+ 'congrats' => _x( 'Congrats', 'as congratulations', 'freemius' ),
246
+ 'oops' => _x( 'Oops', 'exclamation', 'freemius' ),
247
+ 'yee-haw' => _x( 'Yee-haw', 'interjection expressing joy or exuberance', 'freemius' ),
248
+ 'woot' => _x( 'W00t', '(especially in electronic communication) used to express elation, enthusiasm, or triumph.', 'freemius' ),
249
+ 'right-on' => _x( 'Right on', 'a positive response', 'freemius' ),
250
+ 'hmm' => _x( 'Hmm', 'something somebody says when they are thinking about what you have just said. ', 'freemius' ),
251
+ 'ok' => __( 'O.K', 'freemius' ),
252
+ 'hey' => _x( 'Hey', 'exclamation', 'freemius' ),
253
+ 'heads-up' => _x( 'Heads up', 'advance notice of something that will need attention.', 'freemius' ),
254
+ #endregion Expressions
255
+
256
+ #region Admin Notices
257
+ 'you-have-latest' => __( 'Seems like you got the latest release.', 'freemius' ),
258
+ 'you-are-good' => __( 'You are all good!', 'freemius' ),
259
+ 'user-exist-message' => __( 'Sorry, we could not complete the email update. Another user with the same email is already registered.', 'freemius' ),
260
+ 'user-exist-message_ownership' => __( 'If you would like to give up the ownership of the plugin\'s account to %s click the Change Ownership button.', 'freemius' ),
261
+ 'email-updated-message' => __( 'Your email was successfully updated. You should receive an email with confirmation instructions in few moments.', 'freemius' ),
262
+ 'name-updated-message' => __( 'Your name was successfully updated.', 'freemius' ),
263
+ 'x-updated' => __( 'You have successfully updated your %s.', 'freemius' ),
264
+ 'name-update-failed-message' => __( 'Please provide your full name.', 'freemius' ),
265
+ 'verification-email-sent-message' => __( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'freemius' ),
266
+ 'addons-info-external-message' => __( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'freemius' ),
267
+ 'no-cc-required' => __( 'No credit card required', 'freemius' ),
268
+ 'premium-activated-message' => __( 'Premium plugin version was successfully activated.', 'freemius' ),
269
+ 'successful-version-upgrade-message' => __( 'The upgrade of %s was successfully completed.', 'freemius' ),
270
+ 'activation-with-plan-x-message' => __( 'Your account was successfully activated with the %s plan.', 'freemius' ),
271
+ 'download-latest-x-version' => __( 'Download the latest %s version now', 'freemius' ),
272
+ 'download-latest-version' => __( 'Download the latest version now', 'freemius' ),
273
+ 'addon-successfully-purchased-message' => _x( '%s Add-on was successfully purchased.', '%s - product name, e.g. Facebook add-on was successfully...', 'freemius' ),
274
+ 'addon-successfully-upgraded-message' => __( 'Your %s Add-on plan was successfully upgraded.', 'freemius' ),
275
+ 'email-verified-message' => __( 'Your email has been successfully verified - you are AWESOME!', 'freemius' ),
276
+ 'plan-upgraded-message' => __( 'Your plan was successfully upgraded.', 'freemius' ),
277
+ 'plan-changed-to-x-message' => __( 'Your plan was successfully changed to %s.', 'freemius' ),
278
+ 'license-expired-blocking-message' => __( 'Your license has expired. You can still continue using the free plugin forever.', 'freemius' ),
279
+ 'license-cancelled' => __( 'Your license has been cancelled. If you think it\'s a mistake, please contact support.', 'freemius' ),
280
+ 'trial-started-message' => __( 'Your trial has been successfully started.', 'freemius' ),
281
+ 'license-activated-message' => __( 'Your license was successfully activated.', 'freemius' ),
282
+ 'no-active-license-message' => __( 'It looks like your site currently doesn\'t have an active license.', 'freemius' ),
283
+ 'license-deactivation-message' => __( 'Your license was successfully deactivated, you are back to the %s plan.', 'freemius' ),
284
+ 'license-deactivation-failed-message' => __( 'It looks like the license deactivation failed.', 'freemius' ),
285
+ 'license-activation-failed-message' => __( 'It looks like the license could not be activated.', 'freemius' ),
286
+ 'server-error-message' => __( 'Error received from the server:', 'freemius' ),
287
+ 'trial-expired-message' => __( 'Your trial has expired. You can still continue using all our free features.', 'freemius' ),
288
+ 'plan-x-downgraded-message' => __( 'Your plan was successfully downgraded. Your %s plan license will expire in %s.', 'freemius' ),
289
+ 'plan-downgraded-failure-message' => __( 'Seems like we are having some temporary issue with your plan downgrade. Please try again in few minutes.', 'freemius' ),
290
+ 'trial-cancel-no-trial-message' => __( 'It looks like you are not in trial mode anymore so there\'s nothing to cancel :)', 'freemius' ),
291
+ 'trial-cancel-message' => __( 'Your %s free trial was successfully cancelled.', 'freemius' ),
292
+ 'version-x-released' => _x( 'Version %s was released.', '%s - numeric version number', 'freemius' ),
293
+ 'please-download-x' => __( 'Please download %s.', 'freemius' ),
294
+ 'latest-x-version' => _x( 'the latest %s version here', '%s - plan name, as the latest professional version here', 'freemius' ),
295
+ 'trial-x-promotion-message' => __( 'How do you like %s so far? Test all our %s premium features with a %d-day free trial.', 'freemius' ),
296
+ 'start-free-trial' => _x( 'Start free trial', 'call to action', 'freemius' ),
297
+ 'trial-cancel-failure-message' => __( 'Seems like we are having some temporary issue with your trial cancellation. Please try again in few minutes.', 'freemius' ),
298
+ 'trial-utilized' => __( 'You already utilized a trial before.', 'freemius' ),
299
+ 'in-trial-mode' => __( 'You are already running the plugin in a trial mode.', 'freemius' ),
300
+ 'trial-plan-x-not-exist' => __( 'Plan %s do not exist, therefore, can\'t start a trial.', 'freemius' ),
301
+ 'plan-x-no-trial' => __( 'Plan %s does not support a trial period.', 'freemius' ),
302
+ 'no-trials' => __( 'None of the plugin\'s plans supports a trial period.', 'freemius' ),
303
+ 'unexpected-api-error' => __( 'Unexpected API error. Please contact the plugin\'s author with the following error.', 'freemius' ),
304
+ 'no-commitment-for-x-days' => __( 'No commitment for %s days - cancel anytime!', 'freemius' ),
305
+ 'license-expired-non-blocking-message' => __( 'Your license has expired. You can still continue using all the %s features, but you\'ll need to renew your license to continue getting updates and support.', 'freemius' ),
306
+ 'could-not-activate-x' => __( 'Couldn\'t activate %s.', 'freemius' ),
307
+ 'contact-us-with-error-message' => __( 'Please contact us with the following message:', 'freemius' ),
308
+ 'plan-did-not-change-message' => __( 'It looks like you are still on the %s plan. If you did upgrade or change your plan, it\'s probably an issue on our side - sorry.', 'freemius' ),
309
+ 'contact-us-here' => __( 'Please contact us here', 'freemius' ),
310
+ 'plan-did-not-change-email-message' => __( 'I have upgraded my account but when I try to Sync the License, the plan remains %s.', 'freemius' ),
311
+ #endregion Admin Notices
312
+ #region Connectivity Issues
313
+ 'connectivity-test-fails-message' => __( 'From unknown reason, the API connectivity test failed.', 'freemius' ),
314
+ 'connectivity-test-maybe-temporary' => __( 'It\'s probably a temporary issue on our end. Just to be sure, with your permission, would it be o.k to run another connectivity test?', 'freemius' ),
315
+ 'curl-missing-message' => __( 'We use PHP cURL library for the API calls, which is a very common library and usually installed out of the box. Unfortunately, cURL is not installed on your server.', 'freemius' ),
316
+ 'cloudflare-blocks-connection-message' => __( 'From unknown reason, CloudFlare, the firewall we use, blocks the connection.', 'freemius' ),
317
+ 'x-requires-access-to-api' => _x( '%s requires an access to our API.', 'as pluginX requires an access to our API', 'freemius' ),
318
+ 'squid-blocks-connection-message' => __( 'It looks like your server is using Squid ACL (access control lists), which blocks the connection.', 'freemius' ),
319
+ 'squid-no-clue-title' => __( 'I don\'t know what is Squid or ACL, help me!', 'freemius' ),
320
+ 'squid-no-clue-desc' => __( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'freemius' ),
321
+ 'sysadmin-title' => __( 'I\'m a system administrator', 'freemius' ),
322
+ 'squid-sysadmin-desc' => __( 'Great, please whitelist the following domains: %s. Once you done, deactivate the plugin and activate it again.', 'freemius' ),
323
+ 'curl-missing-no-clue-title' => __( 'I don\'t know what is cURL or how to install it, help me!', 'freemius' ),
324
+ 'curl-missing-no-clue-desc' => __( 'We\'ll make sure to contact your hosting company and resolve the issue. You will get a follow-up email to %s once we have an update.', 'freemius' ),
325
+ 'curl-missing-sysadmin-desc' => __( 'Great, please install cURL and enable it in your php.ini file. To make sure it was successfully activated, use \'phpinfo()\'. Once activated, deactivate the plugin and reactivate it back again.', 'freemius' ),
326
+ 'happy-to-resolve-issue-asap' => __( 'We are sure it\'s an issue on our side and more than happy to resolve it for you ASAP if you give us a chance.', 'freemius' ),
327
+ 'fix-issue-title' => __( 'Yes - I\'m giving you a chance to fix it', 'freemius' ),
328
+ 'fix-issue-desc' => __( 'We will do our best to whitelist your server and resolve this issue ASAP. You will get a follow-up email to %s once we have an update.', 'freemius' ),
329
+ 'install-previous-title' => __( 'Let\'s try your previous version', 'freemius' ),
330
+ 'install-previous-desc' => __( 'Uninstall this version and install the previous one.', 'freemius' ),
331
+ 'deactivate-plugin-title' => __( 'That\'s exhausting, please deactivate', 'freemius' ),
332
+ 'deactivate-plugin-desc' => __( 'We feel your frustration and sincerely apologize for the inconvenience. Hope to see you again in the future.', 'freemius' ),
333
+ 'fix-request-sent-message' => __( 'Thank for giving us the chance to fix it! A message was just sent to our technical staff. We will get back to you as soon as we have an update to %s. Appreciate your patience.', 'freemius' ),
334
+ 'server-blocking-access' => _x( 'Your server is blocking the access to Freemius\' API, which is crucial for %1s synchronization. Please contact your host to whitelist %2s', '%1s - plugin title, %2s - API domain', 'freemius' ),
335
+ 'wrong-authentication-param-message' => __( 'It seems like one of the authentication parameters is wrong. Update your Public Key, Secret Key & User ID, and try again.', 'freemius' ),
336
+ #endregion Connectivity Issues
337
+ #region Change Owner
338
+ 'change-owner-request-sent-x' => __( 'Please check your mailbox, you should receive an email via %s to confirm the ownership change. From security reasons, you must confirm the change within the next 15 min. If you cannot find the email, please check your spam folder.', 'freemius' ),
339
+ 'change-owner-request_owner-confirmed' => __( 'Thanks for confirming the ownership change. An email was just sent to %s for final approval.', 'freemius' ),
340
+ 'change-owner-request_candidate-confirmed' => __( '%s is the new owner of the account.', 'freemius' ),
341
+ #endregion Change Owner
342
+ 'addon-x-cannot-run-without-y' => _x( '%s cannot run without %s.', 'addonX cannot run without pluginY', 'freemius' ),
343
+ 'addon-x-cannot-run-without-parent' => _x( '%s cannot run without the plugin.', 'addonX cannot run...', 'freemius' ),
344
+ 'plugin-x-activation-message' => _x( '%s activation was successfully completed.', 'pluginX activation was successfully...', 'freemius' ),
345
+ 'features-and-pricing' => _x( 'Features & Pricing', 'Plugin installer section title', 'freemius' ),
346
+ 'free-addon-not-deployed' => __( 'Add-on must be deployed to WordPress.org or Freemius.', 'freemius' ),
347
+ 'paid-addon-not-deployed' => __( 'Paid add-on must be deployed to Freemius.', 'freemius' ),
348
+ #region Add-On Licensing
349
+ 'addon-no-license-message' => __( '%s is a premium only add-on. You have to purchase a license first before activating the plugin.', 'freemius' ),
350
+ 'addon-trial-cancelled-message' => __( '%s free trial was successfully cancelled. Since the add-on is premium only it was automatically deactivated. If you like to use it in the future, you\'ll have to purchase a license.', 'freemius' ),
351
+ #endregion Add-On Licensing
352
+ #region Billing Cycles
353
+ 'monthly' => _x( 'Monthly', 'as every month', 'freemius' ),
354
+ 'mo' => _x( 'mo', 'as monthly period', 'freemius' ),
355
+ 'annual' => _x( 'Annual', 'as once a year', 'freemius' ),
356
+ 'annually' => _x( 'Annually', 'as once a year', 'freemius' ),
357
+ 'once' => _x( 'Once', 'as once a year', 'freemius' ),
358
+ 'year' => _x( 'year', 'as annual period', 'freemius' ),
359
+ 'lifetime' => __( 'Lifetime', 'freemius' ),
360
+ 'best' => _x( 'Best', 'e.g. the best product', 'freemius' ),
361
+ 'billed-x' => _x( 'Billed %s', 'e.g. billed monthly', 'freemius' ),
362
+ 'save-x' => _x( 'Save %s', 'as a discount of $5 or 10%', 'freemius' ),
363
+ #endregion Billing Cycles
364
+ 'view-details' => __( 'View details', 'freemius' ),
365
+ );
freemius/includes/managers/class-fs-admin-menu-manager.php ADDED
@@ -0,0 +1,549 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Menu_Manager {
14
+
15
+ #region Properties
16
+
17
+ /**
18
+ * @var string
19
+ */
20
+ protected $_plugin_slug;
21
+
22
+ /**
23
+ * @since 1.0.6
24
+ *
25
+ * @var string
26
+ */
27
+ private $_menu_slug;
28
+ /**
29
+ * @since 1.1.3
30
+ *
31
+ * @var string
32
+ */
33
+ private $_parent_slug;
34
+ /**
35
+ * @since 1.1.3
36
+ *
37
+ * @var string
38
+ */
39
+ private $_parent_type;
40
+ /**
41
+ * @since 1.1.3
42
+ *
43
+ * @var string
44
+ */
45
+ private $_type;
46
+ /**
47
+ * @since 1.1.3
48
+ *
49
+ * @var bool
50
+ */
51
+ private $_is_top_level;
52
+ /**
53
+ * @since 1.1.3
54
+ *
55
+ * @var bool
56
+ */
57
+ private $_is_override_exact;
58
+ /**
59
+ * @since 1.1.3
60
+ *
61
+ * @var string[]bool
62
+ */
63
+ private $_default_submenu_items;
64
+ /**
65
+ * @since 1.1.3
66
+ *
67
+ * @var string
68
+ */
69
+ private $_first_time_path;
70
+
71
+ #endregion Properties
72
+
73
+ /**
74
+ * @var FS_Logger
75
+ */
76
+ protected $_logger;
77
+
78
+ #region Singleton
79
+
80
+ /**
81
+ * @var FS_Admin_Menu_Manager[]
82
+ */
83
+ private static $_instances = array();
84
+
85
+ /**
86
+ * @param string $plugin_slug
87
+ *
88
+ * @return FS_Admin_Notice_Manager
89
+ */
90
+ static function instance( $plugin_slug ) {
91
+ if ( ! isset( self::$_instances[ $plugin_slug ] ) ) {
92
+ self::$_instances[ $plugin_slug ] = new FS_Admin_Menu_Manager( $plugin_slug );
93
+ }
94
+
95
+ return self::$_instances[ $plugin_slug ];
96
+ }
97
+
98
+ protected function __construct( $plugin_slug ) {
99
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $plugin_slug . '_admin_menu', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
100
+
101
+ $this->_plugin_slug = $plugin_slug;
102
+ }
103
+
104
+ #endregion Singleton
105
+
106
+ #region Helpers
107
+
108
+ private function get_option( &$options, $key, $default = false ) {
109
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
110
+ }
111
+
112
+ private function get_bool_option( &$options, $key, $default = false ) {
113
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
114
+ }
115
+
116
+ #endregion Helpers
117
+
118
+ /**
119
+ * @param array $menu
120
+ * @param bool $is_addon
121
+ */
122
+ function init( $menu, $is_addon = false ) {
123
+ $this->_menu_slug = $menu['slug'];
124
+
125
+ $this->_default_submenu_items = array();
126
+ // @deprecated
127
+ $this->_type = 'page';
128
+ $this->_is_top_level = true;
129
+ $this->_is_override_exact = false;
130
+ $this->_parent_slug = false;
131
+ // @deprecated
132
+ $this->_parent_type = 'page';
133
+
134
+ if ( ! $is_addon && isset( $menu ) ) {
135
+ $this->_default_submenu_items = array(
136
+ 'contact' => $this->get_bool_option( $menu, 'contact', true ),
137
+ 'support' => $this->get_bool_option( $menu, 'support', true ),
138
+ 'account' => $this->get_bool_option( $menu, 'account', true ),
139
+ 'pricing' => $this->get_bool_option( $menu, 'pricing', true ),
140
+ 'addons' => $this->get_bool_option( $menu, 'addons', true ),
141
+ );
142
+
143
+ // @deprecated
144
+ $this->_type = $this->get_option( $menu, 'type', 'page' );
145
+ $this->_is_override_exact = $this->get_bool_option( $menu, 'override_exact' );
146
+
147
+ if ( isset( $menu['parent'] ) ) {
148
+ $this->_parent_slug = $this->get_option( $menu['parent'], 'slug' );
149
+ // @deprecated
150
+ $this->_parent_type = $this->get_option( $menu['parent'], 'type', 'page' );
151
+
152
+ // If parent's slug is different, then it's NOT a top level menu item.
153
+ $this->_is_top_level = ( $this->_parent_slug === $this->_menu_slug );
154
+ } else {
155
+ /**
156
+ * If no parent then top level if:
157
+ * - Has custom admin menu ('page')
158
+ * - CPT menu type ('cpt')
159
+ */
160
+ // $this->_is_top_level = in_array( $this->_type, array(
161
+ // 'cpt',
162
+ // 'page'
163
+ // ) );
164
+ }
165
+
166
+ $this->_first_time_path = $this->get_option( $menu, 'first-path', false );
167
+ if ( ! empty( $this->_first_time_path ) && is_string( $this->_first_time_path ) ) {
168
+ $this->_first_time_path = admin_url( $this->_first_time_path, 'admin' );
169
+ }
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Check if top level menu.
175
+ *
176
+ * @author Vova Feldman (@svovaf)
177
+ * @since 1.1.3
178
+ *
179
+ * @return bool False if submenu item.
180
+ */
181
+ function is_top_level() {
182
+ return $this->_is_top_level;
183
+ }
184
+
185
+ /**
186
+ * Check if the page should be override on exact URL match.
187
+ *
188
+ * @author Vova Feldman (@svovaf)
189
+ * @since 1.1.3
190
+ *
191
+ * @return bool False if submenu item.
192
+ */
193
+ function is_override_exact() {
194
+ return $this->_is_override_exact;
195
+ }
196
+
197
+
198
+ /**
199
+ * Get the path of the page the user should be forwarded to after first activation.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.3
203
+ *
204
+ * @return string
205
+ */
206
+ function get_first_time_path() {
207
+ return $this->_first_time_path;
208
+ }
209
+
210
+ /**
211
+ * Check if plugin's menu item is part of a custom top level menu.
212
+ *
213
+ * @author Vova Feldman (@svovaf)
214
+ * @since 1.1.3
215
+ *
216
+ * @return bool
217
+ */
218
+ function has_custom_parent() {
219
+ return ! $this->_is_top_level && is_string( $this->_parent_slug );
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.1.3
225
+ *
226
+ * @return string
227
+ */
228
+ // function slug(){
229
+ // return $this->_menu_slug;
230
+ // }
231
+
232
+ /**
233
+ * @author Vova Feldman (@svovaf)
234
+ * @since 1.1.3
235
+ *
236
+ * @param string $id
237
+ * @param bool $default
238
+ *
239
+ * @return bool
240
+ */
241
+ function is_submenu_item_visible( $id, $default = true ) {
242
+ return fs_apply_filter(
243
+ $this->_plugin_slug,
244
+ 'is_submenu_visible',
245
+ $this->get_bool_option( $this->_default_submenu_items, $id, $default ),
246
+ $id
247
+ );
248
+ }
249
+
250
+ /**
251
+ * Calculates admin settings menu slug.
252
+ * If plugin's menu slug is a file (e.g. CPT), uses plugin's slug as the menu slug.
253
+ *
254
+ * @author Vova Feldman (@svovaf)
255
+ * @since 1.1.3
256
+ *
257
+ * @param string $page
258
+ *
259
+ * @return string
260
+ */
261
+ function get_slug( $page = '' ) {
262
+ return ( ( false === strpos( $this->_menu_slug, '.php?' ) ) ?
263
+ $this->_menu_slug :
264
+ $this->_plugin_slug ) . ( empty( $page ) ? '' : ( '-' . $page ) );
265
+ }
266
+
267
+ /**
268
+ * @author Vova Feldman (@svovaf)
269
+ * @since 1.1.3
270
+ *
271
+ * @return string
272
+ */
273
+ function get_parent_slug() {
274
+ return $this->_parent_slug;
275
+ }
276
+
277
+ /**
278
+ * @author Vova Feldman (@svovaf)
279
+ * @since 1.1.3
280
+ *
281
+ * @return string
282
+ */
283
+ function get_type() {
284
+ return $this->_type;
285
+ }
286
+
287
+ /**
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.1.3
290
+ *
291
+ * @return bool
292
+ */
293
+ function is_cpt() {
294
+ return ( 0 === strpos( $this->_menu_slug, 'edit.php?post_type=' ) ||
295
+ // Back compatibility.
296
+ 'cpt' === $this->_type
297
+ );
298
+ }
299
+
300
+ /**
301
+ * @author Vova Feldman (@svovaf)
302
+ * @since 1.1.3
303
+ *
304
+ * @return string
305
+ */
306
+ function get_parent_type() {
307
+ return $this->_parent_type;
308
+ }
309
+
310
+ /**
311
+ * @author Vova Feldman (@svovaf)
312
+ * @since 1.1.3
313
+ *
314
+ * @return string
315
+ */
316
+ function get_raw_slug() {
317
+ return $this->_menu_slug;
318
+ }
319
+
320
+ /**
321
+ * Get plugin's original menu slug.
322
+ *
323
+ * @author Vova Feldman (@svovaf)
324
+ * @since 1.1.3
325
+ *
326
+ * @return string
327
+ */
328
+ function get_original_menu_slug() {
329
+ if ( 'cpt' === $this->_type ) {
330
+ return add_query_arg( array(
331
+ 'post_type' => $this->_menu_slug
332
+ ), 'edit.php' );
333
+ }
334
+
335
+ if ( false === strpos( $this->_menu_slug, '.php?' ) ) {
336
+ return $this->_menu_slug;
337
+ } else {
338
+ return $this->_plugin_slug;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * @author Vova Feldman (@svovaf)
344
+ * @since 1.1.3
345
+ *
346
+ * @return string
347
+ */
348
+ function get_top_level_menu_slug() {
349
+ return $this->has_custom_parent() ?
350
+ $this->get_parent_slug() :
351
+ $this->get_raw_slug();
352
+ }
353
+
354
+ /**
355
+ * Is user on plugin's admin activation page.
356
+ *
357
+ * @author Vova Feldman (@svovaf)
358
+ * @since 1.0.8
359
+ *
360
+ * @return bool
361
+ */
362
+ function is_activation_page() {
363
+ return isset( $_GET['page'] ) &&
364
+ ( ( strtolower( $this->_menu_slug ) === strtolower( $_GET['page'] ) ) ||
365
+ ( strtolower( $this->_plugin_slug ) === strtolower( $_GET['page'] ) ) );
366
+ }
367
+
368
+ #region Submenu Override
369
+
370
+ /**
371
+ * Override submenu's action.
372
+ *
373
+ * @author Vova Feldman (@svovaf)
374
+ * @since 1.1.0
375
+ *
376
+ * @param string $parent_slug
377
+ * @param string $menu_slug
378
+ * @param callable $function
379
+ *
380
+ * @return false|string If submenu exist, will return the hook name.
381
+ */
382
+ function override_submenu_action( $parent_slug, $menu_slug, $function ) {
383
+ global $submenu;
384
+
385
+ $menu_slug = plugin_basename( $menu_slug );
386
+ $parent_slug = plugin_basename( $parent_slug );
387
+
388
+ if ( ! isset( $submenu[ $parent_slug ] ) ) {
389
+ // Parent menu not exist.
390
+ return false;
391
+ }
392
+
393
+ $found_submenu_item = false;
394
+ foreach ( $submenu[ $parent_slug ] as $submenu_item ) {
395
+ if ( $menu_slug === $submenu_item[2] ) {
396
+ $found_submenu_item = $submenu_item;
397
+ break;
398
+ }
399
+ }
400
+
401
+ if ( false === $found_submenu_item ) {
402
+ // Submenu item not found.
403
+ return false;
404
+ }
405
+
406
+ // Remove current function.
407
+ $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
408
+ remove_all_actions( $hookname );
409
+
410
+ // Attach new action.
411
+ add_action( $hookname, $function );
412
+
413
+ return $hookname;
414
+ }
415
+
416
+ #endregion Submenu Override
417
+
418
+ #region Top level menu Override
419
+
420
+ /**
421
+ * Find plugin's admin dashboard main menu item.
422
+ *
423
+ * @author Vova Feldman (@svovaf)
424
+ * @since 1.0.2
425
+ *
426
+ * @return string[]|false
427
+ */
428
+ private function find_top_level_menu() {
429
+ global $menu;
430
+
431
+ $position = - 1;
432
+ $found_menu = false;
433
+
434
+ $menu_slug = $this->get_raw_slug();
435
+
436
+ $hook_name = get_plugin_page_hookname( $menu_slug, '' );
437
+ foreach ( $menu as $pos => $m ) {
438
+ if ( $menu_slug === $m[2] ) {
439
+ $position = $pos;
440
+ $found_menu = $m;
441
+ break;
442
+ }
443
+ }
444
+
445
+ if ( false === $found_menu ) {
446
+ return false;
447
+ }
448
+
449
+ return array(
450
+ 'menu' => $found_menu,
451
+ 'position' => $position,
452
+ 'hook_name' => $hook_name
453
+ );
454
+ }
455
+
456
+ /**
457
+ * Remove all sub-menu items.
458
+ *
459
+ * @author Vova Feldman (@svovaf)
460
+ * @since 1.0.7
461
+ *
462
+ * @return bool If submenu with plugin's menu slug was found.
463
+ */
464
+ private function remove_all_submenu_items() {
465
+ global $submenu;
466
+
467
+ $menu_slug = $this->get_raw_slug();
468
+
469
+ if ( ! isset( $submenu[ $menu_slug ] ) ) {
470
+ return false;
471
+ }
472
+
473
+ $submenu[ $menu_slug ] = array();
474
+
475
+ return true;
476
+ }
477
+
478
+ /**
479
+ *
480
+ * @author Vova Feldman (@svovaf)
481
+ * @since 1.0.9
482
+ *
483
+ * @return array[string]mixed
484
+ */
485
+ function remove_menu_item() {
486
+ $this->_logger->entrance();
487
+
488
+ // Find main menu item.
489
+ $menu = $this->find_top_level_menu();
490
+
491
+ if ( false === $menu ) {
492
+ return false;
493
+ }
494
+
495
+ // Remove it with its actions.
496
+ remove_all_actions( $menu['hook_name'] );
497
+
498
+ // Remove all submenu items.
499
+ $this->remove_all_submenu_items();
500
+
501
+ return $menu;
502
+ }
503
+
504
+ /**
505
+ *
506
+ * @author Vova Feldman (@svovaf)
507
+ * @since 1.1.4
508
+ *
509
+ * @param callable $function
510
+ *
511
+ * @return array[string]mixed
512
+ */
513
+ function override_menu_item( $function ) {
514
+ $found_menu = $this->remove_menu_item();
515
+
516
+ if ( false === $found_menu ) {
517
+ return false;
518
+ }
519
+
520
+ if ( ! $this->is_top_level() || ! $this->is_cpt() ) {
521
+ $menu_slug = plugin_basename( $this->get_slug() );
522
+
523
+ $hookname = get_plugin_page_hookname( $menu_slug, '' );
524
+
525
+ // Override menu action.
526
+ add_action( $hookname, $function );
527
+ } else {
528
+ global $menu;
529
+
530
+ // Remove original CPT menu.
531
+ unset( $menu[ $found_menu['position'] ] );
532
+
533
+ // Create new top-level menu action.
534
+ $hookname = add_menu_page(
535
+ $found_menu['menu'][3],
536
+ $found_menu['menu'][0],
537
+ 'manage_options',
538
+ $this->get_slug(),
539
+ $function,
540
+ $found_menu['menu'][6],
541
+ $found_menu['position']
542
+ );
543
+ }
544
+
545
+ return $hookname;
546
+ }
547
+
548
+ #endregion Top level menu Override
549
+ }
freemius/includes/managers/class-fs-admin-notice-manager.php ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Admin_Notice_Manager {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_slug;
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_title;
22
+ /**
23
+ * @var array[]
24
+ */
25
+ private $_admin_messages = array();
26
+ /**
27
+ * @var FS_Key_Value_Storage
28
+ */
29
+ private $_sticky_storage;
30
+ /**
31
+ * @var FS_Plugin_Manager[]
32
+ */
33
+ private static $_instances = array();
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ protected $_logger;
38
+
39
+ /**
40
+ * @param string $slug
41
+ * @param string $title
42
+ *
43
+ * @return FS_Admin_Notice_Manager
44
+ */
45
+ static function instance( $slug, $title = '' ) {
46
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
47
+ self::$_instances[ $slug ] = new FS_Admin_Notice_Manager( $slug, $title );
48
+ }
49
+
50
+ return self::$_instances[ $slug ];
51
+ }
52
+
53
+ protected function __construct( $slug, $title = '' ) {
54
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_data', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
55
+
56
+ $this->_slug = $slug;
57
+ $this->_title = ! empty( $title ) ? $title : '';
58
+ $this->_sticky_storage = FS_Key_Value_Storage::instance( 'admin_notices', $this->_slug );
59
+
60
+ if ( is_admin() ) {
61
+ if ( 0 < count( $this->_sticky_storage ) ) {
62
+ // If there are sticky notices for the current slug, add a callback
63
+ // to the AJAX action that handles message dismiss.
64
+ add_action( "wp_ajax_{$slug}_dismiss_notice_action", array(
65
+ &$this,
66
+ 'dismiss_notice_ajax_callback'
67
+ ) );
68
+
69
+ foreach ( $this->_sticky_storage as $id => $msg ) {
70
+ // Add admin notice.
71
+ $this->add(
72
+ $msg['message'],
73
+ $msg['title'],
74
+ $msg['type'],
75
+ true,
76
+ $msg['all'],
77
+ $msg['id'],
78
+ false
79
+ );
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Remove sticky message by ID.
87
+ *
88
+ * @author Vova Feldman (@svovaf)
89
+ * @since 1.0.7
90
+ *
91
+ */
92
+ function dismiss_notice_ajax_callback() {
93
+ $this->_sticky_storage->remove( $_POST['message_id'] );
94
+ wp_die();
95
+ }
96
+
97
+ /**
98
+ * Rendered sticky message dismiss JavaScript.
99
+ *
100
+ * @author Vova Feldman (@svovaf)
101
+ * @since 1.0.7
102
+ */
103
+ static function _add_sticky_dismiss_javascript() {
104
+ $params = array();
105
+ fs_require_once_template( 'sticky-admin-notice-js.php', $params );
106
+ }
107
+
108
+ private static $_added_sticky_javascript = false;
109
+
110
+ /**
111
+ * Hook to the admin_footer to add sticky message dismiss JavaScript handler.
112
+ *
113
+ * @author Vova Feldman (@svovaf)
114
+ * @since 1.0.7
115
+ */
116
+ private static function has_sticky_messages() {
117
+ if ( ! self::$_added_sticky_javascript ) {
118
+ add_action( 'admin_footer', array( 'FS_Admin_Notice_Manager', '_add_sticky_dismiss_javascript' ) );
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Handle admin_notices by printing the admin messages stacked in the queue.
124
+ *
125
+ * @author Vova Feldman (@svovaf)
126
+ * @since 1.0.4
127
+ *
128
+ */
129
+ function _admin_notices_hook() {
130
+ $notice_type = 'admin_notices';
131
+
132
+ if ( function_exists( 'current_user_can' ) &&
133
+ ! current_user_can( 'manage_options' )
134
+ ) {
135
+ // Only show messages to admins.
136
+ return;
137
+ }
138
+
139
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
140
+ return;
141
+ }
142
+
143
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
144
+ fs_require_template( 'admin-notice.php', $msg );
145
+
146
+ if ( $msg['sticky'] ) {
147
+ self::has_sticky_messages();
148
+ }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Handle all_admin_notices by printing the admin messages stacked in the queue.
154
+ *
155
+ * @author Vova Feldman (@svovaf)
156
+ * @since 1.0.4
157
+ *
158
+ */
159
+ function _all_admin_notices_hook() {
160
+ $notice_type = 'all_admin_notices';
161
+
162
+ if ( ! isset( $this->_admin_messages[ $notice_type ] ) || ! is_array( $this->_admin_messages[ $notice_type ] ) ) {
163
+ return;
164
+ }
165
+
166
+ foreach ( $this->_admin_messages[ $notice_type ] as $id => $msg ) {
167
+ fs_require_template( 'all-admin-notice.php', $msg );
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Enqueue common stylesheet to style admin notice.
173
+ *
174
+ * @author Vova Feldman (@svovaf)
175
+ * @since 1.0.7
176
+ */
177
+ function _enqueue_styles() {
178
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
179
+ }
180
+
181
+ /**
182
+ * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
183
+ *
184
+ * @author Vova Feldman (@svovaf)
185
+ * @since 1.0.4
186
+ *
187
+ * @param string $message
188
+ * @param string $title
189
+ * @param string $type
190
+ * @param bool $is_sticky
191
+ * @param bool $all_admin
192
+ * @param string $id Message ID
193
+ * @param bool $store_if_sticky
194
+ *
195
+ * @uses add_action()
196
+ */
197
+ function add( $message, $title = '', $type = 'success', $is_sticky = false, $all_admin = false, $id = '', $store_if_sticky = true ) {
198
+ $key = ( $all_admin ? 'all_admin_notices' : 'admin_notices' );
199
+
200
+ if ( ! isset( $this->_admin_messages[ $key ] ) ) {
201
+ $this->_admin_messages[ $key ] = array();
202
+
203
+ add_action( $key, array( &$this, "_{$key}_hook" ) );
204
+ add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_styles' ) );
205
+
206
+ }
207
+
208
+ if ( '' === $id ) {
209
+ $id = md5( $title . ' ' . $message . ' ' . $type );
210
+ }
211
+
212
+ $message_object = array(
213
+ 'message' => $message,
214
+ 'title' => $title,
215
+ 'type' => $type,
216
+ 'sticky' => $is_sticky,
217
+ 'id' => $id,
218
+ 'all' => $all_admin,
219
+ 'slug' => $this->_slug,
220
+ 'plugin' => $this->_title,
221
+ );
222
+
223
+ if ( $is_sticky && $store_if_sticky ) {
224
+ $this->_sticky_storage->{$id} = $message_object;
225
+ }
226
+
227
+ $this->_admin_messages[ $key ][ $id ] = $message_object;
228
+ }
229
+
230
+ /**
231
+ * @author Vova Feldman (@svovaf)
232
+ * @since 1.0.7
233
+ *
234
+ * @param string|string[] $ids
235
+ */
236
+ function remove_sticky( $ids ) {
237
+ if ( ! is_array( $ids ) ) {
238
+ $ids = array( $ids );
239
+ }
240
+
241
+ foreach ( $ids as $id ) {
242
+ // Remove from sticky storage.
243
+ $this->_sticky_storage->remove( $id );
244
+
245
+ // Remove from current admin messages.
246
+ if ( isset( $this->_admin_messages['all_admin_notices'] ) && isset( $this->_admin_messages['all_admin_notices'][ $id ] ) ) {
247
+ unset( $this->_admin_messages['all_admin_notices'][ $id ] );
248
+ }
249
+ if ( isset( $this->_admin_messages['admin_notices'] ) && isset( $this->_admin_messages['admin_notices'][ $id ] ) ) {
250
+ unset( $this->_admin_messages['admin_notices'][ $id ] );
251
+ }
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Check if sticky message exists by id.
257
+ *
258
+ * @author Vova Feldman (@svovaf)
259
+ * @since 1.0.9
260
+ *
261
+ * @param $id
262
+ *
263
+ * @return bool
264
+ */
265
+ function has_sticky( $id ) {
266
+ return isset( $this->_sticky_storage[ $id ] );
267
+ }
268
+
269
+ /**
270
+ * Adds sticky admin notification.
271
+ *
272
+ * @author Vova Feldman (@svovaf)
273
+ * @since 1.0.7
274
+ *
275
+ * @param string $message
276
+ * @param string $id Message ID
277
+ * @param string $title
278
+ * @param string $type
279
+ * @param bool $all_admin
280
+ */
281
+ function add_sticky( $message, $id, $title = '', $type = 'success', $all_admin = false ) {
282
+ $this->add( $message, $title, $type, true, $all_admin, $id );
283
+ }
284
+
285
+ /**
286
+ * Clear all sticky messages.
287
+ *
288
+ * @author Vova Feldman (@svovaf)
289
+ * @since 1.0.8
290
+ */
291
+ function clear_all_sticky() {
292
+ $this->_sticky_storage->clear_all();
293
+ }
294
+
295
+ /**
296
+ * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
297
+ *
298
+ * @author Vova Feldman (@svovaf)
299
+ * @since 1.0.4
300
+ *
301
+ * @param string $message
302
+ * @param string $title
303
+ * @param string $type
304
+ * @param bool $is_sticky
305
+ * @param string $id Message ID
306
+ */
307
+ function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
308
+ $this->add( $message, $title, $type, $is_sticky, true, $id );
309
+ }
310
+ }
freemius/includes/managers/class-fs-cache-manager.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Cache_Manager {
14
+ /**
15
+ * @var FS_Option_Manager
16
+ */
17
+ private $_options;
18
+ /**
19
+ * @var FS_Logger
20
+ */
21
+ private $_logger;
22
+
23
+ /**
24
+ * @var FS_Cache_Manager[]
25
+ */
26
+ private static $_MANAGERS = array();
27
+
28
+ /**
29
+ * @author Vova Feldman (@svovaf)
30
+ * @since 1.1.3
31
+ *
32
+ * @param string $id
33
+ */
34
+ private function __construct( $id ) {
35
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_cach_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
36
+
37
+ $this->_logger->entrance();
38
+ $this->_logger->log( 'id = ' . $id );
39
+
40
+ $this->_options = FS_Option_Manager::get_manager( $id, true );
41
+ }
42
+
43
+ /**
44
+ * @author Vova Feldman (@svovaf)
45
+ * @since 1.1.6
46
+ *
47
+ * @param $id
48
+ *
49
+ * @return FS_Cache_Manager
50
+ */
51
+ static function get_manager( $id ) {
52
+ $id = strtolower( $id );
53
+
54
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
55
+ self::$_MANAGERS[ $id ] = new FS_Cache_Manager( $id );
56
+ }
57
+
58
+ return self::$_MANAGERS[ $id ];
59
+ }
60
+
61
+ /**
62
+ * @author Vova Feldman (@svovaf)
63
+ * @since 1.1.6
64
+ *
65
+ * @return bool
66
+ */
67
+ function is_empty() {
68
+ $this->_logger->entrance();
69
+
70
+ return $this->_options->is_empty();
71
+ }
72
+
73
+ /**
74
+ * @author Vova Feldman (@svovaf)
75
+ * @since 1.1.6
76
+ */
77
+ function clear() {
78
+ $this->_logger->entrance();
79
+
80
+ $this->_options->clear( true );
81
+ }
82
+
83
+ /**
84
+ * Delete cache manager from DB.
85
+ *
86
+ * @author Vova Feldman (@svovaf)
87
+ * @since 1.0.9
88
+ */
89
+ function delete() {
90
+ $this->_options->delete();
91
+ }
92
+
93
+ /**
94
+ * Check if there's a cached item.
95
+ *
96
+ * @author Vova Feldman (@svovaf)
97
+ * @since 1.1.6
98
+ *
99
+ * @param string $key
100
+ *
101
+ * @return bool
102
+ */
103
+ function has( $key ) {
104
+ $cache_entry = $this->_options->get_option( $key, false );
105
+
106
+ return ( is_object( $cache_entry ) &&
107
+ isset( $cache_entry->timestamp ) &&
108
+ is_numeric( $cache_entry->timestamp )
109
+ );
110
+ }
111
+
112
+ /**
113
+ * Check if there's a valid cached item.
114
+ *
115
+ * @author Vova Feldman (@svovaf)
116
+ * @since 1.1.6
117
+ *
118
+ * @param string $key
119
+ *
120
+ * @return bool
121
+ */
122
+ function has_valid( $key ) {
123
+ $cache_entry = $this->_options->get_option( $key, false );
124
+
125
+ return ( is_object( $cache_entry ) &&
126
+ isset( $cache_entry->timestamp ) &&
127
+ is_numeric( $cache_entry->timestamp ) &&
128
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
129
+ );
130
+ }
131
+
132
+ /**
133
+ * @author Vova Feldman (@svovaf)
134
+ * @since 1.1.6
135
+ *
136
+ * @param string $key
137
+ * @param mixed $default
138
+ *
139
+ * @return mixed
140
+ */
141
+ function get( $key, $default = null ) {
142
+ $this->_logger->entrance( 'key = ' . $key );
143
+
144
+ $cache_entry = $this->_options->get_option( $key, false );
145
+
146
+ if ( is_object( $cache_entry ) &&
147
+ isset( $cache_entry->timestamp ) &&
148
+ is_numeric( $cache_entry->timestamp )
149
+ ) {
150
+ return $cache_entry->result;
151
+ }
152
+
153
+ return $default;
154
+ }
155
+
156
+ /**
157
+ * @author Vova Feldman (@svovaf)
158
+ * @since 1.1.6
159
+ *
160
+ * @param string $key
161
+ * @param mixed $default
162
+ *
163
+ * @return mixed
164
+ */
165
+ function get_valid( $key, $default = null ) {
166
+ $this->_logger->entrance( 'key = ' . $key );
167
+
168
+ $cache_entry = $this->_options->get_option( $key, false );
169
+
170
+ if ( is_object( $cache_entry ) &&
171
+ isset( $cache_entry->timestamp ) &&
172
+ is_numeric( $cache_entry->timestamp ) &&
173
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
174
+ ) {
175
+ return $cache_entry->result;
176
+ }
177
+
178
+ return $default;
179
+ }
180
+
181
+ /**
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.1.6
184
+ *
185
+ * @param string $key
186
+ * @param mixed $value
187
+ * @param int $expiration
188
+ */
189
+ function set( $key, $value, $expiration = WP_FS__TIME_24_HOURS_IN_SEC ) {
190
+ $this->_logger->entrance( 'key = ' . $key );
191
+
192
+ $cache_entry = new stdClass();
193
+ $cache_entry->result = $value;
194
+ $cache_entry->timestamp = WP_FS__SCRIPT_START_TIME + $expiration;
195
+ $this->_options->set_option( $key, $cache_entry, true );
196
+ }
197
+
198
+ /**
199
+ * Get cached record expiration, or false if not cached or expired.
200
+ *
201
+ * @author Vova Feldman (@svovaf)
202
+ * @since 1.1.7.3
203
+ *
204
+ * @param string $key
205
+ *
206
+ * @return bool|int
207
+ */
208
+ function get_record_expiration( $key ) {
209
+ $this->_logger->entrance( 'key = ' . $key );
210
+
211
+ $cache_entry = $this->_options->get_option( $key, false );
212
+
213
+ if ( is_object( $cache_entry ) &&
214
+ isset( $cache_entry->timestamp ) &&
215
+ is_numeric( $cache_entry->timestamp ) &&
216
+ $cache_entry->timestamp > WP_FS__SCRIPT_START_TIME
217
+ ) {
218
+ return $cache_entry->timestamp;
219
+ }
220
+
221
+ return false;
222
+ }
223
+
224
+ /**
225
+ * Purge cached item.
226
+ *
227
+ * @author Vova Feldman (@svovaf)
228
+ * @since 1.1.6
229
+ *
230
+ * @param string $key
231
+ */
232
+ function purge( $key ) {
233
+ $this->_logger->entrance( 'key = ' . $key );
234
+
235
+ $this->_options->unset_option( $key, true );
236
+ }
237
+ }
freemius/includes/managers/class-fs-key-value-storage.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Key_Value_Storage implements ArrayAccess, Iterator, Countable {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_id;
18
+ /**
19
+ * @var string
20
+ */
21
+ protected $_slug;
22
+ /**
23
+ * @var array
24
+ */
25
+ protected $_data;
26
+
27
+ /**
28
+ * @var FS_Plugin_Manager[]
29
+ */
30
+ private static $_instances = array();
31
+ /**
32
+ * @var FS_Logger
33
+ */
34
+ protected $_logger;
35
+
36
+ /**
37
+ * @param string $id
38
+ * @param string $slug
39
+ *
40
+ * @return FS_Key_Value_Storage
41
+ */
42
+ static function instance( $id, $slug ) {
43
+ $key = $id . ':' . $slug;
44
+ if ( ! isset( self::$_instances[ $key ] ) ) {
45
+ self::$_instances[ $key ] = new FS_Key_Value_Storage( $id, $slug );
46
+ }
47
+
48
+ return self::$_instances[ $key ];
49
+ }
50
+
51
+ protected function __construct( $id, $slug ) {
52
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
+
54
+ $this->_slug = $slug;
55
+ $this->_id = $id;
56
+ $this->load();
57
+ }
58
+
59
+ protected function get_option_manager() {
60
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
61
+ }
62
+
63
+ protected function get_all_data() {
64
+ return $this->get_option_manager()->get_option( $this->_id, array() );
65
+ }
66
+
67
+ /**
68
+ * Load plugin data from local DB.
69
+ *
70
+ * @author Vova Feldman (@svovaf)
71
+ * @since 1.0.7
72
+ */
73
+ function load() {
74
+ $all_plugins_data = $this->get_all_data();
75
+ $this->_data = isset( $all_plugins_data[ $this->_slug ] ) ?
76
+ $all_plugins_data[ $this->_slug ] :
77
+ array();
78
+ }
79
+
80
+ /**
81
+ * @author Vova Feldman (@svovaf)
82
+ * @since 1.0.7
83
+ *
84
+ * @param string $key
85
+ * @param mixed $value
86
+ * @param bool $flush
87
+ */
88
+ function store( $key, $value, $flush = true ) {
89
+ if ( $this->_logger->is_on() ) {
90
+ $this->_logger->entrance( $key . ' = ' . var_export( $value, true ) );
91
+ }
92
+
93
+ if ( array_key_exists( $key, $this->_data ) && $value === $this->_data[ $key ] ) {
94
+ // No need to store data if the value wasn't changed.
95
+ return;
96
+ }
97
+
98
+ $all_data = $this->get_all_data();
99
+
100
+ $this->_data[ $key ] = $value;
101
+
102
+ $all_data[ $this->_slug ] = $this->_data;
103
+
104
+ $options_manager = $this->get_option_manager();
105
+ $options_manager->set_option( $this->_id, $all_data, $flush );
106
+ }
107
+
108
+ /**
109
+ * @author Vova Feldman (@svovaf)
110
+ * @since 1.0.7
111
+ *
112
+ * @param bool $store
113
+ * @param string[] $exceptions Set of keys to keep and not clear.
114
+ */
115
+ function clear_all( $store = true, $exceptions = array() ) {
116
+ $new_data = array();
117
+ foreach ( $exceptions as $key ) {
118
+ if ( isset( $this->_data[ $key ] ) ) {
119
+ $new_data[ $key ] = $this->_data[ $key ];
120
+ }
121
+ }
122
+
123
+ $this->_data = $new_data;
124
+
125
+ if ( $store ) {
126
+ $all_data = $this->get_all_data();
127
+ $all_data[ $this->_slug ] = $this->_data;
128
+ $options_manager = $this->get_option_manager();
129
+ $options_manager->set_option( $this->_id, $all_data, true );
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Delete key-value storage.
135
+ *
136
+ * @author Vova Feldman (@svovaf)
137
+ * @since 1.0.9
138
+ */
139
+ function delete() {
140
+ $this->_data = array();
141
+
142
+ $all_data = $this->get_all_data();
143
+ unset( $all_data[ $this->_slug ] );
144
+ $options_manager = $this->get_option_manager();
145
+ $options_manager->set_option( $this->_id, $all_data, true );
146
+ }
147
+
148
+ /**
149
+ * @author Vova Feldman (@svovaf)
150
+ * @since 1.0.7
151
+ *
152
+ * @param string $key
153
+ * @param bool $store
154
+ */
155
+ function remove( $key, $store = true ) {
156
+ if ( ! array_key_exists( $key, $this->_data ) ) {
157
+ return;
158
+ }
159
+
160
+ unset( $this->_data[ $key ] );
161
+
162
+ if ( $store ) {
163
+ $all_data = $this->get_all_data();
164
+ $all_data[ $this->_slug ] = $this->_data;
165
+ $options_manager = $this->get_option_manager();
166
+ $options_manager->set_option( $this->_id, $all_data, true );
167
+ }
168
+ }
169
+
170
+ /**
171
+ * @author Vova Feldman (@svovaf)
172
+ * @since 1.0.7
173
+ *
174
+ * @param string $key
175
+ * @param mixed $default
176
+ *
177
+ * @return bool|\FS_Plugin
178
+ */
179
+ function get( $key, $default = false ) {
180
+ return array_key_exists( $key, $this->_data ) ?
181
+ $this->_data[ $key ] :
182
+ $default;
183
+ }
184
+
185
+
186
+ /* ArrayAccess + Magic Access (better for refactoring)
187
+ -----------------------------------------------------------------------------------*/
188
+ function __set( $k, $v ) {
189
+ $this->store( $k, $v );
190
+ }
191
+
192
+ function __isset( $k ) {
193
+ return array_key_exists( $k, $this->_data );
194
+ }
195
+
196
+ function __unset( $k ) {
197
+ $this->remove( $k );
198
+ }
199
+
200
+ function __get( $k ) {
201
+ return $this->get( $k, null );
202
+ }
203
+
204
+ function offsetSet( $k, $v ) {
205
+ if ( is_null( $k ) ) {
206
+ throw new Exception( 'Can\'t append value to request params.' );
207
+ } else {
208
+ $this->{$k} = $v;
209
+ }
210
+ }
211
+
212
+ function offsetExists( $k ) {
213
+ return array_key_exists( $k, $this->_data );
214
+ }
215
+
216
+ function offsetUnset( $k ) {
217
+ unset( $this->$k );
218
+ }
219
+
220
+ function offsetGet( $k ) {
221
+ return $this->get( $k, null );
222
+ }
223
+
224
+ /**
225
+ * (PHP 5 &gt;= 5.0.0)<br/>
226
+ * Return the current element
227
+ *
228
+ * @link http://php.net/manual/en/iterator.current.php
229
+ * @return mixed Can return any type.
230
+ */
231
+ public function current() {
232
+ return current( $this->_data );
233
+ }
234
+
235
+ /**
236
+ * (PHP 5 &gt;= 5.0.0)<br/>
237
+ * Move forward to next element
238
+ *
239
+ * @link http://php.net/manual/en/iterator.next.php
240
+ * @return void Any returned value is ignored.
241
+ */
242
+ public function next() {
243
+ next( $this->_data );
244
+ }
245
+
246
+ /**
247
+ * (PHP 5 &gt;= 5.0.0)<br/>
248
+ * Return the key of the current element
249
+ *
250
+ * @link http://php.net/manual/en/iterator.key.php
251
+ * @return mixed scalar on success, or null on failure.
252
+ */
253
+ public function key() {
254
+ return key( $this->_data );
255
+ }
256
+
257
+ /**
258
+ * (PHP 5 &gt;= 5.0.0)<br/>
259
+ * Checks if current position is valid
260
+ *
261
+ * @link http://php.net/manual/en/iterator.valid.php
262
+ * @return boolean The return value will be casted to boolean and then evaluated.
263
+ * Returns true on success or false on failure.
264
+ */
265
+ public function valid() {
266
+ $key = key( $this->_data );
267
+
268
+ return ( $key !== null && $key !== false );
269
+ }
270
+
271
+ /**
272
+ * (PHP 5 &gt;= 5.0.0)<br/>
273
+ * Rewind the Iterator to the first element
274
+ *
275
+ * @link http://php.net/manual/en/iterator.rewind.php
276
+ * @return void Any returned value is ignored.
277
+ */
278
+ public function rewind() {
279
+ reset( $this->_data );
280
+ }
281
+
282
+ /**
283
+ * (PHP 5 &gt;= 5.1.0)<br/>
284
+ * Count elements of an object
285
+ *
286
+ * @link http://php.net/manual/en/countable.count.php
287
+ * @return int The custom count as an integer.
288
+ * </p>
289
+ * <p>
290
+ * The return value is cast to an integer.
291
+ */
292
+ public function count() {
293
+ return count( $this->_data );
294
+ }
295
+ }
freemius/includes/managers/class-fs-license-manager.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_License_Manager /*extends FS_Abstract_Manager*/
14
+ {
15
+ //
16
+ //
17
+ // /**
18
+ // * @var FS_License_Manager[]
19
+ // */
20
+ // private static $_instances = array();
21
+ //
22
+ // static function instance( Freemius $fs ) {
23
+ // $slug = strtolower( $fs->get_slug() );
24
+ //
25
+ // if ( ! isset( self::$_instances[ $slug ] ) ) {
26
+ // self::$_instances[ $slug ] = new FS_License_Manager( $slug, $fs );
27
+ // }
28
+ //
29
+ // return self::$_instances[ $slug ];
30
+ // }
31
+ //
32
+ //// private function __construct($slug) {
33
+ //// parent::__construct($slug);
34
+ //// }
35
+ //
36
+ // function entry_id() {
37
+ // return 'licenses';
38
+ // }
39
+ //
40
+ // function sync( $id ) {
41
+ //
42
+ // }
43
+ //
44
+ // /**
45
+ // * @author Vova Feldman (@svovaf)
46
+ // * @since 1.0.5
47
+ // * @uses FS_Api
48
+ // *
49
+ // * @param number|bool $plugin_id
50
+ // *
51
+ // * @return FS_Plugin_License[]|stdClass Licenses or API error.
52
+ // */
53
+ // function api_get_user_plugin_licenses( $plugin_id = false ) {
54
+ // $api = $this->_fs->get_api_user_scope();
55
+ //
56
+ // if ( ! is_numeric( $plugin_id ) ) {
57
+ // $plugin_id = $this->_fs->get_id();
58
+ // }
59
+ //
60
+ // $result = $api->call( "/plugins/{$plugin_id}/licenses.json" );
61
+ //
62
+ // if ( ! isset( $result->error ) ) {
63
+ // for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
64
+ // $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
65
+ // }
66
+ //
67
+ // $result = $result->licenses;
68
+ // }
69
+ //
70
+ // return $result;
71
+ // }
72
+ //
73
+ // function api_get_many() {
74
+ //
75
+ // }
76
+ //
77
+ // function api_activate( $id ) {
78
+ //
79
+ // }
80
+ //
81
+ // function api_deactivate( $id ) {
82
+ //
83
+ // }
84
+
85
+ /**
86
+ * @param FS_Plugin_License[] $licenses
87
+ *
88
+ * @return bool
89
+ */
90
+ static function has_premium_license( $licenses ) {
91
+ if ( is_array( $licenses ) ) {
92
+ foreach ( $licenses as $license ) {
93
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
94
+ return true;
95
+ }
96
+ }
97
+ }
98
+
99
+ return false;
100
+ }
101
+ }
freemius/includes/managers/class-fs-option-manager.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * 3-layer lazy options manager.
15
+ * layer 3: Memory
16
+ * layer 2: Cache (if there's any caching plugin and if WP_FS__DEBUG_SDK is FALSE)
17
+ * layer 1: Database (options table). All options stored as one option record in the DB to reduce number of DB
18
+ * queries.
19
+ *
20
+ * If load() is not explicitly called, starts as empty manager. Same thing about saving the data - you have to
21
+ * explicitly call store().
22
+ *
23
+ * Class Freemius_Option_Manager
24
+ */
25
+ class FS_Option_Manager {
26
+ /**
27
+ * @var string
28
+ */
29
+ private $_id;
30
+ /**
31
+ * @var array
32
+ */
33
+ private $_options;
34
+ /**
35
+ * @var FS_Logger
36
+ */
37
+ private $_logger;
38
+
39
+ /**
40
+ * @var FS_Option_Manager[]
41
+ */
42
+ private static $_MANAGERS = array();
43
+
44
+ /**
45
+ * @author Vova Feldman (@svovaf)
46
+ * @since 1.0.3
47
+ *
48
+ * @param string $id
49
+ * @param bool $load
50
+ */
51
+ private function __construct( $id, $load = false ) {
52
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_opt_mngr_' . $id, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
53
+
54
+ $this->_logger->entrance();
55
+ $this->_logger->log( 'id = ' . $id );
56
+
57
+ $this->_id = $id;
58
+
59
+ if ( $load ) {
60
+ $this->load();
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @author Vova Feldman (@svovaf)
66
+ * @since 1.0.3
67
+ *
68
+ * @param $id
69
+ * @param $load
70
+ *
71
+ * @return FS_Option_Manager
72
+ */
73
+ static function get_manager( $id, $load = false ) {
74
+ $id = strtolower( $id );
75
+
76
+ if ( ! isset( self::$_MANAGERS[ $id ] ) ) {
77
+ self::$_MANAGERS[ $id ] = new FS_Option_Manager( $id, $load );
78
+ } // If load required but not yet loaded, load.
79
+ else if ( $load && ! self::$_MANAGERS[ $id ]->is_loaded() ) {
80
+ self::$_MANAGERS[ $id ]->load();
81
+ }
82
+
83
+ return self::$_MANAGERS[ $id ];
84
+ }
85
+
86
+ private function _get_option_manager_name() {
87
+ // return WP_FS__SLUG . '_' . $this->_id;
88
+ return $this->_id;
89
+ }
90
+
91
+ /**
92
+ * @author Vova Feldman (@svovaf)
93
+ * @since 1.0.3
94
+ *
95
+ * @param bool $flush
96
+ */
97
+ function load( $flush = false ) {
98
+ $this->_logger->entrance();
99
+
100
+ $option_name = $this->_get_option_manager_name();
101
+
102
+ if ( $flush || ! isset( $this->_options ) ) {
103
+ if ( isset( $this->_options ) ) {
104
+ // Clear prev options.
105
+ $this->clear();
106
+ }
107
+
108
+ if ( ! WP_FS__DEBUG_SDK ) {
109
+ $this->_options = wp_cache_get( $option_name, WP_FS__SLUG );
110
+ }
111
+
112
+ // $this->_logger->info('wp_cache_get = ' . var_export($this->_options, true));
113
+
114
+ // if ( is_array( $this->_options ) ) {
115
+ // $this->clear();
116
+ // }
117
+
118
+ $cached = true;
119
+
120
+ if ( empty( $this->_options ) ) {
121
+ $this->_options = get_option( $option_name );
122
+
123
+ if ( is_string( $this->_options ) ) {
124
+ $this->_options = json_decode( $this->_options );
125
+ }
126
+
127
+ // $this->_logger->info('get_option = ' . var_export($this->_options, true));
128
+
129
+ if ( false === $this->_options ) {
130
+ $this->clear();
131
+ }
132
+
133
+ $cached = false;
134
+ }
135
+
136
+ if ( ! WP_FS__DEBUG_SDK && ! $cached ) // Set non encoded cache.
137
+ {
138
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
139
+ }
140
+ }
141
+ }
142
+
143
+ /**
144
+ * @author Vova Feldman (@svovaf)
145
+ * @since 1.0.3
146
+ *
147
+ * @return bool
148
+ */
149
+ function is_loaded() {
150
+ return isset( $this->_options );
151
+ }
152
+
153
+ /**
154
+ * @author Vova Feldman (@svovaf)
155
+ * @since 1.0.3
156
+ *
157
+ * @return bool
158
+ */
159
+ function is_empty() {
160
+ return ( $this->is_loaded() && false === $this->_options );
161
+ }
162
+
163
+ /**
164
+ * @author Vova Feldman (@svovaf)
165
+ * @since 1.0.6
166
+ *
167
+ * @param bool $flush
168
+ */
169
+ function clear( $flush = false ) {
170
+ $this->_logger->entrance();
171
+
172
+ $this->_options = array();
173
+
174
+ if ( $flush ) {
175
+ $this->store();
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Delete options manager from DB.
181
+ *
182
+ * @author Vova Feldman (@svovaf)
183
+ * @since 1.0.9
184
+ */
185
+ function delete() {
186
+ delete_option( $this->_get_option_manager_name() );
187
+ }
188
+
189
+ /**
190
+ * @author Vova Feldman (@svovaf)
191
+ * @since 1.0.6
192
+ *
193
+ * @param string $option
194
+ *
195
+ * @return bool
196
+ */
197
+ function has_option( $option ) {
198
+ return array_key_exists( $option, $this->_options );
199
+ }
200
+
201
+ /**
202
+ * @author Vova Feldman (@svovaf)
203
+ * @since 1.0.3
204
+ *
205
+ * @param string $option
206
+ * @param mixed $default
207
+ *
208
+ * @return mixed
209
+ */
210
+ function get_option( $option, $default = null ) {
211
+ $this->_logger->entrance( 'option = ' . $option );
212
+
213
+ if ( is_array( $this->_options ) ) {
214
+ return isset( $this->_options[ $option ] ) ? $this->_options[ $option ] : $default;
215
+ } else if ( is_object( $this->_options ) ) {
216
+ return isset( $this->_options->{$option} ) ? $this->_options->{$option} : $default;
217
+ }
218
+
219
+ return $default;
220
+ }
221
+
222
+ /**
223
+ * @author Vova Feldman (@svovaf)
224
+ * @since 1.0.3
225
+ *
226
+ * @param string $option
227
+ * @param mixed $value
228
+ * @param bool $flush
229
+ */
230
+ function set_option( $option, $value, $flush = false ) {
231
+ $this->_logger->entrance( 'option = ' . $option );
232
+
233
+ if ( ! $this->is_loaded() ) {
234
+ $this->clear();
235
+ }
236
+
237
+ if ( is_array( $this->_options ) ) {
238
+ $this->_options[ $option ] = $value;
239
+ } else if ( is_object( $this->_options ) ) {
240
+ $this->_options->{$option} = $value;
241
+ }
242
+
243
+ if ( $flush ) {
244
+ $this->store();
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Unset option.
250
+ *
251
+ * @author Vova Feldman (@svovaf)
252
+ * @since 1.0.3
253
+ *
254
+ * @param string $option
255
+ * @param bool $flush
256
+ */
257
+ function unset_option( $option, $flush = false ) {
258
+ $this->_logger->entrance( 'option = ' . $option );
259
+
260
+ if ( is_array( $this->_options ) ) {
261
+ if ( ! isset( $this->_options[ $option ] ) ) {
262
+ return;
263
+ }
264
+
265
+ unset( $this->_options[ $option ] );
266
+
267
+ } else if ( is_object( $this->_options ) ) {
268
+ if ( ! isset( $this->_options->{$option} ) ) {
269
+ return;
270
+ }
271
+
272
+ unset( $this->_options->{$option} );
273
+ }
274
+
275
+ if ( $flush ) {
276
+ $this->store();
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Dump options to database.
282
+ *
283
+ * @author Vova Feldman (@svovaf)
284
+ * @since 1.0.3
285
+ */
286
+ function store() {
287
+ $this->_logger->entrance();
288
+
289
+ $option_name = $this->_get_option_manager_name();
290
+
291
+ if ( $this->_logger->is_on() ) {
292
+ $this->_logger->info( $option_name . ' = ' . var_export( $this->_options, true ) );
293
+ }
294
+
295
+ // Update DB.
296
+ update_option( $option_name, $this->_options );
297
+
298
+ if ( ! WP_FS__DEBUG_SDK ) {
299
+ wp_cache_set( $option_name, $this->_options, WP_FS__SLUG );
300
+ }
301
+ }
302
+ }
freemius/includes/managers/class-fs-plan-manager.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plan_Manager {
14
+ /**
15
+ * @var FS_Plan_Manager
16
+ */
17
+ private static $_instance;
18
+
19
+ /**
20
+ * @return FS_Plan_Manager
21
+ */
22
+ static function instance() {
23
+ if ( ! isset( self::$_instance ) ) {
24
+ self::$_instance = new FS_Plan_Manager();
25
+ }
26
+
27
+ return self::$_instance;
28
+ }
29
+
30
+ private function __construct() {
31
+ }
32
+
33
+ /**
34
+ * @param FS_Plugin_License[] $licenses
35
+ *
36
+ * @return bool
37
+ */
38
+ function has_premium_license( $licenses ) {
39
+ if ( is_array( $licenses ) ) {
40
+ /**
41
+ * @var FS_Plugin_License[] $licenses
42
+ */
43
+ foreach ( $licenses as $license ) {
44
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
45
+ return true;
46
+ }
47
+ }
48
+ }
49
+
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * Check if plugin has any paid plans.
55
+ *
56
+ * @author Vova Feldman (@svovaf)
57
+ * @since 1.0.7
58
+ *
59
+ * @param FS_Plugin_Plan[] $plans
60
+ *
61
+ * @return bool
62
+ */
63
+ function has_paid_plan( $plans ) {
64
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
65
+ return false;
66
+ }
67
+
68
+ /**
69
+ * @var FS_Plugin_Plan[] $plans
70
+ */
71
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
72
+ if ( ! $plans[ $i ]->is_free() ) {
73
+ return true;
74
+ }
75
+ }
76
+
77
+ return false;
78
+ }
79
+
80
+ /**
81
+ * Check if plugin has any free plan, or is it premium only.
82
+ *
83
+ * Note: If no plans configured, assume plugin is free.
84
+ *
85
+ * @author Vova Feldman (@svovaf)
86
+ * @since 1.0.7
87
+ *
88
+ * @param FS_Plugin_Plan[] $plans
89
+ *
90
+ * @return bool
91
+ */
92
+ function has_free_plan( $plans ) {
93
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
94
+ return true;
95
+ }
96
+
97
+ /**
98
+ * @var FS_Plugin_Plan[] $plans
99
+ */
100
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
101
+ if ( $plans[ $i ]->is_free() ) {
102
+ return true;
103
+ }
104
+ }
105
+
106
+ return false;
107
+ }
108
+
109
+ /**
110
+ * Find all plans that have trial.
111
+ *
112
+ * @author Vova Feldman (@svovaf)
113
+ * @since 1.0.9
114
+ *
115
+ * @param FS_Plugin_Plan[] $plans
116
+ *
117
+ * @return FS_Plugin_Plan[]
118
+ */
119
+ function get_trial_plans( $plans ) {
120
+ $trial_plans = array();
121
+
122
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
123
+ /**
124
+ * @var FS_Plugin_Plan[] $plans
125
+ */
126
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
127
+ if ( $plans[ $i ]->has_trial() ) {
128
+ $trial_plans[] = $plans[ $i ];
129
+ }
130
+ }
131
+ }
132
+
133
+ return $trial_plans;
134
+ }
135
+
136
+ /**
137
+ * Check if plugin has any trial plan.
138
+ *
139
+ * @author Vova Feldman (@svovaf)
140
+ * @since 1.0.9
141
+ *
142
+ * @param FS_Plugin_Plan[] $plans
143
+ *
144
+ * @return bool
145
+ */
146
+ function has_trial_plan( $plans ) {
147
+ if ( ! is_array( $plans ) || 0 === count( $plans ) ) {
148
+ return true;
149
+ }
150
+
151
+ /**
152
+ * @var FS_Plugin_Plan[] $plans
153
+ */
154
+ for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) {
155
+ if ( $plans[ $i ]->has_trial() ) {
156
+ return true;
157
+ }
158
+ }
159
+
160
+ return false;
161
+ }
162
+ }
freemius/includes/managers/class-fs-plugin-manager.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ class FS_Plugin_Manager {
14
+ /**
15
+ * @var string
16
+ */
17
+ protected $_slug;
18
+ /**
19
+ * @var FS_Plugin
20
+ */
21
+ protected $_plugin;
22
+
23
+ /**
24
+ * @var FS_Plugin_Manager[]
25
+ */
26
+ private static $_instances = array();
27
+ /**
28
+ * @var FS_Logger
29
+ */
30
+ protected $_logger;
31
+
32
+ /**
33
+ * @param string $slug
34
+ *
35
+ * @return FS_Plugin_Manager
36
+ */
37
+ static function instance( $slug ) {
38
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
39
+ self::$_instances[ $slug ] = new FS_Plugin_Manager( $slug );
40
+ }
41
+
42
+ return self::$_instances[ $slug ];
43
+ }
44
+
45
+ protected function __construct( $slug ) {
46
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug . '_' . 'plugins', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
47
+
48
+ $this->_slug = $slug;
49
+ $this->load();
50
+ }
51
+
52
+ protected function get_option_manager() {
53
+ return FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
54
+ }
55
+
56
+ protected function get_all_plugins() {
57
+ return $this->get_option_manager()->get_option( 'plugins', array() );
58
+ }
59
+
60
+ /**
61
+ * Load plugin data from local DB.
62
+ *
63
+ * @author Vova Feldman (@svovaf)
64
+ * @since 1.0.6
65
+ */
66
+ function load() {
67
+ $all_plugins = $this->get_all_plugins();
68
+ $this->_plugin = isset( $all_plugins[ $this->_slug ] ) ?
69
+ $all_plugins[ $this->_slug ] :
70
+ null;
71
+ }
72
+
73
+ /**
74
+ * Store plugin on local DB.
75
+ *
76
+ * @author Vova Feldman (@svovaf)
77
+ * @since 1.0.6
78
+ *
79
+ * @param bool|FS_Plugin $plugin
80
+ * @param bool $flush
81
+ *
82
+ * @return bool|\FS_Plugin
83
+ */
84
+ function store( $plugin = false, $flush = true ) {
85
+ $all_plugins = $this->get_all_plugins();
86
+
87
+ if ( false !== $plugin ) {
88
+ $this->_plugin = $plugin;
89
+ }
90
+
91
+ $all_plugins[ $this->_slug ] = $this->_plugin;
92
+
93
+ $options_manager = $this->get_option_manager();
94
+ $options_manager->set_option( 'plugins', $all_plugins, $flush );
95
+
96
+ return $this->_plugin;
97
+ }
98
+
99
+ /**
100
+ * Update local plugin data if different.
101
+ *
102
+ * @author Vova Feldman (@svovaf)
103
+ * @since 1.0.6
104
+ *
105
+ * @param \FS_Plugin $plugin
106
+ * @param bool $store
107
+ *
108
+ * @return bool True if plugin was updated.
109
+ */
110
+ function update( FS_Plugin $plugin, $store = true ) {
111
+ if ( ! ( $this->_plugin instanceof FS_Plugin ) ||
112
+ $this->_plugin->slug != $plugin->slug ||
113
+ $this->_plugin->public_key != $plugin->public_key ||
114
+ $this->_plugin->secret_key != $plugin->secret_key ||
115
+ $this->_plugin->parent_plugin_id != $plugin->parent_plugin_id ||
116
+ $this->_plugin->title != $plugin->title
117
+ ) {
118
+ $this->store( $plugin, $store );
119
+
120
+ return true;
121
+ }
122
+
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * @author Vova Feldman (@svovaf)
128
+ * @since 1.0.6
129
+ *
130
+ * @param FS_Plugin $plugin
131
+ * @param bool $store
132
+ */
133
+ function set( FS_Plugin $plugin, $store = false ) {
134
+ $this->_plugin = $plugin;
135
+
136
+ if ( $store ) {
137
+ $this->store();
138
+ }
139
+ }
140
+
141
+ /**
142
+ * @author Vova Feldman (@svovaf)
143
+ * @since 1.0.6
144
+ *
145
+ * @return bool|\FS_Plugin
146
+ */
147
+ function get() {
148
+ return isset( $this->_plugin ) ?
149
+ $this->_plugin :
150
+ false;
151
+ }
152
+
153
+
154
+ }
freemius/includes/sdk/Exceptions/ArgumentNotExistException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_ArgumentNotExistException extends Freemius_InvalidArgumentException { }
freemius/includes/sdk/Exceptions/EmptyArgumentException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_EmptyArgumentException extends Freemius_InvalidArgumentException { }
freemius/includes/sdk/Exceptions/Exception.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Thrown when an API call returns an exception.
4
+ *
5
+ */
6
+ class Freemius_Exception extends Exception
7
+ {
8
+ protected $_result;
9
+ protected $_type;
10
+ protected $_code;
11
+
12
+ /**
13
+ * Make a new API Exception with the given result.
14
+ *
15
+ * @param array $result The result from the API server.
16
+ */
17
+ public function __construct($result)
18
+ {
19
+ $this->_result = $result;
20
+
21
+ $code = 0;
22
+ $message = 'Unknown error, please check GetResult().';
23
+ $type = '';
24
+
25
+ if (isset($result['error']) && is_array($result['error']))
26
+ {
27
+ if (isset($result['error']['code']))
28
+ $code = $result['error']['code'];
29
+ if (isset($result['error']['message']))
30
+ $message = $result['error']['message'];
31
+ if (isset($result['error']['type']))
32
+ $type = $result['error']['type'];
33
+ }
34
+
35
+ $this->_type = $type;
36
+ $this->_code = $code;
37
+
38
+ parent::__construct($message, is_numeric($code) ? $code : 0);
39
+ }
40
+
41
+ /**
42
+ * Return the associated result object returned by the API server.
43
+ *
44
+ * @return array The result from the API server
45
+ */
46
+ public function getResult()
47
+ {
48
+ return $this->_result;
49
+ }
50
+
51
+ public function getStringCode()
52
+ {
53
+ return $this->_code;
54
+ }
55
+
56
+ public function getType()
57
+ {
58
+ return $this->_type;
59
+ }
60
+
61
+ /**
62
+ * To make debugging easier.
63
+ *
64
+ * @return string The string representation of the error
65
+ */
66
+ public function __toString()
67
+ {
68
+ $str = $this->getType() . ': ';
69
+
70
+ if ($this->code != 0)
71
+ $str .= $this->getStringCode() . ': ';
72
+
73
+ return $str . $this->getMessage();
74
+ }
75
+ }
freemius/includes/sdk/Exceptions/InvalidArgumentException.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_InvalidArgumentException extends Freemius_Exception { }
freemius/includes/sdk/Exceptions/OAuthException.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'Freemius_Exception' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class Freemius_OAuthException extends Freemius_Exception
7
+ {
8
+ public function __construct($pResult)
9
+ {
10
+ parent::__construct($pResult);
11
+ }
12
+ }
freemius/includes/sdk/Freemius.php ADDED
@@ -0,0 +1,576 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2014 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ require_once( dirname( __FILE__ ) . '/FreemiusBase.php' );
19
+
20
+ define( 'FS_SDK__USER_AGENT', 'fs-php-' . Freemius_Api_Base::VERSION );
21
+
22
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_CURL' ) ) {
23
+ define( 'FS_SDK__SIMULATE_NO_CURL', false );
24
+ }
25
+
26
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
27
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
28
+ }
29
+
30
+ if ( ! defined( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
31
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
32
+ }
33
+
34
+ define( 'FS_SDK__HAS_CURL', ! FS_SDK__SIMULATE_NO_CURL && function_exists( 'curl_version' ) );
35
+
36
+ if ( ! FS_SDK__HAS_CURL ) {
37
+ $curl_version = array( 'version' => '7.0.0' );
38
+ } else {
39
+ $curl_version = curl_version();
40
+ }
41
+
42
+ define( 'FS_API__PROTOCOL', version_compare( $curl_version['version'], '7.37', '>=' ) ? 'https' : 'http' );
43
+
44
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
45
+ define( 'FS_API__LOGGER_ON', false );
46
+ }
47
+
48
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
49
+ define( 'FS_API__ADDRESS', '://api.freemius.com' );
50
+ }
51
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
52
+ define( 'FS_API__SANDBOX_ADDRESS', '://sandbox-api.freemius.com' );
53
+ }
54
+
55
+ class Freemius_Api extends Freemius_Api_Base {
56
+ private static $_logger = array();
57
+
58
+ /**
59
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
60
+ * @param number $pID Element's id.
61
+ * @param string $pPublic Public key.
62
+ * @param string|bool $pSecret Element's secret key.
63
+ * @param bool $pSandbox Whether or not to run API in sandbox mode.
64
+ */
65
+ public function __construct( $pScope, $pID, $pPublic, $pSecret = false, $pSandbox = false ) {
66
+ // If secret key not provided, use public key encryption.
67
+ if ( is_bool( $pSecret ) ) {
68
+ $pSecret = $pPublic;
69
+ }
70
+
71
+ parent::Init( $pScope, $pID, $pPublic, $pSecret, $pSandbox );
72
+ }
73
+
74
+ public static function GetUrl( $pCanonizedPath = '', $pIsSandbox = false ) {
75
+ $address = ( $pIsSandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS );
76
+
77
+ if ( ':' === $address[0] ) {
78
+ $address = self::$_protocol . $address;
79
+ }
80
+
81
+ return $address . $pCanonizedPath;
82
+ }
83
+
84
+ #region Servers Clock Diff ------------------------------------------------------
85
+
86
+ /**
87
+ * @var int Clock diff in seconds between current server to API server.
88
+ */
89
+ private static $_clock_diff = 0;
90
+
91
+ /**
92
+ * Set clock diff for all API calls.
93
+ *
94
+ * @since 1.0.3
95
+ *
96
+ * @param $pSeconds
97
+ */
98
+ public static function SetClockDiff( $pSeconds ) {
99
+ self::$_clock_diff = $pSeconds;
100
+ }
101
+
102
+ /**
103
+ * Find clock diff between current server to API server.
104
+ *
105
+ * @since 1.0.2
106
+ * @return int Clock diff in seconds.
107
+ */
108
+ public static function FindClockDiff() {
109
+ $time = time();
110
+ $pong = self::Ping();
111
+
112
+ return ( $time - strtotime( $pong->timestamp ) );
113
+ }
114
+
115
+ #endregion Servers Clock Diff ------------------------------------------------------
116
+
117
+ /**
118
+ * @var string http or https
119
+ */
120
+ private static $_protocol = FS_API__PROTOCOL;
121
+
122
+ /**
123
+ * Set API connection protocol.
124
+ *
125
+ * @since 1.0.4
126
+ */
127
+ public static function SetHttp() {
128
+ self::$_protocol = 'http';
129
+ }
130
+
131
+ /**
132
+ * @since 1.0.4
133
+ *
134
+ * @return bool
135
+ */
136
+ public static function IsHttps() {
137
+ return ( 'https' === self::$_protocol );
138
+ }
139
+
140
+ /**
141
+ * Sign request with the following HTTP headers:
142
+ * Content-MD5: MD5(HTTP Request body)
143
+ * Date: Current date (i.e Sat, 14 Feb 2015 20:24:46 +0000)
144
+ * Authorization: FS {scope_entity_id}:{scope_entity_public_key}:base64encode(sha256(string_to_sign,
145
+ * {scope_entity_secret_key}))
146
+ *
147
+ * @param string $pResourceUrl
148
+ * @param array $pCurlOptions
149
+ *
150
+ * @return array
151
+ */
152
+ function SignRequest( $pResourceUrl, $pCurlOptions ) {
153
+ $eol = "\n";
154
+ $content_md5 = '';
155
+ $now = ( time() - self::$_clock_diff );
156
+ $date = date( 'r', $now );
157
+ $content_type = '';
158
+
159
+ if ( isset( $pCurlOptions[ CURLOPT_POST ] ) && 0 < $pCurlOptions[ CURLOPT_POST ] ) {
160
+ $content_md5 = md5( $pCurlOptions[ CURLOPT_POSTFIELDS ] );
161
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Content-MD5: ' . $content_md5;
162
+ $content_type = 'application/json';
163
+ }
164
+
165
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Date: ' . $date;
166
+
167
+ $string_to_sign = implode( $eol, array(
168
+ $pCurlOptions[ CURLOPT_CUSTOMREQUEST ],
169
+ $content_md5,
170
+ $content_type,
171
+ $date,
172
+ $pResourceUrl
173
+ ) );
174
+
175
+ // If secret and public keys are identical, it means that
176
+ // the signature uses public key hash encoding.
177
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
178
+
179
+ // Add authorization header.
180
+ $pCurlOptions[ CURLOPT_HTTPHEADER ][] = 'Authorization: ' .
181
+ $auth_type . ' ' .
182
+ $this->_id . ':' .
183
+ $this->_public . ':' .
184
+ self::Base64UrlEncode(
185
+ hash_hmac( 'sha256', $string_to_sign, $this->_secret )
186
+ );
187
+
188
+ return $pCurlOptions;
189
+ }
190
+
191
+ /**
192
+ * Get API request URL signed via query string.
193
+ *
194
+ * @param string $pPath
195
+ *
196
+ * @throws Freemius_Exception
197
+ *
198
+ * @return string
199
+ */
200
+ function GetSignedUrl( $pPath ) {
201
+ $resource = explode( '?', $this->CanonizePath( $pPath ) );
202
+ $pResourceUrl = $resource[0];
203
+
204
+ $eol = "\n";
205
+ $content_md5 = '';
206
+ $content_type = '';
207
+ $now = ( time() - self::$_clock_diff );
208
+ $date = date( 'r', $now );
209
+
210
+ $string_to_sign = implode( $eol, array(
211
+ 'GET',
212
+ $content_md5,
213
+ $content_type,
214
+ $date,
215
+ $pResourceUrl
216
+ ) );
217
+
218
+ // If secret and public keys are identical, it means that
219
+ // the signature uses public key hash encoding.
220
+ $auth_type = ( $this->_secret !== $this->_public ) ? 'FS' : 'FSP';
221
+
222
+ return Freemius_Api::GetUrl(
223
+ $pResourceUrl . '?' .
224
+ ( 1 < count( $resource ) && ! empty( $resource[1] ) ? $resource[1] . '&' : '' ) .
225
+ http_build_query( array(
226
+ 'auth_date' => $date,
227
+ 'authorization' => $auth_type . ' ' . $this->_id . ':' .
228
+ $this->_public . ':' .
229
+ self::Base64UrlEncode( hash_hmac(
230
+ 'sha256', $string_to_sign, $this->_secret
231
+ ) )
232
+ ) ), $this->_isSandbox );
233
+ }
234
+
235
+ /**
236
+ * @param resource $pCurlHandler
237
+ * @param array $pCurlOptions
238
+ *
239
+ * @return mixed
240
+ */
241
+ private static function ExecuteRequest( &$pCurlHandler, &$pCurlOptions ) {
242
+ $start = microtime( true );
243
+
244
+ $result = curl_exec( $pCurlHandler );
245
+
246
+ if ( FS_API__LOGGER_ON ) {
247
+ $end = microtime( true );
248
+
249
+ $has_body = ( isset( $pCurlOptions[ CURLOPT_POST ] ) && 0 < $pCurlOptions[ CURLOPT_POST ] );
250
+
251
+ self::$_logger[] = array(
252
+ 'id' => count( self::$_logger ),
253
+ 'start' => $start,
254
+ 'end' => $end,
255
+ 'total' => ( $end - $start ),
256
+ 'method' => $pCurlOptions[ CURLOPT_CUSTOMREQUEST ],
257
+ 'path' => $pCurlOptions[ CURLOPT_URL ],
258
+ 'body' => $has_body ? $pCurlOptions[ CURLOPT_POSTFIELDS ] : null,
259
+ 'result' => $result,
260
+ 'code' => curl_getinfo( $pCurlHandler, CURLINFO_HTTP_CODE ),
261
+ 'backtrace' => debug_backtrace(),
262
+ );
263
+ }
264
+
265
+ return $result;
266
+ }
267
+
268
+ /**
269
+ * @return array
270
+ */
271
+ static function GetLogger() {
272
+ return self::$_logger;
273
+ }
274
+
275
+ /**
276
+ * @param string $pCanonizedPath
277
+ * @param string $pMethod
278
+ * @param array $pParams
279
+ * @param null|resource $pCurlHandler
280
+ * @param bool $pIsSandbox
281
+ * @param null|callable $pBeforeExecutionFunction
282
+ *
283
+ * @return object[]|object|null
284
+ *
285
+ * @throws \Freemius_Exception
286
+ */
287
+ private static function MakeStaticRequest(
288
+ $pCanonizedPath,
289
+ $pMethod = 'GET',
290
+ $pParams = array(),
291
+ $pCurlHandler = null,
292
+ $pIsSandbox = false,
293
+ $pBeforeExecutionFunction = null
294
+ ) {
295
+ if ( ! FS_SDK__HAS_CURL ) {
296
+ self::ThrowNoCurlException();
297
+ }
298
+
299
+ // Connectivity errors simulation.
300
+ if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
301
+ self::ThrowCloudFlareDDoSException();
302
+ } else if ( FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
303
+ self::ThrowSquidAclException();
304
+ }
305
+
306
+ if ( ! $pCurlHandler ) {
307
+ $pCurlHandler = curl_init();
308
+ }
309
+
310
+ $opts = array(
311
+ CURLOPT_CONNECTTIMEOUT => 10,
312
+ CURLOPT_RETURNTRANSFER => true,
313
+ CURLOPT_TIMEOUT => 60,
314
+ CURLOPT_USERAGENT => FS_SDK__USER_AGENT,
315
+ );
316
+
317
+ if ( ! isset( $opts[ CURLOPT_HTTPHEADER ] ) || ! is_array( $opts[ CURLOPT_HTTPHEADER ] ) ) {
318
+ $opts[ CURLOPT_HTTPHEADER ] = array();
319
+ }
320
+
321
+ if ( 'POST' === $pMethod || 'PUT' === $pMethod ) {
322
+ if ( is_array( $pParams ) && 0 < count( $pParams ) ) {
323
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Content-Type: application/json';
324
+ $opts[ CURLOPT_POST ] = count( $pParams );
325
+ $opts[ CURLOPT_POSTFIELDS ] = json_encode( $pParams );
326
+ }
327
+
328
+ $opts[ CURLOPT_RETURNTRANSFER ] = true;
329
+ }
330
+
331
+ $request_url = Freemius_Api::GetUrl( $pCanonizedPath, $pIsSandbox );
332
+
333
+ $opts[ CURLOPT_URL ] = $request_url;
334
+ $opts[ CURLOPT_CUSTOMREQUEST ] = $pMethod;
335
+
336
+ $resource = explode( '?', $pCanonizedPath );
337
+
338
+ // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
339
+ // for 2 seconds if the server does not support this header.
340
+ $opts[ CURLOPT_HTTPHEADER ][] = 'Expect:';
341
+
342
+ if ( 'https' === substr( strtolower( $request_url ), 0, 5 ) ) {
343
+ $opts[ CURLOPT_SSL_VERIFYHOST ] = false;
344
+ $opts[ CURLOPT_SSL_VERIFYPEER ] = false;
345
+ }
346
+
347
+ if ( false !== $pBeforeExecutionFunction &&
348
+ is_callable( $pBeforeExecutionFunction )
349
+ ) {
350
+ $opts = call_user_func( $pBeforeExecutionFunction, $resource[0], $opts );
351
+ }
352
+
353
+ curl_setopt_array( $pCurlHandler, $opts );
354
+ $result = self::ExecuteRequest( $pCurlHandler, $opts );
355
+
356
+ /*if (curl_errno($ch) == 60) // CURLE_SSL_CACERT
357
+ {
358
+ self::errorLog('Invalid or no certificate authority found, using bundled information');
359
+ curl_setopt($ch, CURLOPT_CAINFO,
360
+ dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
361
+ $result = curl_exec($ch);
362
+ }*/
363
+
364
+ // With dual stacked DNS responses, it's possible for a server to
365
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
366
+ // the case, curl will try IPv4 first and if that fails, then it will
367
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
368
+ // operating system.
369
+ if ( false === $result && empty( $opts[ CURLOPT_IPRESOLVE ] ) ) {
370
+ $matches = array();
371
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
372
+ if ( preg_match( $regex, curl_error( $pCurlHandler ), $matches ) ) {
373
+ if ( strlen( @inet_pton( $matches[1] ) ) === 16 ) {
374
+ // self::errorLog('Invalid IPv6 configuration on server, Please disable or get native IPv6 on your server.');
375
+ $opts[ CURLOPT_IPRESOLVE ] = CURL_IPRESOLVE_V4;
376
+ curl_setopt( $pCurlHandler, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
377
+ $result = self::ExecuteRequest( $pCurlHandler, $opts );
378
+ }
379
+ }
380
+ }
381
+
382
+ if ( $result === false ) {
383
+ self::ThrowCurlException( $pCurlHandler );
384
+ }
385
+
386
+ curl_close( $pCurlHandler );
387
+
388
+ if ( empty( $result ) ) {
389
+ return null;
390
+ }
391
+
392
+ $decoded = json_decode( $result );
393
+
394
+ if ( is_null( $decoded ) ) {
395
+ if ( preg_match( '/Please turn JavaScript on/i', $result ) &&
396
+ preg_match( '/text\/javascript/', $result )
397
+ ) {
398
+ self::ThrowCloudFlareDDoSException( $result );
399
+ } else if ( preg_match( '/Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect./', $result ) &&
400
+ preg_match( '/squid/', $result )
401
+ ) {
402
+ self::ThrowSquidAclException( $result );
403
+ } else {
404
+ $decoded = (object) array(
405
+ 'error' => (object) array(
406
+ 'type' => 'Unknown',
407
+ 'message' => $result,
408
+ 'code' => 'unknown',
409
+ 'http' => 402
410
+ )
411
+ );
412
+ }
413
+ }
414
+
415
+ return $decoded;
416
+ }
417
+
418
+
419
+ /**
420
+ * Makes an HTTP request. This method can be overridden by subclasses if
421
+ * developers want to do fancier things or use something other than curl to
422
+ * make the request.
423
+ *
424
+ * @param string $pCanonizedPath The URL to make the request to
425
+ * @param string $pMethod HTTP method
426
+ * @param array $pParams The parameters to use for the POST body
427
+ * @param null|resource $pCurlHandler Initialized curl handle
428
+ *
429
+ * @return object[]|object|null
430
+ *
431
+ * @throws Freemius_Exception
432
+ */
433
+ public function MakeRequest(
434
+ $pCanonizedPath,
435
+ $pMethod = 'GET',
436
+ $pParams = array(),
437
+ $pCurlHandler = null
438
+ ) {
439
+ $resource = explode( '?', $pCanonizedPath );
440
+
441
+ // Only sign request if not ping.json connectivity test.
442
+ $sign_request = ( '/v1/ping.json' !== strtolower( substr( $resource[0], - strlen( '/v1/ping.json' ) ) ) );
443
+
444
+ return self::MakeStaticRequest(
445
+ $pCanonizedPath,
446
+ $pMethod,
447
+ $pParams,
448
+ $pCurlHandler,
449
+ $this->_isSandbox,
450
+ $sign_request ? array( &$this, 'SignRequest' ) : null
451
+ );
452
+ }
453
+
454
+ #region Connectivity Test ------------------------------------------------------
455
+
456
+ /**
457
+ * If successful connectivity to the API endpoint using ping.json endpoint.
458
+ *
459
+ * - OR -
460
+ *
461
+ * Validate if ping result object is valid.
462
+ *
463
+ * @param mixed $pPong
464
+ *
465
+ * @return bool
466
+ */
467
+ public static function Test( $pPong = null ) {
468
+ $pong = is_null( $pPong ) ?
469
+ self::Ping() :
470
+ $pPong;
471
+
472
+ return (
473
+ is_object( $pong ) &&
474
+ isset( $pong->api ) &&
475
+ 'pong' === $pong->api
476
+ );
477
+ }
478
+
479
+ /**
480
+ * Ping API to test connectivity.
481
+ *
482
+ * @return object
483
+ */
484
+ public static function Ping() {
485
+ try {
486
+ $result = self::MakeStaticRequest( '/v' . FS_API__VERSION . '/ping.json' );
487
+ } catch ( Freemius_Exception $e ) {
488
+ // Map to error object.
489
+ $result = (object) $e->getResult();
490
+ } catch ( Exception $e ) {
491
+ // Map to error object.
492
+ $result = (object) array(
493
+ 'error' => array(
494
+ 'type' => 'Unknown',
495
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
496
+ 'code' => 'unknown',
497
+ 'http' => 402
498
+ )
499
+ );
500
+ }
501
+
502
+ return $result;
503
+ }
504
+
505
+ #endregion Connectivity Test ------------------------------------------------------
506
+
507
+ #region Connectivity Exceptions ------------------------------------------------------
508
+
509
+ /**
510
+ * @param resource $pCurlHandler
511
+ *
512
+ * @throws Freemius_Exception
513
+ */
514
+ private static function ThrowCurlException( $pCurlHandler ) {
515
+ $e = new Freemius_Exception( array(
516
+ 'error' => array(
517
+ 'code' => curl_errno( $pCurlHandler ),
518
+ 'message' => curl_error( $pCurlHandler ),
519
+ 'type' => 'CurlException',
520
+ ),
521
+ ) );
522
+
523
+ curl_close( $pCurlHandler );
524
+ throw $e;
525
+ }
526
+
527
+ /**
528
+ * @param string $pResult
529
+ *
530
+ * @throws Freemius_Exception
531
+ */
532
+ private static function ThrowNoCurlException( $pResult = '' ) {
533
+ throw new Freemius_Exception( array(
534
+ 'error' => (object) array(
535
+ 'type' => 'cUrlMissing',
536
+ 'message' => $pResult,
537
+ 'code' => 'curl_missing',
538
+ 'http' => 402
539
+ )
540
+ ) );
541
+ }
542
+
543
+ /**
544
+ * @param string $pResult
545
+ *
546
+ * @throws Freemius_Exception
547
+ */
548
+ private static function ThrowCloudFlareDDoSException( $pResult = '' ) {
549
+ throw new Freemius_Exception( array(
550
+ 'error' => (object) array(
551
+ 'type' => 'CloudFlareDDoSProtection',
552
+ 'message' => $pResult,
553
+ 'code' => 'cloudflare_ddos_protection',
554
+ 'http' => 402
555
+ )
556
+ ) );
557
+ }
558
+
559
+ /**
560
+ * @param string $pResult
561
+ *
562
+ * @throws Freemius_Exception
563
+ */
564
+ private static function ThrowSquidAclException( $pResult = '' ) {
565
+ throw new Freemius_Exception( array(
566
+ 'error' => (object) array(
567
+ 'type' => 'SquidCacheBlock',
568
+ 'message' => $pResult,
569
+ 'code' => 'squid_cache_block',
570
+ 'http' => 402
571
+ )
572
+ ) );
573
+ }
574
+
575
+ #endregion Connectivity Exceptions ------------------------------------------------------
576
+ }
freemius/includes/sdk/FreemiusBase.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright 2014 Freemius, Inc.
4
+ *
5
+ * Licensed under the GPL v2 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://choosealicense.com/licenses/gpl-v2/
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ define( 'FS_API__VERSION', '1' );
19
+ define( 'FS_SDK__PATH', dirname( __FILE__ ) );
20
+ define( 'FS_SDK__EXCEPTIONS_PATH', FS_SDK__PATH . '/Exceptions/' );
21
+
22
+ if ( ! function_exists( 'json_decode' ) ) {
23
+ throw new Exception( 'Freemius needs the JSON PHP extension.' );
24
+ }
25
+
26
+ // Include all exception files.
27
+ $exceptions = array(
28
+ 'Exception',
29
+ 'InvalidArgumentException',
30
+ 'ArgumentNotExistException',
31
+ 'EmptyArgumentException',
32
+ 'OAuthException'
33
+ );
34
+
35
+ foreach ( $exceptions as $e ) {
36
+ require_once FS_SDK__EXCEPTIONS_PATH . $e . '.php';
37
+ }
38
+
39
+ abstract class Freemius_Api_Base {
40
+ const VERSION = '1.0.4';
41
+ const FORMAT = 'json';
42
+
43
+ protected $_id;
44
+ protected $_public;
45
+ protected $_secret;
46
+ protected $_scope;
47
+ protected $_isSandbox;
48
+
49
+ /**
50
+ * @param string $pScope 'app', 'developer', 'user' or 'install'.
51
+ * @param number $pID Element's id.
52
+ * @param string $pPublic Public key.
53
+ * @param string $pSecret Element's secret key.
54
+ * @param bool $pIsSandbox Whether or not to run API in sandbox mode.
55
+ */
56
+ public function Init( $pScope, $pID, $pPublic, $pSecret, $pIsSandbox = false ) {
57
+ $this->_id = $pID;
58
+ $this->_public = $pPublic;
59
+ $this->_secret = $pSecret;
60
+ $this->_scope = $pScope;
61
+ $this->_isSandbox = $pIsSandbox;
62
+ }
63
+
64
+ public function IsSandbox() {
65
+ return $this->_isSandbox;
66
+ }
67
+
68
+ function CanonizePath( $pPath ) {
69
+ $pPath = trim( $pPath, '/' );
70
+ $query_pos = strpos( $pPath, '?' );
71
+ $query = '';
72
+
73
+ if ( false !== $query_pos ) {
74
+ $query = substr( $pPath, $query_pos );
75
+ $pPath = substr( $pPath, 0, $query_pos );
76
+ }
77
+
78
+ // Trim '.json' suffix.
79
+ $format_length = strlen( '.' . self::FORMAT );
80
+ $start = $format_length * ( - 1 ); //negative
81
+ if ( substr( strtolower( $pPath ), $start ) === ( '.' . self::FORMAT ) ) {
82
+ $pPath = substr( $pPath, 0, strlen( $pPath ) - $format_length );
83
+ }
84
+
85
+ switch ( $this->_scope ) {
86
+ case 'app':
87
+ $base = '/apps/' . $this->_id;
88
+ break;
89
+ case 'developer':
90
+ $base = '/developers/' . $this->_id;
91
+ break;
92
+ case 'user':
93
+ $base = '/users/' . $this->_id;
94
+ break;
95
+ case 'plugin':
96
+ $base = '/plugins/' . $this->_id;
97
+ break;
98
+ case 'install':
99
+ $base = '/installs/' . $this->_id;
100
+ break;
101
+ default:
102
+ throw new Freemius_Exception( 'Scope not implemented.' );
103
+ }
104
+
105
+ return '/v' . FS_API__VERSION . $base .
106
+ ( ! empty( $pPath ) ? '/' : '' ) . $pPath .
107
+ ( ( false === strpos( $pPath, '.' ) ) ? '.' . self::FORMAT : '' ) . $query;
108
+ }
109
+
110
+ abstract function MakeRequest( $pCanonizedPath, $pMethod = 'GET', $pParams = array() );
111
+
112
+ /**
113
+ * @param string $pPath
114
+ * @param string $pMethod
115
+ * @param array $pParams
116
+ *
117
+ * @return object[]|object|null
118
+ */
119
+ private function _Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
120
+ $pMethod = strtoupper( $pMethod );
121
+
122
+ try {
123
+ $result = $this->MakeRequest( $pPath, $pMethod, $pParams );
124
+ } catch ( Freemius_Exception $e ) {
125
+ // Map to error object.
126
+ $result = (object) $e->getResult();
127
+ } catch ( Exception $e ) {
128
+ // Map to error object.
129
+ $result = (object) array(
130
+ 'error' => array(
131
+ 'type' => 'Unknown',
132
+ 'message' => $e->getMessage() . ' (' . $e->getFile() . ': ' . $e->getLine() . ')',
133
+ 'code' => 'unknown',
134
+ 'http' => 402
135
+ )
136
+ );
137
+ }
138
+
139
+ return $result;
140
+ }
141
+
142
+ public function Api( $pPath, $pMethod = 'GET', $pParams = array() ) {
143
+ return $this->_Api( $this->CanonizePath( $pPath ), $pMethod, $pParams );
144
+ }
145
+
146
+ /**
147
+ * Base64 encoding that does not need to be urlencode()ed.
148
+ * Exactly the same as base64_encode except it uses
149
+ * - instead of +
150
+ * _ instead of /
151
+ * No padded =
152
+ *
153
+ * @param string $input base64UrlEncoded string
154
+ *
155
+ * @return string
156
+ */
157
+ protected static function Base64UrlDecode( $input ) {
158
+ return base64_decode( strtr( $input, '-_', '+/' ) );
159
+ }
160
+
161
+ /**
162
+ * Base64 encoding that does not need to be urlencode()ed.
163
+ * Exactly the same as base64_encode except it uses
164
+ * - instead of +
165
+ * _ instead of /
166
+ *
167
+ * @param string $input string
168
+ *
169
+ * @return string base64Url encoded string
170
+ */
171
+ protected static function Base64UrlEncode( $input ) {
172
+ $str = strtr( base64_encode( $input ), '+/', '-_' );
173
+ $str = str_replace( '=', '', $str );
174
+
175
+ return $str;
176
+ }
177
+
178
+ }
freemius/includes/sdk/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
340
+
freemius/includes/supplements/fs-essential-functions-1.1.7.1.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Find the plugin main file path based on any give file inside the plugin's folder.
15
+ *
16
+ * @author Vova Feldman (@svovaf)
17
+ * @since 1.1.7.1
18
+ *
19
+ * @param string $file Absolute path to a file inside a plugin's folder.
20
+ *
21
+ * @return string
22
+ */
23
+ function fs_find_direct_caller_plugin_file( $file ) {
24
+ /**
25
+ * All the code below will be executed once on activation.
26
+ * If the user changes the main plugin's file name, the file_exists()
27
+ * will catch it.
28
+ */
29
+ if ( ! function_exists( 'get_plugins' ) ) {
30
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
31
+ }
32
+
33
+ $all_plugins = get_plugins();
34
+
35
+ $file_real_path = fs_normalize_path( realpath( $file ) );
36
+
37
+ // Get active plugin's main files real full names (might be symlinks).
38
+ foreach ( $all_plugins as $relative_path => &$data ) {
39
+ if ( 0 === strpos( $file_real_path, fs_normalize_path( dirname( realpath( WP_PLUGIN_DIR . '/' . $relative_path ) ) ) ) ) {
40
+ return $relative_path;
41
+ }
42
+ }
43
+
44
+ return null;
45
+ }
freemius/start.php ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * Freemius SDK Version.
15
+ *
16
+ * @var string
17
+ */
18
+ $this_sdk_version = '1.1.9';
19
+
20
+ #region SDK Selection Logic --------------------------------------------------------------------
21
+
22
+ /**
23
+ * Special logic added on 1.1.6 to make sure that every Freemius powered plugin
24
+ * will ALWAYS be loaded with the newest SDK from the active Freemius powered plugins.
25
+ *
26
+ * Since Freemius SDK is backward compatible, this will make sure that all Freemius powered
27
+ * plugins will run correctly.
28
+ *
29
+ * @since 1.1.6
30
+ */
31
+
32
+ global $fs_active_plugins;
33
+
34
+ $this_sdk_relative_path = plugin_basename( dirname( __FILE__ ) );
35
+
36
+ if ( ! isset( $fs_active_plugins ) ) {
37
+ // Require SDK essentials.
38
+ require_once dirname( __FILE__ ) . '/includes/fs-essential-functions.php';
39
+
40
+ // Load all Freemius powered active plugins.
41
+ $fs_active_plugins = get_option( 'fs_active_plugins', new stdClass() );
42
+
43
+ if ( ! isset( $fs_active_plugins->plugins ) ) {
44
+ $fs_active_plugins->plugins = array();
45
+ }
46
+ }
47
+
48
+ if ( ! function_exists( 'fs_find_direct_caller_plugin_file' ) ) {
49
+ require_once dirname( __FILE__ ) . '/includes/supplements/fs-essential-functions-1.1.7.1.php';
50
+ }
51
+
52
+ // Update current SDK info based on the SDK path.
53
+ if ( ! isset( $fs_active_plugins->plugins[ $this_sdk_relative_path ] ) ||
54
+ $this_sdk_version != $fs_active_plugins->plugins[ $this_sdk_relative_path ]->version
55
+ ) {
56
+ $fs_active_plugins->plugins[ $this_sdk_relative_path ] = (object) array(
57
+ 'version' => $this_sdk_version,
58
+ 'timestamp' => time(),
59
+ 'plugin_path' => plugin_basename( fs_find_direct_caller_plugin_file( __FILE__ ) ),
60
+ );
61
+ }
62
+
63
+ $is_current_sdk_newest = isset( $fs_active_plugins->newest ) && ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path );
64
+
65
+ if ( ! isset( $fs_active_plugins->newest ) ) {
66
+ /**
67
+ * This will be executed only once, for the first time a Freemius powered plugin is activated.
68
+ */
69
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
70
+
71
+ $is_current_sdk_newest = true;
72
+ } else if ( version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '<' ) ) {
73
+ /**
74
+ * Current SDK is newer than the newest stored SDK.
75
+ */
76
+ fs_update_sdk_newest_version( $this_sdk_relative_path, $fs_active_plugins->plugins[ $this_sdk_relative_path ]->plugin_path );
77
+
78
+ if ( class_exists( 'Freemius' ) ) {
79
+ // Older SDK version was already loaded.
80
+
81
+ if ( ! $fs_active_plugins->newest->in_activation ) {
82
+ // Re-order plugins to load this plugin first.
83
+ fs_newest_sdk_plugin_first();
84
+ }
85
+
86
+ // Refresh page.
87
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
88
+ exit();
89
+ }
90
+ }
91
+ } else {
92
+ if ( ! function_exists( 'get_plugins' ) ) {
93
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
94
+ }
95
+
96
+ $is_newest_sdk_plugin_activate = is_plugin_active( $fs_active_plugins->newest->plugin_path );
97
+
98
+ if ( $is_current_sdk_newest &&
99
+ ! $is_newest_sdk_plugin_activate &&
100
+ ! $fs_active_plugins->newest->in_activation
101
+ ) {
102
+ // If current SDK is the newest and the plugin is NOT active, it means
103
+ // that the current plugin in activation mode.
104
+ $fs_active_plugins->newest->in_activation = true;
105
+ update_option( 'fs_active_plugins', $fs_active_plugins );
106
+ }
107
+
108
+ $is_newest_sdk_path_valid = ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) && file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this_sdk_relative_path . '/start.php' ) );
109
+
110
+ if ( ! $is_newest_sdk_path_valid && ! $is_current_sdk_newest ) {
111
+ // Plugin with newest SDK is no longer active, or SDK was moved to a different location.
112
+ unset( $fs_active_plugins->plugins[ $fs_active_plugins->newest->sdk_path ] );
113
+ }
114
+
115
+ if ( ! ( $is_newest_sdk_plugin_activate || $fs_active_plugins->newest->in_activation ) ||
116
+ ! $is_newest_sdk_path_valid ||
117
+ // Is newest SDK downgraded.
118
+ ( $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
119
+ version_compare( $fs_active_plugins->newest->version, $this_sdk_version, '>' ) )
120
+ ) {
121
+ /**
122
+ * Plugin with newest SDK is no longer active.
123
+ * OR
124
+ * The newest SDK was in the current plugin. BUT, seems like the version of
125
+ * the SDK was downgraded to a lower SDK.
126
+ */
127
+ // Find the active plugin with the newest SDK version and update the newest reference.
128
+ fs_fallback_to_newest_active_sdk();
129
+ } else {
130
+ if ( $is_newest_sdk_plugin_activate &&
131
+ $this_sdk_relative_path == $fs_active_plugins->newest->sdk_path &&
132
+ ( $fs_active_plugins->newest->in_activation ||
133
+ ( class_exists( 'Freemius' ) && ( ! defined( 'WP_FS__SDK_VERSION' ) || version_compare( WP_FS__SDK_VERSION, $this_sdk_version, '<' ) ) )
134
+ )
135
+
136
+ ) {
137
+ if ( $fs_active_plugins->newest->in_activation ) {
138
+ // Plugin no more in activation.
139
+ $fs_active_plugins->newest->in_activation = false;
140
+ update_option( 'fs_active_plugins', $fs_active_plugins );
141
+ }
142
+
143
+ // Reorder plugins to load plugin with newest SDK first.
144
+ if ( fs_newest_sdk_plugin_first() ) {
145
+ // Refresh page after re-order to make sure activated plugin loads newest SDK.
146
+ if ( class_exists( 'Freemius' ) ) {
147
+ if ( fs_redirect( $_SERVER['REQUEST_URI'] ) ) {
148
+ exit();
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ if ( class_exists( 'Freemius' ) ) {
157
+ // SDK was already loaded.
158
+ return;
159
+ }
160
+
161
+ if ( version_compare( $this_sdk_version, $fs_active_plugins->newest->version, '<' ) ) {
162
+ $newest_sdk_starter = fs_normalize_path( WP_PLUGIN_DIR . '/' . $fs_active_plugins->newest->sdk_path . '/start.php' );
163
+
164
+ if ( file_exists( $newest_sdk_starter ) ) {
165
+ // Reorder plugins to load plugin with newest SDK first.
166
+ fs_newest_sdk_plugin_first();
167
+
168
+ // There's a newer SDK version, load it instead of the current one!
169
+ require_once $newest_sdk_starter;
170
+
171
+ return;
172
+ }
173
+ }
174
+
175
+ #endregion SDK Selection Logic --------------------------------------------------------------------
176
+
177
+ #region Hooks & Filters Collection --------------------------------------------------------------------
178
+
179
+ /**
180
+ * Freemius hooks (actions & filters) tags structure:
181
+ *
182
+ * fs_{filter/action_name}_{plugin_slug}
183
+ *
184
+ * --------------------------------------------------------
185
+ *
186
+ * Usage with WordPress' add_action() / add_filter():
187
+ *
188
+ * add_action('fs_{filter/action_name}_{plugin_slug}', $callable);
189
+ *
190
+ * --------------------------------------------------------
191
+ *
192
+ * Usage with Freemius' instance add_action() / add_filter():
193
+ *
194
+ * // No need to add 'fs_' prefix nor '_{plugin_slug}' suffix.
195
+ * my_freemius()->add_action('{action_name}', $callable);
196
+ *
197
+ * --------------------------------------------------------
198
+ *
199
+ * Freemius filters collection:
200
+ *
201
+ * fs_connect_url_{plugin_slug}
202
+ * fs_trial_promotion_message_{plugin_slug}
203
+ * fs_is_long_term_user_{plugin_slug}
204
+ * fs_uninstall_reasons_{plugin_slug}
205
+ * fs_is_plugin_update_{plugin_slug}
206
+ * fs_api_domains_{plugin_slug}
207
+ * fs_email_template_sections_{plugin_slug}
208
+ * fs_support_forum_submenu_{plugin_slug}
209
+ * fs_support_forum_url_{plugin_slug}
210
+ * fs_connect_message_{plugin_slug}
211
+ * fs_connect_message_on_update_{plugin_slug}
212
+ * fs_uninstall_confirmation_message_{plugin_slug}
213
+ * fs_pending_activation_message_{plugin_slug}
214
+ * fs_is_submenu_visible_{plugin_slug}
215
+ * fs_plugin_icon_{plugin_slug}
216
+ * fs_show_trial_{plugin_slug}
217
+ *
218
+ * --------------------------------------------------------
219
+ *
220
+ * Freemius actions collection:
221
+ *
222
+ * fs_after_license_loaded_{plugin_slug}
223
+ * fs_after_license_change_{plugin_slug}
224
+ * fs_after_plans_sync_{plugin_slug}
225
+ *
226
+ * fs_after_account_details_{plugin_slug}
227
+ * fs_after_account_user_sync_{plugin_slug}
228
+ * fs_after_account_plan_sync_{plugin_slug}
229
+ * fs_before_account_load_{plugin_slug}
230
+ * fs_after_account_connection_{plugin_slug}
231
+ * fs_account_property_edit_{plugin_slug}
232
+ * fs_account_email_verified_{plugin_slug}
233
+ * fs_account_page_load_before_departure_{plugin_slug}
234
+ * fs_before_account_delete_{plugin_slug}
235
+ * fs_after_account_delete_{plugin_slug}
236
+ *
237
+ * fs_sdk_version_update_{plugin_slug}
238
+ * fs_plugin_version_update_{plugin_slug}
239
+ *
240
+ * fs_initiated_{plugin_slug}
241
+ * fs_after_init_plugin_registered_{plugin_slug}
242
+ * fs_after_init_plugin_anonymous_{plugin_slug}
243
+ * fs_after_init_plugin_pending_activations_{plugin_slug}
244
+ * fs_after_init_addon_registered_{plugin_slug}
245
+ * fs_after_init_addon_anonymous_{plugin_slug}
246
+ * fs_after_init_addon_pending_activations_{plugin_slug}
247
+ *
248
+ * fs_after_premium_version_activation_{plugin_slug}
249
+ * fs_after_free_version_reactivation_{plugin_slug}
250
+ *
251
+ * fs_after_uninstall_{plugin_slug}
252
+ * fs_before_admin_menu_init_{plugin_slug}
253
+ */
254
+
255
+ #endregion Hooks & Filters Collection --------------------------------------------------------------------
256
+
257
+ if ( ! class_exists( 'Freemius' ) ) {
258
+
259
+ if ( ! defined( 'WP_FS__SDK_VERSION' ) ) {
260
+ define( 'WP_FS__SDK_VERSION', $this_sdk_version );
261
+ }
262
+
263
+ // Configuration should be loaded first.
264
+ require_once dirname( __FILE__ ) . '/config.php';
265
+
266
+ // Logger must be loaded before any other.
267
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-logger.php';
268
+ require_once WP_FS__DIR_INCLUDES . '/debug/debug-bar-start.php';
269
+
270
+ require_once WP_FS__DIR_INCLUDES . '/fs-core-functions.php';
271
+ // require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-abstract-manager.php';
272
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-option-manager.php';
273
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-cache-manager.php';
274
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-notice-manager.php';
275
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-admin-menu-manager.php';
276
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-key-value-storage.php';
277
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-license-manager.php';
278
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plan-manager.php';
279
+ require_once WP_FS__DIR_INCLUDES . '/managers/class-fs-plugin-manager.php';
280
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-entity.php';
281
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-scope-entity.php';
282
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-user.php';
283
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-site.php';
284
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin.php';
285
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-info.php';
286
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-tag.php';
287
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-plan.php';
288
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-pricing.php';
289
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-plugin-license.php';
290
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-subscription.php';
291
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-api.php';
292
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-plugin-updater.php';
293
+ require_once WP_FS__DIR_INCLUDES . '/class-fs-security.php';
294
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius-abstract.php';
295
+ require_once WP_FS__DIR_INCLUDES . '/sdk/Exceptions/Exception.php';
296
+ require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';
297
+
298
+ /**
299
+ * Quick shortcut to get Freemius for specified plugin.
300
+ * Used by various templates.
301
+ *
302
+ * @param string $slug
303
+ *
304
+ * @return Freemius
305
+ */
306
+ function freemius( $slug ) {
307
+ return Freemius::instance( $slug );
308
+ }
309
+
310
+ /**
311
+ * @param string $slug
312
+ * @param number $plugin_id
313
+ * @param string $public_key
314
+ * @param bool $is_live Is live or test plugin.
315
+ * @param bool $is_premium Hints freemius if running the premium plugin or not.
316
+ *
317
+ * @return Freemius
318
+ */
319
+ function fs_init( $slug, $plugin_id, $public_key, $is_live = true, $is_premium = true ) {
320
+ $fs = Freemius::instance( $slug );
321
+ $fs->init( $plugin_id, $public_key, $is_live, $is_premium );
322
+
323
+ return $fs;
324
+ }
325
+
326
+ /**
327
+ * @param array [string]string $plugin
328
+ *
329
+ * @return Freemius
330
+ * @throws Freemius_Exception
331
+ */
332
+ function fs_dynamic_init( $plugin ) {
333
+ $fs = Freemius::instance( $plugin['slug'] );
334
+ $fs->dynamic_init( $plugin );
335
+
336
+ return $fs;
337
+ }
338
+
339
+ function fs_dump_log() {
340
+ FS_Logger::dump();
341
+ }
342
+ }
freemius/templates/account.php ADDED
@@ -0,0 +1,625 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ /**
15
+ * @var Freemius $fs
16
+ */
17
+ $fs = freemius( $slug );
18
+
19
+ /**
20
+ * @var FS_Plugin_Tag $update
21
+ */
22
+ $update = $fs->get_update( false, false );
23
+
24
+ $is_paying = $fs->is_paying();
25
+ $user = $fs->get_user();
26
+ $site = $fs->get_site();
27
+ $name = $user->get_name();
28
+ $license = $fs->_get_license();
29
+ $subscription = $fs->_get_subscription();
30
+ $plan = $fs->get_plan();
31
+ $is_active_subscription = ( is_object( $subscription ) && $subscription->is_active() );
32
+ $is_paid_trial = $fs->is_paid_trial();
33
+ $show_upgrade = ( ! $is_paying && ! $is_paid_trial );
34
+ ?>
35
+
36
+ <div class="wrap">
37
+ <h2 class="nav-tab-wrapper">
38
+ <a href="<?php $fs->get_account_url() ?>" class="nav-tab nav-tab-active"><?php _efs( 'account', $slug ) ?></a>
39
+ <?php if ( $fs->has_addons() ) : ?>
40
+ <a href="<?php echo $fs->_get_admin_page_url( 'addons' ) ?>"
41
+ class="nav-tab"><?php _efs( 'add-ons', $slug ) ?></a>
42
+ <?php endif ?>
43
+ <?php if ( $fs->is_not_paying() && $fs->has_paid_plan() ) : ?>
44
+ <a href="<?php echo $fs->get_upgrade_url() ?>" class="nav-tab"><?php _efs( 'upgrade', $slug ) ?></a>
45
+ <?php if ( $fs->apply_filters( 'show_trial', true ) && ! $fs->is_trial_utilized() && $fs->has_trial_plan() ) : ?>
46
+ <a href="<?php echo $fs->get_trial_url() ?>" class="nav-tab"><?php _efs( 'free-trial', $slug ) ?></a>
47
+ <?php endif ?>
48
+ <?php endif ?>
49
+ </h2>
50
+
51
+ <div id="poststuff">
52
+ <div id="fs_account">
53
+ <div class="has-sidebar has-right-sidebar">
54
+ <div class="has-sidebar-content">
55
+ <div class="postbox">
56
+ <h3><?php _efs('account-details', $slug) ?></h3>
57
+
58
+ <div class="fs-header-actions">
59
+ <ul>
60
+ <li>
61
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
62
+ <input type="hidden" name="fs_action" value="delete_account">
63
+ <?php wp_nonce_field('delete_account') ?>
64
+ <a href="#" onclick="if (confirm('<?php
65
+ if ($is_active_subscription) {
66
+ echo esc_attr(sprintf(__fs('delete-account-x-confirm', $slug), $plan->title));
67
+ } else {
68
+ _efs('delete-account-confirm', $slug);
69
+ }
70
+ ?>')) this.parentNode.submit(); return false;"><i
71
+ class="dashicons dashicons-no"></i> <?php _efs('delete-account', $slug) ?></a>
72
+ </form>
73
+ </li>
74
+ <?php if ($is_paying) : ?>
75
+ <li>
76
+ &nbsp;•&nbsp;
77
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
78
+ <input type="hidden" name="fs_action" value="deactivate_license">
79
+ <?php wp_nonce_field('deactivate_license') ?>
80
+ <a href="#"
81
+ onclick="if (confirm('<?php _efs('deactivate-license-confirm', $slug) ?>')) this.parentNode.submit(); return false;"><i
82
+ class="dashicons dashicons-admin-network"></i> <?php _efs('deactivate-license', $slug) ?>
83
+ </a>
84
+ </form>
85
+ </li>
86
+ <?php if (! $license->is_lifetime() &&
87
+ $is_active_subscription
88
+ ) : ?>
89
+ <li>
90
+ &nbsp;•&nbsp;
91
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
92
+ <input type="hidden" name="fs_action" value="downgrade_account">
93
+ <?php wp_nonce_field('downgrade_account') ?>
94
+ <a href="#"
95
+ onclick="if (confirm('<?php printf(__fs('downgrade-x-confirm', $slug), $plan->title, human_time_diff(time(), strtotime($license->expiration))) ?> <?php if (! $license->is_block_features) {
96
+ printf(__fs('after-downgrade-non-blocking', $slug), $plan->title);
97
+ } else {
98
+ printf(__fs('after-downgrade-blocking', $slug), $plan->title);
99
+ }?> <?php _efs('proceed-confirmation', $slug) ?>')) this.parentNode.submit(); return false;"><i
100
+ class="dashicons dashicons-download"></i> <?php _efs('downgrade', $slug) ?></a>
101
+ </form>
102
+ </li>
103
+ <?php endif ?>
104
+ <li>
105
+ &nbsp;•&nbsp;
106
+ <a href="<?php echo $fs->get_upgrade_url() ?>"><i
107
+ class="dashicons dashicons-grid-view"></i> <?php _efs('change-plan', $slug) ?></a>
108
+ </li>
109
+ <?php elseif ($is_paid_trial) : ?>
110
+ <li>
111
+ &nbsp;•&nbsp;
112
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
113
+ <input type="hidden" name="fs_action" value="cancel_trial">
114
+ <?php wp_nonce_field('cancel_trial') ?>
115
+ <a href="#"
116
+ onclick="if (confirm('<?php _efs('cancel-trial-confirm') ?>')) this.parentNode.submit(); return false;"><i
117
+ class="dashicons dashicons-download"></i> <?php _efs('cancel-trial', $slug) ?></a>
118
+ </form>
119
+ </li>
120
+ <?php endif ?>
121
+ <li>
122
+ &nbsp;•&nbsp;
123
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
124
+ <input type="hidden" name="fs_action" value="<?php echo $slug ?>_sync_license">
125
+ <?php wp_nonce_field($slug . '_sync_license') ?>
126
+ <a href="#" onclick="this.parentNode.submit(); return false;"><i
127
+ class="dashicons dashicons-image-rotate"></i> <?php _efs('sync', $slug) ?></a>
128
+ </form>
129
+ </li>
130
+
131
+ </ul>
132
+ </div>
133
+ <div class="inside">
134
+ <table id="fs_account_details" cellspacing="0" class="fs-key-value-table">
135
+ <?php
136
+ $profile = array();
137
+ $profile[] = array(
138
+ 'id' => 'user_name',
139
+ 'title' => __fs('name', $slug),
140
+ 'value' => $name
141
+ );
142
+ // if (isset($user->email) && false !== strpos($user->email, '@'))
143
+ $profile[] = array(
144
+ 'id' => 'email',
145
+ 'title' => __fs('email', $slug),
146
+ 'value' => $user->email
147
+ );
148
+ if (is_numeric($user->id)) {
149
+ $profile[] = array(
150
+ 'id' => 'user_id',
151
+ 'title' => __fs('user-id', $slug),
152
+ 'value' => $user->id
153
+ );
154
+ }
155
+
156
+ $profile[] = array(
157
+ 'id' => 'site_id',
158
+ 'title' => __fs('site-id', $slug),
159
+ 'value' => is_string($site->id) ?
160
+ $site->id :
161
+ __fs('no-id', $slug)
162
+ );
163
+
164
+ $profile[] = array(
165
+ 'id' => 'site_public_key',
166
+ 'title' => __fs('public-key', $slug),
167
+ 'value' => $site->public_key
168
+ );
169
+
170
+ $profile[] = array(
171
+ 'id' => 'site_secret_key',
172
+ 'title' => __fs('secret-key', $slug),
173
+ 'value' => ((is_string($site->secret_key)) ?
174
+ $site->secret_key :
175
+ __fs('no-secret', $slug)
176
+ )
177
+ );
178
+
179
+ if ($fs->has_paid_plan()) {
180
+ if ($fs->is_trial()) {
181
+ $trial_plan = $fs->get_trial_plan();
182
+
183
+ $profile[] = array(
184
+ 'id' => 'plan',
185
+ 'title' => __fs('plan', $slug),
186
+ 'value' => (is_string($trial_plan->name) ?
187
+ strtoupper($trial_plan->title) :
188
+ __fs('trial', $slug))
189
+ );
190
+ } else {
191
+ $profile[] = array(
192
+ 'id' => 'plan',
193
+ 'title' => __fs('plan', $slug),
194
+ 'value' => is_string($site->plan->name) ?
195
+ strtoupper($site->plan->title) :
196
+ strtoupper(__fs('free', $slug))
197
+ );
198
+ }
199
+ }
200
+
201
+ $profile[] = array(
202
+ 'id' => 'version',
203
+ 'title' => __fs('version', $slug),
204
+ 'value' => $fs->get_plugin_version()
205
+ );
206
+ ?>
207
+ <?php $odd = true;
208
+ foreach ($profile as $p) : ?>
209
+ <?php
210
+ if ('plan' === $p['id'] && ! $fs->has_paid_plan()) {
211
+ // If plugin don't have any paid plans, there's no reason
212
+ // to show current plan.
213
+ continue;
214
+ }
215
+ ?>
216
+ <tr class="fs-field-<?php echo $p['id'] ?><?php if ($odd) : ?> alternate<?php endif ?>">
217
+ <td>
218
+ <nobr><?php echo $p['title'] ?>:</nobr>
219
+ </td>
220
+ <td>
221
+ <code><?php echo htmlspecialchars($p['value']) ?></code>
222
+ <?php if ('email' === $p['id'] && ! $user->is_verified()) : ?>
223
+ <label class="fs-tag fs-warn"><?php _efs('not-verified', $slug) ?></label>
224
+ <?php endif ?>
225
+ <?php if ('plan' === $p['id']) : ?>
226
+ <?php if ($fs->is_trial()) : ?>
227
+ <label class="fs-tag fs-success"><?php _efs('trial', $slug) ?></label>
228
+ <?php endif ?>
229
+ <?php if (is_object($license) && ! $license->is_lifetime()) : ?>
230
+ <?php if (! $is_active_subscription && ! $license->is_first_payment_pending()) : ?>
231
+ <label
232
+ class="fs-tag fs-warn"><?php printf(__fs('expires-in', $slug), human_time_diff(time(), strtotime($license->expiration))) ?></label>
233
+ <?php elseif ($is_active_subscription && ! $subscription->is_first_payment_pending()) : ?>
234
+ <label
235
+ class="fs-tag fs-success"><?php printf(__fs('renews-in', $slug), human_time_diff(time(), strtotime($subscription->next_payment))) ?></label>
236
+ <?php endif ?>
237
+ <?php elseif ($fs->is_trial()) : ?>
238
+ <label
239
+ class="fs-tag fs-warn"><?php printf(__fs('expires-in', $slug), human_time_diff(time(), strtotime($site->trial_ends))) ?></label>
240
+ <?php endif ?>
241
+ <?php endif ?>
242
+ <?php if ('version' === $p['id'] && $fs->has_paid_plan()) : ?>
243
+ <?php if ($fs->is_premium()) : ?>
244
+ <label
245
+ class="fs-tag fs-<?php echo $fs->can_use_premium_code() ? 'success' : 'warn' ?>"><?php _efs('premium-version') ?></label>
246
+ <?php elseif ($fs->can_use_premium_code()) : ?>
247
+ <label class="fs-tag fs-warn"><?php _efs('free-version') ?></label>
248
+ <?php endif ?>
249
+ <?php endif ?>
250
+ </td>
251
+ <td class="fs-right">
252
+ <?php if ('email' === $p['id'] && ! $user->is_verified()) : ?>
253
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST">
254
+ <input type="hidden" name="fs_action" value="verify_email">
255
+ <?php wp_nonce_field('verify_email') ?>
256
+ <input type="submit" class="button button-small"
257
+ value="<?php _efs('verify-email', $slug) ?>">
258
+ </form>
259
+ <?php endif ?>
260
+ <?php if ('plan' === $p['id']) : ?>
261
+ <div class="button-group">
262
+ <?php $license = $fs->is_free_plan() ? $fs->_get_available_premium_license() : false ?>
263
+ <?php if (false !== $license && ($license->left() > 0 || ($site->is_localhost() && $license->is_free_localhost))) : ?>
264
+ <?php $premium_plan = $fs->_get_plan_by_id($license->plan_id) ?>
265
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>"
266
+ method="POST">
267
+ <input type="hidden" name="fs_action" value="activate_license">
268
+ <input type="hidden" name="license_id" value="<?php echo $license->id ?>">
269
+ <?php wp_nonce_field('activate_license') ?>
270
+ <input type="submit" class="button button-primary"
271
+ value="<?php printf(
272
+ __fs( 'activate-x-plan', $slug ) . '%s',
273
+ $premium_plan->title,
274
+ ( $site->is_localhost() && $license->is_free_localhost ) ?
275
+ ' [' . __fs( 'localhost', $slug ) . ']' :
276
+ ( $license->is_single_site() ?
277
+ '' :
278
+ ' [' . ( 1 < $license->left() ?
279
+ sprintf( __fs( 'x-left', $slug ), $license->left() ) :
280
+ strtolower( __fs( 'last-license', $slug ) ) ) . ']'
281
+ )
282
+ ) ?> ">
283
+ </form>
284
+ <?php else : ?>
285
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>"
286
+ method="POST" class="button-group">
287
+ <input type="submit" class="button"
288
+ value="<?php _efs('sync-license', $slug) ?>">
289
+ <input type="hidden" name="fs_action"
290
+ value="<?php echo $slug ?>_sync_license">
291
+ <?php wp_nonce_field($slug . '_sync_license') ?>
292
+ <a href="<?php echo $fs->get_upgrade_url() ?>"
293
+ class="button<?php if ($show_upgrade) {
294
+ echo ' button-primary';
295
+ } ?> button-upgrade"><i
296
+ class="dashicons dashicons-cart"></i> <?php ($show_upgrade) ?
297
+ _efs('upgrade', $slug) :
298
+ _efs('change-plan', $slug)
299
+ ?></a>
300
+ </form>
301
+ <?php endif ?>
302
+ </div>
303
+ <?php elseif ('version' === $p['id']) : ?>
304
+ <div class="button-group">
305
+ <?php if ($is_paying || $fs->is_trial()) : ?>
306
+ <?php if (! $fs->is_allowed_to_install()) : ?>
307
+ <a target="_blank" class="button button-primary"
308
+ href="<?php echo $fs->_get_latest_download_local_url() ?>"><?php echo sprintf(__fs('download-x-version', $slug), $site->plan->title) . (is_object($update) ? ' [' . $update->version . ']' : '') ?></a>
309
+ <?php elseif (is_object($update)) : ?>
310
+ <a class="button button-primary"
311
+ href="<?php echo wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $fs->get_plugin_basename()), 'upgrade-plugin_' . $fs->get_plugin_basename()) ?>"><?php echo __fs('install-update-now', $slug) . ' [' . $update->version . ']' ?></a>
312
+ <?php endif ?>
313
+ <?php endif; ?>
314
+ </div>
315
+ <?php
316
+ elseif (/*in_array($p['id'], array('site_secret_key', 'site_id', 'site_public_key')) ||*/
317
+ (is_string($user->secret_key) && in_array($p['id'], array(
318
+ 'email',
319
+ 'user_name'
320
+ )))
321
+ ) : ?>
322
+ <form action="<?php echo $fs->_get_admin_page_url('account') ?>" method="POST"
323
+ onsubmit="var val = prompt('<?php printf(__fs('what-is-your-x', $slug), $p['title']) ?>', '<?php echo $p['value'] ?>'); if (null == val || '' === val) return false; jQuery('input[name=fs_<?php echo $p['id'] ?>_<?php echo $slug ?>]').val(val); return true;">
324
+ <input type="hidden" name="fs_action" value="update_<?php echo $p['id'] ?>">
325
+ <input type="hidden" name="fs_<?php echo $p['id'] ?>_<?php echo $slug ?>"
326
+ value="">
327
+ <?php wp_nonce_field('update_' . $p['id']) ?>
328
+ <input type="submit" class="button button-small"
329
+ value="<?php _ex('Edit', 'verb', 'freemius') ?>">
330
+ </form>
331
+ <?php endif ?>
332
+ </td>
333
+ </tr>
334
+ <?php $odd = ! $odd;
335
+ endforeach ?>
336
+ </table>
337
+ </div>
338
+ </div>
339
+ <?php
340
+ $account_addons = $fs->get_account_addons();
341
+ if (! is_array($account_addons)) {
342
+ $account_addons = array();
343
+ }
344
+
345
+ $installed_addons = $fs->get_installed_addons();
346
+ $installed_addons_ids = array();
347
+ foreach ($installed_addons as $fs_addon) {
348
+ $installed_addons_ids[] = $fs_addon->get_id();
349
+ }
350
+
351
+ $addons_to_show = array_unique(array_merge($installed_addons_ids, $account_addons));
352
+ ?>
353
+ <?php if (0 < count($addons_to_show)) : ?>
354
+ <div class="postbox">
355
+ <div class="">
356
+ <!-- <div class="inside">-->
357
+ <table id="fs_addons" class="widefat">
358
+ <thead>
359
+ <tr>
360
+ <th><h3><?php _efs('add-ons', $slug) ?></h3></th>
361
+ <th><?php _efs('id', $slug) ?></th>
362
+ <th><?php _efs('version', $slug) ?></th>
363
+ <th><?php _efs('plan', $slug) ?></th>
364
+ <th><?php _efs('license', $slug) ?></th>
365
+ <th></th>
366
+ <?php if (defined('WP_FS__DEV_MODE') && WP_FS__DEV_MODE) : ?>
367
+ <th></th>
368
+ <?php endif ?>
369
+ </tr>
370
+ </thead>
371
+ <tbody>
372
+ <?php $odd = true;
373
+ foreach ($addons_to_show as $addon_id) : ?>
374
+ <?php
375
+ $addon = $fs->get_addon($addon_id);
376
+ $is_addon_activated = $fs->is_addon_activated($addon->slug);
377
+ $is_addon_connected = $fs->is_addon_connected($addon->slug);
378
+
379
+ $fs_addon = $is_addon_connected ? freemius($addon->slug) : false;
380
+ if (is_object($fs_addon)) {
381
+ $is_paying = $fs_addon->is_paying();
382
+ $user = $fs_addon->get_user();
383
+ $site = $fs_addon->get_site();
384
+ $license = $fs_addon->_get_license();
385
+ $subscription = $fs_addon->_get_subscription();
386
+ $plan = $fs_addon->get_plan();
387
+ $is_active_subscription = (is_object($subscription) && $subscription->is_active());
388
+ $is_paid_trial = $fs_addon->is_paid_trial();
389
+ $show_upgrade = (! $is_paying && ! $is_paid_trial && ! $fs_addon->_has_premium_license());
390
+ $is_current_license_expired = is_object($license) && $license->is_expired();
391
+ }
392
+
393
+ // var_dump( $is_paid_trial, $license, $site, $subscription );
394
+
395
+ ?>
396
+ <tr<?php if ($odd) {
397
+ echo ' class="alternate"';
398
+ } ?>>
399
+ <td>
400
+ <!-- Title -->
401
+ <?php echo $addon->title ?>
402
+ </td>
403
+ <?php if ($is_addon_connected) : ?>
404
+ <?php // Add-on Installed ?>
405
+ <?php $addon_site = $fs_addon->get_site(); ?>
406
+ <td>
407
+ <!-- ID -->
408
+ <?php echo $addon_site->id ?>
409
+ </td>
410
+ <td>
411
+ <!-- Version -->
412
+ <?php echo $fs_addon->get_plugin_version() ?>
413
+ </td>
414
+ <td>
415
+ <!-- Plan Title -->
416
+ <?php echo is_string($addon_site->plan->name) ? strtoupper($addon_site->plan->title) : 'FREE' ?>
417
+ </td>
418
+ <td>
419
+ <!-- Expiration -->
420
+ <?php
421
+ $tags = array();
422
+
423
+ if ($fs_addon->is_trial()) {
424
+ $tags[] = array('label' => __fs('trial', $slug), 'type' => 'success');
425
+
426
+ $tags[] = array(
427
+ 'label' => sprintf(__fs(($is_paid_trial ? 'renews-in' : 'expires-in'), $slug), human_time_diff(time(), strtotime($site->trial_ends))),
428
+ 'type' => ($is_paid_trial ? 'success' : 'warn')
429
+ );
430
+ } else {
431
+ if (is_object($license)) {
432
+ if ($license->is_cancelled) {
433
+ $tags[] = array(
434
+ 'label' => __fs('cancelled', $slug),
435
+ 'type' => 'error'
436
+ );
437
+ } else if ($license->is_expired()) {
438
+ $tags[] = array(
439
+ 'label' => __fs('expired', $slug),
440
+ 'type' => 'error'
441
+ );
442
+ } else if ($license->is_lifetime()) {
443
+ $tags[] = array(
444
+ 'label' => __fs('no-expiration', $slug),
445
+ 'type' => 'success'
446
+ );
447
+ } else if (! $is_active_subscription && ! $license->is_first_payment_pending()) {
448
+ $tags[] = array(
449
+ 'label' => sprintf(__fs('expires-in', $slug), human_time_diff(time(), strtotime($license->expiration))),
450
+ 'type' => 'warn'
451
+ );
452
+ } else if ($is_active_subscription && ! $subscription->is_first_payment_pending()) {
453
+ $tags[] = array(
454
+ 'label' => sprintf(__fs('renews-in', $slug), human_time_diff(time(), strtotime($subscription->next_payment))),
455
+ 'type' => 'success'
456
+ );
457
+ }
458
+ }
459
+ }
460
+
461
+ foreach ($tags as $t) {
462
+ printf('<label class="fs-tag fs-%s">%s</label>' . "\n", $t['type'], $t['label']);
463
+ }
464
+ ?>
465
+ </td>
466
+ <?php
467
+ $buttons = array();
468
+ if ($is_addon_activated) {
469
+ if ($is_paying) {
470
+ $buttons[] = fs_ui_get_action_button(
471
+ $slug,
472
+ 'account',
473
+ 'deactivate_license',
474
+ __fs('deactivate-license', $slug),
475
+ array('plugin_id' => $addon_id),
476
+ false
477
+ );
478
+ } else if ($is_paid_trial) {
479
+ $buttons[] = fs_ui_get_action_button(
480
+ $slug,
481
+ 'account',
482
+ 'cancel_trial',
483
+ __fs('cancel-trial', $slug),
484
+ array('plugin_id' => $addon_id),
485
+ false,
486
+ 'dashicons dashicons-download',
487
+ __fs('cancel-trial-confirm', $slug),
488
+ 'POST'
489
+ );
490
+ } else {
491
+ $premium_license = $fs_addon->_get_available_premium_license();
492
+
493
+ if (is_object($premium_license)) {
494
+ $site = $fs_addon->get_site();
495
+
496
+ $buttons[] = fs_ui_get_action_button(
497
+ $slug,
498
+ 'account',
499
+ 'activate_license',
500
+ sprintf(__fs('activate-x-plan', $slug), $fs_addon->get_plan_title(), ($site->is_localhost() && $premium_license->is_free_localhost) ? '[localhost]' : (1 < $premium_license->left() ? $premium_license->left() . ' left' : '')),
501
+ array(
502
+ 'plugin_id' => $addon_id,
503
+ 'license_id' => $premium_license->id,
504
+ )
505
+ );
506
+ }
507
+ }
508
+
509
+ if (0 == count($buttons)) {
510
+ // Add sync license only if non of the other CTAs are visible.
511
+ $buttons[] = fs_ui_get_action_button(
512
+ $slug,
513
+ 'account',
514
+ $slug . '_sync_license',
515
+ __fs('sync-license', $slug),
516
+ array('plugin_id' => $addon_id),
517
+ false
518
+ );
519
+
520
+ }
521
+ } else if (! $show_upgrade) {
522
+ if ($fs->is_addon_installed($addon->slug)) {
523
+ $addon_file = $fs->get_addon_basename($addon->slug);
524
+ $buttons[] = sprintf(
525
+ '<a class="button button-primary" href="%s" title="%s" class="edit">%s</a>',
526
+ wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file),
527
+ esc_attr(__fs('activate-this-addon', $slug)),
528
+ __fs('activate', $slug)
529
+ );
530
+ } else {
531
+ if ($fs->is_allowed_to_install()) {
532
+ $buttons[] = sprintf(
533
+ '<a class="button button-primary" href="%s" class="edit">%s</a>',
534
+ wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $addon->slug), 'install-plugin_' . $addon->slug),
535
+ __fs('install-now', $slug)
536
+ );
537
+ } else {
538
+ $buttons[] = sprintf(
539
+ '<a target="_blank" class="button button-primary" href="%s" class="edit">%s</a>',
540
+ $fs->_get_latest_download_local_url($addon_id),
541
+ __fs('download-latest', $slug)
542
+ );
543
+ }
544
+ }
545
+ }
546
+
547
+ if ($show_upgrade) {
548
+ $buttons[] = sprintf('<a href="%s" class="thickbox button button-primary" aria-label="%s" data-title="%s"><i class="dashicons dashicons-cart"></i> %s</a>',
549
+ esc_url(network_admin_url('plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
550
+ '&TB_iframe=true&width=600&height=550')),
551
+ esc_attr(sprintf(__fs('more-information-about-x', $slug), $addon->title)),
552
+ esc_attr($addon->title),
553
+ __fs(($fs_addon->has_free_plan() ? 'upgrade' : 'purchase'), $slug)
554
+ );
555
+ }
556
+
557
+ $buttons_count = count($buttons);
558
+ ?>
559
+
560
+ <td>
561
+ <!-- Actions -->
562
+ <?php if ($buttons_count > 1) : ?>
563
+ <div class="button-group">
564
+ <?php endif ?>
565
+ <?php foreach ($buttons as $button) : ?>
566
+ <?php echo $button ?>
567
+ <?php endforeach ?>
568
+ <?php if ($buttons_count > 1) : ?>
569
+ </div>
570
+ <?php endif ?>
571
+ </td>
572
+ <?php else : ?>
573
+ <?php // Add-on NOT Installed or was never connected.
574
+ ?>
575
+ <td colspan="4">
576
+ <!-- Action -->
577
+ <?php if ($fs->is_addon_installed($addon->slug)) : ?>
578
+ <?php $addon_file = $fs->get_addon_basename($addon->slug) ?>
579
+ <a class="button button-primary"
580
+ href="<?php echo wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file) ?>"
581
+ title="<?php esc_attr(__fs('activate-this-addon', $slug)) ?>"
582
+ class="edit"><?php _efs('activate', $slug) ?></a>
583
+ <?php else : ?>
584
+ <?php if ($fs->is_allowed_to_install()) : ?>
585
+ <a class="button button-primary"
586
+ href="<?php echo wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $addon->slug), 'install-plugin_' . $addon->slug) ?>"><?php _efs('install-now', $slug) ?></a>
587
+ <?php else : ?>
588
+ <a target="_blank" class="button button-primary"
589
+ href="<?php echo $fs->_get_latest_download_local_url($addon_id) ?>"><?php _efs('download-latest', $slug) ?></a>
590
+ <?php endif ?>
591
+ <?php endif ?>
592
+ </td>
593
+ <?php endif ?>
594
+ <?php if (defined('WP_FS__DEV_MODE') && WP_FS__DEV_MODE) : ?>
595
+ <td>
596
+ <!-- Optional Delete Action -->
597
+ <?php
598
+ if ($is_addon_activated) {
599
+ fs_ui_action_button(
600
+ $slug, 'account',
601
+ 'delete_account',
602
+ __fs('delete', $slug),
603
+ array('plugin_id' => $addon_id),
604
+ false
605
+ );
606
+ }
607
+ ?>
608
+ </td>
609
+ <?php endif ?>
610
+ </tr>
611
+ <?php $odd = ! $odd;
612
+ endforeach ?>
613
+ </tbody>
614
+ </table>
615
+ </div>
616
+ </div>
617
+ <?php endif ?>
618
+
619
+ <?php $fs->do_action('after_account_details') ?>
620
+ </div>
621
+ </div>
622
+ </div>
623
+ </div>
624
+ </div>
625
+ <?php fs_require_template('powered-by.php') ?>
freemius/templates/add-ons.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ /**
15
+ * @var Freemius
16
+ */
17
+ $fs = freemius( $slug );
18
+
19
+ $open_addon_slug = fs_request_get( 'slug' );
20
+
21
+ $open_addon = false;
22
+
23
+ /**
24
+ * @var FS_Plugin[]
25
+ */
26
+ $addons = $fs->get_addons();
27
+
28
+ $has_addons = ( is_array( $addons ) && 0 < count( $addons ) );
29
+ ?>
30
+ <div id="fs_addons" class="wrap">
31
+ <h2><?php printf( __fs( 'add-ons-for-x', $slug ), $fs->get_plugin_name() ) ?></h2>
32
+
33
+ <div id="poststuff">
34
+ <?php if ( ! $has_addons ) : ?>
35
+ <h3><?php printf(
36
+ '%s... %s',
37
+ __fs( 'oops', $slug ),
38
+ __fs( 'add-ons-missing', $slug )
39
+ ) ?></h3>
40
+ <?php endif ?>
41
+ <ul class="fs-cards-list">
42
+ <?php if ( $has_addons ) : ?>
43
+ <?php foreach ( $addons as $addon ) : ?>
44
+ <?php
45
+ $open_addon = ( $open_addon || ( $open_addon_slug === $addon->slug ) );
46
+
47
+ $price = 0;
48
+ $plan = null;
49
+ $plans_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans.json" );
50
+ if ( ! isset( $plans_result->error ) ) {
51
+ $plans = $plans_result->plans;
52
+ if ( is_array( $plans ) && 0 < count( $plans ) ) {
53
+ $plan = new FS_Plugin_Plan( $plans[0] );
54
+ $pricing_result = $fs->get_api_site_or_plugin_scope()->get( "/addons/{$addon->id}/plans/{$plan->id}/pricing.json" );
55
+ if ( ! isset( $pricing_result->error ) ) {
56
+ // Update plan's pricing.
57
+ $plan->pricing = $pricing_result->pricing;
58
+
59
+ if ( is_array( $plan->pricing ) && 0 < count( $plan->pricing ) ) {
60
+ $min_price = 999999;
61
+ foreach ( $plan->pricing as $pricing ) {
62
+ if ( ! is_null( $pricing->annual_price ) && $pricing->annual_price > 0 ) {
63
+ $min_price = min( $min_price, $pricing->annual_price );
64
+ } else if ( ! is_null( $pricing->monthly_price ) && $pricing->monthly_price > 0 ) {
65
+ $min_price = min( $min_price, 12 * $pricing->monthly_price );
66
+ }
67
+ }
68
+
69
+ if ( $min_price < 999999 ) {
70
+ $price = $min_price;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ ?>
77
+ <li class="fs-card fs-addon" data-slug="<?php echo $addon->slug ?>">
78
+ <?php
79
+ echo sprintf( '<a href="%s" class="thickbox fs-overlay" aria-label="%s" data-title="%s"></a>',
80
+ esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon->slug .
81
+ '&TB_iframe=true&width=600&height=550' ) ),
82
+ esc_attr( sprintf( __fs( 'more-information-about-x', $slug ), $addon->title ) ),
83
+ esc_attr( $addon->title )
84
+ );
85
+ ?>
86
+ <?php
87
+ if ( is_null( $addon->info ) ) {
88
+ $addon->info = new stdClass();
89
+ }
90
+ if ( ! isset( $addon->info->card_banner_url ) ) {
91
+ $addon->info->card_banner_url = '//dashboard.freemius.com/assets/img/marketing/blueprint-300x100.jpg';
92
+ }
93
+ if ( ! isset( $addon->info->short_description ) ) {
94
+ $addon->info->short_description = 'What\'s the one thing your add-on does really, really well?';
95
+ }
96
+ ?>
97
+ <div class="fs-inner">
98
+ <ul>
99
+ <li class="fs-card-banner"
100
+ style="background-image: url('<?php echo $addon->info->card_banner_url ?>');"></li>
101
+ <!-- <li class="fs-tag"></li>-->
102
+ <li class="fs-title"><?php echo $addon->title ?></li>
103
+ <li class="fs-offer">
104
+ <span
105
+ class="fs-price"><?php echo ( 0 == $price ) ? __fs( 'free', $slug ) : ('$' . number_format( $price, 2 ) . ($plan->has_trial() ? ' - ' . __fs('trial', $slug) : '')) ?></span>
106
+ </li>
107
+ <li class="fs-description"><?php echo ! empty( $addon->info->short_description ) ? $addon->info->short_description : 'SHORT DESCRIPTION' ?></li>
108
+ <li class="fs-cta"><a class="button"><?php _efs( 'view-details', $slug ) ?></a></li>
109
+ </ul>
110
+ </div>
111
+ </li>
112
+ <?php endforeach ?>
113
+ <?php endif ?>
114
+ </ul>
115
+ </div>
116
+ </div>
117
+ <script type="text/javascript">
118
+ (function ($) {
119
+ <?php if ( $open_addon ) : ?>
120
+
121
+ var interval = setInterval(function () {
122
+ // Open add-on information page.
123
+ $('.fs-card[data-slug=<?php echo $open_addon_slug ?>] a').click();
124
+ if ($('#TB_iframeContent').length > 0) {
125
+ clearInterval(interval);
126
+ interval = null;
127
+ }
128
+ }, 200);
129
+
130
+ <?php else : ?>
131
+
132
+
133
+ $('.fs-card.fs-addon').mouseover(function(){
134
+ $(this).find('.fs-cta .button').addClass('button-primary');
135
+ });
136
+
137
+ $('.fs-card.fs-addon').mouseout(function(){
138
+ $(this).find('.fs-cta .button').removeClass('button-primary');
139
+ });
140
+
141
+ <?php endif ?>
142
+ })(jQuery);
143
+ </script>
144
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/admin-notice.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+ <div<?php if ( ! empty( $VARS['id'] ) ) : ?> data-id="<?php echo $VARS['id'] ?>"<?php endif ?><?php if ( ! empty( $VARS['slug'] ) ) : ?> data-slug="<?php echo $VARS['slug'] ?>"<?php endif ?>
14
+ class="<?php
15
+ switch ( $VARS['type'] ) {
16
+ case 'error':
17
+ echo 'error form-invalid';
18
+ break;
19
+ case 'promotion':
20
+ echo 'updated promotion';
21
+ break;
22
+ case 'update':
23
+ // echo 'update-nag update';
24
+ // break;
25
+ case 'success':
26
+ default:
27
+ echo 'updated success';
28
+ break;
29
+ }
30
+ ?> fs-notice<?php if ( ! empty( $VARS['sticky'] ) ) {
31
+ echo ' fs-sticky';
32
+ } ?><?php if ( ! empty( $VARS['plugin'] ) ) {
33
+ echo ' fs-has-title';
34
+ } ?>"><?php if ( ! empty( $VARS['plugin'] ) ) : ?>
35
+ <label class="fs-plugin-title"><?php echo $VARS['plugin'] ?></label>
36
+ <?php endif ?>
37
+ <?php if ( ! empty( $VARS['sticky'] ) ) : ?>
38
+ <div class="fs-close"><i class="dashicons dashicons-no"
39
+ title="<?php _efs( 'dismiss' ) ?>"></i> <span><?php _efs( 'dismiss' ) ?></span>
40
+ </div>
41
+ <?php endif ?>
42
+ <div class="fs-notice-body">
43
+ <?php if ( ! empty( $VARS['title'] ) ) : ?><b><?php echo $VARS['title'] ?></b> <?php endif ?>
44
+ <?php echo $VARS['message'] ?>
45
+ </div>
46
+ </div>
freemius/templates/all-admin-notice.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+ ?>
13
+ <div class="<?php
14
+ switch ($VARS['type']) {
15
+ case 'error':
16
+ echo 'error form-invalid';
17
+ break;
18
+ case 'update-nag':
19
+ echo 'update-nag ';
20
+ break;
21
+ case 'update':
22
+ case 'success':
23
+ default:
24
+ echo 'updated success';
25
+ break;
26
+ }
27
+ ?> fs-notice">
28
+ <?php if ('update-nag' !== $VARS['type']) : ?><p><?php endif ?>
29
+ <?php if (!empty($VARS['title'])) : ?>
30
+ <b><?php echo $VARS['title'] ?></b>
31
+ <?php endif ?>
32
+ <?php echo $VARS['message'] ?>
33
+ <?php if ('update-nag' !== $VARS['type']) : ?></p><?php endif ?>
34
+ <?php if ($VARS['sticky']) : ?><i class="dashicons dashicons-no"></i><?php endif ?>
35
+ </div>
freemius/templates/checkout.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
18
+
19
+ $slug = $VARS['slug'];
20
+ $fs = freemius( $slug );
21
+
22
+ $timestamp = time();
23
+
24
+ $context_params = array(
25
+ 'plugin_id' => $fs->get_id(),
26
+ 'plugin_public_key' => $fs->get_public_key(),
27
+ 'plugin_version' => $fs->get_plugin_version(),
28
+ );
29
+
30
+ // Get site context secure params.
31
+ if ( $fs->is_registered() ) {
32
+ $site = $fs->get_site();
33
+ $plugin_id = fs_request_get( 'plugin_id', $fs->get_id() );
34
+
35
+ if ($plugin_id != $fs->get_id()) {
36
+ if ( $fs->is_addon_activated( $plugin_id ) ) {
37
+ $fs_addon = Freemius::get_instance_by_id( $plugin_id );
38
+ $site = $fs_addon->get_site();
39
+ }
40
+ }
41
+
42
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
43
+ $site,
44
+ $timestamp,
45
+ 'checkout'
46
+ ) );
47
+ } else {
48
+ $current_user = Freemius::_get_current_wp_user();
49
+
50
+ // Add site and user info to the request, this information
51
+ // is NOT being stored unless the user complete the purchase
52
+ // and agrees to the TOS.
53
+ $context_params = array_merge( $context_params, array(
54
+ 'user_firstname' => $current_user->user_firstname,
55
+ 'user_lastname' => $current_user->user_lastname,
56
+ 'user_email' => $current_user->user_email,
57
+ // 'user_nickname' => $current_user->user_nicename,
58
+ // 'plugin_slug' => $slug,
59
+ // 'site_url' => get_site_url(),
60
+ // 'site_name' => get_bloginfo( 'name' ),
61
+ // 'platform_version' => get_bloginfo( 'version' ),
62
+ // 'language' => get_bloginfo( 'language' ),
63
+ // 'charset' => get_bloginfo( 'charset' ),
64
+ // 'account_url' => fs_nonce_url( $fs->_get_admin_page_url(
65
+ // 'account',
66
+ // array( 'fs_action' => 'sync_user' )
67
+ // ), 'sync_user' ),
68
+ ) );
69
+
70
+ $fs_user = Freemius::_get_user_by_email( $current_user->user_email );
71
+
72
+ if ( is_object( $fs_user ) ) {
73
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
74
+ $fs_user,
75
+ $timestamp,
76
+ 'checkout'
77
+ ) );
78
+ }
79
+ }
80
+
81
+ if ( $fs->is_payments_sandbox() )
82
+ {
83
+ // Append plugin secure token for sandbox mode authentication.
84
+ $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
85
+ $fs->get_plugin(),
86
+ $timestamp,
87
+ 'checkout'
88
+ );
89
+
90
+ /**
91
+ * @since 1.1.7.3 Add security timestamp for sandbox even for anonymous user.
92
+ */
93
+ if ( empty( $context_params['s_ctx_ts'] ) ) {
94
+ $context_params['s_ctx_ts'] = $timestamp;
95
+ }
96
+ }
97
+
98
+ $return_url = fs_nonce_url( $fs->_get_admin_page_url(
99
+ 'account',
100
+ array(
101
+ 'fs_action' => $slug . '_sync_license',
102
+ 'plugin_id' => isset( $_GET['plugin_id'] ) ? $_GET['plugin_id'] : $fs->get_id()
103
+ )
104
+ ), $slug . '_sync_license' );
105
+
106
+ $query_params = array_merge( $context_params, $_GET, array(
107
+ // Current plugin version.
108
+ 'plugin_version' => $fs->get_plugin_version(),
109
+ 'return_url' => $return_url,
110
+ // Admin CSS URL for style/design competability.
111
+ // 'wp_admin_css' => get_bloginfo('wpurl') . "/wp-admin/load-styles.php?c=1&load=buttons,wp-admin,dashicons",
112
+ ) );
113
+ ?>
114
+ <div class="fs-secure-notice">
115
+ <i class="dashicons dashicons-lock"></i>
116
+ <span><b>Secure HTTPS Checkout</b> - PCI compliant, running via iframe from external domain</span>
117
+ </div>
118
+ <div id="fs_contact" class="wrap" style="margin: 40px 0 -65px -20px;">
119
+ <div id="iframe"></div>
120
+ <script type="text/javascript">
121
+ // http://stackoverflow.com/questions/4583703/jquery-post-request-not-ajax
122
+ jQuery(function ($) {
123
+ $.extend({
124
+ form: function (url, data, method) {
125
+ if (method == null) method = 'POST';
126
+ if (data == null) data = {};
127
+
128
+ var form = $('<form>').attr({
129
+ method: method,
130
+ action: url
131
+ }).css({
132
+ display: 'none'
133
+ });
134
+
135
+ var addData = function (name, data) {
136
+ if ($.isArray(data)) {
137
+ for (var i = 0; i < data.length; i++) {
138
+ var value = data[i];
139
+ addData(name + '[]', value);
140
+ }
141
+ } else if (typeof data === 'object') {
142
+ for (var key in data) {
143
+ if (data.hasOwnProperty(key)) {
144
+ addData(name + '[' + key + ']', data[key]);
145
+ }
146
+ }
147
+ } else if (data != null) {
148
+ form.append($('<input>').attr({
149
+ type : 'hidden',
150
+ name : String(name),
151
+ value: String(data)
152
+ }));
153
+ }
154
+ };
155
+
156
+ for (var key in data) {
157
+ if (data.hasOwnProperty(key)) {
158
+ addData(key, data[key]);
159
+ }
160
+ }
161
+
162
+ return form.appendTo('body');
163
+ }
164
+ });
165
+ });
166
+
167
+ (function ($) {
168
+ $(function () {
169
+
170
+ var
171
+ // Keep track of the iframe height.
172
+ iframe_height = 800,
173
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
174
+ // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
175
+ // passed via query string or hard coded into the child page, it depends on your needs).
176
+ src = base_url + '/checkout/?<?php echo (isset($_REQUEST['XDEBUG_SESSION']) ? 'XDEBUG_SESSION=' . $_REQUEST['XDEBUG_SESSION'] . '&' : '') . http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
177
+
178
+ // Append the Iframe into the DOM.
179
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
180
+ .appendTo('#iframe');
181
+
182
+ FS.PostMessage.init(base_url);
183
+ FS.PostMessage.receiveOnce('height', function (data) {
184
+ var h = data.height;
185
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
186
+ iframe_height = h;
187
+ $("#iframe iframe").height(iframe_height + 'px');
188
+ }
189
+ });
190
+
191
+ FS.PostMessage.receiveOnce('install', function (data) {
192
+ // Post data to activation URL.
193
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
194
+ 'fs_action' => $slug . '_activate_new',
195
+ 'plugin_id' => isset($_GET['plugin_id']) ? $_GET['plugin_id'] : $fs->get_id()
196
+ )), $slug . '_activate_new') ?>', {
197
+ user_id : data.user.id,
198
+ user_secret_key : data.user.secret_key,
199
+ user_public_key : data.user.public_key,
200
+ install_id : data.install.id,
201
+ install_secret_key: data.install.secret_key,
202
+ install_public_key: data.install.public_key
203
+ }).submit();
204
+ });
205
+
206
+ FS.PostMessage.receiveOnce('pending_activation', function (data) {
207
+ $.form('<?php echo fs_nonce_url($fs->_get_admin_page_url('account', array(
208
+ 'fs_action' => $slug . '_activate_new',
209
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
210
+ 'pending_activation' => true,
211
+ )), $slug . '_activate_new') ?>', {
212
+ user_email: data.user_email
213
+ }).submit();
214
+ });
215
+
216
+ FS.PostMessage.receiveOnce('get_context', function () {
217
+ console.debug('receiveOnce', 'get_context');
218
+
219
+ // If the user didn't connect his account with Freemius,
220
+ // once he accepts the Terms of Service and Privacy Policy,
221
+ // and then click the purchase button, the context information
222
+ // of the user will be shared with Freemius in order to complete the
223
+ // purchase workflow and activate the license for the right user.
224
+ FS.PostMessage.post('context', {
225
+ plugin_id : '<?php echo $fs->get_id() ?>',
226
+ plugin_public_key: '<?php echo $fs->get_public_key() ?>',
227
+ plugin_version : '<?php echo $fs->get_plugin_version() ?>',
228
+ plugin_slug : '<?php echo $slug ?>',
229
+ site_name : '<?php echo get_bloginfo('name') ?>',
230
+ platform_version : '<?php echo get_bloginfo('version') ?>',
231
+ language : '<?php echo get_bloginfo('language') ?>',
232
+ charset : '<?php echo get_bloginfo('charset') ?>',
233
+ return_url : '<?php echo $return_url ?>',
234
+ account_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url(
235
+ 'account',
236
+ array('fs_action' => 'sync_user')
237
+ ), 'sync_user') ?>',
238
+ activation_url : '<?php echo fs_nonce_url($fs->_get_admin_page_url('',
239
+ array(
240
+ 'fs_action' => $slug . '_activate_new',
241
+ 'plugin_id' => fs_request_get('plugin_id', $fs->get_id()),
242
+
243
+ )),
244
+ $slug . '_activate_new') ?>'
245
+ }, iframe[0]);
246
+ });
247
+
248
+ FS.PostMessage.receiveOnce('get_dimensions', function (data) {
249
+ console.debug('receiveOnce', 'get_dimensions');
250
+
251
+ FS.PostMessage.post('dimensions', {
252
+ height : $(document.body).height(),
253
+ scrollTop: $(document).scrollTop()
254
+ }, iframe[0]);
255
+ });
256
+ });
257
+ })(jQuery);
258
+ </script>
259
+ </div>
260
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/connect.php ADDED
@@ -0,0 +1,333 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.7
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+ $is_pending_activation = $fs->is_pending_activation();
16
+ $is_premium_only = $fs->is_only_premium();
17
+ $has_paid_plans = $fs->has_paid_plan();
18
+ $is_premium_code = $fs->is_premium();
19
+ $is_freemium = $fs->is_freemium();
20
+
21
+ $fs->_enqueue_connect_essentials();
22
+
23
+ $current_user = Freemius::_get_current_wp_user();
24
+
25
+ $first_name = $current_user->user_firstname;
26
+ if ( empty( $first_name ) ) {
27
+ $first_name = $current_user->nickname;
28
+ }
29
+
30
+ $site_url = get_site_url();
31
+ $protocol_pos = strpos( $site_url, '://' );
32
+ if ( false !== $protocol_pos ) {
33
+ $site_url = substr( $site_url, $protocol_pos + 3 );
34
+ }
35
+
36
+ $freemius_site_url = $fs->has_paid_plan() ?
37
+ 'https://freemius.com/wordpress/' :
38
+ // Insights platform information.
39
+ 'https://freemius.com/wordpress/usage-tracking/';
40
+
41
+ $freemius_site_url .= '?' . http_build_query( array(
42
+ 'plugin_id' => $fs->get_id(),
43
+ ) );
44
+
45
+ $freemius_link = '<a href="' . $freemius_site_url . '" target="_blank" tabindex="1">freemius.com</a>';
46
+
47
+ $error = fs_request_get( 'error' );
48
+
49
+ $require_license_key = $is_premium_only ||
50
+ ( $is_freemium && $is_premium_code && fs_request_get_bool( 'require_license', true ) );
51
+ ?>
52
+ <div id="fs_connect"
53
+ class="wrap<?php if ( ! $fs->is_enable_anonymous() || $is_pending_activation || $require_license_key ) {
54
+ echo ' fs-anonymous-disabled';
55
+ } ?>">
56
+ <div class="fs-visual">
57
+ <b class="fs-site-icon"><i class="dashicons dashicons-wordpress"></i></b>
58
+ <i class="dashicons dashicons-plus fs-first"></i>
59
+ <?php
60
+ $vars = array( 'slug' => $slug );
61
+ fs_require_once_template( 'plugin-icon.php', $vars );
62
+ ?>
63
+ <i class="dashicons dashicons-plus fs-second"></i>
64
+ <img class="fs-connect-logo" width="80" height="80" src="//img.freemius.com/connect-logo.png"/>
65
+ </div>
66
+ <div class="fs-content">
67
+ <?php if ( ! empty( $error ) ) : ?>
68
+ <p class="fs-error"><?php echo $error ?></p>
69
+ <?php endif ?>
70
+ <p><?php
71
+ $button_label = 'opt-in-connect';
72
+
73
+ if ( $is_pending_activation ) {
74
+ $button_label = 'resend-activation-email';
75
+
76
+ echo $fs->apply_filters( 'pending_activation_message', sprintf(
77
+ __fs( 'thanks-x', $slug ) . '<br>' .
78
+ __fs( 'pending-activation-message', $slug ),
79
+ $first_name,
80
+ '<b>' . $fs->get_plugin_name() . '</b>',
81
+ '<b>' . $current_user->user_email . '</b>'
82
+ ) );
83
+ } else if ( $require_license_key ) {
84
+ $button_label = 'agree-activate-license';
85
+
86
+ echo $fs->apply_filters( 'connect-message_on-premium',
87
+ sprintf( __fs( 'hey-x', $slug ), $first_name ) . '<br>' .
88
+ sprintf( __fs( 'thanks-for-purchasing', $slug ), '<b>' . $fs->get_plugin_name() . '</b>' ),
89
+ $first_name,
90
+ $fs->get_plugin_name()
91
+ );
92
+ } else {
93
+ $filter = 'connect_message';
94
+ $default_optin_message = 'connect-message';
95
+
96
+ if ( $fs->is_plugin_update() ) {
97
+ // If Freemius was added on a plugin update, set different
98
+ // opt-in message.
99
+ $default_optin_message = 'connect-message_on-update';
100
+
101
+ // If user customized the opt-in message on update, use
102
+ // that message. Otherwise, fallback to regular opt-in
103
+ // custom message if exist.
104
+ if ( $fs->has_filter( 'connect_message_on_update' ) ) {
105
+ $filter = 'connect_message_on_update';
106
+ }
107
+ }
108
+
109
+ echo $fs->apply_filters( $filter,
110
+ sprintf(
111
+ __fs( 'hey-x', $slug ) . '<br>' .
112
+ __fs( $default_optin_message, $slug ),
113
+ $first_name,
114
+ '<b>' . $fs->get_plugin_name() . '</b>',
115
+ '<b>' . $current_user->user_login . '</b>',
116
+ '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
117
+ $freemius_link
118
+ ),
119
+ $first_name,
120
+ $fs->get_plugin_name(),
121
+ $current_user->user_login,
122
+ '<a href="' . $site_url . '" target="_blank">' . $site_url . '</a>',
123
+ $freemius_link
124
+ );
125
+ }
126
+ ?></p>
127
+ <?php if ( $require_license_key ) : ?>
128
+ <div class="fs-license-key-container">
129
+ <input id="fs_license_key" name="fs_key" type="text" required maxlength="32"
130
+ placeholder="<?php _efs( 'license-key', $slug ) ?>" tabindex="1"/>
131
+ <i class="dashicons dashicons-admin-network"></i>
132
+ </div>
133
+ <?php endif ?>
134
+ </div>
135
+ <div class="fs-actions">
136
+ <?php if ( $fs->is_enable_anonymous() && ! $is_pending_activation && ! $require_license_key ) : ?>
137
+ <a href="<?php echo wp_nonce_url( $fs->_get_admin_page_url( '', array( 'fs_action' => $slug . '_skip_activation' ) ), $slug . '_skip_activation' ) ?>"
138
+ class="button button-secondary" tabindex="2"><?php _efs( 'skip', $slug ) ?></a>
139
+ <?php endif ?>
140
+
141
+ <?php $fs_user = Freemius::_get_user_by_email( $current_user->user_email ) ?>
142
+ <?php if ( is_object( $fs_user ) && ! $is_pending_activation ) : ?>
143
+ <form action="" method="POST">
144
+ <input type="hidden" name="fs_action" value="<?php echo $slug ?>_activate_existing">
145
+ <?php wp_nonce_field( 'activate_existing_' . $fs->get_public_key() ) ?>
146
+ <button class="button button-primary" tabindex="1"
147
+ type="submit"<?php if ( $require_license_key ) {
148
+ echo ' disabled="disabled"';
149
+ } ?>><?php _efs( $button_label, $slug ) ?></button>
150
+ </form>
151
+ <?php else : ?>
152
+ <form method="post" action="<?php echo WP_FS__ADDRESS ?>/action/service/user/install/">
153
+ <?php $params = $fs->get_opt_in_params() ?>
154
+ <?php foreach ( $params as $name => $value ) : ?>
155
+ <input type="hidden" name="<?php echo $name ?>" value="<?php echo esc_attr( $value ) ?>">
156
+ <?php endforeach ?>
157
+ <button class="button button-primary" tabindex="1"
158
+ type="submit"<?php if ( $require_license_key ) {
159
+ echo ' disabled="disabled"';
160
+ } ?>><?php _efs( $button_label, $slug ) ?></button>
161
+ </form>
162
+ <?php endif ?>
163
+ </div><?php
164
+
165
+ // Set core permission list items.
166
+ $permissions = array(
167
+ 'profile' => array(
168
+ 'icon-class' => 'dashicons dashicons-admin-users',
169
+ 'label' => __fs( 'permissions-profile' ),
170
+ 'desc' => __fs( 'permissions-profile_desc' ),
171
+ 'priority' => 5,
172
+ ),
173
+ 'site' => array(
174
+ 'icon-class' => 'dashicons dashicons-admin-settings',
175
+ 'label' => __fs( 'permissions-site' ),
176
+ 'desc' => __fs( 'permissions-site_desc' ),
177
+ 'priority' => 10,
178
+ ),
179
+ 'events' => array(
180
+ 'icon-class' => 'dashicons dashicons-admin-plugins',
181
+ 'label' => __fs( 'permissions-events' ),
182
+ 'desc' => __fs( 'permissions-events_desc' ),
183
+ 'priority' => 20,
184
+ ),
185
+ // 'plugins_themes' => array(
186
+ // 'icon-class' => 'dashicons dashicons-admin-settings',
187
+ // 'label' => __fs( 'permissions-plugins_themes' ),
188
+ // 'desc' => __fs( 'permissions-plugins_themes_desc' ),
189
+ // 'priority' => 30,
190
+ // ),
191
+ );
192
+
193
+ // Add newsletter permissions if enabled.
194
+ if ( $fs->is_permission_requested( 'newsletter' ) ) {
195
+ $permissions['newsletter'] = array(
196
+ 'icon-class' => 'dashicons dashicons-email-alt',
197
+ 'label' => __fs( 'permissions-newsletter' ),
198
+ 'desc' => __fs( 'permissions-newsletter_desc' ),
199
+ 'priority' => 15,
200
+ );
201
+ }
202
+
203
+ // Allow filtering of the permissions list.
204
+ $permissions = $fs->apply_filters( 'permission_list', $permissions );
205
+
206
+ // Sort by priority.
207
+ uasort( $permissions, 'fs_sort_by_priority' );
208
+
209
+ if ( ! empty( $permissions ) ) : ?>
210
+ <div class="fs-permissions">
211
+ <?php if ( $require_license_key ) : ?>
212
+ <p class="fs-license-sync-disclaimer"><?php printf( __fs( 'license-sync-disclaimer', $slug ), $freemius_link ) ?></p>
213
+ <?php endif ?>
214
+ <a class="fs-trigger" href="#" tabindex="1"><?php _efs( 'what-permissions', $slug ) ?></a>
215
+ <ul><?php
216
+ foreach ( $permissions as $id => $permission ) : ?>
217
+ <li id="fs-permission-<?php esc_attr_e( $id ); ?>"
218
+ class="fs-permission fs-<?php esc_attr_e( $id ); ?>">
219
+ <i class="<?php esc_attr_e( $permission['icon-class'] ); ?>"></i>
220
+
221
+ <div>
222
+ <span><?php esc_html_e( $permission['label'] ); ?></span>
223
+
224
+ <p><?php esc_html_e( $permission['desc'] ); ?></p>
225
+ </div>
226
+ </li>
227
+ <?php endforeach; ?>
228
+ </ul>
229
+ </div>
230
+ <?php endif ?>
231
+ <?php if ( $is_premium_code && $is_freemium ) : ?>
232
+ <div class="fs-freemium-licensing">
233
+ <p>
234
+ <?php if ( $require_license_key ) : ?>
235
+ <?php _efs( 'dont-have-license-key', $slug ) ?>
236
+ <a data-require-license="false" tabindex="1"><?php _efs( 'activate-free-version', $slug ) ?></a>
237
+ <?php else : ?>
238
+ <?php _efs( 'have-license-key', $slug ) ?>
239
+ <a data-require-license="true" tabindex="1"><?php _efs( 'activate-license', $slug ) ?></a>
240
+ <?php endif ?>
241
+ </p>
242
+ </div>
243
+ <?php endif ?>
244
+ <div class="fs-terms">
245
+ <a href="https://freemius.com/privacy/" target="_blank"
246
+ tabindex="1"><?php _efs( 'privacy-policy', $slug ) ?></a>
247
+ &nbsp;&nbsp;-&nbsp;&nbsp;
248
+ <a href="https://freemius.com/terms/" target="_blank" tabindex="1"><?php _efs( 'tos', $slug ) ?></a>
249
+ </div>
250
+ </div>
251
+ <script type="text/javascript">
252
+ (function ($) {
253
+ var $primaryCta = $('.fs-actions .button.button-primary'),
254
+ $form = $('.fs-actions form'),
255
+ requireLicenseKey = <?php echo $require_license_key ? 'true' : 'false' ?>,
256
+ $licenseSecret,
257
+ $licenseKeyInput = $('#fs_license_key');
258
+
259
+ $('.fs-actions .button').on('click', function () {
260
+ // Set loading mode.
261
+ $(document.body).css({'cursor': 'wait'});
262
+ });
263
+
264
+ $form.on('submit', function () {
265
+ /**
266
+ * @author Vova Feldman (@svovaf)
267
+ * @since 1.1.9
268
+ */
269
+ if (requireLicenseKey) {
270
+ if (null == $licenseSecret) {
271
+ $licenseSecret = $('<input type="hidden" name="license_secret_key" value="" />');
272
+ $form.append($licenseSecret);
273
+ }
274
+
275
+ // Update secret key if premium only plugin.
276
+ $licenseSecret.val($licenseKeyInput.val());
277
+ }
278
+
279
+ return true;
280
+ });
281
+
282
+ $primaryCta.on('click', function () {
283
+ $(this).addClass('fs-loading');
284
+ $(this).html('<?php _efs( $is_pending_activation ? 'sending-email' : 'activating' , $slug ) ?>...').css({'cursor': 'wait'});
285
+ });
286
+
287
+ $('.fs-permissions .fs-trigger').on('click', function () {
288
+ $('.fs-permissions').toggleClass('fs-open');
289
+ });
290
+
291
+ if (requireLicenseKey) {
292
+ /**
293
+ * Submit license key on enter.
294
+ *
295
+ * @author Vova Feldman (@svovaf)
296
+ * @since 1.1.9
297
+ */
298
+ $licenseKeyInput.keypress(function (e) {
299
+ if (e.which == 13) {
300
+ if ('' !== $(this).val()) {
301
+ $primaryCta.click();
302
+ return false;
303
+ }
304
+ }
305
+ });
306
+
307
+ /**
308
+ * Disable activation button when empty license key.
309
+ *
310
+ * @author Vova Feldman (@svovaf)
311
+ * @since 1.1.9
312
+ */
313
+ $licenseKeyInput.on('keyup', function () {
314
+ if ('' === $(this).val()) {
315
+ $primaryCta.attr('disabled', 'disabled');
316
+ } else {
317
+ $primaryCta.prop('disabled', false);
318
+ }
319
+ }).focus();
320
+ }
321
+
322
+ /**
323
+ * Set license mode trigger URL.
324
+ *
325
+ * @author Vova Feldman (@svovaf)
326
+ * @since 1.1.9
327
+ */
328
+ var $connectLicenseModeTrigger = $('#fs_connect .fs-freemium-licensing a');
329
+ if ($connectLicenseModeTrigger.length > 0) {
330
+ $connectLicenseModeTrigger.attr('href', window.location.href + '&require_license=' + $connectLicenseModeTrigger.attr('data-require-license'))
331
+ }
332
+ })(jQuery);
333
+ </script>
freemius/templates/contact.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+ fs_enqueue_local_style( 'fs_checkout', '/admin/common.css' );
18
+
19
+ $slug = $VARS['slug'];
20
+ $fs = freemius( $slug );
21
+
22
+ $context_params = array(
23
+ 'plugin_id' => $fs->get_id(),
24
+ 'plugin_public_key' => $fs->get_public_key(),
25
+ 'plugin_version' => $fs->get_plugin_version(),
26
+ );
27
+
28
+
29
+ // Get site context secure params.
30
+ if ( $fs->is_registered() ) {
31
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
32
+ $fs->get_site(),
33
+ time(),
34
+ 'contact'
35
+ ) );
36
+ }
37
+
38
+ $query_params = array_merge( $_GET, array_merge( $context_params, array(
39
+ 'plugin_version' => $fs->get_plugin_version(),
40
+ 'wp_login_url' => wp_login_url(),
41
+ 'site_url' => get_site_url(),
42
+ // 'wp_admin_css' => get_bloginfo('wpurl') . "/wp-admin/load-styles.php?c=1&load=buttons,wp-admin,dashicons",
43
+ ) ) );
44
+ ?>
45
+ <div class="fs-secure-notice">
46
+ <i class="dashicons dashicons-lock"></i>
47
+ <span><b>Secure HTTPS contact page</b>, running via iframe from external domain</span>
48
+ </div>
49
+ <div id="fs_contact" class="wrap" style="margin: 40px 0 -65px -20px;">
50
+ <div id="iframe"></div>
51
+ <script type="text/javascript">
52
+ (function ($) {
53
+ $(function () {
54
+
55
+ var
56
+ // Keep track of the iframe height.
57
+ iframe_height = 800,
58
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
59
+ src = base_url + '/contact/?<?php echo http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
60
+
61
+ // Append the Iframe into the DOM.
62
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
63
+ .appendTo('#iframe');
64
+
65
+ FS.PostMessage.init(base_url);
66
+ FS.PostMessage.receive('height', function (data) {
67
+ var h = data.height;
68
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
69
+ iframe_height = h;
70
+ $("#iframe iframe").height(iframe_height + 'px');
71
+ }
72
+ });
73
+ });
74
+ })(jQuery);
75
+ </script>
76
+ </div>
77
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/deactivation-feedback-modal.php ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.2
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ $confirmation_message = $fs->apply_filters( 'uninstall_confirmation_message', '' );
17
+
18
+ $reasons = $VARS['reasons'];
19
+
20
+ $reasons_list_items_html = '';
21
+
22
+ foreach ( $reasons as $reason ) {
23
+ $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
24
+ $reasons_list_items_html .= '<li class="' . $list_item_classes . '" data-input-type="' . $reason['input_type'] . '" data-input-placeholder="' . $reason['input_placeholder'] . '"><label><span><input type="radio" name="selected-reason" value="' . $reason['id'] . '"/></span><span>' . $reason['text'] . '</span></label></li>';
25
+ }
26
+ ?>
27
+ <script type="text/javascript">
28
+ (function ($) {
29
+ var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ); ?>,
30
+ modalHtml =
31
+ '<div class="fs-modal<?php echo empty( $confirmation_message ) ? ' no-confirmation-message' : ''; ?>">'
32
+ + ' <div class="fs-modal-dialog">'
33
+ + ' <div class="fs-modal-body">'
34
+ + ' <div class="fs-modal-panel" data-panel-id="confirm"><p><?php echo $confirmation_message; ?></p></div>'
35
+ + ' <div class="fs-modal-panel active" data-panel-id="reasons"><h3><strong><?php printf( __fs( 'deactivation-share-reason' , $slug ) ); ?>:</strong></h3><ul id="reasons-list">' + reasonsHtml + '</ul></div>'
36
+ + ' </div>'
37
+ + ' <div class="fs-modal-footer">'
38
+ + ' <a href="#" class="button button-secondary button-deactivate"></a>'
39
+ + ' <a href="#" class="button button-primary button-close"><?php printf( __fs( 'deactivation-modal-button-cancel' , $slug ) ); ?></a>'
40
+ + ' </div>'
41
+ + ' </div>'
42
+ + '</div>',
43
+ $modal = $(modalHtml),
44
+ $deactivateLink = $('#the-list .deactivate > [data-slug=<?php echo $VARS['slug']; ?>].fs-slug').prev(),
45
+ selectedReasonID = false;
46
+
47
+ $modal.appendTo($('body'));
48
+
49
+ registerEventHandlers();
50
+
51
+ function registerEventHandlers() {
52
+ $deactivateLink.click(function (evt) {
53
+ evt.preventDefault();
54
+
55
+ showModal();
56
+ });
57
+
58
+ $modal.on('input propertychange', '.reason-input input', function () {
59
+ if (!isOtherReasonSelected()) {
60
+ return;
61
+ }
62
+
63
+ var reason = $(this).val().trim();
64
+
65
+ /**
66
+ * If reason is not empty, remove the error-message class of the message container
67
+ * to change the message color back to default.
68
+ */
69
+ if (reason.length > 0) {
70
+ $('.message').removeClass('error-message');
71
+ enableDeactivateButton();
72
+ }
73
+ });
74
+
75
+ $modal.on('blur', '.reason-input input', function () {
76
+ var $userReason = $(this);
77
+
78
+ setTimeout(function () {
79
+ if (!isOtherReasonSelected()) {
80
+ return;
81
+ }
82
+
83
+ /**
84
+ * If reason is empty, add the error-message class to the message container
85
+ * to change the message color to red.
86
+ */
87
+ if (0 === $userReason.val().trim().length) {
88
+ $('.message').addClass('error-message');
89
+ disableDeactivateButton();
90
+ }
91
+ }, 150);
92
+ });
93
+
94
+ $modal.on('click', '.button', function (evt) {
95
+ evt.preventDefault();
96
+
97
+ if ($(this).hasClass('disabled')) {
98
+ return;
99
+ }
100
+
101
+ var _parent = $(this).parents('.fs-modal:first');
102
+ var _this = $(this);
103
+
104
+ if (_this.hasClass('allow-deactivate')) {
105
+ var $radio = $('input[type="radio"]:checked');
106
+
107
+ if (0 === $radio.length) {
108
+ // If no selected reason, just deactivate the plugin.
109
+ window.location.href = $deactivateLink.attr('href');
110
+ return;
111
+ }
112
+
113
+ var $selected_reason = $radio.parents('li:first'),
114
+ $input = $selected_reason.find('textarea, input[type="text"]'),
115
+ userReason = ( 0 !== $input.length ) ? $input.val().trim() : '';
116
+
117
+ if (isOtherReasonSelected() && ( '' === userReason )) {
118
+ return;
119
+ }
120
+
121
+ $.ajax({
122
+ url : ajaxurl,
123
+ method : 'POST',
124
+ data : {
125
+ 'action' : 'submit-uninstall-reason',
126
+ 'reason_id' : $radio.val(),
127
+ 'reason_info': userReason
128
+ },
129
+ beforeSend: function () {
130
+ _parent.find('.button').addClass('disabled');
131
+ _parent.find('.button-secondary').text('Processing...');
132
+ },
133
+ complete : function () {
134
+ // Do not show the dialog box, deactivate the plugin.
135
+ window.location.href = $deactivateLink.attr('href');
136
+ }
137
+ });
138
+ } else if (_this.hasClass('button-deactivate')) {
139
+ // Change the Deactivate button's text and show the reasons panel.
140
+ _parent.find('.button-deactivate').addClass('allow-deactivate');
141
+
142
+ showPanel('reasons');
143
+ }
144
+ });
145
+
146
+ $modal.on('click', 'input[type="radio"]', function () {
147
+ var $selectedReasonOption = $(this);
148
+
149
+ // If the selection has not changed, do not proceed.
150
+ if (selectedReasonID === $selectedReasonOption.val())
151
+ return;
152
+
153
+ selectedReasonID = $selectedReasonOption.val();
154
+
155
+ var _parent = $(this).parents('li:first');
156
+
157
+ $modal.find('.reason-input').remove();
158
+ $modal.find('.button-deactivate').text('<?php printf( __fs( 'deactivation-modal-button-submit' , $slug ) ); ?>');
159
+
160
+ enableDeactivateButton();
161
+
162
+ if (_parent.hasClass('has-input')) {
163
+ var inputType = _parent.data('input-type'),
164
+ inputPlaceholder = _parent.data('input-placeholder'),
165
+ reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>';
166
+
167
+ _parent.append($(reasonInputHtml));
168
+ _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
169
+
170
+ if (isOtherReasonSelected()) {
171
+ showMessage('<?php printf( __fs( 'ask-for-reason-message' , $slug ) ); ?>');
172
+ disableDeactivateButton();
173
+ }
174
+ }
175
+ });
176
+
177
+ // If the user has clicked outside the window, cancel it.
178
+ $modal.on('click', function (evt) {
179
+ var $target = $(evt.target);
180
+
181
+ // If the user has clicked anywhere in the modal dialog, just return.
182
+ if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) {
183
+ return;
184
+ }
185
+
186
+ // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
187
+ if (!$target.hasClass('button-close') && ( $target.parents('.fs-modal-body').length > 0 || $target.parents('.fs-modal-footer').length > 0 )) {
188
+ return;
189
+ }
190
+
191
+ closeModal();
192
+ });
193
+ }
194
+
195
+ function isOtherReasonSelected() {
196
+ // Get the selected radio input element.
197
+ var $selectedReasonOption = $modal.find('input[type="radio"]:checked'),
198
+ selectedReason = $selectedReasonOption.parent().next().text().trim();
199
+
200
+ return ( 'Other' === selectedReason );
201
+ }
202
+
203
+ function showModal() {
204
+ resetModal();
205
+
206
+ // Display the dialog box.
207
+ $modal.addClass('active');
208
+
209
+ $('body').addClass('has-fs-modal');
210
+ }
211
+
212
+ function closeModal() {
213
+ $modal.removeClass('active');
214
+
215
+ $('body').removeClass('has-fs-modal');
216
+ }
217
+
218
+ function resetModal() {
219
+ selectedReasonID = false;
220
+
221
+ enableDeactivateButton();
222
+
223
+ // Uncheck all radio buttons.
224
+ $modal.find('input[type="radio"]').prop('checked', false);
225
+
226
+ // Remove all input fields ( textfield, textarea ).
227
+ $modal.find('.reason-input').remove();
228
+
229
+ $modal.find('.message').hide();
230
+
231
+ var $deactivateButton = $modal.find('.button-deactivate');
232
+
233
+ /*
234
+ * If the modal dialog has no confirmation message, that is, it has only one panel, then ensure
235
+ * that clicking the deactivate button will actually deactivate the plugin.
236
+ */
237
+ if ($modal.hasClass('no-confirmation-message')) {
238
+ $deactivateButton.addClass('allow-deactivate');
239
+
240
+ showPanel('reasons');
241
+ } else {
242
+ $deactivateButton.removeClass('allow-deactivate');
243
+
244
+ showPanel('confirm');
245
+ }
246
+ }
247
+
248
+ function showMessage(message) {
249
+ $modal.find('.message').text(message).show();
250
+ }
251
+
252
+ function enableDeactivateButton() {
253
+ $modal.find('.button-deactivate').removeClass('disabled');
254
+ }
255
+
256
+ function disableDeactivateButton() {
257
+ $modal.find('.button-deactivate').addClass('disabled');
258
+ }
259
+
260
+ function showPanel(panelType) {
261
+ $modal.find('.fs-modal-panel').removeClass('active ');
262
+ $modal.find('[data-panel-id="' + panelType + '"]').addClass('active');
263
+
264
+ updateButtonLabels();
265
+ }
266
+
267
+ function updateButtonLabels() {
268
+ var $deactivateButton = $modal.find('.button-deactivate');
269
+
270
+ // Reset the deactivate button's text.
271
+ if ('confirm' === getCurrentPanel()) {
272
+ $deactivateButton.text('<?php printf( __fs( 'deactivation-modal-button-confirm' , $slug ) ); ?>');
273
+ } else {
274
+ $deactivateButton.text('<?php printf( __fs( 'skip-deactivate' , $slug ) ); ?>');
275
+ }
276
+ }
277
+
278
+ function getCurrentPanel() {
279
+ return $modal.find('.fs-modal-panel.active').attr('data-panel-id');
280
+ }
281
+ })(jQuery);
282
+ </script>
freemius/templates/debug.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ global $fs_active_plugins;
14
+
15
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
16
+ ?>
17
+ <h1><?php echo __fs( 'Freemius Debug' ) . ' - ' . __fs( 'SDK' ) . ' v.' . $fs_active_plugins->newest->version ?></h1>
18
+ <div>
19
+ <!-- Debugging Switch -->
20
+ <?php //$debug_mode = get_option( 'fs_debug_mode', null ) ?>
21
+ <span class="switch-label"><?php _efs( 'debugging' ) ?></span>
22
+
23
+ <div class="switch <?php echo WP_FS__DEBUG_SDK ? 'off' : 'on' ?>">
24
+ <div class="toggle"></div>
25
+ <span class="on"><?php _efs( 'on' ) ?></span>
26
+ <span class="off"><?php _efs( 'off' ) ?></span>
27
+ </div>
28
+ <script type="text/javascript">
29
+ (function ($) {
30
+ $(document).ready(function () {
31
+ // Switch toggle
32
+ $('.switch').click(function () {
33
+ $(this)
34
+ .toggleClass('on')
35
+ .toggleClass('off');
36
+
37
+ $.post(ajaxurl, {
38
+ action: 'fs_toggle_debug_mode',
39
+ is_on : ($(this).hasClass('off') ? 1 : 0)
40
+ }, function (response) {
41
+ if (1 == response) {
42
+ // Refresh page on success.
43
+ location.reload();
44
+ }
45
+ });
46
+ });
47
+ });
48
+ }(jQuery));
49
+ </script>
50
+ </div>
51
+ <h2><?php _efs( 'actions' ) ?></h2>
52
+ <table>
53
+ <tbody>
54
+ <tr>
55
+ <td>
56
+ <!-- Delete All Accounts -->
57
+ <form action="" method="POST">
58
+ <input type="hidden" name="fs_action" value="restart_freemius">
59
+ <?php wp_nonce_field( 'restart_freemius' ) ?>
60
+ <button class="button button-primary"
61
+ onclick="if (confirm('<?php _efs( 'delete-all-confirm' ) ?>')) this.parentNode.submit(); return false;"><?php _efs( 'delete-all-accounts' ) ?></button>
62
+ </form>
63
+ </td>
64
+ <td>
65
+ <!-- Clear API Cache -->
66
+ <form action="" method="POST">
67
+ <input type="hidden" name="fs_clear_api_cache" value="true">
68
+ <button class="button button-primary"><?php _efs( 'clear-api-cache' ) ?></button>
69
+ </form>
70
+ </td>
71
+ <td>
72
+ <!-- Sync Data with Server -->
73
+ <form action="" method="POST">
74
+ <input type="hidden" name="background_sync" value="true">
75
+ <button class="button button-primary"><?php _efs( 'sync-data-from-server' ) ?></button>
76
+ </form>
77
+ </td>
78
+ </tr>
79
+ </tbody>
80
+ </table>
81
+ <h2><?php _efs( 'sdk-versions' ) ?></h2>
82
+ <table id="fs_sdks" class="widefat">
83
+ <thead>
84
+ <tr>
85
+ <th><?php _efs( 'version' ) ?></th>
86
+ <th><?php _efs( 'sdk-path' ) ?></th>
87
+ <th><?php _efs( 'plugin-path' ) ?></th>
88
+ <th><?php _efs( 'is-active' ) ?></th>
89
+ </tr>
90
+ </thead>
91
+ <tbody>
92
+ <?php foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) : ?>
93
+ <?php $is_active = ( WP_FS__SDK_VERSION == $data->version ) ?>
94
+ <tr<?php if ( $is_active ) {
95
+ echo ' style="background: #E6FFE6; font-weight: bold"';
96
+ } ?>>
97
+ <td><?php echo $data->version ?></td>
98
+ <td><?php echo $sdk_path ?></td>
99
+ <td><?php echo $data->plugin_path ?></td>
100
+ <td><?php echo ( $is_active ) ? 'Active' : 'Inactive' ?></td>
101
+ </tr>
102
+ <?php endforeach ?>
103
+ </tbody>
104
+ </table>
105
+ <?php $plugins = $fs_options->get_option( 'plugins' ) ?>
106
+ <?php if ( is_array( $plugins ) && 0 < count( $plugins ) ) : ?>
107
+ <h2><?php _efs( 'plugins' ) ?></h2>
108
+ <table id="fs_plugins" class="widefat">
109
+ <thead>
110
+ <tr>
111
+ <th><?php _efs( 'id' ) ?></th>
112
+ <th><?php _efs( 'slug' ) ?></th>
113
+ <th><?php _efs( 'version' ) ?></th>
114
+ <th><?php _efs( 'title' ) ?></th>
115
+ <th><?php _efs( 'api' ) ?></th>
116
+ <th><?php _efs( 'freemius-state' ) ?></th>
117
+ <th><?php _efs( 'plugin-path' ) ?></th>
118
+ <th><?php _efs( 'public-key' ) ?></th>
119
+ </tr>
120
+ </thead>
121
+ <tbody>
122
+ <?php foreach ( $plugins as $slug => $data ) : ?>
123
+ <?php $is_active = is_plugin_active( $data->file ) ?>
124
+ <?php $fs = $is_active ? freemius( $slug ) : null ?>
125
+ <tr<?php if ( $is_active ) {
126
+ echo ' style="background: #E6FFE6; font-weight: bold"';
127
+ } ?>>
128
+ <td><?php echo $data->id ?></td>
129
+ <td><?php echo $slug ?></td>
130
+ <td><?php echo $data->version ?></td>
131
+ <td><?php echo $data->title ?></td>
132
+ <td><?php if ( $is_active ) {
133
+ echo $fs->has_api_connectivity() ?
134
+ __fs( 'connected' ) :
135
+ __fs( 'blocked' );
136
+ } ?></td>
137
+ <td><?php if ( $is_active ) {
138
+ echo $fs->is_on() ?
139
+ __fs( 'on' ) :
140
+ __fs( 'off' );
141
+ } ?></td>
142
+ <td><?php echo $data->file ?></td>
143
+ <td><?php echo $data->public_key ?></td>
144
+ </tr>
145
+ <?php endforeach ?>
146
+ </tbody>
147
+ </table>
148
+ <?php endif ?>
149
+ <?php
150
+ /**
151
+ * @var FS_Site[] $sites
152
+ */
153
+ $sites = $VARS['sites'];
154
+ ?>
155
+ <?php if ( is_array( $sites ) && 0 < count( $sites ) ) : ?>
156
+ <h2><?php _efs( 'plugin-installs' ) ?> / <?php _efs( 'sites' ) ?></h2>
157
+ <table id="fs_installs" class="widefat">
158
+ <thead>
159
+ <tr>
160
+ <th><?php _efs( 'id' ) ?></th>
161
+ <th><?php _efs( 'slug' ) ?></th>
162
+ <th><?php _efs( 'plan' ) ?></th>
163
+ <th><?php _efs( 'public-key' ) ?></th>
164
+ <th><?php _efs( 'secret-key' ) ?></th>
165
+ </tr>
166
+ </thead>
167
+ <tbody>
168
+ <?php foreach ( $sites as $slug => $site ) : ?>
169
+ <tr>
170
+ <td><?php echo $site->id ?></td>
171
+ <td><?php echo $slug ?></td>
172
+ <td><?php
173
+ echo is_object( $site->plan ) ?
174
+ base64_decode( $site->plan->name ) :
175
+ ''
176
+ ?></td>
177
+ <td><?php echo $site->public_key ?></td>
178
+ <td><?php echo $site->secret_key ?></td>
179
+ </tr>
180
+ <?php endforeach ?>
181
+ </tbody>
182
+ </table>
183
+ <?php endif ?>
184
+ <?php
185
+ $addons = $VARS['addons'];
186
+ ?>
187
+ <?php foreach ( $addons as $plugin_id => $plugin_addons ) : ?>
188
+ <h2><?php printf( __fs( 'addons-of-x' ), $plugin_id ) ?></h2>
189
+ <table id="fs_addons" class="widefat">
190
+ <thead>
191
+ <tr>
192
+ <th><?php _efs( 'id' ) ?></th>
193
+ <th><?php _efs( 'title' ) ?></th>
194
+ <th><?php _efs( 'slug' ) ?></th>
195
+ <th><?php _efs( 'version' ) ?></th>
196
+ <th><?php _efs( 'public-key' ) ?></th>
197
+ <th><?php _efs( 'secret-key' ) ?></th>
198
+ </tr>
199
+ </thead>
200
+ <tbody>
201
+ <?php
202
+ /**
203
+ * @var FS_Plugin[] $plugin_addons
204
+ */
205
+ foreach ( $plugin_addons as $addon ) : ?>
206
+ <tr>
207
+ <td><?php echo $addon->id ?></td>
208
+ <td><?php echo $addon->title ?></td>
209
+ <td><?php echo $addon->slug ?></td>
210
+ <td><?php echo $addon->version ?></td>
211
+ <td><?php echo $addon->public_key ?></td>
212
+ <td><?php echo $addon->secret_key ?></td>
213
+ </tr>
214
+ <?php endforeach ?>
215
+ </tbody>
216
+ </table>
217
+ <?php endforeach ?>
218
+ <?php
219
+ /**
220
+ * @var FS_User[] $users
221
+ */
222
+ $users = $VARS['users'];
223
+ ?>
224
+ <?php if ( is_array( $users ) && 0 < count( $users ) ) : ?>
225
+ <h2><?php _efs( 'users' ) ?></h2>
226
+ <table id="fs_users" class="widefat">
227
+ <thead>
228
+ <tr>
229
+ <th><?php _efs( 'id' ) ?></th>
230
+ <th><?php _efs( 'name' ) ?></th>
231
+ <th><?php _efs( 'email' ) ?></th>
232
+ <th><?php _efs( 'verified' ) ?></th>
233
+ <th><?php _efs( 'public-key' ) ?></th>
234
+ <th><?php _efs( 'secret-key' ) ?></th>
235
+ </tr>
236
+ </thead>
237
+ <tbody>
238
+ <?php foreach ( $users as $user_id => $user ) : ?>
239
+ <tr>
240
+ <td><?php echo $user->id ?></td>
241
+ <td><?php echo $user->get_name() ?></td>
242
+ <td><a href="mailto:<?php esc_attr_e($user->email) ?>"><?php echo $user->email ?></a></td>
243
+ <td><?php echo json_encode( $user->is_verified ) ?></td>
244
+ <td><?php echo $user->public_key ?></td>
245
+ <td><?php echo $user->secret_key ?></td>
246
+ </tr>
247
+ <?php endforeach ?>
248
+ </tbody>
249
+ </table>
250
+ <?php endif ?>
freemius/templates/debug/api-calls.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( class_exists( 'Freemius_Api' ) ) {
14
+ $logger = Freemius_Api::GetLogger();
15
+ } else {
16
+ $logger = array();
17
+ }
18
+
19
+ $counters = array(
20
+ 'GET' => 0,
21
+ 'POST' => 0,
22
+ 'PUT' => 0,
23
+ 'DELETE' => 0
24
+ );
25
+
26
+ $show_body = false;
27
+ foreach ( $logger as $log ) {
28
+ $counters[ $log['method'] ] ++;
29
+
30
+ if ( ! is_null( $log['body'] ) ) {
31
+ $show_body = true;
32
+ }
33
+ }
34
+
35
+ $pretty_print = $show_body && defined( 'JSON_PRETTY_PRINT' ) && version_compare( phpversion(), '5.3', '>=' );
36
+
37
+ $root_path_len = strlen( ABSPATH );
38
+ ?>
39
+ <h1><?php _efs( 'API' ) ?></h1>
40
+
41
+ <h2><span>Total Time:</span><?php echo Freemius_Debug_Bar_Panel::total_time() ?></h2>
42
+
43
+ <h2><span>Total Requests:</span><?php echo Freemius_Debug_Bar_Panel::requests_count() ?></h2>
44
+ <?php foreach ( $counters as $method => $count ) : ?>
45
+ <h2><span><?php echo $method ?>:</span><?php echo number_format( $count ) ?></h2>
46
+ <?php endforeach ?>
47
+ <table class="widefat">
48
+ <thead>
49
+ <tr>
50
+ <th>#</th>
51
+ <th><?php _efs( 'Method' ) ?></th>
52
+ <th><?php _efs( 'Code' ) ?></th>
53
+ <th><?php _efs( 'Length' ) ?></th>
54
+ <th><?php _efs( 'Path' ) ?></th>
55
+ <?php if ( $show_body ) : ?>
56
+ <th><?php _efs( 'Body' ) ?></th>
57
+ <?php endif ?>
58
+ <th><?php _efs( 'Result' ) ?></th>
59
+ <th><?php _efs( 'Start' ) ?></th>
60
+ <th><?php _efs( 'End' ) ?></th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <?php foreach ( $logger as $log ) : ?>
65
+ <tr>
66
+ <td><?php echo $log['id'] ?>.</td>
67
+ <td><?php echo $log['method'] ?></td>
68
+ <td><?php echo $log['code'] ?></td>
69
+ <td><?php echo number_format( 100 * $log['total'], 2 ) . ' ' . __fs( 'ms' ) ?></td>
70
+ <td>
71
+ <?php
72
+ printf( '<a href="#" onclick="jQuery(this).parent().find(\'table\').toggle(); return false;">%s</a>',
73
+ $log['path']
74
+ );
75
+ ?>
76
+ <table class="widefat" style="display: none">
77
+ <tbody>
78
+ <?php for ( $i = 0, $bt = $log['backtrace'], $len = count( $bt ); $i < $len; $i ++ ) : ?>
79
+ <tr>
80
+ <td><?php echo( $len - $i ) ?></td>
81
+ <td><?php if ( isset( $bt[ $i ]['function'] ) ) {
82
+ echo ( isset( $bt[ $i ]['class'] ) ? $bt[ $i ]['class'] . $bt[ $i ]['type'] : '' ) . $bt[ $i ]['function'];
83
+ } ?></td>
84
+ <td><?php if ( isset( $bt[ $i ]['file'] ) ) {
85
+ echo substr( $bt[ $i ]['file'], $root_path_len ) . ':' . $bt[ $i ]['line'];
86
+ } ?></td>
87
+ </tr>
88
+ <?php endfor ?>
89
+ </tbody>
90
+ </table>
91
+ </td>
92
+ <?php if ( $show_body ) : ?>
93
+ <td>
94
+ <?php if ( 'GET' !== $log['method'] ) : ?>
95
+ <?php
96
+ $body = $log['body'];
97
+ printf(
98
+ '<a href="#" onclick="jQuery(this).parent().find(\'pre\').toggle(); return false;">%s</a>',
99
+ substr( $body, 0, 32 ) . ( 32 < strlen( $body ) ? '...' : '' )
100
+ );
101
+ if ( $pretty_print ) {
102
+ $body = json_encode( json_decode( $log['body'] ), JSON_PRETTY_PRINT );
103
+ }
104
+ ?>
105
+ <pre style="display: none"><code><?php echo esc_html( $body ) ?></code></pre>
106
+ <?php endif ?>
107
+ </td>
108
+ <?php endif ?>
109
+ <td>
110
+ <?php
111
+ $result = $log['result'];
112
+
113
+ $is_not_empty_result = ( is_string( $result ) && ! empty( $result ) );
114
+
115
+ if ( $is_not_empty_result ) {
116
+ printf(
117
+ '<a href="#" onclick="jQuery(this).parent().find(\'pre\').toggle(); return false;">%s</a>',
118
+ substr( $result, 0, 32 ) . ( 32 < strlen( $result ) ? '...' : '' )
119
+ );
120
+ }
121
+
122
+ if ( $is_not_empty_result && $pretty_print ) {
123
+ $decoded = json_decode( $result );
124
+ if ( ! is_null( $decoded ) ) {
125
+ $result = json_encode( $decoded, JSON_PRETTY_PRINT );
126
+ }
127
+ } else {
128
+ $result = is_string( $result ) ? $result : json_encode( $result );
129
+ }
130
+ ?>
131
+ <pre<?php if ( $is_not_empty_result ) : ?> style="display: none"<?php endif ?>><code><?php echo esc_html( $result ) ?></code></pre>
132
+ </td>
133
+ <td><?php echo number_format( 100 * ( $log['start'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
134
+ <td><?php echo number_format( 100 * ( $log['end'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
135
+ </tr>
136
+ <?php endforeach ?>
137
+ </tbody>
138
+ </table>
freemius/templates/debug/logger.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $log_book = FS_Logger::get_log();
14
+ ?>
15
+ <h1><?php _efs( 'Log' ) ?></h1>
16
+
17
+ <table class="widefat" style="font-size: 11px;">
18
+ <thead>
19
+ <tr>
20
+ <th>#</th>
21
+ <th><?php _efs( 'id' ) ?></th>
22
+ <th><?php _efs( 'type' ) ?></th>
23
+ <th><?php _efs( 'function' ) ?></th>
24
+ <th><?php _efs( 'message' ) ?></th>
25
+ <th><?php _efs( 'file' ) ?></th>
26
+ <th><?php _efs( 'timestamp' ) ?></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+
31
+ <?php $i = 0;
32
+ foreach ( $log_book as $log ) : ?>
33
+ <tr<?php if ( $i % 2 ) {
34
+ echo ' class="alternate"';
35
+ } ?>>
36
+ <td><?php echo $log['cnt'] ?>.</td>
37
+ <td><?php echo $log['logger']->get_id() ?></td>
38
+ <td><?php echo $log['type'] ?></td>
39
+ <td><b><code style="color: blue;"><?php echo $log['function'] ?></code></b></td>
40
+ <td>
41
+ <?php
42
+ printf(
43
+ '<a href="#" style="color: darkorange !important;" onclick="jQuery(this).parent().find(\'div\').toggle(); return false;"><nobr>%s</nobr></a>',
44
+ substr( $log['msg'], 0, 32 ) . ( 32 < strlen( $log['msg'] ) ? '...' : '' )
45
+ );
46
+ ?>
47
+ <div style="display: none;">
48
+ <b style="color: darkorange;"><?php echo $log['msg'] ?></b>
49
+ </div>
50
+ </td>
51
+ <td><?php
52
+ if ( isset( $log['file'] ) ) {
53
+ echo substr( $log['file'], $log['logger']->get_file() ) . ':' . $log['line'] . ')';
54
+ }
55
+ ?></td>
56
+ <td><?php echo number_format( 100 * ( $log['timestamp'] - WP_FS__SCRIPT_START_TIME ), 2 ) . ' ' . __fs( 'ms' ) ?></td>
57
+ </tr>
58
+ <?php $i ++; endforeach ?>
59
+ </tbody>
60
+ </table>
freemius/templates/debug/plugins-themes-sync.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
14
+ $all_plugins = $fs_options->get_option( 'all_plugins' );
15
+ $all_themes = $fs_options->get_option( 'all_themes' );
16
+ ?>
17
+ <h1><?php _efs( 'plugins-themes-sync' ) ?></h1>
18
+ <table class="widefat">
19
+ <thead>
20
+ <tr>
21
+ <th></th>
22
+ <th><?php _efs( 'total' ) ?></th>
23
+ <th><?php _efs( 'Last' ) ?></th>
24
+ </tr>
25
+ </thead>
26
+ <tbody>
27
+ <?php if ( is_object( $all_plugins ) ) : ?>
28
+ <tr>
29
+ <td><?php _efs( 'plugins' ) ?></td>
30
+ <td><?php echo count( $all_plugins->plugins ) ?></td>
31
+ <td><?php
32
+ if ( isset( $all_plugins->timestamp ) && is_numeric( $all_plugins->timestamp ) ) {
33
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $all_plugins->timestamp );
34
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
35
+ $diff . ' ' . __fs( 'sec' ) :
36
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $all_plugins->timestamp );
37
+
38
+ if ( WP_FS__SCRIPT_START_TIME < $all_plugins->timestamp ) {
39
+ printf( __fs( 'in-x' ), $human_diff );
40
+ } else {
41
+ printf( __fs( 'x-ago' ), $human_diff );
42
+ }
43
+ }
44
+ ?></td>
45
+ </tr>
46
+ <?php endif ?>
47
+ <?php if ( is_object( $all_themes ) ) : ?>
48
+ <tr>
49
+ <td><?php _efs( 'themes' ) ?></td>
50
+ <td><?php echo count( $all_themes->themes ) ?></td>
51
+ <td><?php
52
+ if ( isset( $all_themes->timestamp ) && is_numeric( $all_themes->timestamp ) ) {
53
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $all_themes->timestamp );
54
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
55
+ $diff . ' ' . __fs( 'sec' ) :
56
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $all_themes->timestamp );
57
+
58
+ if ( WP_FS__SCRIPT_START_TIME < $all_themes->timestamp ) {
59
+ printf( __fs( 'in-x' ), $human_diff );
60
+ } else {
61
+ printf( __fs( 'x-ago' ), $human_diff );
62
+ }
63
+ }
64
+ ?></td>
65
+ </tr>
66
+ <?php endif ?>
67
+ </tbody>
68
+ </table>
freemius/templates/debug/scheduled-crons.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.7.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $fs_options = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
14
+ $plugins = $fs_options->get_option( 'plugins' );
15
+ $scheduled_crons = array();
16
+ if ( is_array( $plugins ) && 0 < count( $plugins ) ) {
17
+ foreach ( $plugins as $slug => $data ) {
18
+ $fs = freemius( $slug );
19
+
20
+ $next_execution = $fs->next_sync_cron();
21
+ $last_execution = $fs->last_sync_cron();
22
+
23
+ if ( false !== $next_execution ) {
24
+ $scheduled_crons[ $slug ][] = array(
25
+ 'name' => $fs->get_plugin_name(),
26
+ 'slug' => $slug,
27
+ 'type' => 'sync_cron',
28
+ 'last' => $last_execution,
29
+ 'next' => $next_execution,
30
+ );
31
+ }
32
+
33
+ $next_install_execution = $fs->next_install_sync();
34
+ $last_install_execution = $fs->last_install_sync();
35
+
36
+ if ( false !== $next_install_execution || false !== $last_install_execution ) {
37
+ $scheduled_crons[ $slug ][] = array(
38
+ 'name' => $fs->get_plugin_name(),
39
+ 'slug' => $slug,
40
+ 'type' => 'install_sync',
41
+ 'last' => $last_install_execution,
42
+ 'next' => $next_install_execution,
43
+ );
44
+ }
45
+ }
46
+ }
47
+ ?>
48
+ <h1><?php _efs( 'scheduled-crons' ) ?></h1>
49
+ <table class="widefat">
50
+ <thead>
51
+ <tr>
52
+ <th><?php _efs( 'slug' ) ?></th>
53
+ <th><?php _efs( 'plugin' ) ?></th>
54
+ <th><?php _efs( 'type' ) ?></th>
55
+ <th><?php _efs( 'Last' ) ?></th>
56
+ <th><?php _efs( 'Next' ) ?></th>
57
+ </tr>
58
+ </thead>
59
+ <tbody>
60
+ <?php foreach ( $scheduled_crons as $slug => $crons ) : ?>
61
+ <?php foreach ( $crons as $cron ) : ?>
62
+ <tr>
63
+ <td><?php echo $slug ?></td>
64
+ <td><?php echo $cron['name'] ?></td>
65
+ <td><?php echo $cron['type'] ?></td>
66
+ <td><?php
67
+ if (is_numeric($cron['last'])) {
68
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $cron['last'] );
69
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
70
+ $diff . ' ' . __fs( 'sec' ) :
71
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $cron['last'] );
72
+
73
+ if ( WP_FS__SCRIPT_START_TIME < $cron['last'] ) {
74
+ printf( __fs( 'in-x' ), $human_diff );
75
+ } else {
76
+ printf( __fs( 'x-ago' ), $human_diff );
77
+ }
78
+
79
+ // echo ' ' . $cron['last'];
80
+ }
81
+ ?></td>
82
+ <td><?php
83
+ if (is_numeric($cron['next'])) {
84
+ $diff = abs( WP_FS__SCRIPT_START_TIME - $cron['next'] );
85
+ $human_diff = ( $diff < MINUTE_IN_SECONDS ) ?
86
+ $diff . ' ' . __fs( 'sec' ) :
87
+ human_time_diff( WP_FS__SCRIPT_START_TIME, $cron['next'] );
88
+
89
+ if ( WP_FS__SCRIPT_START_TIME < $cron['next'] ) {
90
+ printf( __fs( 'in-x' ), $human_diff );
91
+ } else {
92
+ printf( __fs( 'x-ago' ), $human_diff );
93
+ }
94
+ }
95
+ ?></td>
96
+ </tr>
97
+ <?php endforeach ?>
98
+ <?php endforeach ?>
99
+ </tbody>
100
+ </table>
freemius/templates/email.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.1
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $sections = $VARS['sections'];
14
+ ?>
15
+ <table>
16
+ <?php
17
+ foreach ( $sections as $section_id => $section ) {
18
+ ?>
19
+ <thead>
20
+ <tr><th colspan="2" style="text-align: left; background: #333; color: #fff; padding: 5px;"><?php echo $section['title']; ?></th></tr>
21
+ </thead>
22
+ <tbody>
23
+ <?php
24
+ foreach ( $section['rows'] as $row_id => $row ) {
25
+ $col_count = count( $row );
26
+ ?>
27
+ <tr>
28
+ <?php
29
+ if ( 1 === $col_count ) { ?>
30
+ <td style="vertical-align: top;" colspan="2"><?php echo $row[0]; ?></td>
31
+ <?php
32
+ } else { ?>
33
+ <td style="vertical-align: top;"><b><?php echo $row[0]; ?>:</b></td>
34
+ <td><?php echo $row[1]; ?></td>
35
+ <?php
36
+ }
37
+ ?>
38
+ </tr>
39
+ <?php
40
+ }
41
+ ?>
42
+ </tbody>
43
+ <?php
44
+ }
45
+ ?>
46
+ </table>
freemius/templates/firewall-issues-js.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * API connectivity issues (CloudFlare's firewall) handler for handling different
4
+ * scenarios selected by the user after connectivity issue is detected, by sending
5
+ * AJAX call to the server in order to make the actual actions.
6
+ *
7
+ * @package Freemius
8
+ * @copyright Copyright (c) 2015, Freemius, Inc.
9
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10
+ * @since 1.0.9
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) {
14
+ exit;
15
+ }
16
+ ?>
17
+ <script type="text/javascript">
18
+ jQuery(document).ready(function ($) {
19
+ $('#fs_firewall_issue_options a.fs-resolve').click(function () {
20
+ var
21
+ error_type = $(this).attr('data-type'),
22
+ notice = $(this).parents('.fs-notice'),
23
+ slug = notice.attr('data-slug');
24
+
25
+ var data = {
26
+ action : slug + '_resolve_firewall_issues',
27
+ slug : slug,
28
+ error_type: error_type
29
+ };
30
+
31
+ if ('squid' === error_type) {
32
+ data.hosting_company = prompt('What is the name or URL of your hosting company?');
33
+ if (null == data.hosting_company)
34
+ return false;
35
+
36
+ if ('' === data.hosting_company) {
37
+ alert('We won\'t be able to help without knowing your hosting company.');
38
+ return false;
39
+ }
40
+ }
41
+
42
+ if ('retry_ping' === error_type) {
43
+ data.action = slug + '_retry_connectivity_test';
44
+ }
45
+
46
+ $(this).css({'cursor': 'wait'});
47
+
48
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
49
+ $.post(ajaxurl, data, function (response) {
50
+ if (1 == response) {
51
+ // Refresh page on success.
52
+ location.reload();
53
+ } else if ('http' === response.substr(0, 4)) {
54
+ // Ping actually worked, redirect.
55
+ window.location = response;
56
+ }
57
+ });
58
+ });
59
+ });
60
+ </script>
freemius/templates/license-activation-modal.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.9
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ $message_above_input_field = __fs( 'activate-license-message', $slug );
17
+ $message_below_input_field = '';
18
+
19
+ if ( $fs->is_registered() ) {
20
+ $activate_button_text = __fs( $fs->is_free_plan() ? 'activate-license' : 'update-license', $slug );
21
+ } else {
22
+ $freemius_site_url = $fs->has_paid_plan() ?
23
+ 'https://freemius.com/wordpress/' :
24
+ // Insights platform information.
25
+ 'https://freemius.com/wordpress/usage-tracking/';
26
+
27
+ $freemius_link = '<a href="' . $freemius_site_url . '" target="_blank">freemius.com</a>';
28
+
29
+ $message_below_input_field = sprintf( __fs( 'license-sync-disclaimer', $slug ), $freemius_link );
30
+
31
+ $activate_button_text = __fs( 'agree-activate-license', $slug );
32
+ }
33
+
34
+ $license_key_text = __fs( 'license-key' , $slug );
35
+
36
+ $modal_content_html = <<< HTML
37
+ <p>{$message_above_input_field}</p>
38
+ <input class="license_key" type="text" placeholder="{$license_key_text}" />
39
+ <p>{$message_below_input_field}</p>
40
+ HTML;
41
+ ?>
42
+ <script type="text/javascript">
43
+ (function( $ ) {
44
+ $( document ).ready(function() {
45
+ var modalContentHtml = <?php echo json_encode($modal_content_html); ?>,
46
+ modalHtml =
47
+ '<div class="fs-modal">'
48
+ + ' <div class="fs-modal-dialog">'
49
+ + ' <div class="fs-modal-body">'
50
+ + ' <div class="fs-modal-panel active">' + modalContentHtml + '</div>'
51
+ + ' </div>'
52
+ + ' <div class="fs-modal-footer">'
53
+ + ' <a href="#" class="button button-secondary button-close"><?php _efs('deactivation-modal-button-cancel', $slug); ?></a>'
54
+ + ' <a href="#" class="button button-primary button-activate-license"><?php echo $activate_button_text; ?></a>'
55
+ + ' </div>'
56
+ + ' </div>'
57
+ + '</div>',
58
+ $modal = $(modalHtml),
59
+ $activateLicenseLink = $('span.activate-license.<?php echo $VARS['slug']; ?>').find('a');
60
+
61
+ $modal.appendTo($('body'));
62
+
63
+ registerEventHandlers();
64
+
65
+ function registerEventHandlers() {
66
+ $activateLicenseLink.click(function (evt) {
67
+ evt.preventDefault();
68
+
69
+ showModal();
70
+ });
71
+
72
+ $modal.on('input propertychange', 'input.license_key', function () {
73
+
74
+ var licenseKey = $(this).val().trim();
75
+
76
+ /**
77
+ * If license key is not empty, enable the license activation button.
78
+ */
79
+ if (licenseKey.length > 0) {
80
+ enableActivateLicenseButton();
81
+ }
82
+ });
83
+
84
+ $modal.on('blur', 'input.license_key', function () {
85
+ var licenseKey = $(this).val().trim();
86
+
87
+ /**
88
+ * If license key is empty, disable the license activation button.
89
+ */
90
+ if (0 === licenseKey.length) {
91
+ disableActivateLicenseButton();
92
+ }
93
+ });
94
+
95
+ $modal.on('click', '.button', function (evt) {
96
+ evt.preventDefault();
97
+
98
+ if ($(this).hasClass('disabled')) {
99
+ return;
100
+ }
101
+
102
+ var
103
+ activateButton = $('.button-activate-license'),
104
+ licenseKey = $('input.license_key').val().trim();
105
+
106
+ activateButton.addClass('disabled');
107
+
108
+ if (0 === licenseKey.length) {
109
+ return;
110
+ }
111
+
112
+ $.ajax({
113
+ url: ajaxurl,
114
+ method: 'POST',
115
+ data: {
116
+ 'action': 'activate-license',
117
+ 'license-key': licenseKey
118
+ },
119
+ beforeSend: function () {
120
+ activateButton.text('<?php _efs('activating-license', $slug); ?>');
121
+ },
122
+ complete: function () {
123
+ closeModal();
124
+ }
125
+ });
126
+ });
127
+
128
+ // If the user has clicked outside the window, close the modal.
129
+ $modal.on('click', function (evt) {
130
+ var $target = $(evt.target);
131
+
132
+ // If the user has clicked anywhere in the modal dialog, just return.
133
+ if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) {
134
+ return;
135
+ }
136
+
137
+ // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
138
+ if (( !$target.hasClass('button-close') ) && ( $target.parents('.fs-modal-body').length > 0 || $target.parents('.fs-modal-footer').length > 0 )) {
139
+ return;
140
+ }
141
+
142
+ closeModal();
143
+ });
144
+ }
145
+
146
+ function showModal() {
147
+ resetModal();
148
+
149
+ // Display the dialog box.
150
+ $modal.addClass('active');
151
+ $('body').addClass('has-fs-modal');
152
+
153
+ $('input.license_key').focus();
154
+ }
155
+
156
+ function closeModal() {
157
+ $modal.removeClass('active');
158
+ $('body').removeClass('has-fs-modal');
159
+ }
160
+
161
+ function resetModal() {
162
+ $('input.license_key').val('');
163
+
164
+ enableActivateLicenseButton();
165
+ $modal.find('.button-activate-license').text('<?php echo $activate_button_text; ?>');
166
+ }
167
+
168
+ function enableActivateLicenseButton() {
169
+ $modal.find('.button-activate-license').removeClass('disabled');
170
+ }
171
+
172
+ function disableActivateLicenseButton() {
173
+ $modal.find('.button-activate-license').addClass('disabled');
174
+ }
175
+ });
176
+ })( jQuery );
177
+ </script>
freemius/templates/plugin-icon.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.1.4
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ $slug = $VARS['slug'];
14
+ $fs = freemius( $slug );
15
+
16
+ /**
17
+ * @since 1.1.7.5
18
+ */
19
+ $local_path = $fs->apply_filters( 'plugin_icon', false );
20
+
21
+ if ( is_string( $local_path ) ) {
22
+ $icons = array( $local_path );
23
+ } else {
24
+ global $fs_active_plugins;
25
+
26
+ $img_dir = WP_FS__DIR_IMG;
27
+
28
+ if ( 1 < count( $fs_active_plugins->plugins ) ) {
29
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
30
+ if ( $data->plugin_path == $fs->get_plugin_basename() ) {
31
+ $img_dir = WP_PLUGIN_DIR . '/' . $sdk_path . '/assets/img';
32
+ break;
33
+ }
34
+ }
35
+ }
36
+
37
+ $icons = glob( fs_normalize_path( $img_dir . '/' . $slug . '.*' ) );
38
+ if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
39
+ $icon_found = false;
40
+ $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.png' );
41
+ $have_write_permissions = is_writable( fs_normalize_path( $img_dir ) );
42
+
43
+ if ( WP_FS__IS_LOCALHOST && $fs->is_org_repo_compliant() && $have_write_permissions ) {
44
+ /**
45
+ * IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
46
+ *
47
+ * This code will only be executed once during the testing
48
+ * of the plugin in a local environment. The plugin icon file WILL
49
+ * already exist in the assets folder when the plugin is deployed to
50
+ * the repository.
51
+ */
52
+ $suffixes = array(
53
+ '-128x128.png',
54
+ '-128x128.jpg',
55
+ '-256x256.png',
56
+ '-256x256.jpg',
57
+ '.svg',
58
+ );
59
+
60
+ $base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';
61
+
62
+ foreach ( $suffixes as $s ) {
63
+ $headers = get_headers( $base_url . $s );
64
+ if ( strpos( $headers[0], '200' ) ) {
65
+ $local_path = fs_normalize_path( $img_dir . '/' . $slug . '.' . substr( $s, strpos( $s, '.' ) + 1 ) );
66
+ fs_download_image( $base_url . $s, $local_path );
67
+ $icon_found = true;
68
+ break;
69
+ }
70
+ }
71
+ }
72
+
73
+ if ( ! $icon_found ) {
74
+ // No icons found, fallback to default icon.
75
+ if ( $have_write_permissions ) {
76
+ // If have write permissions, copy default icon.
77
+ copy( fs_normalize_path( $img_dir . '/plugin-icon.png' ), $local_path );
78
+ } else {
79
+ // If doesn't have write permissions, use default icon path.
80
+ $local_path = fs_normalize_path( $img_dir . '/plugin-icon.png' );
81
+ }
82
+ }
83
+
84
+ $icons = array( $local_path );
85
+ }
86
+ }
87
+
88
+ $icon_dir = dirname( $icons[0] );
89
+ $relative_url = fs_img_url( substr( $icons[0], strlen( $icon_dir ) ), $icon_dir );
90
+ ?>
91
+ <div class="fs-plugin-icon">
92
+ <img src="<?php echo $relative_url ?>" width="80" height="80" />
93
+ </div>
freemius/templates/plugin-info/description.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ if ( ! empty( $plugin->info->selling_point_0 ) ||
19
+ ! empty( $plugin->info->selling_point_1 ) ||
20
+ ! empty( $plugin->info->selling_point_2 )
21
+ ) : ?>
22
+ <div class="fs-selling-points">
23
+ <ul>
24
+ <?php for ( $i = 0; $i < 3; $i ++ ) : ?>
25
+ <?php if ( ! empty( $plugin->info->{'selling_point_' . $i} ) ) : ?>
26
+ <li><i class="dashicons dashicons-yes"></i>
27
+
28
+ <h3><?php echo $plugin->info->{'selling_point_' . $i} ?></h3></li>
29
+ <?php endif ?>
30
+ <?php endfor ?>
31
+ </ul>
32
+ </div>
33
+ <?php endif ?>
34
+ <div>
35
+ <?php
36
+ echo wp_kses( $plugin->info->description, array(
37
+ 'a' => array( 'href' => array(), 'title' => array(), 'target' => array() ),
38
+ 'b' => array(),
39
+ 'i' => array(),
40
+ 'p' => array(),
41
+ 'blockquote' => array(),
42
+ 'h2' => array(),
43
+ 'h3' => array(),
44
+ 'ul' => array(),
45
+ 'ol' => array(),
46
+ 'li' => array()
47
+ ) );
48
+ ?>
49
+ </div>
50
+ <?php if ( ! empty( $plugin->info->screenshots ) ) : ?>
51
+ <?php $screenshots = $plugin->info->screenshots ?>
52
+ <div class="fs-screenshots clearfix">
53
+ <h2><?php _efs( 'screenshots', $plugin->slug ) ?></h2>
54
+ <ul>
55
+ <?php $i = 0;
56
+ foreach ( $screenshots as $s => $url ) : ?>
57
+ <?php
58
+ // Relative URLs are replaced with WordPress.org base URL
59
+ // therefore we need to set absolute URLs.
60
+ $url = 'http' . ( WP_FS__IS_HTTPS ? 's' : '' ) . ':' . $url; ?>
61
+ <li class="<?php echo ( 0 === $i % 2 ) ? 'odd' : 'even' ?>">
62
+ <style>
63
+ #section-description .fs-screenshots <?php echo ".fs-screenshot-{$i}" ?>
64
+ {
65
+ background-image: url('<?php echo $url ?>');
66
+ }
67
+ </style>
68
+ <a href="<?php echo $url ?>"
69
+ title="<?php printf( __fs( 'view-full-size-x', $plugin->slug ), $i ) ?>"
70
+ class="fs-screenshot-<?php echo $i ?>"></a>
71
+ </li>
72
+ <?php $i ++; endforeach ?>
73
+ </ul>
74
+ </div>
75
+ <?php endif ?>
freemius/templates/plugin-info/features.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ $plans = $VARS['plans'];
19
+
20
+ $features_plan_map = array();
21
+ foreach ( $plans as $plan ) {
22
+ foreach ( $plan->features as $feature ) {
23
+ if ( ! isset( $features_plan_map[ $feature->id ] ) ) {
24
+ $features_plan_map[ $feature->id ] = array( 'feature' => $feature, 'plans' => array() );
25
+ }
26
+
27
+ $features_plan_map[ $feature->id ]['plans'][ $plan->id ] = $feature;
28
+ }
29
+
30
+ // Add support as a feature.
31
+ if ( ! empty( $plan->support_email ) ||
32
+ ! empty( $plan->support_skype ) ||
33
+ ! empty( $plan->support_phone ) ||
34
+ true === $plan->is_success_manager
35
+ ) {
36
+ if ( ! isset( $features_plan_map['support'] ) ) {
37
+ $support_feature = new stdClass();
38
+ $support_feature->id = 'support';
39
+ $support_feature->title = __fs( 'Support', $plugin->slug );
40
+ $features_plan_map[ $support_feature->id ] = array( 'feature' => $support_feature, 'plans' => array() );
41
+ } else {
42
+ $support_feature = $features_plan_map['support'];
43
+ }
44
+
45
+ $features_plan_map[ $support_feature->id ]['plans'][ $plan->id ] = $support_feature;
46
+ }
47
+ }
48
+
49
+ // Add updates as a feature for all plans.
50
+ $updates_feature = new stdClass();
51
+ $updates_feature->id = 'updates';
52
+ $updates_feature->title = __fs( 'unlimited-updates', $plugin->slug );
53
+ $features_plan_map[ $updates_feature->id ] = array( 'feature' => $updates_feature, 'plans' => array() );
54
+ foreach ( $plans as $plan ) {
55
+ $features_plan_map[ $updates_feature->id ]['plans'][ $plan->id ] = $updates_feature;
56
+ }
57
+ ?>
58
+ <div class="fs-features">
59
+ <table>
60
+ <thead>
61
+ <tr>
62
+ <th></th>
63
+ <?php foreach ( $plans as $plan ) : ?>
64
+ <th>
65
+ <?php echo $plan->title ?>
66
+ <span class="fs-price">
67
+ <?php foreach ( $plan->pricing as $pricing ) : ?>
68
+ <?php if ( 1 == $pricing->licenses ) : ?>
69
+ $<?php echo $pricing->annual_price ?> / year
70
+ <?php endif ?>
71
+ <?php endforeach ?>
72
+ </span>
73
+ </th>
74
+ <?php endforeach ?>
75
+ </tr>
76
+ </thead>
77
+ <tbody>
78
+ <?php $odd = true;
79
+ foreach ( $features_plan_map as $feature_id => $data ) : ?>
80
+ <tr class="fs-<?php echo $odd ? 'odd' : 'even' ?>">
81
+ <td><?php echo ucfirst( $data['feature']->title ) ?></td>
82
+ <?php foreach ( $plans as $plan ) : ?>
83
+ <td>
84
+ <?php if ( isset( $data['plans'][ $plan->id ] ) ) : ?>
85
+ <?php if ( ! empty( $data['plans'][ $plan->id ]->value ) ) : ?>
86
+ <b><?php echo $data['plans'][ $plan->id ]->value ?></b>
87
+ <?php else : ?>
88
+ <i class="dashicons dashicons-yes"></i>
89
+ <?php endif ?>
90
+ <?php endif ?>
91
+ </td>
92
+ <?php endforeach ?>
93
+ </tr>
94
+ <?php $odd = ! $odd; endforeach ?>
95
+ </tbody>
96
+ </table>
97
+ </div>
freemius/templates/plugin-info/screenshots.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.6
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * @var FS_Plugin $plugin
15
+ */
16
+ $plugin = $VARS['plugin'];
17
+
18
+ $screenshots = $VARS['screenshots'];
19
+ ?>
20
+ <ol>
21
+ <?php $i = 0;
22
+ foreach ( $screenshots as $s => $url ) : ?>
23
+ <?php
24
+ // Relative URLs are replaced with WordPress.org base URL
25
+ // therefore we need to set absolute URLs.
26
+ $url = 'http' . ( WP_FS__IS_HTTPS ? 's' : '' ) . ':' . $url; ?>
27
+ <li>
28
+ <a href="<?php echo $url ?>"
29
+ title="<?php printf( __fs( 'view-full-size-x', $plugin->slug ), $i ) ?>"><img
30
+ src="<?php echo $url ?>"></a>
31
+ </li>
32
+ <?php $i ++; endforeach ?>
33
+ </ol>
freemius/templates/powered-by.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.5
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ /**
14
+ * KEEP THE POWERED BY TAB AND GET ADDITIONAL - 1% - OFF THE COMMISSION
15
+ */
16
+
17
+ wp_enqueue_script( 'jquery' );
18
+ wp_enqueue_script( 'json2' );
19
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
20
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
21
+ ?>
22
+
23
+ <div id="piframe"></div>
24
+ <script type="text/javascript">
25
+ (function ($) {
26
+ $(function () {
27
+ var
28
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
29
+ piframe = $('<iframe id="fs_promo_tab" src="' + base_url + '/promotional-tab/?page=contact#' + encodeURIComponent(document.location.href) + '" height="350" width="60" frameborder="0" style=" background: transparent; position: fixed; top: 20%; right: 0;" scrolling="no"></iframe>')
30
+ .appendTo('#piframe');
31
+
32
+ FS.PostMessage.init(base_url);
33
+ FS.PostMessage.receive('state', function (state) {
34
+ if ('closed' === state)
35
+ $('#fs_promo_tab').css('width', '60px');
36
+ else
37
+ $('#fs_promo_tab').css('width', '345px');
38
+ });
39
+ });
40
+ })(jQuery);
41
+ </script>
freemius/templates/pricing.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Freemius
4
+ * @copyright Copyright (c) 2015, Freemius, Inc.
5
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6
+ * @since 1.0.3
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ wp_enqueue_script( 'jquery' );
14
+ wp_enqueue_script( 'json2' );
15
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
16
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
17
+
18
+ $slug = $VARS['slug'];
19
+ $fs = freemius( $slug );
20
+ $timestamp = time();
21
+
22
+ $context_params = array(
23
+ 'plugin_id' => $fs->get_id(),
24
+ 'plugin_public_key' => $fs->get_public_key(),
25
+ 'plugin_version' => $fs->get_plugin_version(),
26
+ );
27
+
28
+ // Get site context secure params.
29
+ if ( $fs->is_registered() ) {
30
+ $context_params = array_merge( $context_params, FS_Security::instance()->get_context_params(
31
+ $fs->get_site(),
32
+ $timestamp,
33
+ 'upgrade'
34
+ ) );
35
+ }
36
+
37
+ if ( $fs->is_payments_sandbox() ) // Append plugin secure token for sandbox mode authentication.)
38
+ {
39
+ $context_params['sandbox'] = FS_Security::instance()->get_secure_token(
40
+ $fs->get_plugin(),
41
+ $timestamp,
42
+ 'checkout'
43
+ );
44
+ }
45
+
46
+ $query_params = array_merge( $context_params, $_GET, array(
47
+ 'next' => $fs->_get_admin_page_url( 'account', array( 'fs_action' => $slug . '_sync_license' ) ),
48
+ 'plugin_version' => $fs->get_plugin_version(),
49
+ // Billing cycle.
50
+ 'billing_cycle' => fs_request_get( 'billing_cycle', WP_FS__PERIOD_ANNUALLY ),
51
+ ) );
52
+ ?>
53
+
54
+ <div id="fs_pricing" class="wrap" style="margin: 0 0 -65px -20px;">
55
+ <div id="iframe"></div>
56
+ <form action="" method="POST">
57
+ <input type="hidden" name="user_id"/>
58
+ <input type="hidden" name="user_email"/>
59
+ <input type="hidden" name="site_id"/>
60
+ <input type="hidden" name="public_key"/>
61
+ <input type="hidden" name="secret_key"/>
62
+ <input type="hidden" name="action" value="account"/>
63
+ </form>
64
+
65
+ <script type="text/javascript">
66
+ (function ($, undef) {
67
+ $(function () {
68
+ var
69
+ // Keep track of the iframe height.
70
+ iframe_height = 800,
71
+ base_url = '<?php echo WP_FS__ADDRESS ?>',
72
+ // Pass the parent page URL into the Iframe in a meaningful way (this URL could be
73
+ // passed via query string or hard coded into the child page, it depends on your needs).
74
+ src = base_url + '/pricing/?<?php echo http_build_query($query_params) ?>#' + encodeURIComponent(document.location.href),
75
+
76
+ // Append the Iframe into the DOM.
77
+ iframe = $('<iframe " src="' + src + '" width="100%" height="' + iframe_height + 'px" scrolling="no" frameborder="0" style="background: transparent;"><\/iframe>')
78
+ .appendTo('#iframe');
79
+
80
+ FS.PostMessage.init(base_url);
81
+
82
+ FS.PostMessage.receive('height', function (data) {
83
+ var h = data.height;
84
+ if (!isNaN(h) && h > 0 && h != iframe_height) {
85
+ iframe_height = h;
86
+ $("#iframe iframe").height(iframe_height + 'px');
87
+ }
88
+ });
89
+
90
+ FS.PostMessage.receive('get_dimensions', function (data) {
91
+ FS.PostMessage.post('dimensions', {
92
+ height : $(document.body).height(),
93
+ scrollTop: $(document).scrollTop()
94
+ }, iframe[0]);
95
+ });
96
+ });
97
+ })(jQuery);
98
+ </script>
99
+ </div>
100
+ <?php fs_require_template( 'powered-by.php' ) ?>
freemius/templates/sticky-admin-notice-js.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sticky admin notices JavaScript handler for dismissing notice messages
4
+ * by sending AJAX call to the server in order to remove the message from the Database.
5
+ *
6
+ * @package Freemius
7
+ * @copyright Copyright (c) 2015, Freemius, Inc.
8
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
+ * @since 1.0.7
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+ ?>
16
+ <script type="text/javascript" >
17
+ jQuery(document).ready(function($) {
18
+ $('.fs-notice.fs-sticky .fs-close').click(function(){
19
+ var
20
+ notice = $(this).parents('.fs-notice'),
21
+ id = notice.attr('data-id'),
22
+ slug = notice.attr('data-slug');
23
+
24
+ notice.fadeOut('fast', function(){
25
+ var data = {
26
+ action: slug + '_dismiss_notice_action',
27
+ slug: slug,
28
+ message_id: id
29
+ };
30
+
31
+ // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
32
+ $.post(ajaxurl, data, function(response) {
33
+
34
+ });
35
+
36
+ notice.remove();
37
+ });
38
+ });
39
+ });
40
+ </script>
{statics → img}/bigplay-dark.svg RENAMED
File without changes
{statics → img}/controls-dark.svg RENAMED
File without changes
inc/enqueue.php CHANGED
@@ -1,22 +1,27 @@
1
  <?php
2
 
3
- // Enqueueing Backend CSS File
 
4
  function wpinked_so_admin_style() {
5
- wp_enqueue_style( 'iw-admin-style', plugin_dir_url( __FILE__ ) . '../statics/admin.css', array(), INKED_SO_WIDGETS );
 
 
6
  }
7
- add_action('admin_enqueue_scripts', 'wpinked_so_admin_style' );
 
 
 
 
 
 
 
8
 
9
- // Register style sheet.
10
- function wpinked_so_register_styles() {
11
- // Registering Javascript Files
12
- wp_register_script( 'iw-mixitup-js', plugin_dir_url(__FILE__) . '../statics/mixitup.min.js', array( 'jquery' ), INKED_SO_WIDGETS, true );
13
- wp_register_script( 'iw-modernizr-js', plugin_dir_url(__FILE__) . '../statics/modernizr.js', array( ), INKED_SO_WIDGETS, false );
14
- wp_register_script( 'iw-foundation-js', plugin_dir_url(__FILE__) . '../statics/foundation.js', array( 'jquery', 'iw-modernizr-js' ), INKED_SO_WIDGETS, true );
15
- wp_register_script( 'iw-equalizer-js', plugin_dir_url(__FILE__) . '../statics/equalizer.js', array( 'iw-foundation-js' ), INKED_SO_WIDGETS, true );
16
- wp_register_script( 'iw-waypoint-js', plugin_dir_url(__FILE__) . '../statics/waypoints.js', array( 'jquery' ), INKED_SO_WIDGETS, true );
17
- wp_register_script( 'iw-countto-js', plugin_dir_url(__FILE__) . '../statics/countto.js', array( 'jquery' ), INKED_SO_WIDGETS, true );
18
 
19
- // Enqueueing CSS Files
20
- wp_enqueue_style( 'iw-defaults', plugin_dir_url(__FILE__) . '../statics/defaults.css', array(), INKED_SO_WIDGETS );
21
  }
22
- add_action( 'wp_enqueue_scripts', 'wpinked_so_register_styles' );
 
1
  <?php
2
 
3
+ if ( ! function_exists ( 'wpinked_so_admin_style' ) ) :
4
+ // Enqueueing Backend style sheet.
5
  function wpinked_so_admin_style() {
6
+
7
+ wp_enqueue_style( 'iw-admin-style', plugin_dir_url( __FILE__ ) . '../css/admin.css', array(), INKED_SO_VER );
8
+
9
  }
10
+ endif;
11
+ add_action( 'admin_enqueue_scripts', 'wpinked_so_admin_style' );
12
+
13
+ if ( ! function_exists ( 'wpinked_so_styles' ) ) :
14
+ // Enqueueing Frontend style sheet.
15
+ function wpinked_so_styles() {
16
+
17
+ wp_enqueue_style( 'iw-defaults', plugin_dir_url(__FILE__) . '../css/defaults.css', array(), INKED_SO_VER );
18
 
19
+ wp_register_script( 'iw-waypoints-js', plugin_dir_url(__FILE__) . '../js/waypoints' . INKED_JS_SUFFIX . '.js', array( 'jquery' ), INKED_SO_VER, true );
20
+ wp_register_script( 'iw-countto-js', plugin_dir_url(__FILE__) . '../js/countto' . INKED_JS_SUFFIX . '.js', array( 'jquery' ), INKED_SO_VER, true );
21
+ wp_register_script( 'iw-easypie-js', plugin_dir_url(__FILE__) . '../js/easypie' . INKED_JS_SUFFIX . '.js', array( 'jquery' ), INKED_SO_VER, true );
22
+ wp_register_script( 'iw-mixitup-js', plugin_dir_url(__FILE__) . '../js/mixitup' . INKED_JS_SUFFIX . '.js', array( 'jquery' ), INKED_SO_VER, true );
23
+ wp_register_script( 'iw-match-height-js', plugin_dir_url(__FILE__) . '../js/match-height' . INKED_JS_SUFFIX . '.js', array( 'jquery' ), INKED_SO_VER, true );
 
 
 
 
24
 
 
 
25
  }
26
+ endif;
27
+ add_action( 'wp_enqueue_scripts', 'wpinked_so_styles' );
inc/functions.php CHANGED
@@ -1,29 +1,46 @@
1
  <?php
2
 
 
3
  add_image_size( 'folio', 600, 400, true );
4
 
 
 
5
 
6
- add_filter( 'wpinked_byline', 'wpinked_so_post_byline_filter' );
 
 
 
 
7
 
8
- function wpinked_so_post_byline_filter( $byline ) {
9
 
10
- $byline = str_replace( '%date%', '%1$s', $byline );
11
- $byline = str_replace( '%category%', '%2$s', $byline );
12
- $byline = str_replace( '%author%', '%3$s', $byline );
13
- $byline = str_replace( '%comments%', '%4$s', $byline );
14
-
15
- return $byline;
16
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
18
  function wpinked_so_post_excerpt ( $limit, $after ) {
19
 
20
  if ( $limit ) :
21
 
22
- $excerpt = explode(' ', get_the_excerpt(), $limit);
23
 
24
  if ( count($excerpt) >= $limit):
25
  array_pop($excerpt);
26
- $excerpt = implode(" ",$excerpt). $after;
27
  else:
28
  $excerpt = implode(" ",$excerpt);
29
  endif;
@@ -34,24 +51,101 @@ function wpinked_so_post_excerpt ( $limit, $after ) {
34
 
35
  endif;
36
 
37
- $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
38
 
39
  echo $excerpt;
40
 
41
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- function wpinked_so_person_social ( $profiles, $align, $target ) {
 
44
 
45
  if ( $profiles ) { ?>
46
 
47
- <p class="iw-so-person-profiles <?php echo $align;?>">
48
 
49
  <?php
50
  $icon_styles = array();
51
 
52
  foreach( $profiles as $index => $profile ) { ?>
53
 
54
- <a href="<?php echo $profile['link']; ?>" target="<?php echo $target; ?>"><?php echo siteorigin_widget_get_icon( $profile['icon'], $icon_styles );?></a>
55
 
56
  <?php } ?>
57
 
@@ -59,30 +153,33 @@ function wpinked_so_person_social ( $profiles, $align, $target ) {
59
 
60
  <?php }
61
  }
 
62
 
 
63
  function wpinked_so_testimonial_name ( $name, $company, $link, $target, $align ) {
64
 
65
  if ( $name ) { ?>
66
 
67
- <h4 class="iw-so-testimonial-name <?php echo $align; ?>"><?php echo $name; ?></h4>
68
 
69
  <?php }
70
 
71
  if ( $company ) { ?>
72
 
73
- <h5 class="iw-so-testimonial-company <?php echo $align; ?>">
74
 
75
  <?php if ( $link ) : ?>
76
- <a target="<?php echo $target; ?>" href="<?php echo $link; ?>"><?php echo $company; ?></a>
77
  <?php else : ?>
78
- <?php echo $company; ?>
79
  <?php endif; ?>
80
- </h5>
81
 
82
  <?php }
83
-
84
  }
 
85
 
 
86
  function wpinked_so_blog_post_col($count, $cols) {
87
  if( $count % $cols == 0 ):
88
  echo 'iw-so-last-col';
@@ -91,3 +188,10 @@ function wpinked_so_blog_post_col($count, $cols) {
91
  echo 'iw-so-first-col';
92
  endif;
93
  }
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ // Add custom image size
4
  add_image_size( 'folio', 600, 400, true );
5
 
6
+ if ( ! function_exists ( 'wpinked_so_post_byline' ) ) :
7
+ function wpinked_so_post_byline( $byline, $id, $sep ) {
8
 
9
+ $byline = str_replace( '%category%', get_the_category_list( $sep, '', $id ), $byline );
10
+ $byline = str_replace( '%author%', '<a href="' . get_author_posts_url( $id ) . '">' . get_the_author() . '</a>', $byline );
11
+ $byline = str_replace( '%date%', get_the_date( '', $id ), $byline );
12
+ $byline = str_replace( '%comments%', get_comments_number( $id ), $byline );
13
+ $byline = do_shortcode( $byline );
14
 
15
+ echo wp_kses_post( $byline );
16
 
 
 
 
 
 
 
17
  }
18
+ endif;
19
+
20
+ if ( ! function_exists ( 'wpinked_so_post_byline_metafield' ) ) :
21
+ function wpinked_so_post_byline_metafield( $atts ) {
22
+ $atts = extract( shortcode_atts( array(
23
+ 'id' => '',
24
+ ), $atts ) );
25
+ if ( ! $id ) return;
26
+ $data = get_post_meta( get_the_ID(), $id, true );
27
+ if ( $data ) {
28
+ return '<span class="iw-so-custom-field id-'. $id .'">'. $data .'</span>';
29
+ }
30
+ }
31
+ endif;
32
+ add_shortcode( 'ink_custom_field', 'wpinked_so_post_byline_metafield' );
33
 
34
+ if ( ! function_exists ( 'wpinked_so_post_excerpt' ) ) :
35
  function wpinked_so_post_excerpt ( $limit, $after ) {
36
 
37
  if ( $limit ) :
38
 
39
+ $excerpt = explode( ' ', get_the_excerpt(), $limit);
40
 
41
  if ( count($excerpt) >= $limit):
42
  array_pop($excerpt);
43
+ $excerpt = implode(" ",$excerpt). esc_html( $after );
44
  else:
45
  $excerpt = implode(" ",$excerpt);
46
  endif;
51
 
52
  endif;
53
 
54
+ $excerpt = preg_replace( '`\[[^\]]*\]`','',$excerpt);
55
 
56
  echo $excerpt;
57
 
58
  }
59
+ endif;
60
+
61
+ if ( ! function_exists ( 'wpinked_so_blog_navigation' ) ) :
62
+ function wpinked_so_blog_navigation( $query, $navigation, $type, $attr, $previous, $next ) {
63
+
64
+ if( $navigation ): ?>
65
+
66
+ <?php if( $type == 'next-prev' ): ?>
67
+ <h3 class="screen-reader-text"><?php _e( 'Posts Navigation', 'wpinked-widgets' ); ?></h3>
68
+ <nav id='iw-so-blog-pagination' class="iw-so-blog-pagination iw-so-blog-prev-next <?php echo $attr; ?>" role="navigation">
69
+ <ul>
70
+ <li class="iw-so-blog-previous"><?php echo str_replace ( '<a', '<a', get_previous_posts_link( $previous, $query->max_num_pages) ) ?></li>
71
+ <li class="iw-so-blog-next"><?php echo str_replace ( '<a', '<a', get_next_posts_link( $next, $query->max_num_pages) ) ?></li>
72
+ </ul>
73
+ </nav>
74
+ <?php endif; ?>
75
+
76
+ <?php if( $type == 'paginate' ): ?>
77
+ <nav id='iw-so-blog-pagination' class="iw-so-blog-pagination iw-so-blog-paginate <?php echo $attr; ?>" role="navigation">
78
+ <h3 class="screen-reader-text"><?php _e( 'Posts Navigation', 'wpinked-widgets' ); ?></h3>
79
+ <div class="iw-so-nav-links">
80
+ <?php
81
+ $big = 999999999; // need an unlikely integer
82
+ $args = array(
83
+ 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
84
+ 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
85
+ 'total' => $query->max_num_pages,
86
+ 'current' => max( 1, $query->get('paged') ),
87
+ 'show_all' => false,
88
+ 'prev_next' => true,
89
+ 'prev_text' => $previous,
90
+ 'next_text' => $next,
91
+ 'end_size' => 1,
92
+ 'mid_size' => 1,
93
+ 'type' => 'plain',
94
+ 'add_args' => false, // array of query args to add
95
+ 'add_fragment' => ''
96
+ );
97
+ ?>
98
+ <?php echo paginate_links( $args ); ?>
99
+
100
+ </div>
101
+ </nav>
102
+ <?php endif; ?>
103
+
104
+ <?php endif;
105
+
106
+ }
107
+ endif;
108
+
109
+ if ( ! function_exists ( 'wpinked_so_blog_navigation_ajax' ) ) :
110
+ function wpinked_so_blog_navigation_ajax( $navigation, $type, $id ) {
111
+
112
+ if ( $navigation && $type == 'ajax' ): ?>
113
+
114
+ <script>
115
+ jQuery(document).ready(function(){
116
+ // AJAX pagination
117
+ jQuery(function($) {
118
+ $( '#<?php echo $id; ?>' ).parent( '.iw-so-blog' ).on( 'click', '#iw-so-blog-pagination.iw-so-navi-ajax a', function(e){
119
+ e.preventDefault();
120
+ var link = $(this).attr( 'href' );
121
+ $( '#<?php echo $id; ?>' ).parent().fadeOut(300, function(){
122
+ $(this).load(link + ' #<?php echo $id; ?>', function() {
123
+ $(this).fadeIn(300);
124
+ });
125
+ });
126
+ });
127
+ });
128
+ });
129
+ </script>
130
+
131
+ <?php endif;
132
+
133
+ }
134
+ endif;
135
 
136
+ if ( ! function_exists( 'wpinked_so_person_social' ) ) :
137
+ function wpinked_so_person_social( $profiles, $align, $target ) {
138
 
139
  if ( $profiles ) { ?>
140
 
141
+ <p class="iw-so-person-profiles <?php echo esc_attr( $align );?>">
142
 
143
  <?php
144
  $icon_styles = array();
145
 
146
  foreach( $profiles as $index => $profile ) { ?>
147
 
148
+ <a href="<?php echo sow_esc_url( $profile['link'] ); ?>" target="<?php echo esc_attr( $target ); ?>"><?php echo siteorigin_widget_get_icon( $profile['icon'], $icon_styles );?></a>
149
 
150
  <?php } ?>
151
 
153
 
154
  <?php }
155
  }
156
+ endif;
157
 
158
+ if ( ! function_exists ( 'wpinked_so_testimonial_name' ) ) :
159
  function wpinked_so_testimonial_name ( $name, $company, $link, $target, $align ) {
160
 
161
  if ( $name ) { ?>
162
 
163
+ <h4 class="iw-so-testimonial-name <?php echo $align; ?>"><?php echo esc_html( $name ); ?></h4>
164
 
165
  <?php }
166
 
167
  if ( $company ) { ?>
168
 
169
+ <p class="iw-so-testimonial-company <?php echo $align; ?>">
170
 
171
  <?php if ( $link ) : ?>
172
+ <a target="<?php echo esc_attr( $target ); ?>" href="<?php echo sow_esc_url( $link ); ?>"><?php echo esc_html( $company ); ?></a>
173
  <?php else : ?>
174
+ <?php echo esc_html( $company ); ?>
175
  <?php endif; ?>
176
+ </p>
177
 
178
  <?php }
 
179
  }
180
+ endif;
181
 
182
+ if ( ! function_exists ( 'wpinked_so_blog_post_col' ) ) :
183
  function wpinked_so_blog_post_col($count, $cols) {
184
  if( $count % $cols == 0 ):
185
  echo 'iw-so-last-col';
188
  echo 'iw-so-first-col';
189
  endif;
190
  }
191
+ endif;
192
+
193
+ if ( ! function_exists ( 'wpinked_so_unique_id' ) ) :
194
+ function wpinked_so_unique_id() {
195
+ return mt_rand(1111, 9999) . '-' . mt_rand(1111, 9999) . '-' . mt_rand(1111, 9999);
196
+ }
197
+ endif;
inc/visibility.php CHANGED
@@ -1,58 +1,62 @@
1
  <?php
2
- // Adding Visibility fields to rows and widgets
3
- add_filter( 'siteorigin_panels_row_style_fields', 'wpinked_so_visibility_fields' );
4
- add_filter( 'siteorigin_panels_widget_style_fields', 'wpinked_so_visibility_fields' );
5
-
6
- // Adding Visibility classes to rows and widgets
7
- add_filter('siteorigin_panels_row_style_attributes', 'wpinked_so_visibility_attributes', 10, 2);
8
- add_filter('siteorigin_panels_widget_style_attributes', 'wpinked_so_visibility_attributes', 10, 2);
9
 
10
- // The functions that make it happen
11
- function wpinked_so_visibility_fields($fields) {
 
12
 
13
  $fields['iw-visible-screen'] = array(
14
- 'name' => __('Visibility - By screen size', 'wpinked-widgets'),
15
  'type' => 'select',
16
  'group' => 'attributes',
17
- 'default' => 'iw-all',
18
- 'options' => array(
19
- 'iw-all' => __( 'All', 'wpinked-widgets' ),
20
- 'iw-small' => __( 'Small', 'wpinked-widgets' ),
21
- 'iw-med-up' => __( 'Medium Up', 'wpinked-widgets' ),
22
- 'iw-medium' => __( 'Medium', 'wpinked-widgets' ),
23
- 'iw-med-dw' => __( 'Medium Down', 'wpinked-widgets' ),
24
- 'iw-large' => __( 'Large', 'wpinked-widgets' )
25
- ),
26
- 'description' => __('Show by screen size.', 'wpinked-widgets'),
27
  'priority' => 12,
28
  );
29
 
30
  $fields['iw-visible-layout'] = array(
31
- 'name' => __('Visibility - By screen layout', 'wpinked-widgets'),
32
  'type' => 'select',
33
  'group' => 'attributes',
34
- 'default' => 'iw-all',
35
- 'options' => array(
36
- 'iw-all' => __( 'All', 'wpinked-widgets' ),
37
- 'iw-show-p' => __( 'Show Portrait', 'wpinked-widgets' ),
38
- 'iw-show-l' => __( 'Show Landscape', 'wpinked-widgets' ),
39
- 'iw-hide-p' => __( 'Hide Portrait', 'wpinked-widgets' ),
40
- 'iw-hide-l' => __( 'Hide Landscape', 'wpinked-widgets' )
41
- ),
42
- 'description' => __('Show based on screen orientation.', 'wpinked-widgets'),
43
  'priority' => 13,
44
  );
45
 
46
  return $fields;
47
  }
 
 
 
48
 
 
 
49
  function wpinked_so_visibility_attributes( $attributes, $args ) {
50
- if( !empty( $args['iw-visible-screen'] ) && ( $args['iw-visible-screen'] !== 'iw-all' ) ) {
51
- array_push($attributes['class'], $args['iw-visible-screen']);
52
- }
53
- if( !empty( $args['iw-visible-layout'] ) && ( $args['iw-visible-screen'] !== 'iw-all' ) ) {
54
- array_push($attributes['class'], $args['iw-visible-layout']);
55
- }
56
-
57
- return $attributes;
58
- }
 
 
 
 
 
1
  <?php
 
 
 
 
 
 
 
2
 
3
+ if ( ! function_exists ( 'wpinked_so_visibility_fields' ) ) :
4
+ // Adding visibility options
5
+ function wpinked_so_visibility_fields( $fields ) {
6
 
7
  $fields['iw-visible-screen'] = array(
8
+ 'name' => __( 'Visibility - By screen size', 'wpinked-widgets' ),
9
  'type' => 'select',
10
  'group' => 'attributes',
11
+ 'default' => 'iw-all',
12
+ 'options' => array(
13
+ 'iw-all' => __( 'All', 'wpinked-widgets' ),
14
+ 'iw-small' => __( 'Small (below 640px)', 'wpinked-widgets' ),
15
+ 'iw-med-up' => __( 'Medium Up (above 640px)', 'wpinked-widgets' ),
16
+ 'iw-medium' => __( 'Medium (640px - 1024px)', 'wpinked-widgets' ),
17
+ 'iw-med-dw' => __( 'Medium Down (below 1024px)', 'wpinked-widgets' ),
18
+ 'iw-large' => __( 'Large (above 1024px)', 'wpinked-widgets' )
19
+ ),
20
+ 'description' => __( 'Show by screen size.', 'wpinked-widgets' ),
21
  'priority' => 12,
22
  );
23
 
24
  $fields['iw-visible-layout'] = array(
25
+ 'name' => __( 'Visibility - By screen layout', 'wpinked-widgets' ),
26
  'type' => 'select',
27
  'group' => 'attributes',
28
+ 'default' => 'iw-all',
29
+ 'options' => array(
30
+ 'iw-all' => __( 'All', 'wpinked-widgets' ),
31
+ 'iw-show-p' => __( 'Show Portrait', 'wpinked-widgets' ),
32
+ 'iw-show-l' => __( 'Show Landscape', 'wpinked-widgets' ),
33
+ 'iw-hide-p' => __( 'Hide Portrait', 'wpinked-widgets' ),
34
+ 'iw-hide-l' => __( 'Hide Landscape', 'wpinked-widgets' )
35
+ ),
36
+ 'description' => __( 'Show based on screen orientation.', 'wpinked-widgets' ),
37
  'priority' => 13,
38
  );
39
 
40
  return $fields;
41
  }
42
+ endif;
43
+ add_filter( 'siteorigin_panels_row_style_fields', 'wpinked_so_visibility_fields' );
44
+ add_filter( 'siteorigin_panels_widget_style_fields', 'wpinked_so_visibility_fields' );
45
 
46
+ if ( ! function_exists ( 'wpinked_so_visibility_attributes' ) ) :
47
+ // Adding visibility classes
48
  function wpinked_so_visibility_attributes( $attributes, $args ) {
49
+
50
+ if( !empty( $args['iw-visible-screen'] ) && ( $args['iw-visible-screen'] !== 'iw-all' ) ) {
51
+ array_push( $attributes['class'], $args['iw-visible-screen'] );
52
+ }
53
+
54
+ if( !empty( $args['iw-visible-layout'] ) && ( $args['iw-visible-layout'] !== 'iw-all' ) ) {
55
+ array_push( $attributes['class'], $args['iw-visible-layout'] );
56
+ }
57
+
58
+ return $attributes;
59
+ }
60
+ endif;
61
+ add_filter( 'siteorigin_panels_row_style_attributes', 'wpinked_so_visibility_attributes', 10, 2);
62
+ add_filter( 'siteorigin_panels_widget_style_attributes', 'wpinked_so_visibility_attributes', 10, 2);
{statics → js}/countto.js RENAMED
@@ -2,9 +2,9 @@
2
  if (typeof define === 'function' && define.amd) {
3
  // AMD
4
  define(['jquery'], factory);
5
- } else if (typeof exports === 'object') {
6
  // CommonJS
7
- factory(require('jquery'));
8
  } else {
9
  // Browser globals
10
  factory(jQuery);
@@ -36,11 +36,11 @@
36
 
37
  CountTo.prototype.dataOptions = function () {
38
  var options = {
39
- from: this.$element.data('from'),
40
- to: this.$element.data('to'),
41
- speed: this.$element.data('speed'),
42
- refreshInterval: this.$element.data('refresh-interval'),
43
- decimals: this.$element.data('decimals')
44
  };
45
 
46
  var keys = Object.keys(options);
@@ -48,7 +48,7 @@
48
  for (var i in keys) {
49
  var key = keys[i];
50
 
51
- if (typeof(options[key]) === 'undefined') {
52
  delete options[key];
53
  }
54
  }
@@ -62,7 +62,7 @@
62
 
63
  this.render();
64
 
65
- if (typeof(this.options.onUpdate) == 'function') {
66
  this.options.onUpdate.call(this.$element, this.value);
67
  }
68
 
@@ -70,7 +70,7 @@
70
  clearInterval(this.interval);
71
  this.value = this.options.to;
72
 
73
- if (typeof(this.options.onComplete) == 'function') {
74
  this.options.onComplete.call(this.$element, this.value);
75
  }
76
  }
@@ -114,17 +114,17 @@
114
  $.fn.countTo = function (option) {
115
  return this.each(function () {
116
  var $this = $(this);
117
- var data = $this.data('countTo');
118
  var init = !data || typeof(option) === 'object';
119
  var options = typeof(option) === 'object' ? option : {};
120
  var method = typeof(option) === 'string' ? option : 'start';
121
 
122
  if (init) {
123
  if (data) data.stop();
124
- $this.data('countTo', data = new CountTo(this, options));
125
  }
126
 
127
  data[method].call(data);
128
  });
129
  };
130
- }));
2
  if (typeof define === 'function' && define.amd) {
3
  // AMD
4
  define(['jquery'], factory);
5
+ } else if (typeof exports === 'object' ) {
6
  // CommonJS
7
+ factory(require( 'jquery' ));
8
  } else {
9
  // Browser globals
10
  factory(jQuery);
36
 
37
  CountTo.prototype.dataOptions = function () {
38
  var options = {
39
+ from: this.$element.data( 'from' ),
40
+ to: this.$element.data( 'to' ),
41
+ speed: this.$element.data( 'speed' ),
42
+ refreshInterval: this.$element.data( 'refresh-interval' ),
43
+ decimals: this.$element.data( 'decimals' )
44
  };
45
 
46
  var keys = Object.keys(options);
48
  for (var i in keys) {
49
  var key = keys[i];
50
 
51
+ if (typeof(options[key]) === 'undefined' ) {
52
  delete options[key];
53
  }
54
  }
62
 
63
  this.render();
64
 
65
+ if (typeof(this.options.onUpdate) == 'function' ) {
66
  this.options.onUpdate.call(this.$element, this.value);
67
  }
68
 
70
  clearInterval(this.interval);
71
  this.value = this.options.to;
72
 
73
+ if (typeof(this.options.onComplete) == 'function' ) {
74
  this.options.onComplete.call(this.$element, this.value);
75
  }
76
  }
114
  $.fn.countTo = function (option) {
115
  return this.each(function () {
116
  var $this = $(this);
117
+ var data = $this.data( 'countTo' );
118
  var init = !data || typeof(option) === 'object';
119
  var options = typeof(option) === 'object' ? option : {};
120
  var method = typeof(option) === 'string' ? option : 'start';
121
 
122
  if (init) {
123
  if (data) data.stop();
124
+ $this.data( 'countTo', data = new CountTo(this, options));
125
  }
126
 
127
  data[method].call(data);
128
  });
129
  };
130
+ }));
js/countto.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t("object"==typeof exports?require("jquery"):jQuery)}(function(t){function e(t,e){return t.toFixed(e.decimals)}var o=function(e,i){this.$element=t(e),this.options=t.extend({},o.DEFAULTS,this.dataOptions(),i),this.init()};o.DEFAULTS={from:0,to:0,speed:1e3,refreshInterval:100,decimals:0,formatter:e,onUpdate:null,onComplete:null},o.prototype.init=function(){this.value=this.options.from,this.loops=Math.ceil(this.options.speed/this.options.refreshInterval),this.loopCount=0,this.increment=(this.options.to-this.options.from)/this.loops},o.prototype.dataOptions=function(){var t={from:this.$element.data("from"),to:this.$element.data("to"),speed:this.$element.data("speed"),refreshInterval:this.$element.data("refresh-interval"),decimals:this.$element.data("decimals")},e=Object.keys(t);for(var o in e){var i=e[o];"undefined"==typeof t[i]&&delete t[i]}return t},o.prototype.update=function(){this.value+=this.increment,this.loopCount++,this.render(),"function"==typeof this.options.onUpdate&&this.options.onUpdate.call(this.$element,this.value),this.loopCount>=this.loops&&(clearInterval(this.interval),this.value=this.options.to,"function"==typeof this.options.onComplete&&this.options.onComplete.call(this.$element,this.value))},o.prototype.render=function(){var t=this.options.formatter.call(this.$element,this.value,this.options);this.$element.text(t)},o.prototype.restart=function(){this.stop(),this.init(),this.start()},o.prototype.start=function(){this.stop(),this.render(),this.interval=setInterval(this.update.bind(this),this.options.refreshInterval)},o.prototype.stop=function(){this.interval&&clearInterval(this.interval)},o.prototype.toggle=function(){this.interval?this.stop():this.start()},t.fn.countTo=function(e){return this.each(function(){var i=t(this),n=i.data("countTo"),s=!n||"object"==typeof e,r="object"==typeof e?e:{},a="string"==typeof e?e:"start";s&&(n&&n.stop(),i.data("countTo",n=new o(this,r))),n[a].call(n)})}});
{widgets/ink-crlc-widget/scripts → js}/easypie.js RENAMED
@@ -2,7 +2,7 @@
2
  * easy-pie-chart
3
  * Lightweight plugin to render simple, animated and retina optimized pie charts
4
  *
5
- * @license
6
  * @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
7
  * @version 2.1.7
8
  **/
@@ -13,7 +13,7 @@
13
  define(["jquery"], function (a0) {
14
  return (factory(a0));
15
  });
16
- } else if (typeof exports === 'object') {
17
  // Node. Does not work with strict CommonJS, but
18
  // only CommonJS-like environments that support module.exports,
19
  // like Node.
@@ -30,15 +30,15 @@
30
  */
31
  var CanvasRenderer = function(el, options) {
32
  var cachedBackground;
33
- var canvas = document.createElement('canvas');
34
 
35
  el.appendChild(canvas);
36
 
37
- if (typeof(G_vmlCanvasManager) === 'object') {
38
  G_vmlCanvasManager.initElement(canvas);
39
  }
40
 
41
- var ctx = canvas.getContext('2d');
42
 
43
  canvas.width = canvas.height = options.size;
44
 
@@ -46,7 +46,7 @@ var CanvasRenderer = function(el, options) {
46
  var scaleBy = 1;
47
  if (window.devicePixelRatio > 1) {
48
  scaleBy = window.devicePixelRatio;
49
- canvas.style.width = canvas.style.height = [options.size, 'px'].join('');
50
  canvas.width = canvas.height = options.size * scaleBy;
51
  ctx.scale(scaleBy, scaleBy);
52
  }
@@ -180,7 +180,7 @@ var CanvasRenderer = function(el, options) {
180
 
181
  // if barcolor is a function execute it and pass the percent as a value
182
  var color;
183
- if (typeof(options.barColor) === 'function') {
184
  color = options.barColor(percent);
185
  } else {
186
  color = options.barColor;
@@ -248,12 +248,12 @@ var EasyPieChart = function(el, opts) {
248
  };
249
 
250
  // detect present renderer
251
- if (typeof(CanvasRenderer) !== 'undefined') {
252
  defaultOptions.renderer = CanvasRenderer;
253
- } else if (typeof(SVGRenderer) !== 'undefined') {
254
  defaultOptions.renderer = SVGRenderer;
255
  } else {
256
- throw new Error('Please load either the SVG- or the CanvasRenderer');
257
  }
258
 
259
  var options = {};
@@ -270,7 +270,7 @@ var EasyPieChart = function(el, opts) {
270
  for (var i in defaultOptions) {
271
  if (defaultOptions.hasOwnProperty(i)) {
272
  options[i] = opts && typeof(opts[i]) !== 'undefined' ? opts[i] : defaultOptions[i];
273
- if (typeof(options[i]) === 'function') {
274
  options[i] = options[i].bind(this);
275
  }
276
  }
@@ -284,7 +284,7 @@ var EasyPieChart = function(el, opts) {
284
  }
285
 
286
  // process earlier animate option to avoid bc breaks
287
- if (typeof(options.animate) === 'number') {
288
  options.animate = {
289
  duration: options.animate,
290
  enabled: true
@@ -307,8 +307,8 @@ var EasyPieChart = function(el, opts) {
307
  // initial update
308
  if (el.dataset && el.dataset.percent) {
309
  this.update(parseFloat(el.dataset.percent));
310
- } else if (el.getAttribute && el.getAttribute('data-percent')) {
311
- this.update(parseFloat(el.getAttribute('data-percent')));
312
  }
313
  }.bind(this);
314
 
@@ -353,7 +353,7 @@ $.fn.easyPieChart = function(options) {
353
  return this.each(function() {
354
  var instanceOptions;
355
 
356
- if (!$.data(this, 'easyPieChart')) {
357
  instanceOptions = $.extend({}, options, $(this).data());
358
  $.data(this, 'easyPieChart', new EasyPieChart(this, instanceOptions));
359
  }
2
  * easy-pie-chart
3
  * Lightweight plugin to render simple, animated and retina optimized pie charts
4
  *
5
+ * @license
6
  * @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
7
  * @version 2.1.7
8
  **/
13
  define(["jquery"], function (a0) {
14
  return (factory(a0));
15
  });
16
+ } else if (typeof exports === 'object' ) {
17
  // Node. Does not work with strict CommonJS, but
18
  // only CommonJS-like environments that support module.exports,
19
  // like Node.
30
  */
31
  var CanvasRenderer = function(el, options) {
32
  var cachedBackground;
33
+ var canvas = document.createElement( 'canvas' );
34
 
35
  el.appendChild(canvas);
36
 
37
+ if (typeof(G_vmlCanvasManager) === 'object' ) {
38
  G_vmlCanvasManager.initElement(canvas);
39
  }
40
 
41
+ var ctx = canvas.getContext( '2d' );
42
 
43
  canvas.width = canvas.height = options.size;
44
 
46
  var scaleBy = 1;
47
  if (window.devicePixelRatio > 1) {
48
  scaleBy = window.devicePixelRatio;
49
+ canvas.style.width = canvas.style.height = [options.size, 'px'].join( '' );
50
  canvas.width = canvas.height = options.size * scaleBy;
51
  ctx.scale(scaleBy, scaleBy);
52
  }
180
 
181
  // if barcolor is a function execute it and pass the percent as a value
182
  var color;
183
+ if (typeof(options.barColor) === 'function' ) {
184
  color = options.barColor(percent);
185
  } else {
186
  color = options.barColor;
248
  };
249
 
250
  // detect present renderer
251
+ if (typeof(CanvasRenderer) !== 'undefined' ) {
252
  defaultOptions.renderer = CanvasRenderer;
253
+ } else if (typeof(SVGRenderer) !== 'undefined' ) {
254
  defaultOptions.renderer = SVGRenderer;
255
  } else {
256
+ throw new Error( 'Please load either the SVG- or the CanvasRenderer' );
257
  }
258
 
259
  var options = {};
270
  for (var i in defaultOptions) {
271
  if (defaultOptions.hasOwnProperty(i)) {
272
  options[i] = opts && typeof(opts[i]) !== 'undefined' ? opts[i] : defaultOptions[i];
273
+ if (typeof(options[i]) === 'function' ) {
274
  options[i] = options[i].bind(this);
275
  }
276
  }
284
  }
285
 
286
  // process earlier animate option to avoid bc breaks
287
+ if (typeof(options.animate) === 'number' ) {
288
  options.animate = {
289
  duration: options.animate,
290
  enabled: true
307
  // initial update
308
  if (el.dataset && el.dataset.percent) {
309
  this.update(parseFloat(el.dataset.percent));
310
+ } else if (el.getAttribute && el.getAttribute( 'data-percent' )) {
311
+ this.update(parseFloat(el.getAttribute( 'data-percent' )));
312
  }
313
  }.bind(this);
314
 
353
  return this.each(function() {
354
  var instanceOptions;
355
 
356
+ if (!$.data(this, 'easyPieChart' )) {
357
  instanceOptions = $.extend({}, options, $(this).data());
358
  $.data(this, 'easyPieChart', new EasyPieChart(this, instanceOptions));
359
  }
js/easypie.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(e,t){"function"==typeof define&&define.amd?define(["jquery"],function(e){return t(e)}):"object"==typeof exports?module.exports=t(require("jquery")):t(jQuery)}(this,function(e){var t=function(e,t){var n,a=document.createElement("canvas");e.appendChild(a),"object"==typeof G_vmlCanvasManager&&G_vmlCanvasManager.initElement(a);var i=a.getContext("2d");a.width=a.height=t.size;var r=1;window.devicePixelRatio>1&&(r=window.devicePixelRatio,a.style.width=a.style.height=[t.size,"px"].join(""),a.width=a.height=t.size*r,i.scale(r,r)),i.translate(t.size/2,t.size/2),i.rotate((-0.5+t.rotate/180)*Math.PI);var o=(t.size-t.lineWidth)/2;t.scaleColor&&t.scaleLength&&(o-=t.scaleLength+2),Date.now=Date.now||function(){return+new Date};var s=function(e,t,n){n=Math.min(Math.max(-1,n||0),1);var a=0>=n;i.beginPath(),i.arc(0,0,o,0,2*Math.PI*n,a),i.strokeStyle=e,i.lineWidth=t,i.stroke()},d=function(){var e,n;i.lineWidth=1,i.fillStyle=t.scaleColor,i.save();for(var a=24;a>0;--a)a%6===0?(n=t.scaleLength,e=0):(n=.6*t.scaleLength,e=t.scaleLength-n),i.fillRect(-t.size/2+e,0,n,1),i.rotate(Math.PI/12);i.restore()},h=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}(),u=function(){t.scaleColor&&d(),t.trackColor&&s(t.trackColor,t.trackWidth||t.lineWidth,1)};this.getCanvas=function(){return a},this.getCtx=function(){return i},this.clear=function(){i.clearRect(t.size/-2,t.size/-2,t.size,t.size)},this.draw=function(e){t.scaleColor||t.trackColor?i.getImageData&&i.putImageData?n?i.putImageData(n,0,0):(u(),n=i.getImageData(0,0,t.size*r,t.size*r)):(this.clear(),u()):this.clear(),i.lineCap=t.lineCap;var a;a="function"==typeof t.barColor?t.barColor(e):t.barColor,s(a,t.lineWidth,e/100)}.bind(this),this.animate=function(e,n){var a=Date.now();t.onStart(e,n);var i=function(){var r=Math.min(Date.now()-a,t.animate.duration),o=t.easing(this,r,e,n-e,t.animate.duration);this.draw(o),t.onStep(e,n,o),r>=t.animate.duration?t.onStop(e,n):h(i)}.bind(this);h(i)}.bind(this)},n=function(e,n){var a={barColor:"#ef1e25",trackColor:"#f9f9f9",scaleColor:"#dfe0e0",scaleLength:5,lineCap:"round",lineWidth:3,trackWidth:void 0,size:110,rotate:0,animate:{duration:1e3,enabled:!0},easing:function(e,t,n,a,i){return t/=i/2,1>t?a/2*t*t+n:-a/2*(--t*(t-2)-1)+n},onStart:function(e,t){},onStep:function(e,t,n){},onStop:function(e,t){}};if("undefined"!=typeof t)a.renderer=t;else{if("undefined"==typeof SVGRenderer)throw new Error("Please load either the SVG- or the CanvasRenderer");a.renderer=SVGRenderer}var i={},r=0,o=function(){this.el=e,this.options=i;for(var t in a)a.hasOwnProperty(t)&&(i[t]=n&&"undefined"!=typeof n[t]?n[t]:a[t],"function"==typeof i[t]&&(i[t]=i[t].bind(this)));"string"==typeof i.easing&&"undefined"!=typeof jQuery&&jQuery.isFunction(jQuery.easing[i.easing])?i.easing=jQuery.easing[i.easing]:i.easing=a.easing,"number"==typeof i.animate&&(i.animate={duration:i.animate,enabled:!0}),"boolean"!=typeof i.animate||i.animate||(i.animate={duration:1e3,enabled:i.animate}),this.renderer=new i.renderer(e,i),this.renderer.draw(r),e.dataset&&e.dataset.percent?this.update(parseFloat(e.dataset.percent)):e.getAttribute&&e.getAttribute("data-percent")&&this.update(parseFloat(e.getAttribute("data-percent")))}.bind(this);this.update=function(e){return e=parseFloat(e),i.animate.enabled?this.renderer.animate(r,e):this.renderer.draw(e),r=e,this}.bind(this),this.disableAnimation=function(){return i.animate.enabled=!1,this},this.enableAnimation=function(){return i.animate.enabled=!0,this},o()};e.fn.easyPieChart=function(t){return this.each(function(){var a;e.data(this,"easyPieChart")||(a=e.extend({},t,e(this).data()),e.data(this,"easyPieChart",new n(this,a)))})}});
js/match-height.js ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * jquery-match-height 0.7.0 by @liabru
3
+ * http://brm.io/jquery-match-height/
4
+ * License: MIT
5
+ */
6
+
7
+ ;(function(factory) { // eslint-disable-line no-extra-semi
8
+ 'use strict';
9
+ if (typeof define === 'function' && define.amd) {
10
+ // AMD
11
+ define(['jquery'], factory);
12
+ } else if (typeof module !== 'undefined' && module.exports) {
13
+ // CommonJS
14
+ module.exports = factory(require('jquery'));
15
+ } else {
16
+ // Global
17
+ factory(jQuery);
18
+ }
19
+ })(function($) {
20
+ /*
21
+ * internal
22
+ */
23
+
24
+ var _previousResizeWidth = -1,
25
+ _updateTimeout = -1;
26
+
27
+ /*
28
+ * _parse
29
+ * value parse utility function
30
+ */
31
+
32
+ var _parse = function(value) {
33
+ // parse value and convert NaN to 0
34
+ return parseFloat(value) || 0;
35
+ };
36
+
37
+ /*
38
+ * _rows
39
+ * utility function returns array of jQuery selections representing each row
40
+ * (as displayed after float wrapping applied by browser)
41
+ */
42
+
43
+ var _rows = function(elements) {
44
+ var tolerance = 1,
45
+ $elements = $(elements),
46
+ lastTop = null,
47
+ rows = [];
48
+
49
+ // group elements by their top position
50
+ $elements.each(function(){
51
+ var $that = $(this),
52
+ top = $that.offset().top - _parse($that.css('margin-top')),
53
+ lastRow = rows.length > 0 ? rows[rows.length - 1] : null;
54
+
55
+ if (lastRow === null) {
56
+ // first item on the row, so just push it
57
+ rows.push($that);
58
+ } else {
59
+ // if the row top is the same, add to the row group
60
+ if (Math.floor(Math.abs(lastTop - top)) <= tolerance) {
61
+ rows[rows.length - 1] = lastRow.add($that);
62
+ } else {
63
+ // otherwise start a new row group
64
+ rows.push($that);
65
+ }
66
+ }
67
+
68
+ // keep track of the last row top
69
+ lastTop = top;
70
+ });
71
+
72
+ return rows;
73
+ };
74
+
75
+ /*
76
+ * _parseOptions
77
+ * handle plugin options
78
+ */
79
+
80
+ var _parseOptions = function(options) {
81
+ var opts = {
82
+ byRow: true,
83
+ property: 'height',
84
+ target: null,
85
+ remove: false
86
+ };
87
+
88
+ if (typeof options === 'object') {
89
+ return $.extend(opts, options);
90
+ }
91
+
92
+ if (typeof options === 'boolean') {
93
+ opts.byRow = options;
94
+ } else if (options === 'remove') {
95
+ opts.remove = true;
96
+ }
97
+
98
+ return opts;
99
+ };
100
+
101
+ /*
102
+ * matchHeight
103
+ * plugin definition
104
+ */
105
+
106
+ var matchHeight = $.fn.matchHeight = function(options) {
107
+ var opts = _parseOptions(options);
108
+
109
+ // handle remove
110
+ if (opts.remove) {
111
+ var that = this;
112
+
113
+ // remove fixed height from all selected elements
114
+ this.css(opts.property, '');
115
+
116
+ // remove selected elements from all groups
117
+ $.each(matchHeight._groups, function(key, group) {
118
+ group.elements = group.elements.not(that);
119
+ });
120
+
121
+ // TODO: cleanup empty groups
122
+
123
+ return this;
124
+ }
125
+
126
+ if (this.length <= 1 && !opts.target) {
127
+ return this;
128
+ }
129
+
130
+ // keep track of this group so we can re-apply later on load and resize events
131
+ matchHeight._groups.push({
132
+ elements: this,
133
+ options: opts
134
+ });
135
+
136
+ // match each element's height to the tallest element in the selection
137
+ matchHeight._apply(this, opts);
138
+
139
+ return this;
140
+ };
141
+
142
+ /*
143
+ * plugin global options
144
+ */
145
+
146
+ matchHeight.version = '0.7.0';
147
+ matchHeight._groups = [];
148
+ matchHeight._throttle = 80;
149
+ matchHeight._maintainScroll = false;
150
+ matchHeight._beforeUpdate = null;
151
+ matchHeight._afterUpdate = null;
152
+ matchHeight._rows = _rows;
153
+ matchHeight._parse = _parse;
154
+ matchHeight._parseOptions = _parseOptions;
155
+
156
+ /*
157
+ * matchHeight._apply
158
+ * apply matchHeight to given elements
159
+ */
160
+
161
+ matchHeight._apply = function(elements, options) {
162
+ var opts = _parseOptions(options),
163
+ $elements = $(elements),
164
+ rows = [$elements];
165
+
166
+ // take note of scroll position
167
+ var scrollTop = $(window).scrollTop(),
168
+ htmlHeight = $('html').outerHeight(true);
169
+
170
+ // get hidden parents
171
+ var $hiddenParents = $elements.parents().filter(':hidden');
172
+
173
+ // cache the original inline style
174
+ $hiddenParents.each(function() {
175
+ var $that = $(this);
176
+ $that.data('style-cache', $that.attr('style'));
177
+ });
178
+
179
+ // temporarily must force hidden parents visible
180
+ $hiddenParents.css('display', 'block');
181
+
182
+ // get rows if using byRow, otherwise assume one row
183
+ if (opts.byRow && !opts.target) {
184
+
185
+ // must first force an arbitrary equal height so floating elements break evenly
186
+ $elements.each(function() {
187
+ var $that = $(this),
188
+ display = $that.css('display');
189
+
190
+ // temporarily force a usable display value
191
+ if (display !== 'inline-block' && display !== 'flex' && display !== 'inline-flex') {
192
+ display = 'block';
193
+ }
194
+
195
+ // cache the original inline style
196
+ $that.data('style-cache', $that.attr('style'));
197
+
198
+ $that.css({
199
+ 'display': display,
200
+ 'padding-top': '0',
201
+ 'padding-bottom': '0',
202
+ 'margin-top': '0',
203
+ 'margin-bottom': '0',
204
+ 'border-top-width': '0',
205
+ 'border-bottom-width': '0',
206
+ 'height': '100px',
207
+ 'overflow': 'hidden'
208
+ });
209
+ });
210
+
211
+ // get the array of rows (based on element top position)
212
+ rows = _rows($elements);
213
+
214
+ // revert original inline styles
215
+ $elements.each(function() {
216
+ var $that = $(this);
217
+ $that.attr('style', $that.data('style-cache') || '');
218
+ });
219
+ }
220
+
221
+ $.each(rows, function(key, row) {
222
+ var $row = $(row),
223
+ targetHeight = 0;
224
+
225
+ if (!opts.target) {
226
+ // skip apply to rows with only one item
227
+ if (opts.byRow && $row.length <= 1) {
228
+ $row.css(opts.property, '');
229
+ return;
230
+ }
231
+
232
+ // iterate the row and find the max height
233
+ $row.each(function(){
234
+ var $that = $(this),
235
+ style = $that.attr('style'),
236
+ display = $that.css('display');
237
+
238
+ // temporarily force a usable display value
239
+ if (display !== 'inline-block' && display !== 'flex' && display !== 'inline-flex') {
240
+ display = 'block';
241
+ }
242
+
243
+ // ensure we get the correct actual height (and not a previously set height value)
244
+ var css = { 'display': display };
245
+ css[opts.property] = '';
246
+ $that.css(css);
247
+
248
+ // find the max height (including padding, but not margin)
249
+ if ($that.outerHeight(false) > targetHeight) {
250
+ targetHeight = $that.outerHeight(false);
251
+ }
252
+
253
+ // revert styles
254
+ if (style) {
255
+ $that.attr('style', style);
256
+ } else {
257
+ $that.css('display', '');
258
+ }
259
+ });
260
+ } else {
261
+ // if target set, use the height of the target element
262
+ targetHeight = opts.target.outerHeight(false);
263
+ }
264
+
265
+ // iterate the row and apply the height to all elements
266
+ $row.each(function(){
267
+ var $that = $(this),
268
+ verticalPadding = 0;
269
+
270
+ // don't apply to a target
271
+ if (opts.target && $that.is(opts.target)) {
272
+ return;
273
+ }
274
+
275
+ // handle padding and border correctly (required when not using border-box)
276
+ if ($that.css('box-sizing') !== 'border-box') {
277
+ verticalPadding += _parse($that.css('border-top-width')) + _parse($that.css('border-bottom-width'));
278
+ verticalPadding += _parse($that.css('padding-top')) + _parse($that.css('padding-bottom'));
279
+ }
280
+
281
+ // set the height (accounting for padding and border)
282
+ $that.css(opts.property, (targetHeight - verticalPadding) + 'px');
283
+ });
284
+ });
285
+
286
+ // revert hidden parents
287
+ $hiddenParents.each(function() {
288
+ var $that = $(this);
289
+ $that.attr('style', $that.data('style-cache') || null);
290
+ });
291
+
292
+ // restore scroll position if enabled
293
+ if (matchHeight._maintainScroll) {
294
+ $(window).scrollTop((scrollTop / htmlHeight) * $('html').outerHeight(true));
295
+ }
296
+
297
+ return this;
298
+ };
299
+
300
+ /*
301
+ * matchHeight._applyDataApi
302
+ * applies matchHeight to all elements with a data-match-height attribute
303
+ */
304
+
305
+ matchHeight._applyDataApi = function() {
306
+ var groups = {};
307
+
308
+ // generate groups by their groupId set by elements using data-match-height
309
+ $('[data-match-height], [data-mh]').each(function() {
310
+ var $this = $(this),
311
+ groupId = $this.attr('data-mh') || $this.attr('data-match-height');
312
+
313
+ if (groupId in groups) {
314
+ groups[groupId] = groups[groupId].add($this);
315
+ } else {
316
+ groups[groupId] = $this;
317
+ }
318
+ });
319
+
320
+ // apply matchHeight to each group
321
+ $.each(groups, function() {
322
+ this.matchHeight(true);
323
+ });
324
+ };
325
+
326
+ /*
327
+ * matchHeight._update
328
+ * updates matchHeight on all current groups with their correct options
329
+ */
330
+
331
+ var _update = function(event) {
332
+ if (matchHeight._beforeUpdate) {
333
+ matchHeight._beforeUpdate(event, matchHeight._groups);
334
+ }
335
+
336
+ $.each(matchHeight._groups, function() {
337
+ matchHeight._apply(this.elements, this.options);
338
+ });
339
+
340
+ if (matchHeight._afterUpdate) {
341
+ matchHeight._afterUpdate(event, matchHeight._groups);
342
+ }
343
+ };
344
+
345
+ matchHeight._update = function(throttle, event) {
346
+ // prevent update if fired from a resize event
347
+ // where the viewport width hasn't actually changed
348
+ // fixes an event looping bug in IE8
349
+ if (event && event.type === 'resize') {
350
+ var windowWidth = $(window).width();
351
+ if (windowWidth === _previousResizeWidth) {
352
+ return;
353
+ }
354
+ _previousResizeWidth = windowWidth;
355
+ }
356
+
357
+ // throttle updates
358
+ if (!throttle) {
359
+ _update(event);
360
+ } else if (_updateTimeout === -1) {
361
+ _updateTimeout = setTimeout(function() {
362
+ _update(event);
363
+ _updateTimeout = -1;
364
+ }, matchHeight._throttle);
365
+ }
366
+ };
367
+
368
+ /*
369
+ * bind events
370
+ */
371
+
372
+ // apply on DOM ready event
373
+ $(matchHeight._applyDataApi);
374
+
375
+ // update heights on load and resize events
376
+ $(window).bind('load', function(event) {
377
+ matchHeight._update(false, event);
378
+ });
379
+
380
+ // throttled update heights on resize events
381
+ $(window).bind('resize orientationchange', function(event) {
382
+ matchHeight._update(true, event);
383
+ });
384
+
385
+ });
js/match-height.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery"],t):"undefined"!=typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){var e=-1,o=-1,i=function(t){return parseFloat(t)||0},a=function(e){var o=1,a=t(e),n=null,r=[];return a.each(function(){var e=t(this),a=e.offset().top-i(e.css("margin-top")),s=r.length>0?r[r.length-1]:null;null===s?r.push(e):Math.floor(Math.abs(n-a))<=o?r[r.length-1]=s.add(e):r.push(e),n=a}),r},n=function(e){var o={byRow:!0,property:"height",target:null,remove:!1};return"object"==typeof e?t.extend(o,e):("boolean"==typeof e?o.byRow=e:"remove"===e&&(o.remove=!0),o)},r=t.fn.matchHeight=function(e){var o=n(e);if(o.remove){var i=this;return this.css(o.property,""),t.each(r._groups,function(t,e){e.elements=e.elements.not(i)}),this}return this.length<=1&&!o.target?this:(r._groups.push({elements:this,options:o}),r._apply(this,o),this)};r.version="0.7.0",r._groups=[],r._throttle=80,r._maintainScroll=!1,r._beforeUpdate=null,r._afterUpdate=null,r._rows=a,r._parse=i,r._parseOptions=n,r._apply=function(e,o){var s=n(o),h=t(e),l=[h],c=t(window).scrollTop(),p=t("html").outerHeight(!0),d=h.parents().filter(":hidden");return d.each(function(){var e=t(this);e.data("style-cache",e.attr("style"))}),d.css("display","block"),s.byRow&&!s.target&&(h.each(function(){var e=t(this),o=e.css("display");"inline-block"!==o&&"flex"!==o&&"inline-flex"!==o&&(o="block"),e.data("style-cache",e.attr("style")),e.css({display:o,"padding-top":"0","padding-bottom":"0","margin-top":"0","margin-bottom":"0","border-top-width":"0","border-bottom-width":"0",height:"100px",overflow:"hidden"})}),l=a(h),h.each(function(){var e=t(this);e.attr("style",e.data("style-cache")||"")})),t.each(l,function(e,o){var a=t(o),n=0;if(s.target)n=s.target.outerHeight(!1);else{if(s.byRow&&a.length<=1)return void a.css(s.property,"");a.each(function(){var e=t(this),o=e.attr("style"),i=e.css("display");"inline-block"!==i&&"flex"!==i&&"inline-flex"!==i&&(i="block");var a={display:i};a[s.property]="",e.css(a),e.outerHeight(!1)>n&&(n=e.outerHeight(!1)),o?e.attr("style",o):e.css("display","")})}a.each(function(){var e=t(this),o=0;s.target&&e.is(s.target)||("border-box"!==e.css("box-sizing")&&(o+=i(e.css("border-top-width"))+i(e.css("border-bottom-width")),o+=i(e.css("padding-top"))+i(e.css("padding-bottom"))),e.css(s.property,n-o+"px"))})}),d.each(function(){var e=t(this);e.attr("style",e.data("style-cache")||null)}),r._maintainScroll&&t(window).scrollTop(c/p*t("html").outerHeight(!0)),this},r._applyDataApi=function(){var e={};t("[data-match-height], [data-mh]").each(function(){var o=t(this),i=o.attr("data-mh")||o.attr("data-match-height");i in e?e[i]=e[i].add(o):e[i]=o}),t.each(e,function(){this.matchHeight(!0)})};var s=function(e){r._beforeUpdate&&r._beforeUpdate(e,r._groups),t.each(r._groups,function(){r._apply(this.elements,this.options)}),r._afterUpdate&&r._afterUpdate(e,r._groups)};r._update=function(i,a){if(a&&"resize"===a.type){var n=t(window).width();if(n===e)return;e=n}i?-1===o&&(o=setTimeout(function(){s(a),o=-1},r._throttle)):s(a)},t(r._applyDataApi),t(window).bind("load",function(t){r._update(!1,t)}),t(window).bind("resize orientationchange",function(t){r._update(!0,t)})});
js/mixitup.js ADDED
@@ -0,0 +1,2098 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**!
2
+ * MixItUp v2.1.11
3
+ *
4
+ * @copyright Copyright 2015 KunkaLabs Limited.
5
+ * @author KunkaLabs Limited.
6
+ * @link https://mixitup.kunkalabs.com
7
+ *
8
+ * @license Commercial use requires a commercial license.
9
+ * https://mixitup.kunkalabs.com/licenses/
10
+ *
11
+ * Non-commercial use permitted under terms of CC-BY-NC license.
12
+ * http://creativecommons.org/licenses/by-nc/3.0/
13
+ */
14
+
15
+ (function($, undf){
16
+ 'use strict';
17
+
18
+ /**
19
+ * MixItUp Constructor Function
20
+ * @constructor
21
+ * @extends jQuery
22
+ */
23
+
24
+ $.MixItUp = function(){
25
+ var self = this;
26
+
27
+ self._execAction('_constructor', 0);
28
+
29
+ $.extend(self, {
30
+
31
+ /* Public Properties
32
+ ---------------------------------------------------------------------- */
33
+
34
+ selectors: {
35
+ target: '.mix',
36
+ filter: '.filter',
37
+ sort: '.sort'
38
+ },
39
+
40
+ animation: {
41
+ enable: true,
42
+ effects: 'fade scale',
43
+ duration: 600,
44
+ easing: 'ease',
45
+ perspectiveDistance: '3000',
46
+ perspectiveOrigin: '50% 50%',
47
+ queue: true,
48
+ queueLimit: 1,
49
+ animateChangeLayout: false,
50
+ animateResizeContainer: true,
51
+ animateResizeTargets: false,
52
+ staggerSequence: false,
53
+ reverseOut: false
54
+ },
55
+
56
+ callbacks: {
57
+ onMixLoad: false,
58
+ onMixStart: false,
59
+ onMixBusy: false,
60
+ onMixEnd: false,
61
+ onMixFail: false,
62
+ _user: false
63
+ },
64
+
65
+ controls: {
66
+ enable: true,
67
+ live: false,
68
+ toggleFilterButtons: false,
69
+ toggleLogic: 'or',
70
+ activeClass: 'active'
71
+ },
72
+
73
+ layout: {
74
+ display: 'inline-block',
75
+ containerClass: '',
76
+ containerClassFail: 'fail'
77
+ },
78
+
79
+ load: {
80
+ filter: 'all',
81
+ sort: false
82
+ },
83
+
84
+ /* Private Properties
85
+ ---------------------------------------------------------------------- */
86
+
87
+ _$body: null,
88
+ _$container: null,
89
+ _$targets: null,
90
+ _$parent: null,
91
+ _$sortButtons: null,
92
+ _$filterButtons: null,
93
+
94
+ _suckMode: false,
95
+ _mixing: false,
96
+ _sorting: false,
97
+ _clicking: false,
98
+ _loading: true,
99
+ _changingLayout: false,
100
+ _changingClass: false,
101
+ _changingDisplay: false,
102
+
103
+ _origOrder: [],
104
+ _startOrder: [],
105
+ _newOrder: [],
106
+ _activeFilter: null,
107
+ _toggleArray: [],
108
+ _toggleString: '',
109
+ _activeSort: 'default:asc',
110
+ _newSort: null,
111
+ _startHeight: null,
112
+ _newHeight: null,
113
+ _incPadding: true,
114
+ _newDisplay: null,
115
+ _newClass: null,
116
+ _targetsBound: 0,
117
+ _targetsDone: 0,
118
+ _queue: [],
119
+
120
+ _$show: $(),
121
+ _$hide: $()
122
+ });
123
+
124
+ self._execAction('_constructor', 1);
125
+ };
126
+
127
+ /**
128
+ * MixItUp Prototype
129
+ * @override
130
+ */
131
+
132
+ $.MixItUp.prototype = {
133
+ constructor: $.MixItUp,
134
+
135
+ /* Static Properties
136
+ ---------------------------------------------------------------------- */
137
+
138
+ _instances: {},
139
+ _handled: {
140
+ _filter: {},
141
+ _sort: {}
142
+ },
143
+ _bound: {
144
+ _filter: {},
145
+ _sort: {}
146
+ },
147
+ _actions: {},
148
+ _filters: {},
149
+
150
+ /* Static Methods
151
+ ---------------------------------------------------------------------- */
152
+
153
+ /**
154
+ * Extend
155
+ * @since 2.1.0
156
+ * @param {object} new properties/methods
157
+ * @extends {object} prototype
158
+ */
159
+
160
+ extend: function(extension){
161
+ for(var key in extension){
162
+ $.MixItUp.prototype[key] = extension[key];
163
+ }
164
+ },
165
+
166
+ /**
167
+ * Add Action
168
+ * @since 2.1.0
169
+ * @param {string} hook name
170
+ * @param {string} namespace
171
+ * @param {function} function to execute
172
+ * @param {number} priority
173
+ * @extends {object} $.MixItUp.prototype._actions
174
+ */
175
+
176
+ addAction: function(hook, name, func, priority){
177
+ $.MixItUp.prototype._addHook('_actions', hook, name, func, priority);
178
+ },
179
+
180
+ /**
181
+ * Add Filter
182
+ * @since 2.1.0
183
+ * @param {string} hook name
184
+ * @param {string} namespace
185
+ * @param {function} function to execute
186
+ * @param {number} priority
187
+ * @extends {object} $.MixItUp.prototype._filters
188
+ */
189
+
190
+ addFilter: function(hook, name, func, priority){
191
+ $.MixItUp.prototype._addHook('_filters', hook, name, func, priority);
192
+ },
193
+
194
+ /**
195
+ * Add Hook
196
+ * @since 2.1.0
197
+ * @param {string} type of hook
198
+ * @param {string} hook name
199
+ * @param {function} function to execute
200
+ * @param {number} priority
201
+ * @extends {object} $.MixItUp.prototype._filters
202
+ */
203
+
204
+ _addHook: function(type, hook, name, func, priority){
205
+ var collection = $.MixItUp.prototype[type],
206
+ obj = {};
207
+
208
+ priority = (priority === 1 || priority === 'post') ? 'post' : 'pre';
209
+
210
+ obj[hook] = {};
211
+ obj[hook][priority] = {};
212
+ obj[hook][priority][name] = func;
213
+
214
+ $.extend(true, collection, obj);
215
+ },
216
+
217
+
218
+ /* Private Methods
219
+ ---------------------------------------------------------------------- */
220
+
221
+ /**
222
+ * Initialise
223
+ * @since 2.0.0
224
+ * @param {object} domNode
225
+ * @param {object} config
226
+ */
227
+
228
+ _init: function(domNode, config){
229
+ var self = this;
230
+
231
+ self._execAction('_init', 0, arguments);
232
+
233
+ config && $.extend(true, self, config);
234
+
235
+ self._$body = $('body');
236
+ self._domNode = domNode;
237
+ self._$container = $(domNode);
238
+ self._$container.addClass(self.layout.containerClass);
239
+ self._id = domNode.id;
240
+
241
+ self._platformDetect();
242
+
243
+ self._brake = self._getPrefixedCSS('transition', 'none');
244
+
245
+ self._refresh(true);
246
+
247
+ self._$parent = self._$targets.parent().length ? self._$targets.parent() : self._$container;
248
+
249
+ if(self.load.sort){
250
+ self._newSort = self._parseSort(self.load.sort);
251
+ self._newSortString = self.load.sort;
252
+ self._activeSort = self.load.sort;
253
+ self._sort();
254
+ self._printSort();
255
+ }
256
+
257
+ self._activeFilter = self.load.filter === 'all' ?
258
+ self.selectors.target :
259
+ self.load.filter === 'none' ?
260
+ '' :
261
+ self.load.filter;
262
+
263
+ self.controls.enable && self._bindHandlers();
264
+
265
+ if(self.controls.toggleFilterButtons){
266
+ self._buildToggleArray();
267
+
268
+ for(var i = 0; i < self._toggleArray.length; i++){
269
+ self._updateControls({filter: self._toggleArray[i], sort: self._activeSort}, true);
270
+ };
271
+ } else if(self.controls.enable){
272
+ self._updateControls({filter: self._activeFilter, sort: self._activeSort});
273
+ }
274
+
275
+ self._filter();
276
+
277
+ self._init = true;
278
+
279
+ self._$container.data('mixItUp',self);
280
+
281
+ self._execAction('_init', 1, arguments);
282
+
283
+ self._buildState();
284
+
285
+ self._$targets.css(self._brake);
286
+
287
+ self._goMix(self.animation.enable);
288
+ },
289
+
290
+ /**
291
+ * Platform Detect
292
+ * @since 2.0.0
293
+ */
294
+
295
+ _platformDetect: function(){
296
+ var self = this,
297
+ vendorsTrans = ['Webkit', 'Moz', 'O', 'ms'],
298
+ vendorsRAF = ['webkit', 'moz'],
299
+ chrome = window.navigator.appVersion.match(/Chrome\/(\d+)\./) || false,
300
+ ff = typeof InstallTrigger !== 'undefined',
301
+ prefix = function(el){
302
+ for (var i = 0; i < vendorsTrans.length; i++){
303
+ if (vendorsTrans[i] + 'Transition' in el.style){
304
+ return {
305
+ prefix: '-'+vendorsTrans[i].toLowerCase()+'-',
306
+ vendor: vendorsTrans[i]
307
+ };
308
+ };
309
+ };
310
+ return 'transition' in el.style ? '' : false;
311
+ },
312
+ transPrefix = prefix(self._domNode);
313
+
314
+ self._execAction('_platformDetect', 0);
315
+
316
+ self._chrome = chrome ? parseInt(chrome[1], 10) : false;
317
+ self._ff = ff ? parseInt(window.navigator.userAgent.match(/rv:([^)]+)\)/)[1]) : false;
318
+ self._prefix = transPrefix.prefix;
319
+ self._vendor = transPrefix.vendor;
320
+ self._suckMode = window.atob && self._prefix ? false : true;
321
+
322
+ self._suckMode && (self.animation.enable = false);
323
+ (self._ff && self._ff <= 4) && (self.animation.enable = false);
324
+
325
+ /* Polyfills
326
+ ---------------------------------------------------------------------- */
327
+
328
+ /**
329
+ * window.requestAnimationFrame
330
+ */
331
+
332
+ for(var x = 0; x < vendorsRAF.length && !window.requestAnimationFrame; x++){
333
+ window.requestAnimationFrame = window[vendorsRAF[x]+'RequestAnimationFrame'];
334
+ }
335
+
336
+ /**
337
+ * Object.getPrototypeOf
338
+ */
339
+
340
+ if(typeof Object.getPrototypeOf !== 'function'){
341
+ if(typeof 'test'.__proto__ === 'object'){
342
+ Object.getPrototypeOf = function(object){
343
+ return object.__proto__;
344
+ };
345
+ } else {
346
+ Object.getPrototypeOf = function(object){
347
+ return object.constructor.prototype;
348
+ };
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Element.nextElementSibling
354
+ */
355
+
356
+ if(self._domNode.nextElementSibling === undf){
357
+ Object.defineProperty(Element.prototype, 'nextElementSibling',{
358
+ get: function(){
359
+ var el = this.nextSibling;
360
+
361
+ while(el){
362
+ if(el.nodeType ===1){
363
+ return el;
364
+ }
365
+ el = el.nextSibling;
366
+ }
367
+ return null;
368
+ }
369
+ });
370
+ }
371
+
372
+ self._execAction('_platformDetect', 1);
373
+ },
374
+
375
+ /**
376
+ * Refresh
377
+ * @since 2.0.0
378
+ * @param {boolean} init
379
+ * @param {boolean} force
380
+ */
381
+
382
+ _refresh: function(init, force){
383
+ var self = this;
384
+
385
+ self._execAction('_refresh', 0, arguments);
386
+
387
+ self._$targets = self._$container.find(self.selectors.target);
388
+
389
+ for(var i = 0; i < self._$targets.length; i++){
390
+ var target = self._$targets[i];
391
+
392
+ if(target.dataset === undf || force){
393
+
394
+ target.dataset = {};
395
+
396
+ for(var j = 0; j < target.attributes.length; j++){
397
+
398
+ var attr = target.attributes[j],
399
+ name = attr.name,
400
+ val = attr.value;
401
+
402
+ if(name.indexOf('data-') > -1){
403
+ var dataName = self._helpers._camelCase(name.substring(5,name.length));
404
+ target.dataset[dataName] = val;
405
+ }
406
+ }
407
+ }
408
+
409
+ if(target.mixParent === undf){
410
+ target.mixParent = self._id;
411
+ }
412
+ }
413
+
414
+ if(
415
+ (self._$targets.length && init) ||
416
+ (!self._origOrder.length && self._$targets.length)
417
+ ){
418
+ self._origOrder = [];
419
+
420
+ for(var i = 0; i < self._$targets.length; i++){
421
+ var target = self._$targets[i];
422
+
423
+ self._origOrder.push(target);
424
+ }
425
+ }
426
+
427
+ self._execAction('_refresh', 1, arguments);
428
+ },
429
+
430
+ /**
431
+ * Bind Handlers
432
+ * @since 2.0.0
433
+ */
434
+
435
+ _bindHandlers: function(){
436
+ var self = this,
437
+ filters = $.MixItUp.prototype._bound._filter,
438
+ sorts = $.MixItUp.prototype._bound._sort;
439
+
440
+ self._execAction('_bindHandlers', 0);
441
+
442
+ if(self.controls.live){
443
+ self._$body
444
+ .on('click.mixItUp.'+self._id, self.selectors.sort, function(){
445
+ self._processClick($(this), 'sort');
446
+ })
447
+ .on('click.mixItUp.'+self._id, self.selectors.filter, function(){
448
+ self._processClick($(this), 'filter');
449
+ });
450
+ } else {
451
+ self._$sortButtons = $(self.selectors.sort);
452
+ self._$filterButtons = $(self.selectors.filter);
453
+
454
+ self._$sortButtons.on('click.mixItUp.'+self._id, function(){
455
+ self._processClick($(this), 'sort');
456
+ });
457
+
458
+ self._$filterButtons.on('click.mixItUp.'+self._id, function(){
459
+ self._processClick($(this), 'filter');
460
+ });
461
+ }
462
+
463
+ filters[self.selectors.filter] = (filters[self.selectors.filter] === undf) ? 1 : filters[self.selectors.filter] + 1;
464
+ sorts[self.selectors.sort] = (sorts[self.selectors.sort] === undf) ? 1 : sorts[self.selectors.sort] + 1;
465
+
466
+ self._execAction('_bindHandlers', 1);
467
+ },
468
+
469
+ /**
470
+ * Process Click
471
+ * @since 2.0.0
472
+ * @param {object} $button
473
+ * @param {string} type
474
+ */
475
+
476
+ _processClick: function($button, type){
477
+ var self = this,
478
+ trackClick = function($button, type, off){
479
+ var proto = $.MixItUp.prototype;
480
+
481
+ proto._handled['_'+type][self.selectors[type]] = (proto._handled['_'+type][self.selectors[type]] === undf) ?
482
+ 1 :
483
+ proto._handled['_'+type][self.selectors[type]] + 1;
484
+
485
+ if(proto._handled['_'+type][self.selectors[type]] === proto._bound['_'+type][self.selectors[type]]){
486
+ $button[(off ? 'remove' : 'add')+'Class'](self.controls.activeClass);
487
+ delete proto._handled['_'+type][self.selectors[type]];
488
+ }
489
+ };
490
+
491
+ self._execAction('_processClick', 0, arguments);
492
+
493
+ if(!self._mixing || (self.animation.queue && self._queue.length < self.animation.queueLimit)){
494
+ self._clicking = true;
495
+
496
+ if(type === 'sort'){
497
+ var sort = $button.attr('data-sort');
498
+
499
+ if(!$button.hasClass(self.controls.activeClass) || sort.indexOf('random') > -1){
500
+ $(self.selectors.sort).removeClass(self.controls.activeClass);
501
+ trackClick($button, type);
502
+ self.sort(sort);
503
+ }
504
+ }
505
+
506
+ if(type === 'filter') {
507
+ var filter = $button.attr('data-filter'),
508
+ ndx,
509
+ seperator = self.controls.toggleLogic === 'or' ? ',' : '';
510
+
511
+ if(!self.controls.toggleFilterButtons){
512
+ if(!$button.hasClass(self.controls.activeClass)){
513
+ $(self.selectors.filter).removeClass(self.controls.activeClass);
514
+ trackClick($button, type);
515
+ self.filter(filter);
516
+ }
517
+ } else {
518
+ self._buildToggleArray();
519
+
520
+ if(!$button.hasClass(self.controls.activeClass)){
521
+ trackClick($button, type);
522
+
523
+ self._toggleArray.push(filter);
524
+ } else {
525
+ trackClick($button, type, true);
526
+ ndx = self._toggleArray.indexOf(filter);
527
+ self._toggleArray.splice(ndx, 1);
528
+ }
529
+
530
+ self._toggleArray = $.grep(self._toggleArray,function(n){return(n);});
531
+
532
+ self._toggleString = self._toggleArray.join(seperator);
533
+
534
+ self.filter(self._toggleString);
535
+ }
536
+ }
537
+
538
+ self._execAction('_processClick', 1, arguments);
539
+ } else {
540
+ if(typeof self.callbacks.onMixBusy === 'function'){
541
+ self.callbacks.onMixBusy.call(self._domNode, self._state, self);
542
+ }
543
+ self._execAction('_processClickBusy', 1, arguments);
544
+ }
545
+ },
546
+
547
+ /**
548
+ * Build Toggle Array
549
+ * @since 2.0.0
550
+ */
551
+
552
+ _buildToggleArray: function(){
553
+ var self = this,
554
+ activeFilter = self._activeFilter.replace(/\s/g, '');
555
+
556
+ self._execAction('_buildToggleArray', 0, arguments);
557
+
558
+ if(self.controls.toggleLogic === 'or'){
559
+ self._toggleArray = activeFilter.split(',');
560
+ } else {
561
+ self._toggleArray = activeFilter.split('.');
562
+
563
+ !self._toggleArray[0] && self._toggleArray.shift();
564
+
565
+ for(var i = 0, filter; filter = self._toggleArray[i]; i++){
566
+ self._toggleArray[i] = '.'+filter;
567
+ }
568
+ }
569
+
570
+ self._execAction('_buildToggleArray', 1, arguments);
571
+ },
572
+
573
+ /**
574
+ * Update Controls
575
+ * @since 2.0.0
576
+ * @param {object} command
577
+ * @param {boolean} multi
578
+ */
579
+
580
+ _updateControls: function(command, multi){
581
+ var self = this,
582
+ output = {
583
+ filter: command.filter,
584
+ sort: command.sort
585
+ },
586
+ update = function($el, filter){
587
+ try {
588
+ (multi && type === 'filter' && !(output.filter === 'none' || output.filter === '')) ?
589
+ $el.filter(filter).addClass(self.controls.activeClass) :
590
+ $el.removeClass(self.controls.activeClass).filter(filter).addClass(self.controls.activeClass);
591
+ } catch(e) {}
592
+ },
593
+ type = 'filter',
594
+ $el = null;
595
+
596
+ self._execAction('_updateControls', 0, arguments);
597
+
598
+ (command.filter === undf) && (output.filter = self._activeFilter);
599
+ (command.sort === undf) && (output.sort = self._activeSort);
600
+ (output.filter === self.selectors.target) && (output.filter = 'all');
601
+
602
+ for(var i = 0; i < 2; i++){
603
+ $el = self.controls.live ? $(self.selectors[type]) : self['_$'+type+'Buttons'];
604
+ $el && update($el, '[data-'+type+'="'+output[type]+'"]');
605
+ type = 'sort';
606
+ }
607
+
608
+ self._execAction('_updateControls', 1, arguments);
609
+ },
610
+
611
+ /**
612
+ * Filter (private)
613
+ * @since 2.0.0
614
+ */
615
+
616
+ _filter: function(){
617
+ var self = this;
618
+
619
+ self._execAction('_filter', 0);
620
+
621
+ for(var i = 0; i < self._$targets.length; i++){
622
+ var $target = $(self._$targets[i]);
623
+
624
+ if($target.is(self._activeFilter)){
625
+ self._$show = self._$show.add($target);
626
+ } else {
627
+ self._$hide = self._$hide.add($target);
628
+ }
629
+ }
630
+
631
+ self._execAction('_filter', 1);
632
+ },
633
+
634
+ /**
635
+ * Sort (private)
636
+ * @since 2.0.0
637
+ */
638
+
639
+ _sort: function(){
640
+ var self = this,
641
+ arrayShuffle = function(oldArray){
642
+ var newArray = oldArray.slice(),
643
+ len = newArray.length,
644
+ i = len;
645
+
646
+ while(i--){
647
+ var p = parseInt(Math.random()*len);
648
+ var t = newArray[i];
649
+ newArray[i] = newArray[p];
650
+ newArray[p] = t;
651
+ };
652
+ return newArray;
653
+ };
654
+
655
+ self._execAction('_sort', 0);
656
+
657
+ self._startOrder = [];
658
+
659
+ for(var i = 0; i < self._$targets.length; i++){
660
+ var target = self._$targets[i];
661
+
662
+ self._startOrder.push(target);
663
+ }
664
+
665
+ switch(self._newSort[0].sortBy){
666
+ case 'default':
667
+ self._newOrder = self._origOrder;
668
+ break;
669
+ case 'random':
670
+ self._newOrder = arrayShuffle(self._startOrder);
671
+ break;
672
+ case 'custom':
673
+ self._newOrder = self._newSort[0].order;
674
+ break;
675
+ default:
676
+ self._newOrder = self._startOrder.concat().sort(function(a, b){
677
+ return self._compare(a, b);
678
+ });
679
+ }
680
+
681
+ self._execAction('_sort', 1);
682
+ },
683
+
684
+ /**
685
+ * Compare Algorithm
686
+ * @since 2.0.0
687
+ * @param {string|number} a
688
+ * @param {string|number} b
689
+ * @param {number} depth (recursion)
690
+ * @return {number}
691
+ */
692
+
693
+ _compare: function(a, b, depth){
694
+ depth = depth ? depth : 0;
695
+
696
+ var self = this,
697
+ order = self._newSort[depth].order,
698
+ getData = function(el){
699
+ return el.dataset[self._newSort[depth].sortBy] || 0;
700
+ },
701
+ attrA = isNaN(getData(a) * 1) ? getData(a).toLowerCase() : getData(a) * 1,
702
+ attrB = isNaN(getData(b) * 1) ? getData(b).toLowerCase() : getData(b) * 1;
703
+
704
+ if(attrA < attrB)
705
+ return order === 'asc' ? -1 : 1;
706
+ if(attrA > attrB)
707
+ return order === 'asc' ? 1 : -1;
708
+ if(attrA === attrB && self._newSort.length > depth+1)
709
+ return self._compare(a, b, depth+1);
710
+
711
+ return 0;
712
+ },
713
+
714
+ /**
715
+ * Print Sort
716
+ * @since 2.0.0
717
+ * @param {boolean} reset
718
+ */
719
+
720
+ _printSort: function(reset){
721
+ var self = this,
722
+ order = reset ? self._startOrder : self._newOrder,
723
+ targets = self._$parent[0].querySelectorAll(self.selectors.target),
724
+ nextSibling = targets.length ? targets[targets.length -1].nextElementSibling : null,
725
+ frag = document.createDocumentFragment();
726
+
727
+ self._execAction('_printSort', 0, arguments);
728
+
729
+ for(var i = 0; i < targets.length; i++){
730
+ var target = targets[i],
731
+ whiteSpace = target.nextSibling;
732
+
733
+ if(target.style.position === 'absolute') continue;
734
+
735
+ if(whiteSpace && whiteSpace.nodeName === '#text'){
736
+ self._$parent[0].removeChild(whiteSpace);
737
+ }
738
+
739
+ self._$parent[0].removeChild(target);
740
+ }
741
+
742
+ for(var i = 0; i < order.length; i++){
743
+ var el = order[i];
744
+
745
+ if(self._newSort[0].sortBy === 'default' && self._newSort[0].order === 'desc' && !reset){
746
+ var firstChild = frag.firstChild;
747
+ frag.insertBefore(el, firstChild);
748
+ frag.insertBefore(document.createTextNode(' '), el);
749
+ } else {
750
+ frag.appendChild(el);
751
+ frag.appendChild(document.createTextNode(' '));
752
+ }
753
+ }
754
+
755
+ nextSibling ?
756
+ self._$parent[0].insertBefore(frag, nextSibling) :
757
+ self._$parent[0].appendChild(frag);
758
+
759
+ self._execAction('_printSort', 1, arguments);
760
+ },
761
+
762
+ /**
763
+ * Parse Sort
764
+ * @since 2.0.0
765
+ * @param {string} sortString
766
+ * @return {array} newSort
767
+ */
768
+
769
+ _parseSort: function(sortString){
770
+ var self = this,
771
+ rules = typeof sortString === 'string' ? sortString.split(' ') : [sortString],
772
+ newSort = [];
773
+
774
+ for(var i = 0; i < rules.length; i++){
775
+ var rule = typeof sortString === 'string' ? rules[i].split(':') : ['custom', rules[i]],
776
+ ruleObj = {
777
+ sortBy: self._helpers._camelCase(rule[0]),
778
+ order: rule[1] || 'asc'
779
+ };
780
+
781
+ newSort.push(ruleObj);
782
+
783
+ if(ruleObj.sortBy === 'default' || ruleObj.sortBy === 'random') break;
784
+ }
785
+
786
+ return self._execFilter('_parseSort', newSort, arguments);
787
+ },
788
+
789
+ /**
790
+ * Parse Effects
791
+ * @since 2.0.0
792
+ * @return {object} effects
793
+ */
794
+
795
+ _parseEffects: function(){
796
+ var self = this,
797
+ effects = {
798
+ opacity: '',
799
+ transformIn: '',
800
+ transformOut: '',
801
+ filter: ''
802
+ },
803
+ parse = function(effect, extract, reverse){
804
+ if(self.animation.effects.indexOf(effect) > -1){
805
+ if(extract){
806
+ var propIndex = self.animation.effects.indexOf(effect+'(');
807
+ if(propIndex > -1){
808
+ var str = self.animation.effects.substring(propIndex),
809
+ match = /\(([^)]+)\)/.exec(str),
810
+ val = match[1];
811
+
812
+ return {val: val};
813
+ }
814
+ }
815
+ return true;
816
+ } else {
817
+ return false;
818
+ }
819
+ },
820
+ negate = function(value, invert){
821
+ if(invert){
822
+ return value.charAt(0) === '-' ? value.substr(1, value.length) : '-'+value;
823
+ } else {
824
+ return value;
825
+ }
826
+ },
827
+ buildTransform = function(key, invert){
828
+ var transforms = [
829
+ ['scale', '.01'],
830
+ ['translateX', '20px'],
831
+ ['translateY', '20px'],
832
+ ['translateZ', '20px'],
833
+ ['rotateX', '90deg'],
834
+ ['rotateY', '90deg'],
835
+ ['rotateZ', '180deg'],
836
+ ];
837
+
838
+ for(var i = 0; i < transforms.length; i++){
839
+ var prop = transforms[i][0],
840
+ def = transforms[i][1],
841
+ inverted = invert && prop !== 'scale';
842
+
843
+ effects[key] += parse(prop) ? prop+'('+negate(parse(prop, true).val || def, inverted)+') ' : '';
844
+ }
845
+ };
846
+
847
+ effects.opacity = parse('fade') ? parse('fade',true).val || '0' : '1';
848
+
849
+ buildTransform('transformIn');
850
+
851
+ self.animation.reverseOut ? buildTransform('transformOut', true) : (effects.transformOut = effects.transformIn);
852
+
853
+ effects.transition = {};
854
+
855
+ effects.transition = self._getPrefixedCSS('transition','all '+self.animation.duration+'ms '+self.animation.easing+', opacity '+self.animation.duration+'ms linear');
856
+
857
+ self.animation.stagger = parse('stagger') ? true : false;
858
+ self.animation.staggerDuration = parseInt(parse('stagger') ? (parse('stagger',true).val ? parse('stagger',true).val : 100) : 100);
859
+
860
+ return self._execFilter('_parseEffects', effects);
861
+ },
862
+
863
+ /**
864
+ * Build State
865
+ * @since 2.0.0
866
+ * @param {boolean} future
867
+ * @return {object} futureState
868
+ */
869
+
870
+ _buildState: function(future){
871
+ var self = this,
872
+ state = {};
873
+
874
+ self._execAction('_buildState', 0);
875
+
876
+ state = {
877
+ activeFilter: self._activeFilter === '' ? 'none' : self._activeFilter,
878
+ activeSort: future && self._newSortString ? self._newSortString : self._activeSort,
879
+ fail: !self._$show.length && self._activeFilter !== '',
880
+ $targets: self._$targets,
881
+ $show: self._$show,
882
+ $hide: self._$hide,
883
+ totalTargets: self._$targets.length,
884
+ totalShow: self._$show.length,
885
+ totalHide: self._$hide.length,
886
+ display: future && self._newDisplay ? self._newDisplay : self.layout.display
887
+ };
888
+
889
+ if(future){
890
+ return self._execFilter('_buildState', state);
891
+ } else {
892
+ self._state = state;
893
+
894
+ self._execAction('_buildState', 1);
895
+ }
896
+ },
897
+
898
+ /**
899
+ * Go Mix
900
+ * @since 2.0.0
901
+ * @param {boolean} animate
902
+ */
903
+
904
+ _goMix: function(animate){
905
+ var self = this,
906
+ phase1 = function(){
907
+ if(self._chrome && (self._chrome === 31)){
908
+ chromeFix(self._$parent[0]);
909
+ }
910
+
911
+ self._setInter();
912
+
913
+ phase2();
914
+ },
915
+ phase2 = function(){
916
+ var scrollTop = window.pageYOffset,
917
+ scrollLeft = window.pageXOffset,
918
+ docHeight = document.documentElement.scrollHeight;
919
+
920
+ self._getInterMixData();
921
+
922
+ self._setFinal();
923
+
924
+ self._getFinalMixData();
925
+
926
+ (window.pageYOffset !== scrollTop) && window.scrollTo(scrollLeft, scrollTop);
927
+
928
+ self._prepTargets();
929
+
930
+ if(window.requestAnimationFrame){
931
+ requestAnimationFrame(phase3);
932
+ } else {
933
+ setTimeout(function(){
934
+ phase3();
935
+ },20);
936
+ }
937
+ },
938
+ phase3 = function(){
939
+ self._animateTargets();
940
+
941
+ if(self._targetsBound === 0){
942
+ self._cleanUp();
943
+ }
944
+ },
945
+ chromeFix = function(grid){
946
+ var parent = grid.parentElement,
947
+ placeholder = document.createElement('div'),
948
+ frag = document.createDocumentFragment();
949
+
950
+ parent.insertBefore(placeholder, grid);
951
+ frag.appendChild(grid);
952
+ parent.replaceChild(grid, placeholder);
953
+ },
954
+ futureState = self._buildState(true);
955
+
956
+ self._execAction('_goMix', 0, arguments);
957
+
958
+ !self.animation.duration && (animate = false);
959
+
960
+ self._mixing = true;
961
+
962
+ self._$container.removeClass(self.layout.containerClassFail);
963
+
964
+ if(typeof self.callbacks.onMixStart === 'function'){
965
+ self.callbacks.onMixStart.call(self._domNode, self._state, futureState, self);
966
+ }
967
+
968
+ self._$container.trigger('mixStart', [self._state, futureState, self]);
969
+
970
+ self._getOrigMixData();
971
+
972
+ if(animate && !self._suckMode){
973
+
974
+ window.requestAnimationFrame ?
975
+ requestAnimationFrame(phase1) :
976
+ phase1();
977
+
978
+ } else {
979
+ self._cleanUp();
980
+ }
981
+
982
+ self._execAction('_goMix', 1, arguments);
983
+ },
984
+
985
+ /**
986
+ * Get Target Data
987
+ * @since 2.0.0
988
+ */
989
+
990
+ _getTargetData: function(el, stage){
991
+ var self = this,
992
+ elStyle;
993
+
994
+ el.dataset[stage+'PosX'] = el.offsetLeft;
995
+ el.dataset[stage+'PosY'] = el.offsetTop;
996
+
997
+ if(self.animation.animateResizeTargets){
998
+ elStyle = !self._suckMode ?
999
+ window.getComputedStyle(el) :
1000
+ {
1001
+ marginBottom: '',
1002
+ marginRight: ''
1003
+ };
1004
+
1005
+ el.dataset[stage+'MarginBottom'] = parseInt(elStyle.marginBottom);
1006
+ el.dataset[stage+'MarginRight'] = parseInt(elStyle.marginRight);
1007
+ el.dataset[stage+'Width'] = el.offsetWidth;
1008
+ el.dataset[stage+'Height'] = el.offsetHeight;
1009
+ }
1010
+ },
1011
+
1012
+ /**
1013
+ * Get Original Mix Data
1014
+ * @since 2.0.0
1015
+ */
1016
+
1017
+ _getOrigMixData: function(){
1018
+ var self = this,
1019
+ parentStyle = !self._suckMode ? window.getComputedStyle(self._$parent[0]) : {boxSizing: ''},
1020
+ parentBS = parentStyle.boxSizing || parentStyle[self._vendor+'BoxSizing'];
1021
+
1022
+ self._incPadding = (parentBS === 'border-box');
1023
+
1024
+ self._execAction('_getOrigMixData', 0);
1025
+
1026
+ !self._suckMode && (self.effects = self._parseEffects());
1027
+
1028
+ self._$toHide = self._$hide.filter(':visible');
1029
+ self._$toShow = self._$show.filter(':hidden');
1030
+ self._$pre = self._$targets.filter(':visible');
1031
+
1032
+ self._startHeight = self._incPadding ?
1033
+ self._$parent.outerHeight() :
1034
+ self._$parent.height();
1035
+
1036
+ for(var i = 0; i < self._$pre.length; i++){
1037
+ var el = self._$pre[i];
1038
+
1039
+ self._getTargetData(el, 'orig');
1040
+ }
1041
+
1042
+ self._execAction('_getOrigMixData', 1);
1043
+ },
1044
+
1045
+ /**
1046
+ * Set Intermediate Positions
1047
+ * @since 2.0.0
1048
+ */
1049
+
1050
+ _setInter: function(){
1051
+ var self = this;
1052
+
1053
+ self._execAction('_setInter', 0);
1054
+
1055
+ if(self._changingLayout && self.animation.animateChangeLayout){
1056
+ self._$toShow.css('display',self._newDisplay);
1057
+
1058
+ if(self._changingClass){
1059
+ self._$container
1060
+ .removeClass(self.layout.containerClass)
1061
+ .addClass(self._newClass);
1062
+ }
1063
+ } else {
1064
+ self._$toShow.css('display', self.layout.display);
1065
+ }
1066
+
1067
+ self._execAction('_setInter', 1);
1068
+ },
1069
+
1070
+ /**
1071
+ * Get Intermediate Mix Data
1072
+ * @since 2.0.0
1073
+ */
1074
+
1075
+ _getInterMixData: function(){
1076
+ var self = this;
1077
+
1078
+ self._execAction('_getInterMixData', 0);
1079
+
1080
+ for(var i = 0; i < self._$toShow.length; i++){
1081
+ var el = self._$toShow[i];
1082
+
1083
+ self._getTargetData(el, 'inter');
1084
+ }
1085
+
1086
+ for(var i = 0; i < self._$pre.length; i++){
1087
+ var el = self._$pre[i];
1088
+
1089
+ self._getTargetData(el, 'inter');
1090
+ }
1091
+
1092
+ self._execAction('_getInterMixData', 1);
1093
+ },
1094
+
1095
+ /**
1096
+ * Set Final Positions
1097
+ * @since 2.0.0
1098
+ */
1099
+
1100
+ _setFinal: function(){
1101
+ var self = this;
1102
+
1103
+ self._execAction('_setFinal', 0);
1104
+
1105
+ self._sorting && self._printSort();
1106
+
1107
+ self._$toHide.removeStyle('display');
1108
+
1109
+ if(self._changingLayout && self.animation.animateChangeLayout){
1110
+ self._$pre.css('display',self._newDisplay);
1111
+ }
1112
+
1113
+ self._execAction('_setFinal', 1);
1114
+ },
1115
+
1116
+ /**
1117
+ * Get Final Mix Data
1118
+ * @since 2.0.0
1119
+ */
1120
+
1121
+ _getFinalMixData: function(){
1122
+ var self = this;
1123
+
1124
+ self._execAction('_getFinalMixData', 0);
1125
+
1126
+ for(var i = 0; i < self._$toShow.length; i++){
1127
+ var el = self._$toShow[i];
1128
+
1129
+ self._getTargetData(el, 'final');
1130
+ }
1131
+
1132
+ for(var i = 0; i < self._$pre.length; i++){
1133
+ var el = self._$pre[i];
1134
+
1135
+ self._getTargetData(el, 'final');
1136
+ }
1137
+
1138
+ self._newHeight = self._incPadding ?
1139
+ self._$parent.outerHeight() :
1140
+ self._$parent.height();
1141
+
1142
+ self._sorting && self._printSort(true);
1143
+
1144
+ self._$toShow.removeStyle('display');
1145
+
1146
+ self._$pre.css('display',self.layout.display);
1147
+
1148
+ if(self._changingClass && self.animation.animateChangeLayout){
1149
+ self._$container
1150
+ .removeClass(self._newClass)
1151
+ .addClass(self.layout.containerClass);
1152
+ }
1153
+
1154
+ self._execAction('_getFinalMixData', 1);
1155
+ },
1156
+
1157
+ /**
1158
+ * Prepare Targets
1159
+ * @since 2.0.0
1160
+ */
1161
+
1162
+ _prepTargets: function(){
1163
+ var self = this,
1164
+ transformCSS = {
1165
+ _in: self._getPrefixedCSS('transform', self.effects.transformIn),
1166
+ _out: self._getPrefixedCSS('transform', self.effects.transformOut)
1167
+ };
1168
+
1169
+ self._execAction('_prepTargets', 0);
1170
+
1171
+ if(self.animation.animateResizeContainer){
1172
+ self._$parent.css('height',self._startHeight+'px');
1173
+ }
1174
+
1175
+ for(var i = 0; i < self._$toShow.length; i++){
1176
+ var el = self._$toShow[i],
1177
+ $el = $(el);
1178
+
1179
+ el.style.opacity = self.effects.opacity;
1180
+ el.style.display = (self._changingLayout && self.animation.animateChangeLayout) ?
1181
+ self._newDisplay :
1182
+ self.layout.display;
1183
+
1184
+ $el.css(transformCSS._in);
1185
+
1186
+ if(self.animation.animateResizeTargets){
1187
+ el.style.width = el.dataset.finalWidth+'px';
1188
+ el.style.height = el.dataset.finalHeight+'px';
1189
+ el.style.marginRight = -(el.dataset.finalWidth - el.dataset.interWidth) + (el.dataset.finalMarginRight * 1)+'px';
1190
+ el.style.marginBottom = -(el.dataset.finalHeight - el.dataset.interHeight) + (el.dataset.finalMarginBottom * 1)+'px';
1191
+ }
1192
+ }
1193
+
1194
+ for(var i = 0; i < self._$pre.length; i++){
1195
+ var el = self._$pre[i],
1196
+ $el = $(el),
1197
+ translate = {
1198
+ x: el.dataset.origPosX - el.dataset.interPosX,
1199
+ y: el.dataset.origPosY - el.dataset.interPosY
1200
+ },
1201
+ transformCSS = self._getPrefixedCSS('transform','translate('+translate.x+'px,'+translate.y+'px)');
1202
+
1203
+ $el.css(transformCSS);
1204
+
1205
+ if(self.animation.animateResizeTargets){
1206
+ el.style.width = el.dataset.origWidth+'px';
1207
+ el.style.height = el.dataset.origHeight+'px';
1208
+
1209
+ if(el.dataset.origWidth - el.dataset.finalWidth){
1210
+ el.style.marginRight = -(el.dataset.origWidth - el.dataset.interWidth) + (el.dataset.origMarginRight * 1)+'px';
1211
+ }
1212
+
1213
+ if(el.dataset.origHeight - el.dataset.finalHeight){
1214
+ el.style.marginBottom = -(el.dataset.origHeight - el.dataset.interHeight) + (el.dataset.origMarginBottom * 1) +'px';
1215
+ }
1216
+ }
1217
+ }
1218
+
1219
+ self._execAction('_prepTargets', 1);
1220
+ },
1221
+
1222
+ /**
1223
+ * Animate Targets
1224
+ * @since 2.0.0
1225
+ */
1226
+
1227
+ _animateTargets: function(){
1228
+ var self = this;
1229
+
1230
+ self._execAction('_animateTargets', 0);
1231
+
1232
+ self._targetsDone = 0;
1233
+ self._targetsBound = 0;
1234
+
1235
+ self._$parent
1236
+ .css(self._getPrefixedCSS('perspective', self.animation.perspectiveDistance+'px'))
1237
+ .css(self._getPrefixedCSS('perspective-origin', self.animation.perspectiveOrigin));
1238
+
1239
+ if(self.animation.animateResizeContainer){
1240
+ self._$parent
1241
+ .css(self._getPrefixedCSS('transition','height '+self.animation.duration+'ms ease'))
1242
+ .css('height',self._newHeight+'px');
1243
+ }
1244
+
1245
+ for(var i = 0; i < self._$toShow.length; i++){
1246
+ var el = self._$toShow[i],
1247
+ $el = $(el),
1248
+ translate = {
1249
+ x: el.dataset.finalPosX - el.dataset.interPosX,
1250
+ y: el.dataset.finalPosY - el.dataset.interPosY
1251
+ },
1252
+ delay = self._getDelay(i),
1253
+ toShowCSS = {};
1254
+
1255
+ el.style.opacity = '';
1256
+
1257
+ for(var j = 0; j < 2; j++){
1258
+ var a = j === 0 ? a = self._prefix : '';
1259
+
1260
+ if(self._ff && self._ff <= 20){
1261
+ toShowCSS[a+'transition-property'] = 'all';
1262
+ toShowCSS[a+'transition-timing-function'] = self.animation.easing+'ms';
1263
+ toShowCSS[a+'transition-duration'] = self.animation.duration+'ms';
1264
+ }
1265
+
1266
+ toShowCSS[a+'transition-delay'] = delay+'ms';
1267
+ toShowCSS[a+'transform'] = 'translate('+translate.x+'px,'+translate.y+'px)';
1268
+ }
1269
+
1270
+ if(self.effects.transform || self.effects.opacity){
1271
+ self._bindTargetDone($el);
1272
+ }
1273
+
1274
+ (self._ff && self._ff <= 20) ?
1275
+ $el.css(toShowCSS) :
1276
+ $el.css(self.effects.transition).css(toShowCSS);
1277
+ }
1278
+
1279
+ for(var i = 0; i < self._$pre.length; i++){
1280
+ var el = self._$pre[i],
1281
+ $el = $(el),
1282
+ translate = {
1283
+ x: el.dataset.finalPosX - el.dataset.interPosX,
1284
+ y: el.dataset.finalPosY - el.dataset.interPosY
1285
+ },
1286
+ delay = self._getDelay(i);
1287
+
1288
+ if(!(
1289
+ el.dataset.finalPosX === el.dataset.origPosX &&
1290
+ el.dataset.finalPosY === el.dataset.origPosY
1291
+ )){
1292
+ self._bindTargetDone($el);
1293
+ }
1294
+
1295
+ $el.css(self._getPrefixedCSS('transition', 'all '+self.animation.duration+'ms '+self.animation.easing+' '+delay+'ms'));
1296
+ $el.css(self._getPrefixedCSS('transform', 'translate('+translate.x+'px,'+translate.y+'px)'));
1297
+
1298
+ if(self.animation.animateResizeTargets){
1299
+ if(el.dataset.origWidth - el.dataset.finalWidth && el.dataset.finalWidth * 1){
1300
+ el.style.width = el.dataset.finalWidth+'px';
1301
+ el.style.marginRight = -(el.dataset.finalWidth - el.dataset.interWidth)+(el.dataset.finalMarginRight * 1)+'px';
1302
+ }
1303
+
1304
+ if(el.dataset.origHeight - el.dataset.finalHeight && el.dataset.finalHeight * 1){
1305
+ el.style.height = el.dataset.finalHeight+'px';
1306
+ el.style.marginBottom = -(el.dataset.finalHeight - el.dataset.interHeight)+(el.dataset.finalMarginBottom * 1) +'px';
1307
+ }
1308
+ }
1309
+ }
1310
+
1311
+ if(self._changingClass){
1312
+ self._$container
1313
+ .removeClass(self.layout.containerClass)
1314
+ .addClass(self._newClass);
1315
+ }
1316
+
1317
+ for(var i = 0; i < self._$toHide.length; i++){
1318
+ var el = self._$toHide[i],
1319
+ $el = $(el),
1320
+ delay = self._getDelay(i),
1321
+ toHideCSS = {};
1322
+
1323
+ for(var j = 0; j<2; j++){
1324
+ var a = j === 0 ? a = self._prefix : '';
1325
+
1326
+ toHideCSS[a+'transition-delay'] = delay+'ms';
1327
+ toHideCSS[a+'transform'] = self.effects.transformOut;
1328
+ toHideCSS.opacity = self.effects.opacity;
1329
+ }
1330
+
1331
+ $el.css(self.effects.transition).css(toHideCSS);
1332
+
1333
+ if(self.effects.transform || self.effects.opacity){
1334
+ self._bindTargetDone($el);
1335
+ };
1336
+ }
1337
+
1338
+ self._execAction('_animateTargets', 1);
1339
+
1340
+ },
1341
+
1342
+ /**
1343
+ * Bind Targets TransitionEnd
1344
+ * @since 2.0.0
1345
+ * @param {object} $el
1346
+ */
1347
+
1348
+ _bindTargetDone: function($el){
1349
+ var self = this,
1350
+ el = $el[0];
1351
+
1352
+ self._execAction('_bindTargetDone', 0, arguments);
1353
+
1354
+ if(!el.dataset.bound){
1355
+
1356
+ el.dataset.bound = true;
1357
+ self._targetsBound++;
1358
+
1359
+ $el.on('webkitTransitionEnd.mixItUp transitionend.mixItUp',function(e){
1360
+ if(
1361
+ (e.originalEvent.propertyName.indexOf('transform') > -1 ||
1362
+ e.originalEvent.propertyName.indexOf('opacity') > -1) &&
1363
+ $(e.originalEvent.target).is(self.selectors.target)
1364
+ ){
1365
+ $el.off('.mixItUp');
1366
+ el.dataset.bound = '';
1367
+ self._targetDone();
1368
+ }
1369
+ });
1370
+ }
1371
+
1372
+ self._execAction('_bindTargetDone', 1, arguments);
1373
+ },
1374
+
1375
+ /**
1376
+ * Target Done
1377
+ * @since 2.0.0
1378
+ */
1379
+
1380
+ _targetDone: function(){
1381
+ var self = this;
1382
+
1383
+ self._execAction('_targetDone', 0);
1384
+
1385
+ self._targetsDone++;
1386
+
1387
+ (self._targetsDone === self._targetsBound) && self._cleanUp();
1388
+
1389
+ self._execAction('_targetDone', 1);
1390
+ },
1391
+
1392
+ /**
1393
+ * Clean Up
1394
+ * @since 2.0.0
1395
+ */
1396
+
1397
+ _cleanUp: function(){
1398
+ var self = this,
1399
+ targetStyles = self.animation.animateResizeTargets ?
1400
+ 'transform opacity width height margin-bottom margin-right' :
1401
+ 'transform opacity',
1402
+ unBrake = function(){
1403
+ self._$targets.removeStyle('transition', self._prefix);
1404
+ };
1405
+
1406
+ self._execAction('_cleanUp', 0);
1407
+
1408
+ !self._changingLayout ?
1409
+ self._$show.css('display',self.layout.display) :
1410
+ self._$show.css('display',self._newDisplay);
1411
+
1412
+ self._$targets.css(self._brake);
1413
+
1414
+ self._$targets
1415
+ .removeStyle(targetStyles, self._prefix)
1416
+ .removeAttr('data-inter-pos-x data-inter-pos-y data-final-pos-x data-final-pos-y data-orig-pos-x data-orig-pos-y data-orig-height data-orig-width data-final-height data-final-width data-inter-width data-inter-height data-orig-margin-right data-orig-margin-bottom data-inter-margin-right data-inter-margin-bottom data-final-margin-right data-final-margin-bottom');
1417
+
1418
+ self._$hide.removeStyle('display');
1419
+
1420
+ self._$parent.removeStyle('height transition perspective-distance perspective perspective-origin-x perspective-origin-y perspective-origin perspectiveOrigin', self._prefix);
1421
+
1422
+ if(self._sorting){
1423
+ self._printSort();
1424
+ self._activeSort = self._newSortString;
1425
+ self._sorting = false;
1426
+ }
1427
+
1428
+ if(self._changingLayout){
1429
+ if(self._changingDisplay){
1430
+ self.layout.display = self._newDisplay;
1431
+ self._changingDisplay = false;
1432
+ }
1433
+
1434
+ if(self._changingClass){
1435
+ self._$parent.removeClass(self.layout.containerClass).addClass(self._newClass);
1436
+ self.layout.containerClass = self._newClass;
1437
+ self._changingClass = false;
1438
+ }
1439
+
1440
+ self._changingLayout = false;
1441
+ }
1442
+
1443
+ self._refresh();
1444
+
1445
+ self._buildState();
1446
+
1447
+ if(self._state.fail){
1448
+ self._$container.addClass(self.layout.containerClassFail);
1449
+ }
1450
+
1451
+ self._$show = $();
1452
+ self._$hide = $();
1453
+
1454
+ if(window.requestAnimationFrame){
1455
+ requestAnimationFrame(unBrake);
1456
+ }
1457
+
1458
+ self._mixing = false;
1459
+
1460
+ if(typeof self.callbacks._user === 'function'){
1461
+ self.callbacks._user.call(self._domNode, self._state, self);
1462
+ }
1463
+
1464
+ if(typeof self.callbacks.onMixEnd === 'function'){
1465
+ self.callbacks.onMixEnd.call(self._domNode, self._state, self);
1466
+ }
1467
+
1468
+ self._$container.trigger('mixEnd', [self._state, self]);
1469
+
1470
+ if(self._state.fail){
1471
+ (typeof self.callbacks.onMixFail === 'function') && self.callbacks.onMixFail.call(self._domNode, self._state, self);
1472
+ self._$container.trigger('mixFail', [self._state, self]);
1473
+ }
1474
+
1475
+ if(self._loading){
1476
+ (typeof self.callbacks.onMixLoad === 'function') && self.callbacks.onMixLoad.call(self._domNode, self._state, self);
1477
+ self._$container.trigger('mixLoad', [self._state, self]);
1478
+ }
1479
+
1480
+ if(self._queue.length){
1481
+ self._execAction('_queue', 0);
1482
+
1483
+ self.multiMix(self._queue[0][0],self._queue[0][1],self._queue[0][2]);
1484
+ self._queue.splice(0, 1);
1485
+ }
1486
+
1487
+ self._execAction('_cleanUp', 1);
1488
+
1489
+ self._loading = false;
1490
+ },
1491
+
1492
+ /**
1493
+ * Get Prefixed CSS
1494
+ * @since 2.0.0
1495
+ * @param {string} property
1496
+ * @param {string} value
1497
+ * @param {boolean} prefixValue
1498
+ * @return {object} styles
1499
+ */
1500
+
1501
+ _getPrefixedCSS: function(property, value, prefixValue){
1502
+ var self = this,
1503
+ styles = {},
1504
+ prefix = '',
1505
+ i = -1;
1506
+
1507
+ for(i = 0; i < 2; i++){
1508
+ prefix = i === 0 ? self._prefix : '';
1509
+ prefixValue ? styles[prefix+property] = prefix+value : styles[prefix+property] = value;
1510
+ }
1511
+
1512
+ return self._execFilter('_getPrefixedCSS', styles, arguments);
1513
+ },
1514
+
1515
+ /**
1516
+ * Get Delay
1517
+ * @since 2.0.0
1518
+ * @param {number} i
1519
+ * @return {number} delay
1520
+ */
1521
+
1522
+ _getDelay: function(i){
1523
+ var self = this,
1524
+ n = typeof self.animation.staggerSequence === 'function' ? self.animation.staggerSequence.call(self._domNode, i, self._state) : i,
1525
+ delay = self.animation.stagger ? n * self.animation.staggerDuration : 0;
1526
+
1527
+ return self._execFilter('_getDelay', delay, arguments);
1528
+ },
1529
+
1530
+ /**
1531
+ * Parse MultiMix Arguments
1532
+ * @since 2.0.0
1533
+ * @param {array} args
1534
+ * @return {object} output
1535
+ */
1536
+
1537
+ _parseMultiMixArgs: function(args){
1538
+ var self = this,
1539
+ output = {
1540
+ command: null,
1541
+ animate: self.animation.enable,
1542
+ callback: null
1543
+ };
1544
+
1545
+ for(var i = 0; i < args.length; i++){
1546
+ var arg = args[i];
1547
+
1548
+ if(arg !== null){
1549
+ if(typeof arg === 'object' || typeof arg === 'string'){
1550
+ output.command = arg;
1551
+ } else if(typeof arg === 'boolean'){
1552
+ output.animate = arg;
1553
+ } else if(typeof arg === 'function'){
1554
+ output.callback = arg;
1555
+ }
1556
+ }
1557
+ }
1558
+
1559
+ return self._execFilter('_parseMultiMixArgs', output, arguments);
1560
+ },
1561
+
1562
+ /**
1563
+ * Parse Insert Arguments
1564
+ * @since 2.0.0
1565
+ * @param {array} args
1566
+ * @return {object} output
1567
+ */
1568
+
1569
+ _parseInsertArgs: function(args){
1570
+ var self = this,
1571
+ output = {
1572
+ index: 0,
1573
+ $object: $(),
1574
+ multiMix: {filter: self._state.activeFilter},
1575
+ callback: null
1576
+ };
1577
+
1578
+ for(var i = 0; i < args.length; i++){
1579
+ var arg = args[i];
1580
+
1581
+ if(typeof arg === 'number'){
1582
+ output.index = arg;
1583
+ } else if(typeof arg === 'object' && arg instanceof $){
1584
+ output.$object = arg;
1585
+ } else if(typeof arg === 'object' && self._helpers._isElement(arg)){
1586
+ output.$object = $(arg);
1587
+ } else if(typeof arg === 'object' && arg !== null){
1588
+ output.multiMix = arg;
1589
+ } else if(typeof arg === 'boolean' && !arg){
1590
+ output.multiMix = false;
1591
+ } else if(typeof arg === 'function'){
1592
+ output.callback = arg;
1593
+ }
1594
+ }
1595
+
1596
+ return self._execFilter('_parseInsertArgs', output, arguments);
1597
+ },
1598
+
1599
+ /**
1600
+ * Execute Action
1601
+ * @since 2.0.0
1602
+ * @param {string} methodName
1603
+ * @param {boolean} isPost
1604
+ * @param {array} args
1605
+ */
1606
+
1607
+ _execAction: function(methodName, isPost, args){
1608
+ var self = this,
1609
+ context = isPost ? 'post' : 'pre';
1610
+
1611
+ if(!self._actions.isEmptyObject && self._actions.hasOwnProperty(methodName)){
1612
+ for(var key in self._actions[methodName][context]){
1613
+ self._actions[methodName][context][key].call(self, args);
1614
+ }
1615
+ }
1616
+ },
1617
+
1618
+ /**
1619
+ * Execute Filter
1620
+ * @since 2.0.0
1621
+ * @param {string} methodName
1622
+ * @param {mixed} value
1623
+ * @return {mixed} value
1624
+ */
1625
+
1626
+ _execFilter: function(methodName, value, args){
1627
+ var self = this;
1628
+
1629
+ if(!self._filters.isEmptyObject && self._filters.hasOwnProperty(methodName)){
1630
+ for(var key in self._filters[methodName]){
1631
+ return self._filters[methodName][key].call(self, args);
1632
+ }
1633
+ } else {
1634
+ return value;
1635
+ }
1636
+ },
1637
+
1638
+ /* Helpers
1639
+ ---------------------------------------------------------------------- */
1640
+
1641
+ _helpers: {
1642
+
1643
+ /**
1644
+ * CamelCase
1645
+ * @since 2.0.0
1646
+ * @param {string}
1647
+ * @return {string}
1648
+ */
1649
+
1650
+ _camelCase: function(string){
1651
+ return string.replace(/-([a-z])/g, function(g){
1652
+ return g[1].toUpperCase();
1653
+ });
1654
+ },
1655
+
1656
+ /**
1657
+ * Is Element
1658
+ * @since 2.1.3
1659
+ * @param {object} element to test
1660
+ * @return {boolean}
1661
+ */
1662
+
1663
+ _isElement: function(el){
1664
+ if(window.HTMLElement){
1665
+ return el instanceof HTMLElement;
1666
+ } else {
1667
+ return (
1668
+ el !== null &&
1669
+ el.nodeType === 1 &&
1670
+ el.nodeName === 'string'
1671
+ );
1672
+ }
1673
+ }
1674
+ },
1675
+
1676
+ /* Public Methods
1677
+ ---------------------------------------------------------------------- */
1678
+
1679
+ /**
1680
+ * Is Mixing
1681
+ * @since 2.0.0
1682
+ * @return {boolean}
1683
+ */
1684
+
1685
+ isMixing: function(){
1686
+ var self = this;
1687
+
1688
+ return self._execFilter('isMixing', self._mixing);
1689
+ },
1690
+
1691
+ /**
1692
+ * Filter (public)
1693
+ * @since 2.0.0
1694
+ * @param {array} arguments
1695
+ */
1696
+
1697
+ filter: function(){
1698
+ var self = this,
1699
+ args = self._parseMultiMixArgs(arguments);
1700
+
1701
+ self._clicking && (self._toggleString = '');
1702
+
1703
+ self.multiMix({filter: args.command}, args.animate, args.callback);
1704
+ },
1705
+
1706
+ /**
1707
+ * Sort (public)
1708
+ * @since 2.0.0
1709
+ * @param {array} arguments
1710
+ */
1711
+
1712
+ sort: function(){
1713
+ var self = this,
1714
+ args = self._parseMultiMixArgs(arguments);
1715
+
1716
+ self.multiMix({sort: args.command}, args.animate, args.callback);
1717
+ },
1718
+
1719
+ /**
1720
+ * Change Layout (public)
1721
+ * @since 2.0.0
1722
+ * @param {array} arguments
1723
+ */
1724
+
1725
+ changeLayout: function(){
1726
+ var self = this,
1727
+ args = self._parseMultiMixArgs(arguments);
1728
+
1729
+ self.multiMix({changeLayout: args.command}, args.animate, args.callback);
1730
+ },
1731
+
1732
+ /**
1733
+ * MultiMix
1734
+ * @since 2.0.0
1735
+ * @param {array} arguments
1736
+ */
1737
+
1738
+ multiMix: function(){
1739
+ var self = this,
1740
+ args = self._parseMultiMixArgs(arguments);
1741
+
1742
+ self._execAction('multiMix', 0, arguments);
1743
+
1744
+ if(!self._mixing){
1745
+ if(self.controls.enable && !self._clicking){
1746
+ self.controls.toggleFilterButtons && self._buildToggleArray();
1747
+ self._updateControls(args.command, self.controls.toggleFilterButtons);
1748
+ }
1749
+
1750
+ (self._queue.length < 2) && (self._clicking = false);
1751
+
1752
+ delete self.callbacks._user;
1753
+ if(args.callback) self.callbacks._user = args.callback;
1754
+
1755
+ var sort = args.command.sort,
1756
+ filter = args.command.filter,
1757
+ changeLayout = args.command.changeLayout;
1758
+
1759
+ self._refresh();
1760
+
1761
+ if(sort){
1762
+ self._newSort = self._parseSort(sort);
1763
+ self._newSortString = sort;
1764
+
1765
+ self._sorting = true;
1766
+ self._sort();
1767
+ }
1768
+
1769
+ if(filter !== undf){
1770
+ filter = (filter === 'all') ? self.selectors.target : filter;
1771
+
1772
+ self._activeFilter = filter;
1773
+ }
1774
+
1775
+ self._filter();
1776
+
1777
+ if(changeLayout){
1778
+ self._newDisplay = (typeof changeLayout === 'string') ? changeLayout : changeLayout.display || self.layout.display;
1779
+ self._newClass = changeLayout.containerClass || '';
1780
+
1781
+ if(
1782
+ self._newDisplay !== self.layout.display ||
1783
+ self._newClass !== self.layout.containerClass
1784
+ ){
1785
+ self._changingLayout = true;
1786
+
1787
+ self._changingClass = (self._newClass !== self.layout.containerClass);
1788
+ self._changingDisplay = (self._newDisplay !== self.layout.display);
1789
+ }
1790
+ }
1791
+
1792
+ self._$targets.css(self._brake);
1793
+
1794
+ self._goMix(args.animate ^ self.animation.enable ? args.animate : self.animation.enable);
1795
+
1796
+ self._execAction('multiMix', 1, arguments);
1797
+
1798
+ } else {
1799
+ if(self.animation.queue && self._queue.length < self.animation.queueLimit){
1800
+ self._queue.push(arguments);
1801
+
1802
+ (self.controls.enable && !self._clicking) && self._updateControls(args.command);
1803
+
1804
+ self._execAction('multiMixQueue', 1, arguments);
1805
+
1806
+ } else {
1807
+ if(typeof self.callbacks.onMixBusy === 'function'){
1808
+ self.callbacks.onMixBusy.call(self._domNode, self._state, self);
1809
+ }
1810
+ self._$container.trigger('mixBusy', [self._state, self]);
1811
+
1812
+ self._execAction('multiMixBusy', 1, arguments);
1813
+ }
1814
+ }
1815
+ },
1816
+
1817
+ /**
1818
+ * Insert
1819
+ * @since 2.0.0
1820
+ * @param {array} arguments
1821
+ */
1822
+
1823
+ insert: function(){
1824
+ var self = this,
1825
+ args = self._parseInsertArgs(arguments),
1826
+ callback = (typeof args.callback === 'function') ? args.callback : null,
1827
+ frag = document.createDocumentFragment(),
1828
+ target = (function(){
1829
+ self._refresh();
1830
+
1831
+ if(self._$targets.length){
1832
+ return (args.index < self._$targets.length || !self._$targets.length) ?
1833
+ self._$targets[args.index] :
1834
+ self._$targets[self._$targets.length-1].nextElementSibling;
1835
+ } else {
1836
+ return self._$parent[0].children[0];
1837
+ }
1838
+ })();
1839
+
1840
+ self._execAction('insert', 0, arguments);
1841
+
1842
+ if(args.$object){
1843
+ for(var i = 0; i < args.$object.length; i++){
1844
+ var el = args.$object[i];
1845
+
1846
+ frag.appendChild(el);
1847
+ frag.appendChild(document.createTextNode(' '));
1848
+ }
1849
+
1850
+ self._$parent[0].insertBefore(frag, target);
1851
+ }
1852
+
1853
+ self._execAction('insert', 1, arguments);
1854
+
1855
+ if(typeof args.multiMix === 'object'){
1856
+ self.multiMix(args.multiMix, callback);
1857
+ }
1858
+ },
1859
+
1860
+ /**
1861
+ * Prepend
1862
+ * @since 2.0.0
1863
+ * @param {array} arguments
1864
+ */
1865
+
1866
+ prepend: function(){
1867
+ var self = this,
1868
+ args = self._parseInsertArgs(arguments);
1869
+
1870
+ self.insert(0, args.$object, args.multiMix, args.callback);
1871
+ },
1872
+
1873
+ /**
1874
+ * Append
1875
+ * @since 2.0.0
1876
+ * @param {array} arguments
1877
+ */
1878
+
1879
+ append: function(){
1880
+ var self = this,
1881
+ args = self._parseInsertArgs(arguments);
1882
+
1883
+ self.insert(self._state.totalTargets, args.$object, args.multiMix, args.callback);
1884
+ },
1885
+
1886
+ /**
1887
+ * Get Option
1888
+ * @since 2.0.0
1889
+ * @param {string} string
1890
+ * @return {mixed} value
1891
+ */
1892
+
1893
+ getOption: function(string){
1894
+ var self = this,
1895
+ getProperty = function(obj, prop){
1896
+ var parts = prop.split('.'),
1897
+ last = parts.pop(),
1898
+ l = parts.length,
1899
+ i = 1,
1900
+ current = parts[0] || prop;
1901
+
1902
+ while((obj = obj[current]) && i < l){
1903
+ current = parts[i];
1904
+ i++;
1905
+ }
1906
+
1907
+ if(obj !== undf){
1908
+ return obj[last] !== undf ? obj[last] : obj;
1909
+ }
1910
+ };
1911
+
1912
+ return string ? self._execFilter('getOption', getProperty(self, string), arguments) : self;
1913
+ },
1914
+
1915
+ /**
1916
+ * Set Options
1917
+ * @since 2.0.0
1918
+ * @param {object} config
1919
+ */
1920
+
1921
+ setOptions: function(config){
1922
+ var self = this;
1923
+
1924
+ self._execAction('setOptions', 0, arguments);
1925
+
1926
+ typeof config === 'object' && $.extend(true, self, config);
1927
+
1928
+ self._execAction('setOptions', 1, arguments);
1929
+ },
1930
+
1931
+ /**
1932
+ * Get State
1933
+ * @since 2.0.0
1934
+ * @return {object} state
1935
+ */
1936
+
1937
+ getState: function(){
1938
+ var self = this;
1939
+
1940
+ return self._execFilter('getState', self._state, self);
1941
+ },
1942
+
1943
+ /**
1944
+ * Force Refresh
1945
+ * @since 2.1.2
1946
+ */
1947
+
1948
+ forceRefresh: function(){
1949
+ var self = this;
1950
+
1951
+ self._refresh(false, true);
1952
+ },
1953
+
1954
+ /**
1955
+ * Destroy
1956
+ * @since 2.0.0
1957
+ * @param {boolean} hideAll
1958
+ */
1959
+
1960
+ destroy: function(hideAll){
1961
+ var self = this,
1962
+ filters = $.MixItUp.prototype._bound._filter,
1963
+ sorts = $.MixItUp.prototype._bound._sort;
1964
+
1965
+ self._execAction('destroy', 0, arguments);
1966
+
1967
+ self._$body
1968
+ .add($(self.selectors.sort))
1969
+ .add($(self.selectors.filter))
1970
+ .off('.mixItUp');
1971
+
1972
+ for(var i = 0; i < self._$targets.length; i++){
1973
+ var target = self._$targets[i];
1974
+
1975
+ hideAll && (target.style.display = '');
1976
+
1977
+ delete target.mixParent;
1978
+ }
1979
+
1980
+ self._execAction('destroy', 1, arguments);
1981
+
1982
+ if(filters[self.selectors.filter] && filters[self.selectors.filter] > 1) {
1983
+ filters[self.selectors.filter]--;
1984
+ } else if(filters[self.selectors.filter] === 1) {
1985
+ delete filters[self.selectors.filter];
1986
+ }
1987
+
1988
+ if(sorts[self.selectors.sort] && sorts[self.selectors.sort] > 1) {
1989
+ sorts[self.selectors.sort]--;
1990
+ } else if(sorts[self.selectors.sort] === 1) {
1991
+ delete sorts[self.selectors.sort];
1992
+ }
1993
+
1994
+ delete $.MixItUp.prototype._instances[self._id];
1995
+ }
1996
+
1997
+ };
1998
+
1999
+ /* jQuery Methods
2000
+ ---------------------------------------------------------------------- */
2001
+
2002
+ /**
2003
+ * jQuery .mixItUp() method
2004
+ * @since 2.0.0
2005
+ * @extends $.fn
2006
+ */
2007
+
2008
+ $.fn.mixItUp = function(){
2009
+ var args = arguments,
2010
+ dataReturn = [],
2011
+ eachReturn,
2012
+ _instantiate = function(domNode, settings){
2013
+ var instance = new $.MixItUp(),
2014
+ rand = function(){
2015
+ return ('00000'+(Math.random()*16777216<<0).toString(16)).substr(-6).toUpperCase();
2016
+ };
2017
+
2018
+ instance._execAction('_instantiate', 0, arguments);
2019
+
2020
+ domNode.id = !domNode.id ? 'MixItUp'+rand() : domNode.id;
2021
+
2022
+ if(!instance._instances[domNode.id]){
2023
+ instance._instances[domNode.id] = instance;
2024
+ instance._init(domNode, settings);
2025
+ }
2026
+
2027
+ instance._execAction('_instantiate', 1, arguments);
2028
+ };
2029
+
2030
+ eachReturn = this.each(function(){
2031
+ if(args && typeof args[0] === 'string'){
2032
+ var instance = $.MixItUp.prototype._instances[this.id];
2033
+ if(args[0] === 'isLoaded'){
2034
+ dataReturn.push(instance ? true : false);
2035
+ } else {
2036
+ var data = instance[args[0]](args[1], args[2], args[3]);
2037
+ if(data !== undf)dataReturn.push(data);
2038
+ }
2039
+ } else {
2040
+ _instantiate(this, args[0]);
2041
+ }
2042
+ });
2043
+
2044
+ if(dataReturn.length){
2045
+ return dataReturn.length > 1 ? dataReturn : dataReturn[0];
2046
+ } else {
2047
+ return eachReturn;
2048
+ }
2049
+ };
2050
+
2051
+ /**
2052
+ * jQuery .removeStyle() method
2053
+ * @since 2.0.0
2054
+ * @extends $.fn
2055
+ */
2056
+
2057
+ $.fn.removeStyle = function(style, prefix){
2058
+ prefix = prefix ? prefix : '';
2059
+
2060
+ return this.each(function(){
2061
+ var el = this,
2062
+ styles = style.split(' ');
2063
+
2064
+ for(var i = 0; i < styles.length; i++){
2065
+ for(var j = 0; j < 4; j++){
2066
+ switch (j) {
2067
+ case 0:
2068
+ var prop = styles[i];
2069
+ break;
2070
+ case 1:
2071
+ var prop = $.MixItUp.prototype._helpers._camelCase(prop);
2072
+ break;
2073
+ case 2:
2074
+ var prop = prefix+styles[i];
2075
+ break;
2076
+ case 3:
2077
+ var prop = $.MixItUp.prototype._helpers._camelCase(prefix+styles[i]);
2078
+ }
2079
+
2080
+ if(
2081
+ el.style[prop] !== undf &&
2082
+ typeof el.style[prop] !== 'unknown' &&
2083
+ el.style[prop].length > 0
2084
+ ){
2085
+ el.style[prop] = '';
2086
+ }
2087
+
2088
+ if(!prefix && j === 1)break;
2089
+ }
2090
+ }
2091
+
2092
+ if(el.attributes && el.attributes.style && el.attributes.style !== undf && el.attributes.style.value === ''){
2093
+ el.attributes.removeNamedItem('style');
2094
+ }
2095
+ });
2096
+ };
2097
+
2098
+ })(jQuery);
js/mixitup.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(t,e){"use strict";t.MixItUp=function(){var e=this;e._execAction("_constructor",0),t.extend(e,{selectors:{target:".mix",filter:".filter",sort:".sort"},animation:{enable:!0,effects:"fade scale",duration:600,easing:"ease",perspectiveDistance:"3000",perspectiveOrigin:"50% 50%",queue:!0,queueLimit:1,animateChangeLayout:!1,animateResizeContainer:!0,animateResizeTargets:!1,staggerSequence:!1,reverseOut:!1},callbacks:{onMixLoad:!1,onMixStart:!1,onMixBusy:!1,onMixEnd:!1,onMixFail:!1,_user:!1},controls:{enable:!0,live:!1,toggleFilterButtons:!1,toggleLogic:"or",activeClass:"active"},layout:{display:"inline-block",containerClass:"",containerClassFail:"fail"},load:{filter:"all",sort:!1},_$body:null,_$container:null,_$targets:null,_$parent:null,_$sortButtons:null,_$filterButtons:null,_suckMode:!1,_mixing:!1,_sorting:!1,_clicking:!1,_loading:!0,_changingLayout:!1,_changingClass:!1,_changingDisplay:!1,_origOrder:[],_startOrder:[],_newOrder:[],_activeFilter:null,_toggleArray:[],_toggleString:"",_activeSort:"default:asc",_newSort:null,_startHeight:null,_newHeight:null,_incPadding:!0,_newDisplay:null,_newClass:null,_targetsBound:0,_targetsDone:0,_queue:[],_$show:t(),_$hide:t()}),e._execAction("_constructor",1)},t.MixItUp.prototype={constructor:t.MixItUp,_instances:{},_handled:{_filter:{},_sort:{}},_bound:{_filter:{},_sort:{}},_actions:{},_filters:{},extend:function(e){for(var a in e)t.MixItUp.prototype[a]=e[a]},addAction:function(e,a,i,n){t.MixItUp.prototype._addHook("_actions",e,a,i,n)},addFilter:function(e,a,i,n){t.MixItUp.prototype._addHook("_filters",e,a,i,n)},_addHook:function(e,a,i,n,r){var o=t.MixItUp.prototype[e],s={};r=1===r||"post"===r?"post":"pre",s[a]={},s[a][r]={},s[a][r][i]=n,t.extend(!0,o,s)},_init:function(e,a){var i=this;if(i._execAction("_init",0,arguments),a&&t.extend(!0,i,a),i._$body=t("body"),i._domNode=e,i._$container=t(e),i._$container.addClass(i.layout.containerClass),i._id=e.id,i._platformDetect(),i._brake=i._getPrefixedCSS("transition","none"),i._refresh(!0),i._$parent=i._$targets.parent().length?i._$targets.parent():i._$container,i.load.sort&&(i._newSort=i._parseSort(i.load.sort),i._newSortString=i.load.sort,i._activeSort=i.load.sort,i._sort(),i._printSort()),i._activeFilter="all"===i.load.filter?i.selectors.target:"none"===i.load.filter?"":i.load.filter,i.controls.enable&&i._bindHandlers(),i.controls.toggleFilterButtons){i._buildToggleArray();for(var n=0;n<i._toggleArray.length;n++)i._updateControls({filter:i._toggleArray[n],sort:i._activeSort},!0)}else i.controls.enable&&i._updateControls({filter:i._activeFilter,sort:i._activeSort});i._filter(),i._init=!0,i._$container.data("mixItUp",i),i._execAction("_init",1,arguments),i._buildState(),i._$targets.css(i._brake),i._goMix(i.animation.enable)},_platformDetect:function(){var t=this,a=["Webkit","Moz","O","ms"],i=["webkit","moz"],n=window.navigator.appVersion.match(/Chrome\/(\d+)\./)||!1,r="undefined"!=typeof InstallTrigger,o=function(t){for(var e=0;e<a.length;e++)if(a[e]+"Transition"in t.style)return{prefix:"-"+a[e].toLowerCase()+"-",vendor:a[e]};return"transition"in t.style?"":!1},s=o(t._domNode);t._execAction("_platformDetect",0),t._chrome=n?parseInt(n[1],10):!1,t._ff=r?parseInt(window.navigator.userAgent.match(/rv:([^)]+)\)/)[1]):!1,t._prefix=s.prefix,t._vendor=s.vendor,t._suckMode=!window.atob||!t._prefix,t._suckMode&&(t.animation.enable=!1),t._ff&&t._ff<=4&&(t.animation.enable=!1);for(var l=0;l<i.length&&!window.requestAnimationFrame;l++)window.requestAnimationFrame=window[i[l]+"RequestAnimationFrame"];"function"!=typeof Object.getPrototypeOf&&("object"==typeof"test".__proto__?Object.getPrototypeOf=function(t){return t.__proto__}:Object.getPrototypeOf=function(t){return t.constructor.prototype}),t._domNode.nextElementSibling===e&&Object.defineProperty(Element.prototype,"nextElementSibling",{get:function(){for(var t=this.nextSibling;t;){if(1===t.nodeType)return t;t=t.nextSibling}return null}}),t._execAction("_platformDetect",1)},_refresh:function(t,a){var i=this;i._execAction("_refresh",0,arguments),i._$targets=i._$container.find(i.selectors.target);for(var n=0;n<i._$targets.length;n++){var r=i._$targets[n];if(r.dataset===e||a){r.dataset={};for(var o=0;o<r.attributes.length;o++){var s=r.attributes[o],l=s.name,c=s.value;if(l.indexOf("data-")>-1){var _=i._helpers._camelCase(l.substring(5,l.length));r.dataset[_]=c}}}r.mixParent===e&&(r.mixParent=i._id)}if(i._$targets.length&&t||!i._origOrder.length&&i._$targets.length){i._origOrder=[];for(var n=0;n<i._$targets.length;n++){var r=i._$targets[n];i._origOrder.push(r)}}i._execAction("_refresh",1,arguments)},_bindHandlers:function(){var a=this,i=t.MixItUp.prototype._bound._filter,n=t.MixItUp.prototype._bound._sort;a._execAction("_bindHandlers",0),a.controls.live?a._$body.on("click.mixItUp."+a._id,a.selectors.sort,function(){a._processClick(t(this),"sort")}).on("click.mixItUp."+a._id,a.selectors.filter,function(){a._processClick(t(this),"filter")}):(a._$sortButtons=t(a.selectors.sort),a._$filterButtons=t(a.selectors.filter),a._$sortButtons.on("click.mixItUp."+a._id,function(){a._processClick(t(this),"sort")}),a._$filterButtons.on("click.mixItUp."+a._id,function(){a._processClick(t(this),"filter")})),i[a.selectors.filter]=i[a.selectors.filter]===e?1:i[a.selectors.filter]+1,n[a.selectors.sort]=n[a.selectors.sort]===e?1:n[a.selectors.sort]+1,a._execAction("_bindHandlers",1)},_processClick:function(a,i){var n=this,r=function(a,i,r){var o=t.MixItUp.prototype;o._handled["_"+i][n.selectors[i]]=o._handled["_"+i][n.selectors[i]]===e?1:o._handled["_"+i][n.selectors[i]]+1,o._handled["_"+i][n.selectors[i]]===o._bound["_"+i][n.selectors[i]]&&(a[(r?"remove":"add")+"Class"](n.controls.activeClass),delete o._handled["_"+i][n.selectors[i]])};if(n._execAction("_processClick",0,arguments),!n._mixing||n.animation.queue&&n._queue.length<n.animation.queueLimit){if(n._clicking=!0,"sort"===i){var o=a.attr("data-sort");(!a.hasClass(n.controls.activeClass)||o.indexOf("random")>-1)&&(t(n.selectors.sort).removeClass(n.controls.activeClass),r(a,i),n.sort(o))}if("filter"===i){var s,l=a.attr("data-filter"),c="or"===n.controls.toggleLogic?",":"";n.controls.toggleFilterButtons?(n._buildToggleArray(),a.hasClass(n.controls.activeClass)?(r(a,i,!0),s=n._toggleArray.indexOf(l),n._toggleArray.splice(s,1)):(r(a,i),n._toggleArray.push(l)),n._toggleArray=t.grep(n._toggleArray,function(t){return t}),n._toggleString=n._toggleArray.join(c),n.filter(n._toggleString)):a.hasClass(n.controls.activeClass)||(t(n.selectors.filter).removeClass(n.controls.activeClass),r(a,i),n.filter(l))}n._execAction("_processClick",1,arguments)}else"function"==typeof n.callbacks.onMixBusy&&n.callbacks.onMixBusy.call(n._domNode,n._state,n),n._execAction("_processClickBusy",1,arguments)},_buildToggleArray:function(){var t=this,e=t._activeFilter.replace(/\s/g,"");if(t._execAction("_buildToggleArray",0,arguments),"or"===t.controls.toggleLogic)t._toggleArray=e.split(",");else{t._toggleArray=e.split("."),!t._toggleArray[0]&&t._toggleArray.shift();for(var a,i=0;a=t._toggleArray[i];i++)t._toggleArray[i]="."+a}t._execAction("_buildToggleArray",1,arguments)},_updateControls:function(a,i){var n=this,r={filter:a.filter,sort:a.sort},o=function(t,e){try{i&&"filter"===s&&"none"!==r.filter&&""!==r.filter?t.filter(e).addClass(n.controls.activeClass):t.removeClass(n.controls.activeClass).filter(e).addClass(n.controls.activeClass)}catch(a){}},s="filter",l=null;n._execAction("_updateControls",0,arguments),a.filter===e&&(r.filter=n._activeFilter),a.sort===e&&(r.sort=n._activeSort),r.filter===n.selectors.target&&(r.filter="all");for(var c=0;2>c;c++)l=n.controls.live?t(n.selectors[s]):n["_$"+s+"Buttons"],l&&o(l,"[data-"+s+'="'+r[s]+'"]'),s="sort";n._execAction("_updateControls",1,arguments)},_filter:function(){var e=this;e._execAction("_filter",0);for(var a=0;a<e._$targets.length;a++){var i=t(e._$targets[a]);i.is(e._activeFilter)?e._$show=e._$show.add(i):e._$hide=e._$hide.add(i)}e._execAction("_filter",1)},_sort:function(){var t=this,e=function(t){for(var e=t.slice(),a=e.length,i=a;i--;){var n=parseInt(Math.random()*a),r=e[i];e[i]=e[n],e[n]=r}return e};t._execAction("_sort",0),t._startOrder=[];for(var a=0;a<t._$targets.length;a++){var i=t._$targets[a];t._startOrder.push(i)}switch(t._newSort[0].sortBy){case"default":t._newOrder=t._origOrder;break;case"random":t._newOrder=e(t._startOrder);break;case"custom":t._newOrder=t._newSort[0].order;break;default:t._newOrder=t._startOrder.concat().sort(function(e,a){return t._compare(e,a)})}t._execAction("_sort",1)},_compare:function(t,e,a){a=a?a:0;var i=this,n=i._newSort[a].order,r=function(t){return t.dataset[i._newSort[a].sortBy]||0},o=isNaN(1*r(t))?r(t).toLowerCase():1*r(t),s=isNaN(1*r(e))?r(e).toLowerCase():1*r(e);return s>o?"asc"===n?-1:1:o>s?"asc"===n?1:-1:o===s&&i._newSort.length>a+1?i._compare(t,e,a+1):0},_printSort:function(t){var e=this,a=t?e._startOrder:e._newOrder,i=e._$parent[0].querySelectorAll(e.selectors.target),n=i.length?i[i.length-1].nextElementSibling:null,r=document.createDocumentFragment();e._execAction("_printSort",0,arguments);for(var o=0;o<i.length;o++){var s=i[o],l=s.nextSibling;"absolute"!==s.style.position&&(l&&"#text"===l.nodeName&&e._$parent[0].removeChild(l),e._$parent[0].removeChild(s))}for(var o=0;o<a.length;o++){var c=a[o];if("default"!==e._newSort[0].sortBy||"desc"!==e._newSort[0].order||t)r.appendChild(c),r.appendChild(document.createTextNode(" "));else{var _=r.firstChild;r.insertBefore(c,_),r.insertBefore(document.createTextNode(" "),c)}}n?e._$parent[0].insertBefore(r,n):e._$parent[0].appendChild(r),e._execAction("_printSort",1,arguments)},_parseSort:function(t){for(var e=this,a="string"==typeof t?t.split(" "):[t],i=[],n=0;n<a.length;n++){var r="string"==typeof t?a[n].split(":"):["custom",a[n]],o={sortBy:e._helpers._camelCase(r[0]),order:r[1]||"asc"};if(i.push(o),"default"===o.sortBy||"random"===o.sortBy)break}return e._execFilter("_parseSort",i,arguments)},_parseEffects:function(){var t=this,e={opacity:"",transformIn:"",transformOut:"",filter:""},a=function(e,a,i){if(t.animation.effects.indexOf(e)>-1){if(a){var n=t.animation.effects.indexOf(e+"(");if(n>-1){var r=t.animation.effects.substring(n),o=/\(([^)]+)\)/.exec(r),s=o[1];return{val:s}}}return!0}return!1},i=function(t,e){return e?"-"===t.charAt(0)?t.substr(1,t.length):"-"+t:t},n=function(t,n){for(var r=[["scale",".01"],["translateX","20px"],["translateY","20px"],["translateZ","20px"],["rotateX","90deg"],["rotateY","90deg"],["rotateZ","180deg"]],o=0;o<r.length;o++){var s=r[o][0],l=r[o][1],c=n&&"scale"!==s;e[t]+=a(s)?s+"("+i(a(s,!0).val||l,c)+") ":""}};return e.opacity=a("fade")?a("fade",!0).val||"0":"1",n("transformIn"),t.animation.reverseOut?n("transformOut",!0):e.transformOut=e.transformIn,e.transition={},e.transition=t._getPrefixedCSS("transition","all "+t.animation.duration+"ms "+t.animation.easing+", opacity "+t.animation.duration+"ms linear"),t.animation.stagger=!!a("stagger"),t.animation.staggerDuration=parseInt(a("stagger")&&a("stagger",!0).val?a("stagger",!0).val:100),t._execFilter("_parseEffects",e)},_buildState:function(t){var e=this,a={};return e._execAction("_buildState",0),a={activeFilter:""===e._activeFilter?"none":e._activeFilter,activeSort:t&&e._newSortString?e._newSortString:e._activeSort,fail:!e._$show.length&&""!==e._activeFilter,$targets:e._$targets,$show:e._$show,$hide:e._$hide,totalTargets:e._$targets.length,totalShow:e._$show.length,totalHide:e._$hide.length,display:t&&e._newDisplay?e._newDisplay:e.layout.display},t?e._execFilter("_buildState",a):(e._state=a,void e._execAction("_buildState",1))},_goMix:function(t){var e=this,a=function(){e._chrome&&31===e._chrome&&r(e._$parent[0]),e._setInter(),i()},i=function(){var t=window.pageYOffset,a=window.pageXOffset;document.documentElement.scrollHeight;e._getInterMixData(),e._setFinal(),e._getFinalMixData(),window.pageYOffset!==t&&window.scrollTo(a,t),e._prepTargets(),window.requestAnimationFrame?requestAnimationFrame(n):setTimeout(function(){n()},20)},n=function(){e._animateTargets(),0===e._targetsBound&&e._cleanUp()},r=function(t){var e=t.parentElement,a=document.createElement("div"),i=document.createDocumentFragment();e.insertBefore(a,t),i.appendChild(t),e.replaceChild(t,a)},o=e._buildState(!0);e._execAction("_goMix",0,arguments),!e.animation.duration&&(t=!1),e._mixing=!0,e._$container.removeClass(e.layout.containerClassFail),"function"==typeof e.callbacks.onMixStart&&e.callbacks.onMixStart.call(e._domNode,e._state,o,e),e._$container.trigger("mixStart",[e._state,o,e]),e._getOrigMixData(),t&&!e._suckMode?window.requestAnimationFrame?requestAnimationFrame(a):a():e._cleanUp(),e._execAction("_goMix",1,arguments)},_getTargetData:function(t,e){var a,i=this;t.dataset[e+"PosX"]=t.offsetLeft,t.dataset[e+"PosY"]=t.offsetTop,i.animation.animateResizeTargets&&(a=i._suckMode?{marginBottom:"",marginRight:""}:window.getComputedStyle(t),t.dataset[e+"MarginBottom"]=parseInt(a.marginBottom),t.dataset[e+"MarginRight"]=parseInt(a.marginRight),t.dataset[e+"Width"]=t.offsetWidth,t.dataset[e+"Height"]=t.offsetHeight)},_getOrigMixData:function(){var t=this,e=t._suckMode?{boxSizing:""}:window.getComputedStyle(t._$parent[0]),a=e.boxSizing||e[t._vendor+"BoxSizing"];t._incPadding="border-box"===a,t._execAction("_getOrigMixData",0),!t._suckMode&&(t.effects=t._parseEffects()),t._$toHide=t._$hide.filter(":visible"),t._$toShow=t._$show.filter(":hidden"),t._$pre=t._$targets.filter(":visible"),t._startHeight=t._incPadding?t._$parent.outerHeight():t._$parent.height();for(var i=0;i<t._$pre.length;i++){var n=t._$pre[i];t._getTargetData(n,"orig")}t._execAction("_getOrigMixData",1)},_setInter:function(){var t=this;t._execAction("_setInter",0),t._changingLayout&&t.animation.animateChangeLayout?(t._$toShow.css("display",t._newDisplay),t._changingClass&&t._$container.removeClass(t.layout.containerClass).addClass(t._newClass)):t._$toShow.css("display",t.layout.display),t._execAction("_setInter",1)},_getInterMixData:function(){var t=this;t._execAction("_getInterMixData",0);for(var e=0;e<t._$toShow.length;e++){var a=t._$toShow[e];t._getTargetData(a,"inter")}for(var e=0;e<t._$pre.length;e++){var a=t._$pre[e];t._getTargetData(a,"inter")}t._execAction("_getInterMixData",1)},_setFinal:function(){var t=this;t._execAction("_setFinal",0),t._sorting&&t._printSort(),t._$toHide.removeStyle("display"),t._changingLayout&&t.animation.animateChangeLayout&&t._$pre.css("display",t._newDisplay),t._execAction("_setFinal",1)},_getFinalMixData:function(){var t=this;t._execAction("_getFinalMixData",0);for(var e=0;e<t._$toShow.length;e++){var a=t._$toShow[e];t._getTargetData(a,"final")}for(var e=0;e<t._$pre.length;e++){var a=t._$pre[e];t._getTargetData(a,"final")}t._newHeight=t._incPadding?t._$parent.outerHeight():t._$parent.height(),t._sorting&&t._printSort(!0),t._$toShow.removeStyle("display"),t._$pre.css("display",t.layout.display),t._changingClass&&t.animation.animateChangeLayout&&t._$container.removeClass(t._newClass).addClass(t.layout.containerClass),t._execAction("_getFinalMixData",1)},_prepTargets:function(){var e=this,a={_in:e._getPrefixedCSS("transform",e.effects.transformIn),_out:e._getPrefixedCSS("transform",e.effects.transformOut)};e._execAction("_prepTargets",0),e.animation.animateResizeContainer&&e._$parent.css("height",e._startHeight+"px");for(var i=0;i<e._$toShow.length;i++){var n=e._$toShow[i],r=t(n);n.style.opacity=e.effects.opacity,n.style.display=e._changingLayout&&e.animation.animateChangeLayout?e._newDisplay:e.layout.display,r.css(a._in),e.animation.animateResizeTargets&&(n.style.width=n.dataset.finalWidth+"px",n.style.height=n.dataset.finalHeight+"px",n.style.marginRight=-(n.dataset.finalWidth-n.dataset.interWidth)+1*n.dataset.finalMarginRight+"px",n.style.marginBottom=-(n.dataset.finalHeight-n.dataset.interHeight)+1*n.dataset.finalMarginBottom+"px")}for(var i=0;i<e._$pre.length;i++){var n=e._$pre[i],r=t(n),o={x:n.dataset.origPosX-n.dataset.interPosX,y:n.dataset.origPosY-n.dataset.interPosY},a=e._getPrefixedCSS("transform","translate("+o.x+"px,"+o.y+"px)");r.css(a),e.animation.animateResizeTargets&&(n.style.width=n.dataset.origWidth+"px",n.style.height=n.dataset.origHeight+"px",n.dataset.origWidth-n.dataset.finalWidth&&(n.style.marginRight=-(n.dataset.origWidth-n.dataset.interWidth)+1*n.dataset.origMarginRight+"px"),n.dataset.origHeight-n.dataset.finalHeight&&(n.style.marginBottom=-(n.dataset.origHeight-n.dataset.interHeight)+1*n.dataset.origMarginBottom+"px"))}e._execAction("_prepTargets",1)},_animateTargets:function(){var e=this;e._execAction("_animateTargets",0),e._targetsDone=0,e._targetsBound=0,e._$parent.css(e._getPrefixedCSS("perspective",e.animation.perspectiveDistance+"px")).css(e._getPrefixedCSS("perspective-origin",e.animation.perspectiveOrigin)),e.animation.animateResizeContainer&&e._$parent.css(e._getPrefixedCSS("transition","height "+e.animation.duration+"ms ease")).css("height",e._newHeight+"px");for(var a=0;a<e._$toShow.length;a++){var i=e._$toShow[a],n=t(i),r={x:i.dataset.finalPosX-i.dataset.interPosX,y:i.dataset.finalPosY-i.dataset.interPosY},o=e._getDelay(a),s={};i.style.opacity="";for(var l=0;2>l;l++){var c=0===l?c=e._prefix:"";e._ff&&e._ff<=20&&(s[c+"transition-property"]="all",s[c+"transition-timing-function"]=e.animation.easing+"ms",s[c+"transition-duration"]=e.animation.duration+"ms"),s[c+"transition-delay"]=o+"ms",s[c+"transform"]="translate("+r.x+"px,"+r.y+"px)"}(e.effects.transform||e.effects.opacity)&&e._bindTargetDone(n),e._ff&&e._ff<=20?n.css(s):n.css(e.effects.transition).css(s)}for(var a=0;a<e._$pre.length;a++){var i=e._$pre[a],n=t(i),r={x:i.dataset.finalPosX-i.dataset.interPosX,y:i.dataset.finalPosY-i.dataset.interPosY},o=e._getDelay(a);i.dataset.finalPosX===i.dataset.origPosX&&i.dataset.finalPosY===i.dataset.origPosY||e._bindTargetDone(n),n.css(e._getPrefixedCSS("transition","all "+e.animation.duration+"ms "+e.animation.easing+" "+o+"ms")),n.css(e._getPrefixedCSS("transform","translate("+r.x+"px,"+r.y+"px)")),e.animation.animateResizeTargets&&(i.dataset.origWidth-i.dataset.finalWidth&&1*i.dataset.finalWidth&&(i.style.width=i.dataset.finalWidth+"px",i.style.marginRight=-(i.dataset.finalWidth-i.dataset.interWidth)+1*i.dataset.finalMarginRight+"px"),i.dataset.origHeight-i.dataset.finalHeight&&1*i.dataset.finalHeight&&(i.style.height=i.dataset.finalHeight+"px",i.style.marginBottom=-(i.dataset.finalHeight-i.dataset.interHeight)+1*i.dataset.finalMarginBottom+"px"))}e._changingClass&&e._$container.removeClass(e.layout.containerClass).addClass(e._newClass);for(var a=0;a<e._$toHide.length;a++){for(var i=e._$toHide[a],n=t(i),o=e._getDelay(a),_={},l=0;2>l;l++){var c=0===l?c=e._prefix:"";_[c+"transition-delay"]=o+"ms",_[c+"transform"]=e.effects.transformOut,_.opacity=e.effects.opacity}n.css(e.effects.transition).css(_),(e.effects.transform||e.effects.opacity)&&e._bindTargetDone(n)}e._execAction("_animateTargets",1)},_bindTargetDone:function(e){var a=this,i=e[0];a._execAction("_bindTargetDone",0,arguments),i.dataset.bound||(i.dataset.bound=!0,a._targetsBound++,e.on("webkitTransitionEnd.mixItUp transitionend.mixItUp",function(n){(n.originalEvent.propertyName.indexOf("transform")>-1||n.originalEvent.propertyName.indexOf("opacity")>-1)&&t(n.originalEvent.target).is(a.selectors.target)&&(e.off(".mixItUp"),i.dataset.bound="",a._targetDone())})),a._execAction("_bindTargetDone",1,arguments)},_targetDone:function(){var t=this;t._execAction("_targetDone",0),t._targetsDone++,t._targetsDone===t._targetsBound&&t._cleanUp(),t._execAction("_targetDone",1)},_cleanUp:function(){var e=this,a=e.animation.animateResizeTargets?"transform opacity width height margin-bottom margin-right":"transform opacity",i=function(){e._$targets.removeStyle("transition",e._prefix)};e._execAction("_cleanUp",0),e._changingLayout?e._$show.css("display",e._newDisplay):e._$show.css("display",e.layout.display),e._$targets.css(e._brake),e._$targets.removeStyle(a,e._prefix).removeAttr("data-inter-pos-x data-inter-pos-y data-final-pos-x data-final-pos-y data-orig-pos-x data-orig-pos-y data-orig-height data-orig-width data-final-height data-final-width data-inter-width data-inter-height data-orig-margin-right data-orig-margin-bottom data-inter-margin-right data-inter-margin-bottom data-final-margin-right data-final-margin-bottom"),e._$hide.removeStyle("display"),e._$parent.removeStyle("height transition perspective-distance perspective perspective-origin-x perspective-origin-y perspective-origin perspectiveOrigin",e._prefix),e._sorting&&(e._printSort(),e._activeSort=e._newSortString,e._sorting=!1),e._changingLayout&&(e._changingDisplay&&(e.layout.display=e._newDisplay,e._changingDisplay=!1),e._changingClass&&(e._$parent.removeClass(e.layout.containerClass).addClass(e._newClass),e.layout.containerClass=e._newClass,e._changingClass=!1),e._changingLayout=!1),e._refresh(),e._buildState(),e._state.fail&&e._$container.addClass(e.layout.containerClassFail),e._$show=t(),e._$hide=t(),window.requestAnimationFrame&&requestAnimationFrame(i),e._mixing=!1,"function"==typeof e.callbacks._user&&e.callbacks._user.call(e._domNode,e._state,e),"function"==typeof e.callbacks.onMixEnd&&e.callbacks.onMixEnd.call(e._domNode,e._state,e),e._$container.trigger("mixEnd",[e._state,e]),e._state.fail&&("function"==typeof e.callbacks.onMixFail&&e.callbacks.onMixFail.call(e._domNode,e._state,e),e._$container.trigger("mixFail",[e._state,e])),e._loading&&("function"==typeof e.callbacks.onMixLoad&&e.callbacks.onMixLoad.call(e._domNode,e._state,e),e._$container.trigger("mixLoad",[e._state,e])),e._queue.length&&(e._execAction("_queue",0),e.multiMix(e._queue[0][0],e._queue[0][1],e._queue[0][2]),e._queue.splice(0,1)),e._execAction("_cleanUp",1),e._loading=!1},_getPrefixedCSS:function(t,e,a){var i=this,n={},r="",o=-1;for(o=0;2>o;o++)r=0===o?i._prefix:"",a?n[r+t]=r+e:n[r+t]=e;return i._execFilter("_getPrefixedCSS",n,arguments)},_getDelay:function(t){var e=this,a="function"==typeof e.animation.staggerSequence?e.animation.staggerSequence.call(e._domNode,t,e._state):t,i=e.animation.stagger?a*e.animation.staggerDuration:0;return e._execFilter("_getDelay",i,arguments)},_parseMultiMixArgs:function(t){for(var e=this,a={command:null,animate:e.animation.enable,callback:null},i=0;i<t.length;i++){var n=t[i];null!==n&&("object"==typeof n||"string"==typeof n?a.command=n:"boolean"==typeof n?a.animate=n:"function"==typeof n&&(a.callback=n))}return e._execFilter("_parseMultiMixArgs",a,arguments)},_parseInsertArgs:function(e){for(var a=this,i={index:0,$object:t(),multiMix:{filter:a._state.activeFilter},callback:null},n=0;n<e.length;n++){var r=e[n];"number"==typeof r?i.index=r:"object"==typeof r&&r instanceof t?i.$object=r:"object"==typeof r&&a._helpers._isElement(r)?i.$object=t(r):"object"==typeof r&&null!==r?i.multiMix=r:"boolean"!=typeof r||r?"function"==typeof r&&(i.callback=r):i.multiMix=!1}return a._execFilter("_parseInsertArgs",i,arguments)},_execAction:function(t,e,a){var i=this,n=e?"post":"pre";if(!i._actions.isEmptyObject&&i._actions.hasOwnProperty(t))for(var r in i._actions[t][n])i._actions[t][n][r].call(i,a)},_execFilter:function(t,e,a){var i=this;if(i._filters.isEmptyObject||!i._filters.hasOwnProperty(t))return e;for(var n in i._filters[t])return i._filters[t][n].call(i,a)},_helpers:{_camelCase:function(t){return t.replace(/-([a-z])/g,function(t){return t[1].toUpperCase()})},_isElement:function(t){return window.HTMLElement?t instanceof HTMLElement:null!==t&&1===t.nodeType&&"string"===t.nodeName}},isMixing:function(){var t=this;return t._execFilter("isMixing",t._mixing)},filter:function(){var t=this,e=t._parseMultiMixArgs(arguments);t._clicking&&(t._toggleString=""),t.multiMix({filter:e.command},e.animate,e.callback)},sort:function(){var t=this,e=t._parseMultiMixArgs(arguments);t.multiMix({sort:e.command},e.animate,e.callback)},changeLayout:function(){var t=this,e=t._parseMultiMixArgs(arguments);t.multiMix({changeLayout:e.command},e.animate,e.callback)},multiMix:function(){var t=this,a=t._parseMultiMixArgs(arguments);if(t._execAction("multiMix",0,arguments),t._mixing)t.animation.queue&&t._queue.length<t.animation.queueLimit?(t._queue.push(arguments),t.controls.enable&&!t._clicking&&t._updateControls(a.command),t._execAction("multiMixQueue",1,arguments)):("function"==typeof t.callbacks.onMixBusy&&t.callbacks.onMixBusy.call(t._domNode,t._state,t),t._$container.trigger("mixBusy",[t._state,t]),t._execAction("multiMixBusy",1,arguments));else{t.controls.enable&&!t._clicking&&(t.controls.toggleFilterButtons&&t._buildToggleArray(),t._updateControls(a.command,t.controls.toggleFilterButtons)),t._queue.length<2&&(t._clicking=!1),delete t.callbacks._user,a.callback&&(t.callbacks._user=a.callback);var i=a.command.sort,n=a.command.filter,r=a.command.changeLayout;t._refresh(),i&&(t._newSort=t._parseSort(i),t._newSortString=i,t._sorting=!0,t._sort()),n!==e&&(n="all"===n?t.selectors.target:n,t._activeFilter=n),t._filter(),r&&(t._newDisplay="string"==typeof r?r:r.display||t.layout.display,t._newClass=r.containerClass||"",t._newDisplay===t.layout.display&&t._newClass===t.layout.containerClass||(t._changingLayout=!0,t._changingClass=t._newClass!==t.layout.containerClass,t._changingDisplay=t._newDisplay!==t.layout.display)),t._$targets.css(t._brake),t._goMix(a.animate^t.animation.enable?a.animate:t.animation.enable),t._execAction("multiMix",1,arguments)}},insert:function(){var t=this,e=t._parseInsertArgs(arguments),a="function"==typeof e.callback?e.callback:null,i=document.createDocumentFragment(),n=function(){return t._refresh(),t._$targets.length?e.index<t._$targets.length||!t._$targets.length?t._$targets[e.index]:t._$targets[t._$targets.length-1].nextElementSibling:t._$parent[0].children[0]}();if(t._execAction("insert",0,arguments),e.$object){for(var r=0;r<e.$object.length;r++){var o=e.$object[r];i.appendChild(o),i.appendChild(document.createTextNode(" "))}t._$parent[0].insertBefore(i,n)}t._execAction("insert",1,arguments),"object"==typeof e.multiMix&&t.multiMix(e.multiMix,a)},prepend:function(){var t=this,e=t._parseInsertArgs(arguments);t.insert(0,e.$object,e.multiMix,e.callback)},append:function(){var t=this,e=t._parseInsertArgs(arguments);t.insert(t._state.totalTargets,e.$object,e.multiMix,e.callback)},getOption:function(t){var a=this,i=function(t,a){for(var i=a.split("."),n=i.pop(),r=i.length,o=1,s=i[0]||a;(t=t[s])&&r>o;)s=i[o],o++;return t!==e?t[n]!==e?t[n]:t:void 0};return t?a._execFilter("getOption",i(a,t),arguments):a},setOptions:function(e){var a=this;a._execAction("setOptions",0,arguments),"object"==typeof e&&t.extend(!0,a,e),a._execAction("setOptions",1,arguments)},getState:function(){var t=this;return t._execFilter("getState",t._state,t)},forceRefresh:function(){var t=this;t._refresh(!1,!0)},destroy:function(e){var a=this,i=t.MixItUp.prototype._bound._filter,n=t.MixItUp.prototype._bound._sort;a._execAction("destroy",0,arguments),a._$body.add(t(a.selectors.sort)).add(t(a.selectors.filter)).off(".mixItUp");for(var r=0;r<a._$targets.length;r++){var o=a._$targets[r];e&&(o.style.display=""),delete o.mixParent}a._execAction("destroy",1,arguments),i[a.selectors.filter]&&i[a.selectors.filter]>1?i[a.selectors.filter]--:1===i[a.selectors.filter]&&delete i[a.selectors.filter],n[a.selectors.sort]&&n[a.selectors.sort]>1?n[a.selectors.sort]--:1===n[a.selectors.sort]&&delete n[a.selectors.sort],delete t.MixItUp.prototype._instances[a._id]}},t.fn.mixItUp=function(){var a,i=arguments,n=[],r=function(e,a){var i=new t.MixItUp,n=function(){return("00000"+(16777216*Math.random()<<0).toString(16)).substr(-6).toUpperCase()};i._execAction("_instantiate",0,arguments),e.id=e.id?e.id:"MixItUp"+n(),i._instances[e.id]||(i._instances[e.id]=i,i._init(e,a)),i._execAction("_instantiate",1,arguments)};return a=this.each(function(){if(i&&"string"==typeof i[0]){var a=t.MixItUp.prototype._instances[this.id];if("isLoaded"===i[0])n.push(!!a);else{var o=a[i[0]](i[1],i[2],i[3]);o!==e&&n.push(o)}}else r(this,i[0])}),n.length?n.length>1?n:n[0]:a},t.fn.removeStyle=function(a,i){return i=i?i:"",this.each(function(){for(var n=this,r=a.split(" "),o=0;o<r.length;o++)for(var s=0;4>s;s++){switch(s){case 0:var l=r[o];break;case 1:var l=t.MixItUp.prototype._helpers._camelCase(l);break;case 2:var l=i+r[o];break;case 3:var l=t.MixItUp.prototype._helpers._camelCase(i+r[o])}if(n.style[l]!==e&&"unknown"!=typeof n.style[l]&&n.style[l].length>0&&(n.style[l]=""),!i&&1===s)break}n.attributes&&n.attributes.style&&n.attributes.style!==e&&""===n.attributes.style.value&&n.attributes.removeNamedItem("style")})}}(jQuery);
{statics → js}/waypoints.js RENAMED
@@ -13,13 +13,13 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
13
  /* http://imakewebthings.com/waypoints/api/waypoint */
14
  function Waypoint(options) {
15
  if (!options) {
16
- throw new Error('No options passed to Waypoint constructor')
17
  }
18
  if (!options.element) {
19
- throw new Error('No element option passed to Waypoint constructor')
20
  }
21
  if (!options.handler) {
22
- throw new Error('No handler option passed to Waypoint constructor')
23
  }
24
 
25
  this.key = 'waypoint-' + keyCounter
@@ -109,19 +109,19 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
109
  /* Public */
110
  /* http://imakewebthings.com/waypoints/api/destroy-all */
111
  Waypoint.destroyAll = function() {
112
- Waypoint.invokeAll('destroy')
113
  }
114
 
115
  /* Public */
116
  /* http://imakewebthings.com/waypoints/api/disable-all */
117
  Waypoint.disableAll = function() {
118
- Waypoint.invokeAll('disable')
119
  }
120
 
121
  /* Public */
122
  /* http://imakewebthings.com/waypoints/api/enable-all */
123
  Waypoint.enableAll = function() {
124
- Waypoint.invokeAll('enable')
125
  }
126
 
127
  /* Public */
@@ -213,7 +213,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
213
  var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal)
214
  var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical)
215
  if (horizontalEmpty && verticalEmpty) {
216
- this.adapter.off('.waypoints')
217
  delete contexts[this.key]
218
  }
219
  }
@@ -227,7 +227,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
227
  self.didResize = false
228
  }
229
 
230
- this.adapter.on('resize.waypoints', function() {
231
  if (!self.didResize) {
232
  self.didResize = true
233
  Waypoint.requestAnimationFrame(resizeHandler)
@@ -243,7 +243,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
243
  self.didScroll = false
244
  }
245
 
246
- this.adapter.on('scroll.waypoints', function() {
247
  if (!self.didScroll || Waypoint.isTouch) {
248
  self.didScroll = true
249
  Waypoint.requestAnimationFrame(scrollHandler)
@@ -389,12 +389,12 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
389
  elementOffset = waypoint.adapter.offset()[axis.offsetProp]
390
  }
391
 
392
- if (typeof adjustment === 'function') {
393
  adjustment = adjustment.apply(waypoint)
394
  }
395
- else if (typeof adjustment === 'string') {
396
  adjustment = parseFloat(adjustment)
397
- if (waypoint.options.offset.indexOf('%') > - 1) {
398
  adjustment = Math.ceil(axis.contextDimension * adjustment / 100)
399
  }
400
  }
@@ -629,7 +629,7 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
629
  var options = framework.extend({}, overrides, {
630
  element: this
631
  })
632
- if (typeof options.context === 'string') {
633
  options.context = framework(this).closest(options.context)[0]
634
  }
635
  waypoints.push(new Waypoint(options))
@@ -646,4 +646,4 @@ https://github.com/imakewebthings/waypoints/blog/master/licenses.txt
646
  window.Zepto.fn.waypoint = createExtension(window.Zepto)
647
  }
648
  }())
649
- ;
13
  /* http://imakewebthings.com/waypoints/api/waypoint */
14
  function Waypoint(options) {
15
  if (!options) {
16
+ throw new Error( 'No options passed to Waypoint constructor' )
17
  }
18
  if (!options.element) {
19
+ throw new Error( 'No element option passed to Waypoint constructor' )
20
  }
21
  if (!options.handler) {
22
+ throw new Error( 'No handler option passed to Waypoint constructor' )
23
  }
24
 
25
  this.key = 'waypoint-' + keyCounter
109
  /* Public */
110
  /* http://imakewebthings.com/waypoints/api/destroy-all */
111
  Waypoint.destroyAll = function() {
112
+ Waypoint.invokeAll( 'destroy' )
113
  }
114
 
115
  /* Public */
116
  /* http://imakewebthings.com/waypoints/api/disable-all */
117
  Waypoint.disableAll = function() {
118
+ Waypoint.invokeAll( 'disable' )
119
  }
120
 
121
  /* Public */
122
  /* http://imakewebthings.com/waypoints/api/enable-all */
123
  Waypoint.enableAll = function() {
124
+ Waypoint.invokeAll( 'enable' )
125
  }
126
 
127
  /* Public */
213
  var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal)
214
  var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical)
215
  if (horizontalEmpty && verticalEmpty) {
216
+ this.adapter.off( '.waypoints' )
217
  delete contexts[this.key]
218
  }
219
  }
227
  self.didResize = false
228
  }
229
 
230
+ this.adapter.on( 'resize.waypoints', function() {
231
  if (!self.didResize) {
232
  self.didResize = true
233
  Waypoint.requestAnimationFrame(resizeHandler)
243
  self.didScroll = false
244
  }
245
 
246
+ this.adapter.on( 'scroll.waypoints', function() {
247
  if (!self.didScroll || Waypoint.isTouch) {
248
  self.didScroll = true
249
  Waypoint.requestAnimationFrame(scrollHandler)
389
  elementOffset = waypoint.adapter.offset()[axis.offsetProp]
390
  }
391
 
392
+ if (typeof adjustment === 'function' ) {
393
  adjustment = adjustment.apply(waypoint)
394
  }
395
+ else if (typeof adjustment === 'string' ) {
396
  adjustment = parseFloat(adjustment)
397
+ if (waypoint.options.offset.indexOf( '%' ) > - 1) {
398
  adjustment = Math.ceil(axis.contextDimension * adjustment / 100)
399
  }
400
  }
629
  var options = framework.extend({}, overrides, {
630
  element: this
631
  })
632
+ if (typeof options.context === 'string' ) {
633
  options.context = framework(this).closest(options.context)[0]
634
  }
635
  waypoints.push(new Waypoint(options))
646
  window.Zepto.fn.waypoint = createExtension(window.Zepto)
647
  }
648
  }())
649
+ ;
js/waypoints.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(){"use strict";function t(o){if(!o)throw new Error("No options passed to Waypoint constructor");if(!o.element)throw new Error("No element option passed to Waypoint constructor");if(!o.handler)throw new Error("No handler option passed to Waypoint constructor");this.key="waypoint-"+e,this.options=t.Adapter.extend({},t.defaults,o),this.element=this.options.element,this.adapter=new t.Adapter(this.element),this.callback=o.handler,this.axis=this.options.horizontal?"horizontal":"vertical",this.enabled=this.options.enabled,this.triggerPoint=null,this.group=t.Group.findOrCreate({name:this.options.group,axis:this.axis}),this.context=t.Context.findOrCreateByElement(this.options.context),t.offsetAliases[this.options.offset]&&(this.options.offset=t.offsetAliases[this.options.offset]),this.group.add(this),this.context.add(this),i[this.key]=this,e+=1}var e=0,i={};t.prototype.queueTrigger=function(t){this.group.queueTrigger(this,t)},t.prototype.trigger=function(t){this.enabled&&this.callback&&this.callback.apply(this,t)},t.prototype.destroy=function(){this.context.remove(this),this.group.remove(this),delete i[this.key]},t.prototype.disable=function(){return this.enabled=!1,this},t.prototype.enable=function(){return this.context.refresh(),this.enabled=!0,this},t.prototype.next=function(){return this.group.next(this)},t.prototype.previous=function(){return this.group.previous(this)},t.invokeAll=function(t){var e=[];for(var o in i)e.push(i[o]);for(var n=0,r=e.length;r>n;n++)e[n][t]()},t.destroyAll=function(){t.invokeAll("destroy")},t.disableAll=function(){t.invokeAll("disable")},t.enableAll=function(){t.invokeAll("enable")},t.refreshAll=function(){t.Context.refreshAll()},t.viewportHeight=function(){return window.innerHeight||document.documentElement.clientHeight},t.viewportWidth=function(){return document.documentElement.clientWidth},t.adapters=[],t.defaults={context:window,continuous:!0,enabled:!0,group:"default",horizontal:!1,offset:0},t.offsetAliases={"bottom-in-view":function(){return this.context.innerHeight()-this.adapter.outerHeight()},"right-in-view":function(){return this.context.innerWidth()-this.adapter.outerWidth()}},window.Waypoint=t}(),function(){"use strict";function t(t){window.setTimeout(t,1e3/60)}function e(t){this.element=t,this.Adapter=n.Adapter,this.adapter=new this.Adapter(t),this.key="waypoint-context-"+i,this.didScroll=!1,this.didResize=!1,this.oldScroll={x:this.adapter.scrollLeft(),y:this.adapter.scrollTop()},this.waypoints={vertical:{},horizontal:{}},t.waypointContextKey=this.key,o[t.waypointContextKey]=this,i+=1,this.createThrottledScrollHandler(),this.createThrottledResizeHandler()}var i=0,o={},n=window.Waypoint,r=window.onload;e.prototype.add=function(t){var e=t.options.horizontal?"horizontal":"vertical";this.waypoints[e][t.key]=t,this.refresh()},e.prototype.checkEmpty=function(){var t=this.Adapter.isEmptyObject(this.waypoints.horizontal),e=this.Adapter.isEmptyObject(this.waypoints.vertical);t&&e&&(this.adapter.off(".waypoints"),delete o[this.key])},e.prototype.createThrottledResizeHandler=function(){function t(){e.handleResize(),e.didResize=!1}var e=this;this.adapter.on("resize.waypoints",function(){e.didResize||(e.didResize=!0,n.requestAnimationFrame(t))})},e.prototype.createThrottledScrollHandler=function(){function t(){e.handleScroll(),e.didScroll=!1}var e=this;this.adapter.on("scroll.waypoints",function(){e.didScroll&&!n.isTouch||(e.didScroll=!0,n.requestAnimationFrame(t))})},e.prototype.handleResize=function(){n.Context.refreshAll()},e.prototype.handleScroll=function(){var t={},e={horizontal:{newScroll:this.adapter.scrollLeft(),oldScroll:this.oldScroll.x,forward:"right",backward:"left"},vertical:{newScroll:this.adapter.scrollTop(),oldScroll:this.oldScroll.y,forward:"down",backward:"up"}};for(var i in e){var o=e[i],n=o.newScroll>o.oldScroll,r=n?o.forward:o.backward;for(var s in this.waypoints[i]){var a=this.waypoints[i][s],l=o.oldScroll<a.triggerPoint,h=o.newScroll>=a.triggerPoint,p=l&&h,c=!l&&!h;(p||c)&&(a.queueTrigger(r),t[a.group.id]=a.group)}}for(var u in t)t[u].flushTriggers();this.oldScroll={x:e.horizontal.newScroll,y:e.vertical.newScroll}},e.prototype.innerHeight=function(){return this.element==this.element.window?n.viewportHeight():this.adapter.innerHeight()},e.prototype.remove=function(t){delete this.waypoints[t.axis][t.key],this.checkEmpty()},e.prototype.innerWidth=function(){return this.element==this.element.window?n.viewportWidth():this.adapter.innerWidth()},e.prototype.destroy=function(){var t=[];for(var e in this.waypoints)for(var i in this.waypoints[e])t.push(this.waypoints[e][i]);for(var o=0,n=t.length;n>o;o++)t[o].destroy()},e.prototype.refresh=function(){var t,e=this.element==this.element.window,i=e?void 0:this.adapter.offset(),o={};this.handleScroll(),t={horizontal:{contextOffset:e?0:i.left,contextScroll:e?0:this.oldScroll.x,contextDimension:this.innerWidth(),oldScroll:this.oldScroll.x,forward:"right",backward:"left",offsetProp:"left"},vertical:{contextOffset:e?0:i.top,contextScroll:e?0:this.oldScroll.y,contextDimension:this.innerHeight(),oldScroll:this.oldScroll.y,forward:"down",backward:"up",offsetProp:"top"}};for(var r in t){var s=t[r];for(var a in this.waypoints[r]){var l,h,p,c,u,d=this.waypoints[r][a],f=d.options.offset,w=d.triggerPoint,y=0,g=null==w;d.element!==d.element.window&&(y=d.adapter.offset()[s.offsetProp]),"function"==typeof f?f=f.apply(d):"string"==typeof f&&(f=parseFloat(f),d.options.offset.indexOf("%")>-1&&(f=Math.ceil(s.contextDimension*f/100))),l=s.contextScroll-s.contextOffset,d.triggerPoint=y+l-f,h=w<s.oldScroll,p=d.triggerPoint>=s.oldScroll,c=h&&p,u=!h&&!p,!g&&c?(d.queueTrigger(s.backward),o[d.group.id]=d.group):!g&&u?(d.queueTrigger(s.forward),o[d.group.id]=d.group):g&&s.oldScroll>=d.triggerPoint&&(d.queueTrigger(s.forward),o[d.group.id]=d.group)}}return n.requestAnimationFrame(function(){for(var t in o)o[t].flushTriggers()}),this},e.findOrCreateByElement=function(t){return e.findByElement(t)||new e(t)},e.refreshAll=function(){for(var t in o)o[t].refresh()},e.findByElement=function(t){return o[t.waypointContextKey]},window.onload=function(){r&&r(),e.refreshAll()},n.requestAnimationFrame=function(e){var i=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||t;i.call(window,e)},n.Context=e}(),function(){"use strict";function t(t,e){return t.triggerPoint-e.triggerPoint}function e(t,e){return e.triggerPoint-t.triggerPoint}function i(t){this.name=t.name,this.axis=t.axis,this.id=this.name+"-"+this.axis,this.waypoints=[],this.clearTriggerQueues(),o[this.axis][this.name]=this}var o={vertical:{},horizontal:{}},n=window.Waypoint;i.prototype.add=function(t){this.waypoints.push(t)},i.prototype.clearTriggerQueues=function(){this.triggerQueues={up:[],down:[],left:[],right:[]}},i.prototype.flushTriggers=function(){for(var i in this.triggerQueues){var o=this.triggerQueues[i],n="up"===i||"left"===i;o.sort(n?e:t);for(var r=0,s=o.length;s>r;r+=1){var a=o[r];(a.options.continuous||r===o.length-1)&&a.trigger([i])}}this.clearTriggerQueues()},i.prototype.next=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints),o=i===this.waypoints.length-1;return o?null:this.waypoints[i+1]},i.prototype.previous=function(e){this.waypoints.sort(t);var i=n.Adapter.inArray(e,this.waypoints);return i?this.waypoints[i-1]:null},i.prototype.queueTrigger=function(t,e){this.triggerQueues[e].push(t)},i.prototype.remove=function(t){var e=n.Adapter.inArray(t,this.waypoints);e>-1&&this.waypoints.splice(e,1)},i.prototype.first=function(){return this.waypoints[0]},i.prototype.last=function(){return this.waypoints[this.waypoints.length-1]},i.findOrCreate=function(t){return o[t.axis][t.name]||new i(t)},n.Group=i}(),function(){"use strict";function t(t){this.$element=e(t)}var e=window.jQuery,i=window.Waypoint;e.each(["innerHeight","innerWidth","off","offset","on","outerHeight","outerWidth","scrollLeft","scrollTop"],function(e,i){t.prototype[i]=function(){var t=Array.prototype.slice.call(arguments);return this.$element[i].apply(this.$element,t)}}),e.each(["extend","inArray","isEmptyObject"],function(i,o){t[o]=e[o]}),i.adapters.push({name:"jquery",Adapter:t}),i.Adapter=t}(),function(){"use strict";function t(t){return function(){var i=[],o=arguments[0];return t.isFunction(arguments[0])&&(o=t.extend({},arguments[1]),o.handler=arguments[0]),this.each(function(){var n=t.extend({},o,{element:this});"string"==typeof n.context&&(n.context=t(this).closest(n.context)[0]),i.push(new e(n))}),i}}var e=window.Waypoint;window.jQuery&&(window.jQuery.fn.waypoint=t(window.jQuery)),window.Zepto&&(window.Zepto.fn.waypoint=t(window.Zepto))}();
languages/wpinked-widgets-en.po CHANGED
@@ -511,7 +511,7 @@ msgstr ""
511
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:358
512
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:371
513
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:384
514
- msgid "Enter the units, eg: px, em, rem, ..."
515
  msgstr ""
516
 
517
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:112
@@ -834,7 +834,7 @@ msgstr ""
834
 
835
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:58
836
  msgid ""
837
- "Define the thickness of the divider. Enter the units, eg: px, em, rem, ..."
838
  msgstr ""
839
 
840
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:64
@@ -842,7 +842,7 @@ msgid "Width"
842
  msgstr ""
843
 
844
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:65
845
- msgid "Enter the units, eg: px, em, rem, %, ..."
846
  msgstr ""
847
 
848
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:71
@@ -850,7 +850,7 @@ msgid "Margin Top"
850
  msgstr ""
851
 
852
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:72
853
- msgid "Spacing above the divider. Enter the units, eg: px, em, rem, ..."
854
  msgstr ""
855
 
856
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:78
@@ -858,7 +858,7 @@ msgid "Margin Bottom"
858
  msgstr ""
859
 
860
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:79
861
- msgid "Spacing below the divider. Enter the units, eg: px, em, rem, ..."
862
  msgstr ""
863
 
864
  #: widgets/ink-prsn-widget/ink-prsn-widget.php:18
511
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:358
512
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:371
513
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:384
514
+ msgid "Please specify units, eg: px, em, rem, ..."
515
  msgstr ""
516
 
517
  #: widgets/ink-blgs-widget/ink-blgs-widget.php:112
834
 
835
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:58
836
  msgid ""
837
+ "Define the thickness of the divider. Please specify units, eg: px, em, rem, ..."
838
  msgstr ""
839
 
840
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:64
842
  msgstr ""
843
 
844
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:65
845
+ msgid "Please specify units, eg: px, em, rem, %, ..."
846
  msgstr ""
847
 
848
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:71
850
  msgstr ""
851
 
852
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:72
853
+ msgid "Spacing above the divider. Please specify units, eg: px, em, rem, ..."
854
  msgstr ""
855
 
856
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:78
858
  msgstr ""
859
 
860
  #: widgets/ink-dvdr-widget/ink-dvdr-widget.php:79
861
+ msgid "Spacing below the divider. Please specify units, eg: px, em, rem, ..."
862
  msgstr ""
863
 
864
  #: widgets/ink-prsn-widget/ink-prsn-widget.php:18
mixins/less/custom.less ADDED
File without changes
mixins/less/elements.less ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*---------------------------------------------------
2
+ LESS Elements 0.9
3
+ ---------------------------------------------------
4
+ A set of useful LESS mixins
5
+ More info at: http://lesselements.com
6
+ ---------------------------------------------------*/
7
+
8
+ .gradient(@color: #F5F5F5, @start: #EEE, @stop: #FFF) {
9
+ background: @color;
10
+ background: -webkit-gradient(linear,
11
+ left bottom,
12
+ left top,
13
+ color-stop(0, @start),
14
+ color-stop(1, @stop));
15
+ background: -ms-linear-gradient(bottom,
16
+ @start,
17
+ @stop);
18
+ background: -moz-linear-gradient(center bottom,
19
+ @start 0%,
20
+ @stop 100%);
21
+ background: -o-linear-gradient(@stop,
22
+ @start);
23
+ filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",@stop,@start));
24
+ }
25
+ .bw-gradient(@color: #F5F5F5, @start: 0, @stop: 255) {
26
+ background: @color;
27
+ background: -webkit-gradient(linear,
28
+ left bottom,
29
+ left top,
30
+ color-stop(0, rgb(@start,@start,@start)),
31
+ color-stop(1, rgb(@stop,@stop,@stop)));
32
+ background: -ms-linear-gradient(bottom,
33
+ rgb(@start,@start,@start) 0%,
34
+ rgb(@stop,@stop,@stop) 100%);
35
+ background: -moz-linear-gradient(center bottom,
36
+ rgb(@start,@start,@start) 0%,
37
+ rgb(@stop,@stop,@stop) 100%);
38
+ background: -o-linear-gradient(rgb(@stop,@stop,@stop),
39
+ rgb(@start,@start,@start));
40
+ filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",rgb(@stop,@stop,@stop),rgb(@start,@start,@start)));
41
+ }
42
+ .bordered(@top-color: #EEE, @right-color: #EEE, @bottom-color: #EEE, @left-color: #EEE) {
43
+ border-top: solid 1px @top-color;
44
+ border-left: solid 1px @left-color;
45
+ border-right: solid 1px @right-color;
46
+ border-bottom: solid 1px @bottom-color;
47
+ }
48
+ .drop-shadow(@x-axis: 0, @y-axis: 1px, @blur: 2px, @alpha: 0.1) {
49
+ -webkit-box-shadow: @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);
50
+ -moz-box-shadow: @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);
51
+ box-shadow: @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);
52
+ }
53
+ .rounded(@radius: 2px) {
54
+ -webkit-border-radius: @radius;
55
+ -moz-border-radius: @radius;
56
+ border-radius: @radius;
57
+ }
58
+ .border-radius(@topright: 0, @bottomright: 0, @bottomleft: 0, @topleft: 0) {
59
+ -webkit-border-top-right-radius: @topright;
60
+ -webkit-border-bottom-right-radius: @bottomright;
61
+ -webkit-border-bottom-left-radius: @bottomleft;
62
+ -webkit-border-top-left-radius: @topleft;
63
+ -moz-border-radius-topright: @topright;
64
+ -moz-border-radius-bottomright: @bottomright;
65
+ -moz-border-radius-bottomleft: @bottomleft;
66
+ -moz-border-radius-topleft: @topleft;
67
+ border-top-right-radius: @topright;
68
+ border-bottom-right-radius: @bottomright;
69
+ border-bottom-left-radius: @bottomleft;
70
+ border-top-left-radius: @topleft;
71
+ .background-clip(padding-box);
72
+ }
73
+ .opacity(@opacity: 0.5) {
74
+ -moz-opacity: @opacity;
75
+ -khtml-opacity: @opacity;
76
+ -webkit-opacity: @opacity;
77
+ opacity: @opacity;
78
+ @opperc: @opacity * 100;
79
+ -ms-filter: ~"progid:DXImageTransform.Microsoft.Alpha(opacity=@{opperc})";
80
+ filter: ~"alpha(opacity=@{opperc})";
81
+ }
82
+ .transition-duration(@duration: 0.2s) {
83
+ -moz-transition-duration: @duration;
84
+ -webkit-transition-duration: @duration;
85
+ -o-transition-duration: @duration;
86
+ transition-duration: @duration;
87
+ }
88
+ .transform(...) {
89
+ -webkit-transform: @arguments;
90
+ -moz-transform: @arguments;
91
+ -o-transform: @arguments;
92
+ -ms-transform: @arguments;
93
+ transform: @arguments;
94
+ }
95
+ .rotation(@deg:5deg){
96
+ .transform(rotate(@deg));
97
+ }
98
+ .scale(@ratio:1.5){
99
+ .transform(scale(@ratio));
100
+ }
101
+ .transition(@duration:0.2s, @ease:ease-out) {
102
+ -webkit-transition: all @duration @ease;
103
+ -moz-transition: all @duration @ease;
104
+ -o-transition: all @duration @ease;
105
+ transition: all @duration @ease;
106
+ }
107
+ .inner-shadow(@horizontal:0, @vertical:1px, @blur:2px, @alpha: 0.4) {
108
+ -webkit-box-shadow: inset @horizontal @vertical @blur rgba(0, 0, 0, @alpha);
109
+ -moz-box-shadow: inset @horizontal @vertical @blur rgba(0, 0, 0, @alpha);
110
+ box-shadow: inset @horizontal @vertical @blur rgba(0, 0, 0, @alpha);
111
+ }
112
+ .box-shadow(@arguments) {
113
+ -webkit-box-shadow: @arguments;
114
+ -moz-box-shadow: @arguments;
115
+ box-shadow: @arguments;
116
+ }
117
+ .box-sizing(@sizing: border-box) {
118
+ -ms-box-sizing: @sizing;
119
+ -moz-box-sizing: @sizing;
120
+ -webkit-box-sizing: @sizing;
121
+ box-sizing: @sizing;
122
+ }
123
+ .user-select(@argument: none) {
124
+ -webkit-user-select: @argument;
125
+ -moz-user-select: @argument;
126
+ -ms-user-select: @argument;
127
+ user-select: @argument;
128
+ }
129
+ .columns(@colwidth: 250px, @colcount: 0, @colgap: 50px, @columnRuleColor: #EEE, @columnRuleStyle: solid, @columnRuleWidth: 1px) {
130
+ -moz-column-width: @colwidth;
131
+ -moz-column-count: @colcount;
132
+ -moz-column-gap: @colgap;
133
+ -moz-column-rule-color: @columnRuleColor;
134
+ -moz-column-rule-style: @columnRuleStyle;
135
+ -moz-column-rule-width: @columnRuleWidth;
136
+ -webkit-column-width: @colwidth;
137
+ -webkit-column-count: @colcount;
138
+ -webkit-column-gap: @colgap;
139
+ -webkit-column-rule-color: @columnRuleColor;
140
+ -webkit-column-rule-style: @columnRuleStyle;
141
+ -webkit-column-rule-width: @columnRuleWidth;
142
+ column-width: @colwidth;
143
+ column-count: @colcount;
144
+ column-gap: @colgap;
145
+ column-rule-color: @columnRuleColor;
146
+ column-rule-style: @columnRuleStyle;
147
+ column-rule-width: @columnRuleWidth;
148
+ }
149
+ .translate(@x:0, @y:0) {
150
+ .transform(translate(@x, @y));
151
+ }
152
+ .background-clip(@argument: padding-box) {
153
+ -moz-background-clip: @argument;
154
+ -webkit-background-clip: @argument;
155
+ background-clip: @argument;
156
+ }
mixins/less/lesshat.less ADDED
@@ -0,0 +1,891 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // * =========================================================== *
2
+ // < LESSHat >
3
+ // * =========================================================== *
4
+ //
5
+ // Made with Energy drinks in Prague, Czech Republic.
6
+ // Handcrafted by Petr Brzek, lesshat.com
7
+ // Works great with CSS Hat csshat.com
8
+ // Licensed under MIT https://github.com/madebysource/lesshat/blob/master/LICENSE
9
+
10
+ // version: v3.0.2 (2014-06-26)
11
+
12
+ // TABLE OF MIXINS:
13
+ // align-content
14
+ // align-items
15
+ // align-self
16
+ // animation
17
+ // animation-delay
18
+ // animation-direction
19
+ // animation-duration
20
+ // animation-fill-mode
21
+ // animation-iteration-count
22
+ // animation-name
23
+ // animation-play-state
24
+ // animation-timing-function
25
+ // appearance
26
+ // backface-visibility
27
+ // background-clip
28
+ // background-image
29
+ // background-origin
30
+ // background-size
31
+ // blur
32
+ // border-bottom-left-radius
33
+ // border-bottom-right-radius
34
+ // border-image
35
+ // border-radius
36
+ // border-top-left-radius
37
+ // border-top-right-radius
38
+ // box-shadow
39
+ // box-sizing
40
+ // brightness
41
+ // calc
42
+ // column-count
43
+ // column-gap
44
+ // column-rule
45
+ // column-width
46
+ // columns
47
+ // contrast
48
+ // display
49
+ // drop-shadow
50
+ // filter
51
+ // flex
52
+ // flex-basis
53
+ // flex-direction
54
+ // flex-grow
55
+ // flex-shrink
56
+ // flex-wrap
57
+ // font-face
58
+ // grayscale
59
+ // hue-rotate
60
+ // hyphens
61
+ // invert
62
+ // justify-content
63
+ // keyframes
64
+ // opacity
65
+ // order
66
+ // perspective
67
+ // perspective-origin
68
+ // placeholder
69
+ // rotate
70
+ // rotate3d
71
+ // rotateX
72
+ // rotateY
73
+ // rotateZ
74
+ // saturate
75
+ // scale
76
+ // scale3d
77
+ // scaleX
78
+ // scaleY
79
+ // scaleZ
80
+ // selection
81
+ // sepia
82
+ // size
83
+ // skew
84
+ // skewX
85
+ // skewY
86
+ // transform
87
+ // transform-origin
88
+ // transform-style
89
+ // transition
90
+ // transition-delay
91
+ // transition-duration
92
+ // transition-property
93
+ // transition-timing-function
94
+ // translate
95
+ // translate3d
96
+ // translateX
97
+ // translateY
98
+ // translateZ
99
+ // user-select
100
+
101
+ .align-content(...) {
102
+ @process: ~`(function(r){return r=r||"stretch"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
103
+ @process_ms: ~`(function(t){return t=t||"stretch","flex-start"==t?t="start":"flex-end"==t?t="end":"space-between"==t?t="justify":"space-around"==t&&(t="distribute"),t})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
104
+ -webkit-align-content: @process;
105
+ -ms-flex-line-pack: @process_ms;
106
+ align-content: @process;
107
+ }
108
+
109
+ .align-items(...) {
110
+ @process_olderwebkit: ~`(function(t){return t=t||"stretch","flex-start"==t?t="start":"flex-end"==t&&(t="end"),t})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
111
+ @process_moz: ~`(function(t){return t=t||"stretch","flex-start"==t?t="start":"flex-end"==t&&(t="end"),t})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
112
+ @process: ~`(function(t){return t=t||"stretch"})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
113
+ @process_ms: ~`(function(t){return t=t||"stretch","flex-start"==t?t="start":"flex-end"==t&&(t="end"),t})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
114
+ -webkit-box-align: @process_olderwebkit;
115
+ -moz-box-align: @process_moz;
116
+ -webkit-align-items: @process;
117
+ -ms-flex-align: @process_ms;
118
+ align-items: @process;
119
+ }
120
+
121
+ .align-self(...) {
122
+ @process: ~`(function(t){return t=t||"auto"})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
123
+ @process_ms: ~`(function(t){return t=t||"auto","flex-start"==t?t="start":"flex-end"==t&&(t="end"),t})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
124
+ -webkit-align-self: @process;
125
+ -ms-flex-item-align: @process_ms;
126
+ align-self: @process;
127
+ }
128
+
129
+ .animation(...) {
130
+ @process: ~`(function(t){return t=t||"none",/^[^, ]*,/.test(t)&&(t=t.replace(/(?:,)(?![^(]*\))/g,"")),t})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
131
+ -webkit-animation: @process;
132
+ -moz-animation: @process;
133
+ -o-animation: @process;
134
+ animation: @process;
135
+ }
136
+
137
+ .animation-delay(...) {
138
+ @process: ~`(function(t){t=t||"0";var r=/(?:\d)(?:ms|s)/gi,e=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(t)||"0"===t||(t=t.replace(e,function(t){return t+=parseFloat(t,10)>10?"ms":"s"})),t})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
139
+ -webkit-animation-delay: @process;
140
+ -moz-animation-delay: @process;
141
+ -o-animation-delay: @process;
142
+ animation-delay: @process;
143
+ }
144
+
145
+ .animation-direction(...) {
146
+ @process: ~`(function(r){return r||"normal"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
147
+ -webkit-animation-direction: @process;
148
+ -moz-animation-direction: @process;
149
+ -o-animation-direction: @process;
150
+ animation-direction: @process;
151
+ }
152
+
153
+ .animation-duration(...) {
154
+ @process: ~`(function(r){r=r||"0";var t=/ms|s/gi,e=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return t.test(r)||"0"===r||(r=r.replace(e,function(r){return r+=parseFloat(r,10)>10?"ms":"s"})),r})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
155
+ -webkit-animation-duration: @process;
156
+ -moz-animation-duration: @process;
157
+ -o-animation-duration: @process;
158
+ animation-duration: @process;
159
+ }
160
+
161
+ .animation-fill-mode(...) {
162
+ @process: ~`(function(r){return r||"none"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
163
+ -webkit-animation-fill-mode: @process;
164
+ -moz-animation-fill-mode: @process;
165
+ -o-animation-fill-mode: @process;
166
+ animation-fill-mode: @process;
167
+ }
168
+
169
+ .animation-iteration-count(...) {
170
+ @process: ~`(function(r){return r||"0"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
171
+ -webkit-animation-iteration-count: @process;
172
+ -moz-animation-iteration-count: @process;
173
+ -o-animation-iteration-count: @process;
174
+ animation-iteration-count: @process;
175
+ }
176
+
177
+ .animation-name(...) {
178
+ @process: ~`(function(r){return r||"none"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
179
+ -webkit-animation-name: @process;
180
+ -moz-animation-name: @process;
181
+ -o-animation-name: @process;
182
+ animation-name: @process;
183
+ }
184
+
185
+ .animation-play-state(...) {
186
+ @process: ~`(function(r){return r||"running"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
187
+ -webkit-animation-play-state: @process;
188
+ -moz-animation-play-state: @process;
189
+ -o-animation-play-state: @process;
190
+ animation-play-state: @process;
191
+ }
192
+
193
+ .animation-timing-function(...) {
194
+ @process: ~`(function(r){return r||"ease"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
195
+ -webkit-animation-timing-function: @process;
196
+ -moz-animation-timing-function: @process;
197
+ -o-animation-timing-function: @process;
198
+ animation-timing-function: @process;
199
+ }
200
+
201
+ .appearance(...) {
202
+ @process: ~`(function(r){return r||"none"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
203
+ -webkit-appearance: @process;
204
+ -moz-appearance: @process;
205
+ appearance: @process;
206
+ }
207
+
208
+ .backface-visibility(...) {
209
+ @process: ~`(function(r){return r||"visible"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
210
+ -webkit-backface-visibility: @process;
211
+ -moz-backface-visibility: @process;
212
+ -ms-backface-visibility: @process;
213
+ -o-backface-visibility: @process;
214
+ backface-visibility: @process;
215
+ }
216
+
217
+ .background-clip(...) {
218
+ @process: ~`(function(r){return r||"border-box"})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
219
+ -webkit-background-clip: @process;
220
+ -moz-background-clip: @process;
221
+ background-clip: @process;
222
+ }
223
+
224
+ .background-image(...) {
225
+ @process_ms: ~`(function(t){function e(t){var e,r,n,a,s,i,u,o,g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c=0,l=0,f="",d=[];if(!t)return t;do e=t.charCodeAt(c++),r=t.charCodeAt(c++),n=t.charCodeAt(c++),o=e<<16|r<<8|n,a=63&o>>18,s=63&o>>12,i=63&o>>6,u=63&o,d[l++]=g.charAt(a)+g.charAt(s)+g.charAt(i)+g.charAt(u);while(c<t.length);f=d.join("");var p=t.length%3;return(p?f.slice(0,p-3):f)+"===".slice(p||3)}if(t=t||8121991,8121991==t)return t;var r=/linear|radial/g.test(t)&&t.split(/,(?=\s*(?:linear|radial|url))/g),n=[],a={"to bottom":'x1="0%" y1="0%" x2="0%" y2="100%"',"to left":'x1="100%" y1="0%" x2="0%" y2="0%"',"to top":'x1="0%" y1="100%" x2="0%" y2="0%"',"to right":'x1="0%" y1="0%" x2="100%" y2="0%"',get"top"(){return this["to bottom"]},get"180deg"(){return this["to bottom"]},get"right"(){return this["to left"]},get"270deg"(){return this["to left"]},get"bottom"(){return this["to top"]},get"90deg"(){return this["to right"]},get"0deg"(){return this["to top"]},get"left"(){return this["to right"]},"-45deg":'x1="0%" y1="0%" x2="100%" y2="100%"',"45deg":'x1="0%" y1="100%" x2="100%" y2="0%"',"ellipse at center":'cx="50%" cy="50%" r="75%"',get"135deg"(){return this["-45deg"]}},s={uri_data:"url(data:image/svg+xml;base64,",xml:'<?xml version="1.0" ?>',svg_start:'<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none">',linear_gradient_start:'<linearGradient id="lesshat-generated" gradientUnits="userSpaceOnUse"',radial_gradient_start:'<radialGradient id="lesshat-generated" gradientUnits="userSpaceOnUse"',linear_gradient_end:"</linearGradient>",radial_gradient_end:"</radialGradient>",rect_linear:'<rect x="0" y="0" width="1" height="1" fill="url(#lesshat-generated)" />',rect_radial:'<rect x="-50" y="-50" width="101" height="101" fill="url(#lesshat-generated)" />',svg_end:"</svg>"};if(r.length){r.forEach(function(t){var e={};if(Object.keys(a).some(function(r){return t.indexOf(r)>=0?(e.svg_direction=a[r],!0):(e.svg_direction=!1,void 0)}),/linear/.test(t))e.svg_type="linear";else if(/radial/.test(t))e.svg_type="radial";else if(!/linear/.test(t)&&!/radial/.test(t))return e.url=t.trim(),e.svg_type="url",e.svg_direction=!0,n.push(e),!1;var r=t.match(/rgb|#[a-zA-Z0-9]|hsl/g).length;e.svg_stops=[],t=t.replace(/transparent/g,"rgba(0,0,0,0)"),t.match(/#[a-zA-Z0-9]/g)&&t.match(/(#[a-zA-Z0-9]+)\s*(\d+%)?/g).forEach(function(t){t=t.split(" "),e.svg_stops.push('<stop offset="'+(t[1]||!1)+'" stop-color="'+t[0]+'" stop-opacity="1"/>')}),t.match(/rgba?\(\d+,\s*\d+,\s*\d+(?:,\s*(0|1|\.\d+|0\.\d+))?\)/g)&&t.replace(/rgba?\((\d+,\s*\d+,\s*\d+)(?:,\s*(0|1|\.\d+|0\.\d+))?\)\s*(\d+%)?/g,function(t,r,n,a){e.svg_stops.push('<stop offset="'+(a||!1)+'" stop-color="rgb('+r+')" stop-opacity="'+(n||1)+'"/>')}),t.match(/hsla?\((\d+,\s*\d+%,\s*\d+%),\s*(0|1|\.\d+|0\.\d+)\)/g)&&t.replace(/hsla?\((\d+,\s*\d+%,\s*\d+%),\s*(0|1|\.\d+|0\.\d+)\)\s*(\d+%)?/g,function(t,r,n,a){e.svg_stops.push('<stop offset="'+(a||!1)+'" stop-color="hsl('+r+')" stop-opacity="'+(n||1)+'"/>')});var s=Math.floor(100/(r-1));e.svg_stops.forEach(function(t,r){/offset="false"/.test(t)&&(e.svg_stops[r]=t.replace(/offset="false"/,'offset="'+s*r+'%"'))}),e.svg_stops.sort(function(t,e){return t=t.match(/offset="(\d+)%"/),e=e.match(/offset="(\d+)%"/),2==t.length&&2==e.length?t[1]-e[1]:void 0}),n.push(e)});var i=[],u=n.every(function(t){for(var e in t)if(0==t[e]||0==t[e].length)return!1;return!0});if(!u)return 8121991;n.forEach(function(t,e){("linear"==t.svg_type||"radial"==t.svg_type)&&(i[e]=s.xml+s.svg_start),"linear"==t.svg_type?(i[e]+=s.linear_gradient_start+" "+t.svg_direction+">",t.svg_stops.forEach(function(t){i[e]+=t}),i[e]+=s.linear_gradient_end,i[e]+=s.rect_linear,i[e]+=s.svg_end):"radial"==t.svg_type?(i[e]+=s.radial_gradient_start+" "+t.svg_direction+">",t.svg_stops.forEach(function(t){i[e]+=t}),i[e]+=s.radial_gradient_end,i[e]+=s.rect_radial,i[e]+=s.svg_end):"url"==t.svg_type&&(i[e]=t.url)}),i.forEach(function(t,r){/<\?xml version="1.0" \?>/g.test(t)&&(i[r]=s.uri_data+e(t)+")")}),t=i.join(",")}return t})((function(){var r="@{arguments}";return r=r.replace(/^\[|\]$/g,"")})())`;
226
+ @process_webkit: ~`(function(t){if(t=t||8121991,8121991==t)return t;var e={"to bottom":"top","to left":"right","to top":"bottom","to right":"left","ellipse at center":"center, ellipse cover","circle closest-side":"center center, circle contain","circle farthest-corner":"center center, circle cover","circle farthest-side":"center center, circle cover","ellipse closest-side":"center center, ellipse contain","ellipse farthest-corner":"center center, ellipse cover","ellipse farthest-side":"center center, ellipse cover"},r=/(radial-gradient\()([a-z- ]+)at\s+(\w+%?)\s*(\w*%?)/g,n=Object.keys(e);return n.some(function(n){return t.indexOf(n)>=0?(t=t.replace(new RegExp(n+"(?![ a-z0-9])","g"),e[n]),!0):(r.test(t)&&(t=t.replace(r,function(t,e,r,n,a){return e.trim()+n.trim()+" "+a.trim()+","+r.replace(/closest-side/g,"contain").replace(/farthest-corner/g,"cover").trim()})),void 0)}),t=t.replace(/(\d+)\s*deg/g,function(t,e){return 90-e+"deg"}).replace(/(linear|radial)-gradient/g,"-webkit-$1-gradient")})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
227
+ @process_moz: ~`(function(e){if(e=e||8121991,8121991==e)return e;var t={"to bottom":"top","to left":"right","to top":"bottom","to right":"left","ellipse at center":"center, ellipse cover","circle closest-side":"center center, circle contain","circle farthest-corner":"center center, circle cover","circle farthest-side":"center center, circle cover","ellipse closest-side":"center center, ellipse contain","ellipse farthest-corner":"center center, ellipse cover","ellipse farthest-side":"center center, ellipse cover"},r=/(radial-gradient\()([a-z- ]+)at\s+(\w+%?)\s*(\w*%?)/g,n=Object.keys(t);return n.some(function(n){return e.indexOf(n)>=0?(e=e.replace(new RegExp(n+"(?![ a-z0-9])","g"),t[n]),!0):(r.test(e)&&(e=e.replace(r,function(e,t,r,n,a){return t.trim()+n.trim()+" "+a.trim()+","+r.replace(/closest-side/g,"contain").replace(/farthest-corner/g,"cover").trim()})),void 0)}),e=e.replace(/(\d+)\s*deg/g,function(e,t){return 90-t+"deg"}).replace(/(linear|radial)-gradient/g,"-moz-$1-gradient")})((function(){var t="@{arguments}";return t=t.replace(/^\[|\]$/g,"")})())`;
228
+ @process_opera: ~`(function(e){if(e=e||8121991,8121991==e)return e;var t={"to bottom":"top","to left":"right","to top":"bottom","to right":"left","ellipse at center":"center, ellipse cover","circle closest-side":"center center, circle contain","circle farthest-corner":"center center, circle cover","circle farthest-side":"center center, circle cover","ellipse closest-side":"center center, ellipse contain","ellipse farthest-corner":"center center, ellipse cover","ellipse farthest-side":"center center, ellipse cover"},r=/(radial-gradient\()([a-z- ]+)at\s+(\w+%?)\s*(\w*%?)/g,n=Object.keys(t);return n.some(function(n){return e.indexOf(n)>=0?(e=e.replace(new RegExp(n+"(?![ a-z0-9])","g"),t[n]),!0):(r.test(e)&&(e=e.replace(r,function(e,t,r,n,a){return t.trim()+n.trim()+" "+a.trim()+","+r.replace(/closest-side/g,"contain").replace(/farthest-corner/g,"cover").trim()})),void 0)}),e=e.replace(/(\d+)\s*deg/g,function(e,t){return 90-t+"deg"}).replace(/(linear|radial)-gradient/g,"-o-$1-gradient")})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
229
+ @process: ~`(function(e){if(e=e||8121991,8121991==e)return e;var t={top:"to bottom",right:"to left",bottom:"to top",left:"to right"},r=Object.keys(t);return r.some(function(r){return e.indexOf(r)>=0&&!new RegExp("to\\s+"+r+"|at\\s+"+r,"g").test(e)?(e=e.replace(new RegExp(r),t[r]),!0):void 0}),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
230
+ background-image: @process_ms;
231
+ background-image: @process_webkit;
232
+ background-image: @process_moz;
233
+ background-image: @process_opera;
234
+ background-image: @process;
235
+ }
236
+
237
+ .background-origin(...) {
238
+ @process: ~`(function(e){return e||"padding-box"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
239
+ -webkit-background-origin: @process;
240
+ -moz-background-origin: @process;
241
+ background-origin: @process;
242
+ }
243
+
244
+ .background-size(...) {
245
+ @process: ~`(function(e){e=e||"auto auto";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
246
+ -webkit-background-size: @process;
247
+ -moz-background-size: @process;
248
+ background-size: @process;
249
+ }
250
+
251
+ .blur(...) {
252
+ @process: ~`(function(e){e=e||"0";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
253
+ -webkit-filter: blur(@process);
254
+ -moz-filter: blur(@process);
255
+ -ms-filter: blur(@process);
256
+ filter: blur(@process);
257
+ }
258
+
259
+ .border-bottom-left-radius(...) {
260
+ @process: ~`(function(e){e=e||"0";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
261
+ -webkit-border-bottom-left-radius: @process; -webkit-background-clip: padding-box;
262
+ -moz-border-radius-bottomleft: @process; -moz-background-clip: padding;
263
+ border-bottom-left-radius: @process; background-clip: padding-box;
264
+ }
265
+
266
+ .border-bottom-right-radius(...) {
267
+ @process: ~`(function(e){e=e||"0";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
268
+ -webkit-border-bottom-right-radius: @process; -webkit-background-clip: padding-box;
269
+ -moz-border-radius-bottomright: @process; -moz-background-clip: padding;
270
+ border-bottom-right-radius: @process; background-clip: padding-box;
271
+ }
272
+
273
+ .border-image(...) {
274
+ @process: ~`(function(e){return e=e||8121991,/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
275
+ -webkit-border-image: @process;
276
+ -moz-border-image: @process;
277
+ -o-border-image: @process;
278
+ border-image: @process;
279
+ }
280
+
281
+ .border-radius(...) {
282
+ @process: ~`(function(e){e=e||"0";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
283
+ -webkit-border-radius: @process; -webkit-background-clip: padding-box;
284
+ -moz-border-radius: @process; -moz-background-clip: padding;
285
+ border-radius: @process; background-clip: padding-box;
286
+ }
287
+
288
+ .border-top-left-radius(...) {
289
+ @process: ~`(function(e){e=e||"0";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
290
+ -webkit-border-top-left-radius: @process; -webkit-background-clip: padding-box;
291
+ -moz-border-radius-topleft: @process; -moz-background-clip: padding;
292
+ border-top-left-radius: @process; background-clip: padding-box;
293
+ }
294
+
295
+ .border-top-right-radius(...) {
296
+ @process: ~`(function(e){e=e||"0";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
297
+ -webkit-border-top-right-radius: @process; -webkit-background-clip: padding-box;
298
+ -moz-border-radius-topright: @process; -moz-background-clip: padding;
299
+ border-top-right-radius: @process; background-clip: padding-box;
300
+ }
301
+
302
+ .box-shadow(...) {
303
+ @process: ~`(function(e){e=e||"0";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
304
+ -webkit-box-shadow: @process;
305
+ -moz-box-shadow: @process;
306
+ box-shadow: @process;
307
+ }
308
+
309
+ .box-sizing(...) {
310
+ @process: ~`(function(e){return e=e||"content-box"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
311
+ -webkit-box-sizing: @process;
312
+ -moz-box-sizing: @process;
313
+ box-sizing: @process;
314
+ }
315
+
316
+ .brightness(...) {
317
+ @process: ~`(function(e){return e=e||"1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
318
+ -webkit-filter: brightness(@process);
319
+ -moz-filter: brightness(@process);
320
+ -ms-filter: brightness(@process);
321
+ filter: brightness(@process);
322
+ }
323
+
324
+ .calc(...) {
325
+ @process: ~`(function(e){function t(t,r){var a=");\n",c=n.split(","),i=c[0]+":"+t+"("+(c[1].trim()||0)+a;"start"==r?e="0;\n"+i:e+=i}e=e||8121991;var r="@{state}",n=e;if(8121991==e)return e;switch(r){case"1":t("-webkit-calc","start"),t("-moz-calc"),t("calc");break;case"2":t("-webkit-calc","start"),t("-moz-calc");break;case"3":t("-webkit-calc","start"),t("calc");break;case"4":t("-webkit-calc","start");break;case"5":t("-moz-calc","start"),t("calc");break;case"6":t("-moz-calc","start");break;case"7":t("calc","start")}return e=e.replace(/;$/g,"")})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
326
+ @state: 1; -lh-property: @process;
327
+
328
+ }
329
+
330
+ .column-count(...) {
331
+ @process: ~`(function(e){return e=e||"auto"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
332
+ -webkit-column-count: @process;
333
+ -moz-column-count: @process;
334
+ column-count: @process;
335
+ }
336
+
337
+ .column-gap(...) {
338
+ @process: ~`(function(e){e=e||"normal";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
339
+ -webkit-column-gap: @process;
340
+ -moz-column-gap: @process;
341
+ column-gap: @process;
342
+ }
343
+
344
+ .column-rule(...) {
345
+ @process: ~`(function(e){e=e||"medium none black";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
346
+ -webkit-column-rule: @process;
347
+ -moz-column-rule: @process;
348
+ column-rule: @process;
349
+ }
350
+
351
+ .column-width(...) {
352
+ @process: ~`(function(e){e=e||"auto";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
353
+ -webkit-column-width: @process;
354
+ -moz-column-width: @process;
355
+ column-width: @process;
356
+ }
357
+
358
+ .columns(...) {
359
+ @process: ~`(function(e){e=e||"auto auto";var t=/^\d+$/;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,""),e=e.split(" ")),t.test(e[0])&&(e[0]=e[0]+"px"),e.join(" ")})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
360
+ -webkit-columns: @process;
361
+ -moz-columns: @process;
362
+ columns: @process;
363
+ }
364
+
365
+ .contrast(...) {
366
+ @process: ~`(function(e){e=e||"100%";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"%"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
367
+ -webkit-filter: ~"contrast(@{process})";
368
+ -moz-filter: ~"contrast(@{process})";
369
+ -ms-filter: ~"contrast(@{process})";
370
+ filter: ~"contrast(@{process})";
371
+ }
372
+
373
+ .display(...) {
374
+ @process_oldwebkit: ~`(function(e){return e="flex"==e||"inline-flex"==e?"-webkit-box":8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
375
+ @process_moz: ~`(function(e){return e="flex"==e||"inline-flex"==e?"-moz-box":8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
376
+ @process_webkit: ~`(function(e){return e="flex"==e||"inline-flex"==e?"-webkit-"+e:8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
377
+ @process_ms: ~`(function(e){return e="flex"==e?"-ms-flexbox":"inline-flex"==e?"-ms-inline-flexbox":8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
378
+ @process: ~`(function(e){return"flex"!=e&&"inline-flex"!=e&&(e=8121991),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
379
+ display: @process_oldwebkit;
380
+ display: @process_moz;
381
+ display: @process_webkit;
382
+ display: @process_ms;
383
+ display: @process;
384
+ }
385
+
386
+ .drop-shadow(...) {
387
+ @process: ~`(function(e){if(e=e||8121991,8121991==e)return e;var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
388
+ -webkit-filter: drop-shadow(@process);
389
+ -moz-filter: drop-shadow(@process);
390
+ -ms-filter: drop-shadow(@process);
391
+ filter: drop-shadow(@process);
392
+ }
393
+
394
+ .filter(...) {
395
+ @process: ~`(function(e){return e=e||"none",/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
396
+ -webkit-filter: @process;
397
+ -moz-filter: @process;
398
+ -ms-filter: @process;
399
+ filter: @process;
400
+ }
401
+
402
+ .flex(...) {
403
+ @process_olderwebkit: ~`(function(e){return/^\d+/.test(e)?e=e.match(/^\d+/)[0]:""==e&&(e="0"),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
404
+ @process_moz: ~`(function(e){return/^\d+/.test(e)?e=e.match(/^\d+/)[0]:""==e&&(e="0"),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
405
+ @process: ~`(function(e){return e=e||"0 1 auto",/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
406
+ -webkit-box-flex: @process_olderwebkit;
407
+ -moz-box-flex: @process_moz;
408
+ -webkit-flex: @process;
409
+ -ms-flex: @process;
410
+ flex: @process;
411
+ }
412
+
413
+ .flex-basis(...) {
414
+ @process: ~`(function(e){e=e||"auto";var t=/\d/gi,r=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return t.test(e)&&(e=e.replace(r,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
415
+ -webkit-flex-basis: @process;
416
+ flex-basis: @process;
417
+ }
418
+
419
+ .flex-direction(...) {
420
+ @process_oldestwebkit: ~`(function(e){return e="row"==e||"column"==e?"normal":"row-reverse"==e||"column-reverse"==e?"reverse":8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
421
+ @process_oldermoz: ~`(function(e){return e="row"==e||"column"==e?"normal":"row-reverse"==e||"column-reverse"==e?"reverse":8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
422
+ @process_olderwebkit: ~`(function(e){return e="row"==e||"row-reverse"==e?"horizontal":"column"==e||"column-reverse"==e?"vertical":8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
423
+ @process_moz: ~`(function(e){return e="row"==e||"row-reverse"==e?"horizontal":"column"==e||"column-reverse"==e?"vertical":8121991})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
424
+ @process: ~`(function(e){return e=e||"row"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
425
+ -webkit-box-direction: @process_oldestwebkit;
426
+ -moz-box-direction: @process_oldermoz;
427
+ -webkit-box-orient: @process_olderwebkit;
428
+ -moz-box-orient: @process_moz;
429
+ -webkit-flex-direction: @process;
430
+ -ms-flex-direction: @process;
431
+ flex-direction: @process;
432
+ }
433
+
434
+ .flex-grow(...) {
435
+ @process: ~`(function(e){return e=e||"0"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
436
+ -webkit-flex-grow: @process;
437
+ flex-grow: @process;
438
+ }
439
+
440
+ .flex-shrink(...) {
441
+ @process: ~`(function(e){return e=e||"1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
442
+ -webkit-flex-shrink: @process;
443
+ flex-shrink: @process;
444
+ }
445
+
446
+ .flex-wrap(...) {
447
+ @process: ~`(function(e){return e=e||"nowrap"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
448
+ -webkit-flex-wrap: @process;
449
+ -ms-flex-wrap: @process;
450
+ flex-wrap: @process;
451
+ }
452
+
453
+ .font-face(@fontname, @fontfile, @fontweight:normal, @fontstyle:normal) {
454
+ font-family: "@{fontname}";
455
+ src: url("@{fontfile}.eot");
456
+ src: url("@{fontfile}.eot?#iefix") format("embedded-opentype"),
457
+ url("@{fontfile}.woff") format("woff"),
458
+ url("@{fontfile}.ttf") format("truetype"),
459
+ url("@{fontfile}.svg#@{fontname}") format("svg");
460
+ font-weight: @fontweight;
461
+ font-style: @fontstyle;
462
+ }
463
+
464
+ .grayscale(...) {
465
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"%"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
466
+ -webkit-filter: grayscale(@process);
467
+ -moz-filter: grayscale(@process);
468
+ -ms-filter: grayscale(@process);
469
+ filter: grayscale(@process);
470
+ }
471
+
472
+ .hue-rotate(...) {
473
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
474
+ -webkit-filter: hue-rotate(@process);
475
+ -moz-filter: hue-rotate(@process);
476
+ -ms-filter: hue-rotate(@process);
477
+ filter: hue-rotate(@process);
478
+ }
479
+
480
+ .hyphens(...) {
481
+ @process: ~`(function(e){return e=e||"manual"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
482
+ -webkit-hyphens: @process;
483
+ -moz-hyphens: @process;
484
+ -ms-hyphens: @process;
485
+ hyphens: @process;
486
+ }
487
+
488
+ .invert(...) {
489
+ @process: ~`(function(e){e=e||"100%";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"%"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
490
+ -webkit-filter: invert(@process);
491
+ -moz-filter: invert(@process);
492
+ -ms-filter: invert(@process);
493
+ filter: invert(@process);
494
+ }
495
+
496
+ .justify-content(...) {
497
+ @process_oldestWebkit: ~`(function(e){return e=e||"start","flex-start"==e?e="start":"flex-end"==e?e="end":("space-between"==e||"space-around"==e)&&(e="justify"),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
498
+ @process_moz: ~`(function(e){return e=e||"start","flex-start"==e?e="start":"flex-end"==e?e="end":("space-between"==e||"space-around"==e)&&(e="justify"),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
499
+ @process_ms: ~`(function(e){return e=e||"start","flex-start"==e?e="start":"flex-end"==e?e="end":"space-between"==e?e="justify":"space-around"==e&&(e="distribute"),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
500
+ @process: ~`(function(e){return e=e||"flex-start"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
501
+ -webkit-box-pack: @process_oldestWebkit;
502
+ -moz-box-pack: @process_moz;
503
+ -ms-flex-pack: @process_ms;
504
+ -webkit-justify-content: @process;
505
+ justify-content: @process;
506
+ }
507
+
508
+ .keyframes(...) {
509
+ @process: ~`(function(e){function r(r,t,c){var i="}\n",u=n.split(/(^[a-zA-Z0-9-]+),/g),s=t+" "+u[1]+"{",o=["-webkit-","-moz-","-ms-",""];c?a.forEach(function(r){-1!==e.indexOf(r)&&(u[2]=u[2].replace(new RegExp(r,"g"),function(e){return c+e}))}):u[2]=u[2].replace(/{([^}]+)}/g,function(e,r){var t=r.split(";");t.forEach(function(e,r){a.forEach(function(n){-1!==e.indexOf(n)&&(t[r]="",o.forEach(function(a){t[r]+=e.trim().replace(new RegExp(n,"g"),function(e){return a+e})+";"}))})});var n=t.join(";").replace(/;;/g,";");return e.replace(r,n)}),s+=u[2]+i,"start"==r?e="0; } \n"+s:"startend"==r?e="0; } \n"+s.replace(i,""):e+="end"==r?s.replace(i,""):s}e=e||8121991;var t="@{state}",n=e;if(8121991==e)return e;var a=["animation","transform","filter"];switch(t){case"1":r("start","@-webkit-keyframes","-webkit-"),r(null,"@-moz-keyframes","-moz-"),r(null,"@-o-keyframes","-o-"),r("end","@keyframes");break;case"2":r("start","@-webkit-keyframes","-webkit-"),r(null,"@-moz-keyframes","-moz-"),r("end","@keyframes");break;case"3":r("start","@-webkit-keyframes","-webkit-"),r(null,"@-moz-keyframes","-moz-"),r("end","@-o-keyframes","-o-");break;case"4":r("start","@-webkit-keyframes","-webkit-"),r(null,"@-o-keyframes","-o-"),r("end","@keyframes");break;case"5":r("start","@-webkit-keyframes","-webkit-"),r("end","@-moz-keyframes","-moz-");break;case"6":r("start","@-webkit-keyframes","-webkit-"),r("end","@-o-keyframes","-o-");break;case"7":r("start","@-webkit-keyframes","-webkit-"),r("end","@keyframes");break;case"8":r("startend","@-webkit-keyframes","-webkit-");break;case"9":r("start","@-moz-keyframes","-moz-"),r(null,"@-o-keyframes","-o-"),r("end","@keyframes");break;case"10":r("start","@-moz-keyframes","-moz-"),r("end","@-o-keyframes","-o-");break;case"11":r("start","@-moz-keyframes","-moz-"),r("end","@keyframes");break;case"12":r("startend","@-moz-keyframes","-moz-");break;case"13":r("start","@-o-keyframes","-o-"),r("end","@keyframes");break;case"14":r("startend","@-o-keyframes","-o-");break;case"15":r("startend","@keyframes")}return e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
510
+ @state: 1; lesshat-selector { -lh-property: @process; }
511
+
512
+
513
+
514
+ }
515
+
516
+ .opacity(...) {
517
+ @process_ms: ~`(function(e){return e=e||"filter: alpha(opacity=100)","alpha(opacity="+Math.floor(100*e)+")"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
518
+ @process: ~`(function(e){return e=e||"1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
519
+ zoom: 1; filter: @process_ms;
520
+ -webkit-opacity: @process;
521
+ -moz-opacity: @process;
522
+ opacity: @process;
523
+ }
524
+
525
+ .order(...) {
526
+ @process: ~`(function(e){return e=e||"0"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
527
+ -webkit-box-ordinal-group: @process;
528
+ -moz-box-ordinal-group: @process;
529
+ -ms-flex-order: @process;
530
+ -webkit-order: @process;
531
+ order: @process;
532
+ }
533
+
534
+ .perspective(...) {
535
+ @process: ~`(function(e){e=e||"none";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
536
+ -webkit-perspective: @process;
537
+ -moz-perspective: @process;
538
+ perspective: @process;
539
+ }
540
+
541
+ .perspective-origin(...) {
542
+ @process: ~`(function(e){e=e||"50% 50%";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"%"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
543
+ -webkit-perspective-origin: @process;
544
+ -moz-perspective-origin: @process;
545
+ perspective-origin: @process;
546
+ }
547
+
548
+ .placeholder(@color:#aaa, @element: 08121991) {
549
+ .inception (@arguments) when not (@element = 08121991) {
550
+ @{element}::-webkit-input-placeholder {
551
+ color: @color;
552
+ }
553
+ @{element}:-moz-placeholder {
554
+ color: @color;
555
+ }
556
+ @{element}::-moz-placeholder {
557
+ color: @color;
558
+ }
559
+ @{element}:-ms-input-placeholder {
560
+ color: @color;
561
+ }
562
+ }
563
+ .inception (@arguments) when (@element = 08121991) {
564
+ &::-webkit-input-placeholder {
565
+ color: @color;
566
+ }
567
+ &:-moz-placeholder {
568
+ color: @color;
569
+ }
570
+ &::-moz-placeholder {
571
+ color: @color;
572
+ }
573
+ &:-ms-input-placeholder {
574
+ color: @color;
575
+ }
576
+ }
577
+ .inception(@arguments);
578
+ }
579
+
580
+ .rotate(...) {
581
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
582
+ -webkit-transform: rotate(@process);
583
+ -moz-transform: rotate(@process);
584
+ -ms-transform: rotate(@process);
585
+ -o-transform: rotate(@process);
586
+ transform: rotate(@process);
587
+ }
588
+
589
+ .rotate3d(...) {
590
+ @process: ~`(function(e){return e=e||"0, 0, 0, 0",e=e.replace(/,\s*\d+$/,function(e){return e+"deg"})})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
591
+ -webkit-transform: rotate3d(@process);
592
+ -moz-transform: rotate3d(@process);
593
+ -ms-transform: rotate3d(@process);
594
+ -o-transform: rotate3d(@process);
595
+ transform: rotate3d(@process);
596
+ }
597
+
598
+ .rotateX(...) {
599
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
600
+ -webkit-transform: rotateX(@process);
601
+ -moz-transform: rotateX(@process);
602
+ -ms-transform: rotateX(@process);
603
+ -o-transform: rotateX(@process);
604
+ transform: rotateX(@process);
605
+ }
606
+
607
+ .rotateY(...) {
608
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
609
+ -webkit-transform: rotateY(@process);
610
+ -moz-transform: rotateY(@process);
611
+ -ms-transform: rotateY(@process);
612
+ -o-transform: rotateY(@process);
613
+ transform: rotateY(@process);
614
+ }
615
+
616
+ .rotateZ(...) {
617
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
618
+ -webkit-transform: rotateZ(@process);
619
+ -moz-transform: rotateZ(@process);
620
+ -ms-transform: rotateZ(@process);
621
+ -o-transform: rotateZ(@process);
622
+ transform: rotateZ(@process);
623
+ }
624
+
625
+ .saturate(...) {
626
+ @process: ~`(function(e){e=e||"100%";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"%"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
627
+ -webkit-filter: ~"saturate(@{process})";
628
+ -moz-filter: ~"saturate(@{process})";
629
+ -ms-filter: ~"saturate(@{process})";
630
+ filter: ~"saturate(@{process})";
631
+ }
632
+
633
+ .scale(...) {
634
+ @process: ~`(function(e){return e=e||"1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
635
+ -webkit-transform: scale(@process);
636
+ -moz-transform: scale(@process);
637
+ -ms-transform: scale(@process);
638
+ -o-transform: scale(@process);
639
+ transform: scale(@process);
640
+ }
641
+
642
+ .scale3d(...) {
643
+ @process: ~`(function(e){return e=e||"1, 1, 1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
644
+ -webkit-transform: scale3d(@process);
645
+ -moz-transform: scale3d(@process);
646
+ -ms-transform: scale3d(@process);
647
+ -o-transform: scale3d(@process);
648
+ transform: scale3d(@process);
649
+ }
650
+
651
+ .scaleX(...) {
652
+ @process: ~`(function(e){return e=e||"1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
653
+ -webkit-transform: scaleX(@process);
654
+ -moz-transform: scaleX(@process);
655
+ -ms-transform: scaleX(@process);
656
+ -o-transform: scaleX(@process);
657
+ transform: scaleX(@process);
658
+ }
659
+
660
+ .scaleY(...) {
661
+ @process: ~`(function(e){return e=e||"1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
662
+ -webkit-transform: scaleY(@process);
663
+ -moz-transform: scaleY(@process);
664
+ -ms-transform: scaleY(@process);
665
+ -o-transform: scaleY(@process);
666
+ transform: scaleY(@process);
667
+ }
668
+
669
+ .scaleZ(...) {
670
+ @process: ~`(function(e){return e=e||"1"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
671
+ -webkit-transform: scaleZ(@process);
672
+ -moz-transform: scaleZ(@process);
673
+ -ms-transform: scaleZ(@process);
674
+ -o-transform: scaleZ(@process);
675
+ transform: scaleZ(@process);
676
+ }
677
+
678
+ .selection(...) {
679
+ @process: ~`(function(e){function r(r,t){var a="}\n",c=n.split(","),u=(c[1]||"")+t+"{"+c[0]+a;"start"==r?e="0; } \n"+u:"startend"==r?e="0; } \n"+u.replace(a,""):e+="end"==r?u.replace(a,""):u}e=e||8121991;var t="@{state}",n=e;if(8121991==e)return e;switch(t){case"1":r("start","::selection"),r("end","::-moz-selection");break;case"2":r("startend","::selection");break;case"3":r("startend","::-moz-selection")}return e=e.replace(/;$/g,"")})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
680
+ @state: 1; lesshat-selector { -lh-property: @process; }
681
+
682
+ }
683
+
684
+ .sepia(...) {
685
+ @process: ~`(function(e){e=e||"100%";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"%"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
686
+ -webkit-filter: sepia(@process);
687
+ -moz-filter: sepia(@process);
688
+ -ms-filter: sepia(@process);
689
+ filter: sepia(@process);
690
+ }
691
+
692
+ .size(@square) {
693
+ @unit: 'px';
694
+ .process(@square) when (ispixel(@square)), (isem(@square)), (ispercentage(@square)), (iskeyword(@square)) {
695
+ width: @square;
696
+ height: @square;
697
+ }
698
+
699
+ .process(@square) when not (ispixel(@square)) and not (isem(@square)) and not (ispercentage(@square)) and not (isstring(@square)) and not (iskeyword(@square)) {
700
+ width: ~`@{square} + @{unit}`;
701
+ height: ~`@{square} + @{unit}`;
702
+ }
703
+
704
+ .process(@square);
705
+
706
+ }
707
+
708
+ .size(@width, @height) {
709
+ @unit: 'px';
710
+ .process(@width, @height) when (ispixel(@width)), (isem(@width)), (ispercentage(@width)), (iskeyword(@width)) {
711
+ .kittens(@height) when (ispixel(@height)), (isem(@height)), (ispercentage(@height)), (iskeyword(@height)) {
712
+ width: @width;
713
+ height: @height;
714
+ }
715
+ .kittens(@height) when not (ispixel(@height)) and not (isem(@height)) and not (ispercentage(@height)) and not (iskeyword(@height)) {
716
+ width: @width;
717
+ height: ~`@{height} + @{unit}`;
718
+ }
719
+ .kittens(@height);
720
+ }
721
+
722
+ .process(@width, @height) when (ispixel(@height)), (isem(@height)), (ispercentage(@height)), (iskeyword(@height)) {
723
+ .kittens(@width) when (ispixel(@width)), (isem(@width)), (ispercentage(@width)), (iskeyword(@width)) {}
724
+ .kittens(@width) when not (ispixel(@width)) and not (isem(@width)) and not (ispercentage(@width)) and not (iskeyword(@width)) {
725
+ width: ~`@{width} + @{unit}`;
726
+ height: @height;
727
+ }
728
+ .kittens(@width);
729
+ }
730
+
731
+ .process(@width, @height) when not (ispixel(@width)) and not (isem(@width)) and not (ispercentage(@width)) and not (iskeyword(@width)) and not (ispixel(@height)) and not (isem(@height)) and not (ispercentage(@height)) and not (iskeyword(@height)) {
732
+ width: ~`@{width} + @{unit}`;
733
+ height: ~`@{height} + @{unit}`;
734
+ }
735
+
736
+ .process(@width, @height);
737
+
738
+ }
739
+
740
+ .skew(...) {
741
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
742
+ -webkit-transform: skew(@process);
743
+ -moz-transform: skew(@process);
744
+ -ms-transform: skew(@process);
745
+ -o-transform: skew(@process);
746
+ transform: skew(@process);
747
+ }
748
+
749
+ .skewX(...) {
750
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
751
+ -webkit-transform: skewX(@process);
752
+ -moz-transform: skewX(@process);
753
+ -ms-transform: skewX(@process);
754
+ -o-transform: skewX(@process);
755
+ transform: skewX(@process);
756
+ }
757
+
758
+ .skewY(...) {
759
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"deg"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
760
+ -webkit-transform: skewY(@process);
761
+ -moz-transform: skewY(@process);
762
+ -ms-transform: skewY(@process);
763
+ -o-transform: skewY(@process);
764
+ transform: skewY(@process);
765
+ }
766
+
767
+ .transform(...) {
768
+ @process: ~`(function(e){e=e||"none";var r={translate:"px",rotate:"deg",rotate3d:"deg",skew:"deg"};/^\w*\(?[a-z0-9.]*\)?/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,""));for(var t in r)e.indexOf(t)>=0&&(e=e.replace(new RegExp(t+"[\\w]?\\([a-z0-9, %]*\\)"),function(e){var n=/(\d+\.?\d*)(?!\w|%)/g;return"rotate3d"==t&&(n=/,\s*\d+$/),e.replace(n,function(e){return e+r[t]})}));return e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
769
+ -webkit-transform: @process;
770
+ -moz-transform: @process;
771
+ -ms-transform: @process;
772
+ -o-transform: @process;
773
+ transform: @process;
774
+ }
775
+
776
+ .transform-origin(...) {
777
+ @process: ~`(function(e){e=e||"50% 50% 0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"%"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
778
+ -webkit-transform-origin: @process;
779
+ -moz-transform-origin: @process;
780
+ -ms-transform-origin: @process;
781
+ -o-transform-origin: @process;
782
+ transform-origin: @process;
783
+ }
784
+
785
+ .transform-style(...) {
786
+ @process: ~`(function(e){return e=e||"flat"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
787
+ -webkit-transform-style: @process;
788
+ -moz-transform-style: @process;
789
+ -ms-transform-style: @process;
790
+ -o-transform-style: @process;
791
+ transform-style: @process;
792
+ }
793
+
794
+ .transition(...) {
795
+ @process_webkit: ~`(function(e){e=e||"all 0 ease 0";var r=["background-size","border-radius","border-bottom-left-radius","border-bottom-right-radius","border-top-left-radius","border-top-right-radius","box-shadow","column","transform","filter"],t="-webkit-",n=/(?:\d)(?:ms|s)/gi,a=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),r.forEach(function(r){-1!==e.indexOf(r)&&(e=e.replace(new RegExp(r,"g"),function(e){return t+e}))}),n.test(e)||"0"===e||(e=e.replace(a,function(e){return e+=parseFloat(e,10)>10?"ms":"s"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
796
+ @process_moz: ~`(function(e){e=e||"all 0 ease 0";var r=["background-size","box-shadow","column","transform","filter"],t="-moz-",n=/(?:\d)(?:ms|s)/gi,a=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),r.forEach(function(r){-1!==e.indexOf(r)&&(e=e.replace(new RegExp(r,"g"),function(e){return t+e}))}),n.test(e)||"0"===e||(e=e.replace(a,function(e){return e+=parseFloat(e,10)>10?"ms":"s"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
797
+ @process_opera: ~`(function(e){e=e||"all 0 ease 0";var r=["transform"],t="-o-",n=/(?:\d)(?:ms|s)/gi,a=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%)/gi;return/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,"")),r.forEach(function(r){-1!==e.indexOf(r)&&(e=e.replace(new RegExp(r,"g"),function(e){return t+e}))}),n.test(e)||"0"===e||(e=e.replace(a,function(e){return e+=parseFloat(e,10)>10?"ms":"s"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
798
+ @process: ~`(function(e){e=e||"all 0 ease 0";var r=["-webkit-","-moz-","-o-",""],t=["column","transform","filter"],n=/(?:\d)(?:ms|s)/gi,a=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%)/gi;/^[^, ]*,/.test(e)&&(e=e.replace(/(?:,)(?![^(]*\))/g,""));var c=e.split(/(?:,)(?![^(]*\))/g);return c.forEach(function(e,n){t.forEach(function(t){-1!==e.indexOf(t)&&(c[n]="",r.forEach(function(a,u){c[n]+=e.trim().replace(new RegExp(t,"g"),function(e){return a+e}),u<r.length-1&&(c[n]+=",")}))})}),e=c.join(","),n.test(e)||"0"===e||(e=e.replace(a,function(e){return e+=parseFloat(e,10)>10?"ms":"s"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
799
+ -webkit-transition: @process_webkit;
800
+ -moz-transition: @process_moz;
801
+ -o-transition: @process_opera;
802
+ transition: @process;
803
+ }
804
+
805
+ .transition-delay(...) {
806
+ @process: ~`(function(e){e=e||"0";var r=/(?:\d)(?:ms|s)/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)||"0"===e||(e=e.replace(t,function(e){return e+=parseFloat(e,10)>10?"ms":"s"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
807
+ -webkit-transition-delay: @process;
808
+ -moz-transition-delay: @process;
809
+ -o-transition-delay: @process;
810
+ transition-delay: @process;
811
+ }
812
+
813
+ .transition-duration(...) {
814
+ @process: ~`(function(e){e=e||"0";var r=/ms|s/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)||"0"===e||(e=e.replace(t,function(e){return e+=parseFloat(e,10)>10?"ms":"s"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
815
+ -webkit-transition-duration: @process;
816
+ -moz-transition-duration: @process;
817
+ -o-transition-duration: @process;
818
+ transition-duration: @process;
819
+ }
820
+
821
+ .transition-property(...) {
822
+ @process_webkit: ~`(function(e){e=e||"all";var r=["background-size","border-radius","border-bottom-left-radius","border-bottom-right-radius","border-top-left-radius","border-top-right-radius","box-shadow","column","transform","filter"],t="-webkit-";return r.forEach(function(r){-1!==e.indexOf(r)&&(e=e.replace(new RegExp(r,"g"),function(e){return t+e}))}),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
823
+ @process_moz: ~`(function(e){e=e||"all";var r=["background-size","box-shadow","column","transform","filter"],t="-moz-";return r.forEach(function(r){-1!==e.indexOf(r)&&(e=e.replace(new RegExp(r,"g"),function(e){return t+e}))}),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
824
+ @process_opera: ~`(function(e){e=e||"all";var r=["transform"],t="-o-";return r.forEach(function(r){-1!==e.indexOf(r)&&(e=e.replace(new RegExp(r,"g"),function(e){return t+e}))}),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
825
+ @process: ~`(function(e){e=e||"all";var r=["-webkit-","-moz-","-o-",""],t=["column","transform","filter"],n=e.split(/(?:,)(?![^(]*\))/g);return n.forEach(function(e,a){t.forEach(function(t){-1!==e.indexOf(t)&&(n[a]="",r.forEach(function(c,u){n[a]+=e.trim().replace(new RegExp(t,"g"),function(e){return c+e}),u<r.length-1&&(n[a]+=",")}))})}),e=n.join(",")})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
826
+ -webkit-transition-property: @process_webkit;
827
+ -moz-transition-property: @process_moz;
828
+ -o-transition-property: @process_opera;
829
+ transition-property: @process;
830
+ }
831
+
832
+ .transition-timing-function(...) {
833
+ @process: ~`(function(e){return e=e||"ease"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
834
+ -webkit-transition-timing-function: @process;
835
+ -moz-transition-timing-function: @process;
836
+ -o-transition-timing-function: @process;
837
+ transition-timing-function: @process;
838
+ }
839
+
840
+ .translate(...) {
841
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
842
+ -webkit-transform: translate(@process);
843
+ -moz-transform: translate(@process);
844
+ -ms-transform: translate(@process);
845
+ -o-transform: translate(@process);
846
+ transform: translate(@process);
847
+ }
848
+
849
+ .translate3d(...) {
850
+ @process: ~`(function(e){e=e||"0, 0, 0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
851
+ -webkit-transform: translate3d(@process);
852
+ -moz-transform: translate3d(@process);
853
+ -ms-transform: translate3d(@process);
854
+ -o-transform: translate3d(@process);
855
+ transform: translate3d(@process);
856
+ }
857
+
858
+ .translateX(...) {
859
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
860
+ -webkit-transform: translateX(@process);
861
+ -moz-transform: translateX(@process);
862
+ -ms-transform: translateX(@process);
863
+ -o-transform: translateX(@process);
864
+ transform: translateX(@process);
865
+ }
866
+
867
+ .translateY(...) {
868
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
869
+ -webkit-transform: translateY(@process);
870
+ -moz-transform: translateY(@process);
871
+ -ms-transform: translateY(@process);
872
+ -o-transform: translateY(@process);
873
+ transform: translateY(@process);
874
+ }
875
+
876
+ .translateZ(...) {
877
+ @process: ~`(function(e){e=e||"0";var r=/\d/gi,t=/(?:\s|^)(\.?\d+\.?\d*)(?![^(]*\)|\w|%|\.)/gi;return r.test(e)&&(e=e.replace(t,function(e){return 0==e&&e||e+"px"})),e})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
878
+ -webkit-transform: translateZ(@process);
879
+ -moz-transform: translateZ(@process);
880
+ -ms-transform: translateZ(@process);
881
+ -o-transform: translateZ(@process);
882
+ transform: translateZ(@process);
883
+ }
884
+
885
+ .user-select(...) {
886
+ @process: ~`(function(e){return e=e||"auto"})((function(){var e="@{arguments}";return e=e.replace(/^\[|\]$/g,"")})())`;
887
+ -webkit-user-select: @process;
888
+ -moz-user-select: @process;
889
+ -ms-user-select: @process;
890
+ user-select: @process;
891
+ }
mixins/less/mixins.less ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ @import "lesshat";
2
+ @import "elements";
3
+ @import "custom";
mixins/sass/bourbon/_bourbon-deprecated-upcoming.scss ADDED
@@ -0,0 +1,411 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The following features have been deprecated and will be removed in the next MAJOR version release
2
+
3
+ @mixin inline-block {
4
+ display: inline-block;
5
+
6
+ @warn "The inline-block mixin is deprecated and will be removed in the next major version release";
7
+ }
8
+
9
+ @mixin button ($style: simple, $base-color: #4294f0, $text-size: inherit, $padding: 7px 18px) {
10
+
11
+ @if type-of($style) == string and type-of($base-color) == color {
12
+ @include buttonstyle($style, $base-color, $text-size, $padding);
13
+ }
14
+
15
+ @if type-of($style) == string and type-of($base-color) == number {
16
+ $padding: $text-size;
17
+ $text-size: $base-color;
18
+ $base-color: #4294f0;
19
+
20
+ @if $padding == inherit {
21
+ $padding: 7px 18px;
22
+ }
23
+
24
+ @include buttonstyle($style, $base-color, $text-size, $padding);
25
+ }
26
+
27
+ @if type-of($style) == color and type-of($base-color) == color {
28
+ $base-color: $style;
29
+ $style: simple;
30
+ @include buttonstyle($style, $base-color, $text-size, $padding);
31
+ }
32
+
33
+ @if type-of($style) == color and type-of($base-color) == number {
34
+ $padding: $text-size;
35
+ $text-size: $base-color;
36
+ $base-color: $style;
37
+ $style: simple;
38
+
39
+ @if $padding == inherit {
40
+ $padding: 7px 18px;
41
+ }
42
+
43
+ @include buttonstyle($style, $base-color, $text-size, $padding);
44
+ }
45
+
46
+ @if type-of($style) == number {
47
+ $padding: $base-color;
48
+ $text-size: $style;
49
+ $base-color: #4294f0;
50
+ $style: simple;
51
+
52
+ @if $padding == #4294f0 {
53
+ $padding: 7px 18px;
54
+ }
55
+
56
+ @include buttonstyle($style, $base-color, $text-size, $padding);
57
+ }
58
+
59
+ &:disabled {
60
+ cursor: not-allowed;
61
+ opacity: 0.5;
62
+ }
63
+
64
+ @warn "The button mixin is deprecated and will be removed in the next major version release";
65
+ }
66
+
67
+ // Selector Style Button
68
+ @mixin buttonstyle($type, $b-color, $t-size, $pad) {
69
+ // Grayscale button
70
+ @if $type == simple and $b-color == grayscale($b-color) {
71
+ @include simple($b-color, true, $t-size, $pad);
72
+ }
73
+
74
+ @if $type == shiny and $b-color == grayscale($b-color) {
75
+ @include shiny($b-color, true, $t-size, $pad);
76
+ }
77
+
78
+ @if $type == pill and $b-color == grayscale($b-color) {
79
+ @include pill($b-color, true, $t-size, $pad);
80
+ }
81
+
82
+ @if $type == flat and $b-color == grayscale($b-color) {
83
+ @include flat($b-color, true, $t-size, $pad);
84
+ }
85
+
86
+ // Colored button
87
+ @if $type == simple {
88
+ @include simple($b-color, false, $t-size, $pad);
89
+ }
90
+
91
+ @else if $type == shiny {
92
+ @include shiny($b-color, false, $t-size, $pad);
93
+ }
94
+
95
+ @else if $type == pill {
96
+ @include pill($b-color, false, $t-size, $pad);
97
+ }
98
+
99
+ @else if $type == flat {
100
+ @include flat($b-color, false, $t-size, $pad);
101
+ }
102
+ }
103
+
104
+ // Simple Button
105
+ @mixin simple($base-color, $grayscale: false, $textsize: inherit, $padding: 7px 18px) {
106
+ $color: hsl(0, 0, 100%);
107
+ $border: adjust-color($base-color, $saturation: 9%, $lightness: -14%);
108
+ $inset-shadow: adjust-color($base-color, $saturation: -8%, $lightness: 15%);
109
+ $stop-gradient: adjust-color($base-color, $saturation: 9%, $lightness: -11%);
110
+ $text-shadow: adjust-color($base-color, $saturation: 15%, $lightness: -18%);
111
+
112
+ @if is-light($base-color) {
113
+ $color: hsl(0, 0, 20%);
114
+ $text-shadow: adjust-color($base-color, $saturation: 10%, $lightness: 4%);
115
+ }
116
+
117
+ @if $grayscale == true {
118
+ $border: grayscale($border);
119
+ $inset-shadow: grayscale($inset-shadow);
120
+ $stop-gradient: grayscale($stop-gradient);
121
+ $text-shadow: grayscale($text-shadow);
122
+ }
123
+
124
+ border: 1px solid $border;
125
+ border-radius: 3px;
126
+ box-shadow: inset 0 1px 0 0 $inset-shadow;
127
+ color: $color;
128
+ display: inline-block;
129
+ font-size: $textsize;
130
+ font-weight: bold;
131
+ @include linear-gradient ($base-color, $stop-gradient);
132
+ padding: $padding;
133
+ text-decoration: none;
134
+ text-shadow: 0 1px 0 $text-shadow;
135
+ background-clip: padding-box;
136
+
137
+ &:hover:not(:disabled) {
138
+ $base-color-hover: adjust-color($base-color, $saturation: -4%, $lightness: -5%);
139
+ $inset-shadow-hover: adjust-color($base-color, $saturation: -7%, $lightness: 5%);
140
+ $stop-gradient-hover: adjust-color($base-color, $saturation: 8%, $lightness: -14%);
141
+
142
+ @if $grayscale == true {
143
+ $base-color-hover: grayscale($base-color-hover);
144
+ $inset-shadow-hover: grayscale($inset-shadow-hover);
145
+ $stop-gradient-hover: grayscale($stop-gradient-hover);
146
+ }
147
+
148
+ @include linear-gradient ($base-color-hover, $stop-gradient-hover);
149
+
150
+ box-shadow: inset 0 1px 0 0 $inset-shadow-hover;
151
+ cursor: pointer;
152
+ }
153
+
154
+ &:active:not(:disabled),
155
+ &:focus:not(:disabled) {
156
+ $border-active: adjust-color($base-color, $saturation: 9%, $lightness: -14%);
157
+ $inset-shadow-active: adjust-color($base-color, $saturation: 7%, $lightness: -17%);
158
+
159
+ @if $grayscale == true {
160
+ $border-active: grayscale($border-active);
161
+ $inset-shadow-active: grayscale($inset-shadow-active);
162
+ }
163
+
164
+ border: 1px solid $border-active;
165
+ box-shadow: inset 0 0 8px 4px $inset-shadow-active, inset 0 0 8px 4px $inset-shadow-active;
166
+ }
167
+ }
168
+
169
+ // Shiny Button
170
+ @mixin shiny($base-color, $grayscale: false, $textsize: inherit, $padding: 7px 18px) {
171
+ $color: hsl(0, 0, 100%);
172
+ $border: adjust-color($base-color, $red: -117, $green: -111, $blue: -81);
173
+ $border-bottom: adjust-color($base-color, $red: -126, $green: -127, $blue: -122);
174
+ $fourth-stop: adjust-color($base-color, $red: -79, $green: -70, $blue: -46);
175
+ $inset-shadow: adjust-color($base-color, $red: 37, $green: 29, $blue: 12);
176
+ $second-stop: adjust-color($base-color, $red: -56, $green: -50, $blue: -33);
177
+ $text-shadow: adjust-color($base-color, $red: -140, $green: -141, $blue: -114);
178
+ $third-stop: adjust-color($base-color, $red: -86, $green: -75, $blue: -48);
179
+
180
+ @if is-light($base-color) {
181
+ $color: hsl(0, 0, 20%);
182
+ $text-shadow: adjust-color($base-color, $saturation: 10%, $lightness: 4%);
183
+ }
184
+
185
+ @if $grayscale == true {
186
+ $border: grayscale($border);
187
+ $border-bottom: grayscale($border-bottom);
188
+ $fourth-stop: grayscale($fourth-stop);
189
+ $inset-shadow: grayscale($inset-shadow);
190
+ $second-stop: grayscale($second-stop);
191
+ $text-shadow: grayscale($text-shadow);
192
+ $third-stop: grayscale($third-stop);
193
+ }
194
+
195
+ @include linear-gradient(top, $base-color 0%, $second-stop 50%, $third-stop 50%, $fourth-stop 100%);
196
+
197
+ border: 1px solid $border;
198
+ border-bottom: 1px solid $border-bottom;
199
+ border-radius: 5px;
200
+ box-shadow: inset 0 1px 0 0 $inset-shadow;
201
+ color: $color;
202
+ display: inline-block;
203
+ font-size: $textsize;
204
+ font-weight: bold;
205
+ padding: $padding;
206
+ text-align: center;
207
+ text-decoration: none;
208
+ text-shadow: 0 -1px 1px $text-shadow;
209
+
210
+ &:hover:not(:disabled) {
211
+ $first-stop-hover: adjust-color($base-color, $red: -13, $green: -15, $blue: -18);
212
+ $second-stop-hover: adjust-color($base-color, $red: -66, $green: -62, $blue: -51);
213
+ $third-stop-hover: adjust-color($base-color, $red: -93, $green: -85, $blue: -66);
214
+ $fourth-stop-hover: adjust-color($base-color, $red: -86, $green: -80, $blue: -63);
215
+
216
+ @if $grayscale == true {
217
+ $first-stop-hover: grayscale($first-stop-hover);
218
+ $second-stop-hover: grayscale($second-stop-hover);
219
+ $third-stop-hover: grayscale($third-stop-hover);
220
+ $fourth-stop-hover: grayscale($fourth-stop-hover);
221
+ }
222
+
223
+ @include linear-gradient(top, $first-stop-hover 0%,
224
+ $second-stop-hover 50%,
225
+ $third-stop-hover 50%,
226
+ $fourth-stop-hover 100%);
227
+ cursor: pointer;
228
+ }
229
+
230
+ &:active:not(:disabled),
231
+ &:focus:not(:disabled) {
232
+ $inset-shadow-active: adjust-color($base-color, $red: -111, $green: -116, $blue: -122);
233
+
234
+ @if $grayscale == true {
235
+ $inset-shadow-active: grayscale($inset-shadow-active);
236
+ }
237
+
238
+ box-shadow: inset 0 0 20px 0 $inset-shadow-active;
239
+ }
240
+ }
241
+
242
+ // Pill Button
243
+ @mixin pill($base-color, $grayscale: false, $textsize: inherit, $padding: 7px 18px) {
244
+ $color: hsl(0, 0, 100%);
245
+ $border-bottom: adjust-color($base-color, $hue: 8, $saturation: -11%, $lightness: -26%);
246
+ $border-sides: adjust-color($base-color, $hue: 4, $saturation: -21%, $lightness: -21%);
247
+ $border-top: adjust-color($base-color, $hue: -1, $saturation: -30%, $lightness: -15%);
248
+ $inset-shadow: adjust-color($base-color, $hue: -1, $saturation: -1%, $lightness: 7%);
249
+ $stop-gradient: adjust-color($base-color, $hue: 8, $saturation: 14%, $lightness: -10%);
250
+ $text-shadow: adjust-color($base-color, $hue: 5, $saturation: -19%, $lightness: -15%);
251
+
252
+ @if is-light($base-color) {
253
+ $color: hsl(0, 0, 20%);
254
+ $text-shadow: adjust-color($base-color, $saturation: 10%, $lightness: 4%);
255
+ }
256
+
257
+ @if $grayscale == true {
258
+ $border-bottom: grayscale($border-bottom);
259
+ $border-sides: grayscale($border-sides);
260
+ $border-top: grayscale($border-top);
261
+ $inset-shadow: grayscale($inset-shadow);
262
+ $stop-gradient: grayscale($stop-gradient);
263
+ $text-shadow: grayscale($text-shadow);
264
+ }
265
+
266
+ border: 1px solid $border-top;
267
+ border-color: $border-top $border-sides $border-bottom;
268
+ border-radius: 16px;
269
+ box-shadow: inset 0 1px 0 0 $inset-shadow;
270
+ color: $color;
271
+ display: inline-block;
272
+ font-size: $textsize;
273
+ font-weight: normal;
274
+ line-height: 1;
275
+ @include linear-gradient ($base-color, $stop-gradient);
276
+ padding: $padding;
277
+ text-align: center;
278
+ text-decoration: none;
279
+ text-shadow: 0 -1px 1px $text-shadow;
280
+ background-clip: padding-box;
281
+
282
+ &:hover:not(:disabled) {
283
+ $base-color-hover: adjust-color($base-color, $lightness: -4.5%);
284
+ $border-bottom: adjust-color($base-color, $hue: 8, $saturation: 13.5%, $lightness: -32%);
285
+ $border-sides: adjust-color($base-color, $hue: 4, $saturation: -2%, $lightness: -27%);
286
+ $border-top: adjust-color($base-color, $hue: -1, $saturation: -17%, $lightness: -21%);
287
+ $inset-shadow-hover: adjust-color($base-color, $saturation: -1%, $lightness: 3%);
288
+ $stop-gradient-hover: adjust-color($base-color, $hue: 8, $saturation: -4%, $lightness: -15.5%);
289
+ $text-shadow-hover: adjust-color($base-color, $hue: 5, $saturation: -5%, $lightness: -22%);
290
+
291
+ @if $grayscale == true {
292
+ $base-color-hover: grayscale($base-color-hover);
293
+ $border-bottom: grayscale($border-bottom);
294
+ $border-sides: grayscale($border-sides);
295
+ $border-top: grayscale($border-top);
296
+ $inset-shadow-hover: grayscale($inset-shadow-hover);
297
+ $stop-gradient-hover: grayscale($stop-gradient-hover);
298
+ $text-shadow-hover: grayscale($text-shadow-hover);
299
+ }
300
+
301
+ @include linear-gradient ($base-color-hover, $stop-gradient-hover);
302
+
303
+ background-clip: padding-box;
304
+ border: 1px solid $border-top;
305
+ border-color: $border-top $border-sides $border-bottom;
306
+ box-shadow: inset 0 1px 0 0 $inset-shadow-hover;
307
+ cursor: pointer;
308
+ text-shadow: 0 -1px 1px $text-shadow-hover;
309
+ }
310
+
311
+ &:active:not(:disabled),
312
+ &:focus:not(:disabled) {
313
+ $active-color: adjust-color($base-color, $hue: 4, $saturation: -12%, $lightness: -10%);
314
+ $border-active: adjust-color($base-color, $hue: 6, $saturation: -2.5%, $lightness: -30%);
315
+ $border-bottom-active: adjust-color($base-color, $hue: 11, $saturation: 6%, $lightness: -31%);
316
+ $inset-shadow-active: adjust-color($base-color, $hue: 9, $saturation: 2%, $lightness: -21.5%);
317
+ $text-shadow-active: adjust-color($base-color, $hue: 5, $saturation: -12%, $lightness: -21.5%);
318
+
319
+ @if $grayscale == true {
320
+ $active-color: grayscale($active-color);
321
+ $border-active: grayscale($border-active);
322
+ $border-bottom-active: grayscale($border-bottom-active);
323
+ $inset-shadow-active: grayscale($inset-shadow-active);
324
+ $text-shadow-active: grayscale($text-shadow-active);
325
+ }
326
+
327
+ background: $active-color;
328
+ border: 1px solid $border-active;
329
+ border-bottom: 1px solid $border-bottom-active;
330
+ box-shadow: inset 0 0 6px 3px $inset-shadow-active;
331
+ text-shadow: 0 -1px 1px $text-shadow-active;
332
+ }
333
+ }
334
+
335
+ // Flat Button
336
+ @mixin flat($base-color, $grayscale: false, $textsize: inherit, $padding: 7px 18px) {
337
+ $color: hsl(0, 0, 100%);
338
+
339
+ @if is-light($base-color) {
340
+ $color: hsl(0, 0, 20%);
341
+ }
342
+
343
+ background-color: $base-color;
344
+ border-radius: 3px;
345
+ border: 0;
346
+ color: $color;
347
+ display: inline-block;
348
+ font-size: $textsize;
349
+ font-weight: bold;
350
+ padding: $padding;
351
+ text-decoration: none;
352
+ background-clip: padding-box;
353
+
354
+ &:hover:not(:disabled){
355
+ $base-color-hover: adjust-color($base-color, $saturation: 4%, $lightness: 5%);
356
+
357
+ @if $grayscale == true {
358
+ $base-color-hover: grayscale($base-color-hover);
359
+ }
360
+
361
+ background-color: $base-color-hover;
362
+ cursor: pointer;
363
+ }
364
+
365
+ &:active:not(:disabled),
366
+ &:focus:not(:disabled) {
367
+ $base-color-active: adjust-color($base-color, $saturation: -4%, $lightness: -5%);
368
+
369
+ @if $grayscale == true {
370
+ $base-color-active: grayscale($base-color-active);
371
+ }
372
+
373
+ background-color: $base-color-active;
374
+ cursor: pointer;
375
+ }
376
+ }
377
+
378
+ // Flexible grid
379
+ @function flex-grid($columns, $container-columns: $fg-max-columns) {
380
+ $width: $columns * $fg-column + ($columns - 1) * $fg-gutter;
381
+ $container-width: $container-columns * $fg-column + ($container-columns - 1) * $fg-gutter;
382
+ @return percentage($width / $container-width);
383
+
384
+ @warn "The flex-grid function is deprecated and will be removed in the next major version release";
385
+ }
386
+
387
+ // Flexible gutter
388
+ @function flex-gutter($container-columns: $fg-max-columns, $gutter: $fg-gutter) {
389
+ $container-width: $container-columns * $fg-column + ($container-columns - 1) * $fg-gutter;
390
+ @return percentage($gutter / $container-width);
391
+
392
+ @warn "The flex-gutter function is deprecated and will be removed in the next major version release";
393
+ }
394
+
395
+ @function grid-width($n) {
396
+ @return $n * $gw-column + ($n - 1) * $gw-gutter;
397
+
398
+ @warn "The grid-width function is deprecated and will be removed in the next major version release";
399
+ }
400
+
401
+ @function golden-ratio($value, $increment) {
402
+ @return modular-scale($increment, $value, $ratio: $golden);
403
+
404
+ @warn "The golden-ratio function is deprecated and will be removed in the next major version release. Please use the modular-scale function, instead.";
405
+ }
406
+
407
+ @mixin box-sizing($box) {
408
+ @include prefixer(box-sizing, $box, webkit moz spec);
409
+
410
+ @warn "The box-sizing mixin is deprecated and will be removed in the next major version release. This property can now be used un-prefixed.";
411
+ }
mixins/sass/bourbon/_bourbon.scss ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Bourbon 4.2.7
2
+ // http://bourbon.io
3
+ // Copyright 2011-2015 thoughtbot, inc.
4
+ // MIT License
5
+
6
+ @import "settings/prefixer";
7
+ @import "settings/px-to-em";
8
+ @import "settings/asset-pipeline";
9
+
10
+ @import "functions/assign-inputs";
11
+ @import "functions/contains";
12
+ @import "functions/contains-falsy";
13
+ @import "functions/is-length";
14
+ @import "functions/is-light";
15
+ @import "functions/is-number";
16
+ @import "functions/is-size";
17
+ @import "functions/px-to-em";
18
+ @import "functions/px-to-rem";
19
+ @import "functions/shade";
20
+ @import "functions/strip-units";
21
+ @import "functions/tint";
22
+ @import "functions/transition-property-name";
23
+ @import "functions/unpack";
24
+ @import "functions/modular-scale";
25
+
26
+ @import "helpers/convert-units";
27
+ @import "helpers/directional-values";
28
+ @import "helpers/font-source-declaration";
29
+ @import "helpers/gradient-positions-parser";
30
+ @import "helpers/linear-angle-parser";
31
+ @import "helpers/linear-gradient-parser";
32
+ @import "helpers/linear-positions-parser";
33
+ @import "helpers/linear-side-corner-parser";
34
+ @import "helpers/radial-arg-parser";
35
+ @import "helpers/radial-positions-parser";
36
+ @import "helpers/radial-gradient-parser";
37
+ @import "helpers/render-gradients";
38
+ @import "helpers/shape-size-stripper";
39
+ @import "helpers/str-to-num";
40
+
41
+ @import "css3/animation";
42
+ @import "css3/appearance";
43
+ @import "css3/backface-visibility";
44
+ @import "css3/background";
45
+ @import "css3/background-image";
46
+ @import "css3/border-image";
47
+ @import "css3/calc";
48
+ @import "css3/columns";
49
+ @import "css3/filter";
50
+ @import "css3/flex-box";
51
+ @import "css3/font-face";
52
+ @import "css3/font-feature-settings";
53
+ @import "css3/hidpi-media-query";
54
+ @import "css3/hyphens";
55
+ @import "css3/image-rendering";
56
+ @import "css3/keyframes";
57
+ @import "css3/linear-gradient";
58
+ @import "css3/perspective";
59
+ @import "css3/placeholder";
60
+ @import "css3/radial-gradient";
61
+ @import "css3/selection";
62
+ @import "css3/text-decoration";
63
+ @import "css3/transform";
64
+ @import "css3/transition";
65
+ @import "css3/user-select";
66
+
67
+ @import "addons/border-color";
68
+ @import "addons/border-radius";
69
+ @import "addons/border-style";
70
+ @import "addons/border-width";
71
+ @import "addons/buttons";
72
+ @import "addons/clearfix";
73
+ @import "addons/ellipsis";
74
+ @import "addons/font-stacks";
75
+ @import "addons/hide-text";
76
+ @import "addons/margin";
77
+ @import "addons/padding";
78
+ @import "addons/position";
79
+ @import "addons/prefixer";
80
+ @import "addons/retina-image";
81
+ @import "addons/size";
82
+ @import "addons/text-inputs";
83
+ @import "addons/timing-functions";
84
+ @import "addons/triangle";
85
+ @import "addons/word-wrap";
86
+
87
+ @import "bourbon-deprecated-upcoming";
mixins/sass/bourbon/addons/_border-color.scss ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides a quick method for targeting `border-color` on specific sides of a box. Use a `null` value to “skip” a side.
4
+ ///
5
+ /// @param {Arglist} $vals
6
+ /// List of arguments
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element {
10
+ /// @include border-color(#a60b55 #76cd9c null #e8ae1a);
11
+ /// }
12
+ ///
13
+ /// @example css - CSS Output
14
+ /// .element {
15
+ /// border-left-color: #e8ae1a;
16
+ /// border-right-color: #76cd9c;
17
+ /// border-top-color: #a60b55;
18
+ /// }
19
+ ///
20
+ /// @require {mixin} directional-property
21
+ ///
22
+ /// @output `border-color`
23
+
24
+ @mixin border-color($vals...) {
25
+ @include directional-property(border, color, $vals...);
26
+ }
mixins/sass/bourbon/addons/_border-radius.scss ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides a quick method for targeting `border-radius` on both corners on the side of a box.
4
+ ///
5
+ /// @param {Number} $radii
6
+ /// List of arguments
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element-one {
10
+ /// @include border-top-radius(5px);
11
+ /// }
12
+ ///
13
+ /// .element-two {
14
+ /// @include border-left-radius(3px);
15
+ /// }
16
+ ///
17
+ /// @example css - CSS Output
18
+ /// .element-one {
19
+ /// border-top-left-radius: 5px;
20
+ /// border-top-right-radius: 5px;
21
+ /// }
22
+ ///
23
+ /// .element-two {
24
+ /// border-bottom-left-radius: 3px;
25
+ /// border-top-left-radius: 3px;
26
+ /// }
27
+ ///
28
+ /// @output `border-radius`
29
+
30
+ @mixin border-top-radius($radii) {
31
+ border-top-left-radius: $radii;
32
+ border-top-right-radius: $radii;
33
+ }
34
+
35
+ @mixin border-right-radius($radii) {
36
+ border-bottom-right-radius: $radii;
37
+ border-top-right-radius: $radii;
38
+ }
39
+
40
+ @mixin border-bottom-radius($radii) {
41
+ border-bottom-left-radius: $radii;
42
+ border-bottom-right-radius: $radii;
43
+ }
44
+
45
+ @mixin border-left-radius($radii) {
46
+ border-bottom-left-radius: $radii;
47
+ border-top-left-radius: $radii;
48
+ }
mixins/sass/bourbon/addons/_border-style.scss ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides a quick method for targeting `border-style` on specific sides of a box. Use a `null` value to “skip” a side.
4
+ ///
5
+ /// @param {Arglist} $vals
6
+ /// List of arguments
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element {
10
+ /// @include border-style(dashed null solid);
11
+ /// }
12
+ ///
13
+ /// @example css - CSS Output
14
+ /// .element {
15
+ /// border-bottom-style: solid;
16
+ /// border-top-style: dashed;
17
+ /// }
18
+ ///
19
+ /// @require {mixin} directional-property
20
+ ///
21
+ /// @output `border-style`
22
+
23
+ @mixin border-style($vals...) {
24
+ @include directional-property(border, style, $vals...);
25
+ }
mixins/sass/bourbon/addons/_border-width.scss ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides a quick method for targeting `border-width` on specific sides of a box. Use a `null` value to “skip” a side.
4
+ ///
5
+ /// @param {Arglist} $vals
6
+ /// List of arguments
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element {
10
+ /// @include border-width(1em null 20px);
11
+ /// }
12
+ ///
13
+ /// @example css - CSS Output
14
+ /// .element {
15
+ /// border-bottom-width: 20px;
16
+ /// border-top-width: 1em;
17
+ /// }
18
+ ///
19
+ /// @require {mixin} directional-property
20
+ ///
21
+ /// @output `border-width`
22
+
23
+ @mixin border-width($vals...) {
24
+ @include directional-property(border, width, $vals...);
25
+ }
mixins/sass/bourbon/addons/_buttons.scss ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Generates variables for all buttons. Please note that you must use interpolation on the variable: `#{$all-buttons}`.
4
+ ///
5
+ /// @example scss - Usage
6
+ /// #{$all-buttons} {
7
+ /// background-color: #f00;
8
+ /// }
9
+ ///
10
+ /// #{$all-buttons-focus},
11
+ /// #{$all-buttons-hover} {
12
+ /// background-color: #0f0;
13
+ /// }
14
+ ///
15
+ /// #{$all-buttons-active} {
16
+ /// background-color: #00f;
17
+ /// }
18
+ ///
19
+ /// @example css - CSS Output
20
+ /// button,
21
+ /// input[type="button"],
22
+ /// input[type="reset"],
23
+ /// input[type="submit"] {
24
+ /// background-color: #f00;
25
+ /// }
26
+ ///
27
+ /// button:focus,
28
+ /// input[type="button"]:focus,
29
+ /// input[type="reset"]:focus,
30
+ /// input[type="submit"]:focus,
31
+ /// button:hover,
32
+ /// input[type="button"]:hover,
33
+ /// input[type="reset"]:hover,
34
+ /// input[type="submit"]:hover {
35
+ /// background-color: #0f0;
36
+ /// }
37
+ ///
38
+ /// button:active,
39
+ /// input[type="button"]:active,
40
+ /// input[type="reset"]:active,
41
+ /// input[type="submit"]:active {
42
+ /// background-color: #00f;
43
+ /// }
44
+ ///
45
+ /// @require assign-inputs
46
+ ///
47
+ /// @type List
48
+ ///
49
+ /// @todo Remove double assigned variables (Lines 59–62) in v5.0.0
50
+
51
+ $buttons-list: 'button',
52
+ 'input[type="button"]',
53
+ 'input[type="reset"]',
54
+ 'input[type="submit"]';
55
+
56
+ $all-buttons: assign-inputs($buttons-list);
57
+ $all-buttons-active: assign-inputs($buttons-list, active);
58
+ $all-buttons-focus: assign-inputs($buttons-list, focus);
59
+ $all-buttons-hover: assign-inputs($buttons-list, hover);
60
+
61
+ $all-button-inputs: $all-buttons;
62
+ $all-button-inputs-active: $all-buttons-active;
63
+ $all-button-inputs-focus: $all-buttons-focus;
64
+ $all-button-inputs-hover: $all-buttons-hover;
mixins/sass/bourbon/addons/_clearfix.scss ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides an easy way to include a clearfix for containing floats.
4
+ ///
5
+ /// @link http://cssmojo.com/latest_new_clearfix_so_far/
6
+ ///
7
+ /// @example scss - Usage
8
+ /// .element {
9
+ /// @include clearfix;
10
+ /// }
11
+ ///
12
+ /// @example css - CSS Output
13
+ /// .element::after {
14
+ /// clear: both;
15
+ /// content: "";
16
+ /// display: table;
17
+ /// }
18
+
19
+ @mixin clearfix {
20
+ &::after {
21
+ clear: both;
22
+ content: "";
23
+ display: table;
24
+ }
25
+ }
mixins/sass/bourbon/addons/_ellipsis.scss ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Truncates text and adds an ellipsis to represent overflow.
4
+ ///
5
+ /// @param {Number} $width [100%]
6
+ /// Max-width for the string to respect before being truncated
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element {
10
+ /// @include ellipsis;
11
+ /// }
12
+ ///
13
+ /// @example css - CSS Output
14
+ /// .element {
15
+ /// display: inline-block;
16
+ /// max-width: 100%;
17
+ /// overflow: hidden;
18
+ /// text-overflow: ellipsis;
19
+ /// white-space: nowrap;
20
+ /// word-wrap: normal;
21
+ /// }
22
+
23
+ @mixin ellipsis($width: 100%) {
24
+ display: inline-block;
25
+ max-width: $width;
26
+ overflow: hidden;
27
+ text-overflow: ellipsis;
28
+ white-space: nowrap;
29
+ word-wrap: normal;
30
+ }
mixins/sass/bourbon/addons/_font-stacks.scss ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Georgia font stack.
4
+ ///
5
+ /// @type List
6
+
7
+ $georgia: "Georgia", "Cambria", "Times New Roman", "Times", serif;
8
+
9
+ /// Helvetica font stack.
10
+ ///
11
+ /// @type List
12
+
13
+ $helvetica: "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
14
+
15
+ /// Lucida Grande font stack.
16
+ ///
17
+ /// @type List
18
+
19
+ $lucida-grande: "Lucida Grande", "Tahoma", "Verdana", "Arial", sans-serif;
20
+
21
+ /// Monospace font stack.
22
+ ///
23
+ /// @type List
24
+
25
+ $monospace: "Bitstream Vera Sans Mono", "Consolas", "Courier", monospace;
26
+
27
+ /// Verdana font stack.
28
+ ///
29
+ /// @type List
30
+
31
+ $verdana: "Verdana", "Geneva", sans-serif;
mixins/sass/bourbon/addons/_hide-text.scss ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// Hides the text in an element, commonly used to show an image. Some elements will need block-level styles applied.
2
+ ///
3
+ /// @link http://zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement
4
+ ///
5
+ /// @example scss - Usage
6
+ /// .element {
7
+ /// @include hide-text;
8
+ /// }
9
+ ///
10
+ /// @example css - CSS Output
11
+ /// .element {
12
+ /// overflow: hidden;
13
+ /// text-indent: 101%;
14
+ /// white-space: nowrap;
15
+ /// }
16
+ ///
17
+ /// @todo Remove height argument in v5.0.0
18
+
19
+ @mixin hide-text($height: null) {
20
+ overflow: hidden;
21
+ text-indent: 101%;
22
+ white-space: nowrap;
23
+
24
+ @if $height {
25
+ @warn "The `hide-text` mixin has changed and no longer requires a height. The height argument will no longer be accepted in v5.0.0";
26
+ }
27
+ }
mixins/sass/bourbon/addons/_margin.scss ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides a quick method for targeting `margin` on specific sides of a box. Use a `null` value to “skip” a side.
4
+ ///
5
+ /// @param {Arglist} $vals
6
+ /// List of arguments
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element {
10
+ /// @include margin(null 10px 3em 20vh);
11
+ /// }
12
+ ///
13
+ /// @example css - CSS Output
14
+ /// .element {
15
+ /// margin-bottom: 3em;
16
+ /// margin-left: 20vh;
17
+ /// margin-right: 10px;
18
+ /// }
19
+ ///
20
+ /// @require {mixin} directional-property
21
+ ///
22
+ /// @output `margin`
23
+
24
+ @mixin margin($vals...) {
25
+ @include directional-property(margin, false, $vals...);
26
+ }
mixins/sass/bourbon/addons/_padding.scss ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides a quick method for targeting `padding` on specific sides of a box. Use a `null` value to “skip” a side.
4
+ ///
5
+ /// @param {Arglist} $vals
6
+ /// List of arguments
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element {
10
+ /// @include padding(12vh null 10px 5%);
11
+ /// }
12
+ ///
13
+ /// @example css - CSS Output
14
+ /// .element {
15
+ /// padding-bottom: 10px;
16
+ /// padding-left: 5%;
17
+ /// padding-top: 12vh;
18
+ /// }
19
+ ///
20
+ /// @require {mixin} directional-property
21
+ ///
22
+ /// @output `padding`
23
+
24
+ @mixin padding($vals...) {
25
+ @include directional-property(padding, false, $vals...);
26
+ }
mixins/sass/bourbon/addons/_position.scss ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides a quick method for setting an element’s position. Use a `null` value to “skip” a side.
4
+ ///
5
+ /// @param {Position} $position [relative]
6
+ /// A CSS position value
7
+ ///
8
+ /// @param {Arglist} $coordinates [null null null null]
9
+ /// List of values that correspond to the 4-value syntax for the edges of a box
10
+ ///
11
+ /// @example scss - Usage
12
+ /// .element {
13
+ /// @include position(absolute, 0 null null 10em);
14
+ /// }
15
+ ///
16
+ /// @example css - CSS Output
17
+ /// .element {
18
+ /// left: 10em;
19
+ /// position: absolute;
20
+ /// top: 0;
21
+ /// }
22
+ ///
23
+ /// @require {function} is-length
24
+ /// @require {function} unpack
25
+
26
+ @mixin position($position: relative, $coordinates: null null null null) {
27
+ @if type-of($position) == list {
28
+ $coordinates: $position;
29
+ $position: relative;
30
+ }
31
+
32
+ $coordinates: unpack($coordinates);
33
+
34
+ $offsets: (
35
+ top: nth($coordinates, 1),
36
+ right: nth($coordinates, 2),
37
+ bottom: nth($coordinates, 3),
38
+ left: nth($coordinates, 4)
39
+ );
40
+
41
+ position: $position;
42
+
43
+ @each $offset, $value in $offsets {
44
+ @if is-length($value) {
45
+ #{$offset}: $value;
46
+ }
47
+ }
48
+ }
mixins/sass/bourbon/addons/_prefixer.scss ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// A mixin for generating vendor prefixes on non-standardized properties.
4
+ ///
5
+ /// @param {String} $property
6
+ /// Property to prefix
7
+ ///
8
+ /// @param {*} $value
9
+ /// Value to use
10
+ ///
11
+ /// @param {List} $prefixes
12
+ /// Prefixes to define
13
+ ///
14
+ /// @example scss - Usage
15
+ /// .element {
16
+ /// @include prefixer(border-radius, 10px, webkit ms spec);
17
+ /// }
18
+ ///
19
+ /// @example css - CSS Output
20
+ /// .element {
21
+ /// -webkit-border-radius: 10px;
22
+ /// -moz-border-radius: 10px;
23
+ /// border-radius: 10px;
24
+ /// }
25
+ ///
26
+ /// @require {variable} $prefix-for-webkit
27
+ /// @require {variable} $prefix-for-mozilla
28
+ /// @require {variable} $prefix-for-microsoft
29
+ /// @require {variable} $prefix-for-opera
30
+ /// @require {variable} $prefix-for-spec
31
+
32
+ @mixin prefixer($property, $value, $prefixes) {
33
+ @each $prefix in $prefixes {
34
+ @if $prefix == webkit {
35
+ @if $prefix-for-webkit {
36
+ -webkit-#{$property}: $value;
37
+ }
38
+ } @else if $prefix == moz {
39
+ @if $prefix-for-mozilla {
40
+ -moz-#{$property}: $value;
41
+ }
42
+ } @else if $prefix == ms {
43
+ @if $prefix-for-microsoft {
44
+ -ms-#{$property}: $value;
45
+ }
46
+ } @else if $prefix == o {
47
+ @if $prefix-for-opera {
48
+ -o-#{$property}: $value;
49
+ }
50
+ } @else if $prefix == spec {
51
+ @if $prefix-for-spec {
52
+ #{$property}: $value;
53
+ }
54
+ } @else {
55
+ @warn "Unrecognized prefix: #{$prefix}";
56
+ }
57
+ }
58
+ }
59
+
60
+ @mixin disable-prefix-for-all() {
61
+ $prefix-for-webkit: false !global;
62
+ $prefix-for-mozilla: false !global;
63
+ $prefix-for-microsoft: false !global;
64
+ $prefix-for-opera: false !global;
65
+ $prefix-for-spec: false !global;
66
+ }
mixins/sass/bourbon/addons/_retina-image.scss ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin retina-image($filename, $background-size, $extension: png, $retina-filename: null, $retina-suffix: _2x, $asset-pipeline: $asset-pipeline) {
2
+ @if $asset-pipeline {
3
+ background-image: image-url("#{$filename}.#{$extension}");
4
+ } @else {
5
+ background-image: url("#{$filename}.#{$extension}");
6
+ }
7
+
8
+ @include hidpi {
9
+ @if $asset-pipeline {
10
+ @if $retina-filename {
11
+ background-image: image-url("#{$retina-filename}.#{$extension}");
12
+ } @else {
13
+ background-image: image-url("#{$filename}#{$retina-suffix}.#{$extension}");
14
+ }
15
+ } @else {
16
+ @if $retina-filename {
17
+ background-image: url("#{$retina-filename}.#{$extension}");
18
+ } @else {
19
+ background-image: url("#{$filename}#{$retina-suffix}.#{$extension}");
20
+ }
21
+ }
22
+
23
+ background-size: $background-size;
24
+ }
25
+ }
mixins/sass/bourbon/addons/_size.scss ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Sets the `width` and `height` of the element.
4
+ ///
5
+ /// @param {List} $size
6
+ /// A list of at most 2 size values.
7
+ ///
8
+ /// If there is only a single value in `$size` it is used for both width and height. All units are supported.
9
+ ///
10
+ /// @example scss - Usage
11
+ /// .first-element {
12
+ /// @include size(2em);
13
+ /// }
14
+ ///
15
+ /// .second-element {
16
+ /// @include size(auto 10em);
17
+ /// }
18
+ ///
19
+ /// @example css - CSS Output
20
+ /// .first-element {
21
+ /// width: 2em;
22
+ /// height: 2em;
23
+ /// }
24
+ ///
25
+ /// .second-element {
26
+ /// width: auto;
27
+ /// height: 10em;
28
+ /// }
29
+ ///
30
+ /// @todo Refactor in 5.0.0 to use a comma-separated argument
31
+
32
+ @mixin size($value) {
33
+ $width: nth($value, 1);
34
+ $height: $width;
35
+
36
+ @if length($value) > 1 {
37
+ $height: nth($value, 2);
38
+ }
39
+
40
+ @if is-size($height) {
41
+ height: $height;
42
+ } @else {
43
+ @warn "`#{$height}` is not a valid length for the `$height` parameter in the `size` mixin.";
44
+ }
45
+
46
+ @if is-size($width) {
47
+ width: $width;
48
+ } @else {
49
+ @warn "`#{$width}` is not a valid length for the `$width` parameter in the `size` mixin.";
50
+ }
51
+ }
mixins/sass/bourbon/addons/_text-inputs.scss ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Generates variables for all text-based inputs. Please note that you must use interpolation on the variable: `#{$all-text-inputs}`.
4
+ ///
5
+ /// @example scss - Usage
6
+ /// #{$all-text-inputs} {
7
+ /// border: 1px solid #f00;
8
+ /// }
9
+ ///
10
+ /// #{$all-text-inputs-focus},
11
+ /// #{$all-text-inputs-hover} {
12
+ /// border: 1px solid #0f0;
13
+ /// }
14
+ ///
15
+ /// #{$all-text-inputs-active} {
16
+ /// border: 1px solid #00f;
17
+ /// }
18
+ ///
19
+ /// @example css - CSS Output
20
+ /// input[type="color"],
21
+ /// input[type="date"],
22
+ /// input[type="datetime"],
23
+ /// input[type="datetime-local"],
24
+ /// input[type="email"],
25
+ /// input[type="month"],
26
+ /// input[type="number"],
27
+ /// input[type="password"],
28
+ /// input[type="search"],
29
+ /// input[type="tel"],
30
+ /// input[type="text"],
31
+ /// input[type="time"],
32
+ /// input[type="url"],
33
+ /// input[type="week"],
34
+ /// textarea {
35
+ /// border: 1px solid #f00;
36
+ /// }
37
+ ///
38
+ /// input[type="color"]:focus,
39
+ /// input[type="date"]:focus,
40
+ /// input[type="datetime"]:focus,
41
+ /// input[type="datetime-local"]:focus,
42
+ /// input[type="email"]:focus,
43
+ /// input[type="month"]:focus,
44
+ /// input[type="number"]:focus,
45
+ /// input[type="password"]:focus,
46
+ /// input[type="search"]:focus,
47
+ /// input[type="tel"]:focus,
48
+ /// input[type="text"]:focus,
49
+ /// input[type="time"]:focus,
50
+ /// input[type="url"]:focus,
51
+ /// input[type="week"]:focus,
52
+ /// textarea:focus,
53
+ /// input[type="color"]:hover,
54
+ /// input[type="date"]:hover,
55
+ /// input[type="datetime"]:hover,
56
+ /// input[type="datetime-local"]:hover,
57
+ /// input[type="email"]:hover,
58
+ /// input[type="month"]:hover,
59
+ /// input[type="number"]:hover,
60
+ /// input[type="password"]:hover,
61
+ /// input[type="search"]:hover,
62
+ /// input[type="tel"]:hover,
63
+ /// input[type="text"]:hover,
64
+ /// input[type="time"]:hover,
65
+ /// input[type="url"]:hover,
66
+ /// input[type="week"]:hover,
67
+ /// textarea:hover {
68
+ /// border: 1px solid #0f0;
69
+ /// }
70
+ ///
71
+ /// input[type="color"]:active,
72
+ /// input[type="date"]:active,
73
+ /// input[type="datetime"]:active,
74
+ /// input[type="datetime-local"]:active,
75
+ /// input[type="email"]:active,
76
+ /// input[type="month"]:active,
77
+ /// input[type="number"]:active,
78
+ /// input[type="password"]:active,
79
+ /// input[type="search"]:active,
80
+ /// input[type="tel"]:active,
81
+ /// input[type="text"]:active,
82
+ /// input[type="time"]:active,
83
+ /// input[type="url"]:active,
84
+ /// input[type="week"]:active,
85
+ /// textarea:active {
86
+ /// border: 1px solid #00f;
87
+ /// }
88
+ ///
89
+ /// @require assign-inputs
90
+ ///
91
+ /// @type List
92
+
93
+ $text-inputs-list: 'input[type="color"]',
94
+ 'input[type="date"]',
95
+ 'input[type="datetime"]',
96
+ 'input[type="datetime-local"]',
97
+ 'input[type="email"]',
98
+ 'input[type="month"]',
99
+ 'input[type="number"]',
100
+ 'input[type="password"]',
101
+ 'input[type="search"]',
102
+ 'input[type="tel"]',
103
+ 'input[type="text"]',
104
+ 'input[type="time"]',
105
+ 'input[type="url"]',
106
+ 'input[type="week"]',
107
+ 'input:not([type])',
108
+ 'textarea';
109
+
110
+ $all-text-inputs: assign-inputs($text-inputs-list);
111
+ $all-text-inputs-active: assign-inputs($text-inputs-list, active);
112
+ $all-text-inputs-focus: assign-inputs($text-inputs-list, focus);
113
+ $all-text-inputs-hover: assign-inputs($text-inputs-list, hover);
mixins/sass/bourbon/addons/_timing-functions.scss ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// CSS cubic-bezier timing functions. Timing functions courtesy of jquery.easie (github.com/jaukia/easie)
4
+ ///
5
+ /// Timing functions are the same as demoed here: http://jqueryui.com/resources/demos/effect/easing.html
6
+ ///
7
+ /// @type cubic-bezier
8
+
9
+ $ease-in-quad: cubic-bezier(0.550, 0.085, 0.680, 0.530);
10
+ $ease-in-cubic: cubic-bezier(0.550, 0.055, 0.675, 0.190);
11
+ $ease-in-quart: cubic-bezier(0.895, 0.030, 0.685, 0.220);
12
+ $ease-in-quint: cubic-bezier(0.755, 0.050, 0.855, 0.060);
13
+ $ease-in-sine: cubic-bezier(0.470, 0.000, 0.745, 0.715);
14
+ $ease-in-expo: cubic-bezier(0.950, 0.050, 0.795, 0.035);
15
+ $ease-in-circ: cubic-bezier(0.600, 0.040, 0.980, 0.335);
16
+ $ease-in-back: cubic-bezier(0.600, -0.280, 0.735, 0.045);
17
+
18
+ $ease-out-quad: cubic-bezier(0.250, 0.460, 0.450, 0.940);
19
+ $ease-out-cubic: cubic-bezier(0.215, 0.610, 0.355, 1.000);
20
+ $ease-out-quart: cubic-bezier(0.165, 0.840, 0.440, 1.000);
21
+ $ease-out-quint: cubic-bezier(0.230, 1.000, 0.320, 1.000);
22
+ $ease-out-sine: cubic-bezier(0.390, 0.575, 0.565, 1.000);
23
+ $ease-out-expo: cubic-bezier(0.190, 1.000, 0.220, 1.000);
24
+ $ease-out-circ: cubic-bezier(0.075, 0.820, 0.165, 1.000);
25
+ $ease-out-back: cubic-bezier(0.175, 0.885, 0.320, 1.275);
26
+
27
+ $ease-in-out-quad: cubic-bezier(0.455, 0.030, 0.515, 0.955);
28
+ $ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1.000);
29
+ $ease-in-out-quart: cubic-bezier(0.770, 0.000, 0.175, 1.000);
30
+ $ease-in-out-quint: cubic-bezier(0.860, 0.000, 0.070, 1.000);
31
+ $ease-in-out-sine: cubic-bezier(0.445, 0.050, 0.550, 0.950);
32
+ $ease-in-out-expo: cubic-bezier(1.000, 0.000, 0.000, 1.000);
33
+ $ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.150, 0.860);
34
+ $ease-in-out-back: cubic-bezier(0.680, -0.550, 0.265, 1.550);
mixins/sass/bourbon/addons/_triangle.scss ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin triangle($size, $color, $direction) {
2
+ $width: nth($size, 1);
3
+ $height: nth($size, length($size));
4
+ $foreground-color: nth($color, 1);
5
+ $background-color: if(length($color) == 2, nth($color, 2), transparent);
6
+ height: 0;
7
+ width: 0;
8
+
9
+ @if ($direction == up) or ($direction == down) or ($direction == right) or ($direction == left) {
10
+ $width: $width / 2;
11
+ $height: if(length($size) > 1, $height, $height/2);
12
+
13
+ @if $direction == up {
14
+ border-bottom: $height solid $foreground-color;
15
+ border-left: $width solid $background-color;
16
+ border-right: $width solid $background-color;
17
+ } @else if $direction == right {
18
+ border-bottom: $width solid $background-color;
19
+ border-left: $height solid $foreground-color;
20
+ border-top: $width solid $background-color;
21
+ } @else if $direction == down {
22
+ border-left: $width solid $background-color;
23
+ border-right: $width solid $background-color;
24
+ border-top: $height solid $foreground-color;
25
+ } @else if $direction == left {
26
+ border-bottom: $width solid $background-color;
27
+ border-right: $height solid $foreground-color;
28
+ border-top: $width solid $background-color;
29
+ }
30
+ } @else if ($direction == up-right) or ($direction == up-left) {
31
+ border-top: $height solid $foreground-color;
32
+
33
+ @if $direction == up-right {
34
+ border-left: $width solid $background-color;
35
+ } @else if $direction == up-left {
36
+ border-right: $width solid $background-color;
37
+ }
38
+ } @else if ($direction == down-right) or ($direction == down-left) {
39
+ border-bottom: $height solid $foreground-color;
40
+
41
+ @if $direction == down-right {
42
+ border-left: $width solid $background-color;
43
+ } @else if $direction == down-left {
44
+ border-right: $width solid $background-color;
45
+ }
46
+ } @else if ($direction == inset-up) {
47
+ border-color: $background-color $background-color $foreground-color;
48
+ border-style: solid;
49
+ border-width: $height $width;
50
+ } @else if ($direction == inset-down) {
51
+ border-color: $foreground-color $background-color $background-color;
52
+ border-style: solid;
53
+ border-width: $height $width;
54
+ } @else if ($direction == inset-right) {
55
+ border-color: $background-color $background-color $background-color $foreground-color;
56
+ border-style: solid;
57
+ border-width: $width $height;
58
+ } @else if ($direction == inset-left) {
59
+ border-color: $background-color $foreground-color $background-color $background-color;
60
+ border-style: solid;
61
+ border-width: $width $height;
62
+ }
63
+ }
mixins/sass/bourbon/addons/_word-wrap.scss ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Provides an easy way to change the `word-wrap` property.
4
+ ///
5
+ /// @param {String} $wrap [break-word]
6
+ /// Value for the `word-break` property.
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .wrapper {
10
+ /// @include word-wrap(break-word);
11
+ /// }
12
+ ///
13
+ /// @example css - CSS Output
14
+ /// .wrapper {
15
+ /// overflow-wrap: break-word;
16
+ /// word-break: break-all;
17
+ /// word-wrap: break-word;
18
+ /// }
19
+
20
+ @mixin word-wrap($wrap: break-word) {
21
+ overflow-wrap: $wrap;
22
+ word-wrap: $wrap;
23
+
24
+ @if $wrap == break-word {
25
+ word-break: break-all;
26
+ } @else {
27
+ word-break: $wrap;
28
+ }
29
+ }
mixins/sass/bourbon/css3/_animation.scss ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // http://www.w3.org/TR/css3-animations/#the-animation-name-property-
2
+ // Each of these mixins support comma separated lists of values, which allows different transitions for individual properties to be described in a single style rule. Each value in the list corresponds to the value at that same position in the other properties.
3
+
4
+ @mixin animation($animations...) {
5
+ @include prefixer(animation, $animations, webkit moz spec);
6
+ }
7
+
8
+ @mixin animation-name($names...) {
9
+ @include prefixer(animation-name, $names, webkit moz spec);
10
+ }
11
+
12
+ @mixin animation-duration($times...) {
13
+ @include prefixer(animation-duration, $times, webkit moz spec);
14
+ }
15
+
16
+ @mixin animation-timing-function($motions...) {
17
+ // ease | linear | ease-in | ease-out | ease-in-out
18
+ @include prefixer(animation-timing-function, $motions, webkit moz spec);
19
+ }
20
+
21
+ @mixin animation-iteration-count($values...) {
22
+ // infinite | <number>
23
+ @include prefixer(animation-iteration-count, $values, webkit moz spec);
24
+ }
25
+
26
+ @mixin animation-direction($directions...) {
27
+ // normal | alternate
28
+ @include prefixer(animation-direction, $directions, webkit moz spec);
29
+ }
30
+
31
+ @mixin animation-play-state($states...) {
32
+ // running | paused
33
+ @include prefixer(animation-play-state, $states, webkit moz spec);
34
+ }
35
+
36
+ @mixin animation-delay($times...) {
37
+ @include prefixer(animation-delay, $times, webkit moz spec);
38
+ }
39
+
40
+ @mixin animation-fill-mode($modes...) {
41
+ // none | forwards | backwards | both
42
+ @include prefixer(animation-fill-mode, $modes, webkit moz spec);
43
+ }
mixins/sass/bourbon/css3/_appearance.scss ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ @mixin appearance($value) {
2
+ @include prefixer(appearance, $value, webkit moz ms o spec);
3
+ }
mixins/sass/bourbon/css3/_backface-visibility.scss ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ @mixin backface-visibility($visibility) {
2
+ @include prefixer(backface-visibility, $visibility, webkit spec);
3
+ }
mixins/sass/bourbon/css3/_background-image.scss ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //************************************************************************//
2
+ // Background-image property for adding multiple background images with
3
+ // gradients, or for stringing multiple gradients together.
4
+ //************************************************************************//
5
+
6
+ @mixin background-image($images...) {
7
+ $webkit-images: ();
8
+ $spec-images: ();
9
+
10
+ @each $image in $images {
11
+ $webkit-image: ();
12
+ $spec-image: ();
13
+
14
+ @if (type-of($image) == string) {
15
+ $url-str: str-slice($image, 1, 3);
16
+ $gradient-type: str-slice($image, 1, 6);
17
+
18
+ @if $url-str == "url" {
19
+ $webkit-image: $image;
20
+ $spec-image: $image;
21
+ }
22
+
23
+ @else if $gradient-type == "linear" {
24
+ $gradients: _linear-gradient-parser($image);
25
+ $webkit-image: map-get($gradients, webkit-image);
26
+ $spec-image: map-get($gradients, spec-image);
27
+ }
28
+
29
+ @else if $gradient-type == "radial" {
30
+ $gradients: _radial-gradient-parser($image);
31
+ $webkit-image: map-get($gradients, webkit-image);
32
+ $spec-image: map-get($gradients, spec-image);
33
+ }
34
+ }
35
+
36
+ $webkit-images: append($webkit-images, $webkit-image, comma);
37
+ $spec-images: append($spec-images, $spec-image, comma);
38
+ }
39
+
40
+ background-image: $webkit-images;
41
+ background-image: $spec-images;
42
+ }
mixins/sass/bourbon/css3/_background.scss ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //************************************************************************//
2
+ // Background property for adding multiple backgrounds using shorthand
3
+ // notation.
4
+ //************************************************************************//
5
+
6
+ @mixin background($backgrounds...) {
7
+ $webkit-backgrounds: ();
8
+ $spec-backgrounds: ();
9
+
10
+ @each $background in $backgrounds {
11
+ $webkit-background: ();
12
+ $spec-background: ();
13
+ $background-type: type-of($background);
14
+
15
+ @if $background-type == string or $background-type == list {
16
+ $background-str: if($background-type == list, nth($background, 1), $background);
17
+
18
+ $url-str: str-slice($background-str, 1, 3);
19
+ $gradient-type: str-slice($background-str, 1, 6);
20
+
21
+ @if $url-str == "url" {
22
+ $webkit-background: $background;
23
+ $spec-background: $background;
24
+ }
25
+
26
+ @else if $gradient-type == "linear" {
27
+ $gradients: _linear-gradient-parser("#{$background}");
28
+ $webkit-background: map-get($gradients, webkit-image);
29
+ $spec-background: map-get($gradients, spec-image);
30
+ }
31
+
32
+ @else if $gradient-type == "radial" {
33
+ $gradients: _radial-gradient-parser("#{$background}");
34
+ $webkit-background: map-get($gradients, webkit-image);
35
+ $spec-background: map-get($gradients, spec-image);
36
+ }
37
+
38
+ @else {
39
+ $webkit-background: $background;
40
+ $spec-background: $background;
41
+ }
42
+ }
43
+
44
+ @else {
45
+ $webkit-background: $background;
46
+ $spec-background: $background;
47
+ }
48
+
49
+ $webkit-backgrounds: append($webkit-backgrounds, $webkit-background, comma);
50
+ $spec-backgrounds: append($spec-backgrounds, $spec-background, comma);
51
+ }
52
+
53
+ background: $webkit-backgrounds;
54
+ background: $spec-backgrounds;
55
+ }
mixins/sass/bourbon/css3/_border-image.scss ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin border-image($borders...) {
2
+ $webkit-borders: ();
3
+ $spec-borders: ();
4
+
5
+ @each $border in $borders {
6
+ $webkit-border: ();
7
+ $spec-border: ();
8
+ $border-type: type-of($border);
9
+
10
+ @if $border-type == string or list {
11
+ $border-str: if($border-type == list, nth($border, 1), $border);
12
+
13
+ $url-str: str-slice($border-str, 1, 3);
14
+ $gradient-type: str-slice($border-str, 1, 6);
15
+
16
+ @if $url-str == "url" {
17
+ $webkit-border: $border;
18
+ $spec-border: $border;
19
+ }
20
+
21
+ @else if $gradient-type == "linear" {
22
+ $gradients: _linear-gradient-parser("#{$border}");
23
+ $webkit-border: map-get($gradients, webkit-image);
24
+ $spec-border: map-get($gradients, spec-image);
25
+ }
26
+
27
+ @else if $gradient-type == "radial" {
28
+ $gradients: _radial-gradient-parser("#{$border}");
29
+ $webkit-border: map-get($gradients, webkit-image);
30
+ $spec-border: map-get($gradients, spec-image);
31
+ }
32
+
33
+ @else {
34
+ $webkit-border: $border;
35
+ $spec-border: $border;
36
+ }
37
+ }
38
+
39
+ @else {
40
+ $webkit-border: $border;
41
+ $spec-border: $border;
42
+ }
43
+
44
+ $webkit-borders: append($webkit-borders, $webkit-border, comma);
45
+ $spec-borders: append($spec-borders, $spec-border, comma);
46
+ }
47
+
48
+ -webkit-border-image: $webkit-borders;
49
+ border-image: $spec-borders;
50
+ border-style: solid;
51
+ }
52
+
53
+ //Examples:
54
+ // @include border-image(url("image.png"));
55
+ // @include border-image(url("image.png") 20 stretch);
56
+ // @include border-image(linear-gradient(45deg, orange, yellow));
57
+ // @include border-image(linear-gradient(45deg, orange, yellow) stretch);
58
+ // @include border-image(linear-gradient(45deg, orange, yellow) 20 30 40 50 stretch round);
59
+ // @include border-image(radial-gradient(top, cover, orange, yellow, orange));
mixins/sass/bourbon/css3/_calc.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @mixin calc($property, $value) {
2
+ #{$property}: -webkit-calc(#{$value});
3
+ #{$property}: calc(#{$value});
4
+ }
mixins/sass/bourbon/css3/_columns.scss ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin columns($arg: auto) {
2
+ // <column-count> || <column-width>
3
+ @include prefixer(columns, $arg, webkit moz spec);
4
+ }
5
+
6
+ @mixin column-count($int: auto) {
7
+ // auto || integer
8
+ @include prefixer(column-count, $int, webkit moz spec);
9
+ }
10
+
11
+ @mixin column-gap($length: normal) {
12
+ // normal || length
13
+ @include prefixer(column-gap, $length, webkit moz spec);
14
+ }
15
+
16
+ @mixin column-fill($arg: auto) {
17
+ // auto || length
18
+ @include prefixer(column-fill, $arg, webkit moz spec);
19
+ }
20
+
21
+ @mixin column-rule($arg) {
22
+ // <border-width> || <border-style> || <color>
23
+ @include prefixer(column-rule, $arg, webkit moz spec);
24
+ }
25
+
26
+ @mixin column-rule-color($color) {
27
+ @include prefixer(column-rule-color, $color, webkit moz spec);
28
+ }
29
+
30
+ @mixin column-rule-style($style: none) {
31
+ // none | hidden | dashed | dotted | double | groove | inset | inset | outset | ridge | solid
32
+ @include prefixer(column-rule-style, $style, webkit moz spec);
33
+ }
34
+
35
+ @mixin column-rule-width ($width: none) {
36
+ @include prefixer(column-rule-width, $width, webkit moz spec);
37
+ }
38
+
39
+ @mixin column-span($arg: none) {
40
+ // none || all
41
+ @include prefixer(column-span, $arg, webkit moz spec);
42
+ }
43
+
44
+ @mixin column-width($length: auto) {
45
+ // auto || length
46
+ @include prefixer(column-width, $length, webkit moz spec);
47
+ }
mixins/sass/bourbon/css3/_filter.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @mixin filter($function: none) {
2
+ // <filter-function> [<filter-function]* | none
3
+ @include prefixer(filter, $function, webkit spec);
4
+ }
mixins/sass/bourbon/css3/_flex-box.scss ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CSS3 Flexible Box Model and property defaults
2
+
3
+ // Custom shorthand notation for flexbox
4
+ @mixin box($orient: inline-axis, $pack: start, $align: stretch) {
5
+ @include display-box;
6
+ @include box-orient($orient);
7
+ @include box-pack($pack);
8
+ @include box-align($align);
9
+ }
10
+
11
+ @mixin display-box {
12
+ display: -webkit-box;
13
+ display: -moz-box;
14
+ display: -ms-flexbox; // IE 10
15
+ display: box;
16
+ }
17
+
18
+ @mixin box-orient($orient: inline-axis) {
19
+ // horizontal|vertical|inline-axis|block-axis|inherit
20
+ @include prefixer(box-orient, $orient, webkit moz spec);
21
+ }
22
+
23
+ @mixin box-pack($pack: start) {
24
+ // start|end|center|justify
25
+ @include prefixer(box-pack, $pack, webkit moz spec);
26
+ -ms-flex-pack: $pack; // IE 10
27
+ }
28
+
29
+ @mixin box-align($align: stretch) {
30
+ // start|end|center|baseline|stretch
31
+ @include prefixer(box-align, $align, webkit moz spec);
32
+ -ms-flex-align: $align; // IE 10
33
+ }
34
+
35
+ @mixin box-direction($direction: normal) {
36
+ // normal|reverse|inherit
37
+ @include prefixer(box-direction, $direction, webkit moz spec);
38
+ -ms-flex-direction: $direction; // IE 10
39
+ }
40
+
41
+ @mixin box-lines($lines: single) {
42
+ // single|multiple
43
+ @include prefixer(box-lines, $lines, webkit moz spec);
44
+ }
45
+
46
+ @mixin box-ordinal-group($int: 1) {
47
+ @include prefixer(box-ordinal-group, $int, webkit moz spec);
48
+ -ms-flex-order: $int; // IE 10
49
+ }
50
+
51
+ @mixin box-flex($value: 0) {
52
+ @include prefixer(box-flex, $value, webkit moz spec);
53
+ -ms-flex: $value; // IE 10
54
+ }
55
+
56
+ @mixin box-flex-group($int: 1) {
57
+ @include prefixer(box-flex-group, $int, webkit moz spec);
58
+ }
59
+
60
+ // CSS3 Flexible Box Model and property defaults
61
+ // Unified attributes for 2009, 2011, and 2012 flavours.
62
+
63
+ // 2009 - display (box | inline-box)
64
+ // 2011 - display (flexbox | inline-flexbox)
65
+ // 2012 - display (flex | inline-flex)
66
+ @mixin display($value) {
67
+ // flex | inline-flex
68
+ @if $value == "flex" {
69
+ // 2009
70
+ display: -webkit-box;
71
+ display: -moz-box;
72
+ display: box;
73
+
74
+ // 2012
75
+ display: -webkit-flex;
76
+ display: -moz-flex;
77
+ display: -ms-flexbox; // 2011 (IE 10)
78
+ display: flex;
79
+ } @else if $value == "inline-flex" {
80
+ display: -webkit-inline-box;
81
+ display: -moz-inline-box;
82
+ display: inline-box;
83
+
84
+ display: -webkit-inline-flex;
85
+ display: -moz-inline-flex;
86
+ display: -ms-inline-flexbox;
87
+ display: inline-flex;
88
+ } @else {
89
+ display: $value;
90
+ }
91
+ }
92
+
93
+ // 2009 - box-flex (integer)
94
+ // 2011 - flex (decimal | width decimal)
95
+ // 2012 - flex (integer integer width)
96
+ @mixin flex($value) {
97
+
98
+ // Grab flex-grow for older browsers.
99
+ $flex-grow: nth($value, 1);
100
+
101
+ // 2009
102
+ @include prefixer(box-flex, $flex-grow, webkit moz spec);
103
+
104
+ // 2011 (IE 10), 2012
105
+ @include prefixer(flex, $value, webkit moz ms spec);
106
+ }
107
+
108
+ // 2009 - box-orient ( horizontal | vertical | inline-axis | block-axis)
109
+ // - box-direction (normal | reverse)
110
+ // 2011 - flex-direction (row | row-reverse | column | column-reverse)
111
+ // 2012 - flex-direction (row | row-reverse | column | column-reverse)
112
+ @mixin flex-direction($value: row) {
113
+
114
+ // Alt values.
115
+ $value-2009: $value;
116
+ $value-2011: $value;
117
+ $direction: normal;
118
+
119
+ @if $value == row {
120
+ $value-2009: horizontal;
121
+ } @else if $value == "row-reverse" {
122
+ $value-2009: horizontal;
123
+ $direction: reverse;
124
+ } @else if $value == column {
125
+ $value-2009: vertical;
126
+ } @else if $value == "column-reverse" {
127
+ $value-2009: vertical;
128
+ $direction: reverse;
129
+ }
130
+
131
+ // 2009
132
+ @include prefixer(box-orient, $value-2009, webkit moz spec);
133
+ @include prefixer(box-direction, $direction, webkit moz spec);
134
+
135
+ // 2012
136
+ @include prefixer(flex-direction, $value, webkit moz spec);
137
+
138
+ // 2011 (IE 10)
139
+ -ms-flex-direction: $value;
140
+ }
141
+
142
+ // 2009 - box-lines (single | multiple)
143
+ // 2011 - flex-wrap (nowrap | wrap | wrap-reverse)
144
+ // 2012 - flex-wrap (nowrap | wrap | wrap-reverse)
145
+ @mixin flex-wrap($value: nowrap) {
146
+ // Alt values
147
+ $alt-value: $value;
148
+ @if $value == nowrap {
149
+ $alt-value: single;
150
+ } @else if $value == wrap {
151
+ $alt-value: multiple;
152
+ } @else if $value == "wrap-reverse" {
153
+ $alt-value: multiple;
154
+ }
155
+
156
+ @include prefixer(box-lines, $alt-value, webkit moz spec);
157
+ @include prefixer(flex-wrap, $value, webkit moz ms spec);
158
+ }
159
+
160
+ // 2009 - TODO: parse values into flex-direction/flex-wrap
161
+ // 2011 - TODO: parse values into flex-direction/flex-wrap
162
+ // 2012 - flex-flow (flex-direction || flex-wrap)
163
+ @mixin flex-flow($value) {
164
+ @include prefixer(flex-flow, $value, webkit moz spec);
165
+ }
166
+
167
+ // 2009 - box-ordinal-group (integer)
168
+ // 2011 - flex-order (integer)
169
+ // 2012 - order (integer)
170
+ @mixin order($int: 0) {
171
+ // 2009
172
+ @include prefixer(box-ordinal-group, $int, webkit moz spec);
173
+
174
+ // 2012
175
+ @include prefixer(order, $int, webkit moz spec);
176
+
177
+ // 2011 (IE 10)
178
+ -ms-flex-order: $int;
179
+ }
180
+
181
+ // 2012 - flex-grow (number)
182
+ @mixin flex-grow($number: 0) {
183
+ @include prefixer(flex-grow, $number, webkit moz spec);
184
+ -ms-flex-positive: $number;
185
+ }
186
+
187
+ // 2012 - flex-shrink (number)
188
+ @mixin flex-shrink($number: 1) {
189
+ @include prefixer(flex-shrink, $number, webkit moz spec);
190
+ -ms-flex-negative: $number;
191
+ }
192
+
193
+ // 2012 - flex-basis (number)
194
+ @mixin flex-basis($width: auto) {
195
+ @include prefixer(flex-basis, $width, webkit moz spec);
196
+ -ms-flex-preferred-size: $width;
197
+ }
198
+
199
+ // 2009 - box-pack (start | end | center | justify)
200
+ // 2011 - flex-pack (start | end | center | justify)
201
+ // 2012 - justify-content (flex-start | flex-end | center | space-between | space-around)
202
+ @mixin justify-content($value: flex-start) {
203
+
204
+ // Alt values.
205
+ $alt-value: $value;
206
+ @if $value == "flex-start" {
207
+ $alt-value: start;
208
+ } @else if $value == "flex-end" {
209
+ $alt-value: end;
210
+ } @else if $value == "space-between" {
211
+ $alt-value: justify;
212
+ } @else if $value == "space-around" {
213
+ $alt-value: distribute;
214
+ }
215
+
216
+ // 2009
217
+ @include prefixer(box-pack, $alt-value, webkit moz spec);
218
+
219
+ // 2012
220
+ @include prefixer(justify-content, $value, webkit moz ms o spec);
221
+
222
+ // 2011 (IE 10)
223
+ -ms-flex-pack: $alt-value;
224
+ }
225
+
226
+ // 2009 - box-align (start | end | center | baseline | stretch)
227
+ // 2011 - flex-align (start | end | center | baseline | stretch)
228
+ // 2012 - align-items (flex-start | flex-end | center | baseline | stretch)
229
+ @mixin align-items($value: stretch) {
230
+
231
+ $alt-value: $value;
232
+
233
+ @if $value == "flex-start" {
234
+ $alt-value: start;
235
+ } @else if $value == "flex-end" {
236
+ $alt-value: end;
237
+ }
238
+
239
+ // 2009
240
+ @include prefixer(box-align, $alt-value, webkit moz spec);
241
+
242
+ // 2012
243
+ @include prefixer(align-items, $value, webkit moz ms o spec);
244
+
245
+ // 2011 (IE 10)
246
+ -ms-flex-align: $alt-value;
247
+ }
248
+
249
+ // 2011 - flex-item-align (auto | start | end | center | baseline | stretch)
250
+ // 2012 - align-self (auto | flex-start | flex-end | center | baseline | stretch)
251
+ @mixin align-self($value: auto) {
252
+
253
+ $value-2011: $value;
254
+ @if $value == "flex-start" {
255
+ $value-2011: start;
256
+ } @else if $value == "flex-end" {
257
+ $value-2011: end;
258
+ }
259
+
260
+ // 2012
261
+ @include prefixer(align-self, $value, webkit moz spec);
262
+
263
+ // 2011 (IE 10)
264
+ -ms-flex-item-align: $value-2011;
265
+ }
266
+
267
+ // 2011 - flex-line-pack (start | end | center | justify | distribute | stretch)
268
+ // 2012 - align-content (flex-start | flex-end | center | space-between | space-around | stretch)
269
+ @mixin align-content($value: stretch) {
270
+
271
+ $value-2011: $value;
272
+ @if $value == "flex-start" {
273
+ $value-2011: start;
274
+ } @else if $value == "flex-end" {
275
+ $value-2011: end;
276
+ } @else if $value == "space-between" {
277
+ $value-2011: justify;
278
+ } @else if $value == "space-around" {
279
+ $value-2011: distribute;
280
+ }
281
+
282
+ // 2012
283
+ @include prefixer(align-content, $value, webkit moz spec);
284
+
285
+ // 2011 (IE 10)
286
+ -ms-flex-line-pack: $value-2011;
287
+ }
mixins/sass/bourbon/css3/_font-face.scss ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin font-face(
2
+ $font-family,
3
+ $file-path,
4
+ $weight: normal,
5
+ $style: normal,
6
+ $asset-pipeline: $asset-pipeline,
7
+ $file-formats: eot woff2 woff ttf svg) {
8
+
9
+ $font-url-prefix: font-url-prefixer($asset-pipeline);
10
+
11
+ @font-face {
12
+ font-family: $font-family;
13
+ font-style: $style;
14
+ font-weight: $weight;
15
+
16
+ src: font-source-declaration(
17
+ $font-family,
18
+ $file-path,
19
+ $asset-pipeline,
20
+ $file-formats,
21
+ $font-url-prefix
22
+ );
23
+ }
24
+ }
mixins/sass/bourbon/css3/_font-feature-settings.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @mixin font-feature-settings($settings...) {
2
+ @if length($settings) == 0 { $settings: none; }
3
+ @include prefixer(font-feature-settings, $settings, webkit moz ms spec);
4
+ }
mixins/sass/bourbon/css3/_hidpi-media-query.scss ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ // HiDPI mixin. Default value set to 1.3 to target Google Nexus 7 (http://bjango.com/articles/min-device-pixel-ratio/)
2
+ @mixin hidpi($ratio: 1.3) {
3
+ @media only screen and (-webkit-min-device-pixel-ratio: $ratio),
4
+ only screen and (min--moz-device-pixel-ratio: $ratio),
5
+ only screen and (-o-min-device-pixel-ratio: #{$ratio}/1),
6
+ only screen and (min-resolution: round($ratio * 96dpi)),
7
+ only screen and (min-resolution: $ratio * 1dppx) {
8
+ @content;
9
+ }
10
+ }
mixins/sass/bourbon/css3/_hyphens.scss ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ @mixin hyphens($hyphenation: none) {
2
+ // none | manual | auto
3
+ @include prefixer(hyphens, $hyphenation, webkit moz ms spec);
4
+ }
mixins/sass/bourbon/css3/_image-rendering.scss ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin image-rendering ($mode:auto) {
2
+
3
+ @if ($mode == crisp-edges) {
4
+ -ms-interpolation-mode: nearest-neighbor; // IE8+
5
+ image-rendering: -moz-crisp-edges;
6
+ image-rendering: -o-crisp-edges;
7
+ image-rendering: -webkit-optimize-contrast;
8
+ image-rendering: crisp-edges;
9
+ }
10
+
11
+ @else {
12
+ image-rendering: $mode;
13
+ }
14
+ }
mixins/sass/bourbon/css3/_keyframes.scss ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Adds keyframes blocks for supported prefixes, removing redundant prefixes in the block's content
2
+ @mixin keyframes($name) {
3
+ $original-prefix-for-webkit: $prefix-for-webkit;
4
+ $original-prefix-for-mozilla: $prefix-for-mozilla;
5
+ $original-prefix-for-microsoft: $prefix-for-microsoft;
6
+ $original-prefix-for-opera: $prefix-for-opera;
7
+ $original-prefix-for-spec: $prefix-for-spec;
8
+
9
+ @if $original-prefix-for-webkit {
10
+ @include disable-prefix-for-all();
11
+ $prefix-for-webkit: true !global;
12
+ @-webkit-keyframes #{$name} {
13
+ @content;
14
+ }
15
+ }
16
+
17
+ @if $original-prefix-for-mozilla {
18
+ @include disable-prefix-for-all();
19
+ $prefix-for-mozilla: true !global;
20
+ @-moz-keyframes #{$name} {
21
+ @content;
22
+ }
23
+ }
24
+
25
+ $prefix-for-webkit: $original-prefix-for-webkit !global;
26
+ $prefix-for-mozilla: $original-prefix-for-mozilla !global;
27
+ $prefix-for-microsoft: $original-prefix-for-microsoft !global;
28
+ $prefix-for-opera: $original-prefix-for-opera !global;
29
+ $prefix-for-spec: $original-prefix-for-spec !global;
30
+
31
+ @if $original-prefix-for-spec {
32
+ @keyframes #{$name} {
33
+ @content;
34
+ }
35
+ }
36
+ }
mixins/sass/bourbon/css3/_linear-gradient.scss ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin linear-gradient($pos, $g1, $g2: null,
2
+ $g3: null, $g4: null,
3
+ $g5: null, $g6: null,
4
+ $g7: null, $g8: null,
5
+ $g9: null, $g10: null,
6
+ $fallback: null) {
7
+ // Detect what type of value exists in $pos
8
+ $pos-type: type-of(nth($pos, 1));
9
+ $pos-spec: null;
10
+ $pos-degree: null;
11
+
12
+ // If $pos is missing from mixin, reassign vars and add default position
13
+ @if ($pos-type == color) or (nth($pos, 1) == "transparent") {
14
+ $g10: $g9; $g9: $g8; $g8: $g7; $g7: $g6; $g6: $g5;
15
+ $g5: $g4; $g4: $g3; $g3: $g2; $g2: $g1; $g1: $pos;
16
+ $pos: null;
17
+ }
18
+
19
+ @if $pos {
20
+ $positions: _linear-positions-parser($pos);
21
+ $pos-degree: nth($positions, 1);
22
+ $pos-spec: nth($positions, 2);
23
+ }
24
+
25
+ $full: $g1, $g2, $g3, $g4, $g5, $g6, $g7, $g8, $g9, $g10;
26
+
27
+ // Set $g1 as the default fallback color
28
+ $fallback-color: nth($g1, 1);
29
+
30
+ // If $fallback is a color use that color as the fallback color
31
+ @if (type-of($fallback) == color) or ($fallback == "transparent") {
32
+ $fallback-color: $fallback;
33
+ }
34
+
35
+ background-color: $fallback-color;
36
+ background-image: -webkit-linear-gradient($pos-degree $full); // Safari 5.1+, Chrome
37
+ background-image: unquote("linear-gradient(#{$pos-spec}#{$full})");
38
+ }
mixins/sass/bourbon/css3/_perspective.scss ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ @mixin perspective($depth: none) {
2
+ // none | <length>
3
+ @include prefixer(perspective, $depth, webkit moz spec);
4
+ }
5
+
6
+ @mixin perspective-origin($value: 50% 50%) {
7
+ @include prefixer(perspective-origin, $value, webkit moz spec);
8
+ }
mixins/sass/bourbon/css3/_placeholder.scss ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ @mixin placeholder {
2
+ $placeholders: ":-webkit-input" ":-moz" "-moz" "-ms-input";
3
+ @each $placeholder in $placeholders {
4
+ &:#{$placeholder}-placeholder {
5
+ @content;
6
+ }
7
+ }
8
+ }
mixins/sass/bourbon/css3/_radial-gradient.scss ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Requires Sass 3.1+
2
+ @mixin radial-gradient($g1, $g2,
3
+ $g3: null, $g4: null,
4
+ $g5: null, $g6: null,
5
+ $g7: null, $g8: null,
6
+ $g9: null, $g10: null,
7
+ $pos: null,
8
+ $shape-size: null,
9
+ $fallback: null) {
10
+
11
+ $data: _radial-arg-parser($g1, $g2, $pos, $shape-size);
12
+ $g1: nth($data, 1);
13
+ $g2: nth($data, 2);
14
+ $pos: nth($data, 3);
15
+ $shape-size: nth($data, 4);
16
+
17
+ $full: $g1, $g2, $g3, $g4, $g5, $g6, $g7, $g8, $g9, $g10;
18
+
19
+ // Strip deprecated cover/contain for spec
20
+ $shape-size-spec: _shape-size-stripper($shape-size);
21
+
22
+ // Set $g1 as the default fallback color
23
+ $first-color: nth($full, 1);
24
+ $fallback-color: nth($first-color, 1);
25
+
26
+ @if (type-of($fallback) == color) or ($fallback == "transparent") {
27
+ $fallback-color: $fallback;
28
+ }
29
+
30
+ // Add Commas and spaces
31
+ $shape-size: if($shape-size, "#{$shape-size}, ", null);
32
+ $pos: if($pos, "#{$pos}, ", null);
33
+ $pos-spec: if($pos, "at #{$pos}", null);
34
+ $shape-size-spec: if(($shape-size-spec != " ") and ($pos == null), "#{$shape-size-spec}, ", "#{$shape-size-spec} ");
35
+
36
+ background-color: $fallback-color;
37
+ background-image: -webkit-radial-gradient(#{$pos}#{$shape-size}#{$full});
38
+ background-image: radial-gradient(#{$shape-size-spec}#{$pos-spec}#{$full});
39
+ }
mixins/sass/bourbon/css3/_selection.scss ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Outputs the spec and prefixed versions of the `::selection` pseudo-element.
4
+ ///
5
+ /// @param {Bool} $current-selector [false]
6
+ /// If set to `true`, it takes the current element into consideration.
7
+ ///
8
+ /// @example scss - Usage
9
+ /// .element {
10
+ /// @include selection(true) {
11
+ /// background-color: #ffbb52;
12
+ /// }
13
+ /// }
14
+ ///
15
+ /// @example css - CSS Output
16
+ /// .element::-moz-selection {
17
+ /// background-color: #ffbb52;
18
+ /// }
19
+ ///
20
+ /// .element::selection {
21
+ /// background-color: #ffbb52;
22
+ /// }
23
+
24
+ @mixin selection($current-selector: false) {
25
+ @if $current-selector {
26
+ &::-moz-selection {
27
+ @content;
28
+ }
29
+
30
+ &::selection {
31
+ @content;
32
+ }
33
+ } @else {
34
+ ::-moz-selection {
35
+ @content;
36
+ }
37
+
38
+ ::selection {
39
+ @content;
40
+ }
41
+ }
42
+ }
mixins/sass/bourbon/css3/_text-decoration.scss ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin text-decoration($value) {
2
+ // <text-decoration-line> || <text-decoration-style> || <text-decoration-color>
3
+ @include prefixer(text-decoration, $value, moz);
4
+ }
5
+
6
+ @mixin text-decoration-line($line: none) {
7
+ // none || underline || overline || line-through
8
+ @include prefixer(text-decoration-line, $line, moz);
9
+ }
10
+
11
+ @mixin text-decoration-style($style: solid) {
12
+ // solid || double || dotted || dashed || wavy
13
+ @include prefixer(text-decoration-style, $style, moz webkit);
14
+ }
15
+
16
+ @mixin text-decoration-color($color: currentColor) {
17
+ // currentColor || <color>
18
+ @include prefixer(text-decoration-color, $color, moz);
19
+ }
mixins/sass/bourbon/css3/_transform.scss ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @mixin transform($property: none) {
2
+ // none | <transform-function>
3
+ @include prefixer(transform, $property, webkit moz ms o spec);
4
+ }
5
+
6
+ @mixin transform-origin($axes: 50%) {
7
+ // x-axis - left | center | right | length | %
8
+ // y-axis - top | center | bottom | length | %
9
+ // z-axis - length
10
+ @include prefixer(transform-origin, $axes, webkit moz ms o spec);
11
+ }
12
+
13
+ @mixin transform-style($style: flat) {
14
+ @include prefixer(transform-style, $style, webkit moz ms o spec);
15
+ }
mixins/sass/bourbon/css3/_transition.scss ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Shorthand mixin. Supports multiple parentheses-deliminated values for each variable.
2
+ // Example: @include transition (all 2s ease-in-out);
3
+ // @include transition (opacity 1s ease-in 2s, width 2s ease-out);
4
+ // @include transition-property (transform, opacity);
5
+
6
+ @mixin transition($properties...) {
7
+ // Fix for vendor-prefix transform property
8
+ $needs-prefixes: false;
9
+ $webkit: ();
10
+ $moz: ();
11
+ $spec: ();
12
+
13
+ // Create lists for vendor-prefixed transform
14
+ @each $list in $properties {
15
+ @if nth($list, 1) == "transform" {
16
+ $needs-prefixes: true;
17
+ $list1: -webkit-transform;
18
+ $list2: -moz-transform;
19
+ $list3: ();
20
+
21
+ @each $var in $list {
22
+ $list3: join($list3, $var);
23
+
24
+ @if $var != "transform" {
25
+ $list1: join($list1, $var);
26
+ $list2: join($list2, $var);
27
+ }
28
+ }
29
+
30
+ $webkit: append($webkit, $list1);
31
+ $moz: append($moz, $list2);
32
+ $spec: append($spec, $list3);
33
+ } @else {
34
+ $webkit: append($webkit, $list, comma);
35
+ $moz: append($moz, $list, comma);
36
+ $spec: append($spec, $list, comma);
37
+ }
38
+ }
39
+
40
+ @if $needs-prefixes {
41
+ -webkit-transition: $webkit;
42
+ -moz-transition: $moz;
43
+ transition: $spec;
44
+ } @else {
45
+ @if length($properties) >= 1 {
46
+ @include prefixer(transition, $properties, webkit moz spec);
47
+ } @else {
48
+ $properties: all 0.15s ease-out 0s;
49
+ @include prefixer(transition, $properties, webkit moz spec);
50
+ }
51
+ }
52
+ }
53
+
54
+ @mixin transition-property($properties...) {
55
+ -webkit-transition-property: transition-property-names($properties, "webkit");
56
+ -moz-transition-property: transition-property-names($properties, "moz");
57
+ transition-property: transition-property-names($properties, false);
58
+ }
59
+
60
+ @mixin transition-duration($times...) {
61
+ @include prefixer(transition-duration, $times, webkit moz spec);
62
+ }
63
+
64
+ @mixin transition-timing-function($motions...) {
65
+ // ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier()
66
+ @include prefixer(transition-timing-function, $motions, webkit moz spec);
67
+ }
68
+
69
+ @mixin transition-delay($times...) {
70
+ @include prefixer(transition-delay, $times, webkit moz spec);
71
+ }
mixins/sass/bourbon/css3/_user-select.scss ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ @mixin user-select($value: none) {
2
+ @include prefixer(user-select, $value, webkit moz ms spec);
3
+ }
mixins/sass/bourbon/functions/_assign-inputs.scss ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ @function assign-inputs($inputs, $pseudo: null) {
2
+ $list: ();
3
+
4
+ @each $input in $inputs {
5
+ $input: unquote($input);
6
+ $input: if($pseudo, $input + ":" + $pseudo, $input);
7
+ $list: append($list, $input, comma);
8
+ }
9
+
10
+ @return $list;
11
+ }
mixins/sass/bourbon/functions/_contains-falsy.scss ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Checks if a list does not contains a value.
4
+ ///
5
+ /// @access private
6
+ ///
7
+ /// @param {List} $list
8
+ /// The list to check against.
9
+ ///
10
+ /// @return {Bool}
11
+
12
+ @function contains-falsy($list) {
13
+ @each $item in $list {
14
+ @if not $item {
15
+ @return true;
16
+ }
17
+ }
18
+
19
+ @return false;
20
+ }
mixins/sass/bourbon/functions/_contains.scss ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Checks if a list contains a value(s).
4
+ ///
5
+ /// @access private
6
+ ///
7
+ /// @param {List} $list
8
+ /// The list to check against.
9
+ ///
10
+ /// @param {List} $values
11
+ /// A single value or list of values to check for.
12
+ ///
13
+ /// @example scss - Usage
14
+ /// contains($list, $value)
15
+ ///
16
+ /// @return {Bool}
17
+
18
+ @function contains($list, $values...) {
19
+ @each $value in $values {
20
+ @if type-of(index($list, $value)) != "number" {
21
+ @return false;
22
+ }
23
+ }
24
+
25
+ @return true;
26
+ }
mixins/sass/bourbon/functions/_is-length.scss ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Checks for a valid CSS length.
4
+ ///
5
+ /// @param {String} $value
6
+
7
+ @function is-length($value) {
8
+ @return type-of($value) != "null" and (str-slice($value + "", 1, 4) == "calc"
9
+ or index(auto inherit initial 0, $value)
10
+ or (type-of($value) == "number" and not(unitless($value))));
11
+ }
mixins/sass/bourbon/functions/_is-light.scss ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Programatically determines whether a color is light or dark.
4
+ ///
5
+ /// @link http://robots.thoughtbot.com/closer-look-color-lightness
6
+ ///
7
+ /// @param {Color (Hex)} $color
8
+ ///
9
+ /// @example scss - Usage
10
+ /// is-light($color)
11
+ ///
12
+ /// @return {Bool}
13
+
14
+ @function is-light($hex-color) {
15
+ $-local-red: red(rgba($hex-color, 1));
16
+ $-local-green: green(rgba($hex-color, 1));
17
+ $-local-blue: blue(rgba($hex-color, 1));
18
+ $-local-lightness: ($-local-red * 0.2126 + $-local-green * 0.7152 + $-local-blue * 0.0722) / 255;
19
+
20
+ @return $-local-lightness > 0.6;
21
+ }
mixins/sass/bourbon/functions/_is-number.scss ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Checks for a valid number.
4
+ ///
5
+ /// @param {Number} $value
6
+ ///
7
+ /// @require {function} contains
8
+
9
+ @function is-number($value) {
10
+ @return contains("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" 0 1 2 3 4 5 6 7 8 9, $value);
11
+ }
mixins/sass/bourbon/functions/_is-size.scss ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Checks for a valid CSS size.
4
+ ///
5
+ /// @param {String} $value
6
+ ///
7
+ /// @require {function} contains
8
+ /// @require {function} is-length
9
+
10
+ @function is-size($value) {
11
+ @return is-length($value)
12
+ or contains("fill" "fit-content" "min-content" "max-content", $value);
13
+ }
mixins/sass/bourbon/functions/_modular-scale.scss ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Scaling Variables
2
+ $golden: 1.618;
3
+ $minor-second: 1.067;
4
+ $major-second: 1.125;
5
+ $minor-third: 1.2;
6
+ $major-third: 1.25;
7
+ $perfect-fourth: 1.333;
8
+ $augmented-fourth: 1.414;
9
+ $perfect-fifth: 1.5;
10
+ $minor-sixth: 1.6;
11
+ $major-sixth: 1.667;
12
+ $minor-seventh: 1.778;
13
+ $major-seventh: 1.875;
14
+ $octave: 2;
15
+ $major-tenth: 2.5;
16
+ $major-eleventh: 2.667;
17
+ $major-twelfth: 3;
18
+ $double-octave: 4;
19
+
20
+ $modular-scale-ratio: $perfect-fourth !default;
21
+ $modular-scale-base: em($em-base) !default;
22
+
23
+ @function modular-scale($increment, $value: $modular-scale-base, $ratio: $modular-scale-ratio) {
24
+ $v1: nth($value, 1);
25
+ $v2: nth($value, length($value));
26
+ $value: $v1;
27
+
28
+ // scale $v2 to just above $v1
29
+ @while $v2 > $v1 {
30
+ $v2: ($v2 / $ratio); // will be off-by-1
31
+ }
32
+ @while $v2 < $v1 {
33
+ $v2: ($v2 * $ratio); // will fix off-by-1
34
+ }
35
+
36
+ // check AFTER scaling $v2 to prevent double-counting corner-case
37
+ $double-stranded: $v2 > $v1;
38
+
39
+ @if $increment > 0 {
40
+ @for $i from 1 through $increment {
41
+ @if $double-stranded and ($v1 * $ratio) > $v2 {
42
+ $value: $v2;
43
+ $v2: ($v2 * $ratio);
44
+ } @else {
45
+ $v1: ($v1 * $ratio);
46
+ $value: $v1;
47
+ }
48
+ }
49
+ }
50
+
51
+ @if $increment < 0 {
52
+ // adjust $v2 to just below $v1
53
+ @if $double-stranded {
54
+ $v2: ($v2 / $ratio);
55
+ }
56
+
57
+ @for $i from $increment through -1 {
58
+ @if $double-stranded and ($v1 / $ratio) < $v2 {
59
+ $value: $v2;
60
+ $v2: ($v2 / $ratio);
61
+ } @else {
62
+ $v1: ($v1 / $ratio);
63
+ $value: $v1;
64
+ }
65
+ }
66
+ }
67
+
68
+ @return $value;
69
+ }
mixins/sass/bourbon/functions/_px-to-em.scss ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Convert pixels to ems
2
+ // eg. for a relational value of 12px write em(12) when the parent is 16px
3
+ // if the parent is another value say 24px write em(12, 24)
4
+
5
+ @function em($pxval, $base: $em-base) {
6
+ @if not unitless($pxval) {
7
+ $pxval: strip-units($pxval);
8
+ }
9
+ @if not unitless($base) {
10
+ $base: strip-units($base);
11
+ }
12
+ @return ($pxval / $base) * 1em;
13
+ }
mixins/sass/bourbon/functions/_px-to-rem.scss ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Convert pixels to rems
2
+ // eg. for a relational value of 12px write rem(12)
3
+ // Assumes $em-base is the font-size of <html>
4
+
5
+ @function rem($pxval) {
6
+ @if not unitless($pxval) {
7
+ $pxval: strip-units($pxval);
8
+ }
9
+
10
+ $base: $em-base;
11
+ @if not unitless($base) {
12
+ $base: strip-units($base);
13
+ }
14
+ @return ($pxval / $base) * 1rem;
15
+ }
mixins/sass/bourbon/functions/_shade.scss ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Mixes a color with black.
4
+ ///
5
+ /// @param {Color} $color
6
+ ///
7
+ /// @param {Number (Percentage)} $percent
8
+ /// The amount of black to be mixed in.
9
+ ///
10
+ /// @example scss - Usage
11
+ /// .element {
12
+ /// background-color: shade(#ffbb52, 60%);
13
+ /// }
14
+ ///
15
+ /// @example css - CSS Output
16
+ /// .element {
17
+ /// background-color: #664a20;
18
+ /// }
19
+ ///
20
+ /// @return {Color}
21
+
22
+ @function shade($color, $percent) {
23
+ @return mix(#000, $color, $percent);
24
+ }
mixins/sass/bourbon/functions/_strip-units.scss ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Strips the unit from a number.
4
+ ///
5
+ /// @param {Number (With Unit)} $value
6
+ ///
7
+ /// @example scss - Usage
8
+ /// $dimension: strip-units(10em);
9
+ ///
10
+ /// @example css - CSS Output
11
+ /// $dimension: 10;
12
+ ///
13
+ /// @return {Number (Unitless)}
14
+
15
+ @function strip-units($value) {
16
+ @return ($value / ($value * 0 + 1));
17
+ }
mixins/sass/bourbon/functions/_tint.scss ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Mixes a color with white.
4
+ ///
5
+ /// @param {Color} $color
6
+ ///
7
+ /// @param {Number (Percentage)} $percent
8
+ /// The amount of white to be mixed in.
9
+ ///
10
+ /// @example scss - Usage
11
+ /// .element {
12
+ /// background-color: tint(#6ecaa6, 40%);
13
+ /// }
14
+ ///
15
+ /// @example css - CSS Output
16
+ /// .element {
17
+ /// background-color: #a8dfc9;
18
+ /// }
19
+ ///
20
+ /// @return {Color}
21
+
22
+ @function tint($color, $percent) {
23
+ @return mix(#fff, $color, $percent);
24
+ }
mixins/sass/bourbon/functions/_transition-property-name.scss ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Return vendor-prefixed property names if appropriate
2
+ // Example: transition-property-names((transform, color, background), moz) -> -moz-transform, color, background
3
+ //************************************************************************//
4
+ @function transition-property-names($props, $vendor: false) {
5
+ $new-props: ();
6
+
7
+ @each $prop in $props {
8
+ $new-props: append($new-props, transition-property-name($prop, $vendor), comma);
9
+ }
10
+
11
+ @return $new-props;
12
+ }
13
+
14
+ @function transition-property-name($prop, $vendor: false) {
15
+ // put other properties that need to be prefixed here aswell
16
+ @if $vendor and $prop == transform {
17
+ @return unquote('-'+$vendor+'-'+$prop);
18
+ }
19
+ @else {
20
+ @return $prop;
21
+ }
22
+ }
mixins/sass/bourbon/functions/_unpack.scss ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
1
+ @charset "UTF-8";
2
+
3
+ /// Converts shorthand to the 4-value syntax.
4
+ ///
5
+ /// @param {List} $shorthand
6
+ ///
7
+ /// @example scss - Usag