FooBox Image Lightbox WordPress Plugin - Version 1.1.11

Version Description

  • Updated to latest JS and CSS fixing some bugs
  • Updated to latest Freemius 1.2.1.5 SDK
  • Free trial for PRO now included in getting started page
Download this release

Release Info

Developer bradvin
Plugin Icon 128x128 FooBox Image Lightbox WordPress Plugin
Version 1.1.11
Comparing to
See all releases

Code changes from version 1.1.10 to 1.1.11

Files changed (38) hide show
  1. foobox-free.php +2 -2
  2. free/css/admin-foobox_page_foobox-settings.css +145 -145
  3. free/css/admin-toplevel_page_foobox-image-lightbox.css +8 -0
  4. free/css/foobox.free.min.css +1 -1
  5. free/includes/class-script-generator.php +1 -1
  6. free/includes/upgrade.php +32 -32
  7. free/includes/view-getting-started.php +18 -6
  8. free/js/admin-foobox_page_foobox-settings.js +66 -66
  9. free/js/foobox.free.min.js +2 -2
  10. freemius/LICENSE.txt +340 -340
  11. freemius/README.md +253 -245
  12. freemius/assets/css/admin/account.css +1 -1
  13. freemius/assets/css/admin/add-ons.css +2 -2
  14. freemius/assets/css/admin/common.css +1 -1
  15. freemius/assets/css/admin/connect.css +1 -1
  16. freemius/assets/css/admin/deactivation-feedback.css +1 -1
  17. freemius/assets/css/admin/debug.css +1 -1
  18. freemius/assets/css/admin/dialog-boxes.css +2 -2
  19. freemius/assets/css/admin/license-activation.css +1 -1
  20. freemius/assets/js/nojquery.ba-postmessage.js +139 -139
  21. freemius/assets/js/nojquery.ba-postmessage.min.js +11 -11
  22. freemius/assets/js/postmessage.js +134 -134
  23. freemius/assets/scss/_colors.scss +58 -58
  24. freemius/assets/scss/_mixins.scss +226 -215
  25. freemius/assets/scss/admin/_deactivation-feedback.scss +54 -54
  26. freemius/assets/scss/admin/_license-activation.scss +6 -6
  27. freemius/assets/scss/admin/_license-key-resend.scss +44 -44
  28. freemius/assets/scss/admin/_modal-common.scss +154 -152
  29. freemius/assets/scss/admin/account.scss +249 -183
  30. freemius/assets/scss/admin/add-ons.scss +448 -448
  31. freemius/assets/scss/admin/common.scss +159 -139
  32. freemius/assets/scss/admin/debug.scss +90 -90
  33. freemius/assets/scss/admin/dialog-boxes.scss +4 -4
  34. freemius/composer.json +10 -10
  35. freemius/config.php +301 -229
  36. freemius/gulpfile.js +41 -41
  37. freemius/includes/class-freemius-abstract.php +526 -452
  38. freemius/includes/class-freemius.php +11338 -10456
foobox-free.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: FooBox Image Lightbox
5
  Plugin URI: http://fooplugins.com/plugins/foobox/
6
  Description: The best responsive lightbox for WordPress.
7
- Version: 1.1.10
8
  Author: FooPlugins
9
  Author URI: http://fooplugins.com
10
  License: GPL2
@@ -20,7 +20,7 @@ if ( !class_exists( 'FooBox' ) ) {
20
  define( 'FOOBOX_BASE_ACTIVATION_REDIRECT_TRANSIENT_KEY', '_foobox_activation_redirect' );
21
  define( 'FOOBOX_BASE_PATH', plugin_dir_path( __FILE__ ) );
22
  define( 'FOOBOX_BASE_URL', plugin_dir_url( __FILE__ ) );
23
- define( 'FOOBOX_BASE_VERSION', '1.1.10' );
24
  // Create a helper function for easy SDK access.
25
  function foobox_fs()
26
  {
4
  Plugin Name: FooBox Image Lightbox
5
  Plugin URI: http://fooplugins.com/plugins/foobox/
6
  Description: The best responsive lightbox for WordPress.
7
+ Version: 1.1.11
8
  Author: FooPlugins
9
  Author URI: http://fooplugins.com
10
  License: GPL2
20
  define( 'FOOBOX_BASE_ACTIVATION_REDIRECT_TRANSIENT_KEY', '_foobox_activation_redirect' );
21
  define( 'FOOBOX_BASE_PATH', plugin_dir_path( __FILE__ ) );
22
  define( 'FOOBOX_BASE_URL', plugin_dir_url( __FILE__ ) );
23
+ define( 'FOOBOX_BASE_VERSION', '1.1.11' );
24
  // Create a helper function for easy SDK access.
25
  function foobox_fs()
26
  {
free/css/admin-foobox_page_foobox-settings.css CHANGED
@@ -1,146 +1,146 @@
1
- a.nav-tab:focus {
2
- box-shadow: none;
3
- }
4
-
5
- .medium_textarea {
6
- width:400px;
7
- height:100px;
8
- }
9
-
10
- .short_input {
11
- width:15em !important;
12
- }
13
-
14
- .long_input {
15
- width:90% !important;
16
- }
17
-
18
- .image-upload-button {
19
- cursor: pointer;
20
- }
21
-
22
- .yellow-message {
23
- background-color: lightYellow; border: solid 1px #E6DB55; padding:3px 10px;
24
- }
25
-
26
- .red-message {
27
- background-color: #ffebe8; border: solid 1px #c00; padding:3px 10px;
28
- }
29
-
30
- .demo-gallery { display: block; }
31
-
32
- .demo-gallery span { display:none; }
33
-
34
- .demo-gallery a
35
- {
36
- display: inline-block;
37
- margin: 10px;
38
- text-align: center;
39
- padding: 2px;
40
- border: 1px solid #9D9B8B;
41
- -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
42
- -moz-box-shadow: 0 0 10px rgba(0,0,0,0.5);
43
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
44
- }
45
-
46
- .demo-gallery a img
47
- {
48
- padding: 2px;
49
- display: block;
50
- }
51
-
52
- .demo-gallery a:hover
53
- {
54
- opacity: 0.8;
55
- }
56
-
57
-
58
- #foobox-free-settings-wrapper {
59
- width: 100%;
60
- }
61
-
62
- #foobox-free-settings-main {
63
- padding: 0;
64
- margin: 0;
65
- }
66
-
67
- #foobox-free-settings-sidebar {
68
- margin: 0;
69
- width:250px;
70
- padding: 0 0 0 20px;
71
- position: absolute;
72
- right: 0;
73
- }
74
-
75
- #foobox-free-settings-header {
76
- position: absolute;
77
- width: 300px;
78
- height: 67px;
79
- background: url('img/demo.png') no-repeat;
80
- margin-left: -200px;
81
- margin-top: -20px;
82
- }
83
-
84
- ul.foobox_features {
85
- padding: 10px;
86
- }
87
-
88
- ul.foobox_features li {
89
- margin-left:10px;
90
- background: url('img/tick.png') no-repeat left top;
91
- padding-left: 25px;
92
- padding-bottom: 10px;
93
- display: inline-block;
94
- width: 33%;
95
- }
96
-
97
- ul.foobox_features.tick2 li {
98
- background: url('img/tick2.png') no-repeat left top;
99
- }
100
-
101
- ul.foobox_features.tick3 li {
102
- background: url('img/tick3.png') no-repeat left top;
103
- }
104
-
105
- ul.foobox_features.single_column li {
106
- display: block;
107
- width: 100%;
108
- }
109
-
110
- .caption_call_to_action {
111
- color: #FFF;
112
- font-size: 24px;
113
- border-radius: 10px;
114
- margin:20px;
115
- }
116
-
117
- #foobox-free-upgrade p {
118
- font-weight: bold;
119
- }
120
-
121
- #upgrade_tab td, #upgrade_tab th {
122
- padding:0 !important;
123
- }
124
-
125
- #foobot_says_tab tr:first-child {
126
- display: none !important;
127
- }
128
-
129
- @media only screen and (max-width: 500px) {
130
- .foobox-free-settings-wrapper .foobox-free-settings-sidebar {
131
- position: relative;
132
- padding: 0;
133
- }
134
-
135
- div.demo-gallery {
136
- width: 100%;
137
- }
138
-
139
- div.demo-gallery img {
140
- height: 120px;
141
- }
142
-
143
- ul.foobox_features li {
144
- width: 50%;
145
- }
146
  }
1
+ a.nav-tab:focus {
2
+ box-shadow: none;
3
+ }
4
+
5
+ .medium_textarea {
6
+ width:400px;
7
+ height:100px;
8
+ }
9
+
10
+ .short_input {
11
+ width:15em !important;
12
+ }
13
+
14
+ .long_input {
15
+ width:90% !important;
16
+ }
17
+
18
+ .image-upload-button {
19
+ cursor: pointer;
20
+ }
21
+
22
+ .yellow-message {
23
+ background-color: lightYellow; border: solid 1px #E6DB55; padding:3px 10px;
24
+ }
25
+
26
+ .red-message {
27
+ background-color: #ffebe8; border: solid 1px #c00; padding:3px 10px;
28
+ }
29
+
30
+ .demo-gallery { display: block; }
31
+
32
+ .demo-gallery span { display:none; }
33
+
34
+ .demo-gallery a
35
+ {
36
+ display: inline-block;
37
+ margin: 10px;
38
+ text-align: center;
39
+ padding: 2px;
40
+ border: 1px solid #9D9B8B;
41
+ -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
42
+ -moz-box-shadow: 0 0 10px rgba(0,0,0,0.5);
43
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
44
+ }
45
+
46
+ .demo-gallery a img
47
+ {
48
+ padding: 2px;
49
+ display: block;
50
+ }
51
+
52
+ .demo-gallery a:hover
53
+ {
54
+ opacity: 0.8;
55
+ }
56
+
57
+
58
+ #foobox-free-settings-wrapper {
59
+ width: 100%;
60
+ }
61
+
62
+ #foobox-free-settings-main {
63
+ padding: 0;
64
+ margin: 0;
65
+ }
66
+
67
+ #foobox-free-settings-sidebar {
68
+ margin: 0;
69
+ width:250px;
70
+ padding: 0 0 0 20px;
71
+ position: absolute;
72
+ right: 0;
73
+ }
74
+
75
+ #foobox-free-settings-header {
76
+ position: absolute;
77
+ width: 300px;
78
+ height: 67px;
79
+ background: url('img/demo.png') no-repeat;
80
+ margin-left: -200px;
81
+ margin-top: -20px;
82
+ }
83
+
84
+ ul.foobox_features {
85
+ padding: 10px;
86
+ }
87
+
88
+ ul.foobox_features li {
89
+ margin-left:10px;
90
+ background: url('img/tick.png') no-repeat left top;
91
+ padding-left: 25px;
92
+ padding-bottom: 10px;
93
+ display: inline-block;
94
+ width: 33%;
95
+ }
96
+
97
+ ul.foobox_features.tick2 li {
98
+ background: url('img/tick2.png') no-repeat left top;
99
+ }
100
+
101
+ ul.foobox_features.tick3 li {
102
+ background: url('img/tick3.png') no-repeat left top;
103
+ }
104
+
105
+ ul.foobox_features.single_column li {
106
+ display: block;
107
+ width: 100%;
108
+ }
109
+
110
+ .caption_call_to_action {
111
+ color: #FFF;
112
+ font-size: 24px;
113
+ border-radius: 10px;
114
+ margin:20px;
115
+ }
116
+
117
+ #foobox-free-upgrade p {
118
+ font-weight: bold;
119
+ }
120
+
121
+ #upgrade_tab td, #upgrade_tab th {
122
+ padding:0 !important;
123
+ }
124
+
125
+ #foobot_says_tab tr:first-child {
126
+ display: none !important;
127
+ }
128
+
129
+ @media only screen and (max-width: 500px) {
130
+ .foobox-free-settings-wrapper .foobox-free-settings-sidebar {
131
+ position: relative;
132
+ padding: 0;
133
+ }
134
+
135
+ div.demo-gallery {
136
+ width: 100%;
137
+ }
138
+
139
+ div.demo-gallery img {
140
+ height: 120px;
141
+ }
142
+
143
+ ul.foobox_features li {
144
+ width: 50%;
145
+ }
146
  }
free/css/admin-toplevel_page_foobox-image-lightbox.css CHANGED
@@ -1,3 +1,11 @@
1
  a.nav-tab:focus {
2
  box-shadow: none;
 
 
 
 
 
 
 
 
3
  }
1
  a.nav-tab:focus {
2
  box-shadow: none;
3
+ }
4
+
5
+ .foobox-getting-started.about-wrap img {
6
+ border: none;
7
+ }
8
+
9
+ .foobox-getting-started.about-wrap .feature-section img {
10
+ margin-bottom: 0;
11
  }
free/css/foobox.free.min.css CHANGED
@@ -5,4 +5,4 @@
5
  * @copyright Steven Usher & Brad Vincent 2014
6
  * @license Released under the MIT license.
7
  * You are free to use FooBox jQuery in personal projects as long as this copyright header is left intact.
8
- */.fbx-close:hover,.fbx-credit a,.fbx-next:hover,.fbx-prev:hover{text-decoration:none}.fbx-modal,.fbx-modal *{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box}.fbx-modal{position:fixed;top:0;left:0;z-index:9000001;visibility:hidden;width:100%;height:100%;font-family:"Segoe UI",Helvetica,Arial,"Sans Serif";line-height:normal;outline:0!important}.fbx-modal.fbx-loading,.fbx-modal.fbx-show{visibility:visible}.fbx-inner-spacer{display:none;padding:40px}.fbx-inner,.fbx-loader{position:absolute;top:50%;left:50%}.fbx-inner{visibility:hidden;overflow:visible!important;margin-top:-5px;margin-left:-5px;min-width:100px;min-height:100px;width:100px;height:100px;z-index:100002}.fbx-show .fbx-inner{visibility:visible}.fbx-loader{visibility:hidden;z-index:100005;margin-top:-40px;margin-left:-40px;width:80px;height:80px;font-size:16px;-moz-box-shadow:0 0 3px #000;-moz-box-shadow:0 0 3px rgba(0,0,0,.4);-webkit-box-shadow:0 0 3px #000;-webkit-box-shadow:0 0 3px rgba(0,0,0,.4);box-shadow:0 0 3px #000;box-shadow:0 0 3px rgba(0,0,0,.4)}.fbx-loading .fbx-loader,.fbx-show .fbx-caption{visibility:visible}.fbx-loader>div{margin:10px;width:60px;height:60px}.fbx-item-current,.fbx-item-next,.fbx-stage{top:0;left:0;margin:0;width:100%;height:100%;padding:0;outline:0;position:absolute;border:none}.fbx-stage{overflow:hidden}.fbx-item-current,.fbx-item-next{-webkit-user-drag:none;overflow:auto}.fbx-loading .fbx-item-current,.fbx-loading .fbx-item-next{overflow:hidden}.fbx-item-next{z-index:100001}.fbx-item-current{z-index:100002}.fbx-error-msg{width:200px;height:200px;position:absolute;top:50%;left:50%;margin-top:-100px;margin-left:-100px}.fbx-error-msg>span{line-height:200px;width:100%;height:100%;display:block}.fbx-error-msg>p{position:absolute;top:100%;text-align:center;width:100%;margin:0}.fbx-item-iframe,.fbx-item-image,.fbx-item-video{margin:0;padding:0;width:100%;height:100%;outline:0;border:none;display:block}.fbx-item-video>.fbx-video{background-color:#000}.fbx-ios .fbx-item-current{-webkit-overflow-scrolling:touch!important;overflow:auto!important}.fbx-ios .fbx-item-iframe{width:1px;min-width:100%}.fbx-close,.fbx-next,.fbx-prev{position:absolute;z-index:100006;display:block;outline:0!important;text-decoration:none;cursor:pointer}.fbx-no-buttons .fbx-next,.fbx-no-buttons .fbx-prev{display:none!important}.fbx-phone .fbx-count,.fbx-phone .fbx-credit em,.fbx-phone.fbx-landscape.fbx-no-nav .fbx-next,.fbx-phone.fbx-landscape.fbx-no-nav .fbx-prev,.fbx-rounded .fbx-next.fbx-disabled,.fbx-rounded .fbx-prev.fbx-disabled{display:none}.fbx-credit{position:absolute;z-index:100003;text-transform:lowercase;font-size:10px}.fbx-credit em{font-style:normal;font-size:10px}.fbx-credit a{font-size:10px}.fbx-credit a:hover span{text-decoration:underline}.fbx-credit a span{letter-spacing:1px;font-size:10px;color:#fff}.fbx-count{position:absolute;z-index:100002;width:100%;text-align:center;font-size:10px}.fbx-btn-transition,.fbx-btn-transition:before{-webkit-transition-property:color,border-color,opacity,-webkit-box-shadow;-moz-transition-property:color,border-color,opacity,-moz-box-shadow;-o-transition-property:color,border-color,opacity,-o-box-shadow;transition-property:color,border-color,opacity,box-shadow;-webkit-transition-duration:.2s,.2s,.2s,.2s;-moz-transition-duration:.2s,.2s,.2s,.2s;-o-transition-duration:.2s,.2s,.2s,.2s;transition-duration:.2s,.2s,.2s,.2s;-webkit-transition-timing-function:ease-in,linear,ease-in,ease-in;-moz-transition-timing-function:ease-in,linear,ease-in,ease-in;-o-transition-timing-function:ease-in,linear,ease-in,ease-in;transition-timing-function:ease-in,linear,ease-in,ease-in;outline:0}.fbx-modal.fbx-phone .fbx-inner{border:none}.fbx-modal.fbx-phone .fbx-close,.fbx-modal.fbx-phone .fbx-next,.fbx-modal.fbx-phone .fbx-prev{position:fixed}.fbx-modal.fbx-phone .fbx-prev{border-radius:0 6px 6px 0}.fbx-modal.fbx-phone .fbx-next{border-radius:6px 0 0 6px}.fbx-modal.fbx-phone .fbx-close{top:0;right:0;opacity:.5;border-radius:0 0 0 25%;-webkit-border-bottom-left-radius:25%;-moz-border-radius-bottomleft:25%}.fbx-modal.fbx-phone .fbx-close:hover{opacity:1}.fbx-modal.fbx-phone .fbx-credit{bottom:2px;left:2px}.fbx-modal.fbx-phone.fbx-portrait .fbx-inner-spacer{padding:35px 5px 15px}.fbx-modal.fbx-phone.fbx-portrait .fbx-close,.fbx-modal.fbx-phone.fbx-portrait .fbx-next,.fbx-modal.fbx-phone.fbx-portrait .fbx-prev{border:none;opacity:1;margin:0;top:0;bottom:auto;width:auto;height:40px;border-radius:0;line-height:40px}.fbx-modal.fbx-phone.fbx-portrait .fbx-prev{left:0;right:66%}.fbx-modal.fbx-phone.fbx-portrait .fbx-next{left:33%;right:33%}.fbx-modal.fbx-phone.fbx-portrait .fbx-close{left:66%;right:0}.fbx-modal.fbx-phone.fbx-portrait.fbx-no-buttons .fbx-close{left:0;right:0}.fbx-modal.fbx-phone.fbx-landscape{border-right-width:46px;border-right-style:solid;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.fbx-modal.fbx-phone.fbx-landscape .fbx-inner-spacer{padding:5px}.fbx-modal.fbx-phone.fbx-landscape .fbx-close,.fbx-modal.fbx-phone.fbx-landscape .fbx-next,.fbx-modal.fbx-phone.fbx-landscape .fbx-prev{bottom:auto;left:auto;right:1px;width:44px;height:44px;line-height:44px;border:none;opacity:1;margin:0;border-radius:0}.fbx-modal.fbx-phone.fbx-landscape .fbx-close{top:0;height:60px}.fbx-modal.fbx-phone.fbx-landscape .fbx-prev{top:62px}.fbx-modal.fbx-phone.fbx-landscape .fbx-next{top:108px}@font-face{font-family:foobox;src:url(font/foobox.eot);src:url(font/foobox.eot?#iefix) format('embedded-opentype'),url(font/foobox.woff) format('woff'),url(font/foobox.ttf) format('truetype'),url(font/foobox.svg#foobox) format('svg');font-weight:400;font-style:normal}@media screen and (-webkit-min-device-pixel-ratio:0){@font-face{font-family:foobox;src:url(font/foobox.svg#foobox) format('svg');font-weight:400;font-style:normal}}.fbx-modal .fbx-error-msg>span,.fbx-modal .fbx-loader>div,.fbx-modal a.fbx-close,.fbx-modal a.fbx-next,.fbx-modal a.fbx-prev{font-family:foobox;font-size:16px;font-weight:400;text-align:center;outline:0;-webkit-font-smoothing:antialiased}.fbx-modal .fbx-loader>div{font-size:300%;line-height:60px}.fbx-modal.fbx-loading .fbx-loader>div{-webkit-animation:spin 2s infinite linear;-moz-animation:spin 2s infinite linear;-ms-animation:spin 2s infinite linear;-o-animation:spin 2s infinite linear;animation:spin 2s infinite linear}.fbx-modal .fbx-error-msg>span{font-size:1000%}.fbx-modal .fbx-error-msg>span:before{content:"\e028"}.fbx-close:before{content:"\e002"}.fbx-prev:before{content:"\e000"}.fbx-next:before{content:"\e001"}.fbx-loader>div:before{content:"\e012"}.fbx-flat .fbx-close:before{content:"\e117"}.fbx-flat .fbx-prev:before{content:"\e094"}.fbx-flat .fbx-next:before{content:"\e095"}.fbx-flat .fbx-loader>div:before{content:"\e105"}@-moz-keyframes spin{0%{-moz-transform:rotate(0)}100%{-moz-transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(359deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0)}100%{-o-transform:rotate(359deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0)}100%{-ms-transform:rotate(359deg)}}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(359deg)}}.fbx-rounded .fbx-prev.fbx-btn-shadow,.fbx-rounded .fbx-prev.fbx-btn-shadow:hover{-moz-box-shadow:-2px 0 2px #000;-moz-box-shadow:-2px 0 2px rgba(0,0,0,.8);-webkit-box-shadow:-2px 0 2px #000;-webkit-box-shadow:-2px 0 2px rgba(0,0,0,.8);box-shadow:-2px 0 2px #000;box-shadow:-2px 0 2px rgba(0,0,0,.8)}.fbx-rounded .fbx-next.fbx-btn-shadow,.fbx-rounded .fbx-next.fbx-btn-shadow:hover{-moz-box-shadow:2px 0 2px #000;-moz-box-shadow:2px 0 2px rgba(0,0,0,.8);-webkit-box-shadow:2px 0 2px #000;-webkit-box-shadow:2px 0 2px rgba(0,0,0,.8);box-shadow:2px 0 2px #000;box-shadow:2px 0 2px rgba(0,0,0,.8)}.fbx-fullscreen-mode .fbx-btn-shadow,.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow,.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow,.fbx-inner-shadow,.fbx-rounded .fbx-btn-shadow,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next.fbx-btn-shadow:before,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev.fbx-btn-shadow:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next.fbx-btn-shadow:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev.fbx-btn-shadow:before,.fbx-sticky-buttons .fbx-next.fbx-btn-shadow,.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow{-moz-box-shadow:0 0 12px #000;-moz-box-shadow:0 0 12px rgba(0,0,0,.8);-webkit-box-shadow:0 0 12px #000;-webkit-box-shadow:0 0 12px rgba(0,0,0,.8);box-shadow:0 0 12px #000;box-shadow:0 0 12px rgba(0,0,0,.8)}.fbx-fullscreen-mode .fbx-btn-shadow:hover,.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow:hover,.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow:hover,.fbx-rounded .fbx-btn-shadow:hover,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next.fbx-btn-shadow:hover:before,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev.fbx-btn-shadow:hover:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next.fbx-btn-shadow:hover:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev.fbx-btn-shadow:hover:before,.fbx-sticky-buttons .fbx-next.fbx-btn-shadow:hover,.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow:hover{-moz-box-shadow:0 0 6px #000;-moz-box-shadow:0 0 6px rgba(0,0,0,.8);-webkit-box-shadow:0 0 6px #000;-webkit-box-shadow:0 0 6px rgba(0,0,0,.8);box-shadow:0 0 6px #000;box-shadow:0 0 6px rgba(0,0,0,.8)}.fbx-flat .fbx-inner-shadow,.fbx-flat .fbx-rounded.fbx-inset-buttons .fbx-prev.fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-btn-shadow:hover,.fbx-flat.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow:hover,.fbx-flat.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow:hover,.fbx-flat.fbx-sticky-buttons .fbx-next.fbx-btn-shadow,.fbx-flat.fbx-sticky-buttons .fbx-next.fbx-btn-shadow:hover,.fbx-flat.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow,.fbx-flat.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow:hover,.fbx-modal.fbx-phone.fbx-fullscreen-mode .fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-rounded .fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-rounded.fbx-inset-buttons .fbx-next.fbx-btn-shadow:before,.fbx-modal.fbx-phone.fbx-rounded.fbx-inset-buttons .fbx-prev.fbx-btn-shadow:before,.fbx-modal.fbx-phone.fbx-sticky-buttons .fbx-next.fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow,.fbx-rounded.fbx-inset-buttons .fbx-next.fbx-btn-shadow{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.fbx-rounded .fbx-inner{border:8px solid transparent;border-radius:6px}.fbx-rounded .fbx-item-current,.fbx-rounded .fbx-item-image,.fbx-rounded .fbx-item-next{border-radius:3px}.fbx-rounded .fbx-loader,.fbx-rounded .fbx-loader>div{border-radius:50%}.fbx-rounded .fbx-error-msg{margin-top:-115px}.fbx-rounded .fbx-close{top:-21px;right:-21px;width:28px;height:28px;line-height:28px;border:3px solid transparent;border-radius:50%}.fbx-rounded .fbx-next,.fbx-rounded .fbx-prev{position:absolute;top:50%;margin-top:-50px;width:30px;height:100px;line-height:100px;border:3px solid transparent}.fbx-rounded .fbx-prev{left:-40px;border-radius:6px 0 0 6px}.fbx-rounded .fbx-next{right:-40px;border-radius:0 6px 6px 0}.fbx-rounded.fbx-phone .fbx-next.fbx-disabled,.fbx-rounded.fbx-phone .fbx-prev.fbx-disabled{display:block;cursor:default}.fbx-rounded.fbx-phone .fbx-next.fbx-disabled:before,.fbx-rounded.fbx-phone .fbx-prev.fbx-disabled:before{opacity:0}.fbx-rounded.fbx-desktop .fbx-next,.fbx-rounded.fbx-desktop .fbx-prev{position:absolute}.fbx-rounded .fbx-count,.fbx-rounded .fbx-credit{bottom:-25px}.fbx-rounded .fbx-inner-spacer{padding:40px 40px 50px}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait .fbx-inner-spacer{padding:60px 5px 0}.fbx-rounded.fbx-sticky-buttons .fbx-next,.fbx-rounded.fbx-sticky-buttons .fbx-prev{position:fixed;top:50%;margin-top:-50px;width:40px;height:100px;line-height:100px}.fbx-rounded.fbx-sticky-buttons .fbx-prev{left:0;border-radius:0 6px 6px 0}.fbx-rounded.fbx-sticky-buttons .fbx-next{right:0;border-radius:6px 0 0 6px}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-inner-spacer{padding:40px 60px}.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-inner-spacer{padding:35px 5px 15px}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-inner-spacer{padding:5px}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{top:0;bottom:0;border-radius:0;width:4%;min-width:45px;height:auto;opacity:.3}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next:hover,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:hover{opacity:1}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next:before,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:before{position:fixed;width:4%;min-width:45px;height:30px;line-height:30px;top:50%;margin-top:-15px}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:before{left:0;right:auto}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next:before{left:auto;right:0}.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-next:before,.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:before{position:relative;width:auto;min-width:0;height:auto;line-height:inherit;top:auto;margin-top:auto}.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{top:0;bottom:auto;border-radius:0;width:auto;min-width:0;height:auto;opacity:1}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{left:0;right:66%}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-next{left:33%;right:33%}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-close{left:66%;right:0}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-no-buttons.fbx-sticky-buttons.fbx-full-buttons .fbx-close{left:0;right:0}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{bottom:auto;width:34px;height:80px;opacity:.5}.fbx-rounded.fbx-phone.fbx-landscape.fbx-full-buttons .fbx-prev,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons .fbx-prev,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{top:62px}.fbx-rounded.fbx-phone.fbx-landscape.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next{top:108px}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next:hover,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:hover{opacity:1}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{border-radius:0 6px 6px 0}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next{border-radius:6px 0 0 6px}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev{z-index:100003;position:absolute;top:0;bottom:0;height:100%;width:25%;margin:0;border-radius:0;background-color:transparent;box-sizing:border-box}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev{left:0}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next{right:0}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next:before,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev:before{width:28px;height:28px;border-radius:50%;position:absolute;top:50%;margin-top:-14px;line-height:28px;border-width:3px;border-style:solid;opacity:0}.fbx-rounded.fbx-inset-buttons .fbx-prev:before{left:10px}.fbx-rounded.fbx-inset-buttons .fbx-next:before{right:10px}.fbx-rounded.fbx-inset-buttons .fbx-next:hover:before,.fbx-rounded.fbx-inset-buttons .fbx-prev:hover:before{opacity:1}.fbx-light,.fbx-light .fbx-caption,.fbx-light .fbx-open-caption,.fbx-light.fbx-phone .fbx-social{background-color:#000;background-color:rgba(0,0,0,.7)}.fbx-ie7.fbx-light,.fbx-ie7.fbx-light .fbx-caption,.fbx-ie8.fbx-light,.fbx-ie8.fbx-light .fbx-caption,.fbx-ie8.fbx-light.fbx-phone .fbx-social{background:0 0;-ms-filter:'progid:DXImageTransform.Microsoft.gradient(startColorstr=#26ffffff,endColorstr=#26ffffff)';filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#B2000000, endColorstr=#B2000000);zoom:1}.fbx-light .fbx-progress{background-color:#838383;background-color:rgba(255,255,255,.5)}.fbx-fullscreen-mode.fbx-light{background-color:#d3d3d3}.fbx-light .fbx-caption,.fbx-light .fbx-inner,.fbx-light .fbx-social,.fbx-light.fbx-inset-buttons .fbx-next:before,.fbx-light.fbx-inset-buttons .fbx-prev:before,.fbx-light.fbx-modal,.fbx-modal.fbx-light.fbx-phone .fbx-close:hover,.fbx-modal.fbx-light.fbx-phone .fbx-fullscreen-toggle:hover,.fbx-modal.fbx-light.fbx-phone .fbx-next:hover,.fbx-modal.fbx-light.fbx-phone .fbx-pause:hover,.fbx-modal.fbx-light.fbx-phone .fbx-play:hover,.fbx-modal.fbx-light.fbx-phone .fbx-prev:hover,.fbx-modal.fbx-light.fbx-phone .fbx-social-toggle:hover,.fbx-rounded.fbx-light .fbx-close,.fbx-rounded.fbx-light .fbx-fullscreen-toggle,.fbx-rounded.fbx-light .fbx-pause,.fbx-rounded.fbx-light .fbx-play,.fbx-rounded.fbx-light .fbx-social-toggle{border-color:#FFF}.fbx-light .fbx-close,.fbx-light .fbx-fullscreen-toggle,.fbx-light .fbx-inner,.fbx-light .fbx-loader,.fbx-light .fbx-next,.fbx-light .fbx-pause,.fbx-light .fbx-play,.fbx-light .fbx-prev,.fbx-light .fbx-social-toggle,.fbx-light.fbx-inset-buttons .fbx-next:before,.fbx-light.fbx-inset-buttons .fbx-prev:before{background-color:#FFF}.fbx-flat.fbx-light .fbx-close,.fbx-flat.fbx-light .fbx-fullscreen-toggle,.fbx-flat.fbx-light .fbx-next,.fbx-flat.fbx-light .fbx-pause,.fbx-flat.fbx-light .fbx-play,.fbx-flat.fbx-light .fbx-prev,.fbx-flat.fbx-light .fbx-social-toggle{background-color:transparent}.fbx-light .fbx-close,.fbx-light .fbx-error-msg,.fbx-light .fbx-fullscreen-toggle,.fbx-light .fbx-loader,.fbx-light .fbx-next,.fbx-light .fbx-pause,.fbx-light .fbx-play,.fbx-light .fbx-prev,.fbx-light .fbx-social-toggle,.fbx-light.fbx-inset-buttons .fbx-next:before,.fbx-light.fbx-inset-buttons .fbx-prev:before,.fbx-metro.fbx-light .fbx-count,.fbx-metro.fbx-light .fbx-credit a{color:#666!important}.fbx-flat.fbx-light .fbx-close,.fbx-flat.fbx-light .fbx-count,.fbx-flat.fbx-light .fbx-credit a,.fbx-flat.fbx-light .fbx-fullscreen-toggle,.fbx-flat.fbx-light .fbx-next,.fbx-flat.fbx-light .fbx-pause,.fbx-flat.fbx-light .fbx-play,.fbx-flat.fbx-light .fbx-prev,.fbx-flat.fbx-light .fbx-social-toggle{color:#FFF!important}.fbx-light .fbx-close:hover,.fbx-light .fbx-fullscreen-toggle:hover,.fbx-light .fbx-next:hover,.fbx-light .fbx-pause:hover,.fbx-light .fbx-play:hover,.fbx-light .fbx-prev:hover,.fbx-light .fbx-social-toggle:hover,.fbx-light.fbx-inset-buttons .fbx-next:hover:before,.fbx-light.fbx-inset-buttons .fbx-prev:hover:before,.fbx-metro.fbx-light .fbx-credit a:hover{color:#bababa!important}.fbx-metro.fbx-light .fbx-close:hover,.fbx-metro.fbx-light .fbx-fullscreen-toggle:hover,.fbx-metro.fbx-light .fbx-next:hover,.fbx-metro.fbx-light .fbx-pause:hover,.fbx-metro.fbx-light .fbx-play:hover,.fbx-metro.fbx-light .fbx-prev:hover,.fbx-metro.fbx-light .fbx-social-toggle:hover{border-color:#bababa}.fbx-rounded.fbx-light .fbx-count,.fbx-rounded.fbx-light .fbx-credit a{color:#888}.fbx-rounded.fbx-light .fbx-credit a:hover span{color:#ddd}.fbx-light .fbx-caption{color:#FFF}.fbx-light .fbx-caption-desc,.fbx-light .fbx-caption-desc a{color:#eee}.fbx-light .fbx-item-current::-webkit-scrollbar{width:12px;height:12px}.fbx-light .fbx-item-current::-webkit-scrollbar-track{background:rgba(0,0,0,.1)}.fbx-light .fbx-item-current::-webkit-scrollbar-thumb{background:rgba(0,0,0,.5)}.fbx-light .fbx-item-current::-webkit-scrollbar,.fbx-light .fbx-item-next::-webkit-scrollbar{width:12px;height:12px}.fbx-light .fbx-item-current::-webkit-scrollbar-track,.fbx-light .fbx-item-next::-webkit-scrollbar-track{background:rgba(0,0,0,.1)}.fbx-light .fbx-item-current::-webkit-scrollbar-corner,.fbx-light .fbx-item-current::-webkit-scrollbar-thumb,.fbx-light .fbx-item-next::-webkit-scrollbar-corner,.fbx-light .fbx-item-next::-webkit-scrollbar-thumb{background:rgba(0,0,0,.3)}.fbx-caption{position:absolute;top:auto;right:auto;bottom:0;left:0;z-index:100004;width:100%;text-align:center;font-size:14px;transition:visible .3s ease,opacity .3s ease,transform .3s ease;opacity:1;transform:translateY(0)}.fbx-show .fbx-caption.fbx-fade-caption{opacity:0;visibility:hidden}.fbx-caption.fbx-slide-caption{transform:translateY(100%)}.fbx-loading .fbx-caption.fbx-hide-caption,.fbx-show .fbx-caption.fbx-hide-caption{visibility:hidden}.fbx-fullscreen-mode .fbx-caption,.fbx-sticky-caption .fbx-caption{position:fixed;z-index:100007}.fbx-close-caption,.fbx-open-caption{position:absolute;color:#FFF;font-size:24px;text-decoration:none;line-height:20px}.fbx-rounded .fbx-caption{border-radius:0 0 3px 3px}.fbx-modal.fbx-phone .fbx-caption,.fbx-sticky-caption.fbx-rounded .fbx-caption{border-radius:0}.fbx-close-caption{top:0;right:0;padding:3px 3px 10px 10px}.fbx-open-caption{z-index:100004;bottom:0;right:5px;padding:0 10px 10px;opacity:0;transition:opacity .3s ease;border-top-left-radius:6px;border-top-right-radius:6px}.fbx-captions-hidden .fbx-open-caption{opacity:1}.fbx-caption-title{font-size:15px;padding:15px}.fbx-caption-desc{font-size:12px;line-height:20px;padding:15px}.fbx-caption-desc a{font-size:12px}.fbx-caption-title+.fbx-caption-desc{margin-top:-30px}.fbx-phone .fbx-caption{min-height:20px;font-size:12px;line-height:20px}.fbx-phone .fbx-caption-title{font-size:13px;padding:10px}.fbx-phone .fbx-caption-desc{font-size:11px;line-height:15px;padding:10px}.fbx-phone .fbx-caption-title+.fbx-caption-desc{margin-top:-20px}.fbx-modal.fbx-phone .fbx-caption{z-index:100004;bottom:0;position:fixed}.fbx-modal.fbx-phone.fbx-landscape .fbx-caption,.fbx-phone.fbx-landscape.fbx-sticky-caption .fbx-caption{z-index:100004}.fbx-modal.fbx-phone.fbx-landscape .fbx-caption{border-right-width:46px;border-right-style:solid;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.fbx-modal.fbx-flat.fbx-phone.fbx-landscape .fbx-caption{border-right-width:0}.fbx-pannable{cursor:-moz-grab;cursor:-webkit-grab;cursor:grab}.fbx-pannable.fbx-panning{cursor:-moz-grabbing;cursor:-webkit-grabbing;cursor:grabbing}.fbx-pannable>div>img.fbx-item{max-width:none;max-height:none}.fbx-pan-overview{cursor:pointer;max-width:150px;max-height:150px;overflow:hidden;background-position:top left;background-size:cover;position:absolute;z-index:100006;border:2px solid #666;-moz-box-shadow:0 0 12px rgba(0,0,0,.8);-webkit-box-shadow:0 0 12px rgba(0,0,0,.8);box-shadow:0 0 12px rgba(0,0,0,.8)}.fbx-pan-overview.fbx-top-left{top:20px;left:20px}.fbx-pan-overview.fbx-top-right{top:20px;right:32px}.fbx-pan-overview.fbx-bottom-left{bottom:32px;left:20px}.fbx-pan-overview.fbx-bottom-right{bottom:32px;right:32px}.fbx-pan-viewport{position:absolute;top:0;left:0;box-shadow:0 0 300px 300px rgba(0,0,0,.7)}.fbx-ie7 .fbx-close{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e002')}.fbx-ie7 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e000')}.fbx-ie7 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e001')}.fbx-ie7.fbx-arrows-1 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01b')}.fbx-ie7.fbx-arrows-1 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01c')}.fbx-ie7.fbx-arrows-2 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01d')}.fbx-ie7.fbx-arrows-2 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01e')}.fbx-ie7.fbx-arrows-3 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01f')}.fbx-ie7.fbx-arrows-3 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e020')}.fbx-ie7.fbx-arrows-4 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e021')}.fbx-ie7.fbx-arrows-4 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e022')}.fbx-ie7.fbx-arrows-5 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e023')}.fbx-ie7.fbx-arrows-5 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e024')}.fbx-ie7.fbx-arrows-6 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e025')}.fbx-ie7.fbx-arrows-6 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e026')}.fbx-ie7 .fbx-play{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e003')}.fbx-ie7 .fbx-pause{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e004')}.fbx-ie7 .fbx-fullscreen-toggle{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00e')}.fbx-fullscreen-mode.fbx-ie7 .fbx-fullscreen-toggle{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00d')}.fbx-ie7 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e012')}.fbx-ie7.fbx-spinner-1 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e005')}.fbx-ie7.fbx-spinner-2 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e011')}.fbx-ie7.fbx-spinner-3 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e027')}.fbx-ie7.fbx-spinner-4 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e013')}.fbx-ie7.fbx-spinner-5 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e014')}.fbx-ie7.fbx-spinner-6 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e015')}.fbx-ie7.fbx-spinner-7 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e016')}.fbx-ie7.fbx-spinner-8 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e017')}.fbx-ie7.fbx-spinner-9 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e018')}.fbx-ie7.fbx-spinner-10 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e019')}.fbx-ie7.fbx-spinner-11 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01a')}.fbx-ie7 .fbx-facebook{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00a')}.fbx-ie7 .fbx-google-plus{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e006')}.fbx-ie7 .fbx-twitter{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e009')}.fbx-ie7 .fbx-pinterest{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e007')}.fbx-ie7 .fbx-linkedin{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e008')}.fbx-ie7 .fbx-buffer{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00b')}.fbx-ie7 .fbx-download{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00f')}.fbx-ie7 .fbx-email{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e010')}
5
  * @copyright Steven Usher & Brad Vincent 2014
6
  * @license Released under the MIT license.
7
  * You are free to use FooBox jQuery in personal projects as long as this copyright header is left intact.
8
+ */.fbx-close:hover,.fbx-credit a,.fbx-next:hover,.fbx-prev:hover{text-decoration:none}.fbx-modal,.fbx-modal *{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box}.fbx-modal{position:fixed;top:0;left:0;z-index:9000001;visibility:hidden;width:100%;height:100%;font-family:"Segoe UI",Helvetica,Arial,"Sans Serif";line-height:normal;outline:0!important}.fbx-modal.fbx-loading,.fbx-modal.fbx-show{visibility:visible}.fbx-inner-spacer{display:none;padding:40px}.fbx-inner,.fbx-loader{position:absolute;top:50%;left:50%}.fbx-inner{visibility:hidden;overflow:visible!important;margin-top:-5px;margin-left:-5px;min-width:100px;min-height:100px;width:100px;height:100px;z-index:100002}.fbx-show .fbx-inner{visibility:visible}.fbx-loader{visibility:hidden;z-index:100005;margin-top:-40px;margin-left:-40px;width:80px;height:80px;font-size:16px;-moz-box-shadow:0 0 3px #000;-moz-box-shadow:0 0 3px rgba(0,0,0,.4);-webkit-box-shadow:0 0 3px #000;-webkit-box-shadow:0 0 3px rgba(0,0,0,.4);box-shadow:0 0 3px #000;box-shadow:0 0 3px rgba(0,0,0,.4)}.fbx-loading .fbx-loader,.fbx-show .fbx-caption{visibility:visible}.fbx-loader>div{margin:10px;width:60px;height:60px}.fbx-item-current,.fbx-item-next,.fbx-stage{top:0;left:0;margin:0;width:100%;height:100%;padding:0;outline:0;position:absolute;border:none}.fbx-stage{overflow:hidden}.fbx-item-current,.fbx-item-next{-webkit-user-drag:none;overflow:auto}.fbx-loading .fbx-item-current,.fbx-loading .fbx-item-next{overflow:hidden}.fbx-item-next{z-index:100001}.fbx-item-current{z-index:100002}.fbx-error-msg{width:200px;height:200px;position:absolute;top:50%;left:50%;margin-top:-100px;margin-left:-100px}.fbx-error-msg>span{line-height:200px;width:100%;height:100%;display:block}.fbx-error-msg>p{position:absolute;top:100%;text-align:center;width:100%;margin:0}.fbx-item-iframe,.fbx-item-image,.fbx-item-video{margin:0;padding:0;width:100%;height:100%;outline:0;border:none;display:block}.fbx-item-video>.fbx-video{background-color:#000}.fbx-ios .fbx-item-current{-webkit-overflow-scrolling:touch!important;overflow:auto!important}.fbx-ios .fbx-item-iframe{width:1px;min-width:100%}.fbx-close,.fbx-next,.fbx-prev{position:absolute;z-index:100006;display:block;outline:0!important;text-decoration:none;cursor:pointer}.fbx-no-buttons .fbx-next,.fbx-no-buttons .fbx-prev{display:none!important}.fbx-phone .fbx-count,.fbx-phone .fbx-credit em,.fbx-phone.fbx-landscape.fbx-no-nav .fbx-next,.fbx-phone.fbx-landscape.fbx-no-nav .fbx-prev,.fbx-rounded .fbx-next.fbx-disabled,.fbx-rounded .fbx-prev.fbx-disabled{display:none}.fbx-credit{position:absolute;z-index:100003;text-transform:lowercase;font-size:10px}.fbx-credit em{font-style:normal;font-size:10px}.fbx-credit a{font-size:10px}.fbx-credit a:hover span{text-decoration:underline}.fbx-credit a span{letter-spacing:1px;font-size:10px;color:#fff}.fbx-count{position:absolute;z-index:100002;width:100%;text-align:center;font-size:10px}.fbx-btn-transition,.fbx-btn-transition:before{-webkit-transition-property:color,border-color,opacity,-webkit-box-shadow;-moz-transition-property:color,border-color,opacity,-moz-box-shadow;-o-transition-property:color,border-color,opacity,-o-box-shadow;transition-property:color,border-color,opacity,box-shadow;-webkit-transition-duration:.2s,.2s,.2s,.2s;-moz-transition-duration:.2s,.2s,.2s,.2s;-o-transition-duration:.2s,.2s,.2s,.2s;transition-duration:.2s,.2s,.2s,.2s;-webkit-transition-timing-function:ease-in,linear,ease-in,ease-in;-moz-transition-timing-function:ease-in,linear,ease-in,ease-in;-o-transition-timing-function:ease-in,linear,ease-in,ease-in;transition-timing-function:ease-in,linear,ease-in,ease-in;outline:0}.fbx-modal.fbx-phone .fbx-inner{border:none}.fbx-modal.fbx-phone .fbx-close,.fbx-modal.fbx-phone .fbx-next,.fbx-modal.fbx-phone .fbx-prev{position:fixed}.fbx-modal.fbx-phone .fbx-prev{border-radius:0 6px 6px 0}.fbx-modal.fbx-phone .fbx-next{border-radius:6px 0 0 6px}.fbx-modal.fbx-phone .fbx-close{top:0;right:0;opacity:.5;border-radius:0 0 0 25%;-webkit-border-bottom-left-radius:25%;-moz-border-radius-bottomleft:25%}.fbx-modal.fbx-phone .fbx-close:hover{opacity:1}.fbx-modal.fbx-phone .fbx-credit{bottom:2px;left:2px}.fbx-modal.fbx-phone.fbx-portrait .fbx-inner-spacer{padding:35px 5px 15px}.fbx-modal.fbx-phone.fbx-portrait .fbx-close,.fbx-modal.fbx-phone.fbx-portrait .fbx-next,.fbx-modal.fbx-phone.fbx-portrait .fbx-prev{border:none;opacity:1;margin:0;top:0;bottom:auto;width:auto;height:40px;border-radius:0;line-height:40px}.fbx-modal.fbx-phone.fbx-portrait .fbx-prev{left:0;right:66%}.fbx-modal.fbx-phone.fbx-portrait .fbx-next{left:33%;right:33%}.fbx-modal.fbx-phone.fbx-portrait .fbx-close{left:66%;right:0}.fbx-modal.fbx-phone.fbx-portrait.fbx-no-buttons .fbx-close{left:0;right:0}.fbx-modal.fbx-phone.fbx-landscape{border-right-width:46px;border-right-style:solid;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.fbx-modal.fbx-phone.fbx-landscape .fbx-inner-spacer{padding:5px}.fbx-modal.fbx-phone.fbx-landscape .fbx-close,.fbx-modal.fbx-phone.fbx-landscape .fbx-next,.fbx-modal.fbx-phone.fbx-landscape .fbx-prev{bottom:auto;left:auto;right:1px;width:44px;height:44px;line-height:44px;border:none;opacity:1;margin:0;border-radius:0}.fbx-modal.fbx-phone.fbx-landscape .fbx-close{top:0;height:60px}.fbx-modal.fbx-phone.fbx-landscape .fbx-prev{top:62px}.fbx-modal.fbx-phone.fbx-landscape .fbx-next{top:108px}@font-face{font-family:foobox;src:url(font/foobox.eot);src:url(font/foobox.eot?#iefix) format('embedded-opentype'),url(font/foobox.woff) format('woff'),url(font/foobox.ttf) format('truetype'),url(font/foobox.svg#foobox) format('svg');font-weight:400;font-style:normal}@media screen and (-webkit-min-device-pixel-ratio:0){@font-face{font-family:foobox;src:url(font/foobox.svg#foobox) format('svg');font-weight:400;font-style:normal}}.fbx-modal .fbx-error-msg>span,.fbx-modal .fbx-loader>div,.fbx-modal a.fbx-close,.fbx-modal a.fbx-next,.fbx-modal a.fbx-prev{font-family:foobox;font-size:16px;font-weight:400;text-align:center;outline:0;-webkit-font-smoothing:antialiased}.fbx-modal .fbx-loader>div{font-size:300%;line-height:60px}.fbx-modal.fbx-loading .fbx-loader>div{-webkit-animation:spin 2s infinite linear;-moz-animation:spin 2s infinite linear;-ms-animation:spin 2s infinite linear;-o-animation:spin 2s infinite linear;animation:spin 2s infinite linear}.fbx-modal .fbx-error-msg>span{font-size:1000%}.fbx-modal .fbx-error-msg>span:before{content:"\e028"}.fbx-close:before{content:"\e002"}.fbx-prev:before{content:"\e000"}.fbx-next:before{content:"\e001"}.fbx-loader>div:before{content:"\e012"}.fbx-flat .fbx-close:before{content:"\e117"}.fbx-flat .fbx-prev:before{content:"\e094"}.fbx-flat .fbx-next:before{content:"\e095"}.fbx-flat .fbx-loader>div:before{content:"\e105"}@-moz-keyframes spin{0%{-moz-transform:rotate(0)}100%{-moz-transform:rotate(359deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(359deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0)}100%{-o-transform:rotate(359deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0)}100%{-ms-transform:rotate(359deg)}}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(359deg)}}.fbx-rounded .fbx-prev.fbx-btn-shadow,.fbx-rounded .fbx-prev.fbx-btn-shadow:hover{-moz-box-shadow:-2px 0 2px #000;-moz-box-shadow:-2px 0 2px rgba(0,0,0,.8);-webkit-box-shadow:-2px 0 2px #000;-webkit-box-shadow:-2px 0 2px rgba(0,0,0,.8);box-shadow:-2px 0 2px #000;box-shadow:-2px 0 2px rgba(0,0,0,.8)}.fbx-rounded .fbx-next.fbx-btn-shadow,.fbx-rounded .fbx-next.fbx-btn-shadow:hover{-moz-box-shadow:2px 0 2px #000;-moz-box-shadow:2px 0 2px rgba(0,0,0,.8);-webkit-box-shadow:2px 0 2px #000;-webkit-box-shadow:2px 0 2px rgba(0,0,0,.8);box-shadow:2px 0 2px #000;box-shadow:2px 0 2px rgba(0,0,0,.8)}.fbx-fullscreen-mode .fbx-btn-shadow,.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow,.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow,.fbx-inner-shadow,.fbx-rounded .fbx-btn-shadow,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next.fbx-btn-shadow:before,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev.fbx-btn-shadow:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next.fbx-btn-shadow:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev.fbx-btn-shadow:before,.fbx-sticky-buttons .fbx-next.fbx-btn-shadow,.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow{-moz-box-shadow:0 0 12px #000;-moz-box-shadow:0 0 12px rgba(0,0,0,.8);-webkit-box-shadow:0 0 12px #000;-webkit-box-shadow:0 0 12px rgba(0,0,0,.8);box-shadow:0 0 12px #000;box-shadow:0 0 12px rgba(0,0,0,.8)}.fbx-fullscreen-mode .fbx-btn-shadow:hover,.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow:hover,.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow:hover,.fbx-rounded .fbx-btn-shadow:hover,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next.fbx-btn-shadow:hover:before,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev.fbx-btn-shadow:hover:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next.fbx-btn-shadow:hover:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev.fbx-btn-shadow:hover:before,.fbx-sticky-buttons .fbx-next.fbx-btn-shadow:hover,.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow:hover{-moz-box-shadow:0 0 6px #000;-moz-box-shadow:0 0 6px rgba(0,0,0,.8);-webkit-box-shadow:0 0 6px #000;-webkit-box-shadow:0 0 6px rgba(0,0,0,.8);box-shadow:0 0 6px #000;box-shadow:0 0 6px rgba(0,0,0,.8)}.fbx-flat .fbx-inner-shadow,.fbx-flat .fbx-rounded.fbx-inset-buttons .fbx-prev.fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-btn-shadow:hover,.fbx-flat.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow:hover,.fbx-flat.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow,.fbx-flat.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow:hover,.fbx-flat.fbx-sticky-buttons .fbx-next.fbx-btn-shadow,.fbx-flat.fbx-sticky-buttons .fbx-next.fbx-btn-shadow:hover,.fbx-flat.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow,.fbx-flat.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow:hover,.fbx-modal.fbx-phone.fbx-fullscreen-mode .fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-fullscreen-mode .fbx-next.fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-fullscreen-mode .fbx-prev.fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-rounded .fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-rounded.fbx-inset-buttons .fbx-next.fbx-btn-shadow:before,.fbx-modal.fbx-phone.fbx-rounded.fbx-inset-buttons .fbx-prev.fbx-btn-shadow:before,.fbx-modal.fbx-phone.fbx-sticky-buttons .fbx-next.fbx-btn-shadow,.fbx-modal.fbx-phone.fbx-sticky-buttons .fbx-prev.fbx-btn-shadow,.fbx-rounded.fbx-inset-buttons .fbx-next.fbx-btn-shadow{-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none}.fbx-rounded .fbx-inner{border:8px solid transparent;border-radius:6px}.fbx-rounded .fbx-item-current,.fbx-rounded .fbx-item-image,.fbx-rounded .fbx-item-next{border-radius:3px}.fbx-rounded .fbx-loader,.fbx-rounded .fbx-loader>div{border-radius:50%}.fbx-rounded .fbx-error-msg{margin-top:-115px}.fbx-rounded .fbx-close{top:-21px;right:-21px;width:28px;height:28px;line-height:28px;border:3px solid transparent;border-radius:50%}.fbx-rounded .fbx-next,.fbx-rounded .fbx-prev{position:absolute;top:50%;margin-top:-50px;width:30px;height:100px;line-height:100px;border:3px solid transparent}.fbx-rounded .fbx-prev{left:-40px;border-radius:6px 0 0 6px}.fbx-rounded .fbx-next{right:-40px;border-radius:0 6px 6px 0}.fbx-rounded.fbx-phone .fbx-next.fbx-disabled,.fbx-rounded.fbx-phone .fbx-prev.fbx-disabled{display:block;cursor:default}.fbx-rounded.fbx-phone .fbx-next.fbx-disabled:before,.fbx-rounded.fbx-phone .fbx-prev.fbx-disabled:before{opacity:0}.fbx-rounded.fbx-desktop .fbx-next,.fbx-rounded.fbx-desktop .fbx-prev{position:absolute}.fbx-rounded .fbx-count,.fbx-rounded .fbx-credit{bottom:-25px}.fbx-rounded .fbx-inner-spacer{padding:40px 40px 50px}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait .fbx-inner-spacer{padding:60px 5px 0}.fbx-rounded.fbx-sticky-buttons .fbx-next,.fbx-rounded.fbx-sticky-buttons .fbx-prev{position:fixed;top:50%;margin-top:-50px;width:40px;height:100px;line-height:100px}.fbx-rounded.fbx-sticky-buttons .fbx-prev{left:0;border-radius:0 6px 6px 0}.fbx-rounded.fbx-sticky-buttons .fbx-next{right:0;border-radius:6px 0 0 6px}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-inner-spacer{padding:40px 60px}.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-inner-spacer{padding:35px 5px 15px}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-inner-spacer{padding:5px}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{top:0;bottom:0;border-radius:0;width:4%;min-width:45px;height:auto;opacity:.3}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next:hover,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:hover{opacity:1}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next:before,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:before{position:fixed;width:4%;min-width:45px;height:30px;line-height:30px;top:50%;margin-top:-15px}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:before{left:0;right:auto}.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-sticky-buttons.fbx-full-buttons .fbx-next:before{left:auto;right:0}.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-next:before,.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:before{position:relative;width:auto;min-width:0;height:auto;line-height:inherit;top:auto;margin-top:auto}.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{top:0;bottom:auto;border-radius:0;width:auto;min-width:0;height:auto;opacity:1}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{left:0;right:66%}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-next{left:33%;right:33%}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-sticky-buttons.fbx-full-buttons .fbx-close{left:66%;right:0}.fbx-modal.fbx-rounded.fbx-phone.fbx-portrait.fbx-no-buttons.fbx-sticky-buttons.fbx-full-buttons .fbx-close{left:0;right:0}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{bottom:auto;width:34px;height:80px;opacity:.5}.fbx-rounded.fbx-phone.fbx-landscape.fbx-full-buttons .fbx-prev,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons .fbx-prev,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{top:62px}.fbx-rounded.fbx-phone.fbx-landscape.fbx-full-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons .fbx-next,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next{top:108px}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next:hover,.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev:hover{opacity:1}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-prev{border-radius:0 6px 6px 0}.fbx-rounded.fbx-phone.fbx-landscape.fbx-sticky-buttons.fbx-full-buttons .fbx-next{border-radius:6px 0 0 6px}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev{z-index:100003;position:absolute;top:0;bottom:0;height:100%;width:25%;margin:0;border-radius:0;background-color:transparent;box-sizing:border-box}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev{left:0}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next{right:0}.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-next:before,.fbx-rounded.fbx-inset-buttons.fbx-desktop .fbx-prev:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-next:before,.fbx-rounded.fbx-inset-buttons.fbx-tablet .fbx-prev:before{width:28px;height:28px;border-radius:50%;position:absolute;top:50%;margin-top:-14px;line-height:28px;border-width:3px;border-style:solid;opacity:0}.fbx-rounded.fbx-inset-buttons .fbx-prev:before{left:10px}.fbx-rounded.fbx-inset-buttons .fbx-next:before{right:10px}.fbx-rounded.fbx-inset-buttons .fbx-next:hover:before,.fbx-rounded.fbx-inset-buttons .fbx-prev:hover:before{opacity:1}.fbx-light,.fbx-light .fbx-caption,.fbx-light .fbx-open-caption,.fbx-light.fbx-phone .fbx-social{background-color:#000;background-color:rgba(0,0,0,.7)}.fbx-ie7.fbx-light,.fbx-ie7.fbx-light .fbx-caption,.fbx-ie8.fbx-light,.fbx-ie8.fbx-light .fbx-caption,.fbx-ie8.fbx-light.fbx-phone .fbx-social{background:0 0;-ms-filter:'progid:DXImageTransform.Microsoft.gradient(startColorstr=#26ffffff,endColorstr=#26ffffff)';filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#B2000000, endColorstr=#B2000000);zoom:1}.fbx-light .fbx-progress{background-color:#838383;background-color:rgba(255,255,255,.5)}.fbx-fullscreen-mode.fbx-light{background-color:#d3d3d3}.fbx-light .fbx-caption,.fbx-light .fbx-inner,.fbx-light .fbx-social,.fbx-light.fbx-inset-buttons .fbx-next:before,.fbx-light.fbx-inset-buttons .fbx-prev:before,.fbx-light.fbx-modal,.fbx-modal.fbx-light.fbx-phone .fbx-close:hover,.fbx-modal.fbx-light.fbx-phone .fbx-fullscreen-toggle:hover,.fbx-modal.fbx-light.fbx-phone .fbx-next:hover,.fbx-modal.fbx-light.fbx-phone .fbx-pause:hover,.fbx-modal.fbx-light.fbx-phone .fbx-play:hover,.fbx-modal.fbx-light.fbx-phone .fbx-prev:hover,.fbx-modal.fbx-light.fbx-phone .fbx-social-toggle:hover,.fbx-rounded.fbx-light .fbx-close,.fbx-rounded.fbx-light .fbx-fullscreen-toggle,.fbx-rounded.fbx-light .fbx-pause,.fbx-rounded.fbx-light .fbx-play,.fbx-rounded.fbx-light .fbx-social-toggle{border-color:#FFF}.fbx-light .fbx-close,.fbx-light .fbx-fullscreen-toggle,.fbx-light .fbx-inner,.fbx-light .fbx-loader,.fbx-light .fbx-next,.fbx-light .fbx-pause,.fbx-light .fbx-play,.fbx-light .fbx-prev,.fbx-light .fbx-social-toggle,.fbx-light.fbx-inset-buttons .fbx-next:before,.fbx-light.fbx-inset-buttons .fbx-prev:before{background-color:#FFF}.fbx-flat.fbx-light .fbx-close,.fbx-flat.fbx-light .fbx-fullscreen-toggle,.fbx-flat.fbx-light .fbx-next,.fbx-flat.fbx-light .fbx-pause,.fbx-flat.fbx-light .fbx-play,.fbx-flat.fbx-light .fbx-prev,.fbx-flat.fbx-light .fbx-social-toggle{background-color:transparent}.fbx-light .fbx-close,.fbx-light .fbx-error-msg,.fbx-light .fbx-fullscreen-toggle,.fbx-light .fbx-loader,.fbx-light .fbx-next,.fbx-light .fbx-pause,.fbx-light .fbx-play,.fbx-light .fbx-prev,.fbx-light .fbx-social-toggle,.fbx-light.fbx-inset-buttons .fbx-next:before,.fbx-light.fbx-inset-buttons .fbx-prev:before,.fbx-metro.fbx-light .fbx-count,.fbx-metro.fbx-light .fbx-credit a{color:#666!important}.fbx-flat.fbx-light .fbx-close,.fbx-flat.fbx-light .fbx-count,.fbx-flat.fbx-light .fbx-credit a,.fbx-flat.fbx-light .fbx-fullscreen-toggle,.fbx-flat.fbx-light .fbx-next,.fbx-flat.fbx-light .fbx-pause,.fbx-flat.fbx-light .fbx-play,.fbx-flat.fbx-light .fbx-prev,.fbx-flat.fbx-light .fbx-social-toggle{color:#FFF!important}.fbx-light .fbx-close:hover,.fbx-light .fbx-fullscreen-toggle:hover,.fbx-light .fbx-next:hover,.fbx-light .fbx-pause:hover,.fbx-light .fbx-play:hover,.fbx-light .fbx-prev:hover,.fbx-light .fbx-social-toggle:hover,.fbx-light.fbx-inset-buttons .fbx-next:hover:before,.fbx-light.fbx-inset-buttons .fbx-prev:hover:before,.fbx-metro.fbx-light .fbx-credit a:hover{color:#bababa!important}.fbx-metro.fbx-light .fbx-close:hover,.fbx-metro.fbx-light .fbx-fullscreen-toggle:hover,.fbx-metro.fbx-light .fbx-next:hover,.fbx-metro.fbx-light .fbx-pause:hover,.fbx-metro.fbx-light .fbx-play:hover,.fbx-metro.fbx-light .fbx-prev:hover,.fbx-metro.fbx-light .fbx-social-toggle:hover{border-color:#bababa}.fbx-rounded.fbx-light .fbx-count,.fbx-rounded.fbx-light .fbx-credit a{color:#888}.fbx-rounded.fbx-light .fbx-credit a:hover span{color:#ddd}.fbx-light .fbx-caption{color:#FFF}.fbx-light .fbx-caption-desc,.fbx-light .fbx-caption-desc a{color:#eee}.fbx-light .fbx-item-current::-webkit-scrollbar{width:12px;height:12px}.fbx-light .fbx-item-current::-webkit-scrollbar-track{background:rgba(0,0,0,.1)}.fbx-light .fbx-item-current::-webkit-scrollbar-thumb{background:rgba(0,0,0,.5)}.fbx-light .fbx-item-current::-webkit-scrollbar,.fbx-light .fbx-item-next::-webkit-scrollbar{width:12px;height:12px}.fbx-light .fbx-item-current::-webkit-scrollbar-track,.fbx-light .fbx-item-next::-webkit-scrollbar-track{background:rgba(0,0,0,.1)}.fbx-light .fbx-item-current::-webkit-scrollbar-corner,.fbx-light .fbx-item-current::-webkit-scrollbar-thumb,.fbx-light .fbx-item-next::-webkit-scrollbar-corner,.fbx-light .fbx-item-next::-webkit-scrollbar-thumb{background:rgba(0,0,0,.3)}.fbx-caption{position:absolute;top:auto;right:auto;bottom:0;left:0;z-index:100004;width:100%;text-align:center;font-size:14px;transition:visible .3s ease,opacity .3s ease,transform .3s ease;opacity:1;transform:translateY(0)}.fbx-loading .fbx-caption.fbx-hide-caption,.fbx-open-caption,.fbx-show .fbx-caption.fbx-hide-caption{visibility:hidden}.fbx-show .fbx-caption.fbx-fade-caption{opacity:0;visibility:hidden}.fbx-caption.fbx-slide-caption{transform:translateY(100%)}.fbx-fullscreen-mode .fbx-caption,.fbx-sticky-caption .fbx-caption{position:fixed;z-index:100007}.fbx-close-caption,.fbx-open-caption{position:absolute;color:#FFF;font-size:24px;text-decoration:none;line-height:20px}.fbx-rounded .fbx-caption{border-radius:0 0 3px 3px}.fbx-modal.fbx-phone .fbx-caption,.fbx-sticky-caption.fbx-rounded .fbx-caption{border-radius:0}.fbx-close-caption{top:0;right:0;padding:3px 3px 10px 10px}.fbx-open-caption{z-index:100004;bottom:0;right:5px;padding:0 10px 10px;opacity:0;transition:opacity .3s ease;border-top-left-radius:6px;border-top-right-radius:6px}.fbx-pannable-item.fbx-captions-hidden .fbx-open-caption{opacity:1;visibility:visible}.fbx-caption-title{font-size:15px;padding:15px}.fbx-caption-desc{font-size:12px;line-height:20px;padding:15px}.fbx-caption-desc a{font-size:12px}.fbx-caption-title+.fbx-caption-desc{margin-top:-30px}.fbx-phone .fbx-caption{min-height:20px;font-size:12px;line-height:20px}.fbx-phone .fbx-caption-title{font-size:13px;padding:10px}.fbx-phone .fbx-caption-desc{font-size:11px;line-height:15px;padding:10px}.fbx-phone .fbx-caption-title+.fbx-caption-desc{margin-top:-20px}.fbx-modal.fbx-phone .fbx-caption{z-index:100004;bottom:0;position:fixed}.fbx-modal.fbx-phone.fbx-landscape .fbx-caption,.fbx-phone.fbx-landscape.fbx-sticky-caption .fbx-caption{z-index:100004}.fbx-modal.fbx-phone.fbx-landscape .fbx-caption{border-right-width:46px;border-right-style:solid;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.fbx-modal.fbx-flat.fbx-phone.fbx-landscape .fbx-caption{border-right-width:0}.fbx-pannable{cursor:-moz-grab;cursor:-webkit-grab;cursor:grab}.fbx-pannable.fbx-panning{cursor:-moz-grabbing;cursor:-webkit-grabbing;cursor:grabbing}.fbx-pannable>div>img.fbx-item{max-width:none;max-height:none}.fbx-pan-overview{cursor:pointer;max-width:150px;max-height:150px;overflow:hidden;background-position:top left;background-size:cover;position:absolute;z-index:100006;border:2px solid #666;-moz-box-shadow:0 0 12px rgba(0,0,0,.8);-webkit-box-shadow:0 0 12px rgba(0,0,0,.8);box-shadow:0 0 12px rgba(0,0,0,.8)}.fbx-pan-overview.fbx-top-left{top:20px;left:20px}.fbx-pan-overview.fbx-top-right{top:20px;right:32px}.fbx-pan-overview.fbx-bottom-left{bottom:32px;left:20px}.fbx-pan-overview.fbx-bottom-right{bottom:32px;right:32px}.fbx-pan-viewport{position:absolute;top:0;left:0;box-shadow:0 0 300px 300px rgba(0,0,0,.7)}.fbx-ie7 .fbx-close{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e002')}.fbx-ie7 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e000')}.fbx-ie7 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e001')}.fbx-ie7.fbx-arrows-1 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01b')}.fbx-ie7.fbx-arrows-1 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01c')}.fbx-ie7.fbx-arrows-2 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01d')}.fbx-ie7.fbx-arrows-2 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01e')}.fbx-ie7.fbx-arrows-3 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01f')}.fbx-ie7.fbx-arrows-3 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e020')}.fbx-ie7.fbx-arrows-4 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e021')}.fbx-ie7.fbx-arrows-4 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e022')}.fbx-ie7.fbx-arrows-5 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e023')}.fbx-ie7.fbx-arrows-5 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e024')}.fbx-ie7.fbx-arrows-6 .fbx-prev{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e025')}.fbx-ie7.fbx-arrows-6 .fbx-next{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e026')}.fbx-ie7 .fbx-play{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e003')}.fbx-ie7 .fbx-pause{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e004')}.fbx-ie7 .fbx-fullscreen-toggle{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00e')}.fbx-fullscreen-mode.fbx-ie7 .fbx-fullscreen-toggle{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00d')}.fbx-ie7 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e012')}.fbx-ie7.fbx-spinner-1 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e005')}.fbx-ie7.fbx-spinner-2 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e011')}.fbx-ie7.fbx-spinner-3 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e027')}.fbx-ie7.fbx-spinner-4 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e013')}.fbx-ie7.fbx-spinner-5 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e014')}.fbx-ie7.fbx-spinner-6 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e015')}.fbx-ie7.fbx-spinner-7 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e016')}.fbx-ie7.fbx-spinner-8 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e017')}.fbx-ie7.fbx-spinner-9 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e018')}.fbx-ie7.fbx-spinner-10 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e019')}.fbx-ie7.fbx-spinner-11 .fbx-loader>div{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e01a')}.fbx-ie7 .fbx-facebook{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00a')}.fbx-ie7 .fbx-google-plus{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e006')}.fbx-ie7 .fbx-twitter{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e009')}.fbx-ie7 .fbx-pinterest{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e007')}.fbx-ie7 .fbx-linkedin{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e008')}.fbx-ie7 .fbx-buffer{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00b')}.fbx-ie7 .fbx-download{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e00f')}.fbx-ie7 .fbx-email{zoom:expression(this.runtimeStyle['zoom'] = '1',this.innerHTML = '\e010')}
free/includes/class-script-generator.php CHANGED
@@ -170,7 +170,7 @@ if ( !class_exists( 'FooBox_Free_Script_Generator' ) ) {
170
 
171
  $ready_event = 'FooBox.ready';
172
 
173
- $preload = ' //preload the foobox font
174
  jQuery("body").append("<span style=\"font-family:\'foobox\'; color:transparent; position:absolute; top:-1000em;\">f</span>");';
175
 
176
  $js .= '
170
 
171
  $ready_event = 'FooBox.ready';
172
 
173
+ $preload = '
174
  jQuery("body").append("<span style=\"font-family:\'foobox\'; color:transparent; position:absolute; top:-1000em;\">f</span>");';
175
 
176
  $js .= '
free/includes/upgrade.php CHANGED
@@ -1,33 +1,33 @@
1
- <div id="foobox-free-upgrade">
2
- <ul class="foobox_features">
3
- <li>Social sharing</li>
4
- <li>Video support</li>
5
- <li>HTML support</li>
6
- <li>iFrame support</li>
7
- <li>Deeplinking</li>
8
- <li>Fullscreen mode</li>
9
- <li>Built-in slideshow</li>
10
- <li>Metro lightbox style</li>
11
- <li><strong>4</strong> more color schemes</li>
12
- <li><strong>11</strong> more button icons</li>
13
- <li><strong>10</strong> more loader icons</li>
14
- </ul>
15
-
16
- <p>Out of the box support for the following galleries and plugins...</p>
17
- <ul class="foobox_features tick2">
18
- <li>FooGallery</li>
19
- <li>Justified Image Grid</li>
20
- <li>JetPack Tiled Gallery</li>
21
- <li>NextGen</li>
22
- <li>WooCommerce product images</li>
23
- <li>Envira Gallery</li>
24
- </ul>
25
-
26
- <p>And also don't forget...</p>
27
- <ul class="foobox_features single_column tick3">
28
- <li>FooBox is actively developed and updated regularly</li>
29
- <li>Fast and friendly premium support</li>
30
- <li>A license to suit your budget</li>
31
- <li>85+ settings to customize to your heart's content</li>
32
- </ul>
33
  </div>
1
+ <div id="foobox-free-upgrade">
2
+ <ul class="foobox_features">
3
+ <li>Social sharing</li>
4
+ <li>Video support</li>
5
+ <li>HTML support</li>
6
+ <li>iFrame support</li>
7
+ <li>Deeplinking</li>
8
+ <li>Fullscreen mode</li>
9
+ <li>Built-in slideshow</li>
10
+ <li>Metro lightbox style</li>
11
+ <li><strong>4</strong> more color schemes</li>
12
+ <li><strong>11</strong> more button icons</li>
13
+ <li><strong>10</strong> more loader icons</li>
14
+ </ul>
15
+
16
+ <p>Out of the box support for the following galleries and plugins...</p>
17
+ <ul class="foobox_features tick2">
18
+ <li>FooGallery</li>
19
+ <li>Justified Image Grid</li>
20
+ <li>JetPack Tiled Gallery</li>
21
+ <li>NextGen</li>
22
+ <li>WooCommerce product images</li>
23
+ <li>Envira Gallery</li>
24
+ </ul>
25
+
26
+ <p>And also don't forget...</p>
27
+ <ul class="foobox_features single_column tick3">
28
+ <li>FooBox is actively developed and updated regularly</li>
29
+ <li>Fast and friendly premium support</li>
30
+ <li>A license to suit your budget</li>
31
+ <li>85+ settings to customize to your heart's content</li>
32
+ </ul>
33
  </div>
free/includes/view-getting-started.php CHANGED
@@ -1,5 +1,11 @@
1
  <?php
2
  $foogallery_url = 'http://foo.gallery?utm_source=foobox_free_plugin&utm_medium=foobox_free_link&utm_campaign=foobox_free_admin_getting_started';
 
 
 
 
 
 
3
  ?>
4
  <style>
5
  .feature-section .dashicons {
@@ -13,17 +19,13 @@ $foogallery_url = 'http://foo.gallery?utm_source=foobox_free_plugin&utm_medium=f
13
  <?php _e( 'Getting Started', 'foobox-image-lightbox' ); ?>
14
  </a>
15
  <a class="nav-tab" href="#pro-features">
16
- <?php _e( 'FooBox PRO Features', 'foobox-image-lightbox' ); ?>
17
  </a>
18
  <a class="nav-tab" href="#demo">
19
  <?php _e( 'Demo', 'foobox-image-lightbox' ); ?>
20
  </a>
21
  </h2>
22
  <div id="getting-started_tab" class="feature-section nav-container">
23
- <div>
24
- <h2 style="font-weight: 800"><?php _e( '*** Important Update Message ***', 'foobox-image-lightbox' );?></h2>
25
- <p><?php _e( 'A friendly reminder that if you use a caching plugin and have just updated from an older version of FooBox, then <strong>please clear your site cache!</strong> The internal file structure of FooBox has changed, and not clearing your site cache might cause 404 errors!', 'foobox-image-lightbox' );?></p>
26
- </div>
27
  <div>
28
  <h2><?php _e( 'Zero Configuration', 'foobox-image-lightbox' );?></h2>
29
  <p><?php _e( 'FooBox FREE works out-of-the-box with the following standard features:', 'foobox-image-lightbox' );?></p>
@@ -77,6 +79,13 @@ $foogallery_url = 'http://foo.gallery?utm_source=foobox_free_plugin&utm_medium=f
77
  </div>
78
  </div>
79
  <div id="pro-features_tab" class="feature-section nav-container" style="display: none">
 
 
 
 
 
 
 
80
  <div id="foobox-free-upgrade">
81
  <h2><?php _e( 'PRO Features', 'foobox-image-lightbox' );?></h2>
82
  <p><span class="dashicons dashicons-yes"></span><strong><?php _e( 'ALL content types', 'foobox-image-lightbox' ); ?></strong> - <?php _e( 'Images, galleries, videos, iframes, html. You name it, FooBox can open it.', 'foobox-image-lightbox' ); ?>
@@ -87,7 +96,7 @@ $foogallery_url = 'http://foo.gallery?utm_source=foobox_free_plugin&utm_medium=f
87
  <p><span class="dashicons dashicons-yes"></span><strong><?php _e( 'Slideshow Mode', 'foobox-image-lightbox' ); ?></strong> - <?php _e( 'Turn your gallery into a media slideshow, with autoplay.', 'foobox-image-lightbox' ); ?>
88
 
89
  <?php if ( !foobox_hide_pricing_menu() ) { ?>
90
- <h4><?php printf( '<a href="%s">%s</a>', esc_url ( foobox_pricing_url() ), __( 'Upgrade to FooBox PRO!', 'foobox-image-lightbox' ) ); ?></h4>
91
  <?php } ?>
92
 
93
  <h2><?php _e( 'Optimized Asset Loading', 'foobox-image-lightbox' ); ?></h2>
@@ -126,6 +135,9 @@ $foogallery_url = 'http://foo.gallery?utm_source=foobox_free_plugin&utm_medium=f
126
  );
127
  ?>
128
  <style>
 
 
 
129
  .demo-gallery a
130
  {
131
  display: inline-block;
1
  <?php
2
  $foogallery_url = 'http://foo.gallery?utm_source=foobox_free_plugin&utm_medium=foobox_free_link&utm_campaign=foobox_free_admin_getting_started';
3
+
4
+ $fs_instance = freemius( FOOBOX_BASE_SLUG );
5
+ $show_trial_message = !$fs_instance->is_trial_utilized();
6
+ $tab_text = $show_trial_message ? __( 'Free Trial', 'foobox-image-lightbox' ) : __( 'Upgrade to PRO', 'foobox-image-lightbox' );
7
+ $button_text = $show_trial_message ? __( 'Already convinced? Upgrade to PRO!', 'foobox-image-lightbox' ) : __( 'Upgrade to PRO!', 'foobox-image-lightbox' );
8
+
9
  ?>
10
  <style>
11
  .feature-section .dashicons {
19
  <?php _e( 'Getting Started', 'foobox-image-lightbox' ); ?>
20
  </a>
21
  <a class="nav-tab" href="#pro-features">
22
+ <?php echo $tab_text; ?>
23
  </a>
24
  <a class="nav-tab" href="#demo">
25
  <?php _e( 'Demo', 'foobox-image-lightbox' ); ?>
26
  </a>
27
  </h2>
28
  <div id="getting-started_tab" class="feature-section nav-container">
 
 
 
 
29
  <div>
30
  <h2><?php _e( 'Zero Configuration', 'foobox-image-lightbox' );?></h2>
31
  <p><?php _e( 'FooBox FREE works out-of-the-box with the following standard features:', 'foobox-image-lightbox' );?></p>
79
  </div>
80
  </div>
81
  <div id="pro-features_tab" class="feature-section nav-container" style="display: none">
82
+ <?php if ( $show_trial_message ) { ?>
83
+ <div>
84
+ <h2><?php _e( 'FooBox PRO Free Trial', 'foobox-image-lightbox' );?></h2>
85
+ <p><?php _e( 'Want to test out all the PRO features? No problem! You can start a 7-day free trial immediately. No credit card is required!', 'foobox-image-lightbox' );?></p>
86
+ <h4><?php printf( '<a href="%s">%s</a>', esc_url ( foobox_freetrial_url() ), __( 'Start Your 7-day Free Trial', 'foobox-image-lightbox' ) ); ?></h4>
87
+ </div>
88
+ <?php } ?>
89
  <div id="foobox-free-upgrade">
90
  <h2><?php _e( 'PRO Features', 'foobox-image-lightbox' );?></h2>
91
  <p><span class="dashicons dashicons-yes"></span><strong><?php _e( 'ALL content types', 'foobox-image-lightbox' ); ?></strong> - <?php _e( 'Images, galleries, videos, iframes, html. You name it, FooBox can open it.', 'foobox-image-lightbox' ); ?>
96
  <p><span class="dashicons dashicons-yes"></span><strong><?php _e( 'Slideshow Mode', 'foobox-image-lightbox' ); ?></strong> - <?php _e( 'Turn your gallery into a media slideshow, with autoplay.', 'foobox-image-lightbox' ); ?>
97
 
98
  <?php if ( !foobox_hide_pricing_menu() ) { ?>
99
+ <h4><?php printf( '<a href="%s">%s</a>', esc_url ( foobox_pricing_url() ), $button_text ); ?></h4>
100
  <?php } ?>
101
 
102
  <h2><?php _e( 'Optimized Asset Loading', 'foobox-image-lightbox' ); ?></h2>
135
  );
136
  ?>
137
  <style>
138
+ .about-wrap .feature-section p.demo-gallery {
139
+ max-width: 40em;
140
+ }
141
  .demo-gallery a
142
  {
143
  display: inline-block;
free/js/admin-foobox_page_foobox-settings.js CHANGED
@@ -1,67 +1,67 @@
1
- jQuery(document).ready(function($) {
2
- $.admin_tabs = {
3
-
4
- init : function() {
5
- $("a.nav-tab").click( function(e) {
6
- e.preventDefault();
7
-
8
- $this = $(this);
9
-
10
- $this.parents(".nav-tab-wrapper:first").find(".nav-tab-active").removeClass("nav-tab-active");
11
- $this.addClass("nav-tab-active");
12
-
13
- $(".nav-container:visible").hide();
14
-
15
- var hash = $this.attr("href");
16
-
17
- $(hash+'_tab').show();
18
-
19
- //fix the referer so if changes are saved, we come back to the same tab
20
- var referer = $("input[name=_wp_http_referer]").val();
21
- if (referer.indexOf("#") >= 0) {
22
- referer = referer.substr(0, referer.indexOf("#"));
23
- }
24
- referer += hash;
25
-
26
- window.location.hash = hash;
27
-
28
- $("input[name=_wp_http_referer]").val(referer);
29
- });
30
-
31
- if (window.location.hash) {
32
- $('a.nav-tab[href="' + window.location.hash + '"]').click();
33
- }
34
-
35
- return false;
36
- }
37
-
38
- }; //End of admin_tabs
39
-
40
- $.admin_tabs.init();
41
-
42
- $('.radio_selector a').click(function(e) {
43
- var $div = $(this).parents('.radio_selector:first');
44
- $div.find('a').removeClass('selected');
45
- var inputId = $(this).parents('label:first').attr('for');
46
- $('#' + inputId).click();
47
- $(this).addClass('selected');
48
- });
49
-
50
- //$('.foobox-colorpicker').minicolors();
51
-
52
- $('.foobox_insert_code').click(function(e) {
53
- e.preventDefault();
54
-
55
- var $target = $( $(this).attr('href') );
56
- var code = $(this).data('code');
57
-
58
- if ( $target.val() !== '' ) {
59
- if (!confirm('The existing text will be overwritten. Proceed?')) {
60
- return;
61
- }
62
- }
63
-
64
- $target.val(code);
65
- });
66
-
67
  });
1
+ jQuery(document).ready(function($) {
2
+ $.admin_tabs = {
3
+
4
+ init : function() {
5
+ $("a.nav-tab").click( function(e) {
6
+ e.preventDefault();
7
+
8
+ $this = $(this);
9
+
10
+ $this.parents(".nav-tab-wrapper:first").find(".nav-tab-active").removeClass("nav-tab-active");
11
+ $this.addClass("nav-tab-active");
12
+
13
+ $(".nav-container:visible").hide();
14
+
15
+ var hash = $this.attr("href");
16
+
17
+ $(hash+'_tab').show();
18
+
19
+ //fix the referer so if changes are saved, we come back to the same tab
20
+ var referer = $("input[name=_wp_http_referer]").val();
21
+ if (referer.indexOf("#") >= 0) {
22
+ referer = referer.substr(0, referer.indexOf("#"));
23
+ }
24
+ referer += hash;
25
+
26
+ window.location.hash = hash;
27
+
28
+ $("input[name=_wp_http_referer]").val(referer);
29
+ });
30
+
31
+ if (window.location.hash) {
32
+ $('a.nav-tab[href="' + window.location.hash + '"]').click();
33
+ }
34
+
35
+ return false;
36
+ }
37
+
38
+ }; //End of admin_tabs
39
+
40
+ $.admin_tabs.init();
41
+
42
+ $('.radio_selector a').click(function(e) {
43
+ var $div = $(this).parents('.radio_selector:first');
44
+ $div.find('a').removeClass('selected');
45
+ var inputId = $(this).parents('label:first').attr('for');
46
+ $('#' + inputId).click();
47
+ $(this).addClass('selected');
48
+ });
49
+
50
+ //$('.foobox-colorpicker').minicolors();
51
+
52
+ $('.foobox_insert_code').click(function(e) {
53
+ e.preventDefault();
54
+
55
+ var $target = $( $(this).attr('href') );
56
+ var code = $(this).data('code');
57
+
58
+ if ( $target.val() !== '' ) {
59
+ if (!confirm('The existing text will be overwritten. Proceed?')) {
60
+ return;
61
+ }
62
+ }
63
+
64
+ $target.val(code);
65
+ });
66
+
67
  });
free/js/foobox.free.min.js CHANGED
@@ -6,5 +6,5 @@
6
  * @license Released under the MIT license.
7
  * You are free to use FooBox jQuery in personal projects as long as this copyright header is left intact.
8
  */
9
- !function(a,b,c,undefined){if(a&&b){b.FooBox={defaults:{affiliate:{enabled:!0,prefix:"Powered by ",url:"http://fooplugins.com/plugins/foobox/"},alwaysInit:!1,closeOnOverlayClick:!0,containerCssClass:"fbx-instance",countMessage:"item %index of %total",error:"Could not load the item",excludes:".fbx-link, .nofoobox",externalSelector:"a[data-foobox],input[data-foobox]",fitToScreen:!1,hideScrollbars:!0,loadDelay:0,loaderTimeout:600,modalClass:"",preload:!1,rel:null,resizeSpeed:300,selector:"a",showButtons:!0,showCount:!0,style:"fbx-rounded",theme:"fbx-light",transitionInSpeed:200,transitionOutSpeed:200,initCallback:null,loop:!0},version:"2.0.10",instances:[],ready:function(b){(Function("/*@cc_on return true@*/")()?"complete"===document.readyState:"loading"!==document.readyState)?b(a):setTimeout(function(){FooBox.ready(b)},1)}},FooBox.$=a,FooBox.format=function(a,b,c){var d,e,f=arguments[0];for(d=0;d<arguments.length-1;d++)e=new RegExp("\\{"+d+"\\}","gm"),f=f.replace(e,arguments[d+1]);return f},FooBox.browser={isIE:!1,isChrome:!1,isSafari:!1,version:0,css:"",iOS:!1,Mac:!1,isMobile:function(a){return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))}(navigator.userAgent||navigator.vendor||b.opera),check:function(){var a=navigator.appVersion.toLowerCase(),b=navigator.userAgent.toLowerCase(),c=navigator.platform;FooBox.browser.iOS=/(iPad|iPhone|iPod)/g.test(c),1==FooBox.browser.iOS&&(FooBox.browser.css+=" fbx-ios"),FooBox.browser.Mac=/(Mac)/g.test(c),1==FooBox.browser.Mac&&(FooBox.browser.css+=" fbx-mac"),FooBox.browser.isChrome=a.indexOf("chrome")>-1||a.indexOf("crios")>-1,FooBox.browser.isChrome&&(FooBox.browser.css+=" fbx-chrome"),FooBox.browser.isSafari=a.indexOf("safari")>-1&&!FooBox.browser.isChrome,FooBox.browser.isSafari&&(FooBox.browser.css+=" fbx-safari"),FooBox.browser.isFirefox=b.indexOf("firefox")>-1,FooBox.browser.isFirefox&&(FooBox.browser.css+=" fbx-firefox");var d=b.indexOf("msie "),e=b.indexOf("trident/"),f=b.indexOf("edge/");if(FooBox.browser.isIE=d>-1||e>-1||f>-1,FooBox.browser.isIE){if(d>-1)FooBox.browser.version=parseInt(b.substring(d+5,b.indexOf(".",d)),10);else if(e>-1){var g=b.indexOf("rv:");FooBox.browser.version=parseInt(b.substring(g+3,b.indexOf(".",g)),10)}else f>-1&&(FooBox.browser.version=parseInt(b.substring(f+5,b.indexOf(".",f)),10));FooBox.browser.css=FooBox.format("fbx-ie fbx-ie{0}",FooBox.browser.version)}},supportsTransitions:function(){var a,b=document.body||document.documentElement,c=b.style,d="transition";if("string"==typeof c[d])return!0;a=["Moz","Webkit","Khtml","O","ms"],d=d.charAt(0).toUpperCase()+d.substr(1);for(var e=0;e<a.length;e++)if("string"==typeof c[a[e]+d])return!0;return!1},transitionEnd:function(){var a,b=document.createElement("fakeelement"),c={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(a in c)if(c.hasOwnProperty(a)&&b.style[a]!==undefined)return c[a];return null}},FooBox.browser.check(),FooBox.qualifiedURL=function(a){var b=document.createElement("a");return b.href=a,b.href},c||(c={}),c.log=c.log||function(){},c.warn=c.warn||function(){},c.error=c.error||function(){},c.info=c.info||function(){};var d={write:function(){c.log(FooBox.format.apply(d,arguments))},error:function(){1===arguments.length&&arguments[0]instanceof Error?c.error(arguments[0]):c.error(FooBox.format.apply(d,arguments))}};jQuery.Event.prototype.fb={instance:null,modal:null,options:null},FooBox.raise=function(b,c,d){d=d||{};var e=a.Event(c);return e.fb={},e.fb.instance=b,e.fb.modal=b.modal.element,e.fb.options=b.options,a.extend(!0,e.fb,d),b.element.one(c,function(a){a.stopPropagation()}).trigger(e),e},FooBox.isjQuery=function(a){return a instanceof jQuery?!0:a&&a.jquery},FooBox.options={isMultipart:function(a,b){return"string"==typeof a&&a.length>0&&-1!==a.indexOf(b)},hasProperties:function(a){if("object"!=typeof a)return!1;var b;for(b in a)if(a.hasOwnProperty(b))return!0;return!1},get:function(a,b){if(FooBox.options.isMultipart(b,".")){var c=b.substring(0,b.indexOf(".")),d=b.substring(b.indexOf(".")+1);return a[c]=a[c]||{},FooBox.options.get(a[c],d)}return a[b]},set:function(a,b,c){if(FooBox.options.isMultipart(b,".")){var d=b.substring(0,b.indexOf(".")),e=b.substring(b.indexOf(".")+1);a[d]=a[d]||{},FooBox.options.set(a[d],e,c)}else a[b]=c},merge:function(a,b,c){var d,e=Array.prototype.slice.call(arguments);for(a=e.shift(),b=e.shift(),FooBox.options._merge(a,b),d=0;d<e.length;d++)c=e[d],FooBox.options._merge(a,c);return a},_merge:function(b,c){var d;for(d in c)c.hasOwnProperty(d)&&(FooBox.options.hasProperties(c[d])&&!a.isArray(c[d])?(b[d]=b[d]||{},FooBox.options._merge(b[d],c[d])):a.isArray(c[d])?(b[d]=[],a.extend(!0,b[d],c[d])):b[d]=c[d])}},FooBox.objects={registered:{},ensure:function(a){return FooBox.objects.registered[a]=FooBox.objects.registered[a]||[]},register:function(b,c,d){var e=FooBox.objects.ensure(b);return e.push(c),"object"==typeof d&&a.extend(!0,FooBox.defaults,d),!0},load:function(a,b){var c,e,f=[],g=FooBox.objects.ensure(a);for(e=0;e<g.length;e++)try{c=g[e],f.push(new c(b))}catch(h){d.error(h)}b.objects=b.objects||{},b.objects[a]=f},call:function(b,c,e,f,g){var h,i=Array.prototype.slice.call(arguments);b=i.shift(),c=i.shift(),e=i.shift();for(var j=c.objects[b]||[],k=0;k<j.length;k++)try{if(h=j[k],!a.isFunction(h[e]))continue;h[e].apply(h,i)}catch(l){d.error(l)}},get:function(b,c,d){var e,f=c.objects[b];if(!f||!a.isFunction(d))return null;for(e=0;e<f.length;e++)if(d(f[e]))return f[e];return null}},FooBox.addons={_ns:"addons",validate:function(b){return a.isFunction(b)?!0:(d.error('Expected type "function", received type "{0}".',typeof b),!1)},register:function(a,b){return FooBox.addons.validate(a)?FooBox.objects.register(FooBox.addons._ns,a,b):(d.error("Failed to register the addon."),!1)},load:function(a){FooBox.objects.load(FooBox.addons._ns,a)},call:function(a,b,c,d){var e=Array.prototype.slice.call(arguments);e.unshift(FooBox.addons._ns),FooBox.objects.call.apply(this,e)}},FooBox.handlers={_ns:"handlers",validate:function(b){if(!a.isFunction(b))return d.error('Expected type "function", received type "{0}".',typeof b),!1;var c=new b;return a.isFunction(c.handles)?a.isFunction(c.defaults)?a.isFunction(c.parse)?a.isFunction(c.load)?a.isFunction(c.getSize)?a.isFunction(c.hasChanged)?a.isFunction(c.preload)?!0:(d.error('The required "preload" method is not implemented.'),!1):(d.error('The required "hasChanged" method is not implemented.'),!1):(d.error('The required "getSize" method is not implemented.'),!1):(d.error('The required "load" method is not implemented.'),!1):(d.error('The required "parse" method is not implemented.'),!1):(d.error('The required "defaults" method is not implemented.'),!1):(d.error('The required "handles" method is not implemented.'),!1)},register:function(a,b){return FooBox.handlers.validate(a)?FooBox.objects.register(FooBox.handlers._ns,a,b):(d.error("Failed to register the handler."),!1)},load:function(a){FooBox.objects.load(FooBox.handlers._ns,a)},call:function(a,b,c,d){var e=Array.prototype.slice.call(arguments);e.unshift(FooBox.handlers._ns),FooBox.objects.call.apply(this,e)},get:function(a,b){return FooBox.objects.get(FooBox.handlers._ns,a,function(a){return a.type==b})}},FooBox.Item=function(b,c,d){return this.type=b,this.element=FooBox.isjQuery(c)?c:a(c),this.handler=d,this.width=null,this.height=null,this.url=null,this.overflow=!1,this.preloaded=!1,this.proportion=!1,this.error=!1,this},FooBox.Size=function(a,b){return this.width="number"==typeof a?a:parseInt(a,0),this.height="number"==typeof b?b:parseInt(b,0),this.equalTo=function(a){return this.width==a.width&&this.height==a.height},this},FooBox.Timer=function(){this.id=null,this.busy=!1;var a=this;return this.start=function(b,c,d){d=d||b,a.stop(),a.id=setTimeout(function(){b.call(d),a.id=null,a.busy=!1},c),a.busy=!0},this.stop=function(){null!==a.id&&a.busy!==!1&&(clearTimeout(a.id),a.id=null,a.busy=!1)},this},a.fn.foobox=function(b){return b=b||{},this.each(function(){var c=a(this).data("fbx_instance");if(c instanceof FooBox.Instance)if(1==c.options.alwaysInit){var d=c.options;c.destroy(),c=new FooBox.Instance(c.id),c.init(this,a.extend(!0,d,b))}else c.reinit(b);else{if(c=a(this).data("fbx_p_instance"),c instanceof FooBox.Instance)return;c=new FooBox.Instance,c.init(this,b)}})},FooBox.Modal=function(b){this.FooBox=b,this.element=null,this.loaderTimeout=new FooBox.Timer,this._first=!1,this._busy=!1,this._closed=!1;var c=this;return this.init=function(a,b){c.setup.html(),c.setup.options(b),c.setup.bind()},this.reinit=function(a){c.setup.options(a)},this.destroy=function(){FooBox.isjQuery(c.element)&&c.element.remove()},this.setup={html:function(){if(!FooBox.isjQuery(c.element)){c.element=a('<div class="fbx-modal"></div>'),c.element.append('<div class="fbx-inner-spacer"></div>');var b=a('<div class="fbx-stage"></div>');b.append('<div class="fbx-item-current"></div>'),b.append('<div class="fbx-item-next"></div>');var d=a('<div class="fbx-inner fbx-inner-shadow"></div>');d.append(b),d.append('<a href="#prev" class="fbx-prev fbx-btn-transition fbx-btn-shadow"></a>'),d.append('<div class="fbx-credit"><a target="_blank" href=""><em></em><span> FooBox</span></a></div>'),d.append('<span class="fbx-count" />'),d.append('<a href="#next" class="fbx-next fbx-btn-transition fbx-btn-shadow"></a>'),d.append('<a href="#close" class="fbx-close fbx-btn-transition fbx-btn-shadow"></a>'),c.element.append('<div class="fbx-loader"><div></div></div>'),c.element.append(d),c.FooBox.raise("foobox.setupHtml"),a("body").append(c.element)}},options:function(a){var b;c.element.removeClass().addClass("fbx-modal").addClass(FooBox.format("fbx-{0}",c.FooBox.id)).addClass(c.FooBox.element.data("style")||a.style).addClass(c.FooBox.element.data("theme")||a.theme).addClass(c.FooBox.element.data("modal-class")).addClass(a.modalClass).data("fbx_instance",c.FooBox),c.element.addClass(FooBox.browser.css),b=a.affiliate.enabled?"":"none",c.element.find(".fbx-credit").css("display",b),a.affiliate.enabled&&(c.element.find(".fbx-credit > a").attr("href",a.affiliate.url),c.element.find(".fbx-credit > a > em").text(a.affiliate.prefix)),b=a.showCount&&c.FooBox.items.multiple()?"":"none",c.element.find(".fbx-count").css("display",b),a.showButtons&&c.FooBox.items.multiple()||c.element.addClass("fbx-no-buttons"),c.FooBox.raise("foobox.setupOptions")},bind:function(){1==c.FooBox.options.closeOnOverlayClick&&c.element.unbind("click.foobox").bind("click.foobox",function(b){1==c.FooBox.options.closeOnOverlayClick&&a(b.target).is(".fbx-modal")&&c.close()}),c.element.find(".fbx-close").unbind("click.foobox").bind("click.foobox",function(a){a.preventDefault(),a.stopPropagation(),c.close()}).end().find(".fbx-prev").unbind("click.foobox").bind("click.foobox",function(b){b.preventDefault(),b.stopPropagation(),a(this).hasClass("fbx-disabled")||c.prev()}).end().find(".fbx-next").unbind("click.foobox").bind("click.foobox",function(b){b.preventDefault(),b.stopPropagation(),a(this).hasClass("fbx-disabled")||c.next()})}},this.prioritize=function(){FooBox.instances.length>1&&c.element.nextAll(".fbx-modal:last").after(c.element)},this.preload=function(){if(1==c.FooBox.options.preload){var a=c.FooBox.items.prev();a&&a.handler.preload(a);var b=c.FooBox.items.next();b&&b.handler.preload(b)}},this.show=function(b){function e(a){if(c.loaderTimeout.stop(),c.element.removeClass("fbx-loading"),c._busy=!1,d.error(a),!c.FooBox.raise("foobox.onError",{error:a}).isDefaultPrevented()){var e=c.FooBox.items.error(f.index);null!=e&&c.show(b)}}b=b||!1,c._first=b,c._busy=!0,c._closed=!1,a("body").addClass("fbx-active"),c.FooBox.options.hideScrollbars&&a("html").css("overflow","hidden");var f=c.FooBox.items.current();1==f.error?c.element.addClass("fbx-error"):c.element.removeClass("fbx-error"),c.element.hasClass("fbx-show")||(c.prioritize(),c.element.addClass("fbx-loading").find(".fbx-inner").css({width:"100px",height:"100px","margin-top":"-50px","margin-left":"-50px"}));var g=c.element.find(".fbx-item-current"),h=c.element.find(".fbx-item-next");if(h.hide().css("opacity","0"),c.element.find(".fbx-count").text(c.FooBox.options.countMessage.replace("%index",""+(c.FooBox.items.indexes.current+1)).replace("%total",""+c.FooBox.items.array.length)),c.FooBox.raise("foobox.beforeLoad",{item:f}).isDefaultPrevented())return void(c._busy=!1);if(f.handler.hasChanged(f)){var i=f.index,j=f.element.get(0);f=f.handler.parse(f.element);var k=c.FooBox.raise("foobox.parseItem",{element:f.element,item:f});j.index=k.fb.item.index=i,c.FooBox.items.array[i]=k.fb.item}c.preload(),c.loaderTimeout.start(function(){c.element.addClass("fbx-loading")},c.FooBox.options.loaderTimeout),setTimeout(function(){c.checkForLoop(f),f.handler.load(f,h,function(a){return 1==c._closed?void(c._busy=!1):void c.transitionOut(g,function(){return 1==c._closed?void(c._busy=!1):void c.resize(a,h,function(){return 1==c._closed?void(c._busy=!1):(c.loaderTimeout.stop(),h.show(),void c.transitionIn(h,function(){return 1==c._closed?void(c._busy=!1):(h.add(g).toggleClass("fbx-item-next fbx-item-current"),g.empty(),void(c.element.hasClass("fbx-show")?(c.element.removeClass("fbx-loading"),c.FooBox.raise("foobox.afterLoad",{item:f}),c._busy=!1):c.FooBox.raise("foobox.beforeShow",{item:f}).isDefaultPrevented()||(c.element.removeClass("fbx-loading").addClass("fbx-show"),c.FooBox.raise("foobox.afterShow",{item:f}),c.FooBox.raise("foobox.afterLoad",{item:f}),c._busy=!1)))},e))},e)},e)},e)},c.FooBox.options.loadDelay)},this.checkForLoop=function(a){1!=c.FooBox.options.loop&&(c.element.find(".fbx-prev, .fbx-next").removeClass("fbx-disabled"),c.FooBox.items.is.first(a)&&c.element.find(".fbx-prev").addClass("fbx-disabled"),c.FooBox.items.is.last(a)&&c.element.find(".fbx-next").addClass("fbx-disabled"))},this.resize=function(b,d,e,f){try{if(0===b.width||0===b.height)return void(a.isFunction(f)&&f(FooBox.format("Invalid size supplied. Width = {0}, Height = {1}",b.width,b.height)));var g=c.FooBox.items.current(),h=c.element.find(".fbx-inner"),i=c.element.find(".fbx-inner-spacer"),j=parseInt(i.css("padding-top"),0),k=parseInt(i.css("padding-bottom"),0),l=parseInt(i.css("padding-left"),0),m=parseInt(i.css("padding-right"),0),n=parseInt(h.css("border-top-width"),0),o=parseInt(h.css("border-bottom-width"),0),p=parseInt(h.css("border-left-width"),0),q=parseInt(h.css("border-right-width"),0),r=parseInt(h.css("padding-left"),0),s=j+k+2*r+n+o,t=l+m+2*r+p+q,u=new FooBox.Size(parseInt(h.css("width"),0),parseInt(h.css("height"),0)),v=new FooBox.Size(c.element.width()-t,c.element.height()-s),w=v.width/b.width;b.height*w>v.height&&(w=v.height/b.height),c.FooBox.options.fitToScreen===!0||1==g.proportion&&(b.height>v.height||b.width>v.width)?(b.height=Math.floor(b.height*w),b.width=Math.floor(b.width*w)):0==g.proportion&&(b.height>v.height&&(b.height=v.height),b.width>v.width&&(b.width=v.width)),b.height<100&&(b.height=100),b.width<100&&(b.width=100);var x=-(b.height/2+r+(k-j/2)/2)+(p+q)/2,y=-(b.width/2+r+(p+q)/2);if(u.equalTo(b))h.css({height:b.height,width:b.width,"margin-top":x,"margin-left":y}),c.overflow(g,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e();else if(!c.FooBox.raise("foobox.beforeResize",{item:g,size:b,offset:{top:x,left:y},error:f,success:e}).isDefaultPrevented())if(c.element.hasClass("fbx-show"))if(FooBox.browser.supportsTransitions()){var z=c.FooBox.options.resizeSpeed/1e3,A="all "+z+"s ease-in-out";h.css({WebkitTransition:A,MozTransition:A,MsTransition:A,OTransition:A,transition:A}),h.css({height:b.height,width:b.width,"margin-top":x,"margin-left":y}),setTimeout(function(){h.css({WebkitTransition:"",MozTransition:"",MsTransition:"",OTransition:"",transition:""}),c.overflow(g,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e(b)},c.FooBox.options.resizeSpeed)}else h.animate({height:b.height,width:b.width,"margin-top":x,"margin-left":y},c.FooBox.options.resizeSpeed,function(){c.overflow(g,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e(b)});else h.css({height:b.height,width:b.width,"margin-top":x,"margin-left":y}),c.overflow(g,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e()}catch(B){a.isFunction(f)&&f(B)}},this.overflow=function(a,b,d){var e=d.find(".fbx-item");1==a.overflow&&(b.width<.8*a.width||b.height<.8*a.height)||1==a.overflow&&0==a.proportion&&(b.width<a.width||b.height<a.height)?(e.css({width:a.width,height:a.height,overflow:""}),d.css({"overflow-x":a.width<=b.width?"hidden":"","overflow-y":a.height<=b.height?"hidden":""}),c.FooBox.raise("foobox.showOverflow",{item:a,container:d})):(e.css({width:"",height:"",overflow:"hidden"}),d.css({"overflow-x":"","overflow-y":"",overflow:"hidden"}),c.FooBox.raise("foobox.hideOverflow",{item:a,container:d}))},this.transitionOut=function(b,d,e){try{if(!c.element.hasClass("fbx-show"))return void(a.isFunction(d)&&d());b.animate({opacity:0},b.is(":visible")?c.FooBox.options.transitionOutSpeed:0,function(){a.isFunction(d)&&d()})}catch(f){a.isFunction(e)&&e(f)}},this.transitionIn=function(b,d,e){try{if(!c.element.hasClass("fbx-show"))return b.css({opacity:1}),void(a.isFunction(d)&&d());b.animate({opacity:1},c.FooBox.options.transitionInSpeed,function(){a.isFunction(d)&&d()})}catch(f){a.isFunction(e)&&e(f)}},this.close=function(){c.FooBox.raise("foobox.beforeClose").isDefaultPrevented()||(c._closed=!0,c._busy=!1,c.element.removeClass("fbx-loading fbx-show"),a("body").removeClass("fbx-active"),c.FooBox.raise("foobox.close"),c.element.find(".fbx-item-current, .fbx-item-next").empty(),c.FooBox.options.hideScrollbars&&a("html").css("overflow",""),c.FooBox.raise("foobox.afterClose"))},this.prev=function(a){if(1!=c._busy){if(c.FooBox.items.indexes.set(c.FooBox.items.indexes.prev),"string"==typeof a)for(var b=c.FooBox.items.current();b.type!=a;)c.FooBox.items.indexes.set(c.FooBox.items.indexes.prev),b=c.FooBox.items.current();c.show(!1),c.FooBox.raise("foobox.previous")}},this.next=function(a){if(1!=c._busy){if(c.FooBox.items.indexes.set(c.FooBox.items.indexes.next),"string"==typeof a)for(var b=c.FooBox.items.current();b.type!=a;)c.FooBox.items.indexes.set(c.FooBox.items.indexes.next),b=c.FooBox.items.current();c.show(!1),c.FooBox.raise("foobox.next")}},this},FooBox.Instance=function(b){this.id=null,"number"==typeof b?(this.id=b,FooBox.instances[b-1]=this):this.id=FooBox.instances.push(this),this.element=null,this.options=a.extend(!0,{},FooBox.defaults),this.modal=new FooBox.Modal(this),this.objects={},FooBox.addons.load(this),FooBox.handlers.load(this);var c=this;return this.raise=function(a,b){return FooBox.raise(c,a,b)},this.init=function(b,d){c.element=FooBox.isjQuery(b)?b:a(b),c.options=FooBox.options.merge(c.options,d||{}),FooBox.addons.call(c,"preinit",c.element,c.options),c.items.init(),c.items.array.length>0?(c.element.data("fbx_instance",c),c.options.containerCssClass&&c.element.addClass(c.options.containerCssClass),c.setup.bind(),c.modal.init(b,c.options),FooBox.handlers.call(c,"init",c.element,c.options),c.raise("foobox.initialized"),a.isFunction(c.options.initCallback)&&c.options.initCallback.call(c)):c.destroy()},this.reinit=function(a){c.options=FooBox.options.merge(c.options,a||{}),c.items.init(!0),c.items.array.length>0?(c.setup.bind(),c.modal.reinit(c.options),FooBox.handlers.call(c,"reinit",c.options),c.raise("foobox.reinitialized")):c.destroy()},this.destroy=function(){FooBox.addons.call(c,"destroy"),FooBox.handlers.call(c,"destroy"),c.items.destroy(),c.modal.destroy(),c.element.removeClass("fbx-instance fbx-item").data({fbx_instance:null,fbx_p_instance:null}),c.id==FooBox.instances.length?FooBox.instances.splice(c.id-1,1):FooBox.instances[c.id-1]=null,c.raise("foobox.destroy")},this.setup={bind:function(){a(c.options.externalSelector).unbind("click.fooboxExternal").bind("click.fooboxExternal",function(b){b.preventDefault();var c=a(this).data("foobox"),d=a(c),e=d.data("fbx_instance")||d.data("fbx_p_instance");return d.length>0&&e instanceof FooBox.Instance&&e.modal instanceof FooBox.Modal&&e.modal.show(!0),!1})}},this.items={array:[],indexes:{prev:-1,current:0,next:1,direction:"*",set:function(a){var b=c.items.indexes.current;a=a||0,a=a>c.items.array.length-1?0:0>a?c.items.array.length-1:a;var d=a-1,e=a+1;c.items.indexes.current=a,c.items.indexes.prev=0>d?c.items.array.length-1:d,c.items.indexes.next=e>c.items.array.length-1?0:e,c.items.indexes.direction=c.items.indexes._direction(b,a,c.items.array.length-1)},_direction:function(a,b,c){return 0==b&&a==c?">":b==c&&0==a?"<":b>a?">":a>b?"<":"*"}},new_array:function(b){b=b||!1;var d,e,f,g=0;if(1==b){if(c.items.array.length>0){for(var h=0;h<c.items.array.length;h++)d=c.items.array[h],FooBox.isjQuery(d.element)?0==d.element.parents(":first").length&&(c.items.array.splice(h,1),h-=1):d.option||(c.items.array.splice(h,1),h-=1);for(var i=0;i<c.items.array.length;i++)d=c.items.array[i],FooBox.isjQuery(d.element)?(f=d.element.get(0),f.index=d.index=i):d.index=i}}else c.items.array=[];if(a.isArray(c.options.items))for(var j=0;j<c.options.items.length;j++)if(d=c.options.items[j],-1==c.items.indexOf(d))for(var k=0;k<c.objects.handlers.length;k++)if(c.objects.handlers[k].type==d.type){d.index=g,d.option=!0,d.handler=c.objects.handlers[k],d.handler.defaults(d),e=c.raise("foobox.parseItem",{element:null,item:d}),c.items.array.push(e.fb.item),g++;break}},init:function(a){a=a||!1,c.items.new_array(a),c.element.is(c.options.selector)&&!c.element.is(c.options.excludes)&&c.items.add(c.element)?c.element.unbind("click.item").bind("click.item",c.items.clicked):c.element.find(c.options.selector).not(c.options.excludes).unbind("click.item").filter(function(){return c.items.add(this)}).bind("click.item",c.items.clicked),c.items.rel()},destroy:function(){var b,d;for(d=0;d<c.items.array.length;d++)b=c.items.array[d],a.isFunction(b.destroy)&&b.destroy(),FooBox.isjQuery(b.element)&&b.element.unbind("click.item").removeClass("fbx-link").data("fbx_p_instance",null);c.items.array=[]},rel:function(){var b=c.options.rel||c.element.attr("rel")||(c.items.first(function(a){return FooBox.isjQuery(a.element)?"string"==typeof a.element.attr("rel"):!1})||{element:a()}).element.attr("rel");"string"==typeof b&&a('[rel="'+b+'"]').not(c.options.excludes).not(c.element).unbind("click.item").filter(function(){return c.items.add(this)}).bind("click.item",c.items.clicked)},indexOf:function(a,b){if(!a)return-1;b=b||"url";var d;for(d=0;d<c.items.array.length;d++)if(c.items.array[d][b]==a[b])return d;return-1},is:{first:function(a){return c.items.array&&0!=c.items.array.length?c.items.array[0].index==a.index:!1},last:function(a){return c.items.array&&0!=c.items.array.length?c.items.array[c.items.array.length-1].index==a.index:!1}},add:function(b){b=FooBox.isjQuery(b)?b:a(b);var d=c.items.parse(b);if(null===d)return!1;var e=b.get(0),f=c.items.indexOf(d);-1!=f?(d=c.items.array[f],e.index=d.index):e.index=d.index=c.items.array.push(d)-1;var g=b.addClass("fbx-link").data("fbx_p_instance");return g instanceof FooBox.Instance||b.data("fbx_p_instance",c),!0},get:function(b){b=FooBox.isjQuery(b)?b:a(b);var d=null,e=b.get(0).index;return e&&e>0&&e<=c.items.array.length-1&&(d=c.items.array[e]),d},parse:function(b){b=FooBox.isjQuery(b)?b:a(b);for(var d,e,f=0;f<c.objects.handlers.length;f++)if(c.objects.handlers[f].handles(b,c.element)){d=c.objects.handlers[f].parse(b),e=c.raise("foobox.parseItem",{element:b,item:d});break}return"undefined"!=typeof e&&e.fb.item?e.fb.item:null},error:function(b){function d(b){var c=this;return c.FooBox=b,c.type="error",c.handles=function(){return!1},c.hasChanged=function(){return!1},c.defaults=function(){},c.parse=function(){},c.load=function(b,d,e,f){try{d.empty().append(b.content),a.isFunction(e)&&e(c.getSize(b))}catch(g){a.isFunction(f)&&f(g)}},c.getSize=function(a){return new FooBox.Size(a.width,a.height)},c}if(c.items.array.length>b&&1==c.items.array[b].error)return c.items.array[b];var e,f,g=FooBox.handlers.get(c,"html"),h=!1;if(null==g&&(g=new d(c)),null!==c.options.error.match(/^#/i)&&a(c.options.error).length>0)e=a(c.options.error),h=!0;else{var i=FooBox.format('<div class="fbx-error-msg" data-width="240" data-height="240"><span></span><p>{0}</p></div>',c.options.error);e=a(i)}return f=new FooBox.Item(g.type,e.get(0),g),f.selector=1==h?c.options.error:null,f.index=b,f.error=!0,f.title=e.data("title")||null,f.description=e.data("description")||null,f.width=e.data("width")||240||null,f.height=e.data("height")||240||null,f.content=1==h?null:e,f.fullscreen=!0,f.handler=g,c.items.array[b]=f,f},first:function(a){for(var b=null,d=0;d<c.items.array.length;d++)if(a(c.items.array[d])){b=c.items.array[d];break}return b},current:function(){return c.items.array[c.items.indexes.current]},prev:function(){return c.items.array[c.items.indexes.prev]},next:function(){return c.items.array[c.items.indexes.next]},multiple:function(){return c.items.array.length>1},clicked:function(a){return a.preventDefault(),c.items.indexes.set(this.index),c.modal.show(!0),!1}},this},FooBox.open=function(b){if(1==FooBox.isDeepLink)return null;var c,d=null;if("object"==typeof b){var e=document.createElement("a");a(e).foobox(b),d=a(e).data("fbx_instance")}else"number"==typeof b?c=b:(c=parseInt(b||0),c=isNaN(c)?0:c),c=c>FooBox.instances.length-1?FooBox.instances.length-1:0>c?0:c,d=FooBox.instances[c];return null!=d&&d.modal instanceof FooBox.Modal?(d.modal.show(!0),d):null},FooBox.close=function(){var a,b=[],c=null;for(a=0;a<FooBox.instances.length;a++)c=FooBox.instances[a],null!=c&&c.modal instanceof FooBox.Modal&&FooBox.isjQuery(c.modal.element)&&c.modal.element.hasClass("fbx-show")&&b.push(c);for(a=0;a<b.length;a++)c=b[a],c.modal.close()},FooBox.resize=function(c,d){if(c||d){var e,f,g,h;for(e=0;e<FooBox.instances.length;e++)f=FooBox.instances[e],null!=f&&f.modal instanceof FooBox.Modal&&FooBox.isjQuery(f.modal.element)&&f.modal.element.hasClass("fbx-show")&&(g=f.items.current(),h=new FooBox.Size(c||g.width||0,d||g.height||0),g.width=h.width,g.height=h.height,f.modal.resize(h,f.modal.element.find(".fbx-item-current")))}else a(b).trigger("resize.foobox")},FooBox.lateBind=function(c,d){var e=a.extend(!0,{},FooBox.defaults,d||b.FOOBOX&&FOOBOX.o||{}),f=a(c);f.on("click.foobox",e.selector,function(a){a.preventDefault();var b=f.data("fbx_instance");b||(b=f.foobox(e).data("fbx_instance")),b instanceof FooBox.Instance&&"number"==typeof this.index&&(b.items.indexes.set(this.index),b.modal.show(!0))})}}}(jQuery,window,window.console),function(a,b){var c={images:{noRightClick:!1,attr:"href",overflow:!1,fullscreen:!0,showCaptions:!0,regex:/\.(jpg|jpeg|png|gif|bmp)/i,maxWidth:-1,maxHeight:-1,findUrl:function(a,c){if(!c)return"";if(c.data("image"))return c.data("image");var d=c.attr(a.options.images.attr);return"string"==typeof d?b.qualifiedURL(c.attr(a.options.images.attr)):""}}};b.Item.prototype.image=null,b.Item.prototype.maxWidth=null,b.Item.prototype.maxHeight=null,b.ImageHandler=function(c){this.FooBox=c,this.type="image";var d=this;this.handles=function(a){var b=d.FooBox.options.images.findUrl(d.FooBox,a),c="string"==typeof b&&null!=b.match(d.FooBox.options.images.regex),e=d.FooBox.raise("foobox.handlesImage",{element:a,handle:c});return e.fb.handle},this.defaults=function(a){a.fullscreen=a.fullscreen||d.FooBox.options.images.fullscreen,a.captions=a.captions||d.FooBox.options.images.showCaptions,a.social=a.social||!0,a.overflow=a.overflow||d.FooBox.options.images.overflow,a.proportion=a.proportion||!0,a.maxWidth=a.maxWidth||d.FooBox.options.images.maxWidth,a.maxHeight=a.maxHeight||d.FooBox.options.images.maxHeight},this.parse=function(a){var c=new b.Item(d.type,a,this);return d.defaults(c),c.url=d.FooBox.options.images.findUrl(d.FooBox,a)||null,c.width=a.data("width")||c.width||null,c.height=a.data("height")||c.height||null,c.fullscreen="boolean"==typeof a.data("fullscreen")?a.data("fullscreen"):c.fullscreen,c.overflow="boolean"==typeof a.data("overflow")?a.data("overflow"):c.overflow,c.proportion="boolean"==typeof a.data("proportion")?a.data("proportion"):c.proportion,c.maxWidth="number"==typeof a.data("maxWidth")?a.data("maxWidth"):c.maxWidth,c.maxHeight="number"==typeof a.data("maxHeight")?a.data("maxHeight"):c.maxHeight,c.image=null,c.image_url=c.url,c},this.load=function(b,c,e,f){try{var g=function(){var f=a(b.image).addClass("fbx-item fbx-item-image");d.FooBox.options.images.noRightClick&&f.bind("contextmenu",function(a){return a.preventDefault(),!1}),c.empty().append(f),a.isFunction(e)&&e(d.getSize(b))};b.image&&null!==b.image?g():(b.image=new Image,b.image.onload=function(){b.image.onload=b.image.onerror=null,b.height=b.image.height,b.width=b.image.width,g()},b.image.onerror=function(){b.image.onload=b.image.onerror=null,b.image=null,a.isFunction(f)&&f("An error occurred attempting to load the image.")},b.image.src=b.url)}catch(h){a.isFunction(f)&&f(h)}},this.preload=function(a){if(1!=a.preloaded){var b=new Image;b.src=a.url,a.preloaded=!0}},this.getSize=function(a){if(null!=a.width&&null!=a.height){if(a.maxWidth>0&&a.maxHeight>0&&(a.width>a.maxWidth||a.height>a.maxHeight)){var c=a.width>a.height?a.maxWidth/a.width:a.maxHeight/a.height;a.width*=c,a.height*=c}return new b.Size(a.width,a.height)}return new b.Size(0,0)},this.hasChanged=function(a){if(b.isjQuery(a.element)){var c=d.FooBox.options.images.findUrl(d.FooBox,a.element);return a.url!=c}return!1}},b.handlers.register(b.ImageHandler,c)}(jQuery,window.FooBox),function(a,b){var c={keyboard:{enabled:!0,preventDefault:!1,stopPropagation:!1}};b.Keyboard=function(a){this.FooBox=a;var c=this;this.preinit=function(a){c.handlers.unbind(!0),a.bind({"foobox.initialized foobox.reinitialized":c.handlers.initialized,"foobox.setupHtml":c.handlers.setupHtml})},this.destroy=function(){c.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&c.FooBox.element.unbind({"foobox.initialized foobox.reinitialized":c.handlers.initialized,"foobox.setupHtml":c.handlers.setupHtml}),c.FooBox.element.unbind("foobox.afterLoad",c.handlers.afterLoad),b.isjQuery(c.FooBox.modal.element)&&c.FooBox.modal.element.unbind("keydown.foobox",c.handlers.onKeydown);
10
- },initialized:function(){c.handlers.unbind(),1==c.FooBox.options.keyboard.enabled&&(c.FooBox.element.bind("foobox.afterLoad",c.handlers.afterLoad),b.isjQuery(c.FooBox.modal.element)&&c.FooBox.modal.element.bind("keydown.foobox",c.handlers.onKeydown))},setupHtml:function(a){a.fb.modal.attr("tabindex",0)},afterLoad:function(a){a.fb.modal.focus()},onKeydown:function(a){var b=c.FooBox.modal,d=c.FooBox.options.keyboard;b.element.hasClass("fbx-show")&&(b.element.hasClass("fbx-fullscreen-mode")||27!==a.which?c.FooBox.items.multiple()&&37===a.which?b.prev():c.FooBox.items.multiple()&&39===a.which&&b.next():b.close(),1==d.preventDefault&&a.preventDefault(),1==d.stopPropagation&&a.stopPropagation(),c.FooBox.raise("foobox.keydown",{keyCode:a.which}))}}},b.addons.register(b.Keyboard,c)}(jQuery,window.FooBox),function(a,b){var c={hideNavOnMobile:!1,resizeTimeout:300,breakpoints:{phone:640,tablet:1024},iosInterval:200};b.BPInfo=function(c){var d="undefined"!=typeof window.devicePixelRatio&&b.browser.isMobile?window.devicePixelRatio:1;this.width=(window.innerWidth||document.documentElement.clientWidth||(document.body?document.body.offsetWidth:0))/d,this.height=(window.innerHeight||document.documentElement.clientHeight||(document.body?document.body.offsetHeight:0))/d,this.orientation=this.width>this.height?"fbx-landscape":"fbx-portrait";var e,f=null;if(a.isArray(c))for(var g=0;g<c.length;g++)if(e=c[g],e&&e.width&&this.width<=e.width){f=e;break}this.breakpoint=null==f?"fbx-desktop":f.name},b.Responsive=function(c){this.FooBox=c,this.breakpoint={values:[],names:""},this.timers={resize:new b.Timer,ios:new b.Timer};var d=this,e=null;this.preinit=function(a){d.handlers.unbind(!0),a.bind("foobox.initialized foobox.reinitialized",d.handlers.initialized)},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(b){b=b||!1,b&&d.FooBox.element.unbind("foobox.initialized foobox.reinitialized",d.handlers.initialized),a(window).unbind("resize.foobox",d.handlers.resize),d.FooBox.element.unbind({"foobox.beforeShow":d.handlers.iosBeforeShow,"foobox.close":d.handlers.iosClose})},initialized:function(){d.handlers.unbind(),d.setup.breakpoints(),d.style(),a(window).bind("resize.foobox",d.handlers.resize),b.browser.iOS&&(b.browser.isSafari||b.browser.isChrome)&&d.FooBox.element.bind({"foobox.beforeShow":d.handlers.iosBeforeShow,"foobox.close":d.handlers.iosClose})},resize:function(){d.timers.resize.start(function(){d.style();var a=d.FooBox.items.current();if(d.FooBox.modal.element.has("fbx-show")&&null!=a){var b=a.handler.getSize(a);d.FooBox.modal.resize(b,d.FooBox.modal.element.find(".fbx-item-current"))}},d.FooBox.options.resizeTimeout)},iosBeforeShow:function(){d.timers.ios.start(d.handlers.ios,d.FooBox.options.iosInterval)},iosClose:function(){d.timers.ios.stop()},ios:function(){if(!d.FooBox.modal.element.hasClass("fbx-show"))return void d.timers.ios.start(d.handlers.ios,d.FooBox.options.iosInterval);var a=window.orientation||0,c=window.innerHeight,f=90==a||-90==a,g=0,h=0,i=f?screen.availWidth:screen.availHeight;b.browser.isChrome?(g=i-(f?76:56),h=i-(f?0:20)):b.browser.isSafari&&(g=i-88,h=i-(f?0:19)),(null==e||0==e)&&g>=c?(e=!0,d.iosRedraw()):(null==e||1==e)&&c>=h&&(e=!1,d.iosRedraw()),d.timers.ios.start(d.handlers.ios,d.FooBox.options.iosInterval)}},this.setup={breakpoints:function(){d.breakpoint.values=[],d.breakpoint.names="";for(var a in d.FooBox.options.breakpoints)d.FooBox.options.breakpoints.hasOwnProperty(a)&&(d.breakpoint.values.push({name:d.fixName(a),width:d.FooBox.options.breakpoints[a]}),d.breakpoint.names+=d.fixName(a)+" ");d.breakpoint.values.sort(function(a,b){return a.width-b.width})}},this.iosRedraw=function(){window.scrollTo(0,document.body.scrollTop),a(window).trigger("resize")},this.fixName=function(a){return/^fbx-[a-zA-Z0-9]/.test(a)?a:"fbx-"+a},this.style=function(){var a=new b.BPInfo(d.breakpoint.values),c=d.FooBox.modal.element;c.removeClass(d.breakpoint.names).removeClass("fbx-desktop fbx-landscape fbx-portrait").addClass(a.breakpoint).addClass(a.orientation),d.FooBox.options.hideNavOnMobile===!0?c.addClass("fbx-no-nav"):c.removeClass("fbx-no-nav")}},b.Responsive.metaCheck=function(){var b=a("meta[name=viewport]"),c=b.attr("content");if(b.length>0&&"string"==typeof c){for(var d=c.split(","),e=!1,f=!1,g=0;g<d.length;g++){var h=a.trim(d[g]);"width"==h.substring(0,5)?e=!0:"initial-scale"==h.substring(0,13)&&(f=!0)}e&&!f&&(d.push("initial-scale=1"),c=d.join(","),b.attr("content",c))}},b.addons.register(b.Responsive,c),b.Responsive.metaCheck()}(jQuery,window.FooBox),function(a,b){var c={captions:{animation:"slide",enabled:!0,descSource:"find",hoverDelay:300,maxHeight:.4,onlyShowOnHover:!1,onlyShowOnClick:!1,overrideDesc:!1,overrideTitle:!1,prettify:!1,titleSource:"image_find"}};b.Item.prototype.captions=!1,b.Item.prototype.title=null,b.Item.prototype.description=null,b.Item.prototype.caption=null,b.Captions=function(c){this.FooBox=c,this.timers={hover:new b.Timer};var d=this;this.preinit=function(a){d.handlers.unbind(!0),a.bind({"foobox.initialized foobox.reinitialized":d.handlers.initialized,"foobox.setupHtml":d.handlers.setupHtml,"foobox.setupOptions":d.handlers.setupOptions,"foobox.parseItem":d.handlers.parseItem,"foobox.onError":d.handlers.onError})},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&d.FooBox.element.unbind({"foobox.initialized foobox.reinitialized":d.handlers.initialized,"foobox.setupHtml":d.handlers.setupHtml,"foobox.setupOptions":d.handlers.setupOptions,"foobox.parseItem":d.handlers.parseItem,"foobox.onError":d.handlers.onError,"foobox.close":d.handlers.close}),d.FooBox.element.unbind({"foobox.beforeLoad":d.handlers.beforeLoad,"foobox.afterLoad":d.handlers.afterLoad}),d.FooBox.modal instanceof b.Modal&&b.isjQuery(d.FooBox.modal.element)&&d.FooBox.modal.element.undelegate("mouseenter.captions mouseleave.captions").find(".fbx-item-current, .fbx-item-next").unbind("click.captions")},initialized:function(a){d.handlers.unbind(),a.fb.options.captions.enabled===!0&&(a.fb.instance.element.bind({"foobox.beforeLoad":d.handlers.beforeLoad,"foobox.afterLoad":d.handlers.afterLoad,"foobox.close":d.handlers.close}),a.fb.options.captions.onlyShowOnHover===!0&&a.fb.modal.delegate(".fbx-inner:not(:has(.fbx-item-error))","mouseenter.captions",d.handlers.mouseenter).delegate(".fbx-inner:not(:has(.fbx-item-error))","mouseleave.captions",d.handlers.mouseleave))},toggleCaptions:function(a){return a.preventDefault(),d.FooBox.modal.element.hasClass("fbx-error")?!0:(d.FooBox.modal.element.find(".fbx-caption").is(".fbx-fade-caption, .fbx-slide-caption, .fbx-hide-caption")?(d.FooBox.modal.element.removeClass("fbx-captions-hidden"),d.show()):(d.FooBox.modal.element.addClass("fbx-captions-hidden"),d.hide()),!0)},mouseenter:function(){d.timers.hover.start(function(){d.show()},d.FooBox.options.captions.hoverDelay)},mouseleave:function(){d.timers.hover.start(function(){d.hide()},d.FooBox.options.captions.hoverDelay)},setupHtml:function(b){var c=a("<div/>",{"class":"fbx-caption"}),e=a("<a/>",{href:"#open_caption","class":"fbx-open-caption",html:"&hellip;"}).bind("click.captions",d.handlers.toggleCaptions);"string"==typeof b.fb.options.modalClass&&-1!=b.fb.options.modalClass.indexOf("fbx-sticky-caption")?b.fb.modal.append(c,e):b.fb.modal.find(".fbx-stage").append(c,e)},setupOptions:function(a){a.fb.modal.find(".fbx-caption").addClass(d.animation())},close:function(a){1!=a.fb.options.captions.onlyShowOnHover&&a.fb.modal.find(".fbx-caption").addClass(d.animation())},beforeLoad:function(a){1!=a.fb.options.captions.onlyShowOnHover&&a.fb.modal.find(".fbx-caption").addClass(d.animation())},afterLoad:function(a){var b=a.fb.item;return!b||b.error||b.captionLoaded||(a.fb.instance.raise("foobox.alterCaption",{element:a.fb.element,item:b}),b.captionLoaded=!0),1==a.fb.options.captions.onlyShowOnHover?void d.update():void(0==a.fb.options.captions.onlyShowOnClick&&d.show())},onError:function(a){a.fb.modal.find(".fbx-caption").addClass(d.animation())},parseItem:function(c){var e=c.fb.options.captions;if(c.fb.item.captions&&0!=e.enabled){var f,g,h="";if(null!=c.fb.element){var i=a(c.fb.element).data("titleSource")||a(c.fb.instance.element).data("titleSource")||e.titleSource,j=a(c.fb.element).data("descSource")||a(c.fb.instance.element).data("descSource")||e.descSource;f=c.fb.element.data("captionTitle")||c.fb.element.data("title")||d.text(c.fb.element,i),g=c.fb.element.data("captionDesc")||c.fb.element.data("description")||d.text(c.fb.element,j)}else f=c.fb.item.title,g=c.fb.item.description;f=null==f||"undefined"==typeof f?"":f+"",g=null==g||"undefined"==typeof g?"":g+"",f&&f==g&&(g=null),h="string"==typeof f&&f.length>0?b.format('<div class="fbx-caption-title">{0}</div>',f):h,h="string"==typeof g&&g.length>0?h+b.format('<div class="fbx-caption-desc">{0}</div>',g):h,c.fb.item.title=f,c.fb.item.description=g,c.fb.item.caption=h,c.fb.instance.raise("foobox.createCaption",{element:c.fb.element,item:c.fb.item})}}},this.text=function(b,c){var e;switch(c){case"find":e=a.trim(b.data("enviraCaption")||b.data("title")||b.attr("title")||b.find("img:first").data("title")||b.find("img:first").data("alt")||b.find("img:first").attr("title")||b.find("img:first").attr("alt"));break;case"image_find":e=a.trim(b.find("img:first").data("title")||b.find("img:first").data("alt")||b.find("img:first").attr("title")||b.find("img:first").attr("alt"));break;case"image":e=a.trim(b.find("img:first").data("title")||b.find("img:first").attr("title"));break;case"image_alt":e=a.trim(b.find("img:first").data("alt")||b.find("img:first").attr("alt"));break;case"anchor":e=a.trim(b.data("enviraCaption")||b.data("title")||b.attr("title"));break;default:e=null}return d.FooBox.options.captions.prettify&&(e=d.prettifier(e)),e},this.animation=function(){switch(d.FooBox.options.captions.animation){case"fade":return"fbx-fade-caption";case"slide":return"fbx-slide-caption";default:return"fbx-hide-caption"}},this.hide=function(){var a=d.FooBox.items.current(),b=d.FooBox.modal.element.find(".fbx-caption");return d.FooBox.options.captions.enabled&&a.captions&&"string"==typeof a.caption&&0!=a.caption.length?void b.addClass(d.animation()):void b.addClass("fbx-hide-caption")},this.show=function(){var a=d.FooBox,c=a.items.current(),e=a.modal.element.find(".fbx-caption");return!a.options.captions.enabled||!c.captions||"string"!=typeof c.caption||0==c.caption.length||a.modal.element.hasClass("fbx-captions-hidden")||b.isjQuery(c.element)&&c.element.hasClass("no-captions")?void e.addClass("fbx-hide-caption"):(d.update(),void e.removeClass("fbx-fade-caption fbx-slide-caption fbx-hide-caption"))},this.update=function(){var c=d.FooBox.items.current(),e=d.FooBox.modal.element.find(".fbx-caption");e.html(c.caption).find('a[href^="#"]').filter(function(){var c=a(this).attr("href"),d=a(c),e=d.data("fbx_instance")||d.data("fbx_p_instance");return d.length>0&&e instanceof b.Instance?(a(this).data("hrefTarget",d.get(0)),!0):!1}).unbind("click.captions").bind("click.captions",function(c){c.preventDefault();var e=a(this).data("hrefTarget"),f=a(e).data("fbx_instance")||a(e).data("fbx_p_instance");return f instanceof b.Instance&&(d.FooBox.modal.close(),f.items.indexes.set(e.index),f.modal.show()),!1}),a("<a/>",{href:"#close_caption","class":"fbx-close-caption",html:"&times;"}).bind("click.captions",d.handlers.toggleCaptions).prependTo(e)},this.prettifier=function(a){return"string"!=typeof a?null:(a=a.replace(/\s*-\d+/g,"").replace(/\s*_\d+/g,"").replace(/-/g," ").replace(/_/g," "),a=a.replace(/\w\S*/g,function(a){return-1!=a.indexOf("#")?a:a.charAt(0).toUpperCase()+a.substr(1).toLowerCase()}))}},b.addons.register(b.Captions,c)}(jQuery,window.FooBox),function(a,b){var c={wordpress:{enabled:!1}};b.Wordpress=function(c){this.FooBox=c;var d=this;this.preinit=function(a){d.handlers.unbind(!0),a.bind("foobox.createCaption",d.handlers.onCreateCaption)},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&d.FooBox.element.unbind("foobox.createCaption",d.handlers.onCreateCaption)},onCreateCaption:function(c){var d=c.fb.options,e=c.fb.instance.element,f=c.fb.item.element,g="",h=c.fb.item.title,i=c.fb.item.description;if(1==d.wordpress.enabled&&b.isjQuery(f)){var j=f.data("captionTitle")||f.data("title"),k=f.data("captionDesc")||f.data("description");if(e.hasClass("gallery"))d.captions.overrideTitle===!1&&(h=j||f.parents(".gallery-item:first").find(".wp-caption-text:first").html()||f.parents(".gallery-item:first").find(".gallery-caption:first").html()||h||""),d.captions.overrideDesc===!1&&(i=k||f.find("img").attr("alt")||i||"");else if(e.hasClass("wp-caption")||f.hasClass("wp-caption"))d.captions.overrideTitle===!1&&(h=j||f.find("img").attr("title")||f.parents(".wp-caption:first").find(".wp-caption-text:first").html()||h||""),d.captions.overrideDesc===!1&&(i=k||f.find("img").attr("alt")||i||"");else if(f.parents(".wp-caption:first").length>0)d.captions.overrideTitle===!1&&(h=j||f.parents(".wp-caption:first").find("img").attr("title")||f.parents(".wp-caption:first").find(".wp-caption-text:first").html()||h||""),d.captions.overrideDesc===!1&&(i=k||f.parents(".wp-caption:first").find("img").attr("alt")||i||"");else{if(!e.hasClass("tiled-gallery"))return;d.captions.overrideTitle===!1&&(h=j||f.parents(".tiled-gallery-item:first").find(".tiled-gallery-caption").html()||f.find("img").data("image-title")||f.find("img").attr("title")||h||""),d.captions.overrideDesc===!1&&(i=k||a.trim(f.find("img").data("image-description")).replace(/(^<p>)|(<\/p>$)/gi,"")||i||"")}h+="",i+="",h=h||"",i=i||"";var l=a("<div/>"),m=l.html(h).text(),n=l.html(i).text();(a.trim(h)==a.trim(i)||m==n)&&(i=null),g="string"==typeof h&&h.length>0?b.format('<div class="fbx-caption-title">{0}</div>',h):g,g="string"==typeof i&&i.length>0?g+b.format('<div class="fbx-caption-desc">{0}</div>',i):g,c.fb.item.title=h,c.fb.item.description=i,c.fb.item.caption=g}}}},b.addons.register(b.Wordpress,c)}(jQuery,window.FooBox),function(a,b){var c={pan:{enabled:!0,showOverview:!0,position:"fbx-top-right"}};b.Pan=function(c){this.FooBox=c;var d,e,f,g,h=this,i=!1,j=!1,k=null,l=null,m=null,n=null,o=null,p=0;this.preinit=function(a){h.handlers.unbind(!0),a.on({"foobox.initialized foobox.reinitialized":h.handlers.initialized})},this.destroy=function(){h.handlers.unbind(!0)},this.setOverview=function(){var a=parseInt(n.css("max-width")),b=parseInt(n.css("max-height")),c=a/k.width,d=b/k.height;p=c>d?d:c;var e=k.width*p,f=k.height*p;n.width(e).height(f).css("background-image","url("+k.url+")")},this.setViewport=function(){var a=l.width(),b=l.height(),c=a*p,d=b*p;o.width(c).height(d)},this.handlers={unbind:function(a){a=a||!1,a&&h.FooBox.element.off({"foobox.initialized foobox.reinitialized":h.handlers.initialized}),h.FooBox.element.off({"foobox.overflowItem":h.handlers.onOverflowItem,"foobox.standardItem":h.handlers.onStandardItem}),h.FooBox.modal instanceof b.Modal&&b.isjQuery(h.FooBox.modal.element)&&h.FooBox.modal.element.find(".fbx-stage").off({mousedown:h.handlers.onMouseDown,mousemove:h.handlers.onMouseMove,mouseup:h.handlers.onMouseUp}).removeClass("fbx-pannable fbx-panning")},initialized:function(a){h.handlers.unbind(),a.fb.options.pan.enabled===!0&&h.FooBox.element.on({"foobox.close":h.handlers.onMouseUp,"foobox.showOverflow":h.handlers.onShowOverflow,"foobox.hideOverflow foobox.beforeLoad":h.handlers.onHideOverflow})},onShowOverflow:function(b){"image"==b.fb.item.handler.type&&(i===!0?(h.setOverview(),h.setViewport()):(i=!0,k=b.fb.item,m=h.FooBox.modal.element.find(".fbx-stage").on({mousedown:h.handlers.onMouseDown,mousemove:h.handlers.onMouseMove,"mouseup mouseleave":h.handlers.onMouseUp}).addClass("fbx-pannable"),l=b.fb.container,b.fb.options.pan.showOverview===!0&&(n=a("<div/>",{"class":"fbx-pan-overview"}).addClass(b.fb.options.pan.position).on("click",h.handlers.onOverviewClick).appendTo(m),o=a("<div/>",{"class":"fbx-pan-viewport"}).appendTo(n),l.on("scroll",h.handlers.onScroll),h.setOverview(),h.setViewport())))},onHideOverflow:function(a){i===!0&&(i=!1,a.fb.options.pan.showOverview===!0&&n.remove(),l.off("scroll",h.handlers.onScroll),m.off({mousedown:h.handlers.onMouseDown,mousemove:h.handlers.onMouseMove,"mouseup mouseleave":h.handlers.onMouseUp}).removeClass("fbx-pannable fbx-panning"))},onMouseDown:function(a){if(i===!0){a.preventDefault(),m.addClass("fbx-panning");var b=l.get(0);j=!0,d=a.pageX,e=a.pageY,f=b.scrollLeft,g=b.scrollTop}},onMouseMove:function(a){if(j===!0&&i===!0){var b=l.get(0);b.scrollLeft=f-(a.pageX-d),b.scrollTop=g-(a.pageY-e)}},onMouseUp:function(){i===!0&&(j=!1,m.removeClass("fbx-panning"),d=0,e=0,f=0,g=0)},onScroll:function(){var a=l.get(0),b=a.scrollTop/k.height*100,c=a.scrollLeft/k.width*100;o.css({top:b+"%",left:c+"%"})},onOverviewClick:function(b){var c=a(this).offset(),d=(b.pageX-c.left)/p,e=(b.pageY-c.top)/p,f=d-l.width()/2,g=e-l.height()/2;l.animate({scrollTop:g,scrollLeft:f},300)}}},b.addons.register(b.Pan,c)}(jQuery,window.FooBox),function(a,b){var c={swipe:{enabled:!0,min:80}};b.Swipe=function(a){this.FooBox=a,this.isMoving=!1;var c,d=this;this.preinit=function(a){d.handlers.unbind(!0),a.bind("foobox.initialized foobox.reinitialized",d.handlers.initialized)},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&d.FooBox.element.unbind("foobox.initialized foobox.reinitialized",d.handlers.initialized),d.FooBox.modal instanceof b.Modal&&b.isjQuery(d.FooBox.modal.element)&&d.FooBox.modal.element.unbind({touchstart:d.handlers.onTouchStart,touchmove:d.handlers.onTouchMove})},initialized:function(a){d.handlers.unbind(),a.fb.options.swipe.enabled===!0&&a.fb.modal.bind("touchstart",d.handlers.onTouchStart)},onTouchStart:function(a){var b=a.originalEvent.touches||a.touches;1==b.length&&d.FooBox.items.multiple()&&(c=b[0].pageX,d.isMoving=!0,d.FooBox.modal.element.bind("touchmove",d.handlers.onTouchMove))},onTouchMove:function(a){if(d.isMoving){var b=a.originalEvent.touches||a.touches,e=b[0].pageX,f=c-e;Math.abs(f)>=d.FooBox.options.swipe.min&&(d.cancelTouch(),f>0?(d.FooBox.raise("foobox.swipeRight"),d.FooBox.modal.next()):(d.FooBox.raise("foobox.swipeLeft"),d.FooBox.modal.prev()))}}},this.cancelTouch=function(){d.FooBox.modal.element.unbind("touchmove",d.handlers.onTouchMove),c=null,d.isMoving=!1}},b.addons.register(b.Swipe,c)}(jQuery,window.FooBox);
6
  * @license Released under the MIT license.
7
  * You are free to use FooBox jQuery in personal projects as long as this copyright header is left intact.
8
  */
9
+ !function(a,b,c,undefined){if(a&&b){b.FooBox={defaults:{affiliate:{enabled:!0,prefix:"Powered by ",url:"http://fooplugins.com/plugins/foobox/"},alwaysInit:!1,closeOnOverlayClick:!0,containerCssClass:"fbx-instance",countMessage:"item %index of %total",error:"Could not load the item",excludes:".fbx-link, .nofoobox",externalSelector:"a[data-foobox],input[data-foobox]",fitToScreen:!1,hideScrollbars:!0,loadDelay:0,loaderTimeout:600,modalClass:"",preload:!1,rel:null,resizeSpeed:300,selector:"a",showButtons:!0,showCount:!0,style:"fbx-rounded",theme:"fbx-light",transitionInSpeed:200,transitionOutSpeed:200,initCallback:null,loop:!0},version:"2.0.10",instances:[],ready:function(b){(Function("/*@cc_on return true@*/")()?"complete"===document.readyState:"loading"!==document.readyState)?b(a):setTimeout(function(){FooBox.ready(b)},1)}},FooBox.$=a,FooBox.format=function(a,b,c){var d,e,f=arguments[0];for(d=0;d<arguments.length-1;d++)e=new RegExp("\\{"+d+"\\}","gm"),f=f.replace(e,arguments[d+1]);return f},FooBox.browser={isIE:!1,isChrome:!1,isSafari:!1,version:0,css:"",iOS:!1,Mac:!1,isMobile:function(a){return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))}(navigator.userAgent||navigator.vendor||b.opera),check:function(){var a=navigator.appVersion.toLowerCase(),b=navigator.userAgent.toLowerCase(),c=navigator.platform;FooBox.browser.iOS=/(iPad|iPhone|iPod)/g.test(c),1==FooBox.browser.iOS&&(FooBox.browser.css+=" fbx-ios"),FooBox.browser.Mac=/(Mac)/g.test(c),1==FooBox.browser.Mac&&(FooBox.browser.css+=" fbx-mac"),FooBox.browser.isChrome=a.indexOf("chrome")>-1||a.indexOf("crios")>-1,FooBox.browser.isChrome&&(FooBox.browser.css+=" fbx-chrome"),FooBox.browser.isSafari=a.indexOf("safari")>-1&&!FooBox.browser.isChrome,FooBox.browser.isSafari&&(FooBox.browser.css+=" fbx-safari"),FooBox.browser.isFirefox=b.indexOf("firefox")>-1,FooBox.browser.isFirefox&&(FooBox.browser.css+=" fbx-firefox");var d=b.indexOf("msie "),e=b.indexOf("trident/"),f=b.indexOf("edge/");if(FooBox.browser.isIE=d>-1||e>-1||f>-1,FooBox.browser.isIE){if(d>-1)FooBox.browser.version=parseInt(b.substring(d+5,b.indexOf(".",d)),10);else if(e>-1){var g=b.indexOf("rv:");FooBox.browser.version=parseInt(b.substring(g+3,b.indexOf(".",g)),10)}else f>-1&&(FooBox.browser.version=parseInt(b.substring(f+5,b.indexOf(".",f)),10));FooBox.browser.css=FooBox.format("fbx-ie fbx-ie{0}",FooBox.browser.version)}},supportsTransitions:function(){var a,b=document.body||document.documentElement,c=b.style,d="transition";if("string"==typeof c[d])return!0;a=["Moz","Webkit","Khtml","O","ms"],d=d.charAt(0).toUpperCase()+d.substr(1);for(var e=0;e<a.length;e++)if("string"==typeof c[a[e]+d])return!0;return!1},transitionEnd:function(){var a,b=document.createElement("fakeelement"),c={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(a in c)if(c.hasOwnProperty(a)&&b.style[a]!==undefined)return c[a];return null}},FooBox.browser.check(),FooBox.qualifiedURL=function(a){var b=document.createElement("a");return b.href=a,b.href},c||(c={}),c.log=c.log||function(){},c.warn=c.warn||function(){},c.error=c.error||function(){},c.info=c.info||function(){};var d={write:function(){c.log(FooBox.format.apply(d,arguments))},error:function(){1===arguments.length&&arguments[0]instanceof Error?c.error(arguments[0]):c.error(FooBox.format.apply(d,arguments))}};jQuery.Event.prototype.fb={instance:null,modal:null,options:null},FooBox.raise=function(b,c,d){d=d||{};var e=a.Event(c);return e.fb={},e.fb.instance=b,e.fb.modal=b.modal.element,e.fb.options=b.options,a.extend(!0,e.fb,d),b.element.one(c,function(a){a.stopPropagation()}).trigger(e),e},FooBox.isjQuery=function(a){return a instanceof jQuery?!0:a&&a.jquery},FooBox.options={isMultipart:function(a,b){return"string"==typeof a&&a.length>0&&-1!==a.indexOf(b)},hasProperties:function(a){if("object"!=typeof a)return!1;var b;for(b in a)if(a.hasOwnProperty(b))return!0;return!1},get:function(a,b){if(FooBox.options.isMultipart(b,".")){var c=b.substring(0,b.indexOf(".")),d=b.substring(b.indexOf(".")+1);return a[c]=a[c]||{},FooBox.options.get(a[c],d)}return a[b]},set:function(a,b,c){if(FooBox.options.isMultipart(b,".")){var d=b.substring(0,b.indexOf(".")),e=b.substring(b.indexOf(".")+1);a[d]=a[d]||{},FooBox.options.set(a[d],e,c)}else a[b]=c},merge:function(a,b,c){var d,e=Array.prototype.slice.call(arguments);for(a=e.shift(),b=e.shift(),FooBox.options._merge(a,b),d=0;d<e.length;d++)c=e[d],FooBox.options._merge(a,c);return a},_merge:function(b,c){var d;for(d in c)c.hasOwnProperty(d)&&(FooBox.options.hasProperties(c[d])&&!a.isArray(c[d])?(b[d]=b[d]||{},FooBox.options._merge(b[d],c[d])):a.isArray(c[d])?(b[d]=[],a.extend(!0,b[d],c[d])):b[d]=c[d])}},FooBox.objects={registered:{},ensure:function(a){return FooBox.objects.registered[a]=FooBox.objects.registered[a]||[]},register:function(b,c,d){var e=FooBox.objects.ensure(b);return e.push(c),"object"==typeof d&&a.extend(!0,FooBox.defaults,d),!0},load:function(a,b){var c,e,f=[],g=FooBox.objects.ensure(a);for(e=0;e<g.length;e++)try{c=g[e],f.push(new c(b))}catch(h){d.error(h)}b.objects=b.objects||{},b.objects[a]=f},call:function(b,c,e,f,g){var h,i=Array.prototype.slice.call(arguments);b=i.shift(),c=i.shift(),e=i.shift();for(var j=c.objects[b]||[],k=0;k<j.length;k++)try{if(h=j[k],!a.isFunction(h[e]))continue;h[e].apply(h,i)}catch(l){d.error(l)}},get:function(b,c,d){var e,f=c.objects[b];if(!f||!a.isFunction(d))return null;for(e=0;e<f.length;e++)if(d(f[e]))return f[e];return null}},FooBox.addons={_ns:"addons",validate:function(b){return a.isFunction(b)?!0:(d.error('Expected type "function", received type "{0}".',typeof b),!1)},register:function(a,b){return FooBox.addons.validate(a)?FooBox.objects.register(FooBox.addons._ns,a,b):(d.error("Failed to register the addon."),!1)},load:function(a){FooBox.objects.load(FooBox.addons._ns,a)},call:function(a,b,c,d){var e=Array.prototype.slice.call(arguments);e.unshift(FooBox.addons._ns),FooBox.objects.call.apply(this,e)}},FooBox.handlers={_ns:"handlers",validate:function(b){if(!a.isFunction(b))return d.error('Expected type "function", received type "{0}".',typeof b),!1;var c=new b;return a.isFunction(c.handles)?a.isFunction(c.defaults)?a.isFunction(c.parse)?a.isFunction(c.load)?a.isFunction(c.getSize)?a.isFunction(c.hasChanged)?a.isFunction(c.preload)?!0:(d.error('The required "preload" method is not implemented.'),!1):(d.error('The required "hasChanged" method is not implemented.'),!1):(d.error('The required "getSize" method is not implemented.'),!1):(d.error('The required "load" method is not implemented.'),!1):(d.error('The required "parse" method is not implemented.'),!1):(d.error('The required "defaults" method is not implemented.'),!1):(d.error('The required "handles" method is not implemented.'),!1)},register:function(a,b){return FooBox.handlers.validate(a)?FooBox.objects.register(FooBox.handlers._ns,a,b):(d.error("Failed to register the handler."),!1)},load:function(a){FooBox.objects.load(FooBox.handlers._ns,a)},call:function(a,b,c,d){var e=Array.prototype.slice.call(arguments);e.unshift(FooBox.handlers._ns),FooBox.objects.call.apply(this,e)},get:function(a,b){return FooBox.objects.get(FooBox.handlers._ns,a,function(a){return a.type==b})}},FooBox.Item=function(b,c,d){return this.type=b,this.element=FooBox.isjQuery(c)?c:a(c),this.handler=d,this.width=null,this.height=null,this.url=null,this.overflow=!1,this.preloaded=!1,this.proportion=!1,this.error=!1,this},FooBox.Size=function(a,b){return this.width="number"==typeof a?a:parseInt(a,0),this.height="number"==typeof b?b:parseInt(b,0),this.equalTo=function(a){return this.width==a.width&&this.height==a.height},this},FooBox.Size.check=function(a){return"number"==typeof a?a:isNaN(parseInt(a))?null:parseInt(a)},FooBox.Timer=function(){this.id=null,this.busy=!1;var a=this;return this.start=function(b,c,d){d=d||b,a.stop(),a.id=setTimeout(function(){b.call(d),a.id=null,a.busy=!1},c),a.busy=!0},this.stop=function(){null!==a.id&&a.busy!==!1&&(clearTimeout(a.id),a.id=null,a.busy=!1)},this},a.fn.foobox=function(b){return b=b||{},this.each(function(){var c=a(this).data("fbx_instance");if(c instanceof FooBox.Instance)if(1==c.options.alwaysInit){var d=c.options;c.destroy(),c=new FooBox.Instance(c.id),c.init(this,a.extend(!0,d,b))}else c.reinit(b);else{if(c=a(this).data("fbx_p_instance"),c instanceof FooBox.Instance)return;c=new FooBox.Instance,c.init(this,b)}})},FooBox.Modal=function(b){this.FooBox=b,this.element=null,this.loaderTimeout=new FooBox.Timer,this._first=!1,this._busy=!1,this._closed=!1;var c=this;return this.init=function(a,b){c.setup.html(),c.setup.options(b),c.setup.bind()},this.reinit=function(a){c.setup.options(a)},this.destroy=function(){FooBox.isjQuery(c.element)&&c.element.remove()},this.setup={html:function(){if(!FooBox.isjQuery(c.element)){c.element=a('<div class="fbx-modal"></div>'),c.element.append('<div class="fbx-inner-spacer"></div>');var b=a('<div class="fbx-stage"></div>');b.append('<div class="fbx-item-current"></div>'),b.append('<div class="fbx-item-next"></div>');var d=a('<div class="fbx-inner fbx-inner-shadow"></div>');d.append(b),d.append('<a href="#prev" class="fbx-prev fbx-btn-transition fbx-btn-shadow"></a>'),d.append('<div class="fbx-credit"><a target="_blank" href=""><em></em><span> FooBox</span></a></div>'),d.append('<span class="fbx-count" />'),d.append('<a href="#next" class="fbx-next fbx-btn-transition fbx-btn-shadow"></a>'),d.append('<a href="#close" class="fbx-close fbx-btn-transition fbx-btn-shadow"></a>'),c.element.append('<div class="fbx-loader"><div></div></div>'),c.element.append(d),c.FooBox.raise("foobox.setupHtml"),a("body").append(c.element)}},options:function(a){var b;c.element.removeClass().addClass("fbx-modal").addClass(FooBox.format("fbx-{0}",c.FooBox.id)).addClass(c.FooBox.element.data("style")||a.style).addClass(c.FooBox.element.data("theme")||a.theme).addClass(c.FooBox.element.data("modal-class")).addClass(a.modalClass).data("fbx_instance",c.FooBox),c.element.addClass(FooBox.browser.css),b=a.affiliate.enabled?"":"none",c.element.find(".fbx-credit").css("display",b),a.affiliate.enabled&&(c.element.find(".fbx-credit > a").attr("href",a.affiliate.url),c.element.find(".fbx-credit > a > em").text(a.affiliate.prefix)),b=a.showCount&&c.FooBox.items.multiple()?"":"none",c.element.find(".fbx-count").css("display",b),a.showButtons&&c.FooBox.items.multiple()||c.element.addClass("fbx-no-buttons"),c.FooBox.raise("foobox.setupOptions")},bind:function(){1==c.FooBox.options.closeOnOverlayClick&&c.element.unbind("click.foobox").bind("click.foobox",function(b){1==c.FooBox.options.closeOnOverlayClick&&a(b.target).is(".fbx-modal")&&c.close()}),c.element.find(".fbx-close").unbind("click.foobox").bind("click.foobox",function(a){a.preventDefault(),a.stopPropagation(),c.close()}).end().find(".fbx-prev").unbind("click.foobox").bind("click.foobox",function(b){b.preventDefault(),b.stopPropagation(),a(this).hasClass("fbx-disabled")||c.prev()}).end().find(".fbx-next").unbind("click.foobox").bind("click.foobox",function(b){b.preventDefault(),b.stopPropagation(),a(this).hasClass("fbx-disabled")||c.next()})}},this.prioritize=function(){FooBox.instances.length>1&&c.element.nextAll(".fbx-modal:last").after(c.element)},this.preload=function(){if(1==c.FooBox.options.preload){var a=c.FooBox.items.prev();a&&a.handler.preload(a);var b=c.FooBox.items.next();b&&b.handler.preload(b)}},this.show=function(b){function e(a){if(c.loaderTimeout.stop(),c.element.removeClass("fbx-loading"),c._busy=!1,d.error(a),!c.FooBox.raise("foobox.onError",{error:a}).isDefaultPrevented()){var e=c.FooBox.items.error(f.index);null!=e&&c.show(b)}}b=b||!1,c._first=b,c._busy=!0,c._closed=!1,a("body").addClass("fbx-active"),c.FooBox.options.hideScrollbars&&a("html").css("overflow","hidden");var f=c.FooBox.items.current();1==f.error?c.element.addClass("fbx-error"):c.element.removeClass("fbx-error"),c.element.hasClass("fbx-show")||(c.prioritize(),c.element.addClass("fbx-loading").find(".fbx-inner").css({width:"100px",height:"100px","margin-top":"-50px","margin-left":"-50px"}));var g=c.element.find(".fbx-item-current"),h=c.element.find(".fbx-item-next");if(h.hide().css("opacity","0"),c.element.find(".fbx-count").text(c.FooBox.options.countMessage.replace("%index",""+(c.FooBox.items.indexes.current+1)).replace("%total",""+c.FooBox.items.array.length)),c.FooBox.raise("foobox.beforeLoad",{item:f}).isDefaultPrevented())return void(c._busy=!1);if(f.handler.hasChanged(f)){var i=f.index,j=f.element.get(0);f=f.handler.parse(f.element);var k=c.FooBox.raise("foobox.parseItem",{element:f.element,item:f});j.index=k.fb.item.index=i,c.FooBox.items.array[i]=k.fb.item}c.preload(),c.loaderTimeout.start(function(){c.element.addClass("fbx-loading")},c.FooBox.options.loaderTimeout),setTimeout(function(){c.checkForLoop(f),f.handler.load(f,h,function(a){return 1==c._closed?void(c._busy=!1):void c.transitionOut(g,function(){return 1==c._closed?void(c._busy=!1):void c.resize(a,h,function(){return 1==c._closed?void(c._busy=!1):(c.loaderTimeout.stop(),h.show(),void c.transitionIn(h,function(){return 1==c._closed?void(c._busy=!1):(h.add(g).toggleClass("fbx-item-next fbx-item-current"),g.empty(),void(c.element.hasClass("fbx-show")?(c.element.removeClass("fbx-loading"),c.FooBox.raise("foobox.afterLoad",{item:f}),c._busy=!1):c.FooBox.raise("foobox.beforeShow",{item:f}).isDefaultPrevented()||(c.element.removeClass("fbx-loading").addClass("fbx-show"),c.FooBox.raise("foobox.afterShow",{item:f}),c.FooBox.raise("foobox.afterLoad",{item:f}),c._busy=!1)))},e))},e)},e)},e)},c.FooBox.options.loadDelay)},this.checkForLoop=function(a){1!=c.FooBox.options.loop&&(c.element.find(".fbx-prev, .fbx-next").removeClass("fbx-disabled"),c.FooBox.items.is.first(a)&&c.element.find(".fbx-prev").addClass("fbx-disabled"),c.FooBox.items.is.last(a)&&c.element.find(".fbx-next").addClass("fbx-disabled"))},this.resize=function(b,d,e,f){try{if(0===b.width||0===b.height)return void(a.isFunction(f)&&f(FooBox.format("Invalid size supplied. Width = {0}, Height = {1}",b.width,b.height)));var g=c.FooBox.items.current(),h=new FooBox.Size(b.width,b.height),i=c.element.find(".fbx-inner"),j=c.element.find(".fbx-inner-spacer"),k=parseInt(j.css("padding-top"),0),l=parseInt(j.css("padding-bottom"),0),m=parseInt(j.css("padding-left"),0),n=parseInt(j.css("padding-right"),0),o=parseInt(i.css("border-top-width"),0),p=parseInt(i.css("border-bottom-width"),0),q=parseInt(i.css("border-left-width"),0),r=parseInt(i.css("border-right-width"),0),s=parseInt(i.css("padding-left"),0),t=k+l+2*s+o+p,u=m+n+2*s+q+r,v=new FooBox.Size(parseInt(i.css("width"),0),parseInt(i.css("height"),0)),w=new FooBox.Size(c.element.width()-u,c.element.height()-t),x=w.width/b.width;b.height*x>w.height&&(x=w.height/b.height),c.FooBox.options.fitToScreen===!0||1==g.proportion&&(b.height>w.height||b.width>w.width)?(b.height=Math.floor(b.height*x),b.width=Math.floor(b.width*x)):0==g.proportion&&(b.height>w.height&&(b.height=w.height),b.width>w.width&&(b.width=w.width)),b.height<100&&(b.height=100),b.width<100&&(b.width=100);var y=-(b.height/2+s+(l-k/2)/2)+(q+r)/2,z=-(b.width/2+s+(q+r)/2);if(v.equalTo(b))i.css({height:b.height,width:b.width,"margin-top":y,"margin-left":z}),c.overflow(g,h,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e();else if(!c.FooBox.raise("foobox.beforeResize",{item:g,size:b,offset:{top:y,left:z},error:f,success:e}).isDefaultPrevented())if(y=-(b.height/2+s+(l-k/2)/2)+(q+r)/2,z=-(b.width/2+s+(q+r)/2),c.element.hasClass("fbx-show"))if(FooBox.browser.supportsTransitions()){var A=c.FooBox.options.resizeSpeed/1e3,B="all "+A+"s ease-in-out";i.css({WebkitTransition:B,MozTransition:B,MsTransition:B,OTransition:B,transition:B}),i.css({height:b.height,width:b.width,"margin-top":y,"margin-left":z}),setTimeout(function(){i.css({WebkitTransition:"",MozTransition:"",MsTransition:"",OTransition:"",transition:""}),c.overflow(g,h,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e(b)},c.FooBox.options.resizeSpeed)}else i.animate({height:b.height,width:b.width,"margin-top":y,"margin-left":z},c.FooBox.options.resizeSpeed,function(){c.overflow(g,h,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e(b)});else i.css({height:b.height,width:b.width,"margin-top":y,"margin-left":z}),c.overflow(g,h,b,d),c.FooBox.raise("foobox.afterResize",{item:g,size:b}),a.isFunction(e)&&e()}catch(C){a.isFunction(f)&&f(C)}},this.overflow=function(a,b,d,e){var f=e.find(".fbx-item");1==a.overflow&&(d.width<.8*b.width||d.height<.8*b.height)||1==a.overflow&&0==a.proportion&&(d.width<b.width||d.height<b.height)||1==a.overflow&&"html"==a.type?("html"==a.type?(f.css({width:"100%",height:"auto",overflow:""}),e.css("overflow","auto")):(f.css({width:b.width,height:b.height,overflow:""}),e.css({"overflow-x":b.width<=d.width?"hidden":"","overflow-y":b.height<=d.height?"hidden":""})),c.FooBox.raise("foobox.showOverflow",{item:a,container:e})):(f.css({width:"",height:"",overflow:"hidden"}),e.css({"overflow-x":"","overflow-y":"",overflow:"hidden"}),c.FooBox.raise("foobox.hideOverflow",{item:a,container:e}))},this.transitionOut=function(b,d,e){try{if(!c.element.hasClass("fbx-show"))return void(a.isFunction(d)&&d());b.animate({opacity:0},b.is(":visible")?c.FooBox.options.transitionOutSpeed:0,function(){a.isFunction(d)&&d()})}catch(f){a.isFunction(e)&&e(f)}},this.transitionIn=function(b,d,e){try{if(!c.element.hasClass("fbx-show"))return b.css({opacity:1}),void(a.isFunction(d)&&d());b.animate({opacity:1},c.FooBox.options.transitionInSpeed,function(){a.isFunction(d)&&d()})}catch(f){a.isFunction(e)&&e(f)}},this.close=function(){c.FooBox.raise("foobox.beforeClose").isDefaultPrevented()||(c._closed=!0,c._busy=!1,c.element.removeClass("fbx-loading fbx-show"),a("body").removeClass("fbx-active"),c.FooBox.raise("foobox.close"),c.element.find(".fbx-item-current, .fbx-item-next").empty(),c.FooBox.options.hideScrollbars&&a("html").css("overflow",""),c.FooBox.raise("foobox.afterClose"))},this.prev=function(a){if(1!=c._busy){if(c.FooBox.items.indexes.set(c.FooBox.items.indexes.prev),"string"==typeof a)for(var b=c.FooBox.items.current();b.type!=a;)c.FooBox.items.indexes.set(c.FooBox.items.indexes.prev),b=c.FooBox.items.current();c.show(!1),c.FooBox.raise("foobox.previous")}},this.next=function(a){if(1!=c._busy){if(c.FooBox.items.indexes.set(c.FooBox.items.indexes.next),"string"==typeof a)for(var b=c.FooBox.items.current();b.type!=a;)c.FooBox.items.indexes.set(c.FooBox.items.indexes.next),b=c.FooBox.items.current();c.show(!1),c.FooBox.raise("foobox.next")}},this},FooBox.Instance=function(b){this.id=null,"number"==typeof b?(this.id=b,FooBox.instances[b-1]=this):this.id=FooBox.instances.push(this),this.element=null,this.options=a.extend(!0,{},FooBox.defaults),this.modal=new FooBox.Modal(this),this.objects={},FooBox.addons.load(this),FooBox.handlers.load(this);var c=this;return this.raise=function(a,b){return FooBox.raise(c,a,b)},this.init=function(b,d){c.element=FooBox.isjQuery(b)?b:a(b),c.options=FooBox.options.merge(c.options,d||{}),FooBox.addons.call(c,"preinit",c.element,c.options),c.items.init(),c.items.array.length>0?(c.element.data("fbx_instance",c),c.options.containerCssClass&&c.element.addClass(c.options.containerCssClass),c.setup.bind(),c.modal.init(b,c.options),FooBox.handlers.call(c,"init",c.element,c.options),c.raise("foobox.initialized"),a.isFunction(c.options.initCallback)&&c.options.initCallback.call(c)):c.destroy()},this.reinit=function(a){c.options=FooBox.options.merge(c.options,a||{}),c.items.init(!0),c.items.array.length>0?(c.setup.bind(),c.modal.reinit(c.options),FooBox.handlers.call(c,"reinit",c.options),c.raise("foobox.reinitialized")):c.destroy()},this.destroy=function(){FooBox.addons.call(c,"destroy"),FooBox.handlers.call(c,"destroy"),c.items.destroy(),c.modal.destroy(),c.element.removeClass("fbx-instance fbx-item").data({fbx_instance:null,fbx_p_instance:null}),c.id==FooBox.instances.length?FooBox.instances.splice(c.id-1,1):FooBox.instances[c.id-1]=null,c.raise("foobox.destroy")},this.setup={bind:function(){a(c.options.externalSelector).unbind("click.fooboxExternal").bind("click.fooboxExternal",function(b){b.preventDefault();var c=a(this).data("foobox"),d=a(c),e=d.data("fbx_instance")||d.data("fbx_p_instance");return d.length>0&&e instanceof FooBox.Instance&&e.modal instanceof FooBox.Modal&&e.modal.show(!0),!1})}},this.items={array:[],indexes:{prev:-1,current:0,next:1,direction:"*",set:function(a){var b=c.items.indexes.current;a=a||0,a=a>c.items.array.length-1?0:0>a?c.items.array.length-1:a;var d=a-1,e=a+1;c.items.indexes.current=a,c.items.indexes.prev=0>d?c.items.array.length-1:d,c.items.indexes.next=e>c.items.array.length-1?0:e,c.items.indexes.direction=c.items.indexes._direction(b,a,c.items.array.length-1)},_direction:function(a,b,c){return 0==b&&a==c?">":b==c&&0==a?"<":b>a?">":a>b?"<":"*"}},new_array:function(b){b=b||!1;var d,e,f,g=0;if(1==b){if(c.items.array.length>0){for(var h=0;h<c.items.array.length;h++)d=c.items.array[h],FooBox.isjQuery(d.element)?0==d.element.parents(":first").length&&(c.items.array.splice(h,1),h-=1):d.option||(c.items.array.splice(h,1),h-=1);for(var i=0;i<c.items.array.length;i++)d=c.items.array[i],FooBox.isjQuery(d.element)?(f=d.element.get(0),f.index=d.index=i):d.index=i}}else c.items.array=[];if(a.isArray(c.options.items))for(var j=0;j<c.options.items.length;j++)if(d=c.options.items[j],-1==c.items.indexOf(d))for(var k=0;k<c.objects.handlers.length;k++)if(c.objects.handlers[k].type==d.type){d.index=g,d.option=!0,d.handler=c.objects.handlers[k],d.handler.defaults(d),e=c.raise("foobox.parseItem",{element:null,item:d}),c.items.array.push(e.fb.item),g++;break}},init:function(a){a=a||!1,c.items.new_array(a),c.element.is(c.options.selector)&&!c.element.is(c.options.excludes)&&c.items.add(c.element)?c.element.unbind("click.item").bind("click.item",c.items.clicked):c.element.find(c.options.selector).not(c.options.excludes).unbind("click.item").filter(function(){return c.items.add(this)}).bind("click.item",c.items.clicked),c.items.rel()},destroy:function(){var b,d;for(d=0;d<c.items.array.length;d++)b=c.items.array[d],a.isFunction(b.destroy)&&b.destroy(),FooBox.isjQuery(b.element)&&b.element.unbind("click.item").removeClass("fbx-link").data("fbx_p_instance",null);c.items.array=[]},rel:function(){var b=c.options.rel||c.element.attr("rel")||(c.items.first(function(a){return FooBox.isjQuery(a.element)?"string"==typeof a.element.attr("rel"):!1})||{element:a()}).element.attr("rel");"string"==typeof b&&a('[rel="'+b+'"]').not(c.options.excludes).not(c.element).unbind("click.item").filter(function(){return c.items.add(this)}).bind("click.item",c.items.clicked)},indexOf:function(a,b){if(!a)return-1;b=b||"url";var d;for(d=0;d<c.items.array.length;d++)if(c.items.array[d][b]==a[b])return d;return-1},is:{first:function(a){return c.items.array&&0!=c.items.array.length?c.items.array[0].index==a.index:!1},last:function(a){return c.items.array&&0!=c.items.array.length?c.items.array[c.items.array.length-1].index==a.index:!1}},add:function(b){b=FooBox.isjQuery(b)?b:a(b);var d=c.items.parse(b);if(null===d)return!1;var e=b.get(0),f=c.items.indexOf(d);-1!=f?(d=c.items.array[f],e.index=d.index):e.index=d.index=c.items.array.push(d)-1;var g=b.addClass("fbx-link").data("fbx_p_instance");return g instanceof FooBox.Instance||b.data("fbx_p_instance",c),!0},get:function(b){b=FooBox.isjQuery(b)?b:a(b);var d=null,e=b.get(0).index;return e&&e>0&&e<=c.items.array.length-1&&(d=c.items.array[e]),d},parse:function(b){b=FooBox.isjQuery(b)?b:a(b);for(var d,e,f=0;f<c.objects.handlers.length;f++)if(c.objects.handlers[f].handles(b,c.element)){d=c.objects.handlers[f].parse(b),e=c.raise("foobox.parseItem",{element:b,item:d});break}return"undefined"!=typeof e&&e.fb.item?e.fb.item:null},error:function(b){function d(b){var c=this;return c.FooBox=b,c.type="error",c.handles=function(){return!1},c.hasChanged=function(){return!1},c.defaults=function(){},c.parse=function(){},c.load=function(b,d,e,f){try{d.empty().append(b.content),a.isFunction(e)&&e(c.getSize(b))}catch(g){a.isFunction(f)&&f(g)}},c.getSize=function(a){return new FooBox.Size(a.width,a.height)},c}if(c.items.array.length>b&&1==c.items.array[b].error)return c.items.array[b];var e,f,g=FooBox.handlers.get(c,"html"),h=!1;if(null==g&&(g=new d(c)),null!==c.options.error.match(/^#/i)&&a(c.options.error).length>0)e=a(c.options.error),h=!0;else{var i=FooBox.format('<div class="fbx-error-msg" data-width="240" data-height="240"><span></span><p>{0}</p></div>',c.options.error);e=a(i)}return f=new FooBox.Item(g.type,e.get(0),g),f.selector=1==h?c.options.error:null,f.index=b,f.error=!0,f.title=e.data("title")||null,f.description=e.data("description")||null,f.width=e.data("width")||240||null,f.height=e.data("height")||240||null,f.content=1==h?null:e,f.fullscreen=!0,f.handler=g,c.items.array[b]=f,f},first:function(a){for(var b=null,d=0;d<c.items.array.length;d++)if(a(c.items.array[d])){b=c.items.array[d];break}return b},current:function(){return c.items.array[c.items.indexes.current]},prev:function(){return c.items.array[c.items.indexes.prev]},next:function(){return c.items.array[c.items.indexes.next]},multiple:function(){return c.items.array.length>1},clicked:function(a){return a.preventDefault(),c.items.indexes.set(this.index),c.modal.show(!0),!1}},this},FooBox.open=function(b){if(1==FooBox.isDeepLink)return null;var c,d=null;if("object"==typeof b){var e=document.createElement("a");a(e).foobox(b),d=a(e).data("fbx_instance")}else"number"==typeof b?c=b:(c=parseInt(b||0),c=isNaN(c)?0:c),c=c>FooBox.instances.length-1?FooBox.instances.length-1:0>c?0:c,d=FooBox.instances[c];return null!=d&&d.modal instanceof FooBox.Modal?(d.modal.show(!0),d):null},FooBox.close=function(){var a,b=[],c=null;for(a=0;a<FooBox.instances.length;a++)c=FooBox.instances[a],null!=c&&c.modal instanceof FooBox.Modal&&FooBox.isjQuery(c.modal.element)&&c.modal.element.hasClass("fbx-show")&&b.push(c);for(a=0;a<b.length;a++)c=b[a],c.modal.close()},FooBox.resize=function(c,d){if(c||d){var e,f,g,h;for(e=0;e<FooBox.instances.length;e++)f=FooBox.instances[e],null!=f&&f.modal instanceof FooBox.Modal&&FooBox.isjQuery(f.modal.element)&&f.modal.element.hasClass("fbx-show")&&(g=f.items.current(),h=new FooBox.Size(c||g.width||0,d||g.height||0),g.width=h.width,g.height=h.height,f.modal.resize(h,f.modal.element.find(".fbx-item-current")))}else a(b).trigger("resize.foobox")},FooBox.lateBind=function(c,d){var e=a.extend(!0,{},FooBox.defaults,d||b.FOOBOX&&FOOBOX.o||{}),f=a(c);f.on("click.foobox",e.selector,function(a){a.preventDefault();var b=f.data("fbx_instance");b||(b=f.foobox(e).data("fbx_instance")),b instanceof FooBox.Instance&&"number"==typeof this.index&&(b.items.indexes.set(this.index),b.modal.show(!0))})}}}(jQuery,window,window.console),function(a,b){var c={images:{noRightClick:!1,attr:"href",overflow:!1,fullscreen:!0,showCaptions:!0,regex:/https?:\/\/.*?\/.*?\.(jpg|jpeg|png|gif|bmp)/i,maxWidth:-1,maxHeight:-1,findUrl:function(a,c){if(!c)return"";if(c.data("image"))return c.data("image");var d=c.attr(a.options.images.attr);return"string"==typeof d?b.qualifiedURL(c.attr(a.options.images.attr)):""}}};b.Item.prototype.image=null,b.Item.prototype.maxWidth=null,b.Item.prototype.maxHeight=null,b.ImageHandler=function(c){this.FooBox=c,this.type="image";var d=this;this.handles=function(a){var b=d.FooBox.options.images.findUrl(d.FooBox,a),c="string"==typeof b&&null!=b.match(d.FooBox.options.images.regex),e=d.FooBox.raise("foobox.handlesImage",{element:a,handle:c});return e.fb.handle},this.defaults=function(a){a.fullscreen=a.fullscreen||d.FooBox.options.images.fullscreen,a.captions=a.captions||d.FooBox.options.images.showCaptions,a.social=a.social||!0,a.overflow=a.overflow||d.FooBox.options.images.overflow,a.proportion=a.proportion||!0,a.maxWidth=a.maxWidth||d.FooBox.options.images.maxWidth,a.maxHeight=a.maxHeight||d.FooBox.options.images.maxHeight},this.parse=function(a){var c=new b.Item(d.type,a,this);return d.defaults(c),c.url=d.FooBox.options.images.findUrl(d.FooBox,a)||null,c.width=b.Size.check(a.data("width")||c.width||null),c.height=b.Size.check(a.data("height")||c.height||null),c.fullscreen="boolean"==typeof a.data("fullscreen")?a.data("fullscreen"):c.fullscreen,c.overflow="boolean"==typeof a.data("overflow")?a.data("overflow"):c.overflow,c.proportion="boolean"==typeof a.data("proportion")?a.data("proportion"):c.proportion,c.maxWidth="number"==typeof a.data("maxWidth")?a.data("maxWidth"):c.maxWidth,c.maxHeight="number"==typeof a.data("maxHeight")?a.data("maxHeight"):c.maxHeight,c.image=null,c.image_url=c.url,c},this.load=function(b,c,e,f){try{var g=function(){var f=a(b.image).addClass("fbx-item fbx-item-image");d.FooBox.options.images.noRightClick&&f.bind("contextmenu",function(a){return a.preventDefault(),!1}),c.empty().append(f),a.isFunction(e)&&e(d.getSize(b))};b.image&&null!==b.image?g():(b.image=new Image,b.image.onload=function(){b.image.onload=b.image.onerror=null,b.height=b.image.height,b.width=b.image.width,g()},b.image.onerror=function(){b.image.onload=b.image.onerror=null,b.image=null,a.isFunction(f)&&f("An error occurred attempting to load the image.")},b.image.src=b.url)}catch(h){a.isFunction(f)&&f(h)}},this.preload=function(a){if(1!=a.preloaded){var b=new Image;b.src=a.url,a.preloaded=!0}},this.getSize=function(a){if(null!=a.width&&null!=a.height){if(a.maxWidth>0&&a.maxHeight>0&&(a.width>a.maxWidth||a.height>a.maxHeight)){var c=a.width>a.height?a.maxWidth/a.width:a.maxHeight/a.height;a.width*=c,a.height*=c}return new b.Size(a.width,a.height)}return new b.Size(0,0)},this.hasChanged=function(a){if(b.isjQuery(a.element)){var c=d.FooBox.options.images.findUrl(d.FooBox,a.element);return a.url!=c}return!1}},b.handlers.register(b.ImageHandler,c)}(jQuery,window.FooBox),function(a,b){var c={keyboard:{enabled:!0,preventDefault:!1,stopPropagation:!1}};b.Keyboard=function(a){this.FooBox=a;var c=this;this.preinit=function(a){c.handlers.unbind(!0),a.bind({"foobox.initialized foobox.reinitialized":c.handlers.initialized,
10
+ "foobox.setupHtml":c.handlers.setupHtml})},this.destroy=function(){c.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&c.FooBox.element.unbind({"foobox.initialized foobox.reinitialized":c.handlers.initialized,"foobox.setupHtml":c.handlers.setupHtml}),c.FooBox.element.unbind("foobox.afterLoad",c.handlers.afterLoad),b.isjQuery(c.FooBox.modal.element)&&c.FooBox.modal.element.unbind("keydown.foobox",c.handlers.onKeydown)},initialized:function(){c.handlers.unbind(),1==c.FooBox.options.keyboard.enabled&&(c.FooBox.element.bind("foobox.afterLoad",c.handlers.afterLoad),b.isjQuery(c.FooBox.modal.element)&&c.FooBox.modal.element.bind("keydown.foobox",c.handlers.onKeydown))},setupHtml:function(a){a.fb.modal.attr("tabindex",0)},afterLoad:function(a){a.fb.modal.focus()},onKeydown:function(a){var b=c.FooBox.modal,d=c.FooBox.options.keyboard;b.element.hasClass("fbx-show")&&(b.element.hasClass("fbx-fullscreen-mode")||27!==a.which?c.FooBox.items.multiple()&&37===a.which?b.prev():c.FooBox.items.multiple()&&39===a.which&&b.next():b.close(),1==d.preventDefault&&a.preventDefault(),1==d.stopPropagation&&a.stopPropagation(),c.FooBox.raise("foobox.keydown",{keyCode:a.which}))}}},b.addons.register(b.Keyboard,c)}(jQuery,window.FooBox),function(a,b){var c={hideNavOnMobile:!1,resizeTimeout:300,breakpoints:{phone:640,tablet:1024},iosInterval:200};b.BPInfo=function(c){var d="undefined"!=typeof window.devicePixelRatio&&b.browser.isMobile?window.devicePixelRatio:1;this.width=(window.innerWidth||document.documentElement.clientWidth||(document.body?document.body.offsetWidth:0))/d,this.height=(window.innerHeight||document.documentElement.clientHeight||(document.body?document.body.offsetHeight:0))/d,this.orientation=this.width>this.height?"fbx-landscape":"fbx-portrait";var e,f=null;if(a.isArray(c))for(var g=0;g<c.length;g++)if(e=c[g],e&&e.width&&this.width<=e.width){f=e;break}this.breakpoint=null==f?"fbx-desktop":f.name},b.Responsive=function(c){this.FooBox=c,this.breakpoint={values:[],names:""},this.timers={resize:new b.Timer,ios:new b.Timer};var d=this,e=null;this.preinit=function(a){d.handlers.unbind(!0),a.bind("foobox.initialized foobox.reinitialized",d.handlers.initialized)},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(b){b=b||!1,b&&d.FooBox.element.unbind("foobox.initialized foobox.reinitialized",d.handlers.initialized),a(window).unbind("resize.foobox",d.handlers.resize),d.FooBox.element.unbind({"foobox.beforeShow":d.handlers.iosBeforeShow,"foobox.close":d.handlers.iosClose})},initialized:function(){d.handlers.unbind(),d.setup.breakpoints(),d.style(),a(window).bind("resize.foobox",d.handlers.resize),b.browser.iOS&&(b.browser.isSafari||b.browser.isChrome)&&d.FooBox.element.bind({"foobox.beforeShow":d.handlers.iosBeforeShow,"foobox.close":d.handlers.iosClose})},resize:function(){d.timers.resize.start(function(){d.style();var a=d.FooBox.items.current();if(d.FooBox.modal.element.has("fbx-show")&&null!=a){var b=a.handler.getSize(a);d.FooBox.modal.resize(b,d.FooBox.modal.element.find(".fbx-item-current"))}},d.FooBox.options.resizeTimeout)},iosBeforeShow:function(){d.timers.ios.start(d.handlers.ios,d.FooBox.options.iosInterval)},iosClose:function(){d.timers.ios.stop()},ios:function(){if(!d.FooBox.modal.element.hasClass("fbx-show"))return void d.timers.ios.start(d.handlers.ios,d.FooBox.options.iosInterval);var a=window.orientation||0,c=window.innerHeight,f=90==a||-90==a,g=0,h=0,i=f?screen.availWidth:screen.availHeight;b.browser.isChrome?(g=i-(f?76:56),h=i-(f?0:20)):b.browser.isSafari&&(g=i-88,h=i-(f?0:19)),(null==e||0==e)&&g>=c?(e=!0,d.iosRedraw()):(null==e||1==e)&&c>=h&&(e=!1,d.iosRedraw()),d.timers.ios.start(d.handlers.ios,d.FooBox.options.iosInterval)}},this.setup={breakpoints:function(){d.breakpoint.values=[],d.breakpoint.names="";for(var a in d.FooBox.options.breakpoints)d.FooBox.options.breakpoints.hasOwnProperty(a)&&(d.breakpoint.values.push({name:d.fixName(a),width:d.FooBox.options.breakpoints[a]}),d.breakpoint.names+=d.fixName(a)+" ");d.breakpoint.values.sort(function(a,b){return a.width-b.width})}},this.iosRedraw=function(){window.scrollTo(0,document.body.scrollTop),a(window).trigger("resize")},this.fixName=function(a){return/^fbx-[a-zA-Z0-9]/.test(a)?a:"fbx-"+a},this.style=function(){var a=new b.BPInfo(d.breakpoint.values),c=d.FooBox.modal.element;c.removeClass(d.breakpoint.names).removeClass("fbx-desktop fbx-landscape fbx-portrait").addClass(a.breakpoint).addClass(a.orientation),d.FooBox.options.hideNavOnMobile===!0?c.addClass("fbx-no-nav"):c.removeClass("fbx-no-nav")}},b.Responsive.metaCheck=function(){var b=a("meta[name=viewport]"),c=b.attr("content");if(b.length>0&&"string"==typeof c){for(var d=c.split(","),e=!1,f=!1,g=0;g<d.length;g++){var h=a.trim(d[g]);"width"==h.substring(0,5)?e=!0:"initial-scale"==h.substring(0,13)&&(f=!0)}e&&!f&&(d.push("initial-scale=1"),c=d.join(","),b.attr("content",c))}},b.addons.register(b.Responsive,c),b.Responsive.metaCheck()}(jQuery,window.FooBox),function(a,b){var c={captions:{animation:"slide",enabled:!0,descSource:"find",hoverDelay:300,maxHeight:.4,onlyShowOnHover:!1,onlyShowOnClick:!1,overrideDesc:!1,overrideTitle:!1,prettify:!1,titleSource:"image_find"}};b.Item.prototype.captions=!1,b.Item.prototype.title=null,b.Item.prototype.description=null,b.Item.prototype.caption=null,b.Captions=function(c){this.FooBox=c,this.timers={hover:new b.Timer};var d=this;this.preinit=function(a){d.handlers.unbind(!0),a.bind({"foobox.initialized foobox.reinitialized":d.handlers.initialized,"foobox.setupHtml":d.handlers.setupHtml,"foobox.setupOptions":d.handlers.setupOptions,"foobox.parseItem":d.handlers.parseItem,"foobox.onError":d.handlers.onError})},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&d.FooBox.element.unbind({"foobox.initialized foobox.reinitialized":d.handlers.initialized,"foobox.setupHtml":d.handlers.setupHtml,"foobox.setupOptions":d.handlers.setupOptions,"foobox.parseItem":d.handlers.parseItem,"foobox.onError":d.handlers.onError,"foobox.close":d.handlers.close}),d.FooBox.element.unbind({"foobox.beforeLoad":d.handlers.beforeLoad,"foobox.afterLoad":d.handlers.afterLoad}),d.FooBox.modal instanceof b.Modal&&b.isjQuery(d.FooBox.modal.element)&&d.FooBox.modal.element.undelegate("mouseenter.captions mouseleave.captions").find(".fbx-item-current, .fbx-item-next").unbind("click.captions")},initialized:function(a){d.handlers.unbind(),a.fb.options.captions.enabled===!0&&(a.fb.instance.element.bind({"foobox.beforeLoad":d.handlers.beforeLoad,"foobox.afterLoad":d.handlers.afterLoad,"foobox.close":d.handlers.close}),a.fb.modal.find(".fbx-item-current, .fbx-item-next").bind("click.captions",d.handlers.toggleCaptions),a.fb.options.captions.onlyShowOnHover===!0&&a.fb.modal.delegate(".fbx-inner:not(:has(.fbx-item-error))","mouseenter.captions",d.handlers.mouseenter).delegate(".fbx-inner:not(:has(.fbx-item-error))","mouseleave.captions",d.handlers.mouseleave))},toggleCaptions:function(a){return a.preventDefault(),d.FooBox.modal.element.hasClass("fbx-error")?!0:(d.FooBox.modal.element.find(".fbx-caption").is(".fbx-fade-caption, .fbx-slide-caption, .fbx-hide-caption")?(d.FooBox.modal.element.removeClass("fbx-captions-hidden"),d.show()):(d.FooBox.modal.element.addClass("fbx-captions-hidden"),d.hide()),!0)},mouseenter:function(){d.timers.hover.start(function(){d.show()},d.FooBox.options.captions.hoverDelay)},mouseleave:function(){d.timers.hover.start(function(){d.hide()},d.FooBox.options.captions.hoverDelay)},setupHtml:function(b){var c=a("<div/>",{"class":"fbx-caption"}),e=a("<a/>",{href:"#open_caption","class":"fbx-open-caption",html:"&hellip;"}).bind("click.captions",d.handlers.toggleCaptions);"string"==typeof b.fb.options.modalClass&&-1!=b.fb.options.modalClass.indexOf("fbx-sticky-caption")?b.fb.modal.append(c,e):(b.fb.modal.find(".fbx-stage").append(c),b.fb.modal.find(".fbx-inner").append(e))},setupOptions:function(a){a.fb.modal.find(".fbx-caption").addClass(d.animation())},close:function(a){1!=a.fb.options.captions.onlyShowOnHover&&a.fb.modal.find(".fbx-caption").addClass(d.animation())},beforeLoad:function(a){1!=a.fb.options.captions.onlyShowOnHover&&a.fb.modal.find(".fbx-caption").addClass(d.animation())},afterLoad:function(a){var b=a.fb.item;!b||b.error||b.captionLoaded||(a.fb.instance.raise("foobox.alterCaption",{element:a.fb.element,item:b}),b.captionLoaded=!0),1!=a.fb.options.captions.onlyShowOnHover&&0==a.fb.options.captions.onlyShowOnClick&&d.show()},onError:function(a){a.fb.modal.find(".fbx-caption").addClass(d.animation())},parseItem:function(c){var e=c.fb.options.captions;if(c.fb.item.captions&&0!=e.enabled){var f,g,h="";if(null!=c.fb.element){var i=a(c.fb.element).data("titleSource")||a(c.fb.instance.element).data("titleSource")||e.titleSource,j=a(c.fb.element).data("descSource")||a(c.fb.instance.element).data("descSource")||e.descSource;f=c.fb.element.data("captionTitle")||c.fb.element.data("title")||d.text(c.fb.element,i),g=c.fb.element.data("captionDesc")||c.fb.element.data("description")||d.text(c.fb.element,j)}else f=c.fb.item.title,g=c.fb.item.description;f=null==f||"undefined"==typeof f?"":f+"",g=null==g||"undefined"==typeof g?"":g+"",f&&f==g&&(g=null),h="string"==typeof f&&f.length>0?b.format('<div class="fbx-caption-title">{0}</div>',f):h,h="string"==typeof g&&g.length>0?h+b.format('<div class="fbx-caption-desc">{0}</div>',g):h,c.fb.item.title=f,c.fb.item.description=g,c.fb.item.caption=h,c.fb.instance.raise("foobox.createCaption",{element:c.fb.element,item:c.fb.item})}}},this.text=function(b,c){var e;switch(c){case"find":e=a.trim(b.data("enviraCaption")||b.data("title")||b.attr("title")||b.find("img:first").data("title")||b.find("img:first").data("alt")||b.find("img:first").attr("title")||b.find("img:first").attr("alt"));break;case"image_find":e=a.trim(b.find("img:first").data("title")||b.find("img:first").data("alt")||b.find("img:first").attr("title")||b.find("img:first").attr("alt"));break;case"image":e=a.trim(b.find("img:first").data("title")||b.find("img:first").attr("title"));break;case"image_alt":e=a.trim(b.find("img:first").data("alt")||b.find("img:first").attr("alt"));break;case"anchor":e=a.trim(b.data("enviraCaption")||b.data("title")||b.attr("title"));break;default:e=null}return d.FooBox.options.captions.prettify&&(e=d.prettifier(e)),e},this.animation=function(){switch(d.FooBox.options.captions.animation){case"fade":return"fbx-fade-caption";case"slide":return"fbx-slide-caption";default:return"fbx-hide-caption"}},this.hide=function(){var a=d.FooBox.items.current(),b=d.FooBox.modal.element.find(".fbx-caption");return d.FooBox.options.captions.enabled&&a.captions&&"string"==typeof a.caption&&0!=a.caption.length?(b.addClass(d.animation()),void d.FooBox.raise("foobox.captionsHide",{item:a})):void b.addClass("fbx-hide-caption")},this.show=function(){var a=d.FooBox,c=a.items.current(),e=a.modal.element.find(".fbx-caption");return!a.options.captions.enabled||!c.captions||"string"!=typeof c.caption||0==c.caption.length||a.modal.element.hasClass("fbx-captions-hidden")||b.isjQuery(c.element)&&c.element.hasClass("no-captions")?void e.addClass("fbx-hide-caption"):(d.update(),e.removeClass("fbx-fade-caption fbx-slide-caption fbx-hide-caption"),void d.FooBox.raise("foobox.captionsShow",{item:c}))},this.update=function(){var c=d.FooBox.items.current(),e=d.FooBox.modal.element.find(".fbx-caption");e.html(c.caption).find('a[href^="#"]').filter(function(){var c=a(this).attr("href"),d=a(c),e=d.data("fbx_instance")||d.data("fbx_p_instance");return d.length>0&&e instanceof b.Instance?(a(this).data("hrefTarget",d.get(0)),!0):!1}).unbind("click.captions").bind("click.captions",function(c){c.preventDefault();var e=a(this).data("hrefTarget"),f=a(e).data("fbx_instance")||a(e).data("fbx_p_instance");return f instanceof b.Instance&&(d.FooBox.modal.close(),f.items.indexes.set(e.index),f.modal.show()),!1}),a("<a/>",{href:"#close_caption","class":"fbx-close-caption",html:"&times;"}).bind("click.captions",d.handlers.toggleCaptions).prependTo(e)},this.prettifier=function(a){return"string"!=typeof a?null:(a=a.replace(/\s*-\d+/g,"").replace(/\s*_\d+/g,"").replace(/-/g," ").replace(/_/g," "),a=a.replace(/\w\S*/g,function(a){return-1!=a.indexOf("#")?a:a.charAt(0).toUpperCase()+a.substr(1).toLowerCase()}))}},b.addons.register(b.Captions,c)}(jQuery,window.FooBox),function(a,b){var c={wordpress:{enabled:!1}};b.Wordpress=function(c){this.FooBox=c;var d=this;this.preinit=function(a){d.handlers.unbind(!0),a.bind("foobox.createCaption",d.handlers.onCreateCaption)},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&d.FooBox.element.unbind("foobox.createCaption",d.handlers.onCreateCaption)},onCreateCaption:function(c){var d=c.fb.options,e=c.fb.instance.element,f=c.fb.item.element,g="",h=c.fb.item.title,i=c.fb.item.description;if(1==d.wordpress.enabled&&b.isjQuery(f)){var j=f.data("captionTitle")||f.data("title"),k=f.data("captionDesc")||f.data("description");if(e.hasClass("gallery"))d.captions.overrideTitle===!1&&(h=j||f.parents(".gallery-item:first").find(".wp-caption-text:first").html()||f.parents(".gallery-item:first").find(".gallery-caption:first").html()||h||""),d.captions.overrideDesc===!1&&(i=k||f.find("img").attr("alt")||i||"");else if(e.hasClass("wp-caption")||f.hasClass("wp-caption"))d.captions.overrideTitle===!1&&(h=j||f.find("img").attr("title")||f.parents(".wp-caption:first").find(".wp-caption-text:first").html()||h||""),d.captions.overrideDesc===!1&&(i=k||f.find("img").attr("alt")||i||"");else if(f.parents(".wp-caption:first").length>0)d.captions.overrideTitle===!1&&(h=j||f.parents(".wp-caption:first").find("img").attr("title")||f.parents(".wp-caption:first").find(".wp-caption-text:first").html()||h||""),d.captions.overrideDesc===!1&&(i=k||f.parents(".wp-caption:first").find("img").attr("alt")||i||"");else{if(!e.hasClass("tiled-gallery"))return;d.captions.overrideTitle===!1&&(h=j||f.parents(".tiled-gallery-item:first").find(".tiled-gallery-caption").html()||f.find("img").data("image-title")||f.find("img").attr("title")||h||""),d.captions.overrideDesc===!1&&(i=k||a.trim(f.find("img").data("image-description")).replace(/(^<p>)|(<\/p>$)/gi,"")||i||"")}h+="",i+="",h=h||"",i=i||"";var l=a("<div/>"),m=l.html(h).text(),n=l.html(i).text();(a.trim(h)==a.trim(i)||m==n)&&(i=null),g="string"==typeof h&&h.length>0?b.format('<div class="fbx-caption-title">{0}</div>',h):g,g="string"==typeof i&&i.length>0?g+b.format('<div class="fbx-caption-desc">{0}</div>',i):g,c.fb.item.title=h,c.fb.item.description=i,c.fb.item.caption=g}}}},b.addons.register(b.Wordpress,c)}(jQuery,window.FooBox),function(a,b){var c={pan:{enabled:!0,showOverview:!0,position:"fbx-top-right"}};b.Pan=function(c){this.FooBox=c;var d,e,f,g,h=this,i=!1,j=!1,k=null,l=null,m=null,n=null,o=null,p=0;this.preinit=function(a){h.handlers.unbind(!0),a.on({"foobox.initialized foobox.reinitialized":h.handlers.initialized})},this.destroy=function(){h.handlers.unbind(!0)},this.setOverview=function(){var a=parseInt(n.css("max-width")),b=parseInt(n.css("max-height")),c=a/k.width,d=b/k.height;p=c>d?d:c;var e=k.width*p,f=k.height*p;n.width(e).height(f).css("background-image","url("+k.url+")")},this.setViewport=function(){var a=m.width(),b=m.height(),c=a*p,d=b*p;o.width(c).height(d)},this.disableCaptionImageClick=function(){var a=h.FooBox.modal.element,c=b.objects.get("addons",h.FooBox,function(a){return a instanceof b.Captions});c&&a.find(".fbx-item-current, .fbx-item-next").unbind("click.captions",c.handlers.toggleCaptions)},this.enableCaptionImageClick=function(){var a=h.FooBox.modal.element,c=b.objects.get("addons",h.FooBox,function(a){return a instanceof b.Captions});c&&a.find(".fbx-item-current, .fbx-item-next").bind("click.captions",c.handlers.toggleCaptions)},this.handlers={unbind:function(a){a=a||!1,a&&h.FooBox.element.off({"foobox.initialized foobox.reinitialized":h.handlers.initialized}),h.FooBox.element.off({"foobox.afterLoad":h.handlers.onAfterLoad,"foobox.showOverflow":h.handlers.onShowOverflow,"foobox.hideOverflow foobox.beforeLoad":h.handlers.onHideOverflow}),h.FooBox.modal instanceof b.Modal&&b.isjQuery(h.FooBox.modal.element)&&h.FooBox.modal.element.find(".fbx-stage").off({mousedown:h.handlers.onMouseDown,mousemove:h.handlers.onMouseMove,mouseup:h.handlers.onMouseUp}).removeClass("fbx-pannable fbx-panning")},initialized:function(a){h.handlers.unbind(),a.fb.options.pan.enabled===!0&&h.FooBox.element.on({"foobox.close":h.handlers.onMouseUp,"foobox.afterLoad":h.handlers.onAfterLoad,"foobox.showOverflow":h.handlers.onShowOverflow,"foobox.hideOverflow foobox.beforeLoad":h.handlers.onHideOverflow})},onAfterLoad:function(a){i===!0&&"image"==a.fb.item.handler.type&&(h.setOverview(),h.setViewport())},onShowOverflow:function(b){"image"==b.fb.item.handler.type&&(i===!0?(h.setOverview(),h.setViewport()):(i=!0,h.disableCaptionImageClick(),k=b.fb.item,m=h.FooBox.modal.element.addClass("fbx-pannable-item").find(".fbx-stage").on({mousedown:h.handlers.onMouseDown,mousemove:h.handlers.onMouseMove,"mouseup mouseleave":h.handlers.onMouseUp}).addClass("fbx-pannable"),l=b.fb.container,b.fb.options.pan.showOverview===!0&&(n=a("<div/>",{"class":"fbx-pan-overview"}).addClass(b.fb.options.pan.position).on("click",h.handlers.onOverviewClick).appendTo(m),o=a("<div/>",{"class":"fbx-pan-viewport"}).appendTo(n),l.on("scroll",h.handlers.onScroll),h.setOverview(),h.setViewport())))},onHideOverflow:function(a){i===!0&&(i=!1,h.enableCaptionImageClick(),a.fb.options.pan.showOverview===!0&&n.remove(),l.off("scroll",h.handlers.onScroll),m.off({mousedown:h.handlers.onMouseDown,mousemove:h.handlers.onMouseMove,"mouseup mouseleave":h.handlers.onMouseUp}).removeClass("fbx-pannable fbx-panning"),h.FooBox.modal.element.removeClass("fbx-pannable-item"))},onMouseDown:function(a){if(i===!0){a.preventDefault(),m.addClass("fbx-panning");var b=l.get(0);j=!0,d=a.pageX,e=a.pageY,f=b.scrollLeft,g=b.scrollTop}},onMouseMove:function(a){if(j===!0&&i===!0){var b=l.get(0);b.scrollLeft=f-(a.pageX-d),b.scrollTop=g-(a.pageY-e)}},onMouseUp:function(){i===!0&&(j=!1,m.removeClass("fbx-panning"),d=0,e=0,f=0,g=0)},onScroll:function(){var a=l.get(0),b=a.scrollTop/k.height*100,c=a.scrollLeft/k.width*100;o.css({top:b+"%",left:c+"%"})},onOverviewClick:function(b){var c=a(this).offset(),d=(b.pageX-c.left)/p,e=(b.pageY-c.top)/p,f=d-l.width()/2,g=e-l.height()/2;l.animate({scrollTop:g,scrollLeft:f},300)}}},b.addons.register(b.Pan,c)}(jQuery,window.FooBox),function(a,b){var c={swipe:{enabled:!0,min:80}};b.Swipe=function(a){this.FooBox=a,this.isMoving=!1;var c,d=this;this.preinit=function(a){d.handlers.unbind(!0),a.bind("foobox.initialized foobox.reinitialized",d.handlers.initialized)},this.destroy=function(){d.handlers.unbind(!0)},this.handlers={unbind:function(a){a=a||!1,a&&d.FooBox.element.unbind("foobox.initialized foobox.reinitialized",d.handlers.initialized),d.FooBox.modal instanceof b.Modal&&b.isjQuery(d.FooBox.modal.element)&&d.FooBox.modal.element.unbind({touchstart:d.handlers.onTouchStart,touchmove:d.handlers.onTouchMove})},initialized:function(a){d.handlers.unbind(),a.fb.options.swipe.enabled===!0&&a.fb.modal.bind("touchstart",d.handlers.onTouchStart)},onTouchStart:function(a){var b=a.originalEvent.touches||a.touches;1==b.length&&d.FooBox.items.multiple()&&(c=b[0].pageX,d.isMoving=!0,d.FooBox.modal.element.bind("touchmove",d.handlers.onTouchMove))},onTouchMove:function(a){if(d.isMoving){var b=a.originalEvent.touches||a.touches,e=b[0].pageX,f=c-e;Math.abs(f)>=d.FooBox.options.swipe.min&&(d.cancelTouch(),f>0?(d.FooBox.raise("foobox.swipeRight"),d.FooBox.modal.next()):(d.FooBox.raise("foobox.swipeLeft"),d.FooBox.modal.prev()))}}},this.cancelTouch=function(){d.FooBox.modal.element.unbind("touchmove",d.handlers.onTouchMove),c=null,d.isMoving=!1}},b.addons.register(b.Swipe,c)}(jQuery,window.FooBox);
freemius/LICENSE.txt CHANGED
@@ -1,340 +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
-
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 CHANGED
@@ -1,245 +1,253 @@
1
- Freemius WordPress SDK
2
- ======================
3
-
4
- Freemius is an [analytics](https://freemius.com/wordpress/insights/) & [monetization](https://freemius.com/wordpress/) platform for plugin developers. Freemius empower developers with advanced real-time analytics and helps turning any plugin into a commercial product in less than 10 min.
5
-
6
- The platform is fully functional and running in production. Having said that, the monetization platform is still in closed beta.
7
- If you are a WordPress plugin developer and you are interested to monetize with Freemius [apply to our closed beta here](http://bit.ly/freemius-beta):
8
-
9
- http://bit.ly/freemius-beta
10
-
11
- **Below you'll find the integration instructions for our WordPress SDK.**
12
-
13
- ## Initializing the SDK
14
-
15
- Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
16
-
17
- ```php
18
- <?php
19
- // Create a helper function for easy SDK access.
20
- function my_prefix_fs() {
21
- global $my_prefix_fs;
22
- if ( ! isset( $my_prefix_fs ) ) {
23
- // Include Freemius SDK.
24
- require_once dirname(__FILE__) . '/freemius/start.php';
25
-
26
- $my_prefix_fs = fs_dynamic_init( array(
27
- 'id' => '1234',
28
- 'slug' => 'my-plugin-slug',
29
- 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
30
- 'public_key' => 'pk_MY_PUBLIC_KEY',
31
- 'is_live' => true,
32
- 'is_premium' => true,
33
- 'has_addons' => false,
34
- 'has_paid_plans' => false,
35
- // Set the SDK to work in a sandbox mode (for development & testing).
36
- // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
37
- 'secret_key' => 'sk_MY_SECRET_KEY',
38
- ) );
39
- }
40
-
41
- return $my_prefix_fs;
42
- }
43
-
44
- // Init Freemius.
45
- my_prefix_fs();
46
- ?>
47
- ```
48
-
49
- - **1234** - Replace with your plugin's ID.
50
- - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
51
- - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
52
- - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
53
- - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
54
-
55
-
56
- ## Usage example
57
-
58
- You can call the SDK by using the shortcode function:
59
-
60
- ```php
61
- <?php my_prefix_fs()->get_upgrade_url(); ?>
62
- ```
63
-
64
- Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
65
-
66
- ```php
67
- <?php
68
- global $my_prefix_fs;
69
- $my_prefix_fs->get_account_url();
70
- ?>
71
- ```
72
-
73
- ## Adding license based logic examples
74
-
75
- Add marketing content to encourage your users to upgrade for your paid version:
76
-
77
- ```php
78
- <?php
79
- if ( my_prefix_fs()->is_not_paying() ) {
80
- echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
81
- echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
82
- esc_html__('Upgrade Now!', 'my-plugin-slug') .
83
- '</a>';
84
- echo '</section>';
85
- }
86
- ?>
87
- ```
88
-
89
- Add logic which will only be available in your premium plugin version:
90
-
91
- ```php
92
- <?php
93
- // This "if" block will be auto removed from the Free version.
94
- if ( my_prefix_fs()->is__premium_only() ) {
95
-
96
- // ... premium only logic ...
97
-
98
- }
99
- ?>
100
- ```
101
-
102
- To add a function which will only be available in your premium plugin version, simply add __premium_only as the suffix of the function name. Just make sure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:
103
-
104
- ```php
105
- <?php
106
- class My_Plugin {
107
- function init() {
108
- ...
109
-
110
- // This "if" block will be auto removed from the free version.
111
- if ( my_prefix_fs()->is__premium_only() ) {
112
- // Init premium version.
113
- $this->admin_init__premium_only();
114
-
115
- add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
116
- }
117
-
118
- ...
119
- }
120
-
121
- // This method will be only included in the premium version.
122
- function admin_init__premium_only() {
123
- ...
124
- }
125
-
126
- // This method will be only included in the premium version.
127
- function admin_init_hook__premium_only() {
128
- ...
129
- }
130
- }
131
- ?>
132
- ```
133
-
134
- Add logic which will only be executed for customers in your 'professional' plan:
135
-
136
- ```php
137
- <?php
138
- if ( my_prefix_fs()->is_plan('professional', true) ) {
139
- // .. logic related to Professional plan only ...
140
- }
141
- ?>
142
- ```
143
-
144
- Add logic which will only be executed for customers in your 'professional' plan or higher plans:
145
-
146
- ```php
147
- <?php
148
- if ( my_prefix_fs()->is_plan('professional') ) {
149
- // ... logic related to Professional plan and higher plans ...
150
- }
151
- ?>
152
- ```
153
-
154
- Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):
155
-
156
- ```php
157
- <?php
158
- // This "if" block will be auto removed from the Free version.
159
- if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
160
- // ... logic related to Professional plan and higher plans ...
161
- }
162
- ?>
163
- ```
164
-
165
- Add logic only for users in trial:
166
-
167
- ```php
168
- <?php
169
- if ( my_prefix_fs()->is_trial() ) {
170
- // ... logic for users in trial ...
171
- }
172
- ?>
173
- ```
174
-
175
- Add logic for specified paid plan:
176
-
177
- ```php
178
- <?php
179
- // This "if" block will be auto removed from the Free version.
180
- if ( my_prefix_fs()->is__premium_only() ) {
181
- if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
182
-
183
- // ... logic related to Professional plan only ...
184
-
185
- } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
186
-
187
- // ... logic related to Business plan and higher plans ...
188
-
189
- }
190
- }
191
- ?>
192
- ```
193
-
194
- ## Excluding files and folders from the free plugin version
195
- There are two ways to exclude files from your free version.
196
-
197
- 1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included in the premium plugin version. This works for all type of files, not only PHP.
198
- 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
199
- ```php
200
- <?php
201
- /**
202
- * Plugin Name: My Very Awesome Plugin
203
- * Plugin URI: http://my-awesome-plugin.com
204
- * Description: Create and manage Awesomeness right in WordPress.
205
- * Version: 1.0.0
206
- * Author: Awesomattic
207
- * Author URI: http://my-awesome-plugin.com/me/
208
- * License: GPLv2
209
- * Text Domain: myplugin
210
- * Domain Path: /langs
211
- *
212
- * @fs_premium_only /lib/functions.php, /premium-files/
213
- */
214
-
215
- if ( ! defined( 'ABSPATH' ) ) {
216
- exit;
217
- }
218
-
219
- // ... my code ...
220
- ?>
221
- ```
222
- The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
223
-
224
- # WordPress.org Compliance
225
- Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
226
- > All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers.
227
-
228
- Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with `if ( my_prefix_fs()->{{ method }}__premium_only() )` or the other methods provided to exclude premium features & files from the free version.
229
-
230
- ## Deployment
231
- Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
232
- The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
233
-
234
- 1. **Premium version**: Identical to your uploaded version, including all code (except your `secret_key`). Will be enabled for download ONLY for your paying or in trial customers.
235
- 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
236
-
237
- The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org complaint and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo.
238
-
239
- ## Reporting Bugs
240
- Email dev [at] freemius [dot] com
241
-
242
- ## FAQ
243
-
244
- ## Copyright
245
- Freemius, Inc.
 
 
 
 
 
 
 
 
1
+ Freemius WordPress SDK
2
+ ======================
3
+
4
+ [Monetization](https://freemius.com/wordpress/), [analytics](https://freemius.com/wordpress/insights/), and marketing automation platform for plugin & theme developers. Freemius empower developers to create prosperous subscription based businesses.
5
+
6
+ You can see some of the WordPress.org plugins & themes that are utilizing the power of Freemius here:
7
+
8
+ https://includewp.com/freemius/#focus
9
+
10
+ If you are a WordPress plugin or theme developer and you are interested to monetize with Freemius you can [sign-up here for free](https://dashboard.freemius.com/register/):
11
+
12
+ https://dashboard.freemius.com/register/
13
+
14
+ **Below you'll find the integration instructions for our WordPress SDK.**
15
+
16
+ ## Code Documentation
17
+
18
+ You can find the SDK's PHP-Doc documentation here:
19
+ https://codedoc.pub/freemius/wordpress-sdk/master/
20
+
21
+ ## Initializing the SDK
22
+
23
+ Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
24
+
25
+ ```php
26
+ <?php
27
+ // Create a helper function for easy SDK access.
28
+ function my_prefix_fs() {
29
+ global $my_prefix_fs;
30
+ if ( ! isset( $my_prefix_fs ) ) {
31
+ // Include Freemius SDK.
32
+ require_once dirname(__FILE__) . '/freemius/start.php';
33
+
34
+ $my_prefix_fs = fs_dynamic_init( array(
35
+ 'id' => '1234',
36
+ 'slug' => 'my-plugin-slug',
37
+ 'menu_slug' => 'my_menu_slug', // You can also use __FILE__
38
+ 'public_key' => 'pk_MY_PUBLIC_KEY',
39
+ 'is_live' => true,
40
+ 'is_premium' => true,
41
+ 'has_addons' => false,
42
+ 'has_paid_plans' => false,
43
+ // Set the SDK to work in a sandbox mode (for development & testing).
44
+ // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
45
+ 'secret_key' => 'sk_MY_SECRET_KEY',
46
+ ) );
47
+ }
48
+
49
+ return $my_prefix_fs;
50
+ }
51
+
52
+ // Init Freemius.
53
+ my_prefix_fs();
54
+ ?>
55
+ ```
56
+
57
+ - **1234** - Replace with your plugin's ID.
58
+ - **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
59
+ - **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
60
+ - **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
61
+ - **my_menu_slug** - Replace with your admin dashboard settings menu slug.
62
+
63
+
64
+ ## Usage example
65
+
66
+ You can call the SDK by using the shortcode function:
67
+
68
+ ```php
69
+ <?php my_prefix_fs()->get_upgrade_url(); ?>
70
+ ```
71
+
72
+ Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
73
+
74
+ ```php
75
+ <?php
76
+ global $my_prefix_fs;
77
+ $my_prefix_fs->get_account_url();
78
+ ?>
79
+ ```
80
+
81
+ ## Adding license based logic examples
82
+
83
+ Add marketing content to encourage your users to upgrade for your paid version:
84
+
85
+ ```php
86
+ <?php
87
+ if ( my_prefix_fs()->is_not_paying() ) {
88
+ echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
89
+ echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
90
+ esc_html__('Upgrade Now!', 'my-plugin-slug') .
91
+ '</a>';
92
+ echo '</section>';
93
+ }
94
+ ?>
95
+ ```
96
+
97
+ Add logic which will only be available in your premium plugin version:
98
+
99
+ ```php
100
+ <?php
101
+ // This "if" block will be auto removed from the Free version.
102
+ if ( my_prefix_fs()->is__premium_only() ) {
103
+
104
+ // ... premium only logic ...
105
+
106
+ }
107
+ ?>
108
+ ```
109
+
110
+ 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:
111
+
112
+ ```php
113
+ <?php
114
+ class My_Plugin {
115
+ function init() {
116
+ ...
117
+
118
+ // This "if" block will be auto removed from the free version.
119
+ if ( my_prefix_fs()->is__premium_only() ) {
120
+ // Init premium version.
121
+ $this->admin_init__premium_only();
122
+
123
+ add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
124
+ }
125
+
126
+ ...
127
+ }
128
+
129
+ // This method will be only included in the premium version.
130
+ function admin_init__premium_only() {
131
+ ...
132
+ }
133
+
134
+ // This method will be only included in the premium version.
135
+ function admin_init_hook__premium_only() {
136
+ ...
137
+ }
138
+ }
139
+ ?>
140
+ ```
141
+
142
+ Add logic which will only be executed for customers in your 'professional' plan:
143
+
144
+ ```php
145
+ <?php
146
+ if ( my_prefix_fs()->is_plan('professional', true) ) {
147
+ // .. logic related to Professional plan only ...
148
+ }
149
+ ?>
150
+ ```
151
+
152
+ Add logic which will only be executed for customers in your 'professional' plan or higher plans:
153
+
154
+ ```php
155
+ <?php
156
+ if ( my_prefix_fs()->is_plan('professional') ) {
157
+ // ... logic related to Professional plan and higher plans ...
158
+ }
159
+ ?>
160
+ ```
161
+
162
+ 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):
163
+
164
+ ```php
165
+ <?php
166
+ // This "if" block will be auto removed from the Free version.
167
+ if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
168
+ // ... logic related to Professional plan and higher plans ...
169
+ }
170
+ ?>
171
+ ```
172
+
173
+ Add logic only for users in trial:
174
+
175
+ ```php
176
+ <?php
177
+ if ( my_prefix_fs()->is_trial() ) {
178
+ // ... logic for users in trial ...
179
+ }
180
+ ?>
181
+ ```
182
+
183
+ Add logic for specified paid plan:
184
+
185
+ ```php
186
+ <?php
187
+ // This "if" block will be auto removed from the Free version.
188
+ if ( my_prefix_fs()->is__premium_only() ) {
189
+ if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
190
+
191
+ // ... logic related to Professional plan only ...
192
+
193
+ } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
194
+
195
+ // ... logic related to Business plan and higher plans ...
196
+
197
+ }
198
+ }
199
+ ?>
200
+ ```
201
+
202
+ ## Excluding files and folders from the free plugin version
203
+ There are two ways to exclude files from your free version.
204
+
205
+ 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.
206
+ 2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
207
+ ```php
208
+ <?php
209
+ /**
210
+ * Plugin Name: My Very Awesome Plugin
211
+ * Plugin URI: http://my-awesome-plugin.com
212
+ * Description: Create and manage Awesomeness right in WordPress.
213
+ * Version: 1.0.0
214
+ * Author: Awesomattic
215
+ * Author URI: http://my-awesome-plugin.com/me/
216
+ * License: GPLv2
217
+ * Text Domain: myplugin
218
+ * Domain Path: /langs
219
+ *
220
+ * @fs_premium_only /lib/functions.php, /premium-files/
221
+ */
222
+
223
+ if ( ! defined( 'ABSPATH' ) ) {
224
+ exit;
225
+ }
226
+
227
+ // ... my code ...
228
+ ?>
229
+ ```
230
+ The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
231
+
232
+ # WordPress.org Compliance
233
+ 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:
234
+ > 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.
235
+
236
+ 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.
237
+
238
+ ## Deployment
239
+ Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
240
+ The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
241
+
242
+ 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.
243
+ 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
244
+
245
+ 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.
246
+
247
+ ## Reporting Bugs
248
+ Email dev [at] freemius [dot] com
249
+
250
+ ## FAQ
251
+
252
+ ## Copyright
253
+ Freemius, Inc.
freemius/assets/css/admin/account.css CHANGED
@@ -1 +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}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_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}
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}#fs_account_details .button-group{float:right}.rtl #fs_account .fs-header-actions{left:15px;right:auto}.fs-key-value-table{width:100%}.fs-key-value-table form{display:inline-block}.fs-key-value-table tr td:first-child{text-align:right}.fs-key-value-table tr td:first-child nobr{font-weight:bold}.fs-key-value-table tr td:first-child form{display:block}.fs-key-value-table tr td.fs-right{text-align:right}.fs-key-value-table tr.fs-odd{background:#ebebeb}.fs-key-value-table td,.fs-key-value-table th{padding:10px}.fs-key-value-table code{line-height:28px}.fs-key-value-table var,.fs-key-value-table code,.fs-key-value-table input[type="text"]{color:#0073AA;font-size:16px;background:none}.fs-key-value-table input[type="text"]{width:100%;font-weight:bold}label.fs-tag{background:#ffba00;color:#fff;display:inline-block;border-radius:3px;padding:5px;font-size:11px;line-height:11px;vertical-align:baseline}label.fs-tag.fs-warn{background:#ffba00}label.fs-tag.fs-success{background:#46b450}label.fs-tag.fs-error{background:#dc3232}#fs_addons h3{border:none;margin-bottom:0;padding:4px 5px}#fs_addons td{vertical-align:middle}#fs_addons thead{white-space:nowrap}#fs_addons td:first-child,#fs_addons th:first-child{text-align:left;font-weight:bold}#fs_addons td:last-child,#fs_addons th:last-child{text-align:right}#fs_addons th{font-weight:bold}#fs_billing_address{width:100%}#fs_billing_address tr td{width:50%;padding:5px}#fs_billing_address tr:first-of-type td{padding-top:0}#fs_billing_address span{font-weight:bold}#fs_billing_address input,#fs_billing_address select{display:block;width:100%;margin-top:5px}#fs_billing_address input::-moz-placeholder,#fs_billing_address select::-moz-placeholder{color:transparent;opacity:1}#fs_billing_address input:-ms-input-placeholder,#fs_billing_address select:-ms-input-placeholder{color:transparent}#fs_billing_address input::-webkit-input-placeholder,#fs_billing_address select::-webkit-input-placeholder{color:transparent}#fs_billing_address input.fs-read-mode,#fs_billing_address select.fs-read-mode{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode td span{display:none}#fs_billing_address.fs-read-mode input,#fs_billing_address.fs-read-mode select{border-color:transparent;color:#777;border-bottom:1px dashed #ccc;padding-left:0;background:none}#fs_billing_address.fs-read-mode input::-moz-placeholder,#fs_billing_address.fs-read-mode select::-moz-placeholder{color:#ccc;opacity:1}#fs_billing_address.fs-read-mode input:-ms-input-placeholder,#fs_billing_address.fs-read-mode select:-ms-input-placeholder{color:#ccc}#fs_billing_address.fs-read-mode input::-webkit-input-placeholder,#fs_billing_address.fs-read-mode select::-webkit-input-placeholder{color:#ccc}#fs_billing_address button{display:block;width:100%}
freemius/assets/css/admin/add-ons.css CHANGED
@@ -1,2 +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}}
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 CHANGED
@@ -1 +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: 500px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}
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: 500px){#fs_promo_tab{display:none}}@media screen and (max-width: 782px){.fs-secure-notice{left:0;top:46px;text-align:center}}span.fs-submenu-item.fs-sub:before{content:'\21B3';padding:0 5px}.rtl span.fs-submenu-item.fs-sub:before{content:'\21B2'}.fs-submenu-item.pricing.upgrade-mode{color:greenyellow}.fs-submenu-item.pricing.trial-mode{color:#83e2ff}#adminmenu .update-plugins.fs-trial{background-color:#00b9eb}
freemius/assets/css/admin/connect.css CHANGED
@@ -1 +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}
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 CHANGED
@@ -1 +1 @@
1
- .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input,.fs-modal .fs-modal-dialog li.reason .internal-message{margin-left:29px}.fs-modal .fs-modal-dialog li.reason label{display:table}.fs-modal .fs-modal-dialog li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}.fs-modal .reason-input,.fs-modal .internal-message{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea,.fs-modal .internal-message input,.fs-modal .internal-message textarea{width:100%}.fs-modal li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}.fs-modal .fs-modal-dialog li.reason{margin-bottom:10px}.fs-modal .fs-modal-dialog li.reason .reason-input,.fs-modal .fs-modal-dialog li.reason .internal-message{margin-left:29px}.fs-modal .fs-modal-dialog li.reason label{display:table}.fs-modal .fs-modal-dialog li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}.fs-modal .reason-input,.fs-modal .internal-message{margin:3px 0 3px 22px}.fs-modal .reason-input input,.fs-modal .reason-input textarea,.fs-modal .internal-message input,.fs-modal .internal-message textarea{width:100%}.fs-modal li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}body.has-fs-modal{overflow:hidden}#the-list .deactivate>.fs-slug{display:none}
freemius/assets/css/admin/debug.css CHANGED
@@ -1 +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}
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/dialog-boxes.css CHANGED
@@ -1,2 +1,2 @@
1
- .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-body{border-bottom:0}.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>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media (max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label{float:left}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-license-activation .fs-modal-body input.license_key{width:100%}.fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend .fs-modal-body input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{margin-top:2px}}
2
- .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}
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-header{border-bottom:#eeeeee solid 1px;background:#fbfbfb;padding:15px 20px;position:relative;margin-bottom:-10px}.fs-modal .fs-modal-header h4{margin:0;padding:0;text-transform:uppercase;font-size:1.2em;font-weight:bold;color:#cacaca;text-shadow:1px 1px 1px #fff;letter-spacing:0.6px;-webkit-font-smoothing:antialiased}.fs-modal .fs-modal-header .fs-close{position:absolute;right:10px;top:12px;cursor:pointer;color:#bbb;-moz-border-radius:20px;-webkit-border-radius:20px;border-radius:20px;padding:3px;-moz-transition:all 0.2s ease-in-out;-o-transition:all 0.2s ease-in-out;-ms-transition:all 0.2s ease-in-out;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out}.fs-modal .fs-modal-header .fs-close:hover{color:#fff;background:#aaa}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px;line-height:1.5em}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel>.notice.inline{margin:0;display:none}.fs-modal .fs-modal-panel:not(.active){display:none}.rtl .fs-modal .fs-modal-header .fs-close{right:auto;left:20px}body.has-fs-modal{overflow:hidden}.fs-modal.fs-modal-deactivation-feedback .reason-input,.fs-modal.fs-modal-deactivation-feedback .internal-message{margin:3px 0 3px 22px}.fs-modal.fs-modal-deactivation-feedback .reason-input input,.fs-modal.fs-modal-deactivation-feedback .reason-input textarea,.fs-modal.fs-modal-deactivation-feedback .internal-message input,.fs-modal.fs-modal-deactivation-feedback .internal-message textarea{width:100%}.fs-modal.fs-modal-deactivation-feedback li.reason.has-internal-message .internal-message{border:1px solid #ccc;padding:7px;display:none}@media (max-width: 650px){.fs-modal.fs-modal-deactivation-feedback li.reason li.reason{margin-bottom:10px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .reason-input,.fs-modal.fs-modal-deactivation-feedback li.reason li.reason .internal-message{margin-left:29px}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label{display:table}.fs-modal.fs-modal-deactivation-feedback li.reason li.reason label>span{display:table-cell;font-size:1.3em}}.fs-modal.fs-modal-deactivation-feedback .anonymous-feedback-label{float:left}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel{margin-top:0 !important}.fs-modal.fs-modal-deactivation-feedback .fs-modal-panel h3{margin-top:0;line-height:1.5em}#the-list .deactivate>.fs-slug{display:none}.fs-modal.fs-modal-license-activation .fs-modal-body input.license_key{width:100%}.fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{overflow:hidden;padding-right:2px}.fs-modal.fs-modal-license-key-resend .fs-modal-body input.email-address{width:100%}.fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:right;margin-left:7px}@media (max-width: 650px){.fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{margin-top:2px}}
2
+ .rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .input-container>.email-address-container{padding-left:2px;padding-right:0}.rtl .fs-modal.fs-modal-license-key-resend .fs-modal-body .button-container{float:left;margin-right:7px;margin-left:0}a.show-license-resend-modal{margin-top:4px;display:inline-block}
freemius/assets/css/admin/license-activation.css CHANGED
@@ -1 +1 @@
1
- .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body .license-activation-message{margin:0;display:none}.fs-modal .fs-modal-body input.license_key{width:100%}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}body.has-fs-modal{overflow:hidden}
1
+ .fs-modal{position:fixed;overflow:auto;height:100%;width:100%;top:0;z-index:100000;display:none;background:rgba(0,0,0,0.6)}.fs-modal .fs-modal-dialog{background:transparent;position:absolute;left:50%;margin-left:-298px;padding-bottom:30px;top:-100%;z-index:100001;width:596px}@media (max-width: 650px){.fs-modal .fs-modal-dialog{margin-left:-50%;box-sizing:border-box;padding-left:10px;padding-right:10px;width:100%}.fs-modal .fs-modal-dialog .fs-modal-panel>h3>strong{font-size:1.3em}}.fs-modal.active{display:block}.fs-modal.active:before{display:block}.fs-modal.active .fs-modal-dialog{top:10%}.fs-modal .fs-modal-body,.fs-modal .fs-modal-footer{border:0;background:#fefefe;padding:20px}.fs-modal .fs-modal-body{border-bottom:0}.fs-modal .fs-modal-body .license-activation-message{margin:0;display:none}.fs-modal .fs-modal-body input.license_key{width:100%}.fs-modal .fs-modal-body p{font-size:14px}.fs-modal .fs-modal-body h2{font-size:20px}.fs-modal .fs-modal-body>div{margin-top:10px}.fs-modal .fs-modal-body>div h2{font-weight:bold;font-size:20px;margin-top:0}.fs-modal .fs-modal-footer{border-top:#eeeeee solid 1px;text-align:right}.fs-modal .fs-modal-footer>.button{margin:0 7px}.fs-modal .fs-modal-footer>.button:first-child{margin:0}.fs-modal .fs-modal-panel:not(.active){display:none}body.has-fs-modal{overflow:hidden}
freemius/assets/js/nojquery.ba-postmessage.js CHANGED
@@ -1,140 +1,140 @@
1
- /*!
2
- * jQuery postMessage - v0.5 - 9/11/2009
3
- * http://benalman.com/projects/jquery-postmessage-plugin/
4
- *
5
- * Copyright (c) 2009 "Cowboy" Ben Alman
6
- * Dual licensed under the MIT and GPL licenses.
7
- * http://benalman.com/about/license/
8
- *
9
- * Non-jQuery fork by Jeff Lee
10
- *
11
- * This fork consists of the following changes:
12
- * 1. Basic code cleanup and restructuring, for legibility.
13
- * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
- * in terms of both function names and object scope. Scope is specified by
15
- * the the "this" context of NoJQueryPostMessageMixin();
16
- * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
- * at least three different GitHub users requesting the removal of this
18
- * "Opera sniff" on the original project's Issues page, so I figured this
19
- * would be a relatively safe change.
20
- * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
- * strings. I actually prefer this structure anyway. `receiveMessage` does
22
- * not implement a corresponding deserialization step, and as such it seems
23
- * cleaner and more symmetric to leave both data serialization and
24
- * deserialization to the client.
25
- * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
- * 6. The `$:nomunge` YUI option is no longer necessary.
27
- */
28
-
29
- function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
-
31
- var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
- intervalId, lastHash, cacheBust = 1;
33
-
34
- if (window.postMessage) {
35
-
36
- if (window.addEventListener) {
37
- setMessageCallback = function(callback) {
38
- window.addEventListener('message', callback, false);
39
- }
40
-
41
- unsetMessageCallback = function(callback) {
42
- window.removeEventListener('message', callback, false);
43
- }
44
- } else {
45
- setMessageCallback = function(callback) {
46
- window.attachEvent('onmessage', callback);
47
- }
48
-
49
- unsetMessageCallback = function(callback) {
50
- window.detachEvent('onmessage', callback);
51
- }
52
- }
53
-
54
- this[postBinding] = function(message, targetUrl, target) {
55
- if (!targetUrl) {
56
- return;
57
- }
58
-
59
- // The browser supports window.postMessage, so call it with a targetOrigin
60
- // set appropriately, based on the targetUrl parameter.
61
- target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
- }
63
-
64
- // Since the browser supports window.postMessage, the callback will be
65
- // bound to the actual event associated with window.postMessage.
66
- this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
- // Unbind an existing callback if it exists.
68
- if (currentMsgCallback) {
69
- unsetMessageCallback(currentMsgCallback);
70
- currentMsgCallback = null;
71
- }
72
-
73
- if (!callback) {
74
- return false;
75
- }
76
-
77
- // Bind the callback. A reference to the callback is stored for ease of
78
- // unbinding.
79
- currentMsgCallback = setMessageCallback(function(e) {
80
- switch(Object.prototype.toString.call(sourceOrigin)) {
81
- case '[object String]':
82
- if (sourceOrigin !== e.origin) {
83
- return false;
84
- }
85
- break;
86
- case '[object Function]':
87
- if (sourceOrigin(e.origin)) {
88
- return false;
89
- }
90
- break;
91
- }
92
-
93
- callback(e);
94
- });
95
- };
96
-
97
- } else {
98
-
99
- this[postBinding] = function(message, targetUrl, target) {
100
- if (!targetUrl) {
101
- return;
102
- }
103
-
104
- // The browser does not support window.postMessage, so set the location
105
- // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
- // bust parameter is added to ensure that repeat messages trigger the
107
- // callback.
108
- target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
- }
110
-
111
- // Since the browser sucks, a polling loop will be started, and the
112
- // callback will be called whenever the location.hash changes.
113
- this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
- if (intervalId) {
115
- clearInterval(intervalId);
116
- intervalId = null;
117
- }
118
-
119
- if (callback) {
120
- delay = typeof sourceOrigin === 'number'
121
- ? sourceOrigin
122
- : typeof delay === 'number'
123
- ? delay
124
- : 100;
125
-
126
- intervalId = setInterval(function(){
127
- var hash = document.location.hash,
128
- re = /^#?\d+&/;
129
- if ( hash !== lastHash && re.test( hash ) ) {
130
- lastHash = hash;
131
- callback({ data: hash.replace( re, '' ) });
132
- }
133
- }, delay );
134
- }
135
- };
136
-
137
- }
138
-
139
- return this;
140
  }
1
+ /*!
2
+ * jQuery postMessage - v0.5 - 9/11/2009
3
+ * http://benalman.com/projects/jquery-postmessage-plugin/
4
+ *
5
+ * Copyright (c) 2009 "Cowboy" Ben Alman
6
+ * Dual licensed under the MIT and GPL licenses.
7
+ * http://benalman.com/about/license/
8
+ *
9
+ * Non-jQuery fork by Jeff Lee
10
+ *
11
+ * This fork consists of the following changes:
12
+ * 1. Basic code cleanup and restructuring, for legibility.
13
+ * 2. The `postMessage` and `receiveMessage` functions can be bound arbitrarily,
14
+ * in terms of both function names and object scope. Scope is specified by
15
+ * the the "this" context of NoJQueryPostMessageMixin();
16
+ * 3. I've removed the check for Opera 9.64, which used `$.browser`. There were
17
+ * at least three different GitHub users requesting the removal of this
18
+ * "Opera sniff" on the original project's Issues page, so I figured this
19
+ * would be a relatively safe change.
20
+ * 4. `postMessage` no longer uses `$.param` to serialize messages that are not
21
+ * strings. I actually prefer this structure anyway. `receiveMessage` does
22
+ * not implement a corresponding deserialization step, and as such it seems
23
+ * cleaner and more symmetric to leave both data serialization and
24
+ * deserialization to the client.
25
+ * 5. The use of `$.isFunction` is replaced by a functionally-identical check.
26
+ * 6. The `$:nomunge` YUI option is no longer necessary.
27
+ */
28
+
29
+ function NoJQueryPostMessageMixin(postBinding, receiveBinding) {
30
+
31
+ var setMessageCallback, unsetMessageCallback, currentMsgCallback,
32
+ intervalId, lastHash, cacheBust = 1;
33
+
34
+ if (window.postMessage) {
35
+
36
+ if (window.addEventListener) {
37
+ setMessageCallback = function(callback) {
38
+ window.addEventListener('message', callback, false);
39
+ }
40
+
41
+ unsetMessageCallback = function(callback) {
42
+ window.removeEventListener('message', callback, false);
43
+ }
44
+ } else {
45
+ setMessageCallback = function(callback) {
46
+ window.attachEvent('onmessage', callback);
47
+ }
48
+
49
+ unsetMessageCallback = function(callback) {
50
+ window.detachEvent('onmessage', callback);
51
+ }
52
+ }
53
+
54
+ this[postBinding] = function(message, targetUrl, target) {
55
+ if (!targetUrl) {
56
+ return;
57
+ }
58
+
59
+ // The browser supports window.postMessage, so call it with a targetOrigin
60
+ // set appropriately, based on the targetUrl parameter.
61
+ target.postMessage( message, targetUrl.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ) );
62
+ }
63
+
64
+ // Since the browser supports window.postMessage, the callback will be
65
+ // bound to the actual event associated with window.postMessage.
66
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
67
+ // Unbind an existing callback if it exists.
68
+ if (currentMsgCallback) {
69
+ unsetMessageCallback(currentMsgCallback);
70
+ currentMsgCallback = null;
71
+ }
72
+
73
+ if (!callback) {
74
+ return false;
75
+ }
76
+
77
+ // Bind the callback. A reference to the callback is stored for ease of
78
+ // unbinding.
79
+ currentMsgCallback = setMessageCallback(function(e) {
80
+ switch(Object.prototype.toString.call(sourceOrigin)) {
81
+ case '[object String]':
82
+ if (sourceOrigin !== e.origin) {
83
+ return false;
84
+ }
85
+ break;
86
+ case '[object Function]':
87
+ if (sourceOrigin(e.origin)) {
88
+ return false;
89
+ }
90
+ break;
91
+ }
92
+
93
+ callback(e);
94
+ });
95
+ };
96
+
97
+ } else {
98
+
99
+ this[postBinding] = function(message, targetUrl, target) {
100
+ if (!targetUrl) {
101
+ return;
102
+ }
103
+
104
+ // The browser does not support window.postMessage, so set the location
105
+ // of the target to targetUrl#message. A bit ugly, but it works! A cache
106
+ // bust parameter is added to ensure that repeat messages trigger the
107
+ // callback.
108
+ target.location = targetUrl.replace( /#.*$/, '' ) + '#' + (+new Date) + (cacheBust++) + '&' + message;
109
+ }
110
+
111
+ // Since the browser sucks, a polling loop will be started, and the
112
+ // callback will be called whenever the location.hash changes.
113
+ this[receiveBinding] = function(callback, sourceOrigin, delay) {
114
+ if (intervalId) {
115
+ clearInterval(intervalId);
116
+ intervalId = null;
117
+ }
118
+
119
+ if (callback) {
120
+ delay = typeof sourceOrigin === 'number'
121
+ ? sourceOrigin
122
+ : typeof delay === 'number'
123
+ ? delay
124
+ : 100;
125
+
126
+ intervalId = setInterval(function(){
127
+ var hash = document.location.hash,
128
+ re = /^#?\d+&/;
129
+ if ( hash !== lastHash && re.test( hash ) ) {
130
+ lastHash = hash;
131
+ callback({ data: hash.replace( re, '' ) });
132
+ }
133
+ }, delay );
134
+ }
135
+ };
136
+
137
+ }
138
+
139
+ return this;
140
  }
freemius/assets/js/nojquery.ba-postmessage.min.js CHANGED
@@ -1,12 +1,12 @@
1
- /*
2
- * nojquery-postmessage by Jeff Lee
3
- * a non-jQuery fork of:
4
- *
5
- * jQuery postMessage - v0.5 - 9/11/2009
6
- * http://benalman.com/projects/jquery-postmessage-plugin/
7
- *
8
- * Copyright (c) 2009 "Cowboy" Ben Alman
9
- * Dual licensed under the MIT and GPL licenses.
10
- * http://benalman.com/about/license/
11
- */
12
  function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
1
+ /*
2
+ * nojquery-postmessage by Jeff Lee
3
+ * a non-jQuery fork of:
4
+ *
5
+ * jQuery postMessage - v0.5 - 9/11/2009
6
+ * http://benalman.com/projects/jquery-postmessage-plugin/
7
+ *
8
+ * Copyright (c) 2009 "Cowboy" Ben Alman
9
+ * Dual licensed under the MIT and GPL licenses.
10
+ * http://benalman.com/about/license/
11
+ */
12
  function NoJQueryPostMessageMixin(g,a){var b,h,e,d,f,c=1;if(window.postMessage){if(window.addEventListener){b=function(i){window.addEventListener("message",i,false)};h=function(i){window.removeEventListener("message",i,false)}}else{b=function(i){window.attachEvent("onmessage",i)};h=function(i){window.detachEvent("onmessage",i)}}this[g]=function(i,k,j){if(!k){return}j.postMessage(i,k.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))};this[a]=function(k,j,i){if(e){h(e);e=null}if(!k){return false}e=b(function(l){switch(Object.prototype.toString.call(j)){case"[object String]":if(j!==l.origin){return false}break;case"[object Function]":if(j(l.origin)){return false}break}k(l)})}}else{this[g]=function(i,k,j){if(!k){return}j.location=k.replace(/#.*$/,"")+"#"+(+new Date)+(c++)+"&"+i};this[a]=function(k,j,i){if(d){clearInterval(d);d=null}if(k){i=typeof j==="number"?j:typeof i==="number"?i:100;d=setInterval(function(){var m=document.location.hash,l=/^#?\d+&/;if(m!==f&&l.test(m)){f=m;k({data:m.replace(l,"")})}},i)}}}return this};
freemius/assets/js/postmessage.js CHANGED
@@ -1,135 +1,135 @@
1
- (function ($, undef) {
2
- var global = this;
3
-
4
- // Namespace.
5
- global.FS = global.FS || {};
6
-
7
- global.FS.PostMessage = function ()
8
- {
9
- var
10
- _is_child = false,
11
- _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
- _callbacks = {},
13
- _base_url,
14
- _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
- _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
- _init = function () {
17
- _postman.receiveMessage(function (e) {
18
- var data = JSON.parse(e.data);
19
-
20
- if (_callbacks[data.type]) {
21
- for (var i = 0; i < _callbacks[data.type].length; i++) {
22
- // Execute type callbacks.
23
- _callbacks[data.type][i](data.data);
24
- }
25
- }
26
- }, _base_url);
27
- },
28
- _hasParent = ('' !== _parent_url),
29
- $window = $(window),
30
- $html = $('html');
31
-
32
- return {
33
- init : function (url, iframes)
34
- {
35
- _base_url = url;
36
- _init();
37
-
38
- // Automatically receive forward messages.
39
- FS.PostMessage.receiveOnce('forward', function (data){
40
- window.location = data.url;
41
- });
42
-
43
- iframes = iframes || [];
44
-
45
- if (iframes.length > 0) {
46
- $window.on('scroll', function () {
47
- for (var i = 0; i < iframes.length; i++) {
48
- FS.PostMessage.postScroll(iframes[i]);
49
- }
50
- });
51
- }
52
- },
53
- init_child : function ()
54
- {
55
- this.init(_parent_subdomain);
56
-
57
- _is_child = true;
58
-
59
- // Post height of a child right after window is loaded.
60
- $(window).bind('load', function () {
61
- FS.PostMessage.postHeight();
62
-
63
- // Post message that window was loaded.
64
- FS.PostMessage.post('loaded');
65
- });
66
- },
67
- hasParent : function ()
68
- {
69
- return _hasParent;
70
- },
71
- postHeight : function (diff, wrapper) {
72
- diff = diff || 0;
73
- wrapper = wrapper || '#wrap_section';
74
- this.post('height', {
75
- height: diff + $(wrapper).outerHeight(true)
76
- });
77
- },
78
- postScroll : function (iframe) {
79
- this.post('scroll', {
80
- top: $window.scrollTop(),
81
- height: ($window.height() - parseFloat($html.css('paddingTop')) - parseFloat($html.css('marginTop')))
82
- }, iframe);
83
- },
84
- post : function (type, data, iframe)
85
- {
86
- console.debug('PostMessage.post', type);
87
-
88
- if (iframe)
89
- {
90
- // Post to iframe.
91
- _postman.postMessage(JSON.stringify({
92
- type: type,
93
- data: data
94
- }), iframe.src, iframe.contentWindow);
95
- }
96
- else {
97
- // Post to parent.
98
- _postman.postMessage(JSON.stringify({
99
- type: type,
100
- data: data
101
- }), _parent_url, window.parent);
102
- }
103
- },
104
- receive: function (type, callback)
105
- {
106
- console.debug('PostMessage.receive', type);
107
-
108
- if (undef === _callbacks[type])
109
- _callbacks[type] = [];
110
-
111
- _callbacks[type].push(callback);
112
- },
113
- receiveOnce: function (type, callback)
114
- {
115
- if (this.is_set(type))
116
- return;
117
-
118
- this.receive(type, callback);
119
- },
120
- // Check if any callbacks assigned to a specified message type.
121
- is_set: function (type)
122
- {
123
- return (undef != _callbacks[type]);
124
- },
125
- parent_url: function ()
126
- {
127
- return _parent_url;
128
- },
129
- parent_subdomain: function ()
130
- {
131
- return _parent_subdomain;
132
- }
133
- };
134
- }();
135
  })(jQuery);
1
+ (function ($, undef) {
2
+ var global = this;
3
+
4
+ // Namespace.
5
+ global.FS = global.FS || {};
6
+
7
+ global.FS.PostMessage = function ()
8
+ {
9
+ var
10
+ _is_child = false,
11
+ _postman = new NoJQueryPostMessageMixin('postMessage', 'receiveMessage'),
12
+ _callbacks = {},
13
+ _base_url,
14
+ _parent_url = decodeURIComponent(document.location.hash.replace(/^#/, '')),
15
+ _parent_subdomain = _parent_url.substring(0, _parent_url.indexOf('/', ('https://' === _parent_url.substring(0, ('https://').length)) ? 8 : 7)),
16
+ _init = function () {
17
+ _postman.receiveMessage(function (e) {
18
+ var data = JSON.parse(e.data);
19
+
20
+ if (_callbacks[data.type]) {
21
+ for (var i = 0; i < _callbacks[data.type].length; i++) {
22
+ // Execute type callbacks.
23
+ _callbacks[data.type][i](data.data);
24
+ }
25
+ }
26
+ }, _base_url);
27
+ },
28
+ _hasParent = ('' !== _parent_url),
29
+ $window = $(window),
30
+ $html = $('html');
31
+
32
+ return {
33
+ init : function (url, iframes)
34
+ {
35
+ _base_url = url;
36
+ _init();
37
+
38
+ // Automatically receive forward messages.
39
+ FS.PostMessage.receiveOnce('forward', function (data){
40
+ window.location = data.url;
41
+ });
42
+
43
+ iframes = iframes || [];
44
+
45
+ if (iframes.length > 0) {
46
+ $window.on('scroll', function () {
47
+ for (var i = 0; i < iframes.length; i++) {
48
+ FS.PostMessage.postScroll(iframes[i]);
49
+ }
50
+ });
51
+ }
52
+ },
53
+ init_child : function ()
54
+ {
55
+ this.init(_parent_subdomain);
56
+
57
+ _is_child = true;
58
+
59
+ // Post height of a child right after window is loaded.
60
+ $(window).bind('load', function () {
61
+ FS.PostMessage.postHeight();
62
+
63
+ // Post message that window was loaded.
64
+ FS.PostMessage.post('loaded');
65
+ });
66
+ },
67
+ hasParent : function ()
68
+ {
69
+ return _hasParent;
70
+ },
71
+ postHeight : function (diff, wrapper) {
72
+ diff = diff || 0;
73
+ wrapper = wrapper || '#wrap_section';
74
+ this.post('height', {
75
+ height: diff + $(wrapper).outerHeight(true)
76
+ });
77
+ },
78
+ postScroll : function (iframe) {
79
+ this.post('scroll', {
80
+ top: $window.scrollTop(),
81
+ height: ($window.height() - parseFloat($html.css('paddingTop')) - parseFloat($html.css('marginTop')))
82
+ }, iframe);
83
+ },
84
+ post : function (type, data, iframe)
85
+ {
86
+ console.debug('PostMessage.post', type);
87
+
88
+ if (iframe)
89
+ {
90
+ // Post to iframe.
91
+ _postman.postMessage(JSON.stringify({
92
+ type: type,
93
+ data: data
94
+ }), iframe.src, iframe.contentWindow);
95
+ }
96
+ else {
97
+ // Post to parent.
98
+ _postman.postMessage(JSON.stringify({
99
+ type: type,
100
+ data: data
101
+ }), _parent_url, window.parent);
102
+ }
103
+ },
104
+ receive: function (type, callback)
105
+ {
106
+ console.debug('PostMessage.receive', type);
107
+
108
+ if (undef === _callbacks[type])
109
+ _callbacks[type] = [];
110
+
111
+ _callbacks[type].push(callback);
112
+ },
113
+ receiveOnce: function (type, callback)
114
+ {
115
+ if (this.is_set(type))
116
+ return;
117
+
118
+ this.receive(type, callback);
119
+ },
120
+ // Check if any callbacks assigned to a specified message type.
121
+ is_set: function (type)
122
+ {
123
+ return (undef != _callbacks[type]);
124
+ },
125
+ parent_url: function ()
126
+ {
127
+ return _parent_url;
128
+ },
129
+ parent_subdomain: function ()
130
+ {
131
+ return _parent_subdomain;
132
+ }
133
+ };
134
+ }();
135
  })(jQuery);
freemius/assets/scss/_colors.scss CHANGED
@@ -1,58 +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
-
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/_mixins.scss CHANGED
@@ -1,216 +1,227 @@
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 size($width, $height: $width)
204
- {
205
- width: $width;
206
- height: $height;
207
- }
208
-
209
- @mixin clearfix
210
- {
211
- &:after {
212
- content: "";
213
- display: table;
214
- clear: both;
215
- }
 
 
 
 
 
 
 
 
 
 
 
216
  }
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 size($width, $height: $width)
204
+ {
205
+ width: $width;
206
+ height: $height;
207
+ }
208
+
209
+ @mixin clearfix
210
+ {
211
+ &:after {
212
+ content: "";
213
+ display: table;
214
+ clear: both;
215
+ }
216
+ }
217
+
218
+ // Placeholder text
219
+ @mixin placeholder($color: $input-color-placeholder) {
220
+ // Firefox
221
+ &::-moz-placeholder {
222
+ color: $color;
223
+ opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
224
+ }
225
+ &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
226
+ &::-webkit-input-placeholder { color: $color; } // Safari and Chrome
227
  }
freemius/assets/scss/admin/_deactivation-feedback.scss CHANGED
@@ -1,55 +1,55 @@
1
- @import "../colors";
2
-
3
- .fs-modal.fs-modal-deactivation-feedback {
4
- .reason-input, .internal-message {
5
- margin: 3px 0 3px 22px;
6
-
7
- input, textarea {
8
- width: 100%;
9
- }
10
- }
11
-
12
- li.reason {
13
- &.has-internal-message .internal-message {
14
- border: 1px solid lighten($darkest-color, 80%);
15
- padding: 7px;
16
- display: none;
17
- }
18
-
19
- @media (max-width: 650px) {
20
- li.reason {
21
- margin-bottom: 10px;
22
-
23
- .reason-input, .internal-message {
24
- margin-left: 29px;
25
- }
26
-
27
- label {
28
- display: table;
29
-
30
- > span {
31
- display: table-cell;
32
- font-size: 1.3em;
33
- }
34
- }
35
- }
36
- }
37
- }
38
-
39
- .anonymous-feedback-label {
40
- float: left;
41
- }
42
-
43
- .fs-modal-panel {
44
- margin-top: 0 !important;
45
-
46
- h3 {
47
- margin-top: 0;
48
- line-height: 1.5em;
49
- }
50
- }
51
- }
52
-
53
- #the-list .deactivate > .fs-slug {
54
- display: none;
55
  }
1
+ @import "../colors";
2
+
3
+ .fs-modal.fs-modal-deactivation-feedback {
4
+ .reason-input, .internal-message {
5
+ margin: 3px 0 3px 22px;
6
+
7
+ input, textarea {
8
+ width: 100%;
9
+ }
10
+ }
11
+
12
+ li.reason {
13
+ &.has-internal-message .internal-message {
14
+ border: 1px solid lighten($darkest-color, 80%);
15
+ padding: 7px;
16
+ display: none;
17
+ }
18
+
19
+ @media (max-width: 650px) {
20
+ li.reason {
21
+ margin-bottom: 10px;
22
+
23
+ .reason-input, .internal-message {
24
+ margin-left: 29px;
25
+ }
26
+
27
+ label {
28
+ display: table;
29
+
30
+ > span {
31
+ display: table-cell;
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ .anonymous-feedback-label {
40
+ float: left;
41
+ }
42
+
43
+ .fs-modal-panel {
44
+ margin-top: 0 !important;
45
+
46
+ h3 {
47
+ margin-top: 0;
48
+ line-height: 1.5em;
49
+ }
50
+ }
51
+ }
52
+
53
+ #the-list .deactivate > .fs-slug {
54
+ display: none;
55
  }
freemius/assets/scss/admin/_license-activation.scss CHANGED
@@ -1,7 +1,7 @@
1
- .fs-modal.fs-modal-license-activation {
2
- .fs-modal-body {
3
- input.license_key {
4
- width: 100%;
5
- }
6
- }
7
  }
1
+ .fs-modal.fs-modal-license-activation {
2
+ .fs-modal-body {
3
+ input.license_key {
4
+ width: 100%;
5
+ }
6
+ }
7
  }
freemius/assets/scss/admin/_license-key-resend.scss CHANGED
@@ -1,44 +1,44 @@
1
- .fs-modal.fs-modal-license-key-resend {
2
- .fs-modal-body {
3
- .input-container > .email-address-container {
4
- overflow: hidden;
5
- padding-right: 2px;
6
- }
7
-
8
- input.email-address {
9
- width: 100%;
10
- }
11
-
12
- .button-container {
13
- float: right;
14
- margin-left: 7px;
15
-
16
- @media (max-width: 650px) {
17
- margin-top: 2px;
18
- }
19
- }
20
- }
21
- }
22
-
23
- .rtl
24
- {
25
- .fs-modal.fs-modal-license-key-resend {
26
- .fs-modal-body {
27
- .input-container > .email-address-container {
28
- padding-left: 2px;
29
- padding-right: 0;
30
- }
31
-
32
- .button-container {
33
- float: left;
34
- margin-right: 7px;
35
- margin-left: 0;
36
- }
37
- }
38
- }
39
- }
40
-
41
- a.show-license-resend-modal {
42
- margin-top: 4px;
43
- display: inline-block;
44
- }
1
+ .fs-modal.fs-modal-license-key-resend {
2
+ .fs-modal-body {
3
+ .input-container > .email-address-container {
4
+ overflow: hidden;
5
+ padding-right: 2px;
6
+ }
7
+
8
+ input.email-address {
9
+ width: 100%;
10
+ }
11
+
12
+ .button-container {
13
+ float: right;
14
+ margin-left: 7px;
15
+
16
+ @media (max-width: 650px) {
17
+ margin-top: 2px;
18
+ }
19
+ }
20
+ }
21
+ }
22
+
23
+ .rtl
24
+ {
25
+ .fs-modal.fs-modal-license-key-resend {
26
+ .fs-modal-body {
27
+ .input-container > .email-address-container {
28
+ padding-left: 2px;
29
+ padding-right: 0;
30
+ }
31
+
32
+ .button-container {
33
+ float: left;
34
+ margin-right: 7px;
35
+ margin-left: 0;
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ a.show-license-resend-modal {
42
+ margin-top: 4px;
43
+ display: inline-block;
44
+ }
freemius/assets/scss/admin/_modal-common.scss CHANGED
@@ -1,153 +1,155 @@
1
- @import "../colors";
2
- @import "../mixins";
3
-
4
- .fs-modal {
5
- position: fixed;
6
- overflow: auto;
7
- height: 100%;
8
- width: 100%;
9
- top: 0;
10
- z-index: 100000;
11
- display: none;
12
- background: rgba(0, 0, 0, 0.6);
13
-
14
- .fs-modal-dialog {
15
- background: transparent;
16
- position: absolute;
17
- left: 50%;
18
- margin-left: -298px;
19
- padding-bottom: 30px;
20
- top: -100%;
21
- z-index: 100001;
22
- width: 596px;
23
-
24
- @media (max-width: 650px) {
25
- margin-left: -50%;
26
- box-sizing: border-box;
27
- padding-left: 10px;
28
- padding-right: 10px;
29
- width: 100%;
30
-
31
- .fs-modal-panel > h3 > strong {
32
- font-size: 1.3em;
33
- }
34
- }
35
- }
36
-
37
- &.active {
38
- display: block;
39
-
40
- &:before {
41
- display: block;
42
- }
43
-
44
- .fs-modal-dialog {
45
- top: 10%;
46
- }
47
- }
48
-
49
- .fs-modal-body,
50
- .fs-modal-footer {
51
- border: 0;
52
- background: #fefefe;
53
- padding: 20px;
54
- }
55
-
56
- .fs-modal-header {
57
- border-bottom: #eeeeee solid 1px;
58
- background: #fbfbfb;
59
- padding: 15px 20px;
60
- position: relative;
61
- // z-index: 2;
62
-
63
- h4 {
64
- margin: 0;
65
- padding: 0;
66
- text-transform: uppercase;
67
- font-size: 1.2em;
68
- font-weight: bold;
69
- color: #cacaca;
70
- text-shadow: 1px 1px 1px #fff;
71
- letter-spacing: 0.6px;
72
- -webkit-font-smoothing: antialiased;
73
- }
74
-
75
- .fs-close {
76
- position: absolute;
77
- right: 10px;
78
- top: 12px;
79
- cursor: pointer;
80
- color: #bbb;
81
- @include border-radius(20px);
82
- padding: 3px;
83
- @include transition(all 0.2s ease-in-out);
84
-
85
- &:hover {
86
- color: #fff;
87
- background: #aaa;
88
- }
89
- }
90
- }
91
-
92
- .fs-modal-body {
93
- border-bottom: 0;
94
-
95
- p {
96
- font-size: 14px;
97
- }
98
-
99
- h2 {
100
- font-size: 20px;
101
- }
102
-
103
- > div {
104
- margin-top: 10px;
105
-
106
- h2 {
107
- font-weight: bold;
108
- font-size: 20px;
109
- margin-top: 0;
110
- }
111
- }
112
- }
113
-
114
- .fs-modal-footer {
115
- border-top: #eeeeee solid 1px;
116
- text-align: right;
117
-
118
- > .button {
119
- margin: 0 7px;
120
-
121
- &:first-child {
122
- margin: 0;
123
- }
124
- }
125
- }
126
-
127
- .fs-modal-panel {
128
- > .notice.inline {
129
- margin: 0;
130
- display: none;
131
- }
132
-
133
- &:not(.active) {
134
- display: none;
135
- }
136
- }
137
- }
138
-
139
- .rtl
140
- {
141
- .fs-modal {
142
- .fs-modal-header {
143
- .fs-close {
144
- right: auto;
145
- left: 20px;
146
- }
147
- }
148
- }
149
- }
150
-
151
- body.has-fs-modal {
152
- overflow: hidden;
 
 
153
  }
1
+ @import "../colors";
2
+ @import "../mixins";
3
+
4
+ .fs-modal {
5
+ position: fixed;
6
+ overflow: auto;
7
+ height: 100%;
8
+ width: 100%;
9
+ top: 0;
10
+ z-index: 100000;
11
+ display: none;
12
+ background: rgba(0, 0, 0, 0.6);
13
+
14
+ .fs-modal-dialog {
15
+ background: transparent;
16
+ position: absolute;
17
+ left: 50%;
18
+ margin-left: -298px;
19
+ padding-bottom: 30px;
20
+ top: -100%;
21
+ z-index: 100001;
22
+ width: 596px;
23
+
24
+ @media (max-width: 650px) {
25
+ margin-left: -50%;
26
+ box-sizing: border-box;
27
+ padding-left: 10px;
28
+ padding-right: 10px;
29
+ width: 100%;
30
+
31
+ .fs-modal-panel > h3 > strong {
32
+ font-size: 1.3em;
33
+ }
34
+ }
35
+ }
36
+
37
+ &.active {
38
+ display: block;
39
+
40
+ &:before {
41
+ display: block;
42
+ }
43
+
44
+ .fs-modal-dialog {
45
+ top: 10%;
46
+ }
47
+ }
48
+
49
+ .fs-modal-body,
50
+ .fs-modal-footer {
51
+ border: 0;
52
+ background: #fefefe;
53
+ padding: 20px;
54
+ }
55
+
56
+ .fs-modal-header {
57
+ border-bottom: #eeeeee solid 1px;
58
+ background: #fbfbfb;
59
+ padding: 15px 20px;
60
+ position: relative;
61
+ margin-bottom: -10px;
62
+ // z-index: 2;
63
+
64
+ h4 {
65
+ margin: 0;
66
+ padding: 0;
67
+ text-transform: uppercase;
68
+ font-size: 1.2em;
69
+ font-weight: bold;
70
+ color: #cacaca;
71
+ text-shadow: 1px 1px 1px #fff;
72
+ letter-spacing: 0.6px;
73
+ -webkit-font-smoothing: antialiased;
74
+ }
75
+
76
+ .fs-close {
77
+ position: absolute;
78
+ right: 10px;
79
+ top: 12px;
80
+ cursor: pointer;
81
+ color: #bbb;
82
+ @include border-radius(20px);
83
+ padding: 3px;
84
+ @include transition(all 0.2s ease-in-out);
85
+
86
+ &:hover {
87
+ color: #fff;
88
+ background: #aaa;
89
+ }
90
+ }
91
+ }
92
+
93
+ .fs-modal-body {
94
+ border-bottom: 0;
95
+
96
+ p {
97
+ font-size: 14px;
98
+ }
99
+
100
+ h2 {
101
+ font-size: 20px;
102
+ line-height: 1.5em;
103
+ }
104
+
105
+ > div {
106
+ margin-top: 10px;
107
+
108
+ h2 {
109
+ font-weight: bold;
110
+ font-size: 20px;
111
+ margin-top: 0;
112
+ }
113
+ }
114
+ }
115
+
116
+ .fs-modal-footer {
117
+ border-top: #eeeeee solid 1px;
118
+ text-align: right;
119
+
120
+ > .button {
121
+ margin: 0 7px;
122
+
123
+ &:first-child {
124
+ margin: 0;
125
+ }
126
+ }
127
+ }
128
+
129
+ .fs-modal-panel {
130
+ > .notice.inline {
131
+ margin: 0;
132
+ display: none;
133
+ }
134
+
135
+ &:not(.active) {
136
+ display: none;
137
+ }
138
+ }
139
+ }
140
+
141
+ .rtl
142
+ {
143
+ .fs-modal {
144
+ .fs-modal-header {
145
+ .fs-close {
146
+ right: auto;
147
+ left: 20px;
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ body.has-fs-modal {
154
+ overflow: hidden;
155
  }
freemius/assets/scss/admin/account.scss CHANGED
@@ -1,184 +1,250 @@
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
- #fs_account_details .button-group {
62
- float: right;
63
- }
64
-
65
- .rtl #fs_account .fs-header-actions
66
- {
67
- left: 15px;
68
- right: auto;
69
- }
70
-
71
- .fs-key-value-table
72
- {
73
- width: 100%;
74
-
75
- form
76
- {
77
- display: inline-block;
78
- }
79
-
80
- tr
81
- {
82
- td:first-child
83
- {
84
- nobr
85
- {
86
- font-weight: bold;
87
- }
88
-
89
- text-align: right;
90
-
91
- form
92
- {
93
- display: block;
94
- }
95
- }
96
-
97
- td.fs-right
98
- {
99
- text-align: right;
100
- }
101
-
102
- &.fs-odd
103
- {
104
- background: #ebebeb;
105
- }
106
- }
107
-
108
- td, th
109
- {
110
- padding: 10px;
111
- }
112
-
113
- code {
114
- line-height: 28px;
115
- }
116
-
117
- var, code, input[type="text"]
118
- {
119
- color: #0073AA;
120
- font-size: 16px;
121
- background: none;
122
- }
123
-
124
- input[type="text"] {
125
- width: 100%;
126
- font-weight: bold;
127
- }
128
- }
129
-
130
- label.fs-tag
131
- {
132
- background: #ffba00;
133
- color: #fff;
134
- display: inline-block;
135
- border-radius: 3px;
136
- padding: 5px;
137
- font-size: 11px;
138
- line-height: 11px;
139
- vertical-align: baseline;
140
-
141
- &.fs-warn
142
- {
143
- background: #ffba00;
144
- }
145
- &.fs-success
146
- {
147
- background: #46b450;
148
- }
149
- &.fs-error
150
- {
151
- background: #dc3232;
152
- }
153
- }
154
-
155
- #fs_addons
156
- {
157
- h3
158
- {
159
- border: none;
160
- margin-bottom: 0;
161
- padding: 4px 5px;
162
- }
163
-
164
- td
165
- {
166
- vertical-align: middle;
167
- }
168
-
169
- td:first-child,
170
- th:first-child
171
- {
172
- text-align: left;
173
- font-weight: bold;
174
- }
175
- td:last-child,
176
- th:last-child
177
- {
178
- text-align: right;
179
- }
180
- th
181
- {
182
- font-weight: bold;
183
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  }
1
+ @import "../start";
2
+
3
+ #fs_account
4
+ {
5
+ .postbox,
6
+ .widefat
7
+ {
8
+ max-width: 700px;
9
+ }
10
+
11
+ h3
12
+ {
13
+ font-size: 1.3em;
14
+ padding: 12px 15px;
15
+ margin: 0 0 12px 0;
16
+ line-height: 1.4;
17
+ border-bottom: 1px solid #F1F1F1;
18
+ }
19
+
20
+ i.dashicons
21
+ {
22
+ font-size: 1.2em;
23
+ height: 1.2em;
24
+ width: 1.2em;
25
+ }
26
+
27
+ .button
28
+ {
29
+ i.dashicons
30
+ {
31
+ vertical-align: middle;
32
+ }
33
+ }
34
+
35
+ .fs-header-actions
36
+ {
37
+ position: absolute;
38
+ top: 17px;
39
+ right: 15px;
40
+ font-size: 0.9em;
41
+
42
+ ul
43
+ {
44
+ margin: 0;
45
+ }
46
+
47
+ li
48
+ {
49
+ form
50
+ {
51
+ display: inline-block;
52
+ }
53
+
54
+ float: left;
55
+ a
56
+ {
57
+ text-decoration: none;
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ #fs_account_details .button-group {
64
+ float: right;
65
+ }
66
+
67
+ .rtl #fs_account .fs-header-actions
68
+ {
69
+ left: 15px;
70
+ right: auto;
71
+ }
72
+
73
+ .fs-key-value-table
74
+ {
75
+ width: 100%;
76
+
77
+ form
78
+ {
79
+ display: inline-block;
80
+ }
81
+
82
+ tr
83
+ {
84
+ td:first-child
85
+ {
86
+ nobr
87
+ {
88
+ font-weight: bold;
89
+ }
90
+
91
+ text-align: right;
92
+
93
+ form
94
+ {
95
+ display: block;
96
+ }
97
+ }
98
+
99
+ td.fs-right
100
+ {
101
+ text-align: right;
102
+ }
103
+
104
+ &.fs-odd
105
+ {
106
+ background: #ebebeb;
107
+ }
108
+ }
109
+
110
+ td, th
111
+ {
112
+ padding: 10px;
113
+ }
114
+
115
+ code {
116
+ line-height: 28px;
117
+ }
118
+
119
+ var, code, input[type="text"]
120
+ {
121
+ color: #0073AA;
122
+ font-size: 16px;
123
+ background: none;
124
+ }
125
+
126
+ input[type="text"] {
127
+ width: 100%;
128
+ font-weight: bold;
129
+ }
130
+ }
131
+
132
+ label.fs-tag
133
+ {
134
+ background: #ffba00;
135
+ color: #fff;
136
+ display: inline-block;
137
+ border-radius: 3px;
138
+ padding: 5px;
139
+ font-size: 11px;
140
+ line-height: 11px;
141
+ vertical-align: baseline;
142
+
143
+ &.fs-warn
144
+ {
145
+ background: #ffba00;
146
+ }
147
+ &.fs-success
148
+ {
149
+ background: #46b450;
150
+ }
151
+ &.fs-error
152
+ {
153
+ background: #dc3232;
154
+ }
155
+ }
156
+
157
+ #fs_addons
158
+ {
159
+ h3
160
+ {
161
+ border: none;
162
+ margin-bottom: 0;
163
+ padding: 4px 5px;
164
+ }
165
+
166
+ td
167
+ {
168
+ vertical-align: middle;
169
+ }
170
+
171
+ thead {
172
+ white-space: nowrap;
173
+ }
174
+
175
+ td:first-child,
176
+ th:first-child
177
+ {
178
+ text-align: left;
179
+ font-weight: bold;
180
+ }
181
+ td:last-child,
182
+ th:last-child
183
+ {
184
+ text-align: right;
185
+ }
186
+ th
187
+ {
188
+ font-weight: bold;
189
+ }
190
+ }
191
+
192
+ #fs_billing_address {
193
+ width: 100%;
194
+
195
+ tr {
196
+ td {
197
+ width: 50%;
198
+ padding: 5px;
199
+ }
200
+
201
+ &:first-of-type {
202
+ td {
203
+ padding-top: 0;
204
+ }
205
+ }
206
+ }
207
+
208
+ @mixin read-mode {
209
+ border-color: transparent;
210
+ color: #777;
211
+ border-bottom: 1px dashed #ccc;
212
+ padding-left: 0;
213
+ background: none;
214
+ }
215
+
216
+ span {
217
+ font-weight: bold;
218
+ }
219
+
220
+ input, select {
221
+ @include placeholder(transparent);
222
+
223
+ display: block;
224
+ width: 100%;
225
+ margin-top: 5px;
226
+
227
+ &.fs-read-mode {
228
+ @include read-mode();
229
+ }
230
+ }
231
+
232
+
233
+ &.fs-read-mode {
234
+ td span {
235
+ display: none;
236
+ }
237
+
238
+ input, select
239
+ {
240
+ @include read-mode();
241
+ @include placeholder(#ccc);
242
+ }
243
+ }
244
+
245
+
246
+ button {
247
+ display: block;
248
+ width: 100%;
249
+ }
250
  }
freemius/assets/scss/admin/add-ons.scss CHANGED
@@ -1,449 +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
  }
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 CHANGED
@@ -1,140 +1,160 @@
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:500px) {
112
- #fs_promo_tab {
113
- display: none;
114
- }
115
- }
116
-
117
- @media screen and (max-width: 782px) {
118
- .fs-secure-notice
119
- {
120
- left: 0;
121
- top: 46px;
122
- text-align: center;
123
- }
124
- }
125
-
126
- span.fs-submenu-item.fs-sub:before
127
- {
128
- // Add small arrow.
129
- content: '\21B3';
130
- padding: 0 5px;
131
- }
132
-
133
- .rtl
134
- {
135
- span.fs-submenu-item.fs-sub:before
136
- {
137
- // Add small RTL arrow.
138
- content: '\21B2';
139
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
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:500px) {
112
+ #fs_promo_tab {
113
+ display: none;
114
+ }
115
+ }
116
+
117
+ @media screen and (max-width: 782px) {
118
+ .fs-secure-notice
119
+ {
120
+ left: 0;
121
+ top: 46px;
122
+ text-align: center;
123
+ }
124
+ }
125
+
126
+ span.fs-submenu-item.fs-sub:before
127
+ {
128
+ // Add small arrow.
129
+ content: '\21B3';
130
+ padding: 0 5px;
131
+ }
132
+
133
+ .rtl
134
+ {
135
+ span.fs-submenu-item.fs-sub:before
136
+ {
137
+ // Add small RTL arrow.
138
+ content: '\21B2';
139
+ }
140
+ }
141
+
142
+ .fs-submenu-item
143
+ {
144
+ &.pricing
145
+ {
146
+ &.upgrade-mode
147
+ {
148
+ color: greenyellow;
149
+ }
150
+
151
+ &.trial-mode
152
+ {
153
+ color: #83e2ff;
154
+ }
155
+ }
156
+ }
157
+
158
+ #adminmenu .update-plugins.fs-trial {
159
+ background-color: #00b9eb;
160
  }
freemius/assets/scss/admin/debug.scss CHANGED
@@ -1,91 +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
  }
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/dialog-boxes.scss CHANGED
@@ -1,5 +1,5 @@
1
- @import "../start";
2
- @import "modal-common";
3
- @import "deactivation-feedback";
4
- @import "license-activation";
5
  @import "license-key-resend";
1
+ @import "../start";
2
+ @import "modal-common";
3
+ @import "deactivation-feedback";
4
+ @import "license-activation";
5
  @import "license-key-resend";
freemius/composer.json CHANGED
@@ -1,10 +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
- }
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 CHANGED
@@ -1,229 +1,301 @@
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 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ( ! defined( 'WP_FS__SLUG' ) ) {
14
+ define( 'WP_FS__SLUG', 'freemius' );
15
+ }
16
+ if ( ! defined( 'WP_FS__DEV_MODE' ) ) {
17
+ define( 'WP_FS__DEV_MODE', false );
18
+ }
19
+
20
+ #--------------------------------------------------------------------------------
21
+ #region API Connectivity Issues Simulation
22
+ #--------------------------------------------------------------------------------
23
+
24
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY' ) ) {
25
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY', false );
26
+ }
27
+ if ( ! defined( 'WP_FS__SIMULATE_NO_CURL' ) ) {
28
+ define( 'WP_FS__SIMULATE_NO_CURL', false );
29
+ }
30
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE' ) ) {
31
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false );
32
+ }
33
+ if ( ! defined( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL' ) ) {
34
+ define( 'WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false );
35
+ }
36
+ if ( WP_FS__SIMULATE_NO_CURL ) {
37
+ define( 'FS_SDK__SIMULATE_NO_CURL', true );
38
+ }
39
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE ) {
40
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true );
41
+ }
42
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL ) {
43
+ define( 'FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true );
44
+ }
45
+
46
+ #endregion
47
+
48
+ if ( ! defined( 'WP_FS__SIMULATE_FREEMIUS_OFF' ) ) {
49
+ define( 'WP_FS__SIMULATE_FREEMIUS_OFF', false );
50
+ }
51
+
52
+ if ( ! defined( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES' ) ) {
53
+ /**
54
+ * @since 1.1.7.3
55
+ * @author Vova Feldman (@svovaf)
56
+ *
57
+ * I'm not sure if shared servers periodically change IP, or the subdomain of the
58
+ * admin dashboard. Also, I've seen sites that have strange loop of switching
59
+ * between domains on a daily basis. Therefore, to eliminate the risk of
60
+ * multiple unwanted connectivity test pings, temporary ignore domain or
61
+ * server IP changes.
62
+ */
63
+ define( 'WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false );
64
+ }
65
+
66
+ /**
67
+ * If your dev environment supports custom public network IP setup
68
+ * like VVV, please update WP_FS__LOCALHOST_IP with your public IP
69
+ * and uncomment it during dev.
70
+ */
71
+ if ( ! defined( 'WP_FS__LOCALHOST_IP' ) ) {
72
+ // VVV default public network IP.
73
+ define( 'WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4' );
74
+
75
+ // define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP );
76
+ }
77
+
78
+ /**
79
+ * If true and running with secret key, the opt-in process
80
+ * will skip the email activation process which is invoked
81
+ * when the email of the context user already exist in Freemius
82
+ * database (as a security precaution, to prevent sharing user
83
+ * secret with unauthorized entity).
84
+ *
85
+ * IMPORTANT:
86
+ * AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST.
87
+ * THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S
88
+ * CLOCK IS SYNCED.
89
+ */
90
+ if ( ! defined( 'WP_FS__SKIP_EMAIL_ACTIVATION' ) ) {
91
+ define( 'WP_FS__SKIP_EMAIL_ACTIVATION', false );
92
+ }
93
+
94
+
95
+ #--------------------------------------------------------------------------------
96
+ #region Directories
97
+ #--------------------------------------------------------------------------------
98
+
99
+ if ( ! defined( 'WP_FS__DIR' ) ) {
100
+ define( 'WP_FS__DIR', dirname( __FILE__ ) );
101
+ }
102
+ if ( ! defined( 'WP_FS__DIR_INCLUDES' ) ) {
103
+ define( 'WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes' );
104
+ }
105
+ if ( ! defined( 'WP_FS__DIR_TEMPLATES' ) ) {
106
+ define( 'WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates' );
107
+ }
108
+ if ( ! defined( 'WP_FS__DIR_ASSETS' ) ) {
109
+ define( 'WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets' );
110
+ }
111
+ if ( ! defined( 'WP_FS__DIR_CSS' ) ) {
112
+ define( 'WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css' );
113
+ }
114
+ if ( ! defined( 'WP_FS__DIR_JS' ) ) {
115
+ define( 'WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js' );
116
+ }
117
+ if ( ! defined( 'WP_FS__DIR_IMG' ) ) {
118
+ define( 'WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img' );
119
+ }
120
+ if ( ! defined( 'WP_FS__DIR_SDK' ) ) {
121
+ define( 'WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk' );
122
+ }
123
+
124
+ #endregion
125
+
126
+ /**
127
+ * Domain / URL / Address
128
+ */
129
+ define( 'WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com' );
130
+ define( 'WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION );
131
+
132
+ if ( ! defined( 'WP_FS__DOMAIN_LOCALHOST' ) ) {
133
+ define( 'WP_FS__DOMAIN_LOCALHOST', 'wp.freemius' );
134
+ }
135
+ if ( ! defined( 'WP_FS__ADDRESS_LOCALHOST' ) ) {
136
+ define( 'WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080' );
137
+ }
138
+
139
+ if ( ! defined( 'WP_FS__TESTING_DOMAIN' ) ) {
140
+ define( 'WP_FS__TESTING_DOMAIN', 'fswp' );
141
+ }
142
+
143
+ #--------------------------------------------------------------------------------
144
+ #region HTTP
145
+ #--------------------------------------------------------------------------------
146
+
147
+ if ( ! defined( 'WP_FS__IS_HTTP_REQUEST' ) ) {
148
+ define( 'WP_FS__IS_HTTP_REQUEST', isset( $_SERVER['HTTP_HOST'] ) );
149
+ }
150
+
151
+ if ( ! defined( 'WP_FS__IS_HTTPS' ) ) {
152
+ define( 'WP_FS__IS_HTTPS', ( WP_FS__IS_HTTP_REQUEST &&
153
+ // Checks if CloudFlare's HTTPS (Flexible SSL support).
154
+ isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) &&
155
+ 'https' === strtolower( $_SERVER['HTTP_X_FORWARDED_PROTO'] )
156
+ ) ||
157
+ // Check if HTTPS request.
158
+ ( isset( $_SERVER['HTTPS'] ) && 'on' == $_SERVER['HTTPS'] ) ||
159
+ ( isset( $_SERVER['SERVER_PORT'] ) && 443 == $_SERVER['SERVER_PORT'] )
160
+ );
161
+ }
162
+
163
+ if ( ! defined( 'WP_FS__IS_POST_REQUEST' ) ) {
164
+ define( 'WP_FS__IS_POST_REQUEST', ( WP_FS__IS_HTTP_REQUEST &&
165
+ strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' ) );
166
+ }
167
+
168
+ if ( ! defined( 'WP_FS__REMOTE_ADDR' ) ) {
169
+ define( 'WP_FS__REMOTE_ADDR', fs_get_ip() );
170
+ }
171
+
172
+ if ( ! defined( 'WP_FS__IS_LOCALHOST' ) ) {
173
+ if ( defined( 'WP_FS__LOCALHOST_IP' ) ) {
174
+ define( 'WP_FS__IS_LOCALHOST', ( WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR ) );
175
+ } else {
176
+ define( 'WP_FS__IS_LOCALHOST', WP_FS__IS_HTTP_REQUEST &&
177
+ is_string( WP_FS__REMOTE_ADDR ) &&
178
+ ( substr( WP_FS__REMOTE_ADDR, 0, 4 ) === '127.' ||
179
+ WP_FS__REMOTE_ADDR === '::1' )
180
+ );
181
+ }
182
+ }
183
+
184
+ if ( ! defined( 'WP_FS__IS_LOCALHOST_FOR_SERVER' ) ) {
185
+ define( 'WP_FS__IS_LOCALHOST_FOR_SERVER', ( ! WP_FS__IS_HTTP_REQUEST ||
186
+ false !== strpos( $_SERVER['HTTP_HOST'], 'localhost' ) ) );
187
+ }
188
+
189
+ #endregion
190
+
191
+ if ( ! defined( 'WP_FS__IS_PRODUCTION_MODE' ) ) {
192
+ // By default, run with Freemius production servers.
193
+ define( 'WP_FS__IS_PRODUCTION_MODE', true );
194
+ }
195
+
196
+ if ( ! defined( 'WP_FS__ADDRESS' ) ) {
197
+ define( 'WP_FS__ADDRESS', ( WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST ) );
198
+ }
199
+
200
+
201
+ #--------------------------------------------------------------------------------
202
+ #region API
203
+ #--------------------------------------------------------------------------------
204
+
205
+ if ( ! defined( 'WP_FS__API_ADDRESS_LOCALHOST' ) ) {
206
+ define( 'WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius:8080' );
207
+ }
208
+ if ( ! defined( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST' ) ) {
209
+ define( 'WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080' );
210
+ }
211
+
212
+ // Set API address for local testing.
213
+ if ( ! WP_FS__IS_PRODUCTION_MODE ) {
214
+ if ( ! defined( 'FS_API__ADDRESS' ) ) {
215
+ define( 'FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST );
216
+ }
217
+ if ( ! defined( 'FS_API__SANDBOX_ADDRESS' ) ) {
218
+ define( 'FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST );
219
+ }
220
+ }
221
+
222
+ #endregion
223
+
224
+ define( 'WP_FS___OPTION_PREFIX', 'fs' . ( WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg' ) . '_' );
225
+
226
+ if ( ! defined( 'WP_FS__ACCOUNTS_OPTION_NAME' ) ) {
227
+ define( 'WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts' );
228
+ }
229
+ if ( ! defined( 'WP_FS__API_CACHE_OPTION_NAME' ) ) {
230
+ define( 'WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache' );
231
+ }
232
+ define( 'WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options' );
233
+
234
+ /**
235
+ * Billing Frequencies
236
+ */
237
+ define( 'WP_FS__PERIOD_ANNUALLY', 'annual' );
238
+ define( 'WP_FS__PERIOD_MONTHLY', 'monthly' );
239
+ define( 'WP_FS__PERIOD_LIFETIME', 'lifetime' );
240
+
241
+ /**
242
+ * Plans
243
+ */
244
+ define( 'WP_FS__PLAN_DEFAULT_PAID', false );
245
+ define( 'WP_FS__PLAN_FREE', 'free' );
246
+ define( 'WP_FS__PLAN_TRIAL', 'trial' );
247
+
248
+ /**
249
+ * Times in seconds
250
+ */
251
+ if ( ! defined( 'WP_FS__TIME_5_MIN_IN_SEC' ) ) {
252
+ define( 'WP_FS__TIME_5_MIN_IN_SEC', 300 );
253
+ }
254
+ if ( ! defined( 'WP_FS__TIME_10_MIN_IN_SEC' ) ) {
255
+ define( 'WP_FS__TIME_10_MIN_IN_SEC', 600 );
256
+ }
257
+ // define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 );
258
+ if ( ! defined( 'WP_FS__TIME_24_HOURS_IN_SEC' ) ) {
259
+ define( 'WP_FS__TIME_24_HOURS_IN_SEC', 86400 );
260
+ }
261
+
262
+ #--------------------------------------------------------------------------------
263
+ #region Debugging
264
+ #--------------------------------------------------------------------------------
265
+
266
+ if ( ! defined( 'WP_FS__DEBUG_SDK' ) ) {
267
+ $debug_mode = get_option( 'fs_debug_mode', null );
268
+
269
+ if ( $debug_mode === null ) {
270
+ $debug_mode = false;
271
+ add_option( 'fs_debug_mode', $debug_mode );
272
+ }
273
+
274
+ define( 'WP_FS__DEBUG_SDK', is_numeric( $debug_mode ) ? ( 0 < $debug_mode ) : WP_FS__DEV_MODE );
275
+ }
276
+
277
+ if ( ! defined( 'WP_FS__ECHO_DEBUG_SDK' ) ) {
278
+ define( 'WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && ! empty( $_GET['fs_dbg_echo'] ) );
279
+ }
280
+ if ( ! defined( 'WP_FS__LOG_DATETIME_FORMAT' ) ) {
281
+ define( 'WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s' );
282
+ }
283
+ if ( ! defined( 'FS_API__LOGGER_ON' ) ) {
284
+ define( 'FS_API__LOGGER_ON', WP_FS__DEBUG_SDK );
285
+ }
286
+
287
+ if ( WP_FS__ECHO_DEBUG_SDK ) {
288
+ error_reporting( E_ALL );
289
+ }
290
+
291
+ #endregion
292
+
293
+ if ( ! defined( 'WP_FS__SCRIPT_START_TIME' ) ) {
294
+ define( 'WP_FS__SCRIPT_START_TIME', time() );
295
+ }
296
+ if ( ! defined( 'WP_FS__DEFAULT_PRIORITY' ) ) {
297
+ define( 'WP_FS__DEFAULT_PRIORITY', 10 );
298
+ }
299
+ if ( ! defined( 'WP_FS__LOWEST_PRIORITY' ) ) {
300
+ define( 'WP_FS__LOWEST_PRIORITY', 999999999 );
301
+ }
freemius/gulpfile.js CHANGED
@@ -1,42 +1,42 @@
1
- var gulp = require('gulp');
2
- var wpPot = require('gulp-wp-pot');
3
- var gettext = require('gulp-gettext');
4
- var sort = require('gulp-sort');
5
- var pofill = require('gulp-pofill');
6
- var rename = require('gulp-rename');
7
-
8
- gulp.task('default', function () {
9
- // Create POT out of i18n.php.
10
- gulp.src('includes/i18n.php')
11
- .pipe(sort())
12
- .pipe(wpPot( {
13
- destFile:'freemius.pot',
14
- package: 'freemius',
15
- bugReport: 'https://github.com/Freemius/wordpress-sdk/issues',
16
- lastTranslator: 'Vova Feldman <vova@freemius.com>',
17
- team: 'Freemius Team <admin@freemius.com>'
18
- } ))
19
- .pipe(gulp.dest('languages/'));
20
-
21
- // Create English PO out of the POT.
22
- gulp.src('languages/freemius.pot')
23
- .pipe(pofill({
24
- items: function(item) {
25
- // If msgstr is empty, use identity translation
26
- if (!item.msgstr.length) {
27
- item.msgstr = [''];
28
- }
29
- if (!item.msgstr[0]) {
30
- item.msgstr[0] = item.msgid;
31
- }
32
- return item;
33
- }
34
- }))
35
- .pipe(rename('freemius-en.po'))
36
- .pipe(gulp.dest('languages/'));
37
-
38
- // Compile POs to MOs.
39
- gulp.src('languages/*.po')
40
- .pipe(gettext())
41
- .pipe(gulp.dest('languages/'))
42
  });
1
+ var gulp = require('gulp');
2
+ var wpPot = require('gulp-wp-pot');
3
+ var gettext = require('gulp-gettext');
4
+ var sort = require('gulp-sort');
5
+ var pofill = require('gulp-pofill');
6
+ var rename = require('gulp-rename');
7
+
8
+ gulp.task('default', function () {
9
+ // Create POT out of i18n.php.
10
+ gulp.src('includes/i18n.php')
11
+ .pipe(sort())
12
+ .pipe(wpPot( {
13
+ destFile:'freemius.pot',
14
+ package: 'freemius',
15
+ bugReport: 'https://github.com/Freemius/wordpress-sdk/issues',
16
+ lastTranslator: 'Vova Feldman <vova@freemius.com>',
17
+ team: 'Freemius Team <admin@freemius.com>'
18
+ } ))
19
+ .pipe(gulp.dest('languages/'));
20
+
21
+ // Create English PO out of the POT.
22
+ gulp.src('languages/freemius.pot')
23
+ .pipe(pofill({
24
+ items: function(item) {
25
+ // If msgstr is empty, use identity translation
26
+ if (!item.msgstr.length) {
27
+ item.msgstr = [''];
28
+ }
29
+ if (!item.msgstr[0]) {
30
+ item.msgstr[0] = item.msgid;
31
+ }
32
+ return item;
33
+ }
34
+ }))
35
+ .pipe(rename('freemius-en.po'))
36
+ .pipe(gulp.dest('languages/'));
37
+
38
+ // Compile POs to MOs.
39
+ gulp.src('languages/*.po')
40
+ .pipe(gettext())
41
+ .pipe(gulp.dest('languages/'))
42
  });
freemius/includes/class-freemius-abstract.php CHANGED
@@ -1,453 +1,527 @@
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->has_paid_plan() &&
344
- $this->has_free_plan();
345
- }
346
-
347
- #endregion Plans ------------------------------------------------------------------
348
-
349
- /**
350
- * Check if running payments in sandbox mode.
351
- *
352
- * @since 1.0.4
353
- *
354
- * @return bool
355
- */
356
- abstract function is_payments_sandbox();
357
-
358
- /**
359
- * Check if running test vs. live plugin.
360
- *
361
- * @since 1.0.5
362
- *
363
- * @return bool
364
- */
365
- abstract function is_live();
366
-
367
- /**
368
- * Check if running premium plugin code.
369
- *
370
- * @since 1.0.5
371
- *
372
- * @return bool
373
- */
374
- abstract function is_premium();
375
-
376
- /**
377
- * Get upgrade URL.
378
- *
379
- * @author Vova Feldman (@svovaf)
380
- * @since 1.0.2
381
- *
382
- * @param string $period Billing cycle
383
- *
384
- * @return string
385
- */
386
- abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
387
-
388
- /**
389
- * Check if Freemius was first added in a plugin update.
390
- *
391
- * @author Vova Feldman (@svovaf)
392
- * @since 1.1.5
393
- *
394
- * @return bool
395
- */
396
- function is_plugin_update() {
397
- return ! $this->is_plugin_new_install();
398
- }
399
-
400
- /**
401
- * Check if Freemius was part of the plugin when the user installed it first.
402
- *
403
- * @author Vova Feldman (@svovaf)
404
- * @since 1.1.5
405
- *
406
- * @return bool
407
- */
408
- abstract function is_plugin_new_install();
409
-
410
- #region Marketing ------------------------------------------------------------------
411
-
412
- /**
413
- * Check if current user purchased any other plugins before.
414
- *
415
- * @author Vova Feldman (@svovaf)
416
- * @since 1.0.9
417
- *
418
- * @return bool
419
- */
420
- abstract function has_purchased_before();
421
-
422
- /**
423
- * Check if current user classified as an agency.
424
- *
425
- * @author Vova Feldman (@svovaf)
426
- * @since 1.0.9
427
- *
428
- * @return bool
429
- */
430
- abstract function is_agency();
431
-
432
- /**
433
- * Check if current user classified as a developer.
434
- *
435
- * @author Vova Feldman (@svovaf)
436
- * @since 1.0.9
437
- *
438
- * @return bool
439
- */
440
- abstract function is_developer();
441
-
442
- /**
443
- * Check if current user classified as a business.
444
- *
445
- * @author Vova Feldman (@svovaf)
446
- * @since 1.0.9
447
- *
448
- * @return bool
449
- */
450
- abstract function is_business();
451
-
452
- #endregion ------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.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
+ #----------------------------------------------------------------------------------
26
+ #region Identity
27
+ #----------------------------------------------------------------------------------
28
+
29
+ /**
30
+ * Check if user registered with Freemius by connecting his account.
31
+ *
32
+ * @since 1.0.1
33
+ * @return bool
34
+ */
35
+ abstract function is_registered();
36
+
37
+ /**
38
+ * Check if the user skipped connecting the account with Freemius.
39
+ *
40
+ * @since 1.0.7
41
+ *
42
+ * @return bool
43
+ */
44
+ abstract function is_anonymous();
45
+
46
+ /**
47
+ * Check if the user currently in activation mode.
48
+ *
49
+ * @since 1.0.7
50
+ *
51
+ * @return bool
52
+ */
53
+ abstract function is_activation_mode();
54
+
55
+ #endregion
56
+
57
+ #----------------------------------------------------------------------------------
58
+ #region Usage Tracking
59
+ #----------------------------------------------------------------------------------
60
+
61
+ /**
62
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
63
+ *
64
+ * @author Leo Fajardo (@leorw)
65
+ * @since 1.2.1.5
66
+ *
67
+ * @return bool
68
+ */
69
+ abstract function is_tracking_allowed();
70
+
71
+ /**
72
+ * Returns TRUE if the user never opted-in or manually opted-out.
73
+ *
74
+ * @author Vova Feldman (@svovaf)
75
+ * @since 1.2.1.5
76
+ *
77
+ * @return bool
78
+ */
79
+ function is_tracking_prohibited() {
80
+ return ! $this->is_registered() || ! $this->is_tracking_allowed();
81
+ }
82
+
83
+ /**
84
+ * Opt-out from usage tracking.
85
+ *
86
+ * Note: This will not delete the account information but will stop all tracking.
87
+ *
88
+ * Returns:
89
+ * 1. FALSE - If the user never opted-in.
90
+ * 2. TRUE - If successfully opted-out.
91
+ * 3. object - API Result on failure.
92
+ *
93
+ * @author Leo Fajardo (@leorw)
94
+ * @since 1.2.1.5
95
+ *
96
+ * @return bool|object
97
+ */
98
+ abstract function stop_tracking();
99
+
100
+ /**
101
+ * Opt-in back into usage tracking.
102
+ *
103
+ * Note: This will only work if the user opted-in previously.
104
+ *
105
+ * Returns:
106
+ * 1. FALSE - If the user never opted-in.
107
+ * 2. TRUE - If successfully opted-in back to usage tracking.
108
+ * 3. object - API result on failure.
109
+ *
110
+ * @author Leo Fajardo (@leorw)
111
+ * @since 1.2.1.5
112
+ *
113
+ * @return bool|object
114
+ */
115
+ abstract function allow_tracking();
116
+
117
+ #endregion
118
+
119
+ #----------------------------------------------------------------------------------
120
+ #region Permissions
121
+ #----------------------------------------------------------------------------------
122
+
123
+ /**
124
+ * Check if plugin must be WordPress.org compliant.
125
+ *
126
+ * @since 1.0.7
127
+ *
128
+ * @return bool
129
+ */
130
+ abstract function is_org_repo_compliant();
131
+
132
+ /**
133
+ * Check if plugin is allowed to install executable files.
134
+ *
135
+ * @author Vova Feldman (@svovaf)
136
+ * @since 1.0.5
137
+ *
138
+ * @return bool
139
+ */
140
+ function is_allowed_to_install() {
141
+ return ( $this->is_premium() || ! $this->is_org_repo_compliant() );
142
+ }
143
+
144
+ #endregion
145
+
146
+ /**
147
+ * Check if user in trial or in free plan (not paying).
148
+ *
149
+ * @author Vova Feldman (@svovaf)
150
+ * @since 1.0.4
151
+ *
152
+ * @return bool
153
+ */
154
+ function is_not_paying() {
155
+ return ( $this->is_trial() || $this->is_free_plan() );
156
+ }
157
+
158
+ /**
159
+ * Check if the user has an activated and valid paid license on current plugin's install.
160
+ *
161
+ * @since 1.0.9
162
+ *
163
+ * @return bool
164
+ */
165
+ abstract function is_paying();
166
+
167
+ /**
168
+ * Check if the user is paying or in trial.
169
+ *
170
+ * @since 1.0.9
171
+ *
172
+ * @return bool
173
+ */
174
+ function is_paying_or_trial() {
175
+ return ( $this->is_paying() || $this->is_trial() );
176
+ }
177
+
178
+ /**
179
+ * Check if user in a trial or have feature enabled license.
180
+ *
181
+ * @author Vova Feldman (@svovaf)
182
+ * @since 1.1.7
183
+ *
184
+ * @return bool
185
+ */
186
+ abstract function can_use_premium_code();
187
+
188
+ #----------------------------------------------------------------------------------
189
+ #region Premium Only
190
+ #----------------------------------------------------------------------------------
191
+
192
+ /**
193
+ * All logic wrapped in methods with "__premium_only()" suffix will be only
194
+ * included in the premium code.
195
+ *
196
+ * Example:
197
+ * if ( freemius()->is__premium_only() ) {
198
+ * ...
199
+ * }
200
+ */
201
+
202
+ /**
203
+ * Returns true when running premium plugin code.
204
+ *
205
+ * @since 1.0.9
206
+ *
207
+ * @return bool
208
+ */
209
+ function is__premium_only() {
210
+ return $this->is_premium();
211
+ }
212
+
213
+ /**
214
+ * Check if the user has an activated and valid paid license on current plugin's install.
215
+ *
216
+ * @since 1.0.9
217
+ *
218
+ * @return bool
219
+ *
220
+ */
221
+ function is_paying__premium_only() {
222
+ return ( $this->is__premium_only() && $this->is_paying() );
223
+ }
224
+
225
+ /**
226
+ * All code wrapped in this statement will be only included in the premium code.
227
+ *
228
+ * @since 1.0.9
229
+ *
230
+ * @param string $plan Plan name
231
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
232
+ *
233
+ * @return bool
234
+ */
235
+ function is_plan__premium_only( $plan, $exact = false ) {
236
+ return ( $this->is_premium() && $this->is_plan( $plan, $exact ) );
237
+ }
238
+
239
+ /**
240
+ * Check if plan matches active license' plan or active trial license' plan.
241
+ *
242
+ * All code wrapped in this statement will be only included in the premium code.
243
+ *
244
+ * @since 1.0.9
245
+ *
246
+ * @param string $plan Plan name
247
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
248
+ *
249
+ * @return bool
250
+ */
251
+ function is_plan_or_trial__premium_only( $plan, $exact = false ) {
252
+ return ( $this->is_premium() && $this->is_plan_or_trial( $plan, $exact ) );
253
+ }
254
+
255
+ /**
256
+ * Check if the user is paying or in trial.
257
+ *
258
+ * All code wrapped in this statement will be only included in the premium code.
259
+ *
260
+ * @since 1.0.9
261
+ *
262
+ * @return bool
263
+ */
264
+ function is_paying_or_trial__premium_only() {
265
+ return $this->is_premium() && $this->is_paying_or_trial();
266
+ }
267
+
268
+ /**
269
+ * Check if the user has an activated and valid paid license on current plugin's install.
270
+ *
271
+ * @since 1.0.4
272
+ *
273
+ * @return bool
274
+ *
275
+ * @deprecated Method name is confusing since it's not clear from the name the code will be removed.
276
+ * @using Alias to is_paying__premium_only()
277
+ */
278
+ function is_paying__fs__() {
279
+ return $this->is_paying__premium_only();
280
+ }
281
+
282
+ /**
283
+ * Check if user in a trial or have feature enabled license.
284
+ *
285
+ * All code wrapped in this statement will be only included in the premium code.
286
+ *
287
+ * @author Vova Feldman (@svovaf)
288
+ * @since 1.1.9
289
+ *
290
+ * @return bool
291
+ */
292
+ function can_use_premium_code__premium_only() {
293
+ return $this->is_premium() && $this->can_use_premium_code();
294
+ }
295
+
296
+ #endregion
297
+
298
+ #----------------------------------------------------------------------------------
299
+ #region Trial
300
+ #----------------------------------------------------------------------------------
301
+
302
+ /**
303
+ * Check if the user in a trial.
304
+ *
305
+ * @since 1.0.3
306
+ *
307
+ * @return bool
308
+ */
309
+ abstract function is_trial();
310
+
311
+ /**
312
+ * Check if trial already utilized.
313
+ *
314
+ * @since 1.0.9
315
+ *
316
+ * @return bool
317
+ */
318
+ abstract function is_trial_utilized();
319
+
320
+ #endregion
321
+
322
+ #----------------------------------------------------------------------------------
323
+ #region Plans
324
+ #----------------------------------------------------------------------------------
325
+
326
+ /**
327
+ * Check if plugin using the free plan.
328
+ *
329
+ * @since 1.0.4
330
+ *
331
+ * @return bool
332
+ */
333
+ abstract function is_free_plan();
334
+
335
+ /**
336
+ * @since 1.0.2
337
+ *
338
+ * @param string $plan Plan name
339
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
340
+ *
341
+ * @return bool
342
+ */
343
+ abstract function is_plan( $plan, $exact = false );
344
+
345
+ /**
346
+ * Check if plan based on trial. If not in trial mode, should return false.
347
+ *
348
+ * @since 1.0.9
349
+ *
350
+ * @param string $plan Plan name
351
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
352
+ *
353
+ * @return bool
354
+ */
355
+ abstract function is_trial_plan( $plan, $exact = false );
356
+
357
+ /**
358
+ * Check if plan matches active license' plan or active trial license' plan.
359
+ *
360
+ * @since 1.0.9
361
+ *
362
+ * @param string $plan Plan name
363
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
364
+ *
365
+ * @return bool
366
+ */
367
+ function is_plan_or_trial( $plan, $exact = false ) {
368
+ return $this->is_plan( $plan, $exact ) ||
369
+ $this->is_trial_plan( $plan, $exact );
370
+ }
371
+
372
+ /**
373
+ * Check if plugin has any paid plans.
374
+ *
375
+ * @author Vova Feldman (@svovaf)
376
+ * @since 1.0.7
377
+ *
378
+ * @return bool
379
+ */
380
+ abstract function has_paid_plan();
381
+
382
+ /**
383
+ * Check if plugin has any free plan, or is it premium only.
384
+ *
385
+ * Note: If no plans configured, assume plugin is free.
386
+ *
387
+ * @author Vova Feldman (@svovaf)
388
+ * @since 1.0.7
389
+ *
390
+ * @return bool
391
+ */
392
+ abstract function has_free_plan();
393
+
394
+ /**
395
+ * Check if plugin is premium only (no free plans).
396
+ *
397
+ * NOTE: is__premium_only() is very different method, don't get confused.
398
+ *
399
+ * @author Vova Feldman (@svovaf)
400
+ * @since 1.1.9
401
+ *
402
+ * @return bool
403
+ */
404
+ abstract function is_only_premium();
405
+
406
+ /**
407
+ * Checks if it's a freemium plugin.
408
+ *
409
+ * @author Vova Feldman (@svovaf)
410
+ * @since 1.1.9
411
+ *
412
+ * @return bool
413
+ */
414
+ function is_freemium() {
415
+ return $this->has_paid_plan() &&
416
+ $this->has_free_plan();
417
+ }
418
+
419
+ #endregion
420
+
421
+ /**
422
+ * Check if running payments in sandbox mode.
423
+ *
424
+ * @since 1.0.4
425
+ *
426
+ * @return bool
427
+ */
428
+ abstract function is_payments_sandbox();
429
+
430
+ /**
431
+ * Check if running test vs. live plugin.
432
+ *
433
+ * @since 1.0.5
434
+ *
435
+ * @return bool
436
+ */
437
+ abstract function is_live();
438
+
439
+ /**
440
+ * Check if running premium plugin code.
441
+ *
442
+ * @since 1.0.5
443
+ *
444
+ * @return bool
445
+ */
446
+ abstract function is_premium();
447
+
448
+ /**
449
+ * Get upgrade URL.
450
+ *
451
+ * @author Vova Feldman (@svovaf)
452
+ * @since 1.0.2
453
+ *
454
+ * @param string $period Billing cycle
455
+ *
456
+ * @return string
457
+ */
458
+ abstract function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY );
459
+
460
+ /**
461
+ * Check if Freemius was first added in a plugin update.
462
+ *
463
+ * @author Vova Feldman (@svovaf)
464
+ * @since 1.1.5
465
+ *
466
+ * @return bool
467
+ */
468
+ function is_plugin_update() {
469
+ return ! $this->is_plugin_new_install();
470
+ }
471
+
472
+ /**
473
+ * Check if Freemius was part of the plugin when the user installed it first.
474
+ *
475
+ * @author Vova Feldman (@svovaf)
476
+ * @since 1.1.5
477
+ *
478
+ * @return bool
479
+ */
480
+ abstract function is_plugin_new_install();
481
+
482
+ #----------------------------------------------------------------------------------
483
+ #region Marketing
484
+ #----------------------------------------------------------------------------------
485
+
486
+ /**
487
+ * Check if current user purchased any other plugins before.
488
+ *
489
+ * @author Vova Feldman (@svovaf)
490
+ * @since 1.0.9
491
+ *
492
+ * @return bool
493
+ */
494
+ abstract function has_purchased_before();
495
+
496
+ /**
497
+ * Check if current user classified as an agency.
498
+ *
499
+ * @author Vova Feldman (@svovaf)
500
+ * @since 1.0.9
501
+ *
502
+ * @return bool
503
+ */
504
+ abstract function is_agency();
505
+
506
+ /**
507
+ * Check if current user classified as a developer.
508
+ *
509
+ * @author Vova Feldman (@svovaf)
510
+ * @since 1.0.9
511
+ *
512
+ * @return bool
513
+ */
514
+ abstract function is_developer();
515
+
516
+ /**
517
+ * Check if current user classified as a business.
518
+ *
519
+ * @author Vova Feldman (@svovaf)
520
+ * @since 1.0.9
521
+ *
522
+ * @return bool
523
+ */
524
+ abstract function is_business();
525
+
526
+ #endregion
527
  }
freemius/includes/class-freemius.php CHANGED
@@ -1,10456 +1,11344 @@
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
- // Reason IDs
231
- const REASON_NO_LONGER_NEEDED = 1;
232
- const REASON_FOUND_A_BETTER_PLUGIN = 2;
233
- const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
234
- const REASON_BROKE_MY_SITE = 4;
235
- const REASON_SUDDENLY_STOPPED_WORKING = 5;
236
- const REASON_CANT_PAY_ANYMORE = 6;
237
- const REASON_OTHER = 7;
238
- const REASON_DIDNT_WORK = 8;
239
- const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
240
- const REASON_COULDNT_MAKE_IT_WORK = 10;
241
- const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
242
- const REASON_NOT_WORKING = 12;
243
- const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
244
- const REASON_DIDNT_WORK_AS_EXPECTED = 14;
245
- const REASON_TEMPORARY_DEACTIVATION = 15;
246
-
247
- /* Ctor
248
- ------------------------------------------------------------------------------------------------------------------*/
249
-
250
- /**
251
- * Main singleton instance.
252
- *
253
- * @author Vova Feldman (@svovaf)
254
- * @since 1.0.0
255
- *
256
- * @param string $slug
257
- * @param bool $is_init Since 1.2.1 Is initiation sequence.
258
- */
259
- private function __construct( $slug, $is_init = false ) {
260
- $this->_slug = $slug;
261
-
262
- $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
263
-
264
- $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
265
-
266
- $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
267
- $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
268
- $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
269
- $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
270
-
271
- $base_name_split = explode( '/', $this->_plugin_basename );
272
- $this->_plugin_dir_name = $base_name_split[0];
273
-
274
- if ( $this->_logger->is_on() ) {
275
- $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
276
- $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
277
- $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
278
- $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
279
- $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
280
- }
281
-
282
- // Remember link between file to slug.
283
- $this->store_file_slug_map();
284
-
285
- // Store plugin's initial install timestamp.
286
- if ( ! isset( $this->_storage->install_timestamp ) ) {
287
- $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
288
- }
289
-
290
- $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
291
-
292
- $this->_admin_notices = FS_Admin_Notice_Manager::instance(
293
- $slug,
294
- is_object( $this->_plugin ) ? $this->_plugin->title : ''
295
- );
296
-
297
- if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
298
- 'true' === fs_request_is_action( 'restart_freemius' )
299
- ) {
300
- FS_Api::clear_cache();
301
- }
302
-
303
- $this->_register_hooks();
304
-
305
- $this->_load_account();
306
-
307
- $this->_version_updates_handler();
308
- }
309
-
310
- /**
311
- * @author Vova Feldman (@svovaf)
312
- * @since 1.0.9
313
- */
314
- private function _version_updates_handler() {
315
- if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
316
- // Freemius version upgrade mode.
317
- $this->_storage->sdk_last_version = $this->_storage->sdk_version;
318
- $this->_storage->sdk_version = $this->version;
319
-
320
- if ( empty( $this->_storage->sdk_last_version ) ||
321
- version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
322
- ) {
323
- $this->_storage->sdk_upgrade_mode = true;
324
- $this->_storage->sdk_downgrade_mode = false;
325
- } else {
326
- $this->_storage->sdk_downgrade_mode = true;
327
- $this->_storage->sdk_upgrade_mode = false;
328
-
329
- }
330
-
331
- $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
332
- }
333
-
334
- $plugin_version = $this->get_plugin_version();
335
- if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
336
- // Plugin version upgrade mode.
337
- $this->_storage->plugin_last_version = $this->_storage->plugin_version;
338
- $this->_storage->plugin_version = $plugin_version;
339
-
340
- if ( empty( $this->_storage->plugin_last_version ) ||
341
- version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
342
- ) {
343
- $this->_storage->plugin_upgrade_mode = true;
344
- $this->_storage->plugin_downgrade_mode = false;
345
- } else {
346
- $this->_storage->plugin_downgrade_mode = true;
347
- $this->_storage->plugin_upgrade_mode = false;
348
- }
349
-
350
- if ( ! empty( $this->_storage->plugin_last_version ) ) {
351
- // Different version of the plugin was installed before, therefore it's an update.
352
- $this->_storage->is_plugin_new_install = false;
353
- }
354
-
355
- $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
356
- }
357
- }
358
-
359
- /**
360
- * @author Vova Feldman (@svovaf)
361
- * @since 1.1.5
362
- *
363
- * @param string $sdk_prev_version
364
- * @param string $sdk_version
365
- */
366
- function _data_migration( $sdk_prev_version, $sdk_version ) {
367
- /**
368
- * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
369
- */
370
- if ( empty( $sdk_prev_version ) ) {
371
- return;
372
- }
373
-
374
- if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
375
- version_compare( $sdk_version, '1.1.5', '>=' )
376
- ) {
377
- // On version 1.1.5 merged connectivity and is_on data.
378
- if ( isset( $this->_storage->connectivity_test ) ) {
379
- if ( ! isset( $this->_storage->is_on ) ) {
380
- unset( $this->_storage->connectivity_test );
381
- } else {
382
- $connectivity_data = $this->_storage->connectivity_test;
383
- $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
384
- $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
385
-
386
- // Override.
387
- $this->_storage->connectivity_test = $connectivity_data;
388
-
389
- // Remove previous structure.
390
- unset( $this->_storage->is_on );
391
- }
392
-
393
- }
394
- }
395
- }
396
-
397
- /**
398
- * This action is connected to the 'plugins_loaded' hook and helps to determine
399
- * if this is a new plugin installation or a plugin update.
400
- *
401
- * There are 3 different use-cases:
402
- * 1) New plugin installation right with Freemius:
403
- * 1.1 _activate_plugin_event_hook() will be executed first
404
- * 1.2 Since $this->_storage->is_plugin_new_install is not set,
405
- * and $this->_storage->plugin_last_version is not set,
406
- * $this->_storage->is_plugin_new_install will be set to TRUE.
407
- * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
408
- * be already set to TRUE.
409
- *
410
- * 2) Plugin update, didn't have Freemius before, and now have the SDK:
411
- * 2.1 _activate_plugin_event_hook() will not be executed, because
412
- * the activation hook do NOT fires on updates since WP 3.1.
413
- * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
414
- * be empty, therefore, it will be set to FALSE.
415
- *
416
- * 3) Plugin update, had Freemius in prev version as well:
417
- * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
418
- * before, $this->_storage->plugin_last_version will NOT be empty,
419
- * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
420
- * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
421
- * already set, therefore, it will not be modified.
422
- *
423
- * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
424
- *
425
- * NOTE:
426
- * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
427
- * and then, the next immediate PageView is the plugin's main settings page, it will not
428
- * show the opt-in right away. The reason it will happen is because Freemius execution
429
- * will be turned off till the plugin is fully loaded at least once
430
- * (till $this->_storage->was_plugin_loaded is TRUE).
431
- *
432
- * @author Vova Feldman (@svovaf)
433
- * @since 1.1.9
434
- *
435
- */
436
- function _plugins_loaded() {
437
- // Update flag that plugin was loaded with Freemius at least once.
438
- $this->_storage->was_plugin_loaded = true;
439
-
440
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
441
- $this->_storage->is_plugin_new_install = false;
442
- }
443
- }
444
-
445
- /**
446
- * @author Vova Feldman (@svovaf)
447
- * @since 1.0.9
448
- */
449
- private function _register_hooks() {
450
- if ( is_admin() ) {
451
- // Hook to plugin activation
452
- register_activation_hook( $this->_plugin_main_file_path, array(
453
- &$this,
454
- '_activate_plugin_event_hook'
455
- ) );
456
-
457
- /**
458
- * Part of the mechanism to identify new plugin install vs. plugin update.
459
- *
460
- * @author Vova Feldman (@svovaf)
461
- * @since 1.1.9
462
- */
463
- if ( empty( $this->_storage->was_plugin_loaded ) ) {
464
- if ( $this->is_activation_mode( false ) ) {
465
- add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
466
- } else {
467
- // If was activated before, then it was already loaded before.
468
- $this->_plugins_loaded();
469
- }
470
- }
471
-
472
- if ( ! $this->is_ajax() ) {
473
- if ( ! $this->is_addon() ) {
474
- add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
475
- add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
476
- }
477
- }
478
- }
479
-
480
- register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
481
-
482
- add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
483
-
484
- $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
485
-
486
- $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
487
- }
488
-
489
- /**
490
- * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
491
- * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
492
- * plugin will trigger inclusion of the free or premium version and if one of them is active during the
493
- * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
494
- *
495
- * @author Leo Fajardo (leorw)
496
- *
497
- * @since 1.2.0
498
- */
499
- private function unregister_uninstall_hook() {
500
- $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
501
- unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
502
- unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
503
-
504
- update_option( 'uninstall_plugins', $uninstallable_plugins );
505
- }
506
-
507
- /**
508
- * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
509
- */
510
- private function clear_module_main_file_cache() {
511
- if ( ! isset( $this->_storage->plugin_main_file ) ||
512
- empty( $this->_storage->plugin_main_file->path )
513
- ) {
514
- return;
515
- }
516
-
517
- // Store cached path (2nd layer cache).
518
- $this->_storage->plugin_main_file->prev_path = $this->_storage->plugin_main_file->path;
519
-
520
- // Clear cached path.
521
- unset( $this->_storage->plugin_main_file->path );
522
- }
523
-
524
- /**
525
- * @author Vova Feldman (@svovaf)
526
- * @since 1.0.9
527
- */
528
- private function _register_account_hooks() {
529
- if ( is_admin() ) {
530
- if ( ! $this->is_ajax() ) {
531
- if ( $this->apply_filters( 'show_trial', true ) && $this->has_trial_plan() ) {
532
- $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
533
- if ( ! $this->_site->is_trial_utilized() &&
534
- (
535
- // Show promotion if never shown it yet and 24 hours after initial activation.
536
- ( false === $last_time_trial_promotion_shown && $this->_storage->activation_timestamp < ( time() - WP_FS__TIME_24_HOURS_IN_SEC ) ) ||
537
- // Show promotion in every 30 days.
538
- ( is_numeric( $last_time_trial_promotion_shown ) && 30 * WP_FS__TIME_24_HOURS_IN_SEC < time() - $last_time_trial_promotion_shown ) )
539
- ) {
540
- $this->add_action( 'after_init_plugin_registered', array( &$this, '_add_trial_notice' ) );
541
- }
542
- }
543
- }
544
-
545
- // If user is paying or in trial and have the free version installed,
546
- // assume that the deactivation is for the upgrade process.
547
- if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
548
- $this->add_ajax_action(
549
- 'submit_uninstall_reason',
550
- array( &$this, '_submit_uninstall_reason_action' )
551
- );
552
-
553
- global $pagenow;
554
- if ( 'plugins.php' === $pagenow ) {
555
- add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
556
- }
557
- }
558
-
559
- if ( ! $this->is_addon() ) {
560
- if ( $this->is_registered() ) {
561
- $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
562
- }
563
- }
564
- }
565
- }
566
-
567
- /**
568
- * Leverage backtrace to find caller plugin file path.
569
- *
570
- * @author Vova Feldman (@svovaf)
571
- * @since 1.0.6
572
- *
573
- * @param bool $is_init Is initiation sequence.
574
- *
575
- * @return string
576
- *
577
- * @uses fs_find_caller_plugin_file
578
- */
579
- private function _find_caller_plugin_file( $is_init = false ) {
580
- // Try to load the cached value of the file path.
581
- if ( isset( $this->_storage->plugin_main_file ) && isset( $this->_storage->plugin_main_file->path ) ) {
582
- if ( file_exists( $this->_storage->plugin_main_file->path ) ) {
583
- return $this->_storage->plugin_main_file->path;
584
- }
585
- }
586
-
587
- /**
588
- * @since 1.2.1
589
- *
590
- * `clear_module_main_file_cache()` is clearing the plugin's cached path on
591
- * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
592
- * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
593
- *
594
- * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
595
- * when the class instantiator isn't the module.
596
- */
597
- if ( ! $is_init ) {
598
- // Fetch prev path cache.
599
- if ( isset( $this->_storage->plugin_main_file ) &&
600
- isset( $this->_storage->plugin_main_file->prev_path )
601
- ) {
602
- if ( file_exists( $this->_storage->plugin_main_file->prev_path ) ) {
603
- return $this->_storage->plugin_main_file->prev_path;
604
- }
605
- }
606
-
607
- wp_die(
608
- __fs( 'failed-finding-main-path', $this->_slug ),
609
- __fs( 'error' ),
610
- array( 'back_link' => true )
611
- );
612
- }
613
-
614
- /**
615
- * @since 1.2.1
616
- *
617
- * Only the original instantiator that calls dynamic_init can modify the module's path.
618
- */
619
- // Find caller module.
620
- $plugin_file = fs_find_caller_plugin_file();
621
-
622
- $this->_storage->plugin_main_file = (object) array(
623
- 'path' => fs_normalize_path( $plugin_file ),
624
- );
625
-
626
- return $plugin_file;
627
- }
628
-
629
-
630
- #region Deactivation Feedback Form ------------------------------------------------------------------
631
-
632
- /**
633
- * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
634
- * page.
635
- *
636
- * @author Vova Feldman (@svovaf)
637
- * @author Leo Fajardo (@leorw)
638
- * @since 1.1.2
639
- */
640
- function _add_deactivation_feedback_dialog_box() {
641
- /* Check the type of user:
642
- * 1. Long-term (long-term)
643
- * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
644
- * 3. Short-term (short-term)
645
- */
646
- $is_long_term_user = true;
647
-
648
- // Check if the site is at least 2 days old.
649
- $time_installed = $this->_storage->install_timestamp;
650
-
651
- // Difference in seconds.
652
- $date_diff = time() - $time_installed;
653
-
654
- // Convert seconds to days.
655
- $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
656
-
657
- if ( $date_diff_days < 2 ) {
658
- $is_long_term_user = false;
659
- }
660
-
661
- $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
662
-
663
- if ( $is_long_term_user ) {
664
- $user_type = 'long-term';
665
- } else {
666
- if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
667
- $user_type = 'non-registered-and-non-anonymous-short-term';
668
- } else {
669
- $user_type = 'short-term';
670
- }
671
- }
672
-
673
- $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
674
-
675
- // Load the HTML template for the deactivation feedback dialog box.
676
- $vars = array(
677
- 'reasons' => $uninstall_reasons,
678
- 'slug' => $this->_slug
679
- );
680
-
681
- /**
682
- * @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.
683
- */
684
- fs_require_template( 'forms/deactivation/form.php', $vars );
685
- }
686
-
687
- /**
688
- * @author Leo Fajardo (leorw)
689
- * @since 1.1.2
690
- *
691
- * @param string $user_type
692
- *
693
- * @return array The uninstall reasons for the specified user type.
694
- */
695
- function _get_uninstall_reasons( $user_type = 'long-term' ) {
696
- $internal_message_template_var = array(
697
- 'slug' => $this->_slug
698
- );
699
-
700
- if ( $this->is_registered() && false !== $this->get_plan() && $this->get_plan()->has_technical_support() ) {
701
- $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
702
- } else {
703
- $contact_support_template = '';
704
- }
705
-
706
- $reason_found_better_plugin = array(
707
- 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
708
- 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
709
- 'input_type' => 'textfield',
710
- 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
711
- );
712
-
713
- $reason_temporary_deactivation = array(
714
- 'id' => self::REASON_TEMPORARY_DEACTIVATION,
715
- 'text' => __fs( 'reason-temporary-deactivation', $this->_slug ),
716
- 'input_type' => '',
717
- 'input_placeholder' => ''
718
- );
719
-
720
- $reason_other = array(
721
- 'id' => self::REASON_OTHER,
722
- 'text' => __fs( 'reason-other', $this->_slug ),
723
- 'input_type' => 'textfield',
724
- 'input_placeholder' => ''
725
- );
726
-
727
- $long_term_user_reasons = array(
728
- array(
729
- 'id' => self::REASON_NO_LONGER_NEEDED,
730
- 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
731
- 'input_type' => '',
732
- 'input_placeholder' => ''
733
- ),
734
- $reason_found_better_plugin,
735
- array(
736
- 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
737
- 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
738
- 'input_type' => '',
739
- 'input_placeholder' => ''
740
- ),
741
- array(
742
- 'id' => self::REASON_BROKE_MY_SITE,
743
- 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
744
- 'input_type' => '',
745
- 'input_placeholder' => '',
746
- 'internal_message' => $contact_support_template
747
- ),
748
- array(
749
- 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
750
- 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
751
- 'input_type' => '',
752
- 'input_placeholder' => '',
753
- 'internal_message' => $contact_support_template
754
- )
755
- );
756
-
757
- if ( $this->is_paying() ) {
758
- $long_term_user_reasons[] = array(
759
- 'id' => self::REASON_CANT_PAY_ANYMORE,
760
- 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
761
- 'input_type' => 'textfield',
762
- 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
763
- );
764
- }
765
-
766
- $reason_dont_share_info = array(
767
- 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
768
- 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
769
- 'input_type' => '',
770
- 'input_placeholder' => ''
771
- );
772
-
773
- /**
774
- * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
775
- * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
776
- * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
777
- * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
778
- * button in the opt-in form is shown/hidden).
779
- */
780
- if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
781
- $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
782
- }
783
-
784
- $uninstall_reasons = array(
785
- 'long-term' => $long_term_user_reasons,
786
- 'non-registered-and-non-anonymous-short-term' => array(
787
- array(
788
- 'id' => self::REASON_DIDNT_WORK,
789
- 'text' => __fs( 'reason-didnt-work', $this->_slug ),
790
- 'input_type' => '',
791
- 'input_placeholder' => ''
792
- ),
793
- $reason_dont_share_info,
794
- $reason_found_better_plugin
795
- ),
796
- 'short-term' => array(
797
- array(
798
- 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
799
- 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
800
- 'input_type' => '',
801
- 'input_placeholder' => '',
802
- 'internal_message' => $contact_support_template
803
- ),
804
- $reason_found_better_plugin,
805
- array(
806
- 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
807
- 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
808
- 'input_type' => 'textarea',
809
- 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
810
- ),
811
- array(
812
- 'id' => self::REASON_NOT_WORKING,
813
- 'text' => __fs( 'reason-not-working', $this->_slug ),
814
- 'input_type' => 'textarea',
815
- 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
816
- ),
817
- array(
818
- 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
819
- 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
820
- 'input_type' => 'textarea',
821
- 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
822
- ),
823
- array(
824
- 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
825
- 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
826
- 'input_type' => 'textarea',
827
- 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
828
- )
829
- )
830
- );
831
-
832
- // Randomize the reasons for the current user type.
833
- shuffle( $uninstall_reasons[ $user_type ] );
834
-
835
- // Keep the following reasons as the last items in the list.
836
- $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
837
- $uninstall_reasons[ $user_type ][] = $reason_other;
838
-
839
- $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
840
-
841
- return $uninstall_reasons[ $user_type ];
842
- }
843
-
844
- /**
845
- * Called after the user has submitted his reason for deactivating the plugin.
846
- *
847
- * @author Leo Fajardo (@leorw)
848
- * @since 1.1.2
849
- */
850
- function _submit_uninstall_reason_action() {
851
- $reason_id = fs_request_get( 'reason_id' );
852
-
853
- // Check if the given reason ID is an unsigned integer.
854
- if ( ! ctype_digit( $reason_id ) ) {
855
- exit;
856
- }
857
-
858
- $reason_info = trim( fs_request_get( 'reason_info', '' ) );
859
- if ( ! empty( $reason_info ) ) {
860
- $reason_info = substr( $reason_info, 0, 128 );
861
- }
862
-
863
- $reason = (object) array(
864
- 'id' => $reason_id,
865
- 'info' => $reason_info,
866
- 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
867
- );
868
-
869
- $this->_storage->store( 'uninstall_reason', $reason );
870
-
871
- // Print '1' for successful operation.
872
- echo 1;
873
- exit;
874
- }
875
-
876
- #endregion Deactivation Feedback Form ------------------------------------------------------------------
877
-
878
- #region Instance ------------------------------------------------------------------
879
-
880
- /**
881
- * Main singleton instance.
882
- *
883
- * @author Vova Feldman (@svovaf)
884
- * @since 1.0.0
885
- *
886
- * @param string $slug
887
- * @param bool $is_init Is initiation sequence.
888
- *
889
- * @return Freemius
890
- */
891
- static function instance( $slug, $is_init = false ) {
892
- $slug = strtolower( $slug );
893
-
894
- if ( ! isset( self::$_instances[ $slug ] ) ) {
895
- if ( 0 === count( self::$_instances ) ) {
896
- self::_load_required_static();
897
- }
898
-
899
- self::$_instances[ $slug ] = new Freemius( $slug, $is_init );
900
- }
901
-
902
- return self::$_instances[ $slug ];
903
- }
904
-
905
- /**
906
- * @author Vova Feldman (@svovaf)
907
- * @since 1.0.6
908
- *
909
- * @param string|number $slug_or_id
910
- *
911
- * @return bool
912
- */
913
- private static function has_instance( $slug_or_id ) {
914
- return ! is_numeric( $slug_or_id ) ?
915
- isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
916
- ( false !== self::get_instance_by_id( $slug_or_id ) );
917
- }
918
-
919
- /**
920
- * @author Vova Feldman (@svovaf)
921
- * @since 1.0.6
922
- *
923
- * @param $id
924
- *
925
- * @return false|Freemius
926
- */
927
- static function get_instance_by_id( $id ) {
928
- foreach ( self::$_instances as $slug => $instance ) {
929
- if ( $id == $instance->get_id() ) {
930
- return $instance;
931
- }
932
- }
933
-
934
- return false;
935
- }
936
-
937
- /**
938
- *
939
- * @author Vova Feldman (@svovaf)
940
- * @since 1.0.1
941
- *
942
- * @param $plugin_file
943
- *
944
- * @return false|Freemius
945
- */
946
- static function get_instance_by_file( $plugin_file ) {
947
- $slug = self::find_slug_by_basename( $plugin_file );
948
-
949
- return ( false !== $slug ) ?
950
- self::instance( $slug ) :
951
- false;
952
- }
953
-
954
- /**
955
- * @author Vova Feldman (@svovaf)
956
- * @since 1.0.6
957
- *
958
- * @return false|Freemius
959
- */
960
- function get_parent_instance() {
961
- return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
962
- }
963
-
964
- /**
965
- * @author Vova Feldman (@svovaf)
966
- * @since 1.0.6
967
- *
968
- * @param $slug_or_id
969
- *
970
- * @return bool|Freemius
971
- */
972
- function get_addon_instance( $slug_or_id ) {
973
- return ! is_numeric( $slug_or_id ) ?
974
- self::instance( strtolower( $slug_or_id ) ) :
975
- self::get_instance_by_id( $slug_or_id );
976
- }
977
-
978
- #endregion ------------------------------------------------------------------
979
-
980
- /**
981
- * @author Vova Feldman (@svovaf)
982
- * @since 1.0.6
983
- *
984
- * @return bool
985
- */
986
- function is_parent_plugin_installed() {
987
- return self::has_instance( $this->_plugin->parent_plugin_id );
988
- }
989
-
990
- /**
991
- * Check if add-on parent plugin in activation mode.
992
- *
993
- * @author Vova Feldman (@svovaf)
994
- * @since 1.0.7
995
- *
996
- * @return bool
997
- */
998
- function is_parent_in_activation() {
999
- $parent_fs = $this->get_parent_instance();
1000
- if ( ! is_object( $parent_fs ) ) {
1001
- return false;
1002
- }
1003
-
1004
- return ( $parent_fs->is_activation_mode() );
1005
- }
1006
-
1007
- /**
1008
- * Is plugin in activation mode.
1009
- *
1010
- * @author Vova Feldman (@svovaf)
1011
- * @since 1.0.7
1012
- *
1013
- * @param bool $and_on
1014
- *
1015
- * @return bool
1016
- */
1017
- function is_activation_mode( $and_on = true ) {
1018
- return (
1019
- ( $this->is_on() || ! $and_on ) &&
1020
- ! $this->is_registered() &&
1021
- ( ! $this->is_enable_anonymous() ||
1022
- ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
1023
- );
1024
- }
1025
-
1026
- /**
1027
- * Get collection of all active plugins.
1028
- *
1029
- * @author Vova Feldman (@svovaf)
1030
- * @since 1.0.9
1031
- *
1032
- * @return array[string]array
1033
- */
1034
- private static function get_active_plugins() {
1035
- self::require_plugin_essentials();
1036
-
1037
- $active_plugin = array();
1038
- $all_plugins = get_plugins();
1039
- $active_plugins_basenames = get_option( 'active_plugins' );
1040
-
1041
- foreach ( $active_plugins_basenames as $plugin_basename ) {
1042
- $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
1043
- }
1044
-
1045
- return $active_plugin;
1046
- }
1047
-
1048
- /**
1049
- * Get collection of all plugins.
1050
- *
1051
- * @author Vova Feldman (@svovaf)
1052
- * @since 1.1.8
1053
- *
1054
- * @return array Key is the plugin file path and the value is an array of the plugin data.
1055
- */
1056
- private static function get_all_plugins() {
1057
- self::require_plugin_essentials();
1058
-
1059
- $all_plugins = get_plugins();
1060
- $active_plugins_basenames = get_option( 'active_plugins' );
1061
-
1062
- foreach ( $all_plugins as $basename => &$data ) {
1063
- // By default set to inactive (next foreach update the active plugins).
1064
- $data['is_active'] = false;
1065
- // Enrich with plugin slug.
1066
- $data['slug'] = self::get_plugin_slug( $basename );
1067
- }
1068
-
1069
- // Flag active plugins.
1070
- foreach ( $active_plugins_basenames as $basename ) {
1071
- if ( isset( $all_plugins[ $basename ] ) ) {
1072
- $all_plugins[ $basename ]['is_active'] = true;
1073
- }
1074
- }
1075
-
1076
- return $all_plugins;
1077
- }
1078
-
1079
-
1080
- /**
1081
- * Cached result of get_site_transient( 'update_plugins' )
1082
- *
1083
- * @author Vova Feldman (@svovaf)
1084
- * @since 1.1.8
1085
- *
1086
- * @var object
1087
- */
1088
- private static $_plugins_info;
1089
-
1090
- /**
1091
- * Helper function to get specified plugin's slug.
1092
- *
1093
- * @author Vova Feldman (@svovaf)
1094
- * @since 1.1.8
1095
- *
1096
- * @param $basename
1097
- *
1098
- * @return string
1099
- */
1100
- private static function get_plugin_slug( $basename ) {
1101
- if ( ! isset( self::$_plugins_info ) ) {
1102
- self::$_plugins_info = get_site_transient( 'update_plugins' );
1103
- }
1104
-
1105
- $slug = '';
1106
-
1107
- if ( is_object( self::$_plugins_info ) ) {
1108
- if ( isset( self::$_plugins_info->no_update ) &&
1109
- isset( self::$_plugins_info->no_update[ $basename ] ) &&
1110
- ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
1111
- ) {
1112
- $slug = self::$_plugins_info->no_update[ $basename ]->slug;
1113
- } else if ( isset( self::$_plugins_info->response ) &&
1114
- isset( self::$_plugins_info->response[ $basename ] ) &&
1115
- ! empty( self::$_plugins_info->response[ $basename ]->slug )
1116
- ) {
1117
- $slug = self::$_plugins_info->response[ $basename ]->slug;
1118
- }
1119
- }
1120
-
1121
- if ( empty( $slug ) ) {
1122
- // Try to find slug from FS data.
1123
- $slug = self::find_slug_by_basename( $basename );
1124
- }
1125
-
1126
- if ( empty( $slug ) ) {
1127
- // Fallback to plugin's folder name.
1128
- $slug = dirname( $basename );
1129
- }
1130
-
1131
- return $slug;
1132
- }
1133
-
1134
- private static $_statics_loaded = false;
1135
-
1136
- /**
1137
- * Load static resources.
1138
- *
1139
- * @author Vova Feldman (@svovaf)
1140
- * @since 1.0.1
1141
- */
1142
- private static function _load_required_static() {
1143
- if ( self::$_statics_loaded ) {
1144
- return;
1145
- }
1146
-
1147
- self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
1148
-
1149
- self::$_static_logger->entrance();
1150
-
1151
- self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
1152
-
1153
- self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
1154
-
1155
- // Configure which Freemius powered plugins should be auto updated.
1156
- // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
1157
-
1158
- add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
1159
-
1160
- add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
1161
-
1162
- add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
1163
-
1164
- self::$_statics_loaded = true;
1165
- }
1166
-
1167
- /**
1168
- * Load framework's text domain.
1169
- *
1170
- * @author Vova Feldman (@svovaf)
1171
- * @since 1.2.1
1172
- */
1173
- static function _load_textdomain() {
1174
- if ( ! is_admin() ) {
1175
- return;
1176
- }
1177
-
1178
- global $fs_active_plugins;
1179
-
1180
- load_plugin_textdomain(
1181
- 'freemius',
1182
- false,
1183
- $fs_active_plugins->newest->sdk_path . '/languages/'
1184
- );
1185
-
1186
- // @todo Load for themes.
1187
- }
1188
-
1189
- #region Debugging ------------------------------------------------------------------
1190
-
1191
- /**
1192
- * @author Vova Feldman (@svovaf)
1193
- * @since 1.0.8
1194
- */
1195
- static function add_debug_page() {
1196
- if ( ! current_user_can( 'activate_plugins' ) ) {
1197
- return;
1198
- }
1199
-
1200
- self::$_static_logger->entrance();
1201
-
1202
- $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
1203
-
1204
- if ( WP_FS__DEV_MODE ) {
1205
- // Add top-level debug menu item.
1206
- $hook = add_menu_page(
1207
- $title,
1208
- $title,
1209
- 'manage_options',
1210
- 'freemius',
1211
- array( 'Freemius', '_debug_page_render' )
1212
- );
1213
- } else {
1214
- // Add hidden debug page.
1215
- $hook = add_submenu_page(
1216
- null,
1217
- $title,
1218
- $title,
1219
- 'manage_options',
1220
- 'freemius',
1221
- array( 'Freemius', '_debug_page_render' )
1222
- );
1223
- }
1224
-
1225
- add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
1226
- }
1227
-
1228
- /**
1229
- * @author Vova Feldman (@svovaf)
1230
- * @since 1.1.7.3
1231
- */
1232
- static function _toggle_debug_mode() {
1233
- if ( in_array( $_POST['is_on'], array( 0, 1 ) ) ) {
1234
- update_option( 'fs_debug_mode', $_POST['is_on'] );
1235
- }
1236
-
1237
- exit;
1238
- }
1239
-
1240
- /**
1241
- * @author Vova Feldman (@svovaf)
1242
- * @since 1.0.8
1243
- */
1244
- static function _debug_page_actions() {
1245
- self::_clean_admin_content_section();
1246
-
1247
- if ( fs_request_is_action( 'restart_freemius' ) ) {
1248
- check_admin_referer( 'restart_freemius' );
1249
-
1250
- self::$_accounts->clear( true );
1251
-
1252
-
1253
- return;
1254
- }
1255
- }
1256
-
1257
- /**
1258
- * @author Vova Feldman (@svovaf)
1259
- * @since 1.0.8
1260
- */
1261
- static function _debug_page_render() {
1262
- self::$_static_logger->entrance();
1263
-
1264
- $sites = self::get_all_sites();
1265
- $users = self::get_all_users();
1266
- $addons = self::get_all_addons();
1267
- $account_addons = self::get_all_account_addons();
1268
- $licenses = self::get_all_licenses();
1269
-
1270
- // $plans = self::get_all_plans();
1271
- // $licenses = self::get_all_licenses();
1272
-
1273
- $vars = array(
1274
- 'sites' => $sites,
1275
- 'users' => $users,
1276
- 'addons' => $addons,
1277
- 'account_addons' => $account_addons,
1278
- 'licenses' => $licenses,
1279
- );
1280
-
1281
- fs_enqueue_local_style( 'fs_account', '/admin/debug.css' );
1282
- fs_require_once_template( 'debug.php', $vars );
1283
- }
1284
-
1285
- #endregion ------------------------------------------------------------------
1286
-
1287
- #region Connectivity Issues ------------------------------------------------------------------
1288
-
1289
- /**
1290
- * Check if Freemius should be turned on for the current plugin install.
1291
- *
1292
- * Note:
1293
- * $this->_is_on is updated in has_api_connectivity()
1294
- *
1295
- * @author Vova Feldman (@svovaf)
1296
- * @since 1.0.9
1297
- *
1298
- * @return bool
1299
- */
1300
- function is_on() {
1301
- self::$_static_logger->entrance();
1302
-
1303
- if ( isset( $this->_is_on ) ) {
1304
- return $this->_is_on;
1305
- }
1306
-
1307
- // If already installed or pending then sure it's on :)
1308
- if ( $this->is_registered() || $this->is_pending_activation() ) {
1309
- $this->_is_on = true;
1310
-
1311
- return true;
1312
- }
1313
-
1314
- return false;
1315
- }
1316
-
1317
- /**
1318
- * @author Vova Feldman (@svovaf)
1319
- * @since 1.1.7.3
1320
- *
1321
- * @param bool $flush_if_no_connectivity
1322
- *
1323
- * @return bool
1324
- */
1325
- private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1326
- if ( ! isset( $this->_storage->connectivity_test ) ) {
1327
- // Connectivity test was never executed, or cache was cleared.
1328
- return true;
1329
- }
1330
-
1331
- if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1332
- if ( WP_FS__IS_HTTP_REQUEST ) {
1333
- if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1334
- // Domain changed.
1335
- return true;
1336
- }
1337
-
1338
- if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1339
- // Server IP changed.
1340
- return true;
1341
- }
1342
- }
1343
- }
1344
-
1345
- if ( $this->_storage->connectivity_test['is_connected'] &&
1346
- $this->_storage->connectivity_test['is_active']
1347
- ) {
1348
- // API connected and Freemius is active - no need to run connectivity check.
1349
- return false;
1350
- }
1351
-
1352
- if ( $flush_if_no_connectivity ) {
1353
- /**
1354
- * If explicitly asked to flush when no connectivity - do it only
1355
- * if at least 10 sec passed from the last API connectivity test.
1356
- */
1357
- return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
1358
- ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
1359
- }
1360
-
1361
- /**
1362
- * @since 1.1.7 Don't check for connectivity on plugin downgrade.
1363
- */
1364
- $version = $this->get_plugin_version();
1365
- if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
1366
- // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
1367
- return true;
1368
- }
1369
-
1370
- return false;
1371
- }
1372
-
1373
- /**
1374
- * @author Vova Feldman (@svovaf)
1375
- * @since 1.1.7.4
1376
- *
1377
- * @return object|false
1378
- */
1379
- private function ping() {
1380
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
1381
- return false;
1382
- }
1383
-
1384
- $version = $this->get_plugin_version();
1385
-
1386
- $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
1387
-
1388
- return $this->get_api_plugin_scope()->ping(
1389
- $this->get_anonymous_id(),
1390
- array(
1391
- 'is_update' => json_encode( $is_update ),
1392
- 'version' => $version,
1393
- 'sdk' => $this->version,
1394
- 'is_admin' => json_encode( is_admin() ),
1395
- 'is_ajax' => json_encode( $this->is_ajax() ),
1396
- 'is_cron' => json_encode( $this->is_cron() ),
1397
- 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
1398
- )
1399
- );
1400
- }
1401
-
1402
- /**
1403
- * Check if there's any connectivity issue to Freemius API.
1404
- *
1405
- * @author Vova Feldman (@svovaf)
1406
- * @since 1.0.9
1407
- *
1408
- * @param bool $flush_if_no_connectivity
1409
- *
1410
- * @return bool
1411
- */
1412
- function has_api_connectivity( $flush_if_no_connectivity = false ) {
1413
- $this->_logger->entrance();
1414
-
1415
- if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
1416
- return $this->_has_api_connection;
1417
- }
1418
-
1419
- if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
1420
- isset( $this->_storage->connectivity_test ) &&
1421
- true === $this->_storage->connectivity_test['is_connected']
1422
- ) {
1423
- unset( $this->_storage->connectivity_test );
1424
- }
1425
-
1426
- if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
1427
- $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
1428
- /**
1429
- * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
1430
- */
1431
- $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
1432
- ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1433
-
1434
- return $this->_has_api_connection;
1435
- }
1436
-
1437
- $pong = $this->ping();
1438
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1439
-
1440
- if ( ! $is_connected ) {
1441
- // API failure.
1442
- $this->_add_connectivity_issue_message( $pong );
1443
- }
1444
-
1445
- $this->store_connectivity_info( $pong, $is_connected );
1446
-
1447
- return $this->_has_api_connection;
1448
- }
1449
-
1450
- /**
1451
- * @author Vova Feldman (@svovaf)
1452
- * @since 1.1.7.4
1453
- *
1454
- * @param object $pong
1455
- * @param bool $is_connected
1456
- */
1457
- private function store_connectivity_info( $pong, $is_connected ) {
1458
- $this->_logger->entrance();
1459
-
1460
- $version = $this->get_plugin_version();
1461
-
1462
- if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
1463
- $is_active = false;
1464
- } else {
1465
- $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
1466
- }
1467
-
1468
- $is_active = $this->apply_filters(
1469
- 'is_on',
1470
- $is_active,
1471
- $this->is_plugin_update(),
1472
- $version
1473
- );
1474
-
1475
- $this->_storage->connectivity_test = array(
1476
- 'is_connected' => $is_connected,
1477
- 'host' => $_SERVER['HTTP_HOST'],
1478
- 'server_ip' => WP_FS__REMOTE_ADDR,
1479
- 'is_active' => $is_active,
1480
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
1481
- // Last version with connectivity attempt.
1482
- 'version' => $version,
1483
- );
1484
-
1485
- $this->_has_api_connection = $is_connected;
1486
- $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1487
- }
1488
-
1489
- /**
1490
- * Force turning Freemius on.
1491
- *
1492
- * @author Vova Feldman (@svovaf)
1493
- * @since 1.1.8.1
1494
- *
1495
- * @return bool TRUE if successfully turned on.
1496
- */
1497
- private function turn_on() {
1498
- $this->_logger->entrance();
1499
-
1500
- if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
1501
- return false;
1502
- }
1503
-
1504
- $updated_connectivity = $this->_storage->connectivity_test;
1505
- $updated_connectivity['is_active'] = true;
1506
- $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
1507
- $this->_storage->connectivity_test = $updated_connectivity;
1508
-
1509
- $this->_is_on = true;
1510
-
1511
- return true;
1512
- }
1513
-
1514
- /**
1515
- * Anonymous and unique site identifier (Hash).
1516
- *
1517
- * @author Vova Feldman (@svovaf)
1518
- * @since 1.1.0
1519
- *
1520
- * @return string
1521
- */
1522
- function get_anonymous_id() {
1523
- $unique_id = self::$_accounts->get_option( 'unique_id' );
1524
-
1525
- if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
1526
- $key = get_site_url();
1527
-
1528
- // If localhost, assign microtime instead of domain.
1529
- if ( WP_FS__IS_LOCALHOST ||
1530
- false !== strpos( $key, 'localhost' ) ||
1531
- false === strpos( $key, '.' )
1532
- ) {
1533
- $key = microtime();
1534
- }
1535
-
1536
- $unique_id = md5( $key );
1537
-
1538
- self::$_accounts->set_option( 'unique_id', $unique_id, true );
1539
- }
1540
-
1541
- $this->_logger->departure( $unique_id );
1542
-
1543
- return $unique_id;
1544
- }
1545
-
1546
- /**
1547
- * @author Vova Feldman (@svovaf)
1548
- * @since 1.1.7.4
1549
- *
1550
- * @return \WP_User
1551
- */
1552
- static function _get_current_wp_user() {
1553
- self::require_pluggable_essentials();
1554
-
1555
- return wp_get_current_user();
1556
- }
1557
-
1558
- /**
1559
- * Generate API connectivity issue message.
1560
- *
1561
- * @author Vova Feldman (@svovaf)
1562
- * @since 1.0.9
1563
- *
1564
- * @param mixed $api_result
1565
- * @param bool $is_first_failure
1566
- */
1567
- function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
1568
- if ( $this->_enable_anonymous ) {
1569
- // Don't add message if can run anonymously.
1570
- return;
1571
- }
1572
-
1573
- if ( ! function_exists( 'wp_nonce_url' ) ) {
1574
- require_once( ABSPATH . 'wp-includes/functions.php' );
1575
- }
1576
-
1577
- $current_user = self::_get_current_wp_user();
1578
- // $admin_email = get_option( 'admin_email' );
1579
- $admin_email = $current_user->user_email;
1580
-
1581
- $message = false;
1582
- if ( is_object( $api_result ) &&
1583
- isset( $api_result->error ) &&
1584
- isset( $api_result->error->code )
1585
- ) {
1586
- switch ( $api_result->error->code ) {
1587
- case 'curl_missing':
1588
- $message = sprintf(
1589
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1590
- __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1591
- ' %s',
1592
- '<b>' . $this->get_plugin_name() . '</b>',
1593
- sprintf(
1594
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1595
- sprintf(
1596
- '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1597
- __fs( 'curl-missing-no-clue-title', $this->_slug ),
1598
- ' - ' . sprintf(
1599
- __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1600
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1601
- )
1602
- ),
1603
- sprintf(
1604
- '<b>%s</b> - %s',
1605
- __fs( 'sysadmin-title', $this->_slug ),
1606
- __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1607
- ),
1608
- sprintf(
1609
- '<a href="%s"><b>%s</b></a>%s',
1610
- 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 ),
1611
- __fs( 'deactivate-plugin-title', $this->_slug ),
1612
- ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1613
- )
1614
- )
1615
- );
1616
- break;
1617
- case 'cloudflare_ddos_protection':
1618
- $message = sprintf(
1619
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1620
- __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1621
- __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1622
- ' %s',
1623
- '<b>' . $this->get_plugin_name() . '</b>',
1624
- sprintf(
1625
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1626
- sprintf(
1627
- '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1628
- __fs( 'fix-issue-title', $this->_slug ),
1629
- ' - ' . sprintf(
1630
- __fs( 'fix-issue-desc', $this->_slug ),
1631
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1632
- )
1633
- ),
1634
- sprintf(
1635
- '<a href="%s" target="_blank"><b>%s</b></a>%s',
1636
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1637
- __fs( 'install-previous-title', $this->_slug ),
1638
- ' - ' . __fs( 'install-previous-desc', $this->_slug )
1639
- ),
1640
- sprintf(
1641
- '<a href="%s"><b>%s</b></a>%s',
1642
- 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 ),
1643
- __fs( 'deactivate-plugin-title', $this->_slug ),
1644
- ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1645
- )
1646
- )
1647
- );
1648
- break;
1649
- case 'squid_cache_block':
1650
- $message = sprintf(
1651
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1652
- __fs( 'squid-blocks-connection-message', $this->_slug ) .
1653
- ' %s',
1654
- '<b>' . $this->get_plugin_name() . '</b>',
1655
- sprintf(
1656
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1657
- sprintf(
1658
- '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1659
- __fs( 'squid-no-clue-title', $this->_slug ),
1660
- ' - ' . sprintf(
1661
- __fs( 'squid-no-clue-desc', $this->_slug ),
1662
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1663
- )
1664
- ),
1665
- sprintf(
1666
- '<b>%s</b> - %s',
1667
- __fs( 'sysadmin-title', $this->_slug ),
1668
- sprintf(
1669
- __fs( 'squid-sysadmin-desc', $this->_slug ),
1670
- // We use a filter since the plugin might require additional API connectivity.
1671
- '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1672
- ),
1673
- sprintf(
1674
- '<a href="%s"><b>%s</b></a>%s',
1675
- 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 ),
1676
- __fs( 'deactivate-plugin-title', $this->_slug ),
1677
- ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1678
- )
1679
- )
1680
- );
1681
- break;
1682
- // default:
1683
- // $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1684
- // break;
1685
- }
1686
- }
1687
-
1688
- $message_id = 'failed_connect_api';
1689
- $type = 'error';
1690
-
1691
- if ( false === $message ) {
1692
- if ( $is_first_failure ) {
1693
- // First attempt failed.
1694
- $message = sprintf(
1695
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1696
- __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1697
- __fs( 'connectivity-test-maybe-temporary', $this->_slug ) . '<br><br>' .
1698
- '%s',
1699
- '<b>' . $this->get_plugin_name() . '</b>',
1700
- sprintf(
1701
- '<div id="fs_firewall_issue_options">%s %s</div>',
1702
- sprintf(
1703
- '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
1704
- __fs( 'yes-do-your-thing', $this->_slug )
1705
- ),
1706
- sprintf(
1707
- '<a href="%s" class="button">%s</a>',
1708
- 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 ),
1709
- __fs( 'no-deactivate', $this->_slug )
1710
- )
1711
- )
1712
- );
1713
-
1714
- $message_id = 'failed_connect_api_first';
1715
- $type = 'promotion';
1716
- } else {
1717
- // Second connectivity attempt failed.
1718
- $message = sprintf(
1719
- __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1720
- __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1721
- __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1722
- ' %s',
1723
- '<b>' . $this->get_plugin_name() . '</b>',
1724
- sprintf(
1725
- '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1726
- sprintf(
1727
- '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1728
- __fs( 'fix-issue-title', $this->_slug ),
1729
- ' - ' . sprintf(
1730
- __fs( 'fix-issue-desc', $this->_slug ),
1731
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1732
- )
1733
- ),
1734
- sprintf(
1735
- '<a href="%s" target="_blank"><b>%s</b></a>%s',
1736
- sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1737
- __fs( 'install-previous-title', $this->_slug ),
1738
- ' - ' . __fs( 'install-previous-desc', $this->_slug )
1739
- ),
1740
- sprintf(
1741
- '<a href="%s"><b>%s</b></a>%s',
1742
- 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 ),
1743
- __fs( 'deactivate-plugin-title', $this->_slug ),
1744
- ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1745
- )
1746
- )
1747
- );
1748
- }
1749
- }
1750
-
1751
- $this->_admin_notices->add_sticky(
1752
- $message,
1753
- $message_id,
1754
- __fs( 'oops', $this->_slug ) . '...',
1755
- $type
1756
- );
1757
- }
1758
-
1759
- /**
1760
- * Handle user request to resolve connectivity issue.
1761
- * This method will send an email to Freemius API technical staff for resolution.
1762
- * The email will contain server's info and installed plugins (might be caching issue).
1763
- *
1764
- * @author Vova Feldman (@svovaf)
1765
- * @since 1.0.9
1766
- */
1767
- function _email_about_firewall_issue() {
1768
- $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1769
-
1770
- $pong = $this->ping();
1771
-
1772
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1773
-
1774
- if ( $is_connected ) {
1775
- $this->store_connectivity_info( $pong, $is_connected );
1776
-
1777
- echo $this->get_after_plugin_activation_redirect_url();
1778
- exit;
1779
- }
1780
-
1781
- $current_user = self::_get_current_wp_user();
1782
- $admin_email = $current_user->user_email;
1783
-
1784
- $error_type = fs_request_get( 'error_type', 'general' );
1785
-
1786
- switch ( $error_type ) {
1787
- case 'squid':
1788
- $title = 'Squid ACL Blocking Issue';
1789
- break;
1790
- case 'cloudflare':
1791
- $title = 'CloudFlare Blocking Issue';
1792
- break;
1793
- default:
1794
- $title = 'API Connectivity Issue';
1795
- break;
1796
- }
1797
-
1798
- $custom_email_sections = array();
1799
-
1800
- if ( 'squid' === $error_type ) {
1801
- // Override the 'Site' email section.
1802
- $custom_email_sections['site'] = array(
1803
- 'rows' => array(
1804
- 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1805
- )
1806
- );
1807
- }
1808
-
1809
- // Add 'API Error' custom email section.
1810
- $custom_email_sections['api_error'] = array(
1811
- 'title' => 'API Error',
1812
- 'rows' => array(
1813
- 'ping' => array( is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong ) )
1814
- )
1815
- );
1816
-
1817
- // Add PHP info for deeper investigation.
1818
- ob_start();
1819
- phpinfo();
1820
- $php_info = ob_get_clean();
1821
- $custom_email_sections['php_info'] = array(
1822
- 'title' => 'PHP Info',
1823
- 'rows' => array(
1824
- 'info' => array( $php_info )
1825
- )
1826
- );
1827
-
1828
- // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1829
- $this->send_email(
1830
- 'api@freemius.com', // recipient
1831
- $title . ' [' . $this->get_plugin_name() . ']', // subject
1832
- $custom_email_sections,
1833
- array( "Reply-To: $admin_email <$admin_email>" ) // headers
1834
- );
1835
-
1836
- $this->_admin_notices->add_sticky(
1837
- sprintf(
1838
- __fs( 'fix-request-sent-message', $this->_slug ),
1839
- '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1840
- ),
1841
- 'server_details_sent'
1842
- );
1843
-
1844
- // Action was taken, tell that API connectivity troubleshooting should be off now.
1845
-
1846
- echo "1";
1847
- exit;
1848
- }
1849
-
1850
- /**
1851
- * Handle connectivity test retry approved by the user.
1852
- *
1853
- * @author Vova Feldman (@svovaf)
1854
- * @since 1.1.7.4
1855
- */
1856
- function _retry_connectivity_test() {
1857
- $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
1858
-
1859
- $pong = $this->ping();
1860
-
1861
- $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1862
-
1863
- if ( $is_connected ) {
1864
- $this->store_connectivity_info( $pong, $is_connected );
1865
-
1866
- echo $this->get_after_plugin_activation_redirect_url();
1867
- } else {
1868
- // Add connectivity issue message after 2nd failed attempt.
1869
- $this->_add_connectivity_issue_message( $pong, false );
1870
-
1871
- echo "1";
1872
- }
1873
-
1874
- exit;
1875
- }
1876
-
1877
- static function _add_firewall_issues_javascript() {
1878
- $params = array();
1879
- fs_require_once_template( 'firewall-issues-js.php', $params );
1880
- }
1881
-
1882
- #endregion Connectivity Issues ------------------------------------------------------------------
1883
-
1884
- #region Email ------------------------------------------------------------------
1885
-
1886
- /**
1887
- * Generates and sends an HTML email with customizable sections.
1888
- *
1889
- * @author Leo Fajardo (@leorw)
1890
- * @since 1.1.2
1891
- *
1892
- * @param string $to_address
1893
- * @param string $subject
1894
- * @param array $sections
1895
- * @param array $headers
1896
- *
1897
- * @return bool Whether the email contents were sent successfully.
1898
- */
1899
- private function send_email(
1900
- $to_address,
1901
- $subject,
1902
- $sections = array(),
1903
- $headers = array()
1904
- ) {
1905
- $default_sections = $this->get_email_sections();
1906
-
1907
- // Insert new sections or replace the default email sections.
1908
- if ( is_array( $sections ) && ! empty( $sections ) ) {
1909
- foreach ( $sections as $section_id => $custom_section ) {
1910
- if ( ! isset( $default_sections[ $section_id ] ) ) {
1911
- // If the section does not exist, add it.
1912
- $default_sections[ $section_id ] = $custom_section;
1913
- } else {
1914
- // If the section already exists, override it.
1915
- $current_section = $default_sections[ $section_id ];
1916
-
1917
- // Replace the current section's title if a custom section title exists.
1918
- if ( isset( $custom_section['title'] ) ) {
1919
- $current_section['title'] = $custom_section['title'];
1920
- }
1921
-
1922
- // Insert new rows under the current section or replace the default rows.
1923
- if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1924
- foreach ( $custom_section['rows'] as $row_id => $row ) {
1925
- $current_section['rows'][ $row_id ] = $row;
1926
- }
1927
- }
1928
-
1929
- $default_sections[ $section_id ] = $current_section;
1930
- }
1931
- }
1932
- }
1933
-
1934
- $vars = array( 'sections' => $default_sections );
1935
- $message = fs_get_template( 'email.php', $vars );
1936
-
1937
- // Set the type of email to HTML.
1938
- $headers[] = 'Content-type: text/html';
1939
-
1940
- $header_string = implode( "\r\n", $headers );
1941
-
1942
- return wp_mail(
1943
- $to_address,
1944
- $subject,
1945
- $message,
1946
- $header_string
1947
- );
1948
- }
1949
-
1950
- /**
1951
- * Generates the data for the sections of the email content.
1952
- *
1953
- * @author Leo Fajardo (@leorw)
1954
- * @since 1.1.2
1955
- *
1956
- * @return array
1957
- */
1958
- private function get_email_sections() {
1959
- // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
1960
- $current_user = self::_get_current_wp_user();
1961
-
1962
- // Retrieve the cURL version information so that we can get the version number below.
1963
- $curl_version_information = curl_version();
1964
-
1965
- $active_plugin = self::get_active_plugins();
1966
-
1967
- // Generate the list of active plugins separated by new line.
1968
- $active_plugin_string = '';
1969
- foreach ( $active_plugin as $plugin ) {
1970
- $active_plugin_string .= sprintf(
1971
- '<a href="%s">%s</a> [v%s]<br>',
1972
- $plugin['PluginURI'],
1973
- $plugin['Name'],
1974
- $plugin['Version']
1975
- );
1976
- }
1977
-
1978
- $server_ip = WP_FS__REMOTE_ADDR;
1979
-
1980
- // Generate the default email sections.
1981
- $sections = array(
1982
- 'sdk' => array(
1983
- 'title' => 'SDK',
1984
- 'rows' => array(
1985
- 'fs_version' => array( 'FS Version', $this->version ),
1986
- 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
1987
- )
1988
- ),
1989
- 'plugin' => array(
1990
- 'title' => 'Plugin',
1991
- 'rows' => array(
1992
- 'name' => array( 'Name', $this->get_plugin_name() ),
1993
- 'version' => array( 'Version', $this->get_plugin_version() )
1994
- )
1995
- ),
1996
- 'site' => array(
1997
- 'title' => 'Site',
1998
- 'rows' => array(
1999
- 'unique_id' => array( 'Address', $this->get_anonymous_id() ),
2000
- 'address' => array( 'Address', site_url() ),
2001
- 'host' => array(
2002
- 'HTTP_HOST',
2003
- ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
2004
- ),
2005
- 'server_addr' => array(
2006
- 'SERVER_ADDR',
2007
- '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
2008
- )
2009
- )
2010
- ),
2011
- 'user' => array(
2012
- 'title' => 'User',
2013
- 'rows' => array(
2014
- 'email' => array( 'Email', $current_user->user_email ),
2015
- 'first' => array( 'First', $current_user->user_firstname ),
2016
- 'last' => array( 'Last', $current_user->user_lastname )
2017
- )
2018
- ),
2019
- 'plugins' => array(
2020
- 'title' => 'Plugins',
2021
- 'rows' => array(
2022
- 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
2023
- )
2024
- ),
2025
- );
2026
-
2027
- // Allow the sections to be modified by other code.
2028
- $sections = $this->apply_filters( 'email_template_sections', $sections );
2029
-
2030
- return $sections;
2031
- }
2032
-
2033
- #endregion Email ------------------------------------------------------------------
2034
-
2035
- #region Initialization ------------------------------------------------------------------
2036
-
2037
- /**
2038
- * Init plugin's Freemius instance.
2039
- *
2040
- * @author Vova Feldman (@svovaf)
2041
- * @since 1.0.1
2042
- *
2043
- * @param number $id
2044
- * @param string $public_key
2045
- * @param bool $is_live
2046
- * @param bool $is_premium
2047
- */
2048
- function init( $id, $public_key, $is_live = true, $is_premium = true ) {
2049
- $this->_logger->entrance();
2050
-
2051
- $this->dynamic_init( array(
2052
- 'id' => $id,
2053
- 'public_key' => $public_key,
2054
- 'is_live' => $is_live,
2055
- 'is_premium' => $is_premium,
2056
- ) );
2057
- }
2058
-
2059
- /**
2060
- * Dynamic initiator, originally created to support initiation
2061
- * with parent_id for add-ons.
2062
- *
2063
- * @author Vova Feldman (@svovaf)
2064
- * @since 1.0.6
2065
- *
2066
- * @param array $plugin_info
2067
- *
2068
- * @throws Freemius_Exception
2069
- */
2070
- function dynamic_init( array $plugin_info ) {
2071
- $this->_logger->entrance();
2072
-
2073
- $this->parse_settings( $plugin_info );
2074
-
2075
- if ( $this->should_stop_execution() ) {
2076
- return;
2077
- }
2078
-
2079
- if ( ! $this->is_registered() ) {
2080
- if ( $this->is_anonymous() ) {
2081
- // If user skipped, no need to test connectivity.
2082
- $this->_has_api_connection = true;
2083
- $this->_is_on = true;
2084
- } else {
2085
- if ( ! $this->has_api_connectivity() ) {
2086
- if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
2087
- $this->_admin_notices->has_sticky( 'failed_connect_api' )
2088
- ) {
2089
- if ( ! $this->_enable_anonymous ) {
2090
- // If anonymous mode is disabled, add firewall admin-notice message.
2091
- add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
2092
-
2093
- $this->add_ajax_action( 'resolve_firewall_issues', array(
2094
- &$this,
2095
- '_email_about_firewall_issue'
2096
- ) );
2097
-
2098
- $this->add_ajax_action( 'retry_connectivity_test', array(
2099
- &$this,
2100
- '_retry_connectivity_test'
2101
- ) );
2102
- }
2103
- }
2104
-
2105
- return;
2106
- } else {
2107
- $this->_admin_notices->remove_sticky( array(
2108
- 'failed_connect_api_first',
2109
- 'failed_connect_api',
2110
- ) );
2111
-
2112
- if ( $this->_anonymous_mode ) {
2113
- // Simulate anonymous mode.
2114
- $this->_is_anonymous = true;
2115
- }
2116
- }
2117
- }
2118
-
2119
- // Check if Freemius is on for the current plugin.
2120
- // This MUST be executed after all the plugin variables has been loaded.
2121
- if ( ! $this->is_on() ) {
2122
- return;
2123
- }
2124
- }
2125
-
2126
- if ( $this->has_api_connectivity() ) {
2127
- if ( $this->is_cron() ) {
2128
- $this->hook_callback_to_sync_cron();
2129
- } else if ( $this->is_user_in_admin() ) {
2130
- /**
2131
- * Schedule daily data sync cron if:
2132
- *
2133
- * 1. User opted-in (for tracking).
2134
- * 2. If skipped, but later upgraded (opted-in via upgrade).
2135
- *
2136
- * @author Vova Feldman (@svovaf)
2137
- * @since 1.1.7.3
2138
- *
2139
- */
2140
- if ( $this->is_registered() ) {
2141
- if ( ! $this->is_sync_cron_on() ) {
2142
- $this->schedule_sync_cron();
2143
- }
2144
- }
2145
-
2146
- /**
2147
- * Check if requested for manual blocking background sync.
2148
- */
2149
- if ( fs_request_has( 'background_sync' ) ) {
2150
- $this->run_manual_sync();
2151
- }
2152
- }
2153
- }
2154
-
2155
- if ( $this->is_registered() ) {
2156
- $this->hook_callback_to_install_sync();
2157
- }
2158
-
2159
- if ( $this->is_addon() ) {
2160
- if ( $this->is_parent_plugin_installed() ) {
2161
- // Link to parent FS.
2162
- $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2163
-
2164
- // Get parent plugin reference.
2165
- $this->_parent_plugin = $this->_parent->get_plugin();
2166
- }
2167
- }
2168
-
2169
- if ( $this->is_user_in_admin() ) {
2170
- global $pagenow;
2171
- if ( 'plugins.php' === $pagenow ) {
2172
- $this->hook_plugin_action_links();
2173
- }
2174
-
2175
- if ( $this->is_addon() ) {
2176
- if ( ! $this->is_parent_plugin_installed() ) {
2177
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2178
-
2179
- if ( isset( $plugin_info['parent'] ) ) {
2180
- $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2181
- }
2182
-
2183
- $this->_admin_notices->add(
2184
- ( ! empty( $parent_name ) ?
2185
- sprintf( __fs( 'addon-x-cannot-run-without-y', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
2186
- sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
2187
- ),
2188
- __fs( 'oops', $this->_slug ) . '...',
2189
- 'error'
2190
- );
2191
-
2192
- return;
2193
- } else {
2194
- if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
2195
- // If parent plugin activated, automatically install add-on for the user.
2196
- $this->_activate_addon_account( $this->_parent );
2197
- }
2198
-
2199
- // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
2200
- if ( $this->is_premium() ) {
2201
- // Remove add-on download admin-notice.
2202
- $this->_parent->_admin_notices->remove_sticky( array(
2203
- 'addon_plan_upgraded_' . $this->_slug,
2204
- 'no_addon_license_' . $this->_slug,
2205
- ) );
2206
- }
2207
-
2208
- $this->deactivate_premium_only_addon_without_license();
2209
- }
2210
- } else {
2211
- add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
2212
-
2213
- if ( $this->has_addons() &&
2214
- 'plugin-information' === fs_request_get( 'tab', false ) &&
2215
- $this->get_id() == fs_request_get( 'parent_plugin_id', false )
2216
- ) {
2217
- require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
2218
-
2219
- new FS_Plugin_Info_Dialog( $this );
2220
- }
2221
- }
2222
-
2223
- if ( $this->is_premium() ) {
2224
- new FS_Plugin_Updater( $this );
2225
- }
2226
-
2227
- // if ( $this->is_registered() ||
2228
- // $this->is_anonymous() ||
2229
- // $this->is_pending_activation()
2230
- // ) {
2231
- // $this->_init_admin();
2232
- // }
2233
- }
2234
-
2235
- $this->do_action( 'initiated' );
2236
-
2237
- if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
2238
- if ( isset( $this->_storage->prev_is_premium ) ) {
2239
- $this->apply_filters(
2240
- 'after_code_type_change',
2241
- // New code type.
2242
- $this->_plugin->is_premium
2243
- );
2244
- } else {
2245
- // Set for code type for the first time.
2246
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2247
- }
2248
- }
2249
-
2250
- if ( ! $this->is_addon() ) {
2251
- if ( $this->is_registered() ) {
2252
- // Fix for upgrade from versions < 1.0.9.
2253
- if ( ! isset( $this->_storage->activation_timestamp ) ) {
2254
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
2255
- }
2256
-
2257
- $this->do_action( 'after_init_plugin_registered' );
2258
- } else if ( $this->is_anonymous() ) {
2259
- $this->do_action( 'after_init_plugin_anonymous' );
2260
- } else if ( $this->is_pending_activation() ) {
2261
- $this->do_action( 'after_init_plugin_pending_activations' );
2262
- }
2263
- } else {
2264
- if ( $this->is_registered() ) {
2265
- $this->do_action( 'after_init_addon_registered' );
2266
- } else if ( $this->is_anonymous() ) {
2267
- $this->do_action( 'after_init_addon_anonymous' );
2268
- } else if ( $this->is_pending_activation() ) {
2269
- $this->do_action( 'after_init_addon_pending_activations' );
2270
- }
2271
- }
2272
-
2273
- // Add license activation link and AJAX request handler.
2274
- if ( $this->has_paid_plan() ) {
2275
- global $pagenow;
2276
- if ( 'plugins.php' === $pagenow ) {
2277
- /**
2278
- * @since 1.2.0 Add license action link only on plugins page.
2279
- */
2280
- $this->_add_license_action_link();
2281
- $this->_require_license_activation_dialog();
2282
- }
2283
-
2284
- if ( $this->is_ajax_action( array(
2285
- 'activate_license',
2286
- 'resend_license_key'
2287
- ) )
2288
- ) {
2289
- // Hook license activation and resend AJAX callbacks.
2290
- $this->_require_license_activation_dialog();
2291
- }
2292
- }
2293
- }
2294
-
2295
- /**
2296
- * Parse plugin's settings (as defined by the plugin dev).
2297
- *
2298
- * @author Vova Feldman (@svovaf)
2299
- * @since 1.1.7.3
2300
- *
2301
- * @param array $plugin_info
2302
- *
2303
- * @throws \Freemius_Exception
2304
- */
2305
- private function parse_settings( &$plugin_info ) {
2306
- $this->_logger->entrance();
2307
-
2308
- $id = $this->get_numeric_option( $plugin_info, 'id', false );
2309
- $public_key = $this->get_option( $plugin_info, 'public_key', false );
2310
- $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
2311
- $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
2312
- $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2313
-
2314
- /**
2315
- * @author Vova Feldman (@svovaf)
2316
- * @since 1.1.9 Try to pull secret key from external config.
2317
- */
2318
- if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
2319
- $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
2320
- }
2321
-
2322
- if ( isset( $plugin_info['parent'] ) ) {
2323
- $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
2324
- // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
2325
- // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
2326
- $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2327
- }
2328
-
2329
- if ( false === $id ) {
2330
- throw new Freemius_Exception( 'Plugin id parameter is not set.' );
2331
- }
2332
- if ( false === $public_key ) {
2333
- throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
2334
- }
2335
-
2336
- $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
2337
- $this->_plugin :
2338
- new FS_Plugin();
2339
-
2340
- $plugin->update( array(
2341
- 'id' => $id,
2342
- 'public_key' => $public_key,
2343
- 'slug' => $this->_slug,
2344
- 'parent_plugin_id' => $parent_id,
2345
- 'version' => $this->get_plugin_version(),
2346
- 'title' => $this->get_plugin_name(),
2347
- 'file' => $this->_plugin_basename,
2348
- 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
2349
- 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
2350
- // 'secret_key' => $secret_key,
2351
- ) );
2352
-
2353
- if ( $plugin->is_updated() ) {
2354
- // Update plugin details.
2355
- $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
2356
- }
2357
- // Set the secret key after storing the plugin, we don't want to store the key in the storage.
2358
- $this->_plugin->secret_key = $secret_key;
2359
-
2360
- if ( ! isset( $plugin_info['menu'] ) ) {
2361
- // Back compatibility to 1.1.2
2362
- $plugin_info['menu'] = array(
2363
- 'slug' => isset( $plugin_info['menu_slug'] ) ?
2364
- $plugin_info['menu_slug'] :
2365
- $this->_slug
2366
- );
2367
- }
2368
-
2369
- $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
2370
- $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
2371
-
2372
- $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
2373
- $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
2374
- $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
2375
- $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
2376
- if ( $this->_is_premium_only ) {
2377
- // If premium only plugin, disable anonymous mode.
2378
- $this->_enable_anonymous = false;
2379
- $this->_anonymous_mode = false;
2380
- } else {
2381
- $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
2382
- $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
2383
- }
2384
- $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
2385
- }
2386
-
2387
- /**
2388
- * @param string[] $options
2389
- * @param string $key
2390
- * @param mixed $default
2391
- *
2392
- * @return bool
2393
- */
2394
- private function get_option( &$options, $key, $default = false ) {
2395
- return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
2396
- }
2397
-
2398
- private function get_bool_option( &$options, $key, $default = false ) {
2399
- return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
2400
- }
2401
-
2402
- private function get_numeric_option( &$options, $key, $default = false ) {
2403
- return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
2404
- }
2405
-
2406
- /**
2407
- * Gate keeper.
2408
- *
2409
- * @author Vova Feldman (@svovaf)
2410
- * @since 1.1.7.3
2411
- *
2412
- * @return bool
2413
- */
2414
- private function should_stop_execution() {
2415
- if ( empty( $this->_storage->was_plugin_loaded ) ) {
2416
- /**
2417
- * Don't execute Freemius until plugin was fully loaded at least once,
2418
- * to give the opportunity for the activation hook to run before pinging
2419
- * the API for connectivity test. This logic is relevant for the
2420
- * identification of new plugin install vs. plugin update.
2421
- *
2422
- * @author Vova Feldman (@svovaf)
2423
- * @since 1.1.9
2424
- */
2425
- return true;
2426
- }
2427
-
2428
- if ( $this->is_activation_mode() ) {
2429
- if ( ! is_admin() ) {
2430
- /**
2431
- * If in activation mode, don't execute Freemius outside of the
2432
- * admin dashboard.
2433
- *
2434
- * @author Vova Feldman (@svovaf)
2435
- * @since 1.1.7.3
2436
- */
2437
- return true;
2438
- }
2439
-
2440
- if ( ! WP_FS__IS_HTTP_REQUEST ) {
2441
- /**
2442
- * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
2443
- * then don't start Freemius.
2444
- *
2445
- * @author Vova Feldman (@svovaf)
2446
- * @since 1.1.6.3
2447
- *
2448
- * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
2449
- */
2450
- return true;
2451
- }
2452
-
2453
- if ( $this->is_cron() ) {
2454
- /**
2455
- * If in activation mode, don't execute Freemius during wp crons
2456
- * (wp crons have HTTP context - called as HTTP request).
2457
- *
2458
- * @author Vova Feldman (@svovaf)
2459
- * @since 1.1.7.3
2460
- */
2461
- return true;
2462
- }
2463
-
2464
- if ( $this->is_ajax() &&
2465
- ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
2466
- ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
2467
- ) {
2468
- /**
2469
- * During activation, if running in AJAX mode, unless there's a sticky
2470
- * connectivity issue notice, don't run Freemius.
2471
- *
2472
- * @author Vova Feldman (@svovaf)
2473
- * @since 1.1.7.3
2474
- */
2475
- return true;
2476
- }
2477
- }
2478
-
2479
- return false;
2480
- }
2481
-
2482
- /**
2483
- * Triggered after code type has changed.
2484
- *
2485
- * @author Vova Feldman (@svovaf)
2486
- * @since 1.1.9.1
2487
- */
2488
- function _after_code_type_change() {
2489
- $this->_logger->entrance();
2490
-
2491
- add_action( is_admin() ? 'admin_init' : 'init', array(
2492
- &$this,
2493
- '_plugin_code_type_changed'
2494
- ) );
2495
- }
2496
-
2497
- /**
2498
- * Handles plugin's code type change (free <--> premium).
2499
- *
2500
- * @author Vova Feldman (@svovaf)
2501
- * @since 1.0.9
2502
- */
2503
- function _plugin_code_type_changed() {
2504
- $this->_logger->entrance();
2505
-
2506
- // Schedule code type changes event.
2507
- // $this->sync_install();
2508
- $this->schedule_install_sync();
2509
-
2510
- if ( $this->is_premium() ) {
2511
- // Activated premium code.
2512
- $this->do_action( 'after_premium_version_activation' );
2513
-
2514
- // Remove all sticky messages related to download of the premium version.
2515
- $this->_admin_notices->remove_sticky( array(
2516
- 'trial_started',
2517
- 'plan_upgraded',
2518
- 'plan_changed',
2519
- ) );
2520
-
2521
- $this->_admin_notices->add_sticky(
2522
- __fs( 'premium-activated-message', $this->_slug ),
2523
- 'premium_activated',
2524
- __fs( 'woot', $this->_slug ) . '!'
2525
- );
2526
- } else {
2527
- // Remove sticky message related to premium code activation.
2528
- $this->_admin_notices->remove_sticky( 'premium_activated' );
2529
-
2530
- // Activated free code (after had the premium before).
2531
- $this->do_action( 'after_free_version_reactivation' );
2532
-
2533
- if ( $this->is_paying() && ! $this->is_premium() ) {
2534
- $this->_admin_notices->add_sticky(
2535
- sprintf(
2536
- __fs( 'you-have-x-license', $this->_slug ),
2537
- $this->_site->plan->title
2538
- ) . $this->get_complete_upgrade_instructions(),
2539
- 'plan_upgraded',
2540
- __fs( 'yee-haw', $this->_slug ) . '!'
2541
- );
2542
- }
2543
- }
2544
-
2545
- /**
2546
- * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
2547
- * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
2548
- * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
2549
- * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
2550
- * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
2551
- * free and premium versions are almost identical (same class or have same functions), a fatal error like
2552
- * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
2553
- */
2554
- $this->unregister_uninstall_hook();
2555
-
2556
- $this->clear_module_main_file_cache();
2557
-
2558
- // Update is_premium of latest version.
2559
- $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2560
- }
2561
-
2562
- #endregion Initialization ------------------------------------------------------------------
2563
-
2564
- #region Add-ons -------------------------------------------------------------------------
2565
-
2566
- /**
2567
- * Check if add-on installed and activated on site.
2568
- *
2569
- * @author Vova Feldman (@svovaf)
2570
- * @since 1.0.6
2571
- *
2572
- * @param string|number $slug_or_id
2573
- *
2574
- * @return bool
2575
- */
2576
- function is_addon_activated( $slug_or_id ) {
2577
- return self::has_instance( $slug_or_id );
2578
- }
2579
-
2580
- /**
2581
- * Check if add-on was connected to install
2582
- *
2583
- * @author Vova Feldman (@svovaf)
2584
- * @since 1.1.7
2585
- *
2586
- * @param string $slug
2587
- *
2588
- * @return bool
2589
- */
2590
- function is_addon_connected( $slug ) {
2591
- $sites = self::get_all_sites();
2592
-
2593
- if ( ! isset( $sites[ $slug ] ) ) {
2594
- return false;
2595
- }
2596
-
2597
- $site = $sites[ $slug ];
2598
-
2599
- $plugin = FS_Plugin_Manager::instance( $slug )->get();
2600
-
2601
- if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
2602
- // The given slug do NOT belong to any of the plugin's add-ons.
2603
- return false;
2604
- }
2605
-
2606
- return ( is_object( $site ) &&
2607
- is_numeric( $site->id ) &&
2608
- is_numeric( $site->user_id ) &&
2609
- is_object( $site->plan )
2610
- );
2611
- }
2612
-
2613
- /**
2614
- * Determines if add-on installed.
2615
- *
2616
- * NOTE: This is a heuristic and only works if the folder/file named as the slug.
2617
- *
2618
- * @author Vova Feldman (@svovaf)
2619
- * @since 1.0.6
2620
- *
2621
- * @param string $slug
2622
- *
2623
- * @return bool
2624
- */
2625
- function is_addon_installed( $slug ) {
2626
- return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
2627
- }
2628
-
2629
- /**
2630
- * Get add-on basename.
2631
- *
2632
- * @author Vova Feldman (@svovaf)
2633
- * @since 1.0.6
2634
- *
2635
- * @param string $slug
2636
- *
2637
- * @return string
2638
- */
2639
- function get_addon_basename( $slug ) {
2640
- if ( $this->is_addon_activated( $slug ) ) {
2641
- self::instance( $slug )->get_plugin_basename();
2642
- }
2643
-
2644
- $premium_basename = $slug . '-premium/' . $slug . '.php';
2645
-
2646
- if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
2647
- return $premium_basename;
2648
- }
2649
-
2650
- $free_basename = $slug . '/' . $slug . '.php';
2651
-
2652
- return $free_basename;
2653
- }
2654
-
2655
- /**
2656
- * Get installed add-ons instances.
2657
- *
2658
- * @author Vova Feldman (@svovaf)
2659
- * @since 1.0.6
2660
- *
2661
- * @return Freemius[]
2662
- */
2663
- function get_installed_addons() {
2664
- $installed_addons = array();
2665
- foreach ( self::$_instances as $slug => $instance ) {
2666
- if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2667
- if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2668
- $installed_addons[] = $instance;
2669
- }
2670
- }
2671
- }
2672
-
2673
- return $installed_addons;
2674
- }
2675
-
2676
- /**
2677
- * Check if any add-ons of the plugin are installed.
2678
- *
2679
- * @author Leo Fajardo (@leorw)
2680
- * @since 1.1.1
2681
- *
2682
- * @return bool
2683
- */
2684
- function has_installed_addons() {
2685
- if ( ! $this->has_addons() ) {
2686
- return false;
2687
- }
2688
-
2689
- foreach ( self::$_instances as $slug => $instance ) {
2690
- if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2691
- if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2692
- return true;
2693
- }
2694
- }
2695
- }
2696
-
2697
- return false;
2698
- }
2699
-
2700
- /**
2701
- * Tell Freemius that the current plugin is an add-on.
2702
- *
2703
- * @author Vova Feldman (@svovaf)
2704
- * @since 1.0.6
2705
- *
2706
- * @param number $parent_plugin_id The parent plugin ID
2707
- */
2708
- function init_addon( $parent_plugin_id ) {
2709
- $this->_plugin->parent_plugin_id = $parent_plugin_id;
2710
- }
2711
-
2712
- /**
2713
- * @author Vova Feldman (@svovaf)
2714
- * @since 1.0.6
2715
- *
2716
- * @return bool
2717
- */
2718
- function is_addon() {
2719
- return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2720
- }
2721
-
2722
- /**
2723
- * Deactivate add-on if it's premium only and the user does't have a valid license.
2724
- *
2725
- * @param bool $is_after_trial_cancel
2726
- *
2727
- * @return bool If add-on was deactivated.
2728
- */
2729
- private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
2730
- if ( ! $this->has_free_plan() &&
2731
- ! $this->has_features_enabled_license() &&
2732
- ! $this->_has_premium_license()
2733
- ) {
2734
- // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
2735
- // if (empty($this->_storage->activation_timestamp) ||
2736
- // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
2737
- // ) {
2738
- /**
2739
- * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
2740
- *
2741
- * Retry syncing the user add-on licenses.
2742
- */
2743
- // Sync licenses.
2744
- $this->_sync_licenses();
2745
- // }
2746
-
2747
- // Try to activate premium license.
2748
- $this->_activate_license( true );
2749
-
2750
- if ( ! $this->has_free_plan() &&
2751
- ! $this->has_features_enabled_license() &&
2752
- ! $this->_has_premium_license()
2753
- ) {
2754
- // @todo Check if deactivate plugins also call the deactivation hook.
2755
-
2756
- deactivate_plugins( array( $this->_plugin_basename ), true );
2757
-
2758
- $this->_parent->_admin_notices->add_sticky(
2759
- sprintf(
2760
- __fs( ( $is_after_trial_cancel ?
2761
- 'addon-trial-cancelled-message' :
2762
- 'addon-no-license-message' ),
2763
- $this->_parent->_slug
2764
- ),
2765
- '<b>' . $this->_plugin->title . '</b>'
2766
- ) . ' ' . sprintf(
2767
- '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
2768
- $this->_parent->addon_url( $this->_slug ),
2769
- esc_attr( sprintf( __fs( 'more-information-about-x', $this->_parent->_slug ), $this->_plugin->title ) ),
2770
- __fs( 'purchase-license', $this->_parent->_slug )
2771
- ),
2772
- 'no_addon_license_' . $this->_slug,
2773
- ( $is_after_trial_cancel ? '' : __fs( 'oops', $this->_parent->_slug ) . '...' ),
2774
- ( $is_after_trial_cancel ? 'success' : 'error' )
2775
- );
2776
-
2777
- return true;
2778
- }
2779
- }
2780
-
2781
- return false;
2782
- }
2783
-
2784
- #endregion ------------------------------------------------------------------
2785
-
2786
- #region Sandbox ------------------------------------------------------------------
2787
-
2788
- /**
2789
- * Set Freemius into sandbox mode for debugging.
2790
- *
2791
- * @author Vova Feldman (@svovaf)
2792
- * @since 1.0.4
2793
- *
2794
- * @param string $secret_key
2795
- */
2796
- function init_sandbox( $secret_key ) {
2797
- $this->_plugin->secret_key = $secret_key;
2798
-
2799
- // Update plugin details.
2800
- FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
2801
- }
2802
-
2803
- /**
2804
- * Check if running payments in sandbox mode.
2805
- *
2806
- * @author Vova Feldman (@svovaf)
2807
- * @since 1.0.4
2808
- *
2809
- * @return bool
2810
- */
2811
- function is_payments_sandbox() {
2812
- return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
2813
- }
2814
-
2815
- #endregion Sandbox ------------------------------------------------------------------
2816
-
2817
- /**
2818
- * Check if running test vs. live plugin.
2819
- *
2820
- * @author Vova Feldman (@svovaf)
2821
- * @since 1.0.5
2822
- *
2823
- * @return bool
2824
- */
2825
- function is_live() {
2826
- return $this->_plugin->is_live;
2827
- }
2828
-
2829
- /**
2830
- * Check if the user skipped connecting the account with Freemius.
2831
- *
2832
- * @author Vova Feldman (@svovaf)
2833
- * @since 1.0.7
2834
- *
2835
- * @return bool
2836
- */
2837
- function is_anonymous() {
2838
- if ( ! isset( $this->_is_anonymous ) ) {
2839
- if ( ! isset( $this->_storage->is_anonymous ) ) {
2840
- // Not skipped.
2841
- $this->_is_anonymous = false;
2842
- } else if ( is_bool( $this->_storage->is_anonymous ) ) {
2843
- // For back compatibility, since the variable was boolean before.
2844
- $this->_is_anonymous = $this->_storage->is_anonymous;
2845
-
2846
- // Upgrade stored data format to 1.1.3 format.
2847
- $this->set_anonymous_mode( $this->_storage->is_anonymous );
2848
- } else {
2849
- // Version 1.1.3 and later.
2850
- $this->_is_anonymous = $this->_storage->is_anonymous['is'];
2851
- }
2852
- }
2853
-
2854
- return $this->_is_anonymous;
2855
- }
2856
-
2857
- /**
2858
- * Check if user connected his account and install pending email activation.
2859
- *
2860
- * @author Vova Feldman (@svovaf)
2861
- * @since 1.0.7
2862
- *
2863
- * @return bool
2864
- */
2865
- function is_pending_activation() {
2866
- return $this->_storage->get( 'is_pending_activation', false );
2867
- }
2868
-
2869
- /**
2870
- * Check if plugin must be WordPress.org compliant.
2871
- *
2872
- * @since 1.0.7
2873
- *
2874
- * @return bool
2875
- */
2876
- function is_org_repo_compliant() {
2877
- return $this->_is_org_compliant;
2878
- }
2879
-
2880
- #region Daily Sync Cron ------------------------------------------------------------------
2881
-
2882
- /**
2883
- * @author Vova Feldman (@svovaf)
2884
- * @since 1.1.7.3
2885
- */
2886
- private function run_manual_sync() {
2887
- $this->require_pluggable_essentials();
2888
-
2889
- if ( ! current_user_can( 'activate_plugins' ) ) {
2890
- return;
2891
- }
2892
-
2893
- // Run manual sync.
2894
- $this->_sync_cron();
2895
-
2896
- // Reschedule next cron to run 24 hours from now (performance optimization).
2897
- $this->clear_sync_cron();
2898
-
2899
- $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
2900
- }
2901
-
2902
- /**
2903
- * Data sync cron job. Replaces the background sync non blocking HTTP request
2904
- * that doesn't halt page loading.
2905
- *
2906
- * @author Vova Feldman (@svovaf)
2907
- * @since 1.1.7.3
2908
- */
2909
- function _sync_cron() {
2910
- $this->_logger->entrance();
2911
-
2912
- // Store the last time data sync was executed.
2913
- $this->_storage->sync_timestamp = time();
2914
-
2915
- // Check if API is temporary down.
2916
- if ( FS_Api::is_temporary_down() ) {
2917
- return;
2918
- }
2919
-
2920
- // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
2921
-
2922
- if ( $this->is_registered() ) {
2923
- if ( $this->has_paid_plan() ) {
2924
- // Initiate background plan sync.
2925
- $this->_sync_license( true );
2926
-
2927
- if ( $this->is_paying() ) {
2928
- // Check for premium plugin updates.
2929
- $this->_check_updates( true );
2930
- }
2931
- } else {
2932
- // Sync install (only if something changed locally).
2933
- $this->sync_install();
2934
- }
2935
- }
2936
-
2937
- $this->do_action( 'after_sync_cron' );
2938
- }
2939
-
2940
- /**
2941
- * Check if sync was executed in the last $period of seconds.
2942
- *
2943
- * @author Vova Feldman (@svovaf)
2944
- * @since 1.1.7.3
2945
- *
2946
- * @param int $period In seconds
2947
- *
2948
- * @return bool
2949
- */
2950
- private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
2951
- if ( ! isset( $this->_storage->sync_timestamp ) ) {
2952
- return false;
2953
- }
2954
-
2955
- return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
2956
- }
2957
-
2958
- /**
2959
- * @author Vova Feldman (@svovaf)
2960
- * @since 1.1.7.3
2961
- *
2962
- * @return bool
2963
- */
2964
- private function is_sync_cron_on() {
2965
- /**
2966
- * @var object $sync_cron_data
2967
- */
2968
- $sync_cron_data = $this->_storage->get( 'sync_cron', null );
2969
-
2970
- return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
2971
- }
2972
-
2973
- /**
2974
- * @author Vova Feldman (@svovaf)
2975
- * @since 1.1.7.3
2976
- *
2977
- * @param int $start_at Defaults to now.
2978
- * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
2979
- * schedule job to start right away.
2980
- */
2981
- private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
2982
- $this->_logger->entrance();
2983
-
2984
- if ( $randomize_start ) {
2985
- // Schedule first sync with a random 12 hour time range from now.
2986
- $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
2987
- }
2988
-
2989
- // Schedule daily WP cron.
2990
- wp_schedule_event(
2991
- $start_at,
2992
- 'daily',
2993
- $this->get_action_tag( 'data_sync' )
2994
- );
2995
-
2996
- $this->_storage->store( 'sync_cron', (object) array(
2997
- 'version' => $this->get_plugin_version(),
2998
- 'sdk_version' => $this->version,
2999
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
3000
- 'on' => true,
3001
- ) );
3002
- }
3003
-
3004
- /**
3005
- * Add the actual sync function to the cron job hook.
3006
- *
3007
- * @author Vova Feldman (@svovaf)
3008
- * @since 1.1.7.3
3009
- */
3010
- private function hook_callback_to_sync_cron() {
3011
- $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
3012
- }
3013
-
3014
- /**
3015
- * @author Vova Feldman (@svovaf)
3016
- * @since 1.1.7.3
3017
- */
3018
- private function clear_sync_cron() {
3019
- $this->_logger->entrance();
3020
-
3021
- if ( ! $this->is_sync_cron_on() ) {
3022
- return;
3023
- }
3024
-
3025
- $this->_storage->remove( 'sync_cron' );
3026
-
3027
- wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
3028
- }
3029
-
3030
- /**
3031
- * Unix timestamp for next sync cron execution or false if not scheduled.
3032
- *
3033
- * @author Vova Feldman (@svovaf)
3034
- * @since 1.1.7.3
3035
- *
3036
- * @return int|false
3037
- */
3038
- function next_sync_cron() {
3039
- $this->_logger->entrance();
3040
-
3041
- if ( ! $this->is_sync_cron_on() ) {
3042
- return false;
3043
- }
3044
-
3045
- return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
3046
- }
3047
-
3048
- /**
3049
- * Unix timestamp for previous sync cron execution or false if never executed.
3050
- *
3051
- * @author Vova Feldman (@svovaf)
3052
- * @since 1.1.7.3
3053
- *
3054
- * @return int|false
3055
- */
3056
- function last_sync_cron() {
3057
- $this->_logger->entrance();
3058
-
3059
- return $this->_storage->get( 'sync_timestamp' );
3060
- }
3061
-
3062
- #endregion Daily Sync Cron ------------------------------------------------------------------
3063
-
3064
- #region Async Install Sync ------------------------------------------------------------------
3065
-
3066
- /**
3067
- * @author Vova Feldman (@svovaf)
3068
- * @since 1.1.7.3
3069
- *
3070
- * @return bool
3071
- */
3072
- private function is_install_sync_scheduled() {
3073
- /**
3074
- * @var object $cron_data
3075
- */
3076
- $cron_data = $this->_storage->get( 'install_sync_cron', null );
3077
-
3078
- return ( ! is_null( $cron_data ) && true === $cron_data->on );
3079
- }
3080
-
3081
- /**
3082
- * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
3083
- *
3084
- * @author Vova Feldman (@svovaf)
3085
- * @since 1.1.7.3
3086
- */
3087
- private function schedule_install_sync() {
3088
- $this->_logger->entrance();
3089
-
3090
- $this->clear_install_sync_cron();
3091
-
3092
- // Schedule immediate install sync.
3093
- wp_schedule_single_event(
3094
- WP_FS__SCRIPT_START_TIME,
3095
- $this->get_action_tag( 'install_sync' )
3096
- );
3097
-
3098
- $this->_storage->store( 'install_sync_cron', (object) array(
3099
- 'version' => $this->get_plugin_version(),
3100
- 'sdk_version' => $this->version,
3101
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
3102
- 'on' => true,
3103
- ) );
3104
- }
3105
-
3106
- /**
3107
- * Unix timestamp for previous install sync cron execution or false if never executed.
3108
- *
3109
- * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
3110
- * updated. But for sure the sync event is working.
3111
- *
3112
- * @author Vova Feldman (@svovaf)
3113
- * @since 1.1.7.3
3114
- *
3115
- * @return int|false
3116
- */
3117
- function last_install_sync() {
3118
- $this->_logger->entrance();
3119
-
3120
- return $this->_storage->get( 'install_sync_timestamp' );
3121
- }
3122
-
3123
- /**
3124
- * Unix timestamp for next install sync cron execution or false if not scheduled.
3125
- *
3126
- * @author Vova Feldman (@svovaf)
3127
- * @since 1.1.7.3
3128
- *
3129
- * @return int|false
3130
- */
3131
- function next_install_sync() {
3132
- $this->_logger->entrance();
3133
-
3134
- if ( ! $this->is_install_sync_scheduled() ) {
3135
- return false;
3136
- }
3137
-
3138
- return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
3139
- }
3140
-
3141
- /**
3142
- * Add the actual install sync function to the cron job hook.
3143
- *
3144
- * @author Vova Feldman (@svovaf)
3145
- * @since 1.1.7.3
3146
- */
3147
- private function hook_callback_to_install_sync() {
3148
- $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
3149
- }
3150
-
3151
- /**
3152
- * @author Vova Feldman (@svovaf)
3153
- * @since 1.1.7.3
3154
- */
3155
- private function clear_install_sync_cron() {
3156
- $this->_logger->entrance();
3157
-
3158
- if ( ! $this->is_install_sync_scheduled() ) {
3159
- return;
3160
- }
3161
-
3162
- $this->_storage->remove( 'install_sync_cron' );
3163
-
3164
- wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
3165
- }
3166
-
3167
- /**
3168
- * @author Vova Feldman (@svovaf)
3169
- * @since 1.1.7.3
3170
- */
3171
- public function _run_sync_install() {
3172
- $this->_logger->entrance();
3173
-
3174
- // Update last install sync timestamp.
3175
- $this->_storage->install_sync_timestamp = time();
3176
-
3177
- $this->sync_install( array(), true );
3178
- }
3179
-
3180
- #endregion Async Install Sync ------------------------------------------------------------------
3181
-
3182
- /**
3183
- * Show a notice that activation is currently pending.
3184
- *
3185
- * @author Vova Feldman (@svovaf)
3186
- * @since 1.0.7
3187
- *
3188
- * @param bool|string $email
3189
- */
3190
- function _add_pending_activation_notice( $email = false ) {
3191
- if ( ! is_string( $email ) ) {
3192
- $current_user = self::_get_current_wp_user();
3193
- $email = $current_user->user_email;
3194
- }
3195
-
3196
- $this->_admin_notices->add_sticky(
3197
- sprintf(
3198
- __fs( 'pending-activation-message', $this->_slug ),
3199
- '<b>' . $this->get_plugin_name() . '</b>',
3200
- '<b>' . $email . '</b>'
3201
- ),
3202
- 'activation_pending',
3203
- 'Thanks!'
3204
- );
3205
- }
3206
-
3207
- /**
3208
- * Check if currently in plugin activation.
3209
- *
3210
- * @author Vova Feldman (@svovaf)
3211
- * @since 1.1.4
3212
- *
3213
- * @return bool
3214
- */
3215
- function is_plugin_activation() {
3216
- return get_option( "fs_{$this->_slug}_activated", false );
3217
- }
3218
-
3219
- /**
3220
- *
3221
- * NOTE: admin_menu action executed before admin_init.
3222
- *
3223
- * @author Vova Feldman (@svovaf)
3224
- * @since 1.0.7
3225
- */
3226
- function _admin_init_action() {
3227
- /**
3228
- * Automatically redirect to connect/activation page after plugin activation.
3229
- *
3230
- * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
3231
- */
3232
- if ( $this->is_plugin_activation() ) {
3233
- delete_option( "fs_{$this->_slug}_activated" );
3234
-
3235
- if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
3236
- $this->_redirect_on_activation_hook();
3237
-
3238
- return;
3239
- }
3240
- }
3241
-
3242
- if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
3243
- check_admin_referer( $this->_slug . '_skip_activation' );
3244
-
3245
- $this->skip_connection();
3246
-
3247
- if ( fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) ) ) {
3248
- exit();
3249
- }
3250
- }
3251
-
3252
- if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
3253
- if ( ! $this->is_pending_activation() ) {
3254
- if ( ! $this->_menu->is_activation_page() ) {
3255
- if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
3256
- // Show notice for new plugin installations.
3257
- $this->_admin_notices->add(
3258
- sprintf(
3259
- __fs( 'you-are-step-away', $this->_slug ),
3260
- sprintf( '<b><a href="%s">%s</a></b>',
3261
- $this->get_activation_url(),
3262
- sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
3263
- )
3264
- ),
3265
- '',
3266
- 'update-nag'
3267
- );
3268
- } else {
3269
- if ( ! isset( $this->_storage->sticky_optin_added ) ) {
3270
- $this->_storage->sticky_optin_added = true;
3271
-
3272
- // Show notice for new plugin installations.
3273
- $this->_admin_notices->add_sticky(
3274
- sprintf(
3275
- __fs( 'few-plugin-tweaks', $this->_slug ),
3276
- sprintf( '<b><a href="%s">%s</a></b>',
3277
- $this->get_activation_url(),
3278
- sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
3279
- )
3280
- ),
3281
- 'connect_account',
3282
- '',
3283
- 'update-nag'
3284
- );
3285
- }
3286
-
3287
- if ( $this->has_filter( 'optin_pointer_element' ) ) {
3288
- // Don't show admin nag if plugin update.
3289
- wp_enqueue_script( 'wp-pointer' );
3290
- wp_enqueue_style( 'wp-pointer' );
3291
-
3292
- $this->_enqueue_connect_essentials();
3293
-
3294
- add_action( 'admin_print_footer_scripts', array(
3295
- $this,
3296
- '_add_connect_pointer_script'
3297
- ) );
3298
- }
3299
-
3300
- }
3301
- }
3302
- }
3303
- }
3304
-
3305
- $this->_add_upgrade_action_link();
3306
- }
3307
-
3308
- /**
3309
- * Enqueue connect requires scripts and styles.
3310
- *
3311
- * @author Vova Feldman (@svovaf)
3312
- * @since 1.1.4
3313
- */
3314
- function _enqueue_connect_essentials() {
3315
- wp_enqueue_script( 'jquery' );
3316
- wp_enqueue_script( 'json2' );
3317
-
3318
- fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
3319
- fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
3320
-
3321
- fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
3322
- }
3323
-
3324
- /**
3325
- * Add connect / opt-in pointer.
3326
- *
3327
- * @author Vova Feldman (@svovaf)
3328
- * @since 1.1.4
3329
- */
3330
- function _add_connect_pointer_script() {
3331
- $vars = array( 'slug' => $this->_slug );
3332
- $pointer_content = fs_get_template( 'connect.php', $vars );
3333
- ?>
3334
- <script type="text/javascript">// <![CDATA[
3335
- jQuery(document).ready(function ($) {
3336
- if ('undefined' !== typeof(jQuery().pointer)) {
3337
-
3338
- var element = <?php echo $this->apply_filters('optin_pointer_element', '$("#non_existing_element");') ?>;
3339
-
3340
- if (element.length > 0) {
3341
- var optin = $(element).pointer($.extend(true, {}, {
3342
- content : <?php echo json_encode($pointer_content) ?>,
3343
- position : {
3344
- edge : 'left',
3345
- align: 'center'
3346
- },
3347
- buttons : function () {
3348
- // Don't show pointer buttons.
3349
- return '';
3350
- },
3351
- pointerWidth: 482
3352
- }, <?php echo $this->apply_filters('optin_pointer_options_json', '{}') ?>));
3353
-
3354
- <?php
3355
- echo $this->apply_filters('optin_pointer_execute', "
3356
-
3357
- optin.pointer('open');
3358
-
3359
- // Tag the opt-in pointer with custom class.
3360
- $('.wp-pointer #fs_connect')
3361
- .parents('.wp-pointer.wp-pointer-top')
3362
- .addClass('fs-opt-in-pointer');
3363
-
3364
- ", 'element', 'optin') ?>
3365
- }
3366
- }
3367
- });
3368
- // ]]></script>
3369
- <?php
3370
- }
3371
-
3372
- /**
3373
- * Return current page's URL.
3374
- *
3375
- * @author Vova Feldman (@svovaf)
3376
- * @since 1.0.7
3377
- *
3378
- * @return string
3379
- */
3380
- function current_page_url() {
3381
- $url = 'http';
3382
-
3383
- if ( isset( $_SERVER["HTTPS"] ) ) {
3384
- if ( $_SERVER["HTTPS"] == "on" ) {
3385
- $url .= "s";
3386
- }
3387
- }
3388
- $url .= "://";
3389
- if ( $_SERVER["SERVER_PORT"] != "80" ) {
3390
- $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
3391
- } else {
3392
- $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
3393
- }
3394
-
3395
- return esc_url( $url );
3396
- }
3397
-
3398
- /**
3399
- * Check if the current page is the plugin's main admin settings page.
3400
- *
3401
- * @author Vova Feldman (@svovaf)
3402
- * @since 1.0.7
3403
- *
3404
- * @return bool
3405
- */
3406
- function _is_plugin_page() {
3407
- return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
3408
- fs_is_plugin_page( $this->_slug );
3409
- }
3410
-
3411
- /* Events
3412
- ------------------------------------------------------------------------------------------------------------------*/
3413
- /**
3414
- * Delete site install from Database.
3415
- *
3416
- * @author Vova Feldman (@svovaf)
3417
- * @since 1.0.1
3418
- *
3419
- * @param bool $store
3420
- */
3421
- function _delete_site( $store = true ) {
3422
- $sites = self::get_all_sites();
3423
-
3424
- if ( isset( $sites[ $this->_slug ] ) ) {
3425
- unset( $sites[ $this->_slug ] );
3426
- }
3427
-
3428
- self::$_accounts->set_option( 'sites', $sites, $store );
3429
- }
3430
-
3431
- /**
3432
- * Delete plugin's plans information.
3433
- *
3434
- * @param bool $store Flush to Database if true.
3435
- *
3436
- * @author Vova Feldman (@svovaf)
3437
- * @since 1.0.9
3438
- */
3439
- private function _delete_plans( $store = true ) {
3440
- $this->_logger->entrance();
3441
-
3442
- $plans = self::get_all_plans();
3443
-
3444
- unset( $plans[ $this->_slug ] );
3445
-
3446
- self::$_accounts->set_option( 'plans', $plans, $store );
3447
- }
3448
-
3449
- /**
3450
- * Delete all plugin licenses.
3451
- *
3452
- * @author Vova Feldman (@svovaf)
3453
- * @since 1.0.9
3454
- *
3455
- * @param bool $store
3456
- * @param string|bool $plugin_slug
3457
- */
3458
- private function _delete_licenses( $store = true, $plugin_slug = false ) {
3459
- $this->_logger->entrance();
3460
-
3461
- $all_licenses = self::get_all_licenses();
3462
-
3463
- if ( ! is_string( $plugin_slug ) ) {
3464
- $plugin_slug = $this->_slug;
3465
- }
3466
-
3467
- unset( $all_licenses[ $plugin_slug ] );
3468
-
3469
- self::$_accounts->set_option( 'licenses', $all_licenses, $store );
3470
- }
3471
-
3472
- /**
3473
- * Check if Freemius was added on new plugin installation.
3474
- *
3475
- * @author Vova Feldman (@svovaf)
3476
- * @since 1.1.5
3477
- *
3478
- * @return bool
3479
- */
3480
- function is_plugin_new_install() {
3481
- return isset( $this->_storage->is_plugin_new_install ) &&
3482
- $this->_storage->is_plugin_new_install;
3483
- }
3484
-
3485
- /**
3486
- * Plugin activated hook.
3487
- *
3488
- * @author Vova Feldman (@svovaf)
3489
- * @since 1.0.1
3490
- *
3491
- * @uses FS_Api
3492
- */
3493
- function _activate_plugin_event_hook() {
3494
- $this->_logger->entrance( 'slug = ' . $this->_slug );
3495
-
3496
- if ( ! current_user_can( 'activate_plugins' ) ) {
3497
- return;
3498
- }
3499
-
3500
- $this->unregister_uninstall_hook();
3501
-
3502
- // Clear API cache on activation.
3503
- FS_Api::clear_cache();
3504
-
3505
- if ( $this->is_registered() ) {
3506
- // Schedule re-activation event and sync.
3507
- // $this->sync_install( array(), true );
3508
- $this->schedule_install_sync();
3509
-
3510
- /**
3511
- * @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.
3512
- */
3513
- if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
3514
- // Deactivate Free plugin version on premium plugin activation.
3515
- deactivate_plugins( $this->_free_plugin_basename );
3516
-
3517
- $this->_admin_notices->add(
3518
- sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
3519
- __fs( 'woot', $this->_slug ) . '!'
3520
- );
3521
- }
3522
- } else if ( $this->is_anonymous() ) {
3523
- /**
3524
- * Reset "skipped" click cache on the following:
3525
- * 1. Development mode.
3526
- * 2. If the user skipped the exact same version before.
3527
- *
3528
- * @todo 3. If explicitly asked to retry after every activation.
3529
- */
3530
- if ( WP_FS__DEV_MODE ||
3531
- $this->get_plugin_version() == $this->_storage->is_anonymous['version']
3532
- ) {
3533
- $this->reset_anonymous_mode();
3534
- }
3535
- }
3536
-
3537
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3538
- /**
3539
- * If no previous version of plugin's version exist, it means that it's either
3540
- * the first time that the plugin installed on the site, or the plugin was installed
3541
- * before but didn't have Freemius integrated.
3542
- *
3543
- * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
3544
- * on manual activation via the dashboard, is_plugin_activation() is TRUE
3545
- * only after immediate activation.
3546
- *
3547
- * @since 1.1.4
3548
- * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
3549
- */
3550
- $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
3551
- }
3552
-
3553
- if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
3554
- // Store hint that the plugin was just activated to enable auto-redirection to settings.
3555
- add_option( "fs_{$this->_slug}_activated", true );
3556
- }
3557
-
3558
- /**
3559
- * Activation hook is executed after the plugin's main file is loaded, therefore,
3560
- * after the plugin was loaded. The logic is located at activate_plugin()
3561
- * ./wp-admin/includes/plugin.php.
3562
- *
3563
- * @author Vova Feldman (@svovaf)
3564
- * @since 1.1.9
3565
- */
3566
- $this->_storage->was_plugin_loaded = true;
3567
- }
3568
-
3569
- /**
3570
- * Delete account.
3571
- *
3572
- * @author Vova Feldman (@svovaf)
3573
- * @since 1.0.3
3574
- *
3575
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
3576
- */
3577
- function delete_account_event( $check_user = true ) {
3578
- $this->_logger->entrance( 'slug = ' . $this->_slug );
3579
-
3580
- if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3581
- return;
3582
- }
3583
-
3584
- $this->do_action( 'before_account_delete' );
3585
-
3586
- // Clear all admin notices.
3587
- $this->_admin_notices->clear_all_sticky();
3588
-
3589
- $this->_delete_site( false );
3590
-
3591
- $this->_delete_plans( false );
3592
-
3593
- $this->_delete_licenses( false );
3594
-
3595
- // Delete add-ons related to plugin's account.
3596
- $this->_delete_account_addons( false );
3597
-
3598
- // @todo Delete plans and licenses of add-ons.
3599
-
3600
- self::$_accounts->store();
3601
-
3602
- /**
3603
- * IMPORTANT:
3604
- * Clear crons must be executed before clearing all storage.
3605
- * Otherwise, the cron will not be cleared.
3606
- */
3607
- $this->clear_sync_cron();
3608
- $this->clear_install_sync_cron();
3609
-
3610
- // Clear all storage data.
3611
- $this->_storage->clear_all( true, array(
3612
- 'connectivity_test',
3613
- 'is_on',
3614
- ) );
3615
-
3616
- // Send delete event.
3617
- $this->get_api_site_scope()->call( '/', 'delete' );
3618
-
3619
- $this->do_action( 'after_account_delete' );
3620
- }
3621
-
3622
- /**
3623
- * Plugin deactivation hook.
3624
- *
3625
- * @author Vova Feldman (@svovaf)
3626
- * @since 1.0.1
3627
- */
3628
- function _deactivate_plugin_hook() {
3629
- $this->_logger->entrance( 'slug = ' . $this->_slug );
3630
-
3631
- if ( ! current_user_can( 'activate_plugins' ) ) {
3632
- return;
3633
- }
3634
-
3635
- $this->_admin_notices->clear_all_sticky();
3636
- if ( isset( $this->_storage->sticky_optin_added ) ) {
3637
- unset( $this->_storage->sticky_optin_added );
3638
- }
3639
-
3640
- if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3641
- // Remember that plugin was already installed.
3642
- $this->_storage->is_plugin_new_install = false;
3643
- }
3644
-
3645
- // Hook to plugin uninstall.
3646
- register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
3647
-
3648
- $this->clear_module_main_file_cache();
3649
- $this->clear_sync_cron();
3650
- $this->clear_install_sync_cron();
3651
-
3652
- if ( $this->is_registered() ) {
3653
- // Send deactivation event.
3654
- $this->sync_install( array(
3655
- 'is_active' => false,
3656
- ) );
3657
- } else {
3658
- if ( ! $this->has_api_connectivity() ) {
3659
- // Reset connectivity test cache.
3660
- unset( $this->_storage->connectivity_test );
3661
- }
3662
- }
3663
-
3664
- // Clear API cache on deactivation.
3665
- FS_Api::clear_cache();
3666
-
3667
- $this->remove_sdk_reference();
3668
- }
3669
-
3670
- /**
3671
- * @author Vova Feldman (@svovaf)
3672
- * @since 1.1.6
3673
- */
3674
- private function remove_sdk_reference() {
3675
- global $fs_active_plugins;
3676
-
3677
- foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
3678
- if ( $this->_plugin_basename == $data->plugin_path ) {
3679
- unset( $fs_active_plugins->plugins[ $sdk_path ] );
3680
- break;
3681
- }
3682
- }
3683
-
3684
- fs_fallback_to_newest_active_sdk();
3685
- }
3686
-
3687
- /**
3688
- * @author Vova Feldman (@svovaf)
3689
- * @since 1.1.3
3690
- *
3691
- * @param bool $is_anonymous
3692
- */
3693
- private function set_anonymous_mode( $is_anonymous = true ) {
3694
- // Store information regarding skip to try and opt-in the user
3695
- // again in the future.
3696
- $this->_storage->is_anonymous = array(
3697
- 'is' => $is_anonymous,
3698
- 'timestamp' => WP_FS__SCRIPT_START_TIME,
3699
- 'version' => $this->get_plugin_version(),
3700
- );
3701
-
3702
- // Update anonymous mode cache.
3703
- $this->_is_anonymous = $is_anonymous;
3704
- }
3705
-
3706
- /**
3707
- * @author Vova Feldman (@svovaf)
3708
- * @since 1.1.3
3709
- */
3710
- private function reset_anonymous_mode() {
3711
- unset( $this->_storage->is_anonymous );
3712
- }
3713
-
3714
- /**
3715
- * Clears the anonymous mode and redirects to the opt-in screen.
3716
- *
3717
- * @author Vova Feldman (@svovaf)
3718
- * @since 1.1.7
3719
- */
3720
- function connect_again() {
3721
- if ( ! $this->is_anonymous() ) {
3722
- return;
3723
- }
3724
-
3725
- $this->reset_anonymous_mode();
3726
-
3727
- if ( fs_redirect( $this->get_activation_url() ) ) {
3728
- exit();
3729
- }
3730
- }
3731
-
3732
- /**
3733
- * Skip account connect, and set anonymous mode.
3734
- *
3735
- * @author Vova Feldman (@svovaf)
3736
- * @since 1.1.1
3737
- */
3738
- private function skip_connection() {
3739
- $this->_logger->entrance();
3740
-
3741
- $this->_admin_notices->remove_sticky( 'connect_account' );
3742
-
3743
- $this->set_anonymous_mode();
3744
-
3745
- // Send anonymous skip event.
3746
- // No user identified info nor any tracking will be sent after the user skips the opt-in.
3747
- $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
3748
- 'uid' => $this->get_anonymous_id(),
3749
- ) );
3750
- }
3751
-
3752
- /**
3753
- * Plugin version update hook.
3754
- *
3755
- * @author Vova Feldman (@svovaf)
3756
- * @since 1.0.4
3757
- */
3758
- private function update_plugin_version_event() {
3759
- $this->_logger->entrance();
3760
-
3761
- if ( ! $this->is_registered() ) {
3762
- return;
3763
- }
3764
-
3765
- $this->schedule_install_sync();
3766
- // $this->sync_install( array(), true );
3767
- }
3768
-
3769
- /**
3770
- * Return a list of modified plugins since the last sync.
3771
- *
3772
- * Note:
3773
- * There's no point to store a plugins counter since even if the number of
3774
- * plugins didn't change, we still need to check if the versions are all the
3775
- * same and the activity state is similar.
3776
- *
3777
- * @author Vova Feldman (@svovaf)
3778
- * @since 1.1.8
3779
- *
3780
- * @return array|false
3781
- */
3782
- private function get_plugins_data_for_api() {
3783
- // Alias.
3784
- $option_name = 'all_plugins';
3785
-
3786
- $all_cached_plugins = self::$_accounts->get_option( $option_name );
3787
-
3788
- if ( ! is_object( $all_cached_plugins ) ) {
3789
- $all_cached_plugins = (object) array(
3790
- 'timestamp' => '',
3791
- 'md5' => '',
3792
- 'plugins' => array(),
3793
- );
3794
- }
3795
-
3796
- $time = time();
3797
-
3798
- if ( ! empty( $all_cached_plugins->timestamp ) &&
3799
- ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3800
- ) {
3801
- // Don't send plugin updates if last update was in the past 5 min.
3802
- return false;
3803
- }
3804
-
3805
- // Write timestamp to lock the logic.
3806
- $all_cached_plugins->timestamp = $time;
3807
- self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3808
-
3809
- // Reload options from DB.
3810
- self::$_accounts->load( true );
3811
- $all_cached_plugins = self::$_accounts->get_option( $option_name );
3812
-
3813
- if ( $time != $all_cached_plugins->timestamp ) {
3814
- // If timestamp is different, then another thread captured the lock.
3815
- return false;
3816
- }
3817
-
3818
- // Check if there's a change in plugins.
3819
- $all_plugins = self::get_all_plugins();
3820
-
3821
- // Check if plugins changed.
3822
- ksort( $all_plugins );
3823
-
3824
- $plugins_signature = '';
3825
- foreach ( $all_plugins as $basename => $data ) {
3826
- $plugins_signature .= $data['slug'] . ',' .
3827
- $data['Version'] . ',' .
3828
- ( $data['is_active'] ? '1' : '0' ) . ';';
3829
- }
3830
-
3831
- // Check if plugins status changed (version or active/inactive).
3832
- $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
3833
-
3834
- $plugins_update_data = array();
3835
-
3836
- if ( $plugins_changed ) {
3837
- // Change in plugins, report changes.
3838
-
3839
- // Update existing plugins info.
3840
- foreach ( $all_cached_plugins->plugins as $basename => $data ) {
3841
- if ( ! isset( $all_plugins[ $basename ] ) ) {
3842
- // Plugin uninstalled.
3843
- $uninstalled_plugin_data = $data;
3844
- $uninstalled_plugin_data['is_active'] = false;
3845
- $uninstalled_plugin_data['is_uninstalled'] = true;
3846
- $plugins_update_data[] = $uninstalled_plugin_data;
3847
-
3848
- unset( $all_plugins[ $basename ] );
3849
- unset( $all_cached_plugins->plugins[ $basename ] );
3850
- } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
3851
- $data['version'] !== $all_plugins[ $basename ]['Version']
3852
- ) {
3853
- // Plugin activated or deactivated, or version changed.
3854
- $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
3855
- $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
3856
-
3857
- $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
3858
- }
3859
- }
3860
-
3861
- // Find new plugins that weren't yet seen before.
3862
- foreach ( $all_plugins as $basename => $data ) {
3863
- if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
3864
- // New plugin.
3865
- $new_plugin = array(
3866
- 'slug' => $data['slug'],
3867
- 'version' => $data['Version'],
3868
- 'title' => $data['Name'],
3869
- 'is_active' => $data['is_active'],
3870
- 'is_uninstalled' => false,
3871
- );
3872
-
3873
- $plugins_update_data[] = $new_plugin;
3874
- $all_cached_plugins->plugins[ $basename ] = $new_plugin;
3875
- }
3876
- }
3877
-
3878
- $all_cached_plugins->md5 = md5( $plugins_signature );
3879
- $all_cached_plugins->timestamp = $time;
3880
- self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
3881
- }
3882
-
3883
- return $plugins_update_data;
3884
- }
3885
-
3886
- /**
3887
- * Return a list of modified themes since the last sync.
3888
- *
3889
- * Note:
3890
- * There's no point to store a themes counter since even if the number of
3891
- * themes didn't change, we still need to check if the versions are all the
3892
- * same and the activity state is similar.
3893
- *
3894
- * @author Vova Feldman (@svovaf)
3895
- * @since 1.1.8
3896
- *
3897
- * @return array|false
3898
- */
3899
- private function get_themes_data_for_api() {
3900
- // Alias.
3901
- $option_name = 'all_themes';
3902
-
3903
- $all_cached_themes = self::$_accounts->get_option( $option_name );
3904
-
3905
- if ( ! is_object( $all_cached_themes ) ) {
3906
- $all_cached_themes = (object) array(
3907
- 'timestamp' => '',
3908
- 'md5' => '',
3909
- 'themes' => array(),
3910
- );
3911
- }
3912
-
3913
- $time = time();
3914
-
3915
- if ( ! empty( $all_cached_themes->timestamp ) &&
3916
- ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
3917
- ) {
3918
- // Don't send theme updates if last update was in the past 5 min.
3919
- return false;
3920
- }
3921
-
3922
- // Write timestamp to lock the logic.
3923
- $all_cached_themes->timestamp = $time;
3924
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
3925
-
3926
- // Reload options from DB.
3927
- self::$_accounts->load( true );
3928
- $all_cached_themes = self::$_accounts->get_option( $option_name );
3929
-
3930
- if ( $time != $all_cached_themes->timestamp ) {
3931
- // If timestamp is different, then another thread captured the lock.
3932
- return false;
3933
- }
3934
-
3935
- // Get active theme.
3936
- $active_theme = wp_get_theme();
3937
- $active_theme_stylesheet = $active_theme->get_stylesheet();
3938
-
3939
- // Check if there's a change in themes.
3940
- $all_themes = wp_get_themes();
3941
-
3942
- // Check if themes changed.
3943
- ksort( $all_themes );
3944
-
3945
- $themes_signature = '';
3946
- foreach ( $all_themes as $slug => $data ) {
3947
- $is_active = ( $slug === $active_theme_stylesheet );
3948
- $themes_signature .= $slug . ',' .
3949
- $data->version . ',' .
3950
- ( $is_active ? '1' : '0' ) . ';';
3951
- }
3952
-
3953
- // Check if themes status changed (version or active/inactive).
3954
- $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
3955
-
3956
- $themes_update_data = array();
3957
-
3958
- if ( $themes_changed ) {
3959
- // Change in themes, report changes.
3960
-
3961
- // Update existing themes info.
3962
- foreach ( $all_cached_themes->themes as $slug => $data ) {
3963
- $is_active = ( $slug === $active_theme_stylesheet );
3964
-
3965
- if ( ! isset( $all_themes[ $slug ] ) ) {
3966
- // Plugin uninstalled.
3967
- $uninstalled_theme_data = $data;
3968
- $uninstalled_theme_data['is_active'] = false;
3969
- $uninstalled_theme_data['is_uninstalled'] = true;
3970
- $themes_update_data[] = $uninstalled_theme_data;
3971
-
3972
- unset( $all_themes[ $slug ] );
3973
- unset( $all_cached_themes->themes[ $slug ] );
3974
- } else if ( $data['is_active'] !== $is_active ||
3975
- $data['version'] !== $all_themes[ $slug ]->version
3976
- ) {
3977
- // Plugin activated or deactivated, or version changed.
3978
-
3979
- $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
3980
- $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
3981
-
3982
- $themes_update_data[] = $all_cached_themes->themes[ $slug ];
3983
- }
3984
- }
3985
-
3986
- // Find new themes that weren't yet seen before.
3987
- foreach ( $all_themes as $slug => $data ) {
3988
- if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
3989
- $is_active = ( $slug === $active_theme_stylesheet );
3990
-
3991
- // New plugin.
3992
- $new_plugin = array(
3993
- 'slug' => $slug,
3994
- 'version' => $data->version,
3995
- 'title' => $data->name,
3996
- 'is_active' => $is_active,
3997
- 'is_uninstalled' => false,
3998
- );
3999
-
4000
- $themes_update_data[] = $new_plugin;
4001
- $all_cached_themes->themes[ $slug ] = $new_plugin;
4002
- }
4003
- }
4004
-
4005
- $all_cached_themes->md5 = md5( $themes_signature );
4006
- $all_cached_themes->timestamp = time();
4007
- self::$_accounts->set_option( $option_name, $all_cached_themes, true );
4008
- }
4009
-
4010
- return $themes_update_data;
4011
- }
4012
-
4013
- /**
4014
- * Update install details.
4015
- *
4016
- * @author Vova Feldman (@svovaf)
4017
- * @since 1.1.2
4018
- *
4019
- * @param string[] string $override
4020
- * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
4021
- * @param bool $include_themes Since 1.1.8 by default include plugin changes.
4022
- *
4023
- * @return array
4024
- */
4025
- private function get_install_data_for_api(
4026
- array $override,
4027
- $include_plugins = true,
4028
- $include_themes = true
4029
- ) {
4030
- /**
4031
- * @since 1.1.8 Also send plugin updates.
4032
- */
4033
- if ( $include_plugins && ! isset( $override['plugins'] ) ) {
4034
- $plugins = $this->get_plugins_data_for_api();
4035
- if ( ! empty( $plugins ) ) {
4036
- $override['plugins'] = $plugins;
4037
- }
4038
- }
4039
- /**
4040
- * @since 1.1.8 Also send themes updates.
4041
- */
4042
- if ( $include_themes && ! isset( $override['themes'] ) ) {
4043
- $themes = $this->get_themes_data_for_api();
4044
- if ( ! empty( $themes ) ) {
4045
- $override['themes'] = $themes;
4046
- }
4047
- }
4048
-
4049
- return array_merge( array(
4050
- 'version' => $this->get_plugin_version(),
4051
- 'is_premium' => $this->is_premium(),
4052
- 'language' => get_bloginfo( 'language' ),
4053
- 'charset' => get_bloginfo( 'charset' ),
4054
- 'platform_version' => get_bloginfo( 'version' ),
4055
- 'programming_language_version' => phpversion(),
4056
- 'title' => get_bloginfo( 'name' ),
4057
- 'url' => get_site_url(),
4058
- // Special params.
4059
- 'is_active' => true,
4060
- 'is_uninstalled' => false,
4061
- ), $override );
4062
- }
4063
-
4064
- /**
4065
- * Update install only if changed.
4066
- *
4067
- * @author Vova Feldman (@svovaf)
4068
- * @since 1.0.9
4069
- *
4070
- * @param string[] string $override
4071
- * @param bool $flush
4072
- *
4073
- * @return false|object|string
4074
- */
4075
- private function send_install_update( $override = array(), $flush = false ) {
4076
- $this->_logger->entrance();
4077
-
4078
- $check_properties = $this->get_install_data_for_api( $override );
4079
-
4080
- if ( $flush ) {
4081
- $params = $check_properties;
4082
- } else {
4083
- $params = array();
4084
- $special = array();
4085
- $special_override = false;
4086
-
4087
- foreach ( $check_properties as $p => $v ) {
4088
- if ( property_exists( $this->_site, $p ) ) {
4089
- if ( ! empty( $this->_site->{$p} ) &&
4090
- $this->_site->{$p} != $v
4091
- ) {
4092
- $this->_site->{$p} = $v;
4093
- $params[ $p ] = $v;
4094
- }
4095
- } else {
4096
- $special[ $p ] = $v;
4097
-
4098
- if ( isset( $override[ $p ] ) ||
4099
- 'plugins' === $p ||
4100
- 'themes' === $p
4101
- ) {
4102
- $special_override = true;
4103
- }
4104
- }
4105
- }
4106
-
4107
- if ( $special_override || 0 < count( $params ) ) {
4108
- // Add special params only if has at least one
4109
- // standard param, or if explicitly requested to
4110
- // override a special param or a param which is not exist
4111
- // in the install object.
4112
- $params = array_merge( $params, $special );
4113
- }
4114
- }
4115
-
4116
- if ( 0 < count( $params ) ) {
4117
- // Update last install sync timestamp.
4118
- $this->_storage->install_sync_timestamp = time();
4119
-
4120
- $params['uid'] = $this->get_anonymous_id();
4121
-
4122
- // Send updated values to FS.
4123
- $site = $this->get_api_site_scope()->call( '/', 'put', $params );
4124
-
4125
- if ( ! $this->is_api_error( $site ) ) {
4126
- // I successfully sent install update, clear scheduled sync if exist.
4127
- $this->clear_install_sync_cron();
4128
- }
4129
-
4130
- return $site;
4131
- }
4132
-
4133
- return false;
4134
- }
4135
-
4136
- /**
4137
- * Update install only if changed.
4138
- *
4139
- * @author Vova Feldman (@svovaf)
4140
- * @since 1.0.9
4141
- *
4142
- * @param string[] string $override
4143
- * @param bool $flush
4144
- *
4145
- * @return false|object|string
4146
- */
4147
- private function sync_install( $override = array(), $flush = false ) {
4148
- $this->_logger->entrance();
4149
-
4150
- $site = $this->send_install_update( $override, $flush );
4151
-
4152
- if ( false === $site ) {
4153
- // No sync required.
4154
- return;
4155
- }
4156
-
4157
- if ( $this->is_api_error( $site ) ) {
4158
- // Failed to sync, don't update locally.
4159
- return;
4160
- }
4161
-
4162
- $plan = $this->get_plan();
4163
- $this->_site = new FS_Site( $site );
4164
- $this->_site->plan = $plan;
4165
-
4166
- $this->_store_site( true );
4167
- }
4168
-
4169
- /**
4170
- * Track install's custom event.
4171
- *
4172
- * IMPORTANT:
4173
- * Custom event tracking is currently only supported for specific clients.
4174
- * If you are not one of them, please don't use this method. If you will,
4175
- * the API will simply ignore your request based on the plugin ID.
4176
- *
4177
- * Need custom tracking for your plugin or theme?
4178
- * If you are interested in custom event tracking please contact yo@freemius.com
4179
- * for further details.
4180
- *
4181
- * @author Vova Feldman (@svovaf)
4182
- * @since 1.2.1
4183
- *
4184
- * @param string $name Event name.
4185
- * @param array $properties Associative key/value array with primitive values only
4186
- * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
4187
- * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
4188
- *
4189
- * @return object|false Event data or FALSE on failure.
4190
- *
4191
- * @throws \Freemius_InvalidArgumentException
4192
- */
4193
- public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
4194
- $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
4195
-
4196
- if ( ! $this->is_registered() ) {
4197
- return false;
4198
- }
4199
-
4200
- $event = array( 'type' => $name );
4201
-
4202
- if ( is_numeric( $process_at ) && $process_at > time() ) {
4203
- $event['process_at'] = $process_at;
4204
- }
4205
-
4206
- if ( $once ) {
4207
- $event['once'] = true;
4208
- }
4209
-
4210
- if ( ! empty( $properties ) ) {
4211
- // Verify associative array values are primitive.
4212
- foreach ( $properties as $k => $v ) {
4213
- if ( ! is_scalar( $v ) ) {
4214
- throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
4215
- }
4216
- }
4217
-
4218
- $event['properties'] = $properties;
4219
- }
4220
-
4221
- $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
4222
-
4223
- return $this->is_api_error( $result ) ?
4224
- false :
4225
- $result;
4226
- }
4227
-
4228
- /**
4229
- * Track install's custom event only once, but it still triggers the API call.
4230
- *
4231
- * IMPORTANT:
4232
- * Custom event tracking is currently only supported for specific clients.
4233
- * If you are not one of them, please don't use this method. If you will,
4234
- * the API will simply ignore your request based on the plugin ID.
4235
- *
4236
- * Need custom tracking for your plugin or theme?
4237
- * If you are interested in custom event tracking please contact yo@freemius.com
4238
- * for further details.
4239
- *
4240
- * @author Vova Feldman (@svovaf)
4241
- * @since 1.2.1
4242
- *
4243
- * @param string $name Event name.
4244
- * @param array $properties Associative key/value array with primitive values only
4245
- * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
4246
- *
4247
- * @return object|false Event data or FALSE on failure.
4248
- *
4249
- * @throws \Freemius_InvalidArgumentException
4250
- *
4251
- * @user Freemius::track_event()
4252
- */
4253
- public function track_event_once( $name, $properties = array(), $process_at = false ) {
4254
- return $this->track_event( $name, $properties, $process_at, true );
4255
- }
4256
-
4257
- /**
4258
- * Plugin uninstall hook.
4259
- *
4260
- * @author Vova Feldman (@svovaf)
4261
- * @since 1.0.1
4262
- *
4263
- * @param bool $check_user Enforce checking if user have plugins activation privileges.
4264
- */
4265
- function _uninstall_plugin_event( $check_user = true ) {
4266
- $this->_logger->entrance( 'slug = ' . $this->_slug );
4267
-
4268
- if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
4269
- return;
4270
- }
4271
-
4272
- $params = array();
4273
- $uninstall_reason = null;
4274
- if ( isset( $this->_storage->uninstall_reason ) ) {
4275
- $uninstall_reason = $this->_storage->uninstall_reason;
4276
- $params['reason_id'] = $uninstall_reason->id;
4277
- $params['reason_info'] = $uninstall_reason->info;
4278
- }
4279
-
4280
- if ( ! $this->is_registered() && isset( $uninstall_reason ) ) {
4281
- // Send anonymous uninstall event only if user submitted a feedback.
4282
- if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
4283
- $this->opt_in( false, false, false, false, true );
4284
- } else {
4285
- $params['uid'] = $this->get_anonymous_id();
4286
- $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
4287
- }
4288
- } else {
4289
- // Send uninstall event.
4290
- $this->send_install_update( array_merge( $params, array(
4291
- 'is_active' => false,
4292
- 'is_uninstalled' => true,
4293
- ) ) );
4294
- }
4295
-
4296
- // @todo Decide if we want to delete plugin information from db.
4297
- }
4298
-
4299
- /**
4300
- * @author Vova Feldman (@svovaf)
4301
- * @since 1.1.1
4302
- *
4303
- * @return string
4304
- */
4305
- private function premium_plugin_basename() {
4306
- return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
4307
- }
4308
-
4309
- /**
4310
- * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
4311
- *
4312
- * @author Vova Feldman (@svovaf)
4313
- * @since 1.0.2
4314
- */
4315
- public static function _uninstall_plugin_hook() {
4316
- self::_load_required_static();
4317
-
4318
- self::$_static_logger->entrance();
4319
-
4320
- if ( ! current_user_can( 'activate_plugins' ) ) {
4321
- return;
4322
- }
4323
-
4324
- $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
4325
-
4326
- self::$_static_logger->info( 'plugin = ' . $plugin_file );
4327
-
4328
- define( 'WP_FS__UNINSTALL_MODE', true );
4329
-
4330
- $fs = self::get_instance_by_file( $plugin_file );
4331
-
4332
- if ( is_object( $fs ) ) {
4333
- self::require_plugin_essentials();
4334
-
4335
- if ( is_plugin_active( $fs->_free_plugin_basename ) ||
4336
- is_plugin_active( $fs->premium_plugin_basename() )
4337
- ) {
4338
- // Deleting Free or Premium plugin version while the other version still installed.
4339
- return;
4340
- }
4341
-
4342
- $fs->_uninstall_plugin_event();
4343
-
4344
- $fs->do_action( 'after_uninstall' );
4345
- }
4346
- }
4347
-
4348
- #region Plugin Information ------------------------------------------------------------------
4349
-
4350
- /**
4351
- * Load WordPress core plugin.php essential module.
4352
- *
4353
- * @author Vova Feldman (@svovaf)
4354
- * @since 1.1.1
4355
- */
4356
- private static function require_plugin_essentials() {
4357
- if ( ! function_exists( 'get_plugins' ) ) {
4358
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
4359
- }
4360
- }
4361
-
4362
- /**
4363
- * Load WordPress core pluggable.php module.
4364
- *
4365
- * @author Vova Feldman (@svovaf)
4366
- * @since 1.1.2
4367
- */
4368
- private static function require_pluggable_essentials() {
4369
- if ( ! function_exists( 'wp_get_current_user' ) ) {
4370
- require_once( ABSPATH . 'wp-includes/pluggable.php' );
4371
- }
4372
- }
4373
-
4374
- /**
4375
- * Return plugin data.
4376
- *
4377
- * @author Vova Feldman (@svovaf)
4378
- * @since 1.0.1
4379
- *
4380
- * @return array
4381
- */
4382
- function get_plugin_data() {
4383
- if ( ! isset( $this->_plugin_data ) ) {
4384
- self::require_plugin_essentials();
4385
-
4386
- /**
4387
- * @author Vova Feldman (@svovaf)
4388
- * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
4389
- *
4390
- * @link https://github.com/Freemius/wordpress-sdk/issues/77
4391
- */
4392
- $this->_plugin_data = get_plugin_data(
4393
- $this->_plugin_main_file_path,
4394
- false,
4395
- false
4396
- );
4397
- }
4398
-
4399
- return $this->_plugin_data;
4400
- }
4401
-
4402
- /**
4403
- * @author Vova Feldman (@svovaf)
4404
- * @since 1.0.1
4405
- *
4406
- * @return string Plugin slug.
4407
- */
4408
- function get_slug() {
4409
- return $this->_slug;
4410
- }
4411
-
4412
- /**
4413
- * @author Vova Feldman (@svovaf)
4414
- * @since 1.0.1
4415
- *
4416
- * @return number Plugin ID.
4417
- */
4418
- function get_id() {
4419
- return $this->_plugin->id;
4420
- }
4421
-
4422
- /**
4423
- * @author Vova Feldman (@svovaf)
4424
- * @since 1.0.1
4425
- *
4426
- * @return string Plugin public key.
4427
- */
4428
- function get_public_key() {
4429
- return $this->_plugin->public_key;
4430
- }
4431
-
4432
- /**
4433
- * Will be available only on sandbox mode.
4434
- *
4435
- * @author Vova Feldman (@svovaf)
4436
- * @since 1.0.4
4437
- *
4438
- * @return mixed Plugin secret key.
4439
- */
4440
- function get_secret_key() {
4441
- return $this->_plugin->secret_key;
4442
- }
4443
-
4444
- /**
4445
- * @author Vova Feldman (@svovaf)
4446
- * @since 1.1.1
4447
- *
4448
- * @return bool
4449
- */
4450
- function has_secret_key() {
4451
- return ! empty( $this->_plugin->secret_key );
4452
- }
4453
-
4454
- /**
4455
- * @author Vova Feldman (@svovaf)
4456
- * @since 1.0.9
4457
- *
4458
- * @return string
4459
- */
4460
- function get_plugin_name() {
4461
- $this->_logger->entrance();
4462
-
4463
- if ( ! isset( $this->_plugin_name ) ) {
4464
- $plugin_data = $this->get_plugin_data();
4465
-
4466
- // Get name.
4467
- $this->_plugin_name = $plugin_data['Name'];
4468
-
4469
- // Check if plugin name contains [Premium] suffix and remove it.
4470
- $suffix = '[premium]';
4471
- $suffix_len = strlen( $suffix );
4472
-
4473
- if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
4474
- $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
4475
- ) {
4476
- $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
4477
- }
4478
-
4479
- $this->_logger->departure( 'Name = ' . $this->_plugin_name );
4480
- }
4481
-
4482
- return $this->_plugin_name;
4483
- }
4484
-
4485
- /**
4486
- * @author Vova Feldman (@svovaf)
4487
- * @since 1.0.0
4488
- *
4489
- * @return string
4490
- */
4491
- function get_plugin_version() {
4492
- $this->_logger->entrance();
4493
-
4494
- $plugin_data = $this->get_plugin_data();
4495
-
4496
- $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
4497
-
4498
- return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
4499
- }
4500
-
4501
- /**
4502
- * @author Vova Feldman (@svovaf)
4503
- * @since 1.0.4
4504
- *
4505
- * @return string
4506
- */
4507
- function get_plugin_basename() {
4508
- return $this->_plugin_basename;
4509
- }
4510
-
4511
- function get_plugin_folder_name() {
4512
- $this->_logger->entrance();
4513
-
4514
- $plugin_folder = $this->_plugin_basename;
4515
-
4516
- while ( '.' !== dirname( $plugin_folder ) ) {
4517
- $plugin_folder = dirname( $plugin_folder );
4518
- }
4519
-
4520
- $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
4521
-
4522
- return $plugin_folder;
4523
- }
4524
-
4525
- #endregion ------------------------------------------------------------------
4526
-
4527
- /* Account
4528
- ------------------------------------------------------------------------------------------------------------------*/
4529
-
4530
- /**
4531
- * Find plugin's slug by plugin's basename.
4532
- *
4533
- * @author Vova Feldman (@svovaf)
4534
- * @since 1.0.9
4535
- *
4536
- * @param string $plugin_base_name
4537
- *
4538
- * @return false|string
4539
- */
4540
- private static function find_slug_by_basename( $plugin_base_name ) {
4541
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4542
-
4543
- if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
4544
- return false;
4545
- }
4546
-
4547
- return $file_slug_map[ $plugin_base_name ];
4548
- }
4549
-
4550
- /**
4551
- * Store the map between the plugin's basename to the slug.
4552
- *
4553
- * @author Vova Feldman (@svovaf)
4554
- * @since 1.0.9
4555
- */
4556
- private function store_file_slug_map() {
4557
- $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4558
-
4559
- if ( ! array( $file_slug_map ) ) {
4560
- $file_slug_map = array();
4561
- }
4562
-
4563
- if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
4564
- $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
4565
- ) {
4566
- $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
4567
- self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
4568
- }
4569
- }
4570
-
4571
- /**
4572
- * @return FS_User[]
4573
- */
4574
- static function get_all_users() {
4575
- $users = self::$_accounts->get_option( 'users', array() );
4576
-
4577
- if ( ! is_array( $users ) ) {
4578
- $users = array();
4579
- }
4580
-
4581
- return $users;
4582
- }
4583
-
4584
- /**
4585
- * @return FS_Site[]
4586
- */
4587
- private static function get_all_sites() {
4588
- $sites = self::$_accounts->get_option( 'sites', array() );
4589
-
4590
- if ( ! is_array( $sites ) ) {
4591
- $sites = array();
4592
- }
4593
-
4594
- return $sites;
4595
- }
4596
-
4597
- /**
4598
- * @author Vova Feldman (@svovaf)
4599
- * @since 1.0.6
4600
- *
4601
- * @return FS_Plugin_License[]
4602
- */
4603
- private static function get_all_licenses() {
4604
- $licenses = self::$_accounts->get_option( 'licenses', array() );
4605
-
4606
- if ( ! is_array( $licenses ) ) {
4607
- $licenses = array();
4608
- }
4609
-
4610
- return $licenses;
4611
- }
4612
-
4613
- /**
4614
- * @return FS_Plugin_Plan[]
4615
- */
4616
- private static function get_all_plans() {
4617
- $plans = self::$_accounts->get_option( 'plans', array() );
4618
-
4619
- if ( ! is_array( $plans ) ) {
4620
- $plans = array();
4621
- }
4622
-
4623
- return $plans;
4624
- }
4625
-
4626
- /**
4627
- * @author Vova Feldman (@svovaf)
4628
- * @since 1.0.4
4629
- *
4630
- * @return FS_Plugin_Tag[]
4631
- */
4632
- private static function get_all_updates() {
4633
- $updates = self::$_accounts->get_option( 'updates', array() );
4634
-
4635
- if ( ! is_array( $updates ) ) {
4636
- $updates = array();
4637
- }
4638
-
4639
- return $updates;
4640
- }
4641
-
4642
- /**
4643
- * @author Vova Feldman (@svovaf)
4644
- * @since 1.0.6
4645
- *
4646
- * @return FS_Plugin[]|false
4647
- */
4648
- private static function get_all_addons() {
4649
- $addons = self::$_accounts->get_option( 'addons', array() );
4650
-
4651
- if ( ! is_array( $addons ) ) {
4652
- $addons = array();
4653
- }
4654
-
4655
- return $addons;
4656
- }
4657
-
4658
- /**
4659
- * @author Vova Feldman (@svovaf)
4660
- * @since 1.0.6
4661
- *
4662
- * @return FS_Plugin[]|false
4663
- */
4664
- private static function get_all_account_addons() {
4665
- $addons = self::$_accounts->get_option( 'account_addons', array() );
4666
-
4667
- if ( ! is_array( $addons ) ) {
4668
- $addons = array();
4669
- }
4670
-
4671
- return $addons;
4672
- }
4673
-
4674
- /**
4675
- * Check if user is registered.
4676
- *
4677
- * @author Vova Feldman (@svovaf)
4678
- * @since 1.0.1
4679
- * @return bool
4680
- */
4681
- function is_registered() {
4682
- return is_object( $this->_user );
4683
- }
4684
-
4685
- /**
4686
- * @author Vova Feldman (@svovaf)
4687
- * @since 1.0.4
4688
- *
4689
- * @return FS_Plugin
4690
- */
4691
- function get_plugin() {
4692
- return $this->_plugin;
4693
- }
4694
-
4695
- /**
4696
- * @author Vova Feldman (@svovaf)
4697
- * @since 1.0.3
4698
- *
4699
- * @return FS_User
4700
- */
4701
- function get_user() {
4702
- return $this->_user;
4703
- }
4704
-
4705
- /**
4706
- * @author Vova Feldman (@svovaf)
4707
- * @since 1.0.3
4708
- *
4709
- * @return FS_Site
4710
- */
4711
- function get_site() {
4712
- return $this->_site;
4713
- }
4714
-
4715
- /**
4716
- * Get plugin add-ons.
4717
- *
4718
- * @author Vova Feldman (@svovaf)
4719
- * @since 1.0.6
4720
- *
4721
- * @since 1.1.7.3 If not yet loaded, fetch data from the API.
4722
- *
4723
- * @return FS_Plugin[]|false
4724
- */
4725
- function get_addons() {
4726
- $this->_logger->entrance();
4727
-
4728
- if ( ! $this->_has_addons ) {
4729
- return false;
4730
- }
4731
-
4732
- $addons = $this->_sync_addons();
4733
-
4734
- return ( ! is_array( $addons ) || empty( $addons ) ) ?
4735
- false :
4736
- $addons;
4737
- }
4738
-
4739
- /**
4740
- * @author Vova Feldman (@svovaf)
4741
- * @since 1.0.6
4742
- *
4743
- * @return FS_Plugin[]|false
4744
- */
4745
- function get_account_addons() {
4746
- $this->_logger->entrance();
4747
-
4748
- $addons = self::get_all_account_addons();
4749
-
4750
- if ( ! is_array( $addons ) ||
4751
- ! isset( $addons[ $this->_plugin->id ] ) ||
4752
- ! is_array( $addons[ $this->_plugin->id ] ) ||
4753
- 0 === count( $addons[ $this->_plugin->id ] )
4754
- ) {
4755
- return false;
4756
- }
4757
-
4758
- return $addons[ $this->_plugin->id ];
4759
- }
4760
-
4761
- /**
4762
- * Check if user has any
4763
- *
4764
- * @author Vova Feldman (@svovaf)
4765
- * @since 1.1.6
4766
- *
4767
- * @return bool
4768
- */
4769
- function has_account_addons() {
4770
- $addons = $this->get_account_addons();
4771
-
4772
- return is_array( $addons ) && ( 0 < count( $addons ) );
4773
- }
4774
-
4775
-
4776
- /**
4777
- * Get add-on by ID (from local data).
4778
- *
4779
- * @author Vova Feldman (@svovaf)
4780
- * @since 1.0.6
4781
- *
4782
- * @param number $id
4783
- *
4784
- * @return FS_Plugin|false
4785
- */
4786
- function get_addon( $id ) {
4787
- $this->_logger->entrance();
4788
-
4789
- $addons = $this->get_addons();
4790
-
4791
- if ( is_array( $addons ) ) {
4792
- foreach ( $addons as $addon ) {
4793
- if ( $id == $addon->id ) {
4794
- return $addon;
4795
- }
4796
- }
4797
- }
4798
-
4799
- return false;
4800
- }
4801
-
4802
- /**
4803
- * Get add-on by slug (from local data).
4804
- *
4805
- * @author Vova Feldman (@svovaf)
4806
- * @since 1.0.6
4807
- *
4808
- * @param string $slug
4809
- *
4810
- * @return FS_Plugin|false
4811
- */
4812
- function get_addon_by_slug( $slug ) {
4813
- $this->_logger->entrance();
4814
-
4815
- $addons = $this->get_addons();
4816
-
4817
- if ( is_array( $addons ) ) {
4818
- foreach ( $addons as $addon ) {
4819
- if ( $slug === $addon->slug ) {
4820
- return $addon;
4821
- }
4822
- }
4823
- }
4824
-
4825
- return false;
4826
- }
4827
-
4828
- #region Plans & Licensing ------------------------------------------------------------------
4829
-
4830
- /**
4831
- * Check if running premium plugin code.
4832
- *
4833
- * @author Vova Feldman (@svovaf)
4834
- * @since 1.0.5
4835
- *
4836
- * @return bool
4837
- */
4838
- function is_premium() {
4839
- return $this->_plugin->is_premium;
4840
- }
4841
-
4842
- /**
4843
- * Get site's plan ID.
4844
- *
4845
- * @author Vova Feldman (@svovaf)
4846
- * @since 1.0.2
4847
- *
4848
- * @return number
4849
- */
4850
- function get_plan_id() {
4851
- return $this->_site->plan->id;
4852
- }
4853
-
4854
- /**
4855
- * Get site's plan title.
4856
- *
4857
- * @author Vova Feldman (@svovaf)
4858
- * @since 1.0.2
4859
- *
4860
- * @return string
4861
- */
4862
- function get_plan_title() {
4863
- return $this->_site->plan->title;
4864
- }
4865
-
4866
- /**
4867
- * @author Vova Feldman (@svovaf)
4868
- * @since 1.0.9
4869
- *
4870
- * @return FS_Plugin_Plan
4871
- */
4872
- function get_plan() {
4873
- return is_object( $this->_site->plan ) ? $this->_site->plan : false;
4874
- }
4875
-
4876
- /**
4877
- * @author Vova Feldman (@svovaf)
4878
- * @since 1.0.3
4879
- *
4880
- * @return bool
4881
- */
4882
- function is_trial() {
4883
- $this->_logger->entrance();
4884
-
4885
- if ( ! $this->is_registered() ) {
4886
- return false;
4887
- }
4888
-
4889
- return $this->_site->is_trial();
4890
- }
4891
-
4892
- /**
4893
- * Check if currently in a trial with payment method (credit card or paypal).
4894
- *
4895
- * @author Vova Feldman (@svovaf)
4896
- * @since 1.1.7
4897
- *
4898
- * @return bool
4899
- */
4900
- function is_paid_trial() {
4901
- $this->_logger->entrance();
4902
-
4903
- if ( ! $this->is_trial() ) {
4904
- return false;
4905
- }
4906
-
4907
- return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
4908
- }
4909
-
4910
- /**
4911
- * Check if trial already utilized.
4912
- *
4913
- * @since 1.0.9
4914
- *
4915
- * @return bool
4916
- */
4917
- function is_trial_utilized() {
4918
- $this->_logger->entrance();
4919
-
4920
- if ( ! $this->is_registered() ) {
4921
- return false;
4922
- }
4923
-
4924
- return $this->_site->is_trial_utilized();
4925
- }
4926
-
4927
- /**
4928
- * Get trial plan information (if in trial).
4929
- *
4930
- * @author Vova Feldman (@svovaf)
4931
- * @since 1.0.9
4932
- *
4933
- * @return bool|FS_Plugin_Plan
4934
- */
4935
- function get_trial_plan() {
4936
- $this->_logger->entrance();
4937
-
4938
- if ( ! $this->is_trial() ) {
4939
- return false;
4940
- }
4941
-
4942
- return $this->_storage->trial_plan;
4943
- }
4944
-
4945
- /**
4946
- * Check if the user has an activate, non-expired license on current plugin's install.
4947
- *
4948
- * @since 1.0.9
4949
- *
4950
- * @return bool
4951
- */
4952
- function is_paying() {
4953
- $this->_logger->entrance();
4954
-
4955
- if ( ! $this->is_registered() ) {
4956
- return false;
4957
- }
4958
-
4959
- if ( ! $this->has_paid_plan() ) {
4960
- return false;
4961
- }
4962
-
4963
- return (
4964
- ! $this->is_trial() &&
4965
- 'free' !== $this->_site->plan->name &&
4966
- $this->has_active_valid_license()
4967
- );
4968
- }
4969
-
4970
- /**
4971
- * @author Vova Feldman (@svovaf)
4972
- * @since 1.0.4
4973
- *
4974
- * @return bool
4975
- */
4976
- function is_free_plan() {
4977
- if ( ! $this->is_registered() ) {
4978
- return true;
4979
- }
4980
-
4981
- if ( ! $this->has_paid_plan() ) {
4982
- return true;
4983
- }
4984
-
4985
- return (
4986
- 'free' === $this->_site->plan->name ||
4987
- ! $this->has_features_enabled_license()
4988
- );
4989
- }
4990
-
4991
- /**
4992
- * @author Vova Feldman (@svovaf)
4993
- * @since 1.0.5
4994
- *
4995
- * @return bool
4996
- */
4997
- function _has_premium_license() {
4998
- $this->_logger->entrance();
4999
-
5000
- $premium_license = $this->_get_available_premium_license();
5001
-
5002
- return ( false !== $premium_license );
5003
- }
5004
-
5005
- /**
5006
- * Check if user has any licenses associated with the plugin (including expired or blocking).
5007
- *
5008
- * @author Vova Feldman (@svovaf)
5009
- * @since 1.1.7.3
5010
- *
5011
- * @return bool
5012
- */
5013
- private function has_any_license() {
5014
- return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
5015
- }
5016
-
5017
- /**
5018
- * @author Vova Feldman (@svovaf)
5019
- * @since 1.0.5
5020
- *
5021
- * @return FS_Plugin_License
5022
- */
5023
- function _get_available_premium_license() {
5024
- $this->_logger->entrance();
5025
-
5026
- if ( ! $this->has_paid_plan() ) {
5027
- return false;
5028
- }
5029
-
5030
- if ( is_array( $this->_licenses ) ) {
5031
- foreach ( $this->_licenses as $license ) {
5032
- if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
5033
- return $license;
5034
- }
5035
- }
5036
- }
5037
-
5038
- return false;
5039
- }
5040
-
5041
- /**
5042
- * Sync local plugin plans with remote server.
5043
- *
5044
- * @author Vova Feldman (@svovaf)
5045
- * @since 1.0.5
5046
- *
5047
- * @return FS_Plugin_Plan[]|object
5048
- */
5049
- function _sync_plans() {
5050
- $plans = $this->_fetch_plugin_plans();
5051
- if ( ! $this->is_api_error( $plans ) ) {
5052
- $this->_plans = $plans;
5053
- $this->_store_plans();
5054
- }
5055
-
5056
- $this->do_action( 'after_plans_sync', $plans );
5057
-
5058
- return $this->_plans;
5059
- }
5060
-
5061
- /**
5062
- * @author Vova Feldman (@svovaf)
5063
- * @since 1.0.5
5064
- *
5065
- * @param number $id
5066
- *
5067
- * @return FS_Plugin_Plan
5068
- */
5069
- function _get_plan_by_id( $id ) {
5070
- $this->_logger->entrance();
5071
-
5072
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
5073
- $this->_sync_plans();
5074
- }
5075
-
5076
- foreach ( $this->_plans as $plan ) {
5077
- if ( $id == $plan->id ) {
5078
- return $plan;
5079
- }
5080
- }
5081
-
5082
- return false;
5083
- }
5084
-
5085
- /**
5086
- * @author Vova Feldman (@svovaf)
5087
- * @since 1.1.8.1
5088
- *
5089
- * @param string $name
5090
- *
5091
- * @return FS_Plugin_Plan|false
5092
- */
5093
- private function get_plan_by_name( $name ) {
5094
- $this->_logger->entrance();
5095
-
5096
- if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
5097
- $this->_sync_plans();
5098
- }
5099
-
5100
- foreach ( $this->_plans as $plan ) {
5101
- if ( $name == $plan->name ) {
5102
- return $plan;
5103
- }
5104
- }
5105
-
5106
- return false;
5107
- }
5108
-
5109
- /**
5110
- * Sync local plugin plans with remote server.
5111
- *
5112
- * @author Vova Feldman (@svovaf)
5113
- * @since 1.0.6
5114
- *
5115
- * @param number|bool $site_license_id
5116
- *
5117
- * @return FS_Plugin_License[]|object
5118
- */
5119
- function _sync_licenses( $site_license_id = false ) {
5120
- $licenses = $this->_fetch_licenses( false, $site_license_id );
5121
- if ( ! $this->is_api_error( $licenses ) ) {
5122
- $this->_licenses = $licenses;
5123
- $this->_store_licenses();
5124
- }
5125
-
5126
- // Update current license.
5127
- if ( is_object( $this->_license ) ) {
5128
- $this->_license = $this->_get_license_by_id( $this->_license->id );
5129
- }
5130
-
5131
- return $this->_licenses;
5132
- }
5133
-
5134
- /**
5135
- * @author Vova Feldman (@svovaf)
5136
- * @since 1.0.5
5137
- *
5138
- * @param number $id
5139
- *
5140
- * @return FS_Plugin_License
5141
- */
5142
- function _get_license_by_id( $id ) {
5143
- $this->_logger->entrance();
5144
-
5145
- if ( ! is_numeric( $id ) ) {
5146
- return false;
5147
- }
5148
-
5149
- if ( ! $this->has_any_license() ) {
5150
- $this->_sync_licenses();
5151
- }
5152
-
5153
- foreach ( $this->_licenses as $license ) {
5154
- if ( $id == $license->id ) {
5155
- return $license;
5156
- }
5157
- }
5158
-
5159
- return false;
5160
- }
5161
-
5162
- /**
5163
- * Sync site's license with user licenses.
5164
- *
5165
- * @author Vova Feldman (@svovaf)
5166
- * @since 1.0.6
5167
- *
5168
- * @param FS_Plugin_License|null $new_license
5169
- */
5170
- function _update_site_license( $new_license ) {
5171
- $this->_logger->entrance();
5172
-
5173
- $this->_license = $new_license;
5174
-
5175
- if ( ! is_object( $new_license ) ) {
5176
- $this->_site->license_id = null;
5177
- $this->_sync_site_subscription( null );
5178
-
5179
- return;
5180
- }
5181
-
5182
- $this->_site->license_id = $this->_license->id;
5183
-
5184
- if ( ! is_array( $this->_licenses ) ) {
5185
- $this->_licenses = array();
5186
- }
5187
-
5188
- $is_license_found = false;
5189
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
5190
- if ( $new_license->id == $this->_licenses[ $i ]->id ) {
5191
- $this->_licenses[ $i ] = $new_license;
5192
-
5193
- $is_license_found = true;
5194
- break;
5195
- }
5196
- }
5197
-
5198
- // If new license just append.
5199
- if ( ! $is_license_found ) {
5200
- $this->_licenses[] = $new_license;
5201
- }
5202
-
5203
- $this->_sync_site_subscription( $new_license );
5204
- }
5205
-
5206
- /**
5207
- * Sync site's subscription.
5208
- *
5209
- * @author Vova Feldman (@svovaf)
5210
- * @since 1.0.9
5211
- *
5212
- * @param FS_Plugin_License|null $license
5213
- *
5214
- * @return bool|\FS_Subscription
5215
- */
5216
- private function _sync_site_subscription( $license ) {
5217
- if ( ! is_object( $license ) ) {
5218
- unset( $this->_storage->subscription );
5219
-
5220
- return false;
5221
- }
5222
-
5223
- // Load subscription details if not lifetime.
5224
- $subscription = $license->is_lifetime() ?
5225
- false :
5226
- $this->_fetch_site_license_subscription();
5227
-
5228
- if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
5229
- $this->_storage->subscription = $subscription;
5230
- } else {
5231
- unset( $this->_storage->subscription );
5232
- }
5233
-
5234
- return $subscription;
5235
- }
5236
-
5237
- /**
5238
- * @author Vova Feldman (@svovaf)
5239
- * @since 1.0.6
5240
- *
5241
- * @return bool|\FS_Plugin_License
5242
- */
5243
- function _get_license() {
5244
- return $this->_license;
5245
- }
5246
-
5247
- /**
5248
- * @return bool|\FS_Subscription
5249
- */
5250
- function _get_subscription() {
5251
- return isset( $this->_storage->subscription ) ?
5252
- $this->_storage->subscription :
5253
- false;
5254
- }
5255
-
5256
- /**
5257
- * @author Vova Feldman (@svovaf)
5258
- * @since 1.0.2
5259
- *
5260
- * @param string $plan Plan name
5261
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
5262
- *
5263
- * @return bool
5264
- */
5265
- function is_plan( $plan, $exact = false ) {
5266
- $this->_logger->entrance();
5267
-
5268
- if ( ! $this->is_registered() ) {
5269
- return false;
5270
- }
5271
-
5272
- $plan = strtolower( $plan );
5273
-
5274
- if ( $this->_site->plan->name === $plan ) // Exact plan.
5275
- {
5276
- return true;
5277
- } else if ( $exact ) // Required exact, but plans are different.
5278
- {
5279
- return false;
5280
- }
5281
-
5282
- $current_plan_order = - 1;
5283
- $required_plan_order = - 1;
5284
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5285
- if ( $plan === $this->_plans[ $i ]->name ) {
5286
- $required_plan_order = $i;
5287
- } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
5288
- $current_plan_order = $i;
5289
- }
5290
- }
5291
-
5292
- return ( $current_plan_order > $required_plan_order );
5293
- }
5294
-
5295
- /**
5296
- * Check if plan based on trial. If not in trial mode, should return false.
5297
- *
5298
- * @since 1.0.9
5299
- *
5300
- * @param string $plan Plan name
5301
- * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
5302
- *
5303
- * @return bool
5304
- */
5305
- function is_trial_plan( $plan, $exact = false ) {
5306
- $this->_logger->entrance();
5307
-
5308
- if ( ! $this->is_registered() ) {
5309
- return false;
5310
- }
5311
-
5312
- if ( ! $this->is_trial() ) {
5313
- return false;
5314
- }
5315
-
5316
- if ( ! isset( $this->_storage->trial_plan ) ) {
5317
- // Store trial plan information.
5318
- $this->_enrich_site_trial_plan( true );
5319
- }
5320
-
5321
- if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
5322
- {
5323
- return true;
5324
- } else if ( $exact ) // Required exact, but plans are different.
5325
- {
5326
- return false;
5327
- }
5328
-
5329
- $current_plan_order = - 1;
5330
- $required_plan_order = - 1;
5331
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5332
- if ( $plan === $this->_plans[ $i ]->name ) {
5333
- $required_plan_order = $i;
5334
- } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
5335
- $current_plan_order = $i;
5336
- }
5337
- }
5338
-
5339
- return ( $current_plan_order > $required_plan_order );
5340
- }
5341
-
5342
- /**
5343
- * Check if plugin has any paid plans.
5344
- *
5345
- * @author Vova Feldman (@svovaf)
5346
- * @since 1.0.7
5347
- *
5348
- * @return bool
5349
- */
5350
- function has_paid_plan() {
5351
- return $this->_has_paid_plans ||
5352
- FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
5353
- }
5354
-
5355
- /**
5356
- * Check if plugin has any plan with a trail.
5357
- *
5358
- * @author Vova Feldman (@svovaf)
5359
- * @since 1.0.9
5360
- *
5361
- * @return bool
5362
- */
5363
- function has_trial_plan() {
5364
- if ( ! $this->is_registered() ) {
5365
- return false;
5366
- }
5367
-
5368
- return $this->_storage->get( 'has_trial_plan', false );
5369
- }
5370
-
5371
- /**
5372
- * Check if plugin has any free plan, or is it premium only.
5373
- *
5374
- * Note: If no plans configured, assume plugin is free.
5375
- *
5376
- * @author Vova Feldman (@svovaf)
5377
- * @since 1.0.7
5378
- *
5379
- * @return bool
5380
- */
5381
- function has_free_plan() {
5382
- return ! $this->is_premium() ||
5383
- ! $this->is_only_premium() ||
5384
- FS_Plan_Manager::instance()->has_free_plan( $this->_plans );
5385
- }
5386
-
5387
- /**
5388
- * Displays a license activation dialog box when the user clicks on the "Activate License"
5389
- * or "Change License" link on the plugins
5390
- * page.
5391
- *
5392
- * @author Leo Fajardo (@leorw)
5393
- * @since 1.1.9
5394
- */
5395
- function _add_license_activation_dialog_box() {
5396
- $vars = array(
5397
- 'slug' => $this->_slug,
5398
- );
5399
-
5400
- fs_require_template( 'forms/license-activation.php', $vars );
5401
- fs_require_template( 'forms/resend-key.php', $vars );
5402
- }
5403
-
5404
- /**
5405
- * Prepare page to include all required UI and logic for the license activation dialog.
5406
- *
5407
- * @author Vova Feldman (@svovaf)
5408
- * @since 1.2.0
5409
- */
5410
- function _require_license_activation_dialog() {
5411
- if ( $this->is_ajax() ) {
5412
- if ( $this->is_ajax_action( 'activate_license' ) ) {
5413
- // Add license activation AJAX callback.
5414
- $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
5415
- }
5416
-
5417
- if ( $this->is_ajax_action( 'resend_license_key' ) ) {
5418
- // Add resend license AJAX callback.
5419
- $this->add_ajax_action( 'resend_license_key', array(
5420
- &$this,
5421
- '_resend_license_key_ajax_action'
5422
- ) );
5423
- }
5424
- } else {
5425
- // Inject license activation dialog UI and client side code.
5426
- add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
5427
- }
5428
- }
5429
-
5430
- /**
5431
- * @author Leo Fajardo (@leorw)
5432
- * @since 1.1.9
5433
- */
5434
- function _activate_license_ajax_action() {
5435
- $license_key = trim( fs_request_get( 'license_key' ) );
5436
-
5437
- if ( empty( $license_key ) ) {
5438
- exit;
5439
- }
5440
-
5441
- $slug = $_POST['slug'];
5442
- $fs = ( ( $slug === $this->_slug ) ? $this : self::instance( $slug ) );
5443
- $error = false;
5444
-
5445
- if ( $this->is_registered() ) {
5446
- $api = $fs->get_api_site_scope();
5447
- $install = $api->call( '/', 'put',
5448
- array(
5449
- 'license_key' => $license_key
5450
- )
5451
- );
5452
-
5453
- if ( isset( $install->error ) ) {
5454
- $error = $install->error->message;
5455
- }
5456
- } else {
5457
- $install = $this->opt_in( false, false, false, $license_key );
5458
-
5459
- if ( isset( $install->error ) ) {
5460
- $error = $install->error;
5461
- }
5462
- }
5463
-
5464
- $result = array(
5465
- 'success' => ( false === $error )
5466
- );
5467
-
5468
- if ( false !== $error ) {
5469
- $result['error'] = $error;
5470
- }
5471
-
5472
- echo json_encode( $result );
5473
-
5474
- exit;
5475
- }
5476
-
5477
- /**
5478
- * @author Leo Fajardo (@leorw)
5479
- * @since 1.2.0
5480
- */
5481
- function _resend_license_key_ajax_action() {
5482
- if ( ! isset( $_POST['email'] ) ) {
5483
- exit;
5484
- }
5485
-
5486
- $email_address = trim( $_POST['email'] );
5487
- if ( empty( $email_address ) ) {
5488
- exit;
5489
- }
5490
-
5491
- $error = false;
5492
-
5493
- $api = $this->get_api_plugin_scope();
5494
- $result = $api->call( '/licenses/resend.json', 'post',
5495
- array(
5496
- 'email' => $email_address,
5497
- 'is_localhost' => WP_FS__IS_LOCALHOST
5498
- )
5499
- );
5500
-
5501
- if ( is_object( $result ) && isset( $result->error ) ) {
5502
- $error = $result->error;
5503
-
5504
- if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
5505
- $error = __fs( 'email-not-found' );
5506
- } else if ( 'no_license' === $error->code ) {
5507
- $error = __fs( 'no-active-licenses' );
5508
- } else {
5509
- $error = $error->message;
5510
- }
5511
- }
5512
-
5513
- $licenses = array(
5514
- 'success' => ( false === $error )
5515
- );
5516
-
5517
- if ( false !== $error ) {
5518
- $licenses['error'] = sprintf( '%s... %s', __fs( 'oops', $this->_slug ), strtolower( $error ) );
5519
- }
5520
-
5521
- echo json_encode( $licenses );
5522
-
5523
- exit;
5524
- }
5525
-
5526
- #region URL Generators
5527
-
5528
- /**
5529
- * Alias to pricing_url().
5530
- *
5531
- * @author Vova Feldman (@svovaf)
5532
- * @since 1.0.2
5533
- *
5534
- * @uses pricing_url()
5535
- *
5536
- * @param string $period Billing cycle
5537
- * @param bool $is_trial
5538
- *
5539
- * @return string
5540
- */
5541
- function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
5542
- return $this->pricing_url( $period, $is_trial );
5543
- }
5544
-
5545
- /**
5546
- * @author Vova Feldman (@svovaf)
5547
- * @since 1.0.9
5548
- *
5549
- * @uses get_upgrade_url()
5550
- *
5551
- * @return string
5552
- */
5553
- function get_trial_url() {
5554
- return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
5555
- }
5556
-
5557
- /**
5558
- * Plugin's pricing URL.
5559
- *
5560
- * @author Vova Feldman (@svovaf)
5561
- * @since 1.0.4
5562
- *
5563
- * @param string $billing_cycle Billing cycle
5564
- *
5565
- * @param bool $is_trial
5566
- *
5567
- * @return string
5568
- */
5569
- function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
5570
- $this->_logger->entrance();
5571
-
5572
- $params = array(
5573
- 'billing_cycle' => $billing_cycle
5574
- );
5575
-
5576
- if ( $is_trial ) {
5577
- $params['trial'] = 'true';
5578
- }
5579
-
5580
- return $this->_get_admin_page_url( 'pricing', $params );
5581
- }
5582
-
5583
- /**
5584
- * Checkout page URL.
5585
- *
5586
- * @author Vova Feldman (@svovaf)
5587
- * @since 1.0.6
5588
- *
5589
- * @param string $billing_cycle Billing cycle
5590
- * @param bool $is_trial
5591
- * @param array $extra (optional) Extra parameters, override other query params.
5592
- *
5593
- * @return string
5594
- */
5595
- function checkout_url(
5596
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5597
- $is_trial = false,
5598
- $extra = array()
5599
- ) {
5600
- $this->_logger->entrance();
5601
-
5602
- $params = array(
5603
- 'checkout' => 'true',
5604
- 'billing_cycle' => $billing_cycle,
5605
- );
5606
-
5607
- if ( $is_trial ) {
5608
- $params['trial'] = 'true';
5609
- }
5610
-
5611
- /**
5612
- * Params in extra override other params.
5613
- */
5614
- $params = array_merge( $params, $extra );
5615
-
5616
- return $this->_get_admin_page_url( 'pricing', $params );
5617
- }
5618
-
5619
- /**
5620
- * Add-on checkout URL.
5621
- *
5622
- * @author Vova Feldman (@svovaf)
5623
- * @since 1.1.7
5624
- *
5625
- * @param number $addon_id
5626
- * @param number $pricing_id
5627
- * @param string $billing_cycle
5628
- * @param bool $is_trial
5629
- *
5630
- * @return string
5631
- */
5632
- function addon_checkout_url(
5633
- $addon_id,
5634
- $pricing_id,
5635
- $billing_cycle = WP_FS__PERIOD_ANNUALLY,
5636
- $is_trial = false
5637
- ) {
5638
- return $this->checkout_url( $billing_cycle, $is_trial, array(
5639
- 'plugin_id' => $addon_id,
5640
- 'pricing_id' => $pricing_id,
5641
- ) );
5642
- }
5643
-
5644
- #endregion
5645
-
5646
- #endregion ------------------------------------------------------------------
5647
-
5648
- /**
5649
- * Check if plugin has any add-ons.
5650
- *
5651
- * @author Vova Feldman (@svovaf)
5652
- * @since 1.0.5
5653
- *
5654
- * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
5655
- *
5656
- * @return bool
5657
- */
5658
- function has_addons() {
5659
- $this->_logger->entrance();
5660
-
5661
- return $this->_has_addons;
5662
- }
5663
-
5664
- /**
5665
- * Check if plugin can work in anonymous mode.
5666
- *
5667
- * @author Vova Feldman (@svovaf)
5668
- * @since 1.0.9
5669
- *
5670
- * @return bool
5671
- *
5672
- * @deprecated Please use is_enable_anonymous() instead
5673
- */
5674
- function enable_anonymous() {
5675
- return $this->_enable_anonymous;
5676
- }
5677
-
5678
- /**
5679
- * Check if plugin can work in anonymous mode.
5680
- *
5681
- * @author Vova Feldman (@svovaf)
5682
- * @since 1.1.9
5683
- *
5684
- * @return bool
5685
- */
5686
- function is_enable_anonymous() {
5687
- return $this->_enable_anonymous;
5688
- }
5689
-
5690
- /**
5691
- * Check if plugin is premium only (no free plans).
5692
- *
5693
- * @author Vova Feldman (@svovaf)
5694
- * @since 1.1.9
5695
- *
5696
- * @return bool
5697
- */
5698
- function is_only_premium() {
5699
- return $this->_is_premium_only;
5700
- }
5701
-
5702
- /**
5703
- * Check if feature supported with current site's plan.
5704
- *
5705
- * @author Vova Feldman (@svovaf)
5706
- * @since 1.0.1
5707
- *
5708
- * @todo IMPLEMENT
5709
- *
5710
- * @param number $feature_id
5711
- *
5712
- * @throws Exception
5713
- */
5714
- function is_feature_supported( $feature_id ) {
5715
- throw new Exception( 'not implemented' );
5716
- }
5717
-
5718
- /**
5719
- * @author Vova Feldman (@svovaf)
5720
- * @since 1.0.1
5721
- *
5722
- * @return bool Is running in SSL/HTTPS
5723
- */
5724
- function is_ssl() {
5725
- return WP_FS__IS_HTTPS;
5726
- }
5727
-
5728
- /**
5729
- * @author Vova Feldman (@svovaf)
5730
- * @since 1.0.9
5731
- *
5732
- * @return bool Is running in AJAX call.
5733
- *
5734
- * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
5735
- */
5736
- function is_ajax() {
5737
- return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
5738
- }
5739
-
5740
- /**
5741
- * Check if it's an AJAX call targeted for the current module.
5742
- *
5743
- * @author Vova Feldman (@svovaf)
5744
- * @since 1.2.0
5745
- *
5746
- * @param array|string $actions Collection of AJAX actions.
5747
- *
5748
- * @return bool
5749
- */
5750
- function is_ajax_action( $actions ) {
5751
- // Verify it's an ajax call.
5752
- if ( ! $this->is_ajax() ) {
5753
- return false;
5754
- }
5755
-
5756
- // Verify the call is relevant for the plugin.
5757
- if ( $this->_slug !== fs_request_get( 'slug' ) ) {
5758
- return false;
5759
- }
5760
-
5761
- // Verify it's one of the specified actions.
5762
- if ( is_string( $actions ) ) {
5763
- $actions = explode( ',', $actions );
5764
- }
5765
-
5766
- if ( is_array( $actions ) && 0 < count( $actions ) ) {
5767
- $ajax_action = fs_request_get( 'action' );
5768
-
5769
- foreach ( $actions as $action ) {
5770
- if ( $ajax_action === $this->get_action_tag( $action ) ) {
5771
- return true;
5772
- }
5773
- }
5774
- }
5775
-
5776
- return false;
5777
- }
5778
-
5779
- /**
5780
- * @author Vova Feldman (@svovaf)
5781
- * @since 1.1.7
5782
- *
5783
- * @return bool
5784
- */
5785
- function is_cron() {
5786
- return ( defined( 'DOING_CRON' ) && DOING_CRON );
5787
- }
5788
-
5789
- /**
5790
- * Check if a real user is visiting the admin dashboard.
5791
- *
5792
- * @author Vova Feldman (@svovaf)
5793
- * @since 1.1.7
5794
- *
5795
- * @return bool
5796
- */
5797
- function is_user_in_admin() {
5798
- return is_admin() && ! $this->is_ajax() && ! $this->is_cron();
5799
- }
5800
-
5801
- /**
5802
- * Check if running in HTTPS and if site's plan matching the specified plan.
5803
- *
5804
- * @param string $plan
5805
- * @param bool $exact
5806
- *
5807
- * @return bool
5808
- */
5809
- function is_ssl_and_plan( $plan, $exact = false ) {
5810
- return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
5811
- }
5812
-
5813
- /**
5814
- * Construct plugin's settings page URL.
5815
- *
5816
- * @author Vova Feldman (@svovaf)
5817
- * @since 1.0.4
5818
- *
5819
- * @param string $page
5820
- * @param array $params
5821
- *
5822
- * @return string
5823
- */
5824
- function _get_admin_page_url( $page = '', $params = array() ) {
5825
- if ( 0 < count( $params ) ) {
5826
- foreach ( $params as $k => $v ) {
5827
- $params[ $k ] = urlencode( $v );
5828
- }
5829
- }
5830
-
5831
- if ( ! $this->_menu->is_top_level() ) {
5832
- $parent_slug = $this->_menu->get_parent_slug();
5833
- $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
5834
- $parent_slug :
5835
- 'admin.php';
5836
-
5837
- return add_query_arg( array_merge( $params, array(
5838
- 'page' => $this->_menu->get_slug( $page ),
5839
- ) ), admin_url( $menu_file, 'admin' ) );
5840
- }
5841
-
5842
- if ( $this->_menu->is_cpt() ) {
5843
- if ( empty( $page ) && $this->is_activation_mode() ) {
5844
- return add_query_arg( array_merge( $params, array(
5845
- 'page' => $this->_menu->get_slug()
5846
- ) ), admin_url( 'admin.php', 'admin' ) );
5847
- } else {
5848
- if ( ! empty( $page ) ) {
5849
- $params['page'] = $this->_menu->get_slug( $page );
5850
- }
5851
-
5852
- return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
5853
- }
5854
- } else {
5855
- return add_query_arg( array_merge( $params, array(
5856
- 'page' => $this->_menu->get_slug( $page ),
5857
- ) ), admin_url( 'admin.php', 'admin' ) );
5858
- }
5859
- }
5860
-
5861
- /**
5862
- * Plugin's account page + sync license URL.
5863
- *
5864
- * @author Vova Feldman (@svovaf)
5865
- * @since 1.1.9.1
5866
- *
5867
- * @param bool|number $plugin_id
5868
- * @param bool $add_action_nonce
5869
- *
5870
- * @return string
5871
- */
5872
- function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true ) {
5873
- $params = array();
5874
-
5875
- if ( is_numeric( $plugin_id ) ) {
5876
- $params['plugin_id'] = $plugin_id;
5877
- }
5878
-
5879
- return $this->get_account_url(
5880
- $this->_slug . '_sync_license',
5881
- $params,
5882
- $add_action_nonce
5883
- );
5884
- }
5885
-
5886
- /**
5887
- * Plugin's account URL.
5888
- *
5889
- * @author Vova Feldman (@svovaf)
5890
- * @since 1.0.4
5891
- *
5892
- * @param bool|string $action
5893
- * @param array $params
5894
- *
5895
- * @param bool $add_action_nonce
5896
- *
5897
- * @return string
5898
- */
5899
- function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
5900
- if ( is_string( $action ) ) {
5901
- $params['fs_action'] = $action;
5902
- }
5903
-
5904
- self::require_pluggable_essentials();
5905
-
5906
- return ( $add_action_nonce && is_string( $action ) ) ?
5907
- wp_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
5908
- $this->_get_admin_page_url( 'account', $params );
5909
- }
5910
-
5911
- /**
5912
- * @author Vova Feldman (@svovaf)
5913
- * @since 1.2.0
5914
- *
5915
- * @param string $tab
5916
- * @param bool $action
5917
- * @param array $params
5918
- * @param bool $add_action_nonce
5919
- *
5920
- * @return string
5921
- *
5922
- * @uses get_account_url()
5923
- */
5924
- function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
5925
- $params['tab'] = $tab;
5926
-
5927
- return $this->get_account_url( $action, $params, $add_action_nonce );
5928
- }
5929
-
5930
- /**
5931
- * Plugin's account URL.
5932
- *
5933
- * @author Vova Feldman (@svovaf)
5934
- * @since 1.0.4
5935
- *
5936
- * @param bool|string $topic
5937
- * @param bool|string $message
5938
- *
5939
- * @return string
5940
- */
5941
- function contact_url( $topic = false, $message = false ) {
5942
- $params = array();
5943
- if ( is_string( $topic ) ) {
5944
- $params['topic'] = $topic;
5945
- }
5946
- if ( is_string( $message ) ) {
5947
- $params['message'] = $message;
5948
- }
5949
-
5950
- if ( $this->is_addon() ) {
5951
- $params['addon_id'] = $this->get_id();
5952
-
5953
- return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
5954
- } else {
5955
- return $this->_get_admin_page_url( 'contact', $params );
5956
- }
5957
- }
5958
-
5959
- /**
5960
- * Add-on direct info URL.
5961
- *
5962
- * @author Vova Feldman (@svovaf)
5963
- * @since 1.1.0
5964
- *
5965
- * @param string $slug
5966
- *
5967
- * @return string
5968
- */
5969
- function addon_url( $slug ) {
5970
- return $this->_get_admin_page_url( 'addons', array(
5971
- 'slug' => $slug
5972
- ) );
5973
- }
5974
-
5975
- /* Logger
5976
- ------------------------------------------------------------------------------------------------------------------*/
5977
- /**
5978
- * @param string $id
5979
- * @param bool $prefix_slug
5980
- *
5981
- * @return FS_Logger
5982
- */
5983
- function get_logger( $id = '', $prefix_slug = true ) {
5984
- return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
5985
- }
5986
-
5987
- /**
5988
- * @param $id
5989
- * @param bool $load_options
5990
- * @param bool $prefix_slug
5991
- *
5992
- * @return FS_Option_Manager
5993
- */
5994
- function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
5995
- return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
5996
- }
5997
-
5998
- /* Security
5999
- ------------------------------------------------------------------------------------------------------------------*/
6000
- private function _encrypt( $str ) {
6001
- if ( is_null( $str ) ) {
6002
- return null;
6003
- }
6004
-
6005
- return base64_encode( $str );
6006
- }
6007
-
6008
- private function _decrypt( $str ) {
6009
- if ( is_null( $str ) ) {
6010
- return null;
6011
- }
6012
-
6013
- return base64_decode( $str );
6014
- }
6015
-
6016
- /**
6017
- * @author Vova Feldman (@svovaf)
6018
- * @since 1.0.5
6019
- *
6020
- * @param FS_Entity $entity
6021
- *
6022
- * @return FS_Entity Return an encrypted clone entity.
6023
- */
6024
- private function _encrypt_entity( FS_Entity $entity ) {
6025
- $clone = clone $entity;
6026
- $props = get_object_vars( $entity );
6027
-
6028
- foreach ( $props as $key => $val ) {
6029
- $clone->{$key} = $this->_encrypt( $val );
6030
- }
6031
-
6032
- return $clone;
6033
- }
6034
-
6035
- /**
6036
- * @author Vova Feldman (@svovaf)
6037
- * @since 1.0.5
6038
- *
6039
- * @param FS_Entity $entity
6040
- *
6041
- * @return FS_Entity Return an decrypted clone entity.
6042
- */
6043
- private function _decrypt_entity( FS_Entity $entity ) {
6044
- $clone = clone $entity;
6045
- $props = get_object_vars( $entity );
6046
-
6047
- foreach ( $props as $key => $val ) {
6048
- $clone->{$key} = $this->_decrypt( $val );
6049
- }
6050
-
6051
- return $clone;
6052
- }
6053
-
6054
- /**
6055
- * Tries to activate account based on POST params.
6056
- *
6057
- * @author Vova Feldman (@svovaf)
6058
- * @since 1.0.2
6059
- */
6060
- function _activate_account() {
6061
- if ( $this->is_registered() ) {
6062
- // Already activated.
6063
- return;
6064
- }
6065
-
6066
- self::_clean_admin_content_section();
6067
-
6068
- if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
6069
- // check_admin_referer( 'activate_' . $this->_plugin->public_key );
6070
-
6071
- // Verify matching plugin details.
6072
- if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
6073
- return;
6074
- }
6075
-
6076
- $user = new FS_User();
6077
- $user->id = fs_request_get( 'user_id' );
6078
- $user->public_key = fs_request_get( 'user_public_key' );
6079
- $user->secret_key = fs_request_get( 'user_secret_key' );
6080
- $user->email = fs_request_get( 'user_email' );
6081
- $user->first = fs_request_get( 'user_first' );
6082
- $user->last = fs_request_get( 'user_last' );
6083
- $user->is_verified = fs_request_get_bool( 'user_is_verified' );
6084
-
6085
- $site = new FS_Site();
6086
- $site->id = fs_request_get( 'install_id' );
6087
- $site->public_key = fs_request_get( 'install_public_key' );
6088
- $site->secret_key = fs_request_get( 'install_secret_key' );
6089
- $site->plan->id = fs_request_get( 'plan_id' );
6090
- $site->plan->title = fs_request_get( 'plan_title' );
6091
- $site->plan->name = fs_request_get( 'plan_name' );
6092
-
6093
- $plans = array();
6094
- $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
6095
- foreach ( $plans_data as $p ) {
6096
- $plans[] = new FS_Plugin_Plan( $p );
6097
- }
6098
-
6099
- $this->_set_account( $user, $site, $plans );
6100
-
6101
- // Reload the page with the keys.
6102
- if ( fs_redirect( $this->_get_admin_page_url() ) ) {
6103
- exit();
6104
- }
6105
- }
6106
- }
6107
-
6108
- /**
6109
- * @author Vova Feldman (@svovaf)
6110
- * @since 1.0.7
6111
- *
6112
- * @param string $email
6113
- *
6114
- * @return FS_User|bool
6115
- */
6116
- static function _get_user_by_email( $email ) {
6117
- self::$_static_logger->entrance();
6118
-
6119
- $email = trim( strtolower( $email ) );
6120
- $users = self::get_all_users();
6121
- if ( is_array( $users ) ) {
6122
- foreach ( $users as $u ) {
6123
- if ( $email === trim( strtolower( $u->email ) ) ) {
6124
- return $u;
6125
- }
6126
- }
6127
- }
6128
-
6129
- return false;
6130
- }
6131
-
6132
- #region Account (Loading, Updates & Activation) ------------------------------------------------------------------
6133
-
6134
- /***
6135
- * Load account information (user + site).
6136
- *
6137
- * @author Vova Feldman (@svovaf)
6138
- * @since 1.0.1
6139
- */
6140
- private function _load_account() {
6141
- $this->_logger->entrance();
6142
-
6143
- $this->do_action( 'before_account_load' );
6144
-
6145
- $sites = self::get_all_sites();
6146
- $users = self::get_all_users();
6147
- $plans = self::get_all_plans();
6148
- $licenses = self::get_all_licenses();
6149
-
6150
- if ( $this->_logger->is_on() && is_admin() ) {
6151
- $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
6152
- $this->_logger->log( 'users = ' . var_export( $users, true ) );
6153
- $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
6154
- $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
6155
- }
6156
-
6157
- $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
6158
-
6159
- if ( is_object( $site ) &&
6160
- is_numeric( $site->id ) &&
6161
- is_numeric( $site->user_id ) &&
6162
- is_object( $site->plan )
6163
- ) {
6164
- // Load site.
6165
- $this->_site = clone $site;
6166
- $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
6167
-
6168
- // Load relevant user.
6169
- $this->_user = clone $users[ $this->_site->user_id ];
6170
-
6171
- // Load plans.
6172
- $this->_plans = $plans[ $this->_slug ];
6173
- if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
6174
- $this->_sync_plans( true );
6175
- } else {
6176
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6177
- if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
6178
- $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
6179
- } else {
6180
- unset( $this->_plans[ $i ] );
6181
- }
6182
- }
6183
- }
6184
-
6185
- // Load licenses.
6186
- $this->_licenses = array();
6187
- if ( is_array( $licenses ) &&
6188
- isset( $licenses[ $this->_slug ] ) &&
6189
- isset( $licenses[ $this->_slug ][ $this->_user->id ] )
6190
- ) {
6191
- $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
6192
- }
6193
-
6194
- $this->_license = $this->_get_license_by_id( $this->_site->license_id );
6195
-
6196
- if ( $this->_site->version != $this->get_plugin_version() ) {
6197
- // If stored install version is different than current installed plugin version,
6198
- // then update plugin version event.
6199
- $this->update_plugin_version_event();
6200
- }
6201
- }
6202
-
6203
- $this->_register_account_hooks();
6204
- }
6205
-
6206
- /**
6207
- * @author Vova Feldman (@svovaf)
6208
- * @since 1.0.1
6209
- *
6210
- * @param FS_User $user
6211
- * @param FS_Site $site
6212
- * @param bool|array $plans
6213
- */
6214
- private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
6215
- $site->slug = $this->_slug;
6216
- $site->user_id = $user->id;
6217
-
6218
- $this->_site = $site;
6219
- $this->_user = $user;
6220
- if ( false !== $plans ) {
6221
- $this->_plans = $plans;
6222
- }
6223
-
6224
- $this->send_install_update();
6225
-
6226
- $this->_store_account();
6227
-
6228
- }
6229
-
6230
- /**
6231
- * @author Vova Feldman (@svovaf)
6232
- * @since 1.1.7.4
6233
- *
6234
- * @param array $override_with
6235
- *
6236
- * @return array
6237
- */
6238
- function get_opt_in_params( $override_with = array() ) {
6239
- $this->_logger->entrance();
6240
-
6241
- $current_user = self::_get_current_wp_user();
6242
-
6243
- $params = array(
6244
- 'user_firstname' => $current_user->user_firstname,
6245
- 'user_lastname' => $current_user->user_lastname,
6246
- 'user_nickname' => $current_user->user_nicename,
6247
- 'user_email' => $current_user->user_email,
6248
- 'user_ip' => WP_FS__REMOTE_ADDR,
6249
- 'plugin_slug' => $this->_slug,
6250
- 'plugin_id' => $this->get_id(),
6251
- 'plugin_public_key' => $this->get_public_key(),
6252
- 'plugin_version' => $this->get_plugin_version(),
6253
- 'return_url' => wp_nonce_url( $this->_get_admin_page_url(
6254
- '',
6255
- array( 'fs_action' => $this->_slug . '_activate_new' )
6256
- ), $this->_slug . '_activate_new' ),
6257
- 'account_url' => wp_nonce_url( $this->_get_admin_page_url(
6258
- 'account',
6259
- array( 'fs_action' => 'sync_user' )
6260
- ), 'sync_user' ),
6261
- 'site_uid' => $this->get_anonymous_id(),
6262
- 'site_url' => get_site_url(),
6263
- 'site_name' => get_bloginfo( 'name' ),
6264
- 'platform_version' => get_bloginfo( 'version' ),
6265
- 'php_version' => phpversion(),
6266
- 'language' => get_bloginfo( 'language' ),
6267
- 'charset' => get_bloginfo( 'charset' ),
6268
- );
6269
-
6270
- if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
6271
- // Even though rand() is known for its security issues,
6272
- // the timestamp adds another layer of protection.
6273
- // It would be very hard for an attacker to get the secret key form here.
6274
- // Plus, this should never run in production since the secret should never
6275
- // be included in the production version.
6276
- $params['ts'] = WP_FS__SCRIPT_START_TIME;
6277
- $params['salt'] = md5( uniqid( rand() ) );
6278
- $params['secure'] = md5(
6279
- $params['ts'] .
6280
- $params['salt'] .
6281
- $this->get_secret_key()
6282
- );
6283
- }
6284
-
6285
- return array_merge( $params, $override_with );
6286
- }
6287
-
6288
- /**
6289
- * @author Vova Feldman (@svovaf)
6290
- * @since 1.1.7.4
6291
- *
6292
- * @param string|bool $email
6293
- * @param string|bool $first
6294
- * @param string|bool $last
6295
- * @param string|bool $license_key
6296
- * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
6297
- * In this case, the user and site info will be sent to the server but no
6298
- * data will be saved to the WP installation's database.
6299
- *
6300
- * @return bool Is successful opt-in (or set to pending).
6301
- *
6302
- * @use WP_Error
6303
- */
6304
- function opt_in(
6305
- $email = false,
6306
- $first = false,
6307
- $last = false,
6308
- $license_key = false,
6309
- $is_uninstall = false
6310
- ) {
6311
- $this->_logger->entrance();
6312
-
6313
- if ( false === $email ) {
6314
- $current_user = self::_get_current_wp_user();
6315
- $email = $current_user->user_email;
6316
- }
6317
-
6318
- /**
6319
- * @since 1.2.1 If activating with license key, ignore the context-user
6320
- * since the user will be automatically loaded from the license.
6321
- */
6322
- if (empty($license_key)) {
6323
- if ( ! $is_uninstall ) {
6324
- $fs_user = Freemius::_get_user_by_email( $email );
6325
- if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
6326
- return $this->install_with_current_user( false );
6327
- }
6328
- }
6329
- }
6330
-
6331
- $user_info = array();
6332
- if ( ! empty( $email ) ) {
6333
- $user_info['user_email'] = $email;
6334
- }
6335
- if ( ! empty( $first ) ) {
6336
- $user_info['user_firstname'] = $first;
6337
- }
6338
- if ( ! empty( $last ) ) {
6339
- $user_info['user_lastname'] = $last;
6340
- }
6341
-
6342
- $params = $this->get_opt_in_params( $user_info );
6343
-
6344
- if ( is_string( $license_key ) ) {
6345
- $params['license_secret_key'] = $license_key;
6346
- }
6347
-
6348
- if ( $is_uninstall ) {
6349
- $params['uninstall_params'] = array(
6350
- 'reason_id' => $this->_storage->uninstall_reason->id,
6351
- 'reason_info' => $this->_storage->uninstall_reason->info
6352
- );
6353
- }
6354
-
6355
- $params['format'] = 'json';
6356
-
6357
- $url = WP_FS__ADDRESS . '/action/service/user/install/';
6358
- if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
6359
- $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
6360
- }
6361
-
6362
- $response = wp_remote_post( $url, array(
6363
- 'method' => 'POST',
6364
- 'body' => $params,
6365
- 'timeout' => 15,
6366
- ) );
6367
-
6368
- if ( $response instanceof WP_Error ) {
6369
- if ( 'https://' === substr( $url, 0, 8 ) &&
6370
- isset( $response->errors ) &&
6371
- isset( $response->errors['http_request_failed'] ) &&
6372
- false !== strpos( $response->errors['http_request_failed'][0], 'sslv3 alert handshake' )
6373
- ) {
6374
- // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
6375
- $url = 'http://' . substr( $url, 8 );
6376
-
6377
- $response = wp_remote_post( $url, array(
6378
- 'method' => 'POST',
6379
- 'body' => $params,
6380
- 'timeout' => 15,
6381
- ) );
6382
- }
6383
-
6384
- if ( $response instanceof WP_Error ) {
6385
- return false;
6386
- }
6387
- }
6388
-
6389
- if ( is_wp_error( $response ) ) {
6390
- return false;
6391
- }
6392
-
6393
- // Module is being uninstalled, don't handle the returned data.
6394
- if ( $is_uninstall ) {
6395
- return true;
6396
- }
6397
-
6398
- $decoded = @json_decode( $response['body'] );
6399
-
6400
- if ( empty( $decoded ) ) {
6401
- return false;
6402
- }
6403
-
6404
- if ( isset( $decoded->error ) ) {
6405
- return $decoded;
6406
- } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
6407
- // Pending activation, add message.
6408
- $this->set_pending_confirmation( false, false );
6409
-
6410
- return true;
6411
- } else if ( isset( $decoded->install_secret_key ) ) {
6412
- $this->install_with_new_user(
6413
- $decoded->user_id,
6414
- $decoded->user_public_key,
6415
- $decoded->user_secret_key,
6416
- $decoded->install_id,
6417
- $decoded->install_public_key,
6418
- $decoded->install_secret_key,
6419
- false
6420
- );
6421
-
6422
- return true;
6423
- }
6424
-
6425
- return $decoded;
6426
- }
6427
-
6428
- /**
6429
- * Set user and site identities.
6430
- *
6431
- * @author Vova Feldman (@svovaf)
6432
- * @since 1.0.9
6433
- *
6434
- * @param FS_User $user
6435
- * @param FS_Site $site
6436
- * @param bool $redirect
6437
- *
6438
- * @return bool False if account already set.
6439
- */
6440
- function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
6441
- $this->_user = $user;
6442
- $this->_site = $site;
6443
-
6444
- $this->_sync_plans();
6445
-
6446
- $this->_enrich_site_plan( false );
6447
-
6448
- $this->_set_account( $user, $site );
6449
-
6450
- if ( $this->is_trial() ) {
6451
- // Store trial plan information.
6452
- $this->_enrich_site_trial_plan( true );
6453
- }
6454
-
6455
- // If Freemius was OFF before, turn it on.
6456
- $this->turn_on();
6457
-
6458
- $this->do_action( 'after_account_connection', $user, $site );
6459
-
6460
- if ( is_numeric( $site->license_id ) ) {
6461
- $this->_license = $this->_get_license_by_id( $site->license_id );
6462
- }
6463
-
6464
- $this->_admin_notices->remove_sticky( 'connect_account' );
6465
-
6466
- if ( $this->is_pending_activation() ) {
6467
- // Remove pending activation sticky notice (if still exist).
6468
- $this->_admin_notices->remove_sticky( 'activation_pending' );
6469
-
6470
- // Remove plugin from pending activation mode.
6471
- unset( $this->_storage->is_pending_activation );
6472
-
6473
- if ( ! $this->is_paying() ) {
6474
- $this->_admin_notices->add_sticky(
6475
- sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
6476
- 'activation_complete'
6477
- );
6478
- }
6479
- }
6480
-
6481
- if ( $this->is_paying() && ! $this->is_premium() ) {
6482
- $this->_admin_notices->add_sticky(
6483
- sprintf(
6484
- __fs( 'activation-with-plan-x-message', $this->_slug ),
6485
- $this->_site->plan->title
6486
- ) . $this->get_complete_upgrade_instructions(),
6487
- 'plan_upgraded',
6488
- __fs( 'yee-haw', $this->_slug ) . '!'
6489
- );
6490
- }
6491
-
6492
- $plugin_id = fs_request_get( 'plugin_id', false );
6493
-
6494
- // Store activation time ONLY for plugins (not add-ons).
6495
- if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
6496
- $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
6497
- }
6498
-
6499
- if ( is_numeric( $plugin_id ) ) {
6500
- if ( $plugin_id != $this->_plugin->id ) {
6501
- // Add-on was installed - sync license right after install.
6502
- if ( $redirect && fs_redirect( $this->_get_sync_license_url( $plugin_id ) )
6503
- ) {
6504
- exit();
6505
- }
6506
-
6507
- }
6508
- } else {
6509
- /**
6510
- * @author Vova Feldman (@svovaf)
6511
- * @since 1.1.9 If site installed with a valid license, sync license.
6512
- */
6513
- if ( $this->is_paying() ) {
6514
- $this->_sync_plugin_license( true );
6515
- }
6516
-
6517
- // Reload the page with the keys.
6518
- if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_connect_url' ) ) ) {
6519
- exit();
6520
- }
6521
- }
6522
- }
6523
-
6524
- /**
6525
- * Install plugin with new user information after approval.
6526
- *
6527
- * @author Vova Feldman (@svovaf)
6528
- * @since 1.0.7
6529
- */
6530
- function _install_with_new_user() {
6531
- $this->_logger->entrance();
6532
-
6533
- if ( $this->is_registered() ) {
6534
- return;
6535
- }
6536
-
6537
- if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6538
- // check_admin_referer( $this->_slug . '_activate_new' );
6539
-
6540
- if ( fs_request_has( 'user_secret_key' ) ) {
6541
- $this->install_with_new_user(
6542
- fs_request_get( 'user_id' ),
6543
- fs_request_get( 'user_public_key' ),
6544
- fs_request_get( 'user_secret_key' ),
6545
- fs_request_get( 'install_id' ),
6546
- fs_request_get( 'install_public_key' ),
6547
- fs_request_get( 'install_secret_key' )
6548
- );
6549
- } else if ( fs_request_has( 'pending_activation' ) ) {
6550
- $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
6551
- }
6552
- }
6553
- }
6554
-
6555
- /**
6556
- * Install plugin with new user.
6557
- *
6558
- * @author Vova Feldman (@svovaf)
6559
- * @since 1.1.7.4
6560
- *
6561
- * @param number $user_id
6562
- * @param string $user_public_key
6563
- * @param string $user_secret_key
6564
- * @param number $install_id
6565
- * @param string $install_public_key
6566
- * @param string $install_secret_key
6567
- * @param bool $redirect
6568
- */
6569
- private function install_with_new_user(
6570
- $user_id,
6571
- $user_public_key,
6572
- $user_secret_key,
6573
- $install_id,
6574
- $install_public_key,
6575
- $install_secret_key,
6576
- $redirect = true
6577
- ) {
6578
- $user = new FS_User();
6579
- $user->id = $user_id;
6580
- $user->public_key = $user_public_key;
6581
- $user->secret_key = $user_secret_key;
6582
-
6583
- $this->_user = $user;
6584
- $user_result = $this->get_api_user_scope()->get();
6585
- $user = new FS_User( $user_result );
6586
- $this->_user = $user;
6587
-
6588
- $site = new FS_Site();
6589
- $site->id = $install_id;
6590
- $site->public_key = $install_public_key;
6591
- $site->secret_key = $install_secret_key;
6592
-
6593
- $this->_site = $site;
6594
- $site_result = $this->get_api_site_scope()->get();
6595
- $site = new FS_Site( $site_result );
6596
- $this->_site = $site;
6597
-
6598
- $this->setup_account( $this->_user, $this->_site, $redirect );
6599
- }
6600
-
6601
- /**
6602
- * @author Vova Feldman (@svovaf)
6603
- * @since 1.1.7.4
6604
- *
6605
- * @param bool $email
6606
- * @param bool $redirect
6607
- */
6608
- private function set_pending_confirmation( $email = false, $redirect = true ) {
6609
- // Install must be activated via email since
6610
- // user with the same email already exist.
6611
- $this->_storage->is_pending_activation = true;
6612
- $this->_add_pending_activation_notice( $email );
6613
-
6614
- // Reload the page with with pending activation message.
6615
- if ( $redirect && fs_redirect( $this->get_after_activation_url( 'after_pending_connect_url' ) ) ) {
6616
- exit();
6617
- }
6618
- }
6619
-
6620
- /**
6621
- * Install plugin with current logged WP user info.
6622
- *
6623
- * @author Vova Feldman (@svovaf)
6624
- * @since 1.0.7
6625
- */
6626
- function _install_with_current_user() {
6627
- $this->_logger->entrance();
6628
-
6629
- if ( $this->is_registered() ) {
6630
- return;
6631
- }
6632
-
6633
- if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
6634
- // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
6635
-
6636
- $this->install_with_current_user();
6637
- }
6638
- }
6639
-
6640
-
6641
- /**
6642
- * @author Vova Feldman (@svovaf)
6643
- * @since 1.1.7.4
6644
- *
6645
- * @param bool $redirect
6646
- *
6647
- * @return object|string
6648
- */
6649
- private function install_with_current_user( $redirect = true ) {
6650
- // Get current logged WP user.
6651
- $current_user = self::_get_current_wp_user();
6652
-
6653
- // Find the relevant FS user by the email.
6654
- $user = self::_get_user_by_email( $current_user->user_email );
6655
-
6656
- // We have to set the user before getting user scope API handler.
6657
- $this->_user = $user;
6658
-
6659
- $extra_install_params = array(
6660
- 'uid' => $this->get_anonymous_id(),
6661
- );
6662
-
6663
- /**
6664
- * @author Vova Feldman (@svovaf)
6665
- * @since 1.1.9 Add license key if given.
6666
- */
6667
- $license_key = fs_request_get( 'license_secret_key' );
6668
-
6669
- if ( ! empty( $license_key ) ) {
6670
- $extra_install_params['license_key'] = $license_key;
6671
- }
6672
-
6673
- // Install the plugin.
6674
- $install = $this->get_api_user_scope()->call(
6675
- "/plugins/{$this->get_id()}/installs.json",
6676
- 'post',
6677
- $this->get_install_data_for_api( $extra_install_params, false, false )
6678
- );
6679
-
6680
- if ( $this->is_api_error($install) ) {
6681
- $this->_admin_notices->add(
6682
- sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
6683
- __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
6684
- __fs( 'oops', $this->_slug ) . '...',
6685
- 'error'
6686
- );
6687
-
6688
- if ( $redirect && fs_redirect( $this->get_activation_url( array('error' => $install->error->message) ) )
6689
- ) {
6690
- exit();
6691
- }
6692
-
6693
- return $install;
6694
- }
6695
-
6696
- $site = new FS_Site( $install );
6697
- $this->_site = $site;
6698
- // $this->_enrich_site_plan( false );
6699
-
6700
- // $this->_set_account( $user, $site );
6701
- // $this->_sync_plans();
6702
-
6703
- $this->setup_account( $this->_user, $this->_site, $redirect );
6704
-
6705
- return $install;
6706
- }
6707
-
6708
- /**
6709
- * Tries to activate add-on account based on parent plugin info.
6710
- *
6711
- * @author Vova Feldman (@svovaf)
6712
- * @since 1.0.6
6713
- *
6714
- * @param Freemius $parent_fs
6715
- */
6716
- private function _activate_addon_account( Freemius $parent_fs ) {
6717
- if ( $this->is_registered() ) {
6718
- // Already activated.
6719
- return;
6720
- }
6721
-
6722
- // Activate add-on with parent plugin credentials.
6723
- $addon_install = $parent_fs->get_api_site_scope()->call(
6724
- "/addons/{$this->_plugin->id}/installs.json",
6725
- 'post',
6726
- $this->get_install_data_for_api( array(
6727
- 'uid' => $this->get_anonymous_id(),
6728
- ), false, false )
6729
- );
6730
-
6731
- if ( isset( $addon_install->error ) ) {
6732
- $this->_admin_notices->add(
6733
- sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
6734
- __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
6735
- __fs( 'oops', $this->_slug ) . '...',
6736
- 'error'
6737
- );
6738
-
6739
- return;
6740
- }
6741
-
6742
- // First of all, set site info - otherwise we won't
6743
- // be able to invoke API calls.
6744
- $this->_site = new FS_Site( $addon_install );
6745
-
6746
- // Sync add-on plans.
6747
- $this->_sync_plans();
6748
-
6749
- // Get site's current plan.
6750
- $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
6751
-
6752
- // Get user information based on parent's plugin.
6753
- $user = $parent_fs->get_user();
6754
-
6755
- $this->_set_account( $user, $this->_site );
6756
-
6757
- // Sync licenses.
6758
- $this->_sync_licenses();
6759
-
6760
- // Try to activate premium license.
6761
- $this->_activate_license( true );
6762
- }
6763
-
6764
- #endregion ------------------------------------------------------------------
6765
-
6766
- #region Admin Menu Items ------------------------------------------------------------------
6767
-
6768
- private $_menu_items = array();
6769
-
6770
- /**
6771
- * @author Vova Feldman (@svovaf)
6772
- * @since 1.0.7
6773
- *
6774
- * @return string
6775
- */
6776
- function get_menu_slug() {
6777
- return $this->_menu->get_slug();
6778
- }
6779
-
6780
- /**
6781
- * @author Vova Feldman (@svovaf)
6782
- * @since 1.0.9
6783
- */
6784
- function _prepare_admin_menu() {
6785
- // if ( ! $this->is_on() ) {
6786
- // return;
6787
- // }
6788
-
6789
- if ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) {
6790
- $this->_menu->remove_menu_item();
6791
- } else {
6792
- $this->do_action( 'before_admin_menu_init' );
6793
-
6794
- $this->add_menu_action();
6795
- $this->add_submenu_items();
6796
- }
6797
- }
6798
-
6799
- /**
6800
- * Admin dashboard menu items modifications.
6801
- *
6802
- * NOTE: admin_menu action executed before admin_init.
6803
- *
6804
- * @author Vova Feldman (@svovaf)
6805
- * @since 1.0.7
6806
- *
6807
- */
6808
- private function add_menu_action() {
6809
- if ( $this->is_activation_mode() ) {
6810
- $this->override_plugin_menu_with_activation();
6811
- } else {
6812
- // If not registered try to install user.
6813
- if ( ! $this->is_registered() &&
6814
- fs_request_is_action( $this->_slug . '_activate_new' )
6815
- ) {
6816
- $this->_install_with_new_user();
6817
- }
6818
- }
6819
- }
6820
-
6821
- /**
6822
- * @author Vova Feldman (@svovaf)
6823
- * @since 1.0.1
6824
- *
6825
- * @return string
6826
- */
6827
- function _redirect_on_clicked_menu_link() {
6828
- $this->_logger->entrance();
6829
-
6830
- $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
6831
-
6832
- $this->_logger->log( 'page = ' . $page );
6833
-
6834
- foreach ( $this->_menu_items as $priority => $items ) {
6835
- foreach ( $items as $item ) {
6836
- if ( isset( $item['url'] ) ) {
6837
- if ( $page === strtolower( $item['menu_slug'] ) ) {
6838
- $this->_logger->log( 'Redirecting to ' . $item['url'] );
6839
-
6840
- fs_redirect( $item['url'] );
6841
- }
6842
- }
6843
- }
6844
- }
6845
- }
6846
-
6847
- /**
6848
- * Remove plugin's all admin menu items & pages, and replace with activation page.
6849
- *
6850
- * @author Vova Feldman (@svovaf)
6851
- * @since 1.0.1
6852
- */
6853
- private function override_plugin_menu_with_activation() {
6854
- $this->_logger->entrance();
6855
-
6856
- $hook = false;
6857
-
6858
- if ( $this->_menu->is_top_level() ) {
6859
- $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
6860
-
6861
- if ( false === $hook ) {
6862
- // Create new menu item just for the opt-in.
6863
- $hook = add_menu_page(
6864
- $this->get_plugin_name(),
6865
- $this->get_plugin_name(),
6866
- 'manage_options',
6867
- $this->_menu->get_slug(),
6868
- array( &$this, '_connect_page_render' )
6869
- );
6870
- }
6871
- } else {
6872
- $menus = array( $this->_menu->get_parent_slug() );
6873
-
6874
- if ( $this->_menu->is_override_exact() ) {
6875
- // Make sure the current page is matching the activation page.
6876
- $activation_url = strtolower( $this->get_activation_url() );
6877
- $request_url = strtolower( $_SERVER['REQUEST_URI'] );
6878
-
6879
- if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
6880
- // Different path - DO NOT OVERRIDE PAGE.
6881
- return;
6882
- }
6883
-
6884
- $activation_url_params = array();
6885
- parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
6886
-
6887
- $request_url_params = array();
6888
- parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
6889
-
6890
-
6891
- foreach ( $activation_url_params as $key => $val ) {
6892
- if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
6893
- // Not matching query string - DO NOT OVERRIDE PAGE.
6894
- return;
6895
- }
6896
- }
6897
- }
6898
-
6899
- foreach ( $menus as $parent_slug ) {
6900
- $hook = $this->_menu->override_submenu_action(
6901
- $parent_slug,
6902
- $this->_menu->get_raw_slug(),
6903
- array( &$this, '_connect_page_render' )
6904
- );
6905
-
6906
- if ( false !== $hook ) {
6907
- // Found plugin's submenu item.
6908
- break;
6909
- }
6910
- }
6911
- }
6912
-
6913
- if ( $this->_menu->is_activation_page() ) {
6914
- // Clean admin page from distracting content.
6915
- self::_clean_admin_content_section();
6916
- }
6917
-
6918
- if ( false !== $hook ) {
6919
- if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
6920
- add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
6921
- } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
6922
- add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
6923
- }
6924
- }
6925
- }
6926
-
6927
- /**
6928
- * @author Leo Fajardo (leorw)
6929
- * @since 1.2.1
6930
- *
6931
- * return string
6932
- */
6933
- function get_top_level_menu_capability() {
6934
- global $menu;
6935
-
6936
- $top_level_menu_slug = $this->get_top_level_menu_slug();
6937
-
6938
- foreach ( $menu as $menu_info ) {
6939
- /**
6940
- * The second element in the menu info array is the capability/role that has access to the menu and the
6941
- * third element is the menu slug.
6942
- */
6943
- if ( $menu_info[2] === $top_level_menu_slug ) {
6944
- return $menu_info[1];
6945
- }
6946
- }
6947
-
6948
- return 'read';
6949
- }
6950
-
6951
- /**
6952
- * @author Vova Feldman (@svovaf)
6953
- * @since 1.0.0
6954
- *
6955
- * @return string
6956
- */
6957
- private function get_top_level_menu_slug() {
6958
- return ( $this->is_addon() ?
6959
- $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
6960
- $this->_menu->get_top_level_menu_slug() );
6961
- }
6962
-
6963
- /**
6964
- * Add default Freemius menu items.
6965
- *
6966
- * @author Vova Feldman (@svovaf)
6967
- * @since 1.0.0
6968
- */
6969
- private function add_submenu_items() {
6970
- $this->_logger->entrance();
6971
-
6972
- if ( ! $this->is_addon() ) {
6973
- if ( ! $this->is_activation_mode() ) {
6974
- if ( $this->is_registered() ) {
6975
- // Add user account page.
6976
- $this->add_submenu_item(
6977
- __fs( 'account', $this->_slug ),
6978
- array( &$this, '_account_page_render' ),
6979
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
6980
- 'manage_options',
6981
- 'account',
6982
- array( &$this, '_account_page_load' ),
6983
- WP_FS__DEFAULT_PRIORITY,
6984
- $this->_menu->is_submenu_item_visible( 'account' )
6985
- );
6986
- }
6987
-
6988
- // Add contact page.
6989
- $this->add_submenu_item(
6990
- __fs( 'contact-us', $this->_slug ),
6991
- array( &$this, '_contact_page_render' ),
6992
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
6993
- 'manage_options',
6994
- 'contact',
6995
- 'Freemius::_clean_admin_content_section',
6996
- WP_FS__DEFAULT_PRIORITY,
6997
- $this->_menu->is_submenu_item_visible( 'contact' )
6998
- );
6999
-
7000
- if ( $this->has_addons() ) {
7001
- $this->add_submenu_item(
7002
- __fs( 'add-ons', $this->_slug ),
7003
- array( &$this, '_addons_page_render' ),
7004
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
7005
- 'manage_options',
7006
- 'addons',
7007
- array( &$this, '_addons_page_load' ),
7008
- WP_FS__LOWEST_PRIORITY - 1,
7009
- $this->_menu->is_submenu_item_visible( 'addons' )
7010
- );
7011
- }
7012
-
7013
- $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
7014
- // If user don't have paid plans, add pricing page
7015
- // to support add-ons checkout but don't add the submenu item.
7016
- // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
7017
-
7018
- // Add upgrade/pricing page.
7019
- $this->add_submenu_item(
7020
- ( $this->is_paying() ? __fs( 'pricing', $this->_slug ) : __fs( 'upgrade', $this->_slug ) . '&nbsp;&nbsp;&#x27a4;' ),
7021
- array( &$this, '_pricing_page_render' ),
7022
- $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
7023
- 'manage_options',
7024
- 'pricing',
7025
- 'Freemius::_clean_admin_content_section',
7026
- WP_FS__LOWEST_PRIORITY,
7027
- $show_pricing
7028
- );
7029
- }
7030
- }
7031
-
7032
-
7033
- if ( 0 < count( $this->_menu_items ) ) {
7034
- if ( ! $this->_menu->is_top_level() ) {
7035
- fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
7036
-
7037
- // Append submenu items right after the plugin's submenu item.
7038
- $this->order_sub_submenu_items();
7039
- } else {
7040
- // Append submenu items.
7041
- $this->embed_submenu_items();
7042
- }
7043
- }
7044
- }
7045
-
7046
- /**
7047
- * Moved the actual submenu item additions to a separated function,
7048
- * in order to support sub-submenu items when the plugin's settings
7049
- * only have a submenu and not top-level menu item.
7050
- *
7051
- * @author Vova Feldman (@svovaf)
7052
- * @since 1.1.4
7053
- */
7054
- private function embed_submenu_items() {
7055
- $item_template = $this->_menu->is_top_level() ?
7056
- '<span class="fs-submenu-item">%s</span>' :
7057
- '<span class="fs-submenu-item fs-sub">%s</span>';
7058
-
7059
- $top_level_menu_capability = $this->get_top_level_menu_capability();
7060
-
7061
- ksort( $this->_menu_items );
7062
-
7063
- foreach ( $this->_menu_items as $priority => $items ) {
7064
- foreach ( $items as $item ) {
7065
- $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
7066
-
7067
- if ( ! isset( $item['url'] ) ) {
7068
- $hook = add_submenu_page(
7069
- $item['show_submenu'] ?
7070
- $this->get_top_level_menu_slug() :
7071
- null,
7072
- $item['page_title'],
7073
- sprintf( $item_template, $item['menu_title'] ),
7074
- $capability,
7075
- $item['menu_slug'],
7076
- $item['render_function']
7077
- );
7078
-
7079
- if ( false !== $item['before_render_function'] ) {
7080
- add_action( "load-$hook", $item['before_render_function'] );
7081
- }
7082
- } else {
7083
- add_submenu_page(
7084
- $this->get_top_level_menu_slug(),
7085
- $item['page_title'],
7086
- sprintf( $item_template, $item['menu_title'] ),
7087
- $capability,
7088
- $item['menu_slug'],
7089
- '__return_true'
7090
- );
7091
- }
7092
- }
7093
- }
7094
- }
7095
-
7096
- /**
7097
- * Re-order the submenu items so all Freemius added new submenu items
7098
- * are added right after the plugin's settings submenu item.
7099
- *
7100
- * @author Vova Feldman (@svovaf)
7101
- * @since 1.1.4
7102
- */
7103
- private function order_sub_submenu_items() {
7104
- global $submenu;
7105
-
7106
- $menu_slug = $this->_menu->get_top_level_menu_slug();
7107
-
7108
- /**
7109
- * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
7110
- * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
7111
- * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
7112
- * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
7113
- *
7114
- * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
7115
- * of another plugin, only users that have the right role can access its sub-submenus since we will use the
7116
- * capability needed to access the parent menu as the capability for the submenus that we will add.
7117
- */
7118
- if ( empty( $submenu[ $menu_slug ] ) ) {
7119
- return;
7120
- }
7121
-
7122
- $top_level_menu = &$submenu[ $menu_slug ];
7123
-
7124
- $all_submenu_items_after = array();
7125
-
7126
- $found_submenu_item = false;
7127
-
7128
- foreach ( $top_level_menu as $submenu_id => $meta ) {
7129
- if ( $found_submenu_item ) {
7130
- // Remove all submenu items after the plugin's submenu item.
7131
- $all_submenu_items_after[] = $meta;
7132
- unset( $top_level_menu[ $submenu_id ] );
7133
- }
7134
-
7135
- if ( $this->_menu->get_raw_slug() === $meta[2] ) {
7136
- // Found the submenu item, put all below.
7137
- $found_submenu_item = true;
7138
- continue;
7139
- }
7140
- }
7141
-
7142
- // Embed all plugin's new submenu items.
7143
- $this->embed_submenu_items();
7144
-
7145
- // Start with specially high number to make sure it's appended.
7146
- $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
7147
- foreach ( $all_submenu_items_after as $meta ) {
7148
- $top_level_menu[ $i ] = $meta;
7149
- $i ++;
7150
- }
7151
-
7152
- // Sort submenu items.
7153
- ksort( $top_level_menu );
7154
- }
7155
-
7156
- /**
7157
- * Displays the Support Forum link when enabled.
7158
- *
7159
- * Can be filtered like so:
7160
- *
7161
- * function _fs_show_support_menu( $is_visible, $menu_id ) {
7162
- * if ( 'support' === $menu_id ) {
7163
- * return _fs->is_registered();
7164
- * }
7165
- * return $is_visible;
7166
- * }
7167
- * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
7168
- *
7169
- */
7170
- function _add_default_submenu_items() {
7171
- if ( ! $this->is_on() ) {
7172
- return;
7173
- }
7174
-
7175
- if ( ! $this->is_activation_mode() ) {
7176
- if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
7177
- $this->add_submenu_link_item(
7178
- $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
7179
- $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
7180
- 'wp-support-forum',
7181
- null,
7182
- 50
7183
- );
7184
- }
7185
- }
7186
- }
7187
-
7188
- /**
7189
- * @author Vova Feldman (@svovaf)
7190
- * @since 1.0.1
7191
- *
7192
- * @param string $menu_title
7193
- * @param callable $render_function
7194
- * @param bool|string $page_title
7195
- * @param string $capability
7196
- * @param bool|string $menu_slug
7197
- * @param bool|callable $before_render_function
7198
- * @param int $priority
7199
- * @param bool $show_submenu
7200
- */
7201
- function add_submenu_item(
7202
- $menu_title,
7203
- $render_function,
7204
- $page_title = false,
7205
- $capability = 'manage_options',
7206
- $menu_slug = false,
7207
- $before_render_function = false,
7208
- $priority = WP_FS__DEFAULT_PRIORITY,
7209
- $show_submenu = true
7210
- ) {
7211
- $this->_logger->entrance( 'Title = ' . $menu_title );
7212
-
7213
- if ( $this->is_addon() ) {
7214
- $parent_fs = $this->get_parent_instance();
7215
-
7216
- if ( is_object( $parent_fs ) ) {
7217
- $parent_fs->add_submenu_item(
7218
- $menu_title,
7219
- $render_function,
7220
- $page_title,
7221
- $capability,
7222
- $menu_slug,
7223
- $before_render_function,
7224
- $priority,
7225
- $show_submenu
7226
- );
7227
-
7228
- return;
7229
- }
7230
- }
7231
-
7232
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
7233
- $this->_menu_items[ $priority ] = array();
7234
- }
7235
-
7236
- $this->_menu_items[ $priority ][] = array(
7237
- 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
7238
- 'menu_title' => $menu_title,
7239
- 'capability' => $capability,
7240
- 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
7241
- 'render_function' => $render_function,
7242
- 'before_render_function' => $before_render_function,
7243
- 'show_submenu' => $show_submenu,
7244
- );
7245
- }
7246
-
7247
- /**
7248
- * @author Vova Feldman (@svovaf)
7249
- * @since 1.0.1
7250
- *
7251
- * @param string $menu_title
7252
- * @param string $url
7253
- * @param bool $menu_slug
7254
- * @param string $capability
7255
- * @param int $priority
7256
- *
7257
- */
7258
- function add_submenu_link_item(
7259
- $menu_title,
7260
- $url,
7261
- $menu_slug = false,
7262
- $capability = 'read',
7263
- $priority = WP_FS__DEFAULT_PRIORITY
7264
- ) {
7265
- $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
7266
-
7267
- if ( $this->is_addon() ) {
7268
- $parent_fs = $this->get_parent_instance();
7269
-
7270
- if ( is_object( $parent_fs ) ) {
7271
- $parent_fs->add_submenu_link_item(
7272
- $menu_title,
7273
- $url,
7274
- $menu_slug,
7275
- $capability,
7276
- $priority
7277
- );
7278
-
7279
- return;
7280
- }
7281
- }
7282
-
7283
- if ( ! isset( $this->_menu_items[ $priority ] ) ) {
7284
- $this->_menu_items[ $priority ] = array();
7285
- }
7286
-
7287
- $this->_menu_items[ $priority ][] = array(
7288
- 'menu_title' => $menu_title,
7289
- 'capability' => $capability,
7290
- 'menu_slug' => $this->_menu->get_slug( is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ) ),
7291
- 'url' => $url,
7292
- 'page_title' => $menu_title,
7293
- 'render_function' => 'fs_dummy',
7294
- 'before_render_function' => '',
7295
- );
7296
- }
7297
-
7298
- #endregion ------------------------------------------------------------------
7299
-
7300
- /* Actions / Hooks / Filters
7301
- ------------------------------------------------------------------------------------------------------------------*/
7302
- /**
7303
- * @author Vova Feldman (@svovaf)
7304
- * @since 1.1.7
7305
- *
7306
- * @param string $tag
7307
- *
7308
- * @return string
7309
- */
7310
- public function get_action_tag( $tag ) {
7311
- return "fs_{$tag}_{$this->_slug}";
7312
- }
7313
-
7314
- /**
7315
- * @author Vova Feldman (@svovaf)
7316
- * @since 1.2.1
7317
- *
7318
- * @param string $tag
7319
- *
7320
- * @return string
7321
- */
7322
- private function get_ajax_action_tag( $tag ) {
7323
- return 'wp_ajax_' . $this->get_action_tag( $tag );
7324
- }
7325
-
7326
- /**
7327
- * Do action, specific for the current context plugin.
7328
- *
7329
- * @author Vova Feldman (@svovaf)
7330
- * @since 1.0.1
7331
- *
7332
- * @param string $tag The name of the action to be executed.
7333
- * @param mixed $arg,... Optional. Additional arguments which are passed on to the
7334
- * functions hooked to the action. Default empty.
7335
- *
7336
- * @uses do_action()
7337
- */
7338
- function do_action( $tag, $arg = '' ) {
7339
- $this->_logger->entrance( $tag );
7340
-
7341
- $args = func_get_args();
7342
-
7343
- call_user_func_array( 'do_action', array_merge(
7344
- array( $this->get_action_tag( $tag ) ),
7345
- array_slice( $args, 1 ) )
7346
- );
7347
- }
7348
-
7349
- /**
7350
- * Add action, specific for the current context plugin.
7351
- *
7352
- * @author Vova Feldman (@svovaf)
7353
- * @since 1.0.1
7354
- *
7355
- * @param string $tag
7356
- * @param callable $function_to_add
7357
- * @param int $priority
7358
- * @param int $accepted_args
7359
- *
7360
- * @uses add_action()
7361
- */
7362
- function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
7363
- $this->_logger->entrance( $tag );
7364
-
7365
- add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
7366
- }
7367
-
7368
- /**
7369
- * Add AJAX action, specific for the current context plugin.
7370
- *
7371
- * @author Vova Feldman (@svovaf)
7372
- * @since 1.2.1
7373
- *
7374
- * @param string $tag
7375
- * @param callable $function_to_add
7376
- * @param int $priority
7377
- * @param int $accepted_args
7378
- *
7379
- * @uses add_action()
7380
- */
7381
- function add_ajax_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
7382
- $this->_logger->entrance( $tag );
7383
-
7384
- add_action( $this->get_ajax_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
7385
- }
7386
-
7387
- /**
7388
- * Apply filter, specific for the current context plugin.
7389
- *
7390
- * @author Vova Feldman (@svovaf)
7391
- * @since 1.0.9
7392
- *
7393
- * @param string $tag The name of the filter hook.
7394
- * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
7395
- *
7396
- * @return mixed The filtered value after all hooked functions are applied to it.
7397
- *
7398
- * @uses apply_filters()
7399
- */
7400
- function apply_filters( $tag, $value ) {
7401
- $this->_logger->entrance( $tag );
7402
-
7403
- $args = func_get_args();
7404
- array_unshift( $args, $this->_slug );
7405
-
7406
- return call_user_func_array( 'fs_apply_filter', $args );
7407
- }
7408
-
7409
- /**
7410
- * Add filter, specific for the current context plugin.
7411
- *
7412
- * @author Vova Feldman (@svovaf)
7413
- * @since 1.0.9
7414
- *
7415
- * @param string $tag
7416
- * @param callable $function_to_add
7417
- * @param int $priority
7418
- * @param int $accepted_args
7419
- *
7420
- * @uses add_filter()
7421
- */
7422
- function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
7423
- $this->_logger->entrance( $tag );
7424
-
7425
- add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
7426
- }
7427
-
7428
- /**
7429
- * Check if has filter.
7430
- *
7431
- * @author Vova Feldman (@svovaf)
7432
- * @since 1.1.4
7433
- *
7434
- * @param string $tag
7435
- * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
7436
- *
7437
- * @return false|int
7438
- *
7439
- * @uses has_filter()
7440
- */
7441
- function has_filter( $tag, $function_to_check = false ) {
7442
- $this->_logger->entrance( $tag );
7443
-
7444
- return has_filter( $this->get_action_tag( $tag ), $function_to_check );
7445
- }
7446
-
7447
- /**
7448
- * Override default i18n text phrases.
7449
- *
7450
- * @author Vova Feldman (@svovaf)
7451
- * @since 1.1.6
7452
- *
7453
- * @param string[] string $key_value
7454
- *
7455
- * @uses fs_override_i18n()
7456
- */
7457
- function override_i18n( $key_value ) {
7458
- fs_override_i18n( $key_value, $this->_slug );
7459
- }
7460
-
7461
- /* Account Page
7462
- ------------------------------------------------------------------------------------------------------------------*/
7463
- /**
7464
- * Update site information.
7465
- *
7466
- * @author Vova Feldman (@svovaf)
7467
- * @since 1.0.1
7468
- *
7469
- * @param bool $store Flush to Database if true.
7470
- */
7471
- private function _store_site( $store = true ) {
7472
- $this->_logger->entrance();
7473
-
7474
- $encrypted_site = clone $this->_site;
7475
- $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
7476
-
7477
- $sites = self::get_all_sites();
7478
- $sites[ $this->_slug ] = $encrypted_site;
7479
- self::$_accounts->set_option( 'sites', $sites, $store );
7480
- }
7481
-
7482
- /**
7483
- * Update plugin's plans information.
7484
- *
7485
- * @author Vova Feldman (@svovaf)
7486
- * @since 1.0.2
7487
- *
7488
- * @param bool $store Flush to Database if true.
7489
- */
7490
- private function _store_plans( $store = true ) {
7491
- $this->_logger->entrance();
7492
-
7493
- $plans = self::get_all_plans();
7494
-
7495
- // Copy plans.
7496
- $encrypted_plans = array();
7497
- for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
7498
- $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
7499
- }
7500
-
7501
- $plans[ $this->_slug ] = $encrypted_plans;
7502
- self::$_accounts->set_option( 'plans', $plans, $store );
7503
- }
7504
-
7505
- /**
7506
- * Update user's plugin licenses.
7507
- *
7508
- * @author Vova Feldman (@svovaf)
7509
- * @since 1.0.5
7510
- *
7511
- * @param bool $store
7512
- * @param string|bool $plugin_slug
7513
- * @param FS_Plugin_License[] $licenses
7514
- */
7515
- private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
7516
- $this->_logger->entrance();
7517
-
7518
- $all_licenses = self::get_all_licenses();
7519
-
7520
- if ( ! is_string( $plugin_slug ) ) {
7521
- $plugin_slug = $this->_slug;
7522
- $licenses = $this->_licenses;
7523
- }
7524
-
7525
- if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
7526
- $all_licenses[ $plugin_slug ] = array();
7527
- }
7528
-
7529
- $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
7530
-
7531
- self::$_accounts->set_option( 'licenses', $all_licenses, $store );
7532
- }
7533
-
7534
- /**
7535
- * Update user information.
7536
- *
7537
- * @author Vova Feldman (@svovaf)
7538
- * @since 1.0.1
7539
- *
7540
- * @param bool $store Flush to Database if true.
7541
- */
7542
- private function _store_user( $store = true ) {
7543
- $this->_logger->entrance();
7544
-
7545
- $users = self::get_all_users();
7546
- $users[ $this->_user->id ] = $this->_user;
7547
- self::$_accounts->set_option( 'users', $users, $store );
7548
- }
7549
-
7550
- /**
7551
- * Update new updates information.
7552
- *
7553
- * @author Vova Feldman (@svovaf)
7554
- * @since 1.0.4
7555
- *
7556
- * @param FS_Plugin_Tag|null $update
7557
- * @param bool $store Flush to Database if true.
7558
- * @param bool|number $plugin_id
7559
- */
7560
- private function _store_update( $update, $store = true, $plugin_id = false ) {
7561
- $this->_logger->entrance();
7562
-
7563
- if ( $update instanceof FS_Plugin_Tag ) {
7564
- $update->updated = time();
7565
- }
7566
-
7567
- if ( ! is_numeric( $plugin_id ) ) {
7568
- $plugin_id = $this->_plugin->id;
7569
- }
7570
-
7571
- $updates = self::get_all_updates();
7572
- $updates[ $plugin_id ] = $update;
7573
- self::$_accounts->set_option( 'updates', $updates, $store );
7574
- }
7575
-
7576
- /**
7577
- * Update new updates information.
7578
- *
7579
- * @author Vova Feldman (@svovaf)
7580
- * @since 1.0.6
7581
- *
7582
- * @param FS_Plugin[] $plugin_addons
7583
- * @param bool $store Flush to Database if true.
7584
- */
7585
- private function _store_addons( $plugin_addons, $store = true ) {
7586
- $this->_logger->entrance();
7587
-
7588
- $addons = self::get_all_addons();
7589
- $addons[ $this->_plugin->id ] = $plugin_addons;
7590
- self::$_accounts->set_option( 'addons', $addons, $store );
7591
- }
7592
-
7593
- /**
7594
- * Delete plugin's associated add-ons.
7595
- *
7596
- * @author Vova Feldman (@svovaf)
7597
- * @since 1.0.8
7598
- *
7599
- * @param bool $store
7600
- *
7601
- * @return bool
7602
- */
7603
- private function _delete_account_addons( $store = true ) {
7604
- $all_addons = self::get_all_account_addons();
7605
-
7606
- if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
7607
- return false;
7608
- }
7609
-
7610
- unset( $all_addons[ $this->_plugin->id ] );
7611
-
7612
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
7613
-
7614
- return true;
7615
- }
7616
-
7617
- /**
7618
- * Update account add-ons list.
7619
- *
7620
- * @author Vova Feldman (@svovaf)
7621
- * @since 1.0.6
7622
- *
7623
- * @param FS_Plugin[] $addons
7624
- * @param bool $store Flush to Database if true.
7625
- */
7626
- private function _store_account_addons( $addons, $store = true ) {
7627
- $this->_logger->entrance();
7628
-
7629
- $all_addons = self::get_all_account_addons();
7630
- $all_addons[ $this->_plugin->id ] = $addons;
7631
- self::$_accounts->set_option( 'account_addons', $all_addons, $store );
7632
- }
7633
-
7634
- /**
7635
- * Store account params in the Database.
7636
- *
7637
- * @author Vova Feldman (@svovaf)
7638
- * @since 1.0.1
7639
- */
7640
- private function _store_account() {
7641
- $this->_logger->entrance();
7642
-
7643
- $this->_store_site( false );
7644
- $this->_store_user( false );
7645
- $this->_store_plans( false );
7646
- $this->_store_licenses( false );
7647
-
7648
- self::$_accounts->store();
7649
- }
7650
-
7651
- /**
7652
- * Sync user's information.
7653
- *
7654
- * @author Vova Feldman (@svovaf)
7655
- * @since 1.0.3
7656
- * @uses FS_Api
7657
- */
7658
- private function _handle_account_user_sync() {
7659
- $this->_logger->entrance();
7660
-
7661
- $api = $this->get_api_user_scope();
7662
-
7663
- // Get user's information.
7664
- $user = $api->get( '/', true );
7665
-
7666
- if ( isset( $user->id ) ) {
7667
- $this->_user->first = $user->first;
7668
- $this->_user->last = $user->last;
7669
- $this->_user->email = $user->email;
7670
-
7671
- $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
7672
-
7673
- if ( $user->is_verified &&
7674
- ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
7675
- ) {
7676
- $this->_user->is_verified = true;
7677
-
7678
- $this->do_action( 'account_email_verified', $user->email );
7679
-
7680
- $this->_admin_notices->add(
7681
- __fs( 'email-verified-message', $this->_slug ),
7682
- __fs( 'right-on', $this->_slug ) . '!',
7683
- 'success',
7684
- // Make admin sticky if account menu item is invisible,
7685
- // since the page will be auto redirected to the plugin's
7686
- // main settings page, and the non-sticky message
7687
- // will disappear.
7688
- ! $is_menu_item_account_visible,
7689
- false,
7690
- 'email_verified'
7691
- );
7692
- }
7693
-
7694
- // Flush user details to DB.
7695
- $this->_store_user();
7696
-
7697
- $this->do_action( 'after_account_user_sync', $user );
7698
-
7699
- /**
7700
- * If account menu item is hidden, redirect to plugin's main settings page.
7701
- *
7702
- * @author Vova Feldman (@svovaf)
7703
- * @since 1.1.6
7704
- *
7705
- * @link https://github.com/Freemius/wordpress-sdk/issues/6
7706
- */
7707
- if ( ! $is_menu_item_account_visible ) {
7708
- if ( fs_redirect( $this->_get_admin_page_url() ) ) {
7709
- exit();
7710
- }
7711
- }
7712
- }
7713
- }
7714
-
7715
- /**
7716
- * @param bool $store
7717
- *
7718
- * @return FS_Plugin_Plan|object|false
7719
- */
7720
- private function _enrich_site_plan( $store = true ) {
7721
- // Try to load plan from local cache.
7722
- $plan = $this->_get_plan_by_id( $this->_site->plan->id );
7723
-
7724
- if ( false === $plan ) {
7725
- $plan = $this->_fetch_site_plan();
7726
- }
7727
-
7728
- if ( $plan instanceof FS_Plugin_Plan ) {
7729
- $this->_update_plan( $plan, $store );
7730
- }
7731
-
7732
- return $plan;
7733
- }
7734
-
7735
- /**
7736
- * @author Vova Feldman (@svovaf)
7737
- * @since 1.0.9
7738
- * @uses FS_Api
7739
- *
7740
- * @param bool $store
7741
- *
7742
- * @return FS_Plugin_Plan|object|false
7743
- */
7744
- private function _enrich_site_trial_plan( $store = true ) {
7745
- // Try to load plan from local cache.
7746
- $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
7747
-
7748
- if ( false === $trial_plan ) {
7749
- $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
7750
- }
7751
-
7752
- if ( $trial_plan instanceof FS_Plugin_Plan ) {
7753
- $this->_storage->store( 'trial_plan', $trial_plan, $store );
7754
- }
7755
-
7756
- return $trial_plan;
7757
- }
7758
-
7759
- /**
7760
- * @author Vova Feldman (@svovaf)
7761
- * @since 1.0.9
7762
- * @uses FS_Api
7763
- *
7764
- * @param number|bool $license_id
7765
- *
7766
- * @return FS_Subscription|object|bool
7767
- */
7768
- private function _fetch_site_license_subscription( $license_id = false ) {
7769
- $this->_logger->entrance();
7770
- $api = $this->get_api_site_scope();
7771
-
7772
- if ( ! is_numeric( $license_id ) ) {
7773
- $license_id = $this->_license->id;
7774
- }
7775
-
7776
- $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
7777
-
7778
- return ! isset( $result->error ) ?
7779
- ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
7780
- new FS_Subscription( $result->subscriptions[0] ) :
7781
- false
7782
- ) :
7783
- $result;
7784
- }
7785
-
7786
- /**
7787
- * @author Vova Feldman (@svovaf)
7788
- * @since 1.0.4
7789
- * @uses FS_Api
7790
- *
7791
- * @param number|bool $plan_id
7792
- *
7793
- * @return FS_Plugin_Plan|object
7794
- */
7795
- private function _fetch_site_plan( $plan_id = false ) {
7796
- $this->_logger->entrance();
7797
- $api = $this->get_api_site_scope();
7798
-
7799
- if ( ! is_numeric( $plan_id ) ) {
7800
- $plan_id = $this->_site->plan->id;
7801
- }
7802
-
7803
- $plan = $api->get( "/plans/{$plan_id}.json", true );
7804
-
7805
- return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
7806
- }
7807
-
7808
- /**
7809
- * @author Vova Feldman (@svovaf)
7810
- * @since 1.0.5
7811
- * @uses FS_Api
7812
- *
7813
- * @return FS_Plugin_Plan[]|object
7814
- */
7815
- private function _fetch_plugin_plans() {
7816
- $this->_logger->entrance();
7817
- $api = $this->get_api_site_scope();
7818
-
7819
- $result = $api->get( '/plans.json', true );
7820
-
7821
- if ( ! $this->is_api_error( $result ) ) {
7822
- for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
7823
- $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
7824
- }
7825
-
7826
- $result = $result->plans;
7827
- }
7828
-
7829
- return $result;
7830
- }
7831
-
7832
- /**
7833
- * @author Vova Feldman (@svovaf)
7834
- * @since 1.0.5
7835
- * @uses FS_Api
7836
- *
7837
- * @param number|bool $plugin_id
7838
- * @param number|bool $site_license_id
7839
- *
7840
- * @return FS_Plugin_License[]|object
7841
- */
7842
- private function _fetch_licenses( $plugin_id = false, $site_license_id = false ) {
7843
- $this->_logger->entrance();
7844
-
7845
- $api = $this->get_api_user_scope();
7846
-
7847
- if ( ! is_numeric( $plugin_id ) ) {
7848
- $plugin_id = $this->_plugin->id;
7849
- }
7850
-
7851
- $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
7852
-
7853
- $is_site_license_synced = false;
7854
-
7855
- if ( ! isset( $result->error ) ) {
7856
- for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
7857
- $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
7858
-
7859
- if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
7860
- $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
7861
- }
7862
- }
7863
-
7864
- $result = $result->licenses;
7865
- }
7866
-
7867
- if ( ! $is_site_license_synced ) {
7868
- $api = $this->get_api_site_scope();
7869
-
7870
- if ( is_numeric( $site_license_id ) ) {
7871
- // Try to retrieve a foreign license that is linked to the install.
7872
- $api_result = $api->call( '/licenses.json' );
7873
-
7874
- if ( ! isset( $api_result->error ) ) {
7875
- $licenses = $api_result->licenses;
7876
-
7877
- if ( ! empty( $licenses ) ) {
7878
- $result[] = new FS_Plugin_License( $licenses[0] );
7879
- }
7880
- }
7881
- } else if ( is_object( $this->_license ) ) {
7882
- // Fetch foreign license by ID and license key.
7883
- $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
7884
- urlencode( $this->_license->secret_key ) );
7885
-
7886
- if ( ! isset( $license->error ) ) {
7887
- $result[] = new FS_Plugin_License( $license );
7888
- }
7889
- }
7890
- }
7891
-
7892
- return $result;
7893
- }
7894
-
7895
- /**
7896
- * @author Vova Feldman (@svovaf)
7897
- * @since 1.2.0
7898
- * @uses FS_Api
7899
- *
7900
- * @param number|bool $plugin_id
7901
- *
7902
- * @return FS_Payment[]|object
7903
- */
7904
- function _fetch_payments( $plugin_id = false ) {
7905
- $this->_logger->entrance();
7906
-
7907
- $api = $this->get_api_user_scope();
7908
-
7909
- if ( ! is_numeric( $plugin_id ) ) {
7910
- $plugin_id = $this->_plugin->id;
7911
- }
7912
-
7913
- $result = $api->get( "/plugins/{$plugin_id}/payments.json", true );
7914
-
7915
- if ( ! isset( $result->error ) ) {
7916
- for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
7917
- $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
7918
- }
7919
- $result = $result->payments;
7920
- }
7921
-
7922
- return $result;
7923
- }
7924
-
7925
- /**
7926
- * @author Vova Feldman (@svovaf)
7927
- * @since 1.0.4
7928
- *
7929
- * @param FS_Plugin_Plan $plan
7930
- * @param bool $store
7931
- */
7932
- private function _update_plan( $plan, $store = false ) {
7933
- $this->_logger->entrance();
7934
-
7935
- $this->_site->plan = $plan;
7936
- $this->_store_site( $store );
7937
- }
7938
-
7939
- /**
7940
- * @author Vova Feldman (@svovaf)
7941
- * @since 1.0.5
7942
- *
7943
- * @param FS_Plugin_License[] $licenses
7944
- * @param string|bool $plugin_slug
7945
- */
7946
- private function _update_licenses( $licenses, $plugin_slug = false ) {
7947
- $this->_logger->entrance();
7948
-
7949
- if ( is_array( $licenses ) ) {
7950
- for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
7951
- $licenses[ $i ]->updated = time();
7952
- }
7953
- }
7954
-
7955
- if ( ! is_string( $plugin_slug ) ) {
7956
- $this->_licenses = $licenses;
7957
- }
7958
-
7959
- $this->_store_licenses( true, $plugin_slug, $licenses );
7960
- }
7961
-
7962
- /**
7963
- * @author Vova Feldman (@svovaf)
7964
- * @since 1.0.4
7965
- *
7966
- * @param bool|number $plugin_id
7967
- * @param bool $flush Since 1.1.7.3
7968
- *
7969
- * @return object|false New plugin tag info if exist.
7970
- */
7971
- private function _fetch_newer_version( $plugin_id = false, $flush = true ) {
7972
- $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush );
7973
-
7974
- if ( ! is_object( $latest_tag ) ) {
7975
- return false;
7976
- }
7977
-
7978
- // Check if version is actually newer.
7979
- $has_new_version =
7980
- // If it's an non-installed add-on then always return latest.
7981
- ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
7982
- // Compare versions.
7983
- version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
7984
-
7985
- $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
7986
-
7987
- return $has_new_version ? $latest_tag : false;
7988
- }
7989
-
7990
- /**
7991
- * @author Vova Feldman (@svovaf)
7992
- * @since 1.0.5
7993
- *
7994
- * @param bool|number $plugin_id
7995
- * @param bool $flush Since 1.1.7.3
7996
- *
7997
- * @return bool|FS_Plugin_Tag
7998
- */
7999
- function get_update( $plugin_id = false, $flush = true ) {
8000
- $this->_logger->entrance();
8001
-
8002
- if ( ! is_numeric( $plugin_id ) ) {
8003
- $plugin_id = $this->_plugin->id;
8004
- }
8005
-
8006
- $this->_check_updates( true, $plugin_id, $flush );
8007
- $updates = $this->get_all_updates();
8008
-
8009
- return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
8010
- }
8011
-
8012
- /**
8013
- * Check if site assigned with active license.
8014
- *
8015
- * @author Vova Feldman (@svovaf)
8016
- * @since 1.0.6
8017
- *
8018
- * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
8019
- */
8020
- function has_active_license() {
8021
- return (
8022
- is_object( $this->_license ) &&
8023
- is_numeric( $this->_license->id ) &&
8024
- ! $this->_license->is_expired()
8025
- );
8026
- }
8027
-
8028
- /**
8029
- * Check if site assigned with active & valid (not expired) license.
8030
- *
8031
- * @author Vova Feldman (@svovaf)
8032
- * @since 1.2.1
8033
- */
8034
- function has_active_valid_license() {
8035
- return (
8036
- is_object( $this->_license ) &&
8037
- is_numeric( $this->_license->id ) &&
8038
- $this->_license->is_active() &&
8039
- $this->_license->is_valid()
8040
- );
8041
- }
8042
-
8043
- /**
8044
- * Check if site assigned with license with enabled features.
8045
- *
8046
- * @author Vova Feldman (@svovaf)
8047
- * @since 1.0.6
8048
- *
8049
- * @return bool
8050
- */
8051
- function has_features_enabled_license() {
8052
- return (
8053
- is_object( $this->_license ) &&
8054
- is_numeric( $this->_license->id ) &&
8055
- $this->_license->is_features_enabled()
8056
- );
8057
- }
8058
-
8059
- /**
8060
- * Check if user is a trial or have feature enabled license.
8061
- *
8062
- * @author Vova Feldman (@svovaf)
8063
- * @since 1.1.7
8064
- *
8065
- * @return bool
8066
- */
8067
- function can_use_premium_code() {
8068
- return $this->is_trial() || $this->has_features_enabled_license();
8069
- }
8070
-
8071
- /**
8072
- * Sync site's plan.
8073
- *
8074
- * @author Vova Feldman (@svovaf)
8075
- * @since 1.0.3
8076
- *
8077
- * @uses FS_Api
8078
- *
8079
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
8080
- * the admin.
8081
- */
8082
- private function _sync_license( $background = false ) {
8083
- $this->_logger->entrance();
8084
-
8085
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
8086
-
8087
- $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
8088
-
8089
- if ( $is_addon_sync ) {
8090
- $this->_sync_addon_license( $plugin_id, $background );
8091
- } else {
8092
- $this->_sync_plugin_license( $background );
8093
- }
8094
-
8095
- $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
8096
- }
8097
-
8098
- /**
8099
- * Sync plugin's add-on license.
8100
- *
8101
- * @author Vova Feldman (@svovaf)
8102
- * @since 1.0.6
8103
- * @uses FS_Api
8104
- *
8105
- * @param number $addon_id
8106
- * @param bool $background
8107
- */
8108
- private function _sync_addon_license( $addon_id, $background ) {
8109
- $this->_logger->entrance();
8110
-
8111
- if ( $this->is_addon_activated( $addon_id ) ) {
8112
- // If already installed, use add-on sync.
8113
- $fs_addon = self::get_instance_by_id( $addon_id );
8114
- $fs_addon->_sync_license( $background );
8115
-
8116
- return;
8117
- }
8118
-
8119
- // Validate add-on exists.
8120
- $addon = $this->get_addon( $addon_id );
8121
-
8122
- if ( ! is_object( $addon ) ) {
8123
- return;
8124
- }
8125
-
8126
- // Add add-on into account add-ons.
8127
- $account_addons = $this->get_account_addons();
8128
- if ( ! is_array( $account_addons ) ) {
8129
- $account_addons = array();
8130
- }
8131
- $account_addons[] = $addon->id;
8132
- $account_addons = array_unique( $account_addons );
8133
- $this->_store_account_addons( $account_addons );
8134
-
8135
- // Load add-on licenses.
8136
- $licenses = $this->_fetch_licenses( $addon->id );
8137
-
8138
- // Sync add-on licenses.
8139
- if ( ! isset( $licenses->error ) ) {
8140
- $this->_update_licenses( $licenses, $addon->slug );
8141
-
8142
- if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
8143
- $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
8144
-
8145
- if ( ! isset( $plans_result->error ) ) {
8146
- $plans = array();
8147
- foreach ( $plans_result->plans as $plan ) {
8148
- $plans[] = new FS_Plugin_Plan( $plan );
8149
- }
8150
-
8151
- $this->_admin_notices->add_sticky(
8152
- FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
8153
- sprintf(
8154
- __fs( 'addon-successfully-upgraded-message', $this->_slug ),
8155
- $addon->title
8156
- ) . ' ' . $this->_get_latest_download_link(
8157
- __fs( 'download-latest-version', $this->_slug ),
8158
- $addon_id
8159
- )
8160
- :
8161
- sprintf(
8162
- __fs( 'addon-successfully-purchased-message', $this->_slug ),
8163
- $addon->title
8164
- ) . ' ' . $this->_get_latest_download_link(
8165
- __fs( 'download-latest-version', $this->_slug ),
8166
- $addon_id
8167
- ),
8168
- 'addon_plan_upgraded_' . $addon->slug,
8169
- __fs( 'yee-haw', $this->_slug ) . '!'
8170
- );
8171
- }
8172
- }
8173
- }
8174
- }
8175
-
8176
- /**
8177
- * Sync site's plugin plan.
8178
- *
8179
- * @author Vova Feldman (@svovaf)
8180
- * @since 1.0.6
8181
- * @uses FS_Api
8182
- *
8183
- * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
8184
- * the admin.
8185
- */
8186
- private function _sync_plugin_license( $background = false ) {
8187
- $this->_logger->entrance();
8188
-
8189
- /**
8190
- * Sync site info.
8191
- *
8192
- * @todo This line will execute install sync on a daily basis, even if running the free version (for opted-in users). The reason we want to keep it that way is for cases when the user was a paying customer, then there was a failure in subscription payment, and then after some time the payment was successful. This could be heavily optimized. For example, we can skip the $flush if the current install was never associated with a paid version.
8193
- */
8194
- $site = $this->send_install_update( array(), true );
8195
-
8196
- $plan_change = 'none';
8197
-
8198
- if ( $this->is_api_error( $site ) ) {
8199
- // Show API messages only if not background sync or if paying customer.
8200
- if ( ! $background || $this->is_paying() ) {
8201
- // Try to ping API to see if not blocked.
8202
- if ( ! FS_Api::test() ) {
8203
- /**
8204
- * Failed to ping API - blocked!
8205
- *
8206
- * @author Vova Feldman (@svovaf)
8207
- * @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.
8208
- */
8209
- $api = $this->get_api_site_scope();
8210
-
8211
- if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
8212
- self::$_global_admin_notices->add(
8213
- sprintf(
8214
- __fs( 'server-blocking-access', $this->_slug ),
8215
- $this->get_plugin_name(),
8216
- '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
8217
- ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
8218
- __fs( 'oops', $this->_slug ) . '...',
8219
- 'error',
8220
- $background,
8221
- false,
8222
- 'api_blocked'
8223
- );
8224
- }
8225
- } else {
8226
- // Authentication params are broken.
8227
- $this->_admin_notices->add(
8228
- __fs( 'wrong-authentication-param-message', $this->_slug ),
8229
- __fs( 'oops', $this->_slug ) . '...',
8230
- 'error'
8231
- );
8232
- }
8233
- }
8234
-
8235
- // No reason to continue with license sync while there are API issues.
8236
- return;
8237
- }
8238
-
8239
- // Remove sticky API connectivity message.
8240
- self::$_global_admin_notices->remove_sticky( 'api_blocked' );
8241
-
8242
- $site = new FS_Site( $site );
8243
-
8244
- // Sync plans.
8245
- $this->_sync_plans();
8246
-
8247
- if ( ! $this->has_paid_plan() ) {
8248
- $this->_site = $site;
8249
- $this->_enrich_site_plan( true );
8250
- $this->_store_site();
8251
- } else {
8252
- /**
8253
- * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
8254
- * associated with that ID is not included in the user's licenses collection.
8255
- */
8256
- $this->_sync_licenses( $site->license_id );
8257
-
8258
- // Check if plan / license changed.
8259
- if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
8260
- // Check if trial started.
8261
- $site->trial_plan_id != $this->_site->trial_plan_id ||
8262
- $site->trial_ends != $this->_site->trial_ends ||
8263
- // Check if license changed.
8264
- $site->license_id != $this->_site->license_id
8265
- ) {
8266
- if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
8267
- // New trial started.
8268
- $this->_site = $site;
8269
- $plan_change = 'trial_started';
8270
-
8271
- // Store trial plan information.
8272
- $this->_enrich_site_trial_plan( true );
8273
-
8274
- // For trial with subscription use-case.
8275
- $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
8276
-
8277
- if ( is_object( $new_license ) && $new_license->is_valid() ) {
8278
- $this->_site = $site;
8279
- $this->_update_site_license( $new_license );
8280
- $this->_store_licenses();
8281
- $this->_enrich_site_plan( true );
8282
-
8283
- $this->_sync_site_subscription( $this->_license );
8284
- }
8285
- } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
8286
- // Was in trial, but now trial expired and no license ID.
8287
- // New trial started.
8288
- $this->_site = $site;
8289
- $plan_change = 'trial_expired';
8290
-
8291
- // Clear trial plan information.
8292
- $this->_storage->trial_plan = null;
8293
-
8294
- } else {
8295
- $is_free = $this->is_free_plan();
8296
-
8297
- // Make sure license exist and not expired.
8298
- $new_license = is_null( $site->license_id ) ?
8299
- null :
8300
- $this->_get_license_by_id( $site->license_id );
8301
-
8302
- if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
8303
- // License cancelled.
8304
- $this->_site = $site;
8305
- $this->_update_site_license( $new_license );
8306
- $this->_store_licenses();
8307
- $this->_enrich_site_plan( true );
8308
-
8309
- $plan_change = 'cancelled';
8310
- } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
8311
- // The license is expired, so ignore upgrade method.
8312
- } else {
8313
- // License changed.
8314
- $this->_site = $site;
8315
- $this->_update_site_license( $new_license );
8316
- $this->_store_licenses();
8317
- $this->_enrich_site_plan( true );
8318
-
8319
- $plan_change = $is_free ?
8320
- 'upgraded' :
8321
- ( is_object( $new_license ) ?
8322
- 'changed' :
8323
- 'downgraded' );
8324
- }
8325
- }
8326
-
8327
- // Store updated site info.
8328
- $this->_store_site();
8329
- } else {
8330
- if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
8331
- if ( ! $this->has_features_enabled_license() ) {
8332
- $this->_deactivate_license();
8333
- $plan_change = 'downgraded';
8334
- } else {
8335
- $plan_change = 'expired';
8336
- }
8337
- }
8338
-
8339
- if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
8340
- $this->_sync_site_subscription( $this->_license );
8341
- }
8342
- }
8343
- }
8344
-
8345
- if ( $this->has_paid_plan() ) {
8346
- switch ( $plan_change ) {
8347
- case 'none':
8348
- if ( ! $background && is_admin() ) {
8349
- $plan = $this->is_trial() ?
8350
- $this->_storage->trial_plan :
8351
- $this->_site->plan;
8352
-
8353
- $this->_admin_notices->add(
8354
- sprintf(
8355
- __fs( 'plan-did-not-change-message', $this->_slug ),
8356
- '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . __fs( 'trial', $this->_slug ) : '' ) . '</b></i>'
8357
- ) . ' ' . sprintf(
8358
- '<a href="%s">%s</a>',
8359
- $this->contact_url(
8360
- 'bug',
8361
- sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
8362
- strtoupper( $plan->name )
8363
- )
8364
- ),
8365
- __fs( 'contact-us-here', $this->_slug )
8366
- ),
8367
- __fs( 'hmm', $this->_slug ) . '...'
8368
- );
8369
- }
8370
- break;
8371
- case 'upgraded':
8372
- $this->_admin_notices->add_sticky(
8373
- sprintf(
8374
- __fs( 'plan-upgraded-message', $this->_slug ),
8375
- '<i>' . $this->get_plugin_name() . '</i>'
8376
- ) . $this->get_complete_upgrade_instructions(),
8377
- 'plan_upgraded',
8378
- __fs( 'yee-haw', $this->_slug ) . '!'
8379
- );
8380
-
8381
- $this->_admin_notices->remove_sticky( array(
8382
- 'trial_started',
8383
- 'trial_promotion',
8384
- 'trial_expired',
8385
- 'activation_complete',
8386
- ) );
8387
- break;
8388
- case 'changed':
8389
- $this->_admin_notices->add_sticky(
8390
- sprintf(
8391
- __fs( 'plan-changed-to-x-message', $this->_slug ),
8392
- $this->_site->plan->title
8393
- ),
8394
- 'plan_changed'
8395
- );
8396
-
8397
- $this->_admin_notices->remove_sticky( array(
8398
- 'trial_started',
8399
- 'trial_promotion',
8400
- 'trial_expired',
8401
- 'activation_complete',
8402
- ) );
8403
- break;
8404
- case 'downgraded':
8405
- $this->_admin_notices->add_sticky(
8406
- sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
8407
- 'license_expired',
8408
- __fs( 'hmm', $this->_slug ) . '...'
8409
- );
8410
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8411
- break;
8412
- case 'cancelled':
8413
- $this->_admin_notices->add(
8414
- __fs( 'license-cancelled', $this->_slug ) . ' ' .
8415
- sprintf(
8416
- '<a href="%s">%s</a>',
8417
- $this->contact_url( 'bug' ),
8418
- __fs( 'contact-us-here', $this->_slug )
8419
- ),
8420
- __fs( 'hmm', $this->_slug ) . '...',
8421
- 'error'
8422
- );
8423
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8424
- break;
8425
- case 'expired':
8426
- $this->_admin_notices->add_sticky(
8427
- sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
8428
- 'license_expired',
8429
- __fs( 'hmm', $this->_slug ) . '...'
8430
- );
8431
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8432
- break;
8433
- case 'trial_started':
8434
- $this->_admin_notices->add_sticky(
8435
- sprintf(
8436
- __fs( 'trial-started-message', $this->_slug ),
8437
- '<i>' . $this->get_plugin_name() . '</i>'
8438
- ) . $this->get_complete_upgrade_instructions( $this->_storage->trial_plan->title ),
8439
- 'trial_started',
8440
- __fs( 'yee-haw', $this->_slug ) . '!'
8441
- );
8442
-
8443
- $this->_admin_notices->remove_sticky( array(
8444
- 'trial_promotion',
8445
- ) );
8446
- break;
8447
- case 'trial_expired':
8448
- $this->_admin_notices->add_sticky(
8449
- __fs( 'trial-expired-message', $this->_slug ),
8450
- 'trial_expired',
8451
- __fs( 'hmm', $this->_slug ) . '...'
8452
- );
8453
- $this->_admin_notices->remove_sticky( array(
8454
- 'trial_started',
8455
- 'trial_promotion',
8456
- 'plan_upgraded',
8457
- ) );
8458
- break;
8459
- }
8460
- }
8461
-
8462
- if ( 'none' !== $plan_change ) {
8463
- $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
8464
- }
8465
- }
8466
-
8467
- /**
8468
- * @author Vova Feldman (@svovaf)
8469
- * @since 1.0.5
8470
- *
8471
- * @param bool $background
8472
- */
8473
- protected function _activate_license( $background = false ) {
8474
- $this->_logger->entrance();
8475
-
8476
- $license_id = fs_request_get( 'license_id' );
8477
-
8478
- if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
8479
- // License is already activated.
8480
- return;
8481
- }
8482
-
8483
- $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
8484
- $this->_get_license_by_id( $license_id ) :
8485
- $this->_get_available_premium_license();
8486
-
8487
- if ( ! is_object( $premium_license ) ) {
8488
- return;
8489
- }
8490
-
8491
- /**
8492
- * If the premium license is already associated with the install, just
8493
- * update the license reference (activation is not required).
8494
- *
8495
- * @since 1.1.9
8496
- */
8497
- if ( $premium_license->id == $this->_site->license_id ) {
8498
- // License is already activated.
8499
- $this->_update_site_license( $premium_license );
8500
- $this->_enrich_site_plan( false );
8501
- $this->_store_account();
8502
-
8503
- return;
8504
- }
8505
-
8506
- if ( $this->_site->user_id != $premium_license->user_id ) {
8507
- $api_request_params = array( 'license_key' => $premium_license->secret_key );
8508
- } else {
8509
- $api_request_params = array();
8510
- }
8511
-
8512
- $api = $this->get_api_site_scope();
8513
- $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
8514
-
8515
- if ( $this->is_api_error( $license ) ) {
8516
- if ( ! $background ) {
8517
- $this->_admin_notices->add( sprintf(
8518
- '%s %s',
8519
- __fs( 'license-activation-failed-message', $this->_slug ),
8520
- ( is_object( $license ) && isset( $license->error ) ?
8521
- $license->error->message :
8522
- sprintf( '%s<br><code>%s</code>',
8523
- __fs( 'server-error-message', $this->_slug ),
8524
- var_export( $license, true )
8525
- )
8526
- )
8527
- ),
8528
- __fs( 'hmm', $this->_slug ) . '...',
8529
- 'error'
8530
- );
8531
- }
8532
-
8533
- return;
8534
- }
8535
-
8536
- $premium_license = new FS_Plugin_License( $license );
8537
-
8538
- // Updated site plan.
8539
- $site = $this->get_api_site_scope()->get( '/', true );
8540
- if ( ! $this->is_api_error( $site ) ) {
8541
- $this->_site = new FS_Site( $site );
8542
- }
8543
- $this->_update_site_license( $premium_license );
8544
- $this->_enrich_site_plan( false );
8545
-
8546
- $this->_store_account();
8547
-
8548
- if ( ! $background ) {
8549
- $this->_admin_notices->add_sticky(
8550
- __fs( 'license-activated-message', $this->_slug ) .
8551
- $this->get_complete_upgrade_instructions(),
8552
- 'license_activated',
8553
- __fs( 'yee-haw', $this->_slug ) . '!'
8554
- );
8555
- }
8556
-
8557
- $this->_admin_notices->remove_sticky( array(
8558
- 'trial_promotion',
8559
- 'license_expired',
8560
- ) );
8561
- }
8562
-
8563
- /**
8564
- * @author Vova Feldman (@svovaf)
8565
- * @since 1.0.5
8566
- *
8567
- * @param bool $show_notice
8568
- */
8569
- protected function _deactivate_license( $show_notice = true ) {
8570
- $this->_logger->entrance();
8571
-
8572
- if ( ! is_object( $this->_license ) ) {
8573
- $this->_admin_notices->add(
8574
- sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
8575
- __fs( 'hmm', $this->_slug ) . '...'
8576
- );
8577
-
8578
- return;
8579
- }
8580
-
8581
- $api = $this->get_api_site_scope();
8582
- $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
8583
-
8584
- if ( isset( $license->error ) ) {
8585
- $this->_admin_notices->add(
8586
- __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
8587
- __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
8588
- __fs( 'hmm', $this->_slug ) . '...',
8589
- 'error'
8590
- );
8591
-
8592
- return;
8593
- }
8594
-
8595
- // Update license cache.
8596
- for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
8597
- if ( $license->id == $this->_licenses[ $i ]->id ) {
8598
- $this->_licenses[ $i ] = new FS_Plugin_License( $license );
8599
- }
8600
- }
8601
-
8602
- // Updated site plan to default.
8603
- $this->_sync_plans();
8604
- $this->_site->plan->id = $this->_plans[0]->id;
8605
- // Unlink license from site.
8606
- $this->_update_site_license( null );
8607
- $this->_enrich_site_plan( false );
8608
-
8609
- $this->_store_account();
8610
-
8611
- if ( $show_notice ) {
8612
- $this->_admin_notices->add(
8613
- sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
8614
- __fs( 'ok', $this->_slug )
8615
- );
8616
- }
8617
-
8618
- $this->_admin_notices->remove_sticky( array(
8619
- 'plan_upgraded',
8620
- 'license_activated',
8621
- ) );
8622
- }
8623
-
8624
- /**
8625
- * Site plan downgrade.
8626
- *
8627
- * @author Vova Feldman (@svovaf)
8628
- * @since 1.0.4
8629
- *
8630
- * @uses FS_Api
8631
- */
8632
- private function _downgrade_site() {
8633
- $this->_logger->entrance();
8634
-
8635
- $api = $this->get_api_site_scope();
8636
- $site = $api->call( 'downgrade.json', 'put' );
8637
-
8638
- $plan_downgraded = false;
8639
- $plan = false;
8640
- if ( ! isset( $site->error ) ) {
8641
- $prev_plan_id = $this->_site->plan->id;
8642
-
8643
- // Update new site plan id.
8644
- $this->_site->plan->id = $site->plan_id;
8645
-
8646
- $plan = $this->_enrich_site_plan();
8647
- $subscription = $this->_sync_site_subscription( $this->_license );
8648
-
8649
- // Plan downgraded if plan was changed or subscription was cancelled.
8650
- $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
8651
- ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
8652
- } else {
8653
- // handle different error cases.
8654
-
8655
- }
8656
-
8657
- if ( $plan_downgraded ) {
8658
- // Remove previous sticky message about upgrade (if exist).
8659
- $this->_admin_notices->remove_sticky( 'plan_upgraded' );
8660
-
8661
- $this->_admin_notices->add(
8662
- sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
8663
- $plan->title,
8664
- human_time_diff( time(), strtotime( $this->_license->expiration ) )
8665
- )
8666
- );
8667
-
8668
- // Store site updates.
8669
- $this->_store_site();
8670
- } else {
8671
- $this->_admin_notices->add(
8672
- __fs( 'plan-downgraded-failure-message', $this->_slug ),
8673
- __fs( 'oops', $this->_slug ) . '...',
8674
- 'error'
8675
- );
8676
- }
8677
- }
8678
-
8679
- /**
8680
- * @author Vova Feldman (@svovaf)
8681
- * @since 1.1.8.1
8682
- *
8683
- * @param bool|string $plan_name
8684
- *
8685
- * @return bool If trial was successfully started.
8686
- */
8687
- function start_trial( $plan_name = false ) {
8688
- $this->_logger->entrance();
8689
-
8690
- if ( $this->is_trial() ) {
8691
- // Already in trial mode.
8692
- $this->_admin_notices->add(
8693
- __fs( 'in-trial-mode', $this->_slug ),
8694
- __fs( 'oops', $this->_slug ) . '...',
8695
- 'error'
8696
- );
8697
-
8698
- return false;
8699
- }
8700
-
8701
- if ( $this->_site->is_trial_utilized() ) {
8702
- // Trial was already utilized.
8703
- $this->_admin_notices->add(
8704
- __fs( 'trial-utilized', $this->_slug ),
8705
- __fs( 'oops', $this->_slug ) . '...',
8706
- 'error'
8707
- );
8708
-
8709
- return false;
8710
- }
8711
-
8712
- if ( false !== $plan_name ) {
8713
- $plan = $this->get_plan_by_name( $plan_name );
8714
-
8715
- if ( false === $plan ) {
8716
- // Plan doesn't exist.
8717
- $this->_admin_notices->add(
8718
- sprintf( __fs( 'trial-plan-x-not-exist', $this->_slug ), $plan_name ),
8719
- __fs( 'oops', $this->_slug ) . '...',
8720
- 'error'
8721
- );
8722
-
8723
- return false;
8724
- }
8725
-
8726
- if ( ! $plan->has_trial() ) {
8727
- // Plan doesn't exist.
8728
- $this->_admin_notices->add(
8729
- sprintf( __fs( 'plan-x-no-trial', $this->_slug ), $plan_name ),
8730
- __fs( 'oops', $this->_slug ) . '...',
8731
- 'error'
8732
- );
8733
-
8734
- return false;
8735
- }
8736
- } else {
8737
- if ( ! $this->has_trial_plan() ) {
8738
- // None of the plans have a trial.
8739
- $this->_admin_notices->add(
8740
- __fs( 'no-trials', $this->_slug ),
8741
- __fs( 'oops', $this->_slug ) . '...',
8742
- 'error'
8743
- );
8744
-
8745
- return false;
8746
- }
8747
-
8748
- $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
8749
-
8750
- $plan = $plans_with_trial[0];
8751
- }
8752
-
8753
- $api = $this->get_api_site_scope();
8754
- $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
8755
-
8756
- if ( $this->is_api_error( $plan ) ) {
8757
- // Some API error while trying to start the trial.
8758
- $this->_admin_notices->add(
8759
- __fs( 'unexpected-api-error', $this->_slug ) . ' ' . var_export( $plan, true ),
8760
- __fs( 'oops', $this->_slug ) . '...',
8761
- 'error'
8762
- );
8763
-
8764
- return false;
8765
- }
8766
-
8767
- // Sync license.
8768
- $this->_sync_license();
8769
-
8770
- return $this->is_trial();
8771
- }
8772
-
8773
- /**
8774
- * Cancel site trial.
8775
- *
8776
- * @author Vova Feldman (@svovaf)
8777
- * @since 1.0.9
8778
- *
8779
- * @uses FS_Api
8780
- */
8781
- private function _cancel_trial() {
8782
- $this->_logger->entrance();
8783
-
8784
- if ( ! $this->is_trial() ) {
8785
- $this->_admin_notices->add(
8786
- __fs( 'trial-cancel-no-trial-message', $this->_slug ),
8787
- __fs( 'oops', $this->_slug ) . '...',
8788
- 'error'
8789
- );
8790
-
8791
- return;
8792
- }
8793
-
8794
- $api = $this->get_api_site_scope();
8795
- $site = $api->call( 'trials.json', 'delete' );
8796
-
8797
- $trial_cancelled = false;
8798
-
8799
- if ( ! $this->is_api_error( $site ) ) {
8800
- $prev_trial_ends = $this->_site->trial_ends;
8801
-
8802
- if ( $this->is_paid_trial() ) {
8803
- $this->_license->expiration = $site->trial_ends;
8804
- $this->_license->is_cancelled = true;
8805
- $this->_update_site_license( $this->_license );
8806
- $this->_store_licenses();
8807
-
8808
- // Clear subscription reference.
8809
- $this->_sync_site_subscription( null );
8810
- }
8811
-
8812
- // Update site info.
8813
- $this->_site = new FS_Site( $site );
8814
- $this->_enrich_site_plan();
8815
-
8816
- $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
8817
- } else {
8818
- // handle different error cases.
8819
-
8820
- }
8821
-
8822
- if ( $trial_cancelled ) {
8823
- // Remove previous sticky messages about upgrade or trial (if exist).
8824
- $this->_admin_notices->remove_sticky( array(
8825
- 'trial_started',
8826
- 'trial_promotion',
8827
- 'plan_upgraded',
8828
- ) );
8829
-
8830
- // Store site updates.
8831
- $this->_store_site();
8832
-
8833
- // Clear trial plan information.
8834
- unset( $this->_storage->trial_plan );
8835
-
8836
- if ( ! $this->is_addon() ||
8837
- ! $this->deactivate_premium_only_addon_without_license( true )
8838
- ) {
8839
- $this->_admin_notices->add(
8840
- sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
8841
- );
8842
- }
8843
- } else {
8844
- $this->_admin_notices->add(
8845
- __fs( 'trial-cancel-failure-message', $this->_slug ),
8846
- __fs( 'oops', $this->_slug ) . '...',
8847
- 'error'
8848
- );
8849
- }
8850
- }
8851
-
8852
- /**
8853
- * @author Vova Feldman (@svovaf)
8854
- * @since 1.0.6
8855
- *
8856
- * @param bool|number $plugin_id
8857
- *
8858
- * @return bool
8859
- */
8860
- private function _is_addon_id( $plugin_id ) {
8861
- return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
8862
- }
8863
-
8864
- /**
8865
- * Check if user eligible to download premium version updates.
8866
- *
8867
- * @author Vova Feldman (@svovaf)
8868
- * @since 1.0.6
8869
- *
8870
- * @return bool
8871
- */
8872
- private function _can_download_premium() {
8873
- return $this->has_active_valid_license() ||
8874
- ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
8875
- }
8876
-
8877
- /**
8878
- *
8879
- * @author Vova Feldman (@svovaf)
8880
- * @since 1.0.6
8881
- *
8882
- * @param bool|number $addon_id
8883
- * @param string $type "json" or "zip"
8884
- *
8885
- * @return string
8886
- */
8887
- private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
8888
-
8889
- $is_addon = $this->_is_addon_id( $addon_id );
8890
-
8891
- $is_premium = null;
8892
- if ( ! $is_addon ) {
8893
- $is_premium = $this->_can_download_premium();
8894
- } else if ( $this->is_addon_activated( $addon_id ) ) {
8895
- $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
8896
- }
8897
-
8898
- return // If add-on, then append add-on ID.
8899
- ( $is_addon ? "/addons/$addon_id" : '' ) .
8900
- '/updates/latest.' . $type .
8901
- // If add-on and not yet activated, try to fetch based on server licensing.
8902
- ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
8903
- }
8904
-
8905
- /**
8906
- * @author Vova Feldman (@svovaf)
8907
- * @since 1.0.4
8908
- *
8909
- * @param bool|number $addon_id
8910
- * @param bool $flush Since 1.1.7.3
8911
- *
8912
- * @return object|false Plugin latest tag info.
8913
- */
8914
- function _fetch_latest_version( $addon_id = false, $flush = true ) {
8915
- $this->_logger->entrance();
8916
-
8917
- /**
8918
- * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
8919
- * @since 1.1.7.4 Also check updates for add-ons.
8920
- */
8921
- if ( ! $this->is_registered() &&
8922
- ! $this->_is_addon_id( $addon_id )
8923
- ) {
8924
- return false;
8925
- }
8926
-
8927
- $tag = $this->get_api_site_or_plugin_scope()->get(
8928
- $this->_get_latest_version_endpoint( $addon_id, 'json' ),
8929
- $flush
8930
- );
8931
-
8932
- $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
8933
-
8934
- $this->_logger->departure( 'Latest version ' . $latest_version );
8935
-
8936
- return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
8937
- }
8938
-
8939
- #region Download Plugin ------------------------------------------------------------------
8940
-
8941
- /**
8942
- * Download latest plugin version, based on plan.
8943
- *
8944
- * Not like _download_latest(), this will redirect the page
8945
- * to secure download url to prevent dual download (from FS to WP server,
8946
- * and then from WP server to the client / browser).
8947
- *
8948
- * @author Vova Feldman (@svovaf)
8949
- * @since 1.0.9
8950
- *
8951
- * @param bool|number $plugin_id
8952
- *
8953
- * @uses FS_Api
8954
- * @uses wp_redirect()
8955
- */
8956
- private function _download_latest_directly( $plugin_id = false ) {
8957
- $this->_logger->entrance();
8958
-
8959
- wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
8960
- }
8961
-
8962
- /**
8963
- * Get latest plugin FS API download URL.
8964
- *
8965
- * @author Vova Feldman (@svovaf)
8966
- * @since 1.0.9
8967
- *
8968
- * @param bool|number $plugin_id
8969
- *
8970
- * @return string
8971
- */
8972
- private function _get_latest_download_api_url( $plugin_id = false ) {
8973
- $this->_logger->entrance();
8974
-
8975
- return $this->get_api_site_scope()->get_signed_url(
8976
- $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
8977
- );
8978
- }
8979
-
8980
- /**
8981
- * Get payment invoice URL.
8982
- *
8983
- * @author Vova Feldman (@svovaf)
8984
- * @since 1.2.0
8985
- *
8986
- * @param bool|number $payment_id
8987
- *
8988
- * @return string
8989
- */
8990
- function _get_invoice_api_url( $payment_id = false ) {
8991
- $this->_logger->entrance();
8992
-
8993
- return $this->get_api_user_scope()->get_signed_url(
8994
- "/payments/{$payment_id}/invoice.pdf"
8995
- );
8996
- }
8997
-
8998
- /**
8999
- * Get latest plugin download link.
9000
- *
9001
- * @author Vova Feldman (@svovaf)
9002
- * @since 1.0.9
9003
- *
9004
- * @param string $label
9005
- * @param bool|number $plugin_id
9006
- *
9007
- * @return string
9008
- */
9009
- private function _get_latest_download_link( $label, $plugin_id = false ) {
9010
- return sprintf(
9011
- '<a target="_blank" href="%s">%s</a>',
9012
- $this->_get_latest_download_local_url( $plugin_id ),
9013
- $label
9014
- );
9015
- }
9016
-
9017
- /**
9018
- * Get latest plugin download local URL.
9019
- *
9020
- * @author Vova Feldman (@svovaf)
9021
- * @since 1.0.9
9022
- *
9023
- * @param bool|number $plugin_id
9024
- *
9025
- * @return string
9026
- */
9027
- function _get_latest_download_local_url( $plugin_id = false ) {
9028
- // Add timestamp to protect from caching.
9029
- $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
9030
-
9031
- if ( ! empty( $plugin_id ) ) {
9032
- $params['plugin_id'] = $plugin_id;
9033
- }
9034
-
9035
- return $this->get_account_url( 'download_latest', $params );
9036
- }
9037
-
9038
- #endregion Download Plugin ------------------------------------------------------------------
9039
-
9040
- /**
9041
- * @author Vova Feldman (@svovaf)
9042
- * @since 1.0.4
9043
- *
9044
- * @uses FS_Api
9045
- *
9046
- * @param bool $background Hints the method if it's a background updates check. If false, it means that
9047
- * was initiated by the admin.
9048
- * @param bool|number $plugin_id
9049
- * @param bool $flush Since 1.1.7.3
9050
- */
9051
- private function _check_updates( $background = false, $plugin_id = false, $flush = true ) {
9052
- $this->_logger->entrance();
9053
-
9054
- // Check if there's a newer version for download.
9055
- $new_version = $this->_fetch_newer_version( $plugin_id, $flush );
9056
-
9057
- $update = null;
9058
- if ( is_object( $new_version ) ) {
9059
- $update = new FS_Plugin_Tag( $new_version );
9060
-
9061
- if ( ! $background ) {
9062
- $this->_admin_notices->add(
9063
- sprintf(
9064
- __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
9065
- $update->version,
9066
- sprintf(
9067
- '<a href="%s" target="_blank">%s</a>',
9068
- $this->get_account_url( 'download_latest' ),
9069
- sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
9070
- )
9071
- ),
9072
- __fs( 'new', $this->_slug ) . '!'
9073
- );
9074
- }
9075
- } else if ( false === $new_version && ! $background ) {
9076
- $this->_admin_notices->add(
9077
- __fs( 'you-have-latest', $this->_slug ),
9078
- __fs( 'you-are-good', $this->_slug )
9079
- );
9080
- }
9081
-
9082
- $this->_store_update( $update, true, $plugin_id );
9083
- }
9084
-
9085
- /**
9086
- * @author Vova Feldman (@svovaf)
9087
- * @since 1.0.4
9088
- *
9089
- * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
9090
- *
9091
- * @return FS_Plugin[]
9092
- *
9093
- * @uses FS_Api
9094
- */
9095
- private function _sync_addons( $flush = false ) {
9096
- $this->_logger->entrance();
9097
-
9098
- $api = $this->get_api_site_or_plugin_scope();
9099
-
9100
- /**
9101
- * @since 1.2.1
9102
- *
9103
- * If there's a cached version of the add-ons and not asking
9104
- * for a flush, just use the currently stored add-ons.
9105
- */
9106
- if ( ! $flush && $api->is_cached( '/addons.json?enriched=true' ) ) {
9107
- $addons = self::get_all_addons();
9108
-
9109
- return $addons[ $this->_plugin->id ];
9110
- }
9111
-
9112
- $result = $api->get( '/addons.json?enriched=true', $flush );
9113
-
9114
- $addons = array();
9115
- if ( ! $this->is_api_error( $result ) ) {
9116
- for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
9117
- $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
9118
- }
9119
-
9120
- $this->_store_addons( $addons, true );
9121
- }
9122
-
9123
- return $addons;
9124
- }
9125
-
9126
- /**
9127
- * Handle user email update.
9128
- *
9129
- * @author Vova Feldman (@svovaf)
9130
- * @since 1.0.3
9131
- * @uses FS_Api
9132
- *
9133
- * @param string $new_email
9134
- *
9135
- * @return object
9136
- */
9137
- private function _update_email( $new_email ) {
9138
- $this->_logger->entrance();
9139
-
9140
-
9141
- $api = $this->get_api_user_scope();
9142
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
9143
- 'email' => $new_email,
9144
- 'after_email_confirm_url' => $this->_get_admin_page_url(
9145
- 'account',
9146
- array( 'fs_action' => 'sync_user' )
9147
- ),
9148
- ) );
9149
-
9150
- if ( ! isset( $user->error ) ) {
9151
- $this->_user->email = $user->email;
9152
- $this->_user->is_verified = $user->is_verified;
9153
- $this->_store_user();
9154
- } else {
9155
- // handle different error cases.
9156
-
9157
- }
9158
-
9159
- return $user;
9160
- }
9161
-
9162
- /**
9163
- * @author Vova Feldman (@svovaf)
9164
- * @since 1.1.1
9165
- *
9166
- * @param mixed $result
9167
- *
9168
- * @return bool Is API result contains an error.
9169
- */
9170
- private function is_api_error( $result ) {
9171
- return ( is_object( $result ) && isset( $result->error ) ) ||
9172
- is_string( $result );
9173
- }
9174
-
9175
- /**
9176
- * Start install ownership change.
9177
- *
9178
- * @author Vova Feldman (@svovaf)
9179
- * @since 1.1.1
9180
- * @uses FS_Api
9181
- *
9182
- * @param string $candidate_email
9183
- *
9184
- * @return bool Is ownership change successfully initiated.
9185
- */
9186
- private function init_change_owner( $candidate_email ) {
9187
- $this->_logger->entrance();
9188
-
9189
- $api = $this->get_api_site_scope();
9190
- $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
9191
- 'email' => $candidate_email,
9192
- 'after_confirm_url' => $this->_get_admin_page_url(
9193
- 'account',
9194
- array( 'fs_action' => 'change_owner' )
9195
- ),
9196
- ) );
9197
-
9198
- return ! $this->is_api_error( $result );
9199
- }
9200
-
9201
- /**
9202
- * Handle install ownership change.
9203
- *
9204
- * @author Vova Feldman (@svovaf)
9205
- * @since 1.1.1
9206
- * @uses FS_Api
9207
- *
9208
- * @return bool Was ownership change successfully complete.
9209
- */
9210
- private function complete_change_owner() {
9211
- $this->_logger->entrance();
9212
-
9213
- $site_result = $this->get_api_site_scope( true )->get();
9214
- $site = new FS_Site( $site_result );
9215
- $this->_site = $site;
9216
-
9217
- $user = new FS_User();
9218
- $user->id = fs_request_get( 'user_id' );
9219
-
9220
- // Validate install's user and given user.
9221
- if ( $user->id != $this->_site->user_id ) {
9222
- return false;
9223
- }
9224
-
9225
- $user->public_key = fs_request_get( 'user_public_key' );
9226
- $user->secret_key = fs_request_get( 'user_secret_key' );
9227
-
9228
- // Fetch new user information.
9229
- $this->_user = $user;
9230
- $user_result = $this->get_api_user_scope( true )->get();
9231
- $user = new FS_User( $user_result );
9232
- $this->_user = $user;
9233
-
9234
- $this->_set_account( $user, $site );
9235
-
9236
- return true;
9237
- }
9238
-
9239
- /**
9240
- * Handle user name update.
9241
- *
9242
- * @author Vova Feldman (@svovaf)
9243
- * @since 1.0.9
9244
- * @uses FS_Api
9245
- *
9246
- * @return object
9247
- */
9248
- private function update_user_name() {
9249
- $this->_logger->entrance();
9250
- $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
9251
-
9252
- $api = $this->get_api_user_scope();
9253
- $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
9254
- 'name' => $name,
9255
- ) );
9256
-
9257
- if ( ! isset( $user->error ) ) {
9258
- $this->_user->first = $user->first;
9259
- $this->_user->last = $user->last;
9260
- $this->_store_user();
9261
- } else {
9262
- // handle different error cases.
9263
-
9264
- }
9265
-
9266
- return $user;
9267
- }
9268
-
9269
- /**
9270
- * Verify user email.
9271
- *
9272
- * @author Vova Feldman (@svovaf)
9273
- * @since 1.0.3
9274
- * @uses FS_Api
9275
- */
9276
- private function verify_email() {
9277
- $this->_handle_account_user_sync();
9278
-
9279
- if ( $this->_user->is_verified() ) {
9280
- return;
9281
- }
9282
-
9283
- $api = $this->get_api_site_scope();
9284
- $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
9285
- 'after_email_confirm_url' => $this->_get_admin_page_url(
9286
- 'account',
9287
- array( 'fs_action' => 'sync_user' )
9288
- )
9289
- ) );
9290
-
9291
- if ( ! isset( $result->error ) ) {
9292
- $this->_admin_notices->add( sprintf(
9293
- __fs( 'verification-email-sent-message', $this->_slug ),
9294
- sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
9295
- ) );
9296
- } else {
9297
- // handle different error cases.
9298
-
9299
- }
9300
- }
9301
-
9302
- /**
9303
- * @author Vova Feldman (@svovaf)
9304
- * @since 1.1.2
9305
- *
9306
- * @param array $params
9307
- *
9308
- * @return string
9309
- */
9310
- private function get_activation_url( $params = array() ) {
9311
- return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params ) );
9312
- }
9313
-
9314
- /**
9315
- * Get the URL of the page that should be loaded after the user connect or skip in the opt-in screen.
9316
- *
9317
- * @author Vova Feldman (@svovaf)
9318
- * @since 1.1.3
9319
- *
9320
- * @param string $filter Filter name.
9321
- *
9322
- * @return string
9323
- */
9324
- private function get_after_activation_url( $filter ) {
9325
- $first_time_path = $this->_menu->get_first_time_path();
9326
-
9327
- return $this->apply_filters(
9328
- $filter,
9329
- empty( $first_time_path ) ?
9330
- $this->_get_admin_page_url() :
9331
- $first_time_path
9332
- );
9333
- }
9334
-
9335
- /**
9336
- * Handle account page updates / edits / actions.
9337
- *
9338
- * @author Vova Feldman (@svovaf)
9339
- * @since 1.0.2
9340
- *
9341
- */
9342
- private function _handle_account_edits() {
9343
- if ( ! current_user_can( 'activate_plugins' ) ) {
9344
- return;
9345
- }
9346
-
9347
- $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
9348
- $action = fs_get_action();
9349
-
9350
- switch ( $action ) {
9351
- case 'delete_account':
9352
- check_admin_referer( $action );
9353
-
9354
- if ( $plugin_id == $this->get_id() ) {
9355
- $this->delete_account_event();
9356
-
9357
- // Clear user and site.
9358
- $this->_site = null;
9359
- $this->_user = null;
9360
-
9361
- if ( fs_redirect( $this->get_activation_url() ) ) {
9362
- exit();
9363
- }
9364
- } else {
9365
- if ( $this->is_addon_activated( $plugin_id ) ) {
9366
- $fs_addon = self::get_instance_by_id( $plugin_id );
9367
- $fs_addon->delete_account_event();
9368
-
9369
- if ( fs_redirect( $this->_get_admin_page_url( 'account' ) ) ) {
9370
- exit();
9371
- }
9372
- }
9373
- }
9374
-
9375
- return;
9376
-
9377
- case 'downgrade_account':
9378
- check_admin_referer( $action );
9379
- $this->_downgrade_site();
9380
-
9381
- return;
9382
-
9383
- case 'activate_license':
9384
- check_admin_referer( $action );
9385
-
9386
- if ( $plugin_id == $this->get_id() ) {
9387
- $this->_activate_license();
9388
- } else {
9389
- if ( $this->is_addon_activated( $plugin_id ) ) {
9390
- $fs_addon = self::get_instance_by_id( $plugin_id );
9391
- $fs_addon->_activate_license();
9392
- }
9393
- }
9394
-
9395
- return;
9396
-
9397
- case 'deactivate_license':
9398
- check_admin_referer( $action );
9399
-
9400
- if ( $plugin_id == $this->get_id() ) {
9401
- $this->_deactivate_license();
9402
- } else {
9403
- if ( $this->is_addon_activated( $plugin_id ) ) {
9404
- $fs_addon = self::get_instance_by_id( $plugin_id );
9405
- $fs_addon->_deactivate_license();
9406
- }
9407
- }
9408
-
9409
- return;
9410
-
9411
- case 'check_updates':
9412
- check_admin_referer( $action );
9413
- $this->_check_updates();
9414
-
9415
- return;
9416
-
9417
- case 'change_owner':
9418
- $state = fs_request_get( 'state', 'init' );
9419
- switch ( $state ) {
9420
- case 'init':
9421
- $candidate_email = fs_request_get( 'candidate_email', '' );
9422
-
9423
- if ( $this->init_change_owner( $candidate_email ) ) {
9424
- $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
9425
- }
9426
- break;
9427
- case 'owner_confirmed':
9428
- $candidate_email = fs_request_get( 'candidate_email', '' );
9429
-
9430
- $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
9431
- break;
9432
- case 'candidate_confirmed':
9433
- if ( $this->complete_change_owner() ) {
9434
- $this->_admin_notices->add_sticky(
9435
- sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
9436
- 'ownership_changed',
9437
- __fs( 'congrats', $this->_slug ) . '!'
9438
- );
9439
- } else {
9440
- // @todo Handle failed ownership change message.
9441
- }
9442
- break;
9443
- }
9444
-
9445
- return;
9446
-
9447
- case 'update_email':
9448
- check_admin_referer( 'update_email' );
9449
-
9450
- $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
9451
- $result = $this->_update_email( $new_email );
9452
-
9453
- if ( isset( $result->error ) ) {
9454
- switch ( $result->error->code ) {
9455
- case 'user_exist':
9456
- $this->_admin_notices->add(
9457
- __fs( 'user-exist-message', $this->_slug ) . ' ' .
9458
- sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
9459
- sprintf(
9460
- '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9461
- $this->get_account_url( 'change_owner', array(
9462
- 'state' => 'init',
9463
- 'candidate_email' => $new_email
9464
- ) ),
9465
- __fs( 'change-ownership', $this->_slug )
9466
- ),
9467
- __fs( 'oops', $this->_slug ) . '...',
9468
- 'error'
9469
- );
9470
- break;
9471
- }
9472
- } else {
9473
- $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
9474
- }
9475
-
9476
- return;
9477
-
9478
- case 'update_user_name':
9479
- check_admin_referer( 'update_user_name' );
9480
-
9481
- $result = $this->update_user_name();
9482
-
9483
- if ( isset( $result->error ) ) {
9484
- $this->_admin_notices->add(
9485
- __fs( 'name-update-failed-message', $this->_slug ),
9486
- __fs( 'oops', $this->_slug ) . '...',
9487
- 'error'
9488
- );
9489
- } else {
9490
- $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
9491
- }
9492
-
9493
- return;
9494
-
9495
- #region Actions that might be called from external links (e.g. email)
9496
-
9497
- case 'cancel_trial':
9498
- if ( $plugin_id == $this->get_id() ) {
9499
- $this->_cancel_trial();
9500
- } else {
9501
- if ( $this->is_addon_activated( $plugin_id ) ) {
9502
- $fs_addon = self::get_instance_by_id( $plugin_id );
9503
- $fs_addon->_cancel_trial();
9504
- }
9505
- }
9506
-
9507
- return;
9508
-
9509
- case 'verify_email':
9510
- $this->verify_email();
9511
-
9512
- return;
9513
-
9514
- case 'sync_user':
9515
- $this->_handle_account_user_sync();
9516
-
9517
- return;
9518
-
9519
- case $this->_slug . '_sync_license':
9520
- $this->_sync_license();
9521
-
9522
- return;
9523
-
9524
- case 'download_latest':
9525
- $this->_download_latest_directly( $plugin_id );
9526
-
9527
- return;
9528
-
9529
- #endregion
9530
- }
9531
-
9532
- if ( WP_FS__IS_POST_REQUEST ) {
9533
- $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
9534
- foreach ( $properties as $p ) {
9535
- if ( 'update_' . $p === $action ) {
9536
- check_admin_referer( $action );
9537
-
9538
- $this->_logger->log( $action );
9539
-
9540
- $site_property = substr( $p, strlen( 'site_' ) );
9541
- $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
9542
- $this->get_site()->{$site_property} = $site_property_value;
9543
-
9544
- // Store account after modification.
9545
- $this->_store_site();
9546
-
9547
- $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
9548
-
9549
- $this->_admin_notices->add( sprintf(
9550
- __fs( 'x-updated', $this->_slug ),
9551
- '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
9552
-
9553
- return;
9554
- }
9555
- }
9556
- }
9557
- }
9558
-
9559
- /**
9560
- * Account page resources load.
9561
- *
9562
- * @author Vova Feldman (@svovaf)
9563
- * @since 1.0.6
9564
- */
9565
- function _account_page_load() {
9566
- $this->_logger->entrance();
9567
-
9568
- $this->_logger->info( var_export( $_REQUEST, true ) );
9569
-
9570
- fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
9571
-
9572
- if ( $this->has_addons() ) {
9573
- wp_enqueue_script( 'plugin-install' );
9574
- add_thickbox();
9575
-
9576
- function fs_addons_body_class( $classes ) {
9577
- $classes .= ' plugins-php';
9578
-
9579
- return $classes;
9580
- }
9581
-
9582
- add_filter( 'admin_body_class', 'fs_addons_body_class' );
9583
- }
9584
-
9585
- if ( $this->has_paid_plan() &&
9586
- ! $this->has_any_license() &&
9587
- ! $this->is_sync_executed()
9588
- ) {
9589
- /**
9590
- * If no licenses found and no sync job was executed during the last 24 hours,
9591
- * just execute the sync job right away (blocking execution).
9592
- *
9593
- * @since 1.1.7.3
9594
- */
9595
- $this->run_manual_sync();
9596
- }
9597
-
9598
- $this->_handle_account_edits();
9599
-
9600
- $this->do_action( 'account_page_load_before_departure' );
9601
- }
9602
-
9603
- /**
9604
- * Render account page.
9605
- *
9606
- * @author Vova Feldman (@svovaf)
9607
- * @since 1.0.0
9608
- */
9609
- function _account_page_render() {
9610
- $this->_logger->entrance();
9611
-
9612
- $vars = array( 'slug' => $this->_slug );
9613
- if ( 'billing' === fs_request_get( 'tab' ) ) {
9614
- fs_require_once_template( 'billing.php', $vars );
9615
- } else {
9616
- fs_require_once_template( 'account.php', $vars );
9617
- }
9618
- }
9619
-
9620
- /**
9621
- * Render account connect page.
9622
- *
9623
- * @author Vova Feldman (@svovaf)
9624
- * @since 1.0.7
9625
- */
9626
- function _connect_page_render() {
9627
- $this->_logger->entrance();
9628
-
9629
- $vars = array( 'slug' => $this->_slug );
9630
- fs_require_once_template( 'connect.php', $vars );
9631
- }
9632
-
9633
- /**
9634
- * Load required resources before add-ons page render.
9635
- *
9636
- * @author Vova Feldman (@svovaf)
9637
- * @since 1.0.6
9638
- */
9639
- function _addons_page_load() {
9640
- $this->_logger->entrance();
9641
-
9642
- fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
9643
-
9644
- wp_enqueue_script( 'plugin-install' );
9645
- add_thickbox();
9646
-
9647
- function fs_addons_body_class( $classes ) {
9648
- $classes .= ' plugins-php';
9649
-
9650
- return $classes;
9651
- }
9652
-
9653
- add_filter( 'admin_body_class', 'fs_addons_body_class' );
9654
-
9655
- if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
9656
- $this->_admin_notices->add(
9657
- sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
9658
- __fs( 'heads-up', $this->_slug ),
9659
- 'update-nag'
9660
- );
9661
- }
9662
- }
9663
-
9664
- /**
9665
- * Render add-ons page.
9666
- *
9667
- * @author Vova Feldman (@svovaf)
9668
- * @since 1.0.6
9669
- */
9670
- function _addons_page_render() {
9671
- $this->_logger->entrance();
9672
-
9673
- $vars = array( 'slug' => $this->_slug );
9674
- fs_require_once_template( 'add-ons.php', $vars );
9675
- }
9676
-
9677
- /* Pricing & Upgrade
9678
- ------------------------------------------------------------------------------------------------------------------*/
9679
- /**
9680
- * Render pricing page.
9681
- *
9682
- * @author Vova Feldman (@svovaf)
9683
- * @since 1.0.0
9684
- */
9685
- function _pricing_page_render() {
9686
- $this->_logger->entrance();
9687
-
9688
- $vars = array( 'slug' => $this->_slug );
9689
-
9690
- if ( 'true' === fs_request_get( 'checkout', false ) ) {
9691
- fs_require_once_template( 'checkout.php', $vars );
9692
- } else {
9693
- fs_require_once_template( 'pricing.php', $vars );
9694
- }
9695
- }
9696
-
9697
- #region Contact Us ------------------------------------------------------------------
9698
-
9699
- /**
9700
- * Render contact-us page.
9701
- *
9702
- * @author Vova Feldman (@svovaf)
9703
- * @since 1.0.3
9704
- */
9705
- function _contact_page_render() {
9706
- $this->_logger->entrance();
9707
-
9708
- $vars = array( 'slug' => $this->_slug );
9709
- fs_require_once_template( 'contact.php', $vars );
9710
- }
9711
-
9712
- #endregion ------------------------------------------------------------------
9713
-
9714
- /**
9715
- * Hide all admin notices to prevent distractions.
9716
- *
9717
- * @author Vova Feldman (@svovaf)
9718
- * @since 1.0.3
9719
- *
9720
- * @uses remove_all_actions()
9721
- */
9722
- private static function _hide_admin_notices() {
9723
- remove_all_actions( 'admin_notices' );
9724
- remove_all_actions( 'network_admin_notices' );
9725
- remove_all_actions( 'all_admin_notices' );
9726
- remove_all_actions( 'user_admin_notices' );
9727
- }
9728
-
9729
- static function _clean_admin_content_section_hook() {
9730
- self::_hide_admin_notices();
9731
-
9732
- // Hide footer.
9733
- echo '<style>#wpfooter { display: none !important; }</style>';
9734
- }
9735
-
9736
- /**
9737
- * Attach to admin_head hook to hide all admin notices.
9738
- *
9739
- * @author Vova Feldman (@svovaf)
9740
- * @since 1.0.3
9741
- */
9742
- static function _clean_admin_content_section() {
9743
- add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
9744
- }
9745
-
9746
- /* CSS & JavaScript
9747
- ------------------------------------------------------------------------------------------------------------------*/
9748
- /* function _enqueue_script($handle, $src) {
9749
- $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
9750
-
9751
- $this->_logger->entrance( 'script = ' . $url );
9752
-
9753
- wp_enqueue_script( $handle, $url );
9754
- }*/
9755
-
9756
- /* SDK
9757
- ------------------------------------------------------------------------------------------------------------------*/
9758
- private $_user_api;
9759
-
9760
- /**
9761
- *
9762
- * @author Vova Feldman (@svovaf)
9763
- * @since 1.0.2
9764
- *
9765
- * @param bool $flush
9766
- *
9767
- * @return FS_Api
9768
- */
9769
- function get_api_user_scope( $flush = false ) {
9770
- if ( ! isset( $this->_user_api ) || $flush ) {
9771
- $this->_user_api = FS_Api::instance(
9772
- $this->_slug,
9773
- 'user',
9774
- $this->_user->id,
9775
- $this->_user->public_key,
9776
- ! $this->is_live(),
9777
- $this->_user->secret_key
9778
- );
9779
- }
9780
-
9781
- return $this->_user_api;
9782
- }
9783
-
9784
- private $_site_api;
9785
-
9786
- /**
9787
- *
9788
- * @author Vova Feldman (@svovaf)
9789
- * @since 1.0.2
9790
- *
9791
- * @param bool $flush
9792
- *
9793
- * @return FS_Api
9794
- */
9795
- function get_api_site_scope( $flush = false ) {
9796
- if ( ! isset( $this->_site_api ) || $flush ) {
9797
- $this->_site_api = FS_Api::instance(
9798
- $this->_slug,
9799
- 'install',
9800
- $this->_site->id,
9801
- $this->_site->public_key,
9802
- ! $this->is_live(),
9803
- $this->_site->secret_key
9804
- );
9805
- }
9806
-
9807
- return $this->_site_api;
9808
- }
9809
-
9810
- private $_plugin_api;
9811
-
9812
- /**
9813
- * Get plugin public API scope.
9814
- *
9815
- * @author Vova Feldman (@svovaf)
9816
- * @since 1.0.7
9817
- *
9818
- * @return FS_Api
9819
- */
9820
- function get_api_plugin_scope() {
9821
- if ( ! isset( $this->_plugin_api ) ) {
9822
- $this->_plugin_api = FS_Api::instance(
9823
- $this->_slug,
9824
- 'plugin',
9825
- $this->_plugin->id,
9826
- $this->_plugin->public_key,
9827
- ! $this->is_live()
9828
- );
9829
- }
9830
-
9831
- return $this->_plugin_api;
9832
- }
9833
-
9834
- /**
9835
- * Get site API scope object (fallback to public plugin scope when not registered).
9836
- *
9837
- * @author Vova Feldman (@svovaf)
9838
- * @since 1.0.7
9839
- *
9840
- * @return FS_Api
9841
- */
9842
- function get_api_site_or_plugin_scope() {
9843
- return $this->is_registered() ?
9844
- $this->get_api_site_scope() :
9845
- $this->get_api_plugin_scope();
9846
- }
9847
-
9848
- /**
9849
- * Show trial promotional notice (if any trial exist).
9850
- *
9851
- * @author Vova Feldman (@svovaf)
9852
- * @since 1.0.9
9853
- *
9854
- * @param $plans
9855
- */
9856
- function _check_for_trial_plans( $plans ) {
9857
- $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
9858
- }
9859
-
9860
- /**
9861
- * Show trial promotional notice (if any trial exist).
9862
- *
9863
- * @author Vova Feldman (@svovaf)
9864
- * @since 1.0.9
9865
- */
9866
- function _add_trial_notice() {
9867
- // Check if trial already utilized.
9868
- if ( $this->_site->is_trial_utilized() ) {
9869
- return;
9870
- }
9871
-
9872
- // Check if already paying.
9873
- if ( $this->is_paying() ) {
9874
- return;
9875
- }
9876
-
9877
- // Check if trial message is already shown.
9878
- if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
9879
- return;
9880
- }
9881
-
9882
- $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
9883
- $trial_plans_count = count( $trial_plans );
9884
-
9885
- // Check if any of the plans contains trial.
9886
- if ( 0 === $trial_plans_count ) {
9887
- return;
9888
- }
9889
-
9890
- /**
9891
- * @var FS_Plugin_Plan $paid_plan
9892
- */
9893
- $paid_plan = $trial_plans[0];
9894
- $require_subscription = $paid_plan->is_require_subscription;
9895
- $upgrade_url = $this->get_trial_url();
9896
- $cc_string = $require_subscription ?
9897
- sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $paid_plan->trial_period ) :
9898
- __fs( 'no-cc-required', $this->_slug ) . '!';
9899
-
9900
-
9901
- $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
9902
-
9903
- if ( $total_paid_plans === $trial_plans_count ) {
9904
- // All paid plans have trials.
9905
- $message = sprintf(
9906
- __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9907
- sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9908
- strtolower( __fs( 'awesome', $this->_slug ) ),
9909
- $paid_plan->trial_period
9910
- );
9911
- } else {
9912
- $plans_string = '';
9913
- for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
9914
- $plans_string .= sprintf( '<a href="%s">%s</a>', $upgrade_url, $trial_plans[ $i ]->title );
9915
-
9916
- if ( $i < $trial_plans_count - 2 ) {
9917
- $plans_string .= ', ';
9918
- } else if ( $i == $trial_plans_count - 2 ) {
9919
- $plans_string .= ' and ';
9920
- }
9921
- }
9922
-
9923
- // Not all paid plans have trials.
9924
- $message = sprintf(
9925
- __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
9926
- sprintf( '<b>%s</b>', $this->get_plugin_name() ),
9927
- $plans_string,
9928
- $paid_plan->trial_period
9929
- );
9930
- }
9931
-
9932
- $message .= ' ' . $cc_string;
9933
-
9934
- // Add start trial button.
9935
- $message .= ' ' . sprintf(
9936
- '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
9937
- $upgrade_url,
9938
- __fs( 'start-free-trial', $this->_slug )
9939
- );
9940
-
9941
- $this->_admin_notices->add_sticky(
9942
- $this->apply_filters( 'trial_promotion_message', $message ),
9943
- 'trial_promotion',
9944
- '',
9945
- 'promotion'
9946
- );
9947
-
9948
- $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
9949
- }
9950
-
9951
- /* Action Links
9952
- ------------------------------------------------------------------------------------------------------------------*/
9953
- private $_action_links_hooked = false;
9954
- private $_action_links = array();
9955
-
9956
- /**
9957
- * Hook to plugin action links filter.
9958
- *
9959
- * @author Vova Feldman (@svovaf)
9960
- * @since 1.0.0
9961
- */
9962
- private function hook_plugin_action_links() {
9963
- $this->_logger->entrance();
9964
-
9965
- $this->_action_links_hooked = true;
9966
-
9967
- $this->_logger->log( 'Adding action links hooks.' );
9968
-
9969
- // Add action link to settings page.
9970
- add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
9971
- &$this,
9972
- '_modify_plugin_action_links_hook'
9973
- ), WP_FS__DEFAULT_PRIORITY, 2 );
9974
- add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
9975
- &$this,
9976
- '_modify_plugin_action_links_hook'
9977
- ), WP_FS__DEFAULT_PRIORITY, 2 );
9978
- }
9979
-
9980
- /**
9981
- * Add plugin action link.
9982
- *
9983
- * @author Vova Feldman (@svovaf)
9984
- * @since 1.0.0
9985
- *
9986
- * @param $label
9987
- * @param $url
9988
- * @param bool $external
9989
- * @param int $priority
9990
- * @param bool $key
9991
- */
9992
- function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
9993
- $this->_logger->entrance();
9994
-
9995
- if ( ! isset( $this->_action_links[ $priority ] ) ) {
9996
- $this->_action_links[ $priority ] = array();
9997
- }
9998
-
9999
- if ( false === $key ) {
10000
- $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
10001
- }
10002
-
10003
- $this->_action_links[ $priority ][] = array(
10004
- 'label' => $label,
10005
- 'href' => $url,
10006
- 'key' => $key,
10007
- 'external' => $external
10008
- );
10009
- }
10010
-
10011
- /**
10012
- * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
10013
- *
10014
- * @author Vova Feldman (@svovaf)
10015
- * @since 1.0.0
10016
- */
10017
- function _add_upgrade_action_link() {
10018
- $this->_logger->entrance();
10019
-
10020
- if ( $this->is_registered() ) {
10021
- if ( ! $this->is_paying() && $this->has_paid_plan() ) {
10022
- $this->add_plugin_action_link(
10023
- __fs( 'upgrade', $this->_slug ),
10024
- $this->get_upgrade_url(),
10025
- false,
10026
- 7,
10027
- 'upgrade'
10028
- );
10029
- }
10030
-
10031
- if ( $this->has_addons() ) {
10032
- $this->add_plugin_action_link(
10033
- __fs( 'add-ons', $this->_slug ),
10034
- $this->_get_admin_page_url( 'addons' ),
10035
- false,
10036
- 9,
10037
- 'addons'
10038
- );
10039
- }
10040
- }
10041
- }
10042
-
10043
- /**
10044
- * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
10045
- *
10046
- * @author Leo Fajardo (@leorw)
10047
- * @since 1.1.9
10048
- */
10049
- function _add_license_action_link() {
10050
- $this->_logger->entrance();
10051
-
10052
- if ( $this->is_free_plan() && $this->is_addon() ) {
10053
- return;
10054
- }
10055
-
10056
- $link_text = __fs(
10057
- $this->is_free_plan() ? 'activate-license' : 'change-license',
10058
- $this->_slug
10059
- );
10060
-
10061
- $this->add_plugin_action_link(
10062
- $link_text,
10063
- '#',
10064
- false,
10065
- 11,
10066
- ( 'activate-license ' . $this->_slug )
10067
- );
10068
- }
10069
-
10070
- /**
10071
- * Get the URL of the page that should be loaded right after the plugin activation.
10072
- *
10073
- * @author Vova Feldman (@svovaf)
10074
- * @since 1.1.7.4
10075
- *
10076
- * @return string
10077
- */
10078
- function get_after_plugin_activation_redirect_url() {
10079
- $url = false;
10080
- $plugin_fs = false;
10081
-
10082
- if ( ! $this->is_addon() ) {
10083
- $first_time_path = $this->_menu->get_first_time_path();
10084
- $plugin_fs = $this;
10085
- $url = $plugin_fs->is_activation_mode() ?
10086
- $plugin_fs->get_activation_url() :
10087
- ( empty( $first_time_path ) ?
10088
- $this->_get_admin_page_url() :
10089
- $first_time_path );
10090
- } else {
10091
- if ( $this->is_parent_plugin_installed() ) {
10092
- $plugin_fs = self::get_parent_instance();
10093
- }
10094
-
10095
- if ( is_object( $plugin_fs ) ) {
10096
- if ( ! $plugin_fs->is_registered() ) {
10097
- // Forward to parent plugin connect when parent not registered.
10098
- $url = $plugin_fs->get_activation_url();
10099
- } else {
10100
- // Forward to account page.
10101
- $url = $plugin_fs->_get_admin_page_url( 'account' );
10102
- }
10103
- }
10104
- }
10105
-
10106
- return $url;
10107
- }
10108
-
10109
- /**
10110
- * Forward page to activation page.
10111
- *
10112
- * @author Vova Feldman (@svovaf)
10113
- * @since 1.0.3
10114
- */
10115
- function _redirect_on_activation_hook() {
10116
- $url = $this->get_after_plugin_activation_redirect_url();
10117
-
10118
- if ( is_string( $url ) ) {
10119
- fs_redirect( $url );
10120
- exit();
10121
- }
10122
- }
10123
-
10124
- /**
10125
- * Modify plugin's page action links collection.
10126
- *
10127
- * @author Vova Feldman (@svovaf)
10128
- * @since 1.0.0
10129
- *
10130
- * @param array $links
10131
- * @param $file
10132
- *
10133
- * @return array
10134
- */
10135
- function _modify_plugin_action_links_hook( $links, $file ) {
10136
- $this->_logger->entrance();
10137
-
10138
- $passed_deactivate = false;
10139
- $deactivate_link = '';
10140
- $before_deactivate = array();
10141
- $after_deactivate = array();
10142
- foreach ( $links as $key => $link ) {
10143
- if ( 'deactivate' === $key ) {
10144
- $deactivate_link = $link;
10145
- $passed_deactivate = true;
10146
- continue;
10147
- }
10148
-
10149
- if ( ! $passed_deactivate ) {
10150
- $before_deactivate[ $key ] = $link;
10151
- } else {
10152
- $after_deactivate[ $key ] = $link;
10153
- }
10154
- }
10155
-
10156
- ksort( $this->_action_links );
10157
-
10158
- foreach ( $this->_action_links as $new_links ) {
10159
- foreach ( $new_links as $link ) {
10160
- $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
10161
- }
10162
- }
10163
-
10164
- if ( ! empty( $deactivate_link ) ) {
10165
- if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
10166
- /*
10167
- * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
10168
- *
10169
- * If user is paying or in trial and have the free version installed,
10170
- * assume that the deactivation is for the upgrade process, so this is not needed.
10171
- */
10172
- $deactivate_link .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
10173
- }
10174
-
10175
- // Append deactivation link.
10176
- $before_deactivate['deactivate'] = $deactivate_link;
10177
- }
10178
-
10179
- return array_merge( $before_deactivate, $after_deactivate );
10180
- }
10181
-
10182
- /**
10183
- * Adds admin message.
10184
- *
10185
- * @author Vova Feldman (@svovaf)
10186
- * @since 1.0.4
10187
- *
10188
- * @param string $message
10189
- * @param string $title
10190
- * @param string $type
10191
- */
10192
- function add_admin_message( $message, $title = '', $type = 'success' ) {
10193
- $this->_admin_notices->add( $message, $title, $type );
10194
- }
10195
-
10196
- /**
10197
- * Adds sticky admin message.
10198
- *
10199
- * @author Vova Feldman (@svovaf)
10200
- * @since 1.1.0
10201
- *
10202
- * @param string $message
10203
- * @param string $id
10204
- * @param string $title
10205
- * @param string $type
10206
- */
10207
- function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
10208
- $this->_admin_notices->add_sticky( $message, $id, $title, $type );
10209
- }
10210
-
10211
- /**
10212
- * Helper function that returns the final steps for the upgrade completion.
10213
- *
10214
- * If the module is already running the premium code, returns an empty string.
10215
- *
10216
- * @author Vova Feldman (@svovaf)
10217
- * @since 1.2.1
10218
- *
10219
- * @param string $plan_title
10220
- *
10221
- * @return string
10222
- */
10223
- private function get_complete_upgrade_instructions( $plan_title = '' ) {
10224
- if ( $this->is_premium() ) {
10225
- return '';
10226
- }
10227
-
10228
- if ( empty( $plan_title ) ) {
10229
- $plan_title = $this->_site->plan->title;
10230
- }
10231
-
10232
- return sprintf(
10233
- ' %s: <ol><li>%s.</li><li>%s.</li><li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
10234
- __fs( 'follow-steps-to-complete-upgrade', $this->_slug ),
10235
- $this->_get_latest_download_link( sprintf(
10236
- __fs( 'download-latest-x-version', $this->_slug ),
10237
- $plan_title
10238
- ) ),
10239
- __fs( 'deactivate-free-version', $this->_slug ),
10240
- __fs( 'upload-and-activate', $this->_slug ),
10241
- '//bit.ly/upload-wp-plugin',
10242
- __fs( 'howto-upload-activate', $this->_slug )
10243
- );
10244
- }
10245
-
10246
- /* Plugin Auto-Updates (@since 1.0.4)
10247
- ------------------------------------------------------------------------------------------------------------------*/
10248
- /**
10249
- * @var string[]
10250
- */
10251
- private static $_auto_updated_plugins;
10252
-
10253
- /**
10254
- * @todo TEST IF IT WORKS!!!
10255
- *
10256
- * Include plugins for automatic updates based on stored settings.
10257
- *
10258
- * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
10259
- *
10260
- * @author Vova Feldman (@svovaf)
10261
- * @since 1.0.4
10262
- *
10263
- * @param bool $update Whether to update (not used for plugins)
10264
- * @param object $item The plugin's info
10265
- *
10266
- * @return bool
10267
- */
10268
- static function _include_plugins_in_auto_update( $update, $item ) {
10269
- // Before version 3.8.2 the $item was the file name of the plugin,
10270
- // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
10271
- $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
10272
-
10273
- if ( ! isset( self::$_auto_updated_plugins ) ) {
10274
- $plugins = self::$_accounts->get_option( 'plugins', array() );
10275
-
10276
- $identifiers = array();
10277
- foreach ( $plugins as $p ) {
10278
- /**
10279
- * @var FS_Plugin $p
10280
- */
10281
- if ( isset( $p->auto_update ) && $p->auto_update ) {
10282
- $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
10283
- }
10284
- }
10285
-
10286
- self::$_auto_updated_plugins = $identifiers;
10287
- }
10288
-
10289
- if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
10290
- return true;
10291
- }
10292
-
10293
- // Pass update decision to next filters
10294
- return $update;
10295
- }
10296
-
10297
- #region Versioning ------------------------------------------------------------------
10298
-
10299
- /**
10300
- * Check if Freemius in SDK upgrade mode.
10301
- *
10302
- * @author Vova Feldman (@svovaf)
10303
- * @since 1.0.9
10304
- *
10305
- * @return bool
10306
- */
10307
- function is_sdk_upgrade_mode() {
10308
- return isset( $this->_storage->sdk_upgrade_mode ) ?
10309
- $this->_storage->sdk_upgrade_mode :
10310
- false;
10311
- }
10312
-
10313
- /**
10314
- * Turn SDK upgrade mode off.
10315
- *
10316
- * @author Vova Feldman (@svovaf)
10317
- * @since 1.0.9
10318
- *
10319
- * @return bool
10320
- */
10321
- function set_sdk_upgrade_complete() {
10322
- $this->_storage->sdk_upgrade_mode = false;
10323
- }
10324
-
10325
- /**
10326
- * Check if plugin upgrade mode.
10327
- *
10328
- * @author Vova Feldman (@svovaf)
10329
- * @since 1.0.9
10330
- *
10331
- * @return bool
10332
- */
10333
- function is_plugin_upgrade_mode() {
10334
- return isset( $this->_storage->plugin_upgrade_mode ) ?
10335
- $this->_storage->plugin_upgrade_mode :
10336
- false;
10337
- }
10338
-
10339
- /**
10340
- * Turn plugin upgrade mode off.
10341
- *
10342
- * @author Vova Feldman (@svovaf)
10343
- * @since 1.0.9
10344
- *
10345
- * @return bool
10346
- */
10347
- function set_plugin_upgrade_complete() {
10348
- $this->_storage->plugin_upgrade_mode = false;
10349
- }
10350
-
10351
- #endregion ------------------------------------------------------------------
10352
-
10353
- #region Permissions ------------------------------------------------------------------
10354
-
10355
- /**
10356
- * Check if specific permission requested.
10357
- *
10358
- * @author Vova Feldman (@svovaf)
10359
- * @since 1.1.6
10360
- *
10361
- * @param string $permission
10362
- *
10363
- * @return bool
10364
- */
10365
- function is_permission_requested( $permission ) {
10366
- return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
10367
- }
10368
-
10369
- #endregion Permissions ------------------------------------------------------------------
10370
-
10371
- #region Marketing ------------------------------------------------------------------
10372
-
10373
- /**
10374
- * Check if current user purchased any other plugins before.
10375
- *
10376
- * @author Vova Feldman (@svovaf)
10377
- * @since 1.0.9
10378
- *
10379
- * @return bool
10380
- */
10381
- function has_purchased_before() {
10382
- // TODO: Implement has_purchased_before() method.
10383
- }
10384
-
10385
- /**
10386
- * Check if current user classified as an agency.
10387
- *
10388
- * @author Vova Feldman (@svovaf)
10389
- * @since 1.0.9
10390
- *
10391
- * @return bool
10392
- */
10393
- function is_agency() {
10394
- // TODO: Implement is_agency() method.
10395
- }
10396
-
10397
- /**
10398
- * Check if current user classified as a developer.
10399
- *
10400
- * @author Vova Feldman (@svovaf)
10401
- * @since 1.0.9
10402
- *
10403
- * @return bool
10404
- */
10405
- function is_developer() {
10406
- // TODO: Implement is_developer() method.
10407
- }
10408
-
10409
- /**
10410
- * Check if current user classified as a business.
10411
- *
10412
- * @author Vova Feldman (@svovaf)
10413
- * @since 1.0.9
10414
- *
10415
- * @return bool
10416
- */
10417
- function is_business() {
10418
- // TODO: Implement is_business() method.
10419
- }
10420
-
10421
- #endregion ------------------------------------------------------------------
10422
-
10423
- #region Free Version Deactivation
10424
- /**
10425
- * Check if the free version of the plugin is activated.
10426
- *
10427
- * @author Brad Vincent (@bradvin)
10428
- * @since 1.2.0
10429
- *
10430
- * @return bool
10431
- */
10432
- public function check_if_free_version_activated() {
10433
- if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
10434
- return is_plugin_active( $this->_free_plugin_basename );
10435
- }
10436
-
10437
- return false;
10438
- }
10439
-
10440
- /**
10441
- * Try to deactivate the free version of the plugin
10442
- *
10443
- * @author Brad Vincent (@bradvin)
10444
- * @since 1.2.0
10445
- *
10446
- */
10447
- public function try_deactivate_free_version() {
10448
- if ( $this->_plugin_basename !== $this->_free_plugin_basename ) {
10449
- if ( is_plugin_active( $this->_free_plugin_basename ) ) {
10450
- //deactivate the free version silently
10451
- deactivate_plugins( $this->_free_plugin_basename, true );
10452
- }
10453
- }
10454
- }
10455
- #endregion
10456
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.2.1.5
119
+ * @var int Hints the SDK if the plugin offers a trial period. If negative, no trial, if zero - has a trial but
120
+ * without a specified period, if positive - the number of trial days.
121
+ */
122
+ private $_trial_days = - 1;
123
+
124
+ /**
125
+ * @since 1.2.1.5
126
+ * @var bool Hints the SDK if the trial requires a payment method or not.
127
+ */
128
+ private $_is_trial_require_payment = false;
129
+
130
+ /**
131
+ * @since 1.0.7
132
+ * @var bool Hints the SDK if the plugin is WordPress.org compliant.
133
+ */
134
+ private $_is_org_compliant;
135
+
136
+ /**
137
+ * @since 1.0.7
138
+ * @var bool Hints the SDK if the plugin is has add-ons.
139
+ */
140
+ private $_has_addons;
141
+
142
+ /**
143
+ * @since 1.1.6
144
+ * @var string[]bool.
145
+ */
146
+ private $_permissions;
147
+
148
+ /**
149
+ * @var FS_Key_Value_Storage
150
+ */
151
+ private $_storage;
152
+
153
+ /**
154
+ * @since 1.0.0
155
+ *
156
+ * @var FS_Logger
157
+ */
158
+ private $_logger;
159
+ /**
160
+ * @since 1.0.4
161
+ *
162
+ * @var FS_Plugin
163
+ */
164
+ private $_plugin = false;
165
+ /**
166
+ * @since 1.0.4
167
+ *
168
+ * @var FS_Plugin|false
169
+ */
170
+ private $_parent_plugin = false;
171
+ /**
172
+ * @since 1.1.1
173
+ *
174
+ * @var Freemius
175
+ */
176
+ private $_parent = false;
177
+ /**
178
+ * @since 1.0.1
179
+ *
180
+ * @var FS_User
181
+ */
182
+ private $_user = false;
183
+ /**
184
+ * @since 1.0.1
185
+ *
186
+ * @var FS_Site
187
+ */
188
+ private $_site = false;
189
+ /**
190
+ * @since 1.0.1
191
+ *
192
+ * @var FS_Plugin_License
193
+ */
194
+ private $_license;
195
+ /**
196
+ * @since 1.0.2
197
+ *
198
+ * @var FS_Plugin_Plan[]
199
+ */
200
+ private $_plans = false;
201
+ /**
202
+ * @var FS_Plugin_License[]
203
+ * @since 1.0.5
204
+ */
205
+ private $_licenses = false;
206
+
207
+ /**
208
+ * @since 1.0.1
209
+ *
210
+ * @var FS_Admin_Menu_Manager
211
+ */
212
+ private $_menu;
213
+
214
+ /**
215
+ * @var FS_Admin_Notice_Manager
216
+ */
217
+ private $_admin_notices;
218
+
219
+ /**
220
+ * @since 1.1.6
221
+ *
222
+ * @var FS_Admin_Notice_Manager
223
+ */
224
+ private static $_global_admin_notices;
225
+
226
+ /**
227
+ * @var FS_Logger
228
+ * @since 1.0.0
229
+ */
230
+ private static $_static_logger;
231
+
232
+ /**
233
+ * @var FS_Option_Manager
234
+ * @since 1.0.2
235
+ */
236
+ private static $_accounts;
237
+
238
+ /**
239
+ * @var Freemius[]
240
+ */
241
+ private static $_instances = array();
242
+
243
+ #region Uninstall Reasons IDs
244
+
245
+ const REASON_NO_LONGER_NEEDED = 1;
246
+ const REASON_FOUND_A_BETTER_PLUGIN = 2;
247
+ const REASON_NEEDED_FOR_A_SHORT_PERIOD = 3;
248
+ const REASON_BROKE_MY_SITE = 4;
249
+ const REASON_SUDDENLY_STOPPED_WORKING = 5;
250
+ const REASON_CANT_PAY_ANYMORE = 6;
251
+ const REASON_OTHER = 7;
252
+ const REASON_DIDNT_WORK = 8;
253
+ const REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION = 9;
254
+ const REASON_COULDNT_MAKE_IT_WORK = 10;
255
+ const REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE = 11;
256
+ const REASON_NOT_WORKING = 12;
257
+ const REASON_NOT_WHAT_I_WAS_LOOKING_FOR = 13;
258
+ const REASON_DIDNT_WORK_AS_EXPECTED = 14;
259
+ const REASON_TEMPORARY_DEACTIVATION = 15;
260
+
261
+ #endregion
262
+
263
+ /* Ctor
264
+ ------------------------------------------------------------------------------------------------------------------*/
265
+
266
+ /**
267
+ * Main singleton instance.
268
+ *
269
+ * @author Vova Feldman (@svovaf)
270
+ * @since 1.0.0
271
+ *
272
+ * @param string $slug
273
+ * @param bool $is_init Since 1.2.1 Is initiation sequence.
274
+ */
275
+ private function __construct( $slug, $is_init = false ) {
276
+ $this->_slug = $slug;
277
+
278
+ $this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $slug, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
279
+
280
+ $this->_storage = FS_Key_Value_Storage::instance( 'plugin_data', $this->_slug );
281
+
282
+ $this->_plugin_main_file_path = $this->_find_caller_plugin_file( $is_init );
283
+ $this->_plugin_dir_path = plugin_dir_path( $this->_plugin_main_file_path );
284
+ $this->_plugin_basename = plugin_basename( $this->_plugin_main_file_path );
285
+ $this->_free_plugin_basename = str_replace( '-premium/', '/', $this->_plugin_basename );
286
+
287
+ $base_name_split = explode( '/', $this->_plugin_basename );
288
+ $this->_plugin_dir_name = $base_name_split[0];
289
+
290
+ if ( $this->_logger->is_on() ) {
291
+ $this->_logger->info( 'plugin_main_file_path = ' . $this->_plugin_main_file_path );
292
+ $this->_logger->info( 'plugin_dir_path = ' . $this->_plugin_dir_path );
293
+ $this->_logger->info( 'plugin_basename = ' . $this->_plugin_basename );
294
+ $this->_logger->info( 'free_plugin_basename = ' . $this->_free_plugin_basename );
295
+ $this->_logger->info( 'plugin_dir_name = ' . $this->_plugin_dir_name );
296
+ }
297
+
298
+ // Remember link between file to slug.
299
+ $this->store_file_slug_map();
300
+
301
+ // Store plugin's initial install timestamp.
302
+ if ( ! isset( $this->_storage->install_timestamp ) ) {
303
+ $this->_storage->install_timestamp = WP_FS__SCRIPT_START_TIME;
304
+ }
305
+
306
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->get();
307
+
308
+ $this->_admin_notices = FS_Admin_Notice_Manager::instance(
309
+ $slug,
310
+ is_object( $this->_plugin ) ? $this->_plugin->title : ''
311
+ );
312
+
313
+ if ( 'true' === fs_request_get( 'fs_clear_api_cache' ) ||
314
+ 'true' === fs_request_is_action( 'restart_freemius' )
315
+ ) {
316
+ FS_Api::clear_cache();
317
+ }
318
+
319
+ $this->_register_hooks();
320
+
321
+ $this->_load_account();
322
+
323
+ $this->_version_updates_handler();
324
+ }
325
+
326
+ /**
327
+ * @author Vova Feldman (@svovaf)
328
+ * @since 1.0.9
329
+ */
330
+ private function _version_updates_handler() {
331
+ if ( ! isset( $this->_storage->sdk_version ) || $this->_storage->sdk_version != $this->version ) {
332
+ // Freemius version upgrade mode.
333
+ $this->_storage->sdk_last_version = $this->_storage->sdk_version;
334
+ $this->_storage->sdk_version = $this->version;
335
+
336
+ if ( empty( $this->_storage->sdk_last_version ) ||
337
+ version_compare( $this->_storage->sdk_last_version, $this->version, '<' )
338
+ ) {
339
+ $this->_storage->sdk_upgrade_mode = true;
340
+ $this->_storage->sdk_downgrade_mode = false;
341
+ } else {
342
+ $this->_storage->sdk_downgrade_mode = true;
343
+ $this->_storage->sdk_upgrade_mode = false;
344
+
345
+ }
346
+
347
+ $this->do_action( 'sdk_version_update', $this->_storage->sdk_last_version, $this->version );
348
+ }
349
+
350
+ $plugin_version = $this->get_plugin_version();
351
+ if ( ! isset( $this->_storage->plugin_version ) || $this->_storage->plugin_version != $plugin_version ) {
352
+ // Plugin version upgrade mode.
353
+ $this->_storage->plugin_last_version = $this->_storage->plugin_version;
354
+ $this->_storage->plugin_version = $plugin_version;
355
+
356
+ if ( empty( $this->_storage->plugin_last_version ) ||
357
+ version_compare( $this->_storage->plugin_last_version, $plugin_version, '<' )
358
+ ) {
359
+ $this->_storage->plugin_upgrade_mode = true;
360
+ $this->_storage->plugin_downgrade_mode = false;
361
+ } else {
362
+ $this->_storage->plugin_downgrade_mode = true;
363
+ $this->_storage->plugin_upgrade_mode = false;
364
+ }
365
+
366
+ if ( ! empty( $this->_storage->plugin_last_version ) ) {
367
+ // Different version of the plugin was installed before, therefore it's an update.
368
+ $this->_storage->is_plugin_new_install = false;
369
+ }
370
+
371
+ $this->do_action( 'plugin_version_update', $this->_storage->plugin_last_version, $plugin_version );
372
+ }
373
+ }
374
+
375
+ /**
376
+ * @author Vova Feldman (@svovaf)
377
+ * @since 1.1.5
378
+ *
379
+ * @param string $sdk_prev_version
380
+ * @param string $sdk_version
381
+ */
382
+ function _data_migration( $sdk_prev_version, $sdk_version ) {
383
+ /**
384
+ * @since 1.1.7.3 Fixed unwanted connectivity test cleanup.
385
+ */
386
+ if ( empty( $sdk_prev_version ) ) {
387
+ return;
388
+ }
389
+
390
+ if ( version_compare( $sdk_prev_version, '1.1.5', '<' ) &&
391
+ version_compare( $sdk_version, '1.1.5', '>=' )
392
+ ) {
393
+ // On version 1.1.5 merged connectivity and is_on data.
394
+ if ( isset( $this->_storage->connectivity_test ) ) {
395
+ if ( ! isset( $this->_storage->is_on ) ) {
396
+ unset( $this->_storage->connectivity_test );
397
+ } else {
398
+ $connectivity_data = $this->_storage->connectivity_test;
399
+ $connectivity_data['is_active'] = $this->_storage->is_on['is_active'];
400
+ $connectivity_data['timestamp'] = $this->_storage->is_on['timestamp'];
401
+
402
+ // Override.
403
+ $this->_storage->connectivity_test = $connectivity_data;
404
+
405
+ // Remove previous structure.
406
+ unset( $this->_storage->is_on );
407
+ }
408
+
409
+ }
410
+ }
411
+ }
412
+
413
+ /**
414
+ * This action is connected to the 'plugins_loaded' hook and helps to determine
415
+ * if this is a new plugin installation or a plugin update.
416
+ *
417
+ * There are 3 different use-cases:
418
+ * 1) New plugin installation right with Freemius:
419
+ * 1.1 _activate_plugin_event_hook() will be executed first
420
+ * 1.2 Since $this->_storage->is_plugin_new_install is not set,
421
+ * and $this->_storage->plugin_last_version is not set,
422
+ * $this->_storage->is_plugin_new_install will be set to TRUE.
423
+ * 1.3 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
424
+ * be already set to TRUE.
425
+ *
426
+ * 2) Plugin update, didn't have Freemius before, and now have the SDK:
427
+ * 2.1 _activate_plugin_event_hook() will not be executed, because
428
+ * the activation hook do NOT fires on updates since WP 3.1.
429
+ * 2.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install will
430
+ * be empty, therefore, it will be set to FALSE.
431
+ *
432
+ * 3) Plugin update, had Freemius in prev version as well:
433
+ * 3.1 _version_updates_handler() will be executed 1st, since FS was installed
434
+ * before, $this->_storage->plugin_last_version will NOT be empty,
435
+ * therefore, $this->_storage->is_plugin_new_install will be set to FALSE.
436
+ * 3.2 When _plugins_loaded() will be executed, $this->_storage->is_plugin_new_install is
437
+ * already set, therefore, it will not be modified.
438
+ *
439
+ * Use-case #3 is backward compatible, #3.1 will be executed since 1.0.9.
440
+ *
441
+ * NOTE:
442
+ * The only fallback of this mechanism is if an admin updates a plugin based on use-case #2,
443
+ * and then, the next immediate PageView is the plugin's main settings page, it will not
444
+ * show the opt-in right away. The reason it will happen is because Freemius execution
445
+ * will be turned off till the plugin is fully loaded at least once
446
+ * (till $this->_storage->was_plugin_loaded is TRUE).
447
+ *
448
+ * @author Vova Feldman (@svovaf)
449
+ * @since 1.1.9
450
+ *
451
+ */
452
+ function _plugins_loaded() {
453
+ // Update flag that plugin was loaded with Freemius at least once.
454
+ $this->_storage->was_plugin_loaded = true;
455
+
456
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
457
+ $this->_storage->is_plugin_new_install = false;
458
+ }
459
+ }
460
+
461
+ /**
462
+ * @author Vova Feldman (@svovaf)
463
+ * @since 1.0.9
464
+ */
465
+ private function _register_hooks() {
466
+ $this->_logger->entrance();
467
+
468
+ if ( is_admin() ) {
469
+ $plugin_dir = dirname( $this->_plugin_dir_path ) . '/';
470
+
471
+ /**
472
+ * @since 1.2.2
473
+ *
474
+ * Hook to both free and premium version activations to support
475
+ * auto deactivation on the other version activation.
476
+ */
477
+ register_activation_hook(
478
+ $plugin_dir . $this->_free_plugin_basename,
479
+ array( &$this, '_activate_plugin_event_hook' )
480
+ );
481
+ register_activation_hook(
482
+ $plugin_dir . $this->premium_plugin_basename(),
483
+ array( &$this, '_activate_plugin_event_hook' )
484
+ );
485
+
486
+ /**
487
+ * Part of the mechanism to identify new plugin install vs. plugin update.
488
+ *
489
+ * @author Vova Feldman (@svovaf)
490
+ * @since 1.1.9
491
+ */
492
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
493
+ if ( $this->is_activation_mode( false ) ) {
494
+ add_action( 'plugins_loaded', array( &$this, '_plugins_loaded' ) );
495
+ } else {
496
+ // If was activated before, then it was already loaded before.
497
+ $this->_plugins_loaded();
498
+ }
499
+ }
500
+
501
+ if ( ! $this->is_ajax() ) {
502
+ if ( ! $this->is_addon() ) {
503
+ add_action( 'init', array( &$this, '_add_default_submenu_items' ), WP_FS__LOWEST_PRIORITY );
504
+ add_action( 'admin_menu', array( &$this, '_prepare_admin_menu' ), WP_FS__LOWEST_PRIORITY );
505
+ }
506
+ }
507
+ }
508
+
509
+ register_deactivation_hook( $this->_plugin_main_file_path, array( &$this, '_deactivate_plugin_hook' ) );
510
+
511
+ add_action( 'init', array( &$this, '_redirect_on_clicked_menu_link' ), WP_FS__LOWEST_PRIORITY );
512
+
513
+ add_action( 'admin_init', array( &$this, '_add_tracking_links' ) );
514
+ add_action( 'admin_init', array( &$this, '_add_license_activation' ) );
515
+ $this->add_ajax_action( 'update_billing', array( &$this, '_update_billing_ajax_action' ) );
516
+ $this->add_ajax_action( 'start_trial', array( &$this, '_start_trial_ajax_action' ) );
517
+
518
+ $this->add_action( 'after_plans_sync', array( &$this, '_check_for_trial_plans' ) );
519
+
520
+ $this->add_action( 'sdk_version_update', array( &$this, '_data_migration' ), WP_FS__DEFAULT_PRIORITY, 2 );
521
+
522
+ add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
523
+ add_action( 'admin_init', array( &$this, '_enqueue_common_css' ) );
524
+
525
+ /**
526
+ * Handle request to reset anonymous mode for `get_reconnect_url()`.
527
+ *
528
+ * @author Vova Feldman (@svovaf)
529
+ * @since 1.2.1.5
530
+ */
531
+ if ( fs_request_is_action( 'reset_anonymous_mode' ) &&
532
+ $this->_slug === fs_request_get( 'fs_slug' )
533
+ ) {
534
+ add_action( 'admin_init', array( &$this, 'connect_again' ) );
535
+ }
536
+ }
537
+
538
+ /**
539
+ * Keeping the uninstall hook registered for free or premium plugin version may result to a fatal error that
540
+ * could happen when a user tries to uninstall either version while one of them is still active. Uninstalling a
541
+ * plugin will trigger inclusion of the free or premium version and if one of them is active during the
542
+ * uninstallation, a fatal error may occur in case the plugin's class or functions are already defined.
543
+ *
544
+ * @author Leo Fajardo (leorw)
545
+ *
546
+ * @since 1.2.0
547
+ */
548
+ private function unregister_uninstall_hook() {
549
+ $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
550
+ unset( $uninstallable_plugins[ $this->_free_plugin_basename ] );
551
+ unset( $uninstallable_plugins[ $this->premium_plugin_basename() ] );
552
+
553
+ update_option( 'uninstall_plugins', $uninstallable_plugins );
554
+ }
555
+
556
+ /**
557
+ * @since 1.2.0 Invalidate module's main file cache, otherwise, FS_Plugin_Updater will not fetch updates.
558
+ */
559
+ private function clear_module_main_file_cache() {
560
+ if ( ! isset( $this->_storage->plugin_main_file ) ||
561
+ empty( $this->_storage->plugin_main_file->path )
562
+ ) {
563
+ return;
564
+ }
565
+
566
+ $plugin_main_file = clone $this->_storage->plugin_main_file;
567
+
568
+ // Store cached path (2nd layer cache).
569
+ $plugin_main_file->prev_path = $plugin_main_file->path;
570
+
571
+ // Clear cached path.
572
+ unset( $plugin_main_file->path );
573
+
574
+ $this->_storage->plugin_main_file = $plugin_main_file;
575
+ }
576
+
577
+ /**
578
+ * @author Vova Feldman (@svovaf)
579
+ * @since 1.0.9
580
+ */
581
+ private function _register_account_hooks() {
582
+ if ( is_admin() ) {
583
+ // If user is paying or in trial and have the free version installed,
584
+ // assume that the deactivation is for the upgrade process.
585
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
586
+ $this->add_ajax_action(
587
+ 'submit_uninstall_reason',
588
+ array( &$this, '_submit_uninstall_reason_action' )
589
+ );
590
+
591
+ if ( $this->is_plugins_page() ) {
592
+ add_action( 'admin_footer', array( &$this, '_add_deactivation_feedback_dialog_box' ) );
593
+ }
594
+ }
595
+
596
+ if ( ! $this->is_addon() ) {
597
+ if ( $this->is_registered() ) {
598
+ $this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
599
+ }
600
+ }
601
+ }
602
+ }
603
+
604
+ /**
605
+ * Leverage backtrace to find caller plugin file path.
606
+ *
607
+ * @author Vova Feldman (@svovaf)
608
+ * @since 1.0.6
609
+ *
610
+ * @param bool $is_init Is initiation sequence.
611
+ *
612
+ * @return string
613
+ *
614
+ * @uses fs_find_caller_plugin_file
615
+ */
616
+ private function _find_caller_plugin_file( $is_init = false ) {
617
+ // Try to load the cached value of the file path.
618
+ if ( isset( $this->_storage->plugin_main_file ) ) {
619
+ $plugin_main_file = $this->_storage->plugin_main_file;
620
+ if ( isset( $plugin_main_file->path ) && file_exists( $plugin_main_file->path ) ) {
621
+ return $this->_storage->plugin_main_file->path;
622
+ }
623
+ }
624
+
625
+ /**
626
+ * @since 1.2.1
627
+ *
628
+ * `clear_module_main_file_cache()` is clearing the plugin's cached path on
629
+ * deactivation. Therefore, if any plugin/theme was initiating `Freemius`
630
+ * with that plugin's slug, it was overriding the empty plugin path with a wrong path.
631
+ *
632
+ * So, we've added a special mechanism with a 2nd layer of cache that uses `prev_path`
633
+ * when the class instantiator isn't the module.
634
+ */
635
+ if ( ! $is_init ) {
636
+ // Fetch prev path cache.
637
+ if ( isset( $this->_storage->plugin_main_file ) &&
638
+ isset( $this->_storage->plugin_main_file->prev_path )
639
+ ) {
640
+ if ( file_exists( $this->_storage->plugin_main_file->prev_path ) ) {
641
+ return $this->_storage->plugin_main_file->prev_path;
642
+ }
643
+ }
644
+
645
+ wp_die(
646
+ __fs( 'failed-finding-main-path', $this->_slug ),
647
+ __fs( 'error' ),
648
+ array( 'back_link' => true )
649
+ );
650
+ }
651
+
652
+ /**
653
+ * @since 1.2.1
654
+ *
655
+ * Only the original instantiator that calls dynamic_init can modify the module's path.
656
+ */
657
+ // Find caller module.
658
+ $plugin_file = fs_find_caller_plugin_file();
659
+
660
+ $this->_storage->plugin_main_file = (object) array(
661
+ 'path' => fs_normalize_path( $plugin_file ),
662
+ );
663
+
664
+ return $plugin_file;
665
+ }
666
+
667
+
668
+ #----------------------------------------------------------------------------------
669
+ #region Deactivation Feedback Form
670
+ #----------------------------------------------------------------------------------
671
+
672
+ /**
673
+ * Displays a confirmation and feedback dialog box when the user clicks on the "Deactivate" link on the plugins
674
+ * page.
675
+ *
676
+ * @author Vova Feldman (@svovaf)
677
+ * @author Leo Fajardo (@leorw)
678
+ * @since 1.1.2
679
+ */
680
+ function _add_deactivation_feedback_dialog_box() {
681
+ /* Check the type of user:
682
+ * 1. Long-term (long-term)
683
+ * 2. Non-registered and non-anonymous short-term (non-registered-and-non-anonymous-short-term).
684
+ * 3. Short-term (short-term)
685
+ */
686
+ $is_long_term_user = true;
687
+
688
+ // Check if the site is at least 2 days old.
689
+ $time_installed = $this->_storage->install_timestamp;
690
+
691
+ // Difference in seconds.
692
+ $date_diff = time() - $time_installed;
693
+
694
+ // Convert seconds to days.
695
+ $date_diff_days = floor( $date_diff / ( 60 * 60 * 24 ) );
696
+
697
+ if ( $date_diff_days < 2 ) {
698
+ $is_long_term_user = false;
699
+ }
700
+
701
+ $is_long_term_user = $this->apply_filters( 'is_long_term_user', $is_long_term_user );
702
+
703
+ if ( $is_long_term_user ) {
704
+ $user_type = 'long-term';
705
+ } else {
706
+ if ( ! $this->is_registered() && ! $this->is_anonymous() ) {
707
+ $user_type = 'non-registered-and-non-anonymous-short-term';
708
+ } else {
709
+ $user_type = 'short-term';
710
+ }
711
+ }
712
+
713
+ $uninstall_reasons = $this->_get_uninstall_reasons( $user_type );
714
+
715
+ // Load the HTML template for the deactivation feedback dialog box.
716
+ $vars = array(
717
+ 'reasons' => $uninstall_reasons,
718
+ 'slug' => $this->_slug
719
+ );
720
+
721
+ /**
722
+ * @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.
723
+ */
724
+ fs_require_template( 'forms/deactivation/form.php', $vars );
725
+ }
726
+
727
+ /**
728
+ * @author Leo Fajardo (leorw)
729
+ * @since 1.1.2
730
+ *
731
+ * @param string $user_type
732
+ *
733
+ * @return array The uninstall reasons for the specified user type.
734
+ */
735
+ function _get_uninstall_reasons( $user_type = 'long-term' ) {
736
+ $internal_message_template_var = array(
737
+ 'slug' => $this->_slug
738
+ );
739
+
740
+ if ( $this->is_registered() && false !== $this->get_plan() && $this->get_plan()->has_technical_support() ) {
741
+ $contact_support_template = fs_get_template( 'forms/deactivation/contact.php', $internal_message_template_var );
742
+ } else {
743
+ $contact_support_template = '';
744
+ }
745
+
746
+ $reason_found_better_plugin = array(
747
+ 'id' => self::REASON_FOUND_A_BETTER_PLUGIN,
748
+ 'text' => __fs( 'reason-found-a-better-plugin', $this->_slug ),
749
+ 'input_type' => 'textfield',
750
+ 'input_placeholder' => __fs( 'placeholder-plugin-name', $this->_slug )
751
+ );
752
+
753
+ $reason_temporary_deactivation = array(
754
+ 'id' => self::REASON_TEMPORARY_DEACTIVATION,
755
+ 'text' => __fs( 'reason-temporary-deactivation', $this->_slug ),
756
+ 'input_type' => '',
757
+ 'input_placeholder' => ''
758
+ );
759
+
760
+ $reason_other = array(
761
+ 'id' => self::REASON_OTHER,
762
+ 'text' => __fs( 'reason-other', $this->_slug ),
763
+ 'input_type' => 'textfield',
764
+ 'input_placeholder' => ''
765
+ );
766
+
767
+ $long_term_user_reasons = array(
768
+ array(
769
+ 'id' => self::REASON_NO_LONGER_NEEDED,
770
+ 'text' => __fs( 'reason-no-longer-needed', $this->_slug ),
771
+ 'input_type' => '',
772
+ 'input_placeholder' => ''
773
+ ),
774
+ $reason_found_better_plugin,
775
+ array(
776
+ 'id' => self::REASON_NEEDED_FOR_A_SHORT_PERIOD,
777
+ 'text' => __fs( 'reason-needed-for-a-short-period', $this->_slug ),
778
+ 'input_type' => '',
779
+ 'input_placeholder' => ''
780
+ ),
781
+ array(
782
+ 'id' => self::REASON_BROKE_MY_SITE,
783
+ 'text' => __fs( 'reason-broke-my-site', $this->_slug ),
784
+ 'input_type' => '',
785
+ 'input_placeholder' => '',
786
+ 'internal_message' => $contact_support_template
787
+ ),
788
+ array(
789
+ 'id' => self::REASON_SUDDENLY_STOPPED_WORKING,
790
+ 'text' => __fs( 'reason-suddenly-stopped-working', $this->_slug ),
791
+ 'input_type' => '',
792
+ 'input_placeholder' => '',
793
+ 'internal_message' => $contact_support_template
794
+ )
795
+ );
796
+
797
+ if ( $this->is_paying() ) {
798
+ $long_term_user_reasons[] = array(
799
+ 'id' => self::REASON_CANT_PAY_ANYMORE,
800
+ 'text' => __fs( 'reason-cant-pay-anymore', $this->_slug ),
801
+ 'input_type' => 'textfield',
802
+ 'input_placeholder' => __fs( 'placeholder-comfortable-price', $this->_slug )
803
+ );
804
+ }
805
+
806
+ $reason_dont_share_info = array(
807
+ 'id' => self::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION,
808
+ 'text' => __fs( 'reason-dont-like-to-share-my-information', $this->_slug ),
809
+ 'input_type' => '',
810
+ 'input_placeholder' => ''
811
+ );
812
+
813
+ /**
814
+ * If the current user has selected the "don't share data" reason in the deactivation feedback modal, inform the
815
+ * user by showing additional message that he doesn't have to share data and can just choose to skip the opt-in
816
+ * (the Skip button is included in the message to show). This message will only be shown if anonymous mode is
817
+ * enabled and the user's account is currently not in pending activation state (similar to the way the Skip
818
+ * button in the opt-in form is shown/hidden).
819
+ */
820
+ if ( $this->is_enable_anonymous() && ! $this->is_pending_activation() ) {
821
+ $reason_dont_share_info['internal_message'] = fs_get_template( 'forms/deactivation/retry-skip.php', $internal_message_template_var );
822
+ }
823
+
824
+ $uninstall_reasons = array(
825
+ 'long-term' => $long_term_user_reasons,
826
+ 'non-registered-and-non-anonymous-short-term' => array(
827
+ array(
828
+ 'id' => self::REASON_DIDNT_WORK,
829
+ 'text' => __fs( 'reason-didnt-work', $this->_slug ),
830
+ 'input_type' => '',
831
+ 'input_placeholder' => ''
832
+ ),
833
+ $reason_dont_share_info,
834
+ $reason_found_better_plugin
835
+ ),
836
+ 'short-term' => array(
837
+ array(
838
+ 'id' => self::REASON_COULDNT_MAKE_IT_WORK,
839
+ 'text' => __fs( 'reason-couldnt-make-it-work', $this->_slug ),
840
+ 'input_type' => '',
841
+ 'input_placeholder' => '',
842
+ 'internal_message' => $contact_support_template
843
+ ),
844
+ $reason_found_better_plugin,
845
+ array(
846
+ 'id' => self::REASON_GREAT_BUT_NEED_SPECIFIC_FEATURE,
847
+ 'text' => __fs( 'reason-great-but-need-specific-feature', $this->_slug ),
848
+ 'input_type' => 'textarea',
849
+ 'input_placeholder' => __fs( 'placeholder-feature', $this->_slug )
850
+ ),
851
+ array(
852
+ 'id' => self::REASON_NOT_WORKING,
853
+ 'text' => __fs( 'reason-not-working', $this->_slug ),
854
+ 'input_type' => 'textarea',
855
+ 'input_placeholder' => __fs( 'placeholder-share-what-didnt-work', $this->_slug )
856
+ ),
857
+ array(
858
+ 'id' => self::REASON_NOT_WHAT_I_WAS_LOOKING_FOR,
859
+ 'text' => __fs( 'reason-not-what-i-was-looking-for', $this->_slug ),
860
+ 'input_type' => 'textarea',
861
+ 'input_placeholder' => __fs( 'placeholder-what-youve-been-looking-for', $this->_slug )
862
+ ),
863
+ array(
864
+ 'id' => self::REASON_DIDNT_WORK_AS_EXPECTED,
865
+ 'text' => __fs( 'reason-didnt-work-as-expected', $this->_slug ),
866
+ 'input_type' => 'textarea',
867
+ 'input_placeholder' => __fs( 'placeholder-what-did-you-expect', $this->_slug )
868
+ )
869
+ )
870
+ );
871
+
872
+ // Randomize the reasons for the current user type.
873
+ shuffle( $uninstall_reasons[ $user_type ] );
874
+
875
+ // Keep the following reasons as the last items in the list.
876
+ $uninstall_reasons[ $user_type ][] = $reason_temporary_deactivation;
877
+ $uninstall_reasons[ $user_type ][] = $reason_other;
878
+
879
+ $uninstall_reasons = $this->apply_filters( 'uninstall_reasons', $uninstall_reasons );
880
+
881
+ return $uninstall_reasons[ $user_type ];
882
+ }
883
+
884
+ /**
885
+ * Called after the user has submitted his reason for deactivating the plugin.
886
+ *
887
+ * @author Leo Fajardo (@leorw)
888
+ * @since 1.1.2
889
+ */
890
+ function _submit_uninstall_reason_action() {
891
+ $reason_id = fs_request_get( 'reason_id' );
892
+
893
+ // Check if the given reason ID is an unsigned integer.
894
+ if ( ! ctype_digit( $reason_id ) ) {
895
+ exit;
896
+ }
897
+
898
+ $reason_info = trim( fs_request_get( 'reason_info', '' ) );
899
+ if ( ! empty( $reason_info ) ) {
900
+ $reason_info = substr( $reason_info, 0, 128 );
901
+ }
902
+
903
+ $reason = (object) array(
904
+ 'id' => $reason_id,
905
+ 'info' => $reason_info,
906
+ 'is_anonymous' => fs_request_get_bool( 'is_anonymous' )
907
+ );
908
+
909
+ $this->_storage->store( 'uninstall_reason', $reason );
910
+
911
+ // Print '1' for successful operation.
912
+ echo 1;
913
+ exit;
914
+ }
915
+
916
+ #endregion
917
+
918
+ #----------------------------------------------------------------------------------
919
+ #region Instance
920
+ #----------------------------------------------------------------------------------
921
+
922
+ /**
923
+ * Main singleton instance.
924
+ *
925
+ * @author Vova Feldman (@svovaf)
926
+ * @since 1.0.0
927
+ *
928
+ * @param string $slug
929
+ * @param bool $is_init Is initiation sequence.
930
+ *
931
+ * @return Freemius
932
+ */
933
+ static function instance( $slug, $is_init = false ) {
934
+ $slug = strtolower( $slug );
935
+
936
+ if ( ! isset( self::$_instances[ $slug ] ) ) {
937
+ if ( 0 === count( self::$_instances ) ) {
938
+ self::_load_required_static();
939
+ }
940
+
941
+ self::$_instances[ $slug ] = new Freemius( $slug, $is_init );
942
+ }
943
+
944
+ return self::$_instances[ $slug ];
945
+ }
946
+
947
+ /**
948
+ * @author Vova Feldman (@svovaf)
949
+ * @since 1.0.6
950
+ *
951
+ * @param string|number $slug_or_id
952
+ *
953
+ * @return bool
954
+ */
955
+ private static function has_instance( $slug_or_id ) {
956
+ return ! is_numeric( $slug_or_id ) ?
957
+ isset( self::$_instances[ strtolower( $slug_or_id ) ] ) :
958
+ ( false !== self::get_instance_by_id( $slug_or_id ) );
959
+ }
960
+
961
+ /**
962
+ * @author Vova Feldman (@svovaf)
963
+ * @since 1.0.6
964
+ *
965
+ * @param $id
966
+ *
967
+ * @return false|Freemius
968
+ */
969
+ static function get_instance_by_id( $id ) {
970
+ foreach ( self::$_instances as $slug => $instance ) {
971
+ if ( $id == $instance->get_id() ) {
972
+ return $instance;
973
+ }
974
+ }
975
+
976
+ return false;
977
+ }
978
+
979
+ /**
980
+ *
981
+ * @author Vova Feldman (@svovaf)
982
+ * @since 1.0.1
983
+ *
984
+ * @param $plugin_file
985
+ *
986
+ * @return false|Freemius
987
+ */
988
+ static function get_instance_by_file( $plugin_file ) {
989
+ $slug = self::find_slug_by_basename( $plugin_file );
990
+
991
+ return ( false !== $slug ) ?
992
+ self::instance( $slug ) :
993
+ false;
994
+ }
995
+
996
+ /**
997
+ * @author Vova Feldman (@svovaf)
998
+ * @since 1.0.6
999
+ *
1000
+ * @return false|Freemius
1001
+ */
1002
+ function get_parent_instance() {
1003
+ return self::get_instance_by_id( $this->_plugin->parent_plugin_id );
1004
+ }
1005
+
1006
+ /**
1007
+ * @author Vova Feldman (@svovaf)
1008
+ * @since 1.0.6
1009
+ *
1010
+ * @param $slug_or_id
1011
+ *
1012
+ * @return bool|Freemius
1013
+ */
1014
+ function get_addon_instance( $slug_or_id ) {
1015
+ return ! is_numeric( $slug_or_id ) ?
1016
+ self::instance( strtolower( $slug_or_id ) ) :
1017
+ self::get_instance_by_id( $slug_or_id );
1018
+ }
1019
+
1020
+ #endregion ------------------------------------------------------------------
1021
+
1022
+ /**
1023
+ * @author Vova Feldman (@svovaf)
1024
+ * @since 1.0.6
1025
+ *
1026
+ * @return bool
1027
+ */
1028
+ function is_parent_plugin_installed() {
1029
+ return self::has_instance( $this->_plugin->parent_plugin_id );
1030
+ }
1031
+
1032
+ /**
1033
+ * Check if add-on parent plugin in activation mode.
1034
+ *
1035
+ * @author Vova Feldman (@svovaf)
1036
+ * @since 1.0.7
1037
+ *
1038
+ * @return bool
1039
+ */
1040
+ function is_parent_in_activation() {
1041
+ $parent_fs = $this->get_parent_instance();
1042
+ if ( ! is_object( $parent_fs ) ) {
1043
+ return false;
1044
+ }
1045
+
1046
+ return ( $parent_fs->is_activation_mode() );
1047
+ }
1048
+
1049
+ /**
1050
+ * Is plugin in activation mode.
1051
+ *
1052
+ * @author Vova Feldman (@svovaf)
1053
+ * @since 1.0.7
1054
+ *
1055
+ * @param bool $and_on
1056
+ *
1057
+ * @return bool
1058
+ */
1059
+ function is_activation_mode( $and_on = true ) {
1060
+ return (
1061
+ ( $this->is_on() || ! $and_on ) &&
1062
+ ! $this->is_registered() &&
1063
+ ( ! $this->is_enable_anonymous() ||
1064
+ ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
1065
+ );
1066
+ }
1067
+
1068
+ /**
1069
+ * Get collection of all active plugins.
1070
+ *
1071
+ * @author Vova Feldman (@svovaf)
1072
+ * @since 1.0.9
1073
+ *
1074
+ * @return array[string]array
1075
+ */
1076
+ private static function get_active_plugins() {
1077
+ self::require_plugin_essentials();
1078
+
1079
+ $active_plugin = array();
1080
+ $all_plugins = get_plugins();
1081
+ $active_plugins_basenames = get_option( 'active_plugins' );
1082
+
1083
+ foreach ( $active_plugins_basenames as $plugin_basename ) {
1084
+ $active_plugin[ $plugin_basename ] = $all_plugins[ $plugin_basename ];
1085
+ }
1086
+
1087
+ return $active_plugin;
1088
+ }
1089
+
1090
+ /**
1091
+ * Get collection of all plugins.
1092
+ *
1093
+ * @author Vova Feldman (@svovaf)
1094
+ * @since 1.1.8
1095
+ *
1096
+ * @return array Key is the plugin file path and the value is an array of the plugin data.
1097
+ */
1098
+ private static function get_all_plugins() {
1099
+ self::require_plugin_essentials();
1100
+
1101
+ $all_plugins = get_plugins();
1102
+ $active_plugins_basenames = get_option( 'active_plugins' );
1103
+
1104
+ foreach ( $all_plugins as $basename => &$data ) {
1105
+ // By default set to inactive (next foreach update the active plugins).
1106
+ $data['is_active'] = false;
1107
+ // Enrich with plugin slug.
1108
+ $data['slug'] = self::get_plugin_slug( $basename );
1109
+ }
1110
+
1111
+ // Flag active plugins.
1112
+ foreach ( $active_plugins_basenames as $basename ) {
1113
+ if ( isset( $all_plugins[ $basename ] ) ) {
1114
+ $all_plugins[ $basename ]['is_active'] = true;
1115
+ }
1116
+ }
1117
+
1118
+ return $all_plugins;
1119
+ }
1120
+
1121
+
1122
+ /**
1123
+ * Cached result of get_site_transient( 'update_plugins' )
1124
+ *
1125
+ * @author Vova Feldman (@svovaf)
1126
+ * @since 1.1.8
1127
+ *
1128
+ * @var object
1129
+ */
1130
+ private static $_plugins_info;
1131
+
1132
+ /**
1133
+ * Helper function to get specified plugin's slug.
1134
+ *
1135
+ * @author Vova Feldman (@svovaf)
1136
+ * @since 1.1.8
1137
+ *
1138
+ * @param $basename
1139
+ *
1140
+ * @return string
1141
+ */
1142
+ private static function get_plugin_slug( $basename ) {
1143
+ if ( ! isset( self::$_plugins_info ) ) {
1144
+ self::$_plugins_info = get_site_transient( 'update_plugins' );
1145
+ }
1146
+
1147
+ $slug = '';
1148
+
1149
+ if ( is_object( self::$_plugins_info ) ) {
1150
+ if ( isset( self::$_plugins_info->no_update ) &&
1151
+ isset( self::$_plugins_info->no_update[ $basename ] ) &&
1152
+ ! empty( self::$_plugins_info->no_update[ $basename ]->slug )
1153
+ ) {
1154
+ $slug = self::$_plugins_info->no_update[ $basename ]->slug;
1155
+ } else if ( isset( self::$_plugins_info->response ) &&
1156
+ isset( self::$_plugins_info->response[ $basename ] ) &&
1157
+ ! empty( self::$_plugins_info->response[ $basename ]->slug )
1158
+ ) {
1159
+ $slug = self::$_plugins_info->response[ $basename ]->slug;
1160
+ }
1161
+ }
1162
+
1163
+ if ( empty( $slug ) ) {
1164
+ // Try to find slug from FS data.
1165
+ $slug = self::find_slug_by_basename( $basename );
1166
+ }
1167
+
1168
+ if ( empty( $slug ) ) {
1169
+ // Fallback to plugin's folder name.
1170
+ $slug = dirname( $basename );
1171
+ }
1172
+
1173
+ return $slug;
1174
+ }
1175
+
1176
+ private static $_statics_loaded = false;
1177
+
1178
+ /**
1179
+ * Load static resources.
1180
+ *
1181
+ * @author Vova Feldman (@svovaf)
1182
+ * @since 1.0.1
1183
+ */
1184
+ private static function _load_required_static() {
1185
+ if ( self::$_statics_loaded ) {
1186
+ return;
1187
+ }
1188
+
1189
+ self::$_static_logger = FS_Logger::get_logger( WP_FS__SLUG, WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
1190
+
1191
+ self::$_static_logger->entrance();
1192
+
1193
+ self::$_accounts = FS_Option_Manager::get_manager( WP_FS__ACCOUNTS_OPTION_NAME, true );
1194
+
1195
+ self::$_global_admin_notices = FS_Admin_Notice_Manager::instance( 'global' );
1196
+
1197
+ // Configure which Freemius powered plugins should be auto updated.
1198
+ // add_filter( 'auto_update_plugin', '_include_plugins_in_auto_update', 10, 2 );
1199
+
1200
+ add_action( 'admin_menu', array( 'Freemius', 'add_debug_page' ) );
1201
+
1202
+ add_action( "wp_ajax_fs_toggle_debug_mode", array( 'Freemius', '_toggle_debug_mode' ) );
1203
+
1204
+ add_action( 'plugins_loaded', array( 'Freemius', '_load_textdomain' ), 1 );
1205
+
1206
+ self::$_statics_loaded = true;
1207
+ }
1208
+
1209
+ #----------------------------------------------------------------------------------
1210
+ #region Localization
1211
+ #----------------------------------------------------------------------------------
1212
+
1213
+ /**
1214
+ * Load framework's text domain.
1215
+ *
1216
+ * @author Vova Feldman (@svovaf)
1217
+ * @since 1.2.1
1218
+ */
1219
+ static function _load_textdomain() {
1220
+ if ( ! is_admin() ) {
1221
+ return;
1222
+ }
1223
+
1224
+ global $fs_active_plugins;
1225
+
1226
+ load_plugin_textdomain(
1227
+ 'freemius',
1228
+ false,
1229
+ $fs_active_plugins->newest->sdk_path . '/languages/'
1230
+ );
1231
+
1232
+ // @todo Load for themes.
1233
+ }
1234
+
1235
+ #endregion
1236
+
1237
+ #----------------------------------------------------------------------------------
1238
+ #region Debugging
1239
+ #----------------------------------------------------------------------------------
1240
+
1241
+ /**
1242
+ * @author Vova Feldman (@svovaf)
1243
+ * @since 1.0.8
1244
+ */
1245
+ static function add_debug_page() {
1246
+ if ( ! current_user_can( 'activate_plugins' ) ) {
1247
+ return;
1248
+ }
1249
+
1250
+ self::$_static_logger->entrance();
1251
+
1252
+ $title = sprintf( '%s [v.%s]', __fs( 'freemius-debug' ), WP_FS__SDK_VERSION );
1253
+
1254
+ if ( WP_FS__DEV_MODE ) {
1255
+ // Add top-level debug menu item.
1256
+ $hook = add_menu_page(
1257
+ $title,
1258
+ $title,
1259
+ 'manage_options',
1260
+ 'freemius',
1261
+ array( 'Freemius', '_debug_page_render' )
1262
+ );
1263
+ } else {
1264
+ // Add hidden debug page.
1265
+ $hook = add_submenu_page(
1266
+ null,
1267
+ $title,
1268
+ $title,
1269
+ 'manage_options',
1270
+ 'freemius',
1271
+ array( 'Freemius', '_debug_page_render' )
1272
+ );
1273
+ }
1274
+
1275
+ add_action( "load-$hook", array( 'Freemius', '_debug_page_actions' ) );
1276
+ }
1277
+
1278
+ /**
1279
+ * @author Vova Feldman (@svovaf)
1280
+ * @since 1.1.7.3
1281
+ */
1282
+ static function _toggle_debug_mode() {
1283
+ if ( in_array( $_POST['is_on'], array( 0, 1 ) ) ) {
1284
+ update_option( 'fs_debug_mode', $_POST['is_on'] );
1285
+ }
1286
+
1287
+ exit;
1288
+ }
1289
+
1290
+ /**
1291
+ * @author Vova Feldman (@svovaf)
1292
+ * @since 1.0.8
1293
+ */
1294
+ static function _debug_page_actions() {
1295
+ self::_clean_admin_content_section();
1296
+
1297
+ if ( fs_request_is_action( 'restart_freemius' ) ) {
1298
+ check_admin_referer( 'restart_freemius' );
1299
+
1300
+ // Clear accounts data.
1301
+ self::$_accounts->clear( true );
1302
+
1303
+ // Clear SDK reference cache.
1304
+ delete_option( 'fs_active_plugins' );
1305
+ } else if ( fs_request_is_action( 'simulate_trial' ) ) {
1306
+ check_admin_referer( 'simulate_trial' );
1307
+
1308
+ $slug = fs_request_get( 'slug' );
1309
+
1310
+ $fs = freemius( $slug );
1311
+
1312
+ // Update SDK install to at least 24 hours before.
1313
+ $fs->_storage->install_timestamp = ( time() - WP_FS__TIME_24_HOURS_IN_SEC );
1314
+ // Unset the trial shown timestamp.
1315
+ unset( $fs->_storage->trial_promotion_shown );
1316
+ }
1317
+ }
1318
+
1319
+ /**
1320
+ * @author Vova Feldman (@svovaf)
1321
+ * @since 1.0.8
1322
+ */
1323
+ static function _debug_page_render() {
1324
+ self::$_static_logger->entrance();
1325
+
1326
+ $sites = self::get_all_sites();
1327
+ $users = self::get_all_users();
1328
+ $addons = self::get_all_addons();
1329
+ $account_addons = self::get_all_account_addons();
1330
+ $licenses = self::get_all_licenses();
1331
+
1332
+ // $plans = self::get_all_plans();
1333
+ // $licenses = self::get_all_licenses();
1334
+
1335
+ $vars = array(
1336
+ 'sites' => $sites,
1337
+ 'users' => $users,
1338
+ 'addons' => $addons,
1339
+ 'account_addons' => $account_addons,
1340
+ 'licenses' => $licenses,
1341
+ );
1342
+
1343
+ fs_enqueue_local_style( 'fs_account', '/admin/debug.css' );
1344
+ fs_require_once_template( 'debug.php', $vars );
1345
+ }
1346
+
1347
+ #endregion
1348
+
1349
+ #----------------------------------------------------------------------------------
1350
+ #region Connectivity Issues
1351
+ #----------------------------------------------------------------------------------
1352
+
1353
+ /**
1354
+ * Check if Freemius should be turned on for the current plugin install.
1355
+ *
1356
+ * Note:
1357
+ * $this->_is_on is updated in has_api_connectivity()
1358
+ *
1359
+ * @author Vova Feldman (@svovaf)
1360
+ * @since 1.0.9
1361
+ *
1362
+ * @return bool
1363
+ */
1364
+ function is_on() {
1365
+ self::$_static_logger->entrance();
1366
+
1367
+ if ( isset( $this->_is_on ) ) {
1368
+ return $this->_is_on;
1369
+ }
1370
+
1371
+ // If already installed or pending then sure it's on :)
1372
+ if ( $this->is_registered() || $this->is_pending_activation() ) {
1373
+ $this->_is_on = true;
1374
+
1375
+ return true;
1376
+ }
1377
+
1378
+ return false;
1379
+ }
1380
+
1381
+ /**
1382
+ * @author Vova Feldman (@svovaf)
1383
+ * @since 1.1.7.3
1384
+ *
1385
+ * @param bool $flush_if_no_connectivity
1386
+ *
1387
+ * @return bool
1388
+ */
1389
+ private function should_run_connectivity_test( $flush_if_no_connectivity = false ) {
1390
+ if ( ! isset( $this->_storage->connectivity_test ) ) {
1391
+ // Connectivity test was never executed, or cache was cleared.
1392
+ return true;
1393
+ }
1394
+
1395
+ if ( WP_FS__PING_API_ON_IP_OR_HOST_CHANGES ) {
1396
+ if ( WP_FS__IS_HTTP_REQUEST ) {
1397
+ if ( $_SERVER['HTTP_HOST'] != $this->_storage->connectivity_test['host'] ) {
1398
+ // Domain changed.
1399
+ return true;
1400
+ }
1401
+
1402
+ if ( WP_FS__REMOTE_ADDR != $this->_storage->connectivity_test['server_ip'] ) {
1403
+ // Server IP changed.
1404
+ return true;
1405
+ }
1406
+ }
1407
+ }
1408
+
1409
+ if ( $this->_storage->connectivity_test['is_connected'] &&
1410
+ $this->_storage->connectivity_test['is_active']
1411
+ ) {
1412
+ // API connected and Freemius is active - no need to run connectivity check.
1413
+ return false;
1414
+ }
1415
+
1416
+ if ( $flush_if_no_connectivity ) {
1417
+ /**
1418
+ * If explicitly asked to flush when no connectivity - do it only
1419
+ * if at least 10 sec passed from the last API connectivity test.
1420
+ */
1421
+ return ( isset( $this->_storage->connectivity_test['timestamp'] ) &&
1422
+ ( WP_FS__SCRIPT_START_TIME - $this->_storage->connectivity_test['timestamp'] ) > 10 );
1423
+ }
1424
+
1425
+ /**
1426
+ * @since 1.1.7 Don't check for connectivity on plugin downgrade.
1427
+ */
1428
+ $version = $this->get_plugin_version();
1429
+ if ( version_compare( $version, $this->_storage->connectivity_test['version'], '>' ) ) {
1430
+ // If it's a plugin version upgrade and Freemius is off or no connectivity, run connectivity test.
1431
+ return true;
1432
+ }
1433
+
1434
+ return false;
1435
+ }
1436
+
1437
+ /**
1438
+ * @author Vova Feldman (@svovaf)
1439
+ * @since 1.1.7.4
1440
+ *
1441
+ * @return object|false
1442
+ */
1443
+ private function ping() {
1444
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY ) {
1445
+ return false;
1446
+ }
1447
+
1448
+ $version = $this->get_plugin_version();
1449
+
1450
+ $is_update = $this->apply_filters( 'is_plugin_update', $this->is_plugin_update() );
1451
+
1452
+ return $this->get_api_plugin_scope()->ping(
1453
+ $this->get_anonymous_id(),
1454
+ array(
1455
+ 'is_update' => json_encode( $is_update ),
1456
+ 'version' => $version,
1457
+ 'sdk' => $this->version,
1458
+ 'is_admin' => json_encode( is_admin() ),
1459
+ 'is_ajax' => json_encode( $this->is_ajax() ),
1460
+ 'is_cron' => json_encode( $this->is_cron() ),
1461
+ 'is_http' => json_encode( WP_FS__IS_HTTP_REQUEST ),
1462
+ )
1463
+ );
1464
+ }
1465
+
1466
+ /**
1467
+ * Check if there's any connectivity issue to Freemius API.
1468
+ *
1469
+ * @author Vova Feldman (@svovaf)
1470
+ * @since 1.0.9
1471
+ *
1472
+ * @param bool $flush_if_no_connectivity
1473
+ *
1474
+ * @return bool
1475
+ */
1476
+ function has_api_connectivity( $flush_if_no_connectivity = false ) {
1477
+ $this->_logger->entrance();
1478
+
1479
+ if ( isset( $this->_has_api_connection ) && ( $this->_has_api_connection || ! $flush_if_no_connectivity ) ) {
1480
+ return $this->_has_api_connection;
1481
+ }
1482
+
1483
+ if ( WP_FS__SIMULATE_NO_API_CONNECTIVITY &&
1484
+ isset( $this->_storage->connectivity_test ) &&
1485
+ true === $this->_storage->connectivity_test['is_connected']
1486
+ ) {
1487
+ unset( $this->_storage->connectivity_test );
1488
+ }
1489
+
1490
+ if ( ! $this->should_run_connectivity_test( $flush_if_no_connectivity ) ) {
1491
+ $this->_has_api_connection = $this->_storage->connectivity_test['is_connected'];
1492
+ /**
1493
+ * @since 1.1.6 During dev mode, if there's connectivity - turn Freemius on regardless the configuration.
1494
+ *
1495
+ * @since 1.2.1.5 If the user running the premium version then ignore the 'is_active' flag and turn Freemius on to enable license key activation.
1496
+ */
1497
+ $this->_is_on = $this->_storage->connectivity_test['is_active'] ||
1498
+ $this->is_premium() ||
1499
+ ( WP_FS__DEV_MODE && $this->_has_api_connection && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1500
+
1501
+ return $this->_has_api_connection;
1502
+ }
1503
+
1504
+ $pong = $this->ping();
1505
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1506
+
1507
+ if ( ! $is_connected ) {
1508
+ // API failure.
1509
+ $this->_add_connectivity_issue_message( $pong );
1510
+ }
1511
+
1512
+ $this->store_connectivity_info( $pong, $is_connected );
1513
+
1514
+ return $this->_has_api_connection;
1515
+ }
1516
+
1517
+ /**
1518
+ * @author Vova Feldman (@svovaf)
1519
+ * @since 1.1.7.4
1520
+ *
1521
+ * @param object $pong
1522
+ * @param bool $is_connected
1523
+ */
1524
+ private function store_connectivity_info( $pong, $is_connected ) {
1525
+ $this->_logger->entrance();
1526
+
1527
+ $version = $this->get_plugin_version();
1528
+
1529
+ if ( ! $is_connected || WP_FS__SIMULATE_FREEMIUS_OFF ) {
1530
+ $is_active = false;
1531
+ } else {
1532
+ $is_active = ( isset( $pong->is_active ) && true == $pong->is_active );
1533
+ }
1534
+
1535
+ $is_active = $this->apply_filters(
1536
+ 'is_on',
1537
+ $is_active,
1538
+ $this->is_plugin_update(),
1539
+ $version
1540
+ );
1541
+
1542
+ $this->_storage->connectivity_test = array(
1543
+ 'is_connected' => $is_connected,
1544
+ 'host' => $_SERVER['HTTP_HOST'],
1545
+ 'server_ip' => WP_FS__REMOTE_ADDR,
1546
+ 'is_active' => $is_active,
1547
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
1548
+ // Last version with connectivity attempt.
1549
+ 'version' => $version,
1550
+ );
1551
+
1552
+ $this->_has_api_connection = $is_connected;
1553
+ $this->_is_on = $is_active || ( WP_FS__DEV_MODE && $is_connected && ! WP_FS__SIMULATE_FREEMIUS_OFF );
1554
+ }
1555
+
1556
+ /**
1557
+ * Force turning Freemius on.
1558
+ *
1559
+ * @author Vova Feldman (@svovaf)
1560
+ * @since 1.1.8.1
1561
+ *
1562
+ * @return bool TRUE if successfully turned on.
1563
+ */
1564
+ private function turn_on() {
1565
+ $this->_logger->entrance();
1566
+
1567
+ if ( $this->is_on() || ! isset( $this->_storage->connectivity_test['is_active'] ) ) {
1568
+ return false;
1569
+ }
1570
+
1571
+ $updated_connectivity = $this->_storage->connectivity_test;
1572
+ $updated_connectivity['is_active'] = true;
1573
+ $updated_connectivity['timestamp'] = WP_FS__SCRIPT_START_TIME;
1574
+ $this->_storage->connectivity_test = $updated_connectivity;
1575
+
1576
+ $this->_is_on = true;
1577
+
1578
+ return true;
1579
+ }
1580
+
1581
+ /**
1582
+ * Anonymous and unique site identifier (Hash).
1583
+ *
1584
+ * @author Vova Feldman (@svovaf)
1585
+ * @since 1.1.0
1586
+ *
1587
+ * @return string
1588
+ */
1589
+ function get_anonymous_id() {
1590
+ $unique_id = self::$_accounts->get_option( 'unique_id' );
1591
+
1592
+ if ( empty( $unique_id ) || ! is_string( $unique_id ) ) {
1593
+ $key = get_site_url();
1594
+
1595
+ // If localhost, assign microtime instead of domain.
1596
+ if ( WP_FS__IS_LOCALHOST ||
1597
+ false !== strpos( $key, 'localhost' ) ||
1598
+ false === strpos( $key, '.' )
1599
+ ) {
1600
+ $key = microtime();
1601
+ }
1602
+
1603
+ $unique_id = md5( $key );
1604
+
1605
+ self::$_accounts->set_option( 'unique_id', $unique_id, true );
1606
+ }
1607
+
1608
+ $this->_logger->departure( $unique_id );
1609
+
1610
+ return $unique_id;
1611
+ }
1612
+
1613
+ /**
1614
+ * @author Vova Feldman (@svovaf)
1615
+ * @since 1.1.7.4
1616
+ *
1617
+ * @return \WP_User
1618
+ */
1619
+ static function _get_current_wp_user() {
1620
+ self::require_pluggable_essentials();
1621
+
1622
+ return wp_get_current_user();
1623
+ }
1624
+
1625
+ /**
1626
+ * Generate API connectivity issue message.
1627
+ *
1628
+ * @author Vova Feldman (@svovaf)
1629
+ * @since 1.0.9
1630
+ *
1631
+ * @param mixed $api_result
1632
+ * @param bool $is_first_failure
1633
+ */
1634
+ function _add_connectivity_issue_message( $api_result, $is_first_failure = true ) {
1635
+ if ( ! $this->is_premium() && $this->_enable_anonymous ) {
1636
+ // Don't add message if it's the free version and can run anonymously.
1637
+ return;
1638
+ }
1639
+
1640
+ if ( ! function_exists( 'wp_nonce_url' ) ) {
1641
+ require_once( ABSPATH . 'wp-includes/functions.php' );
1642
+ }
1643
+
1644
+ $current_user = self::_get_current_wp_user();
1645
+ // $admin_email = get_option( 'admin_email' );
1646
+ $admin_email = $current_user->user_email;
1647
+
1648
+ $message = false;
1649
+ if ( is_object( $api_result ) &&
1650
+ isset( $api_result->error ) &&
1651
+ isset( $api_result->error->code )
1652
+ ) {
1653
+ switch ( $api_result->error->code ) {
1654
+ case 'curl_missing':
1655
+ $message = sprintf(
1656
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1657
+ __fs( 'curl-missing-message', $this->_slug ) . ' ' .
1658
+ ' %s',
1659
+ '<b>' . $this->get_plugin_name() . '</b>',
1660
+ sprintf(
1661
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1662
+ sprintf(
1663
+ '<a class="fs-resolve" data-type="curl" href="#"><b>%s</b></a>%s',
1664
+ __fs( 'curl-missing-no-clue-title', $this->_slug ),
1665
+ ' - ' . sprintf(
1666
+ __fs( 'curl-missing-no-clue-desc', $this->_slug ),
1667
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1668
+ )
1669
+ ),
1670
+ sprintf(
1671
+ '<b>%s</b> - %s',
1672
+ __fs( 'sysadmin-title', $this->_slug ),
1673
+ __fs( 'curl-missing-sysadmin-desc', $this->_slug )
1674
+ ),
1675
+ sprintf(
1676
+ '<a href="%s"><b>%s</b></a>%s',
1677
+ 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 ),
1678
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1679
+ ' - ' . __fs( 'deactivate-plugin-desc', 'freemius', $this->_slug )
1680
+ )
1681
+ )
1682
+ );
1683
+ break;
1684
+ case 'cloudflare_ddos_protection':
1685
+ $message = sprintf(
1686
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1687
+ __fs( 'cloudflare-blocks-connection-message', $this->_slug ) . ' ' .
1688
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1689
+ ' %s',
1690
+ '<b>' . $this->get_plugin_name() . '</b>',
1691
+ sprintf(
1692
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1693
+ sprintf(
1694
+ '<a class="fs-resolve" data-type="cloudflare" href="#"><b>%s</b></a>%s',
1695
+ __fs( 'fix-issue-title', $this->_slug ),
1696
+ ' - ' . sprintf(
1697
+ __fs( 'fix-issue-desc', $this->_slug ),
1698
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1699
+ )
1700
+ ),
1701
+ sprintf(
1702
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1703
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1704
+ __fs( 'install-previous-title', $this->_slug ),
1705
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1706
+ ),
1707
+ sprintf(
1708
+ '<a href="%s"><b>%s</b></a>%s',
1709
+ 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 ),
1710
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1711
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1712
+ )
1713
+ )
1714
+ );
1715
+ break;
1716
+ case 'squid_cache_block':
1717
+ $message = sprintf(
1718
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1719
+ __fs( 'squid-blocks-connection-message', $this->_slug ) .
1720
+ ' %s',
1721
+ '<b>' . $this->get_plugin_name() . '</b>',
1722
+ sprintf(
1723
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1724
+ sprintf(
1725
+ '<a class="fs-resolve" data-type="squid" href="#"><b>%s</b></a>%s',
1726
+ __fs( 'squid-no-clue-title', $this->_slug ),
1727
+ ' - ' . sprintf(
1728
+ __fs( 'squid-no-clue-desc', $this->_slug ),
1729
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1730
+ )
1731
+ ),
1732
+ sprintf(
1733
+ '<b>%s</b> - %s',
1734
+ __fs( 'sysadmin-title', $this->_slug ),
1735
+ sprintf(
1736
+ __fs( 'squid-sysadmin-desc', $this->_slug ),
1737
+ // We use a filter since the plugin might require additional API connectivity.
1738
+ '<b>' . implode( ', ', $this->apply_filters( 'api_domains', array( 'api.freemius.com' ) ) ) . '</b>' )
1739
+ ),
1740
+ sprintf(
1741
+ '<a href="%s"><b>%s</b></a>%s',
1742
+ 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 ),
1743
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1744
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1745
+ )
1746
+ )
1747
+ );
1748
+ break;
1749
+ // default:
1750
+ // $message = __fs( 'connectivity-test-fails-message', $this->_slug );
1751
+ // break;
1752
+ }
1753
+ }
1754
+
1755
+ $message_id = 'failed_connect_api';
1756
+ $type = 'error';
1757
+
1758
+ if ( false === $message ) {
1759
+ if ( $is_first_failure ) {
1760
+ // First attempt failed.
1761
+ $message = sprintf(
1762
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1763
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1764
+ __fs( 'connectivity-test-maybe-temporary', $this->_slug ) . '<br><br>' .
1765
+ '%s',
1766
+ '<b>' . $this->get_plugin_name() . '</b>',
1767
+ sprintf(
1768
+ '<div id="fs_firewall_issue_options">%s %s</div>',
1769
+ sprintf(
1770
+ '<a class="button button-primary fs-resolve" data-type="retry_ping" href="#">%s</a>',
1771
+ __fs( 'yes-do-your-thing', $this->_slug )
1772
+ ),
1773
+ sprintf(
1774
+ '<a href="%s" class="button">%s</a>',
1775
+ 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 ),
1776
+ __fs( 'no-deactivate', $this->_slug )
1777
+ )
1778
+ )
1779
+ );
1780
+
1781
+ $message_id = 'failed_connect_api_first';
1782
+ $type = 'promotion';
1783
+ } else {
1784
+ // Second connectivity attempt failed.
1785
+ $message = sprintf(
1786
+ __fs( 'x-requires-access-to-api', $this->_slug ) . ' ' .
1787
+ __fs( 'connectivity-test-fails-message', $this->_slug ) . ' ' .
1788
+ __fs( 'happy-to-resolve-issue-asap', $this->_slug ) .
1789
+ ' %s',
1790
+ '<b>' . $this->get_plugin_name() . '</b>',
1791
+ sprintf(
1792
+ '<ol id="fs_firewall_issue_options"><li>%s</li><li>%s</li><li>%s</li></ol>',
1793
+ sprintf(
1794
+ '<a class="fs-resolve" data-type="general" href="#"><b>%s</b></a>%s',
1795
+ __fs( 'fix-issue-title', $this->_slug ),
1796
+ ' - ' . sprintf(
1797
+ __fs( 'fix-issue-desc', $this->_slug ),
1798
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1799
+ )
1800
+ ),
1801
+ sprintf(
1802
+ '<a href="%s" target="_blank"><b>%s</b></a>%s',
1803
+ sprintf( 'https://wordpress.org/plugins/%s/download/', $this->_slug ),
1804
+ __fs( 'install-previous-title', $this->_slug ),
1805
+ ' - ' . __fs( 'install-previous-desc', $this->_slug )
1806
+ ),
1807
+ sprintf(
1808
+ '<a href="%s"><b>%s</b></a>%s',
1809
+ 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 ),
1810
+ __fs( 'deactivate-plugin-title', $this->_slug ),
1811
+ ' - ' . __fs( 'deactivate-plugin-desc', $this->_slug )
1812
+ )
1813
+ )
1814
+ );
1815
+ }
1816
+ }
1817
+
1818
+ $this->_admin_notices->add_sticky(
1819
+ $message,
1820
+ $message_id,
1821
+ __fs( 'oops', $this->_slug ) . '...',
1822
+ $type
1823
+ );
1824
+ }
1825
+
1826
+ /**
1827
+ * Handle user request to resolve connectivity issue.
1828
+ * This method will send an email to Freemius API technical staff for resolution.
1829
+ * The email will contain server's info and installed plugins (might be caching issue).
1830
+ *
1831
+ * @author Vova Feldman (@svovaf)
1832
+ * @since 1.0.9
1833
+ */
1834
+ function _email_about_firewall_issue() {
1835
+ $this->_admin_notices->remove_sticky( 'failed_connect_api' );
1836
+
1837
+ $pong = $this->ping();
1838
+
1839
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1840
+
1841
+ if ( $is_connected ) {
1842
+ $this->store_connectivity_info( $pong, $is_connected );
1843
+
1844
+ echo $this->get_after_plugin_activation_redirect_url();
1845
+ exit;
1846
+ }
1847
+
1848
+ $current_user = self::_get_current_wp_user();
1849
+ $admin_email = $current_user->user_email;
1850
+
1851
+ $error_type = fs_request_get( 'error_type', 'general' );
1852
+
1853
+ switch ( $error_type ) {
1854
+ case 'squid':
1855
+ $title = 'Squid ACL Blocking Issue';
1856
+ break;
1857
+ case 'cloudflare':
1858
+ $title = 'CloudFlare Blocking Issue';
1859
+ break;
1860
+ default:
1861
+ $title = 'API Connectivity Issue';
1862
+ break;
1863
+ }
1864
+
1865
+ $custom_email_sections = array();
1866
+
1867
+ if ( 'squid' === $error_type ) {
1868
+ // Override the 'Site' email section.
1869
+ $custom_email_sections['site'] = array(
1870
+ 'rows' => array(
1871
+ 'hosting_company' => array( 'Hosting Company', fs_request_get( 'hosting_company' ) )
1872
+ )
1873
+ );
1874
+ }
1875
+
1876
+ // Add 'API Error' custom email section.
1877
+ $custom_email_sections['api_error'] = array(
1878
+ 'title' => 'API Error',
1879
+ 'rows' => array(
1880
+ 'ping' => array( is_string( $pong ) ? htmlentities( $pong ) : json_encode( $pong ) )
1881
+ )
1882
+ );
1883
+
1884
+ // Add PHP info for deeper investigation.
1885
+ ob_start();
1886
+ phpinfo();
1887
+ $php_info = ob_get_clean();
1888
+ $custom_email_sections['php_info'] = array(
1889
+ 'title' => 'PHP Info',
1890
+ 'rows' => array(
1891
+ 'info' => array( $php_info )
1892
+ )
1893
+ );
1894
+
1895
+ // Send email with technical details to resolve CloudFlare's firewall unnecessary protection.
1896
+ $this->send_email(
1897
+ 'api@freemius.com', // recipient
1898
+ $title . ' [' . $this->get_plugin_name() . ']', // subject
1899
+ $custom_email_sections,
1900
+ array( "Reply-To: $admin_email <$admin_email>" ) // headers
1901
+ );
1902
+
1903
+ $this->_admin_notices->add_sticky(
1904
+ sprintf(
1905
+ __fs( 'fix-request-sent-message', $this->_slug ),
1906
+ '<a href="mailto:' . $admin_email . '">' . $admin_email . '</a>'
1907
+ ),
1908
+ 'server_details_sent'
1909
+ );
1910
+
1911
+ // Action was taken, tell that API connectivity troubleshooting should be off now.
1912
+
1913
+ echo "1";
1914
+ exit;
1915
+ }
1916
+
1917
+ /**
1918
+ * Handle connectivity test retry approved by the user.
1919
+ *
1920
+ * @author Vova Feldman (@svovaf)
1921
+ * @since 1.1.7.4
1922
+ */
1923
+ function _retry_connectivity_test() {
1924
+ $this->_admin_notices->remove_sticky( 'failed_connect_api_first' );
1925
+
1926
+ $pong = $this->ping();
1927
+
1928
+ $is_connected = $this->get_api_plugin_scope()->is_valid_ping( $pong );
1929
+
1930
+ if ( $is_connected ) {
1931
+ $this->store_connectivity_info( $pong, $is_connected );
1932
+
1933
+ echo $this->get_after_plugin_activation_redirect_url();
1934
+ } else {
1935
+ // Add connectivity issue message after 2nd failed attempt.
1936
+ $this->_add_connectivity_issue_message( $pong, false );
1937
+
1938
+ echo "1";
1939
+ }
1940
+
1941
+ exit;
1942
+ }
1943
+
1944
+ static function _add_firewall_issues_javascript() {
1945
+ $params = array();
1946
+ fs_require_once_template( 'firewall-issues-js.php', $params );
1947
+ }
1948
+
1949
+ #endregion
1950
+
1951
+ #----------------------------------------------------------------------------------
1952
+ #region Email
1953
+ #----------------------------------------------------------------------------------
1954
+
1955
+ /**
1956
+ * Generates and sends an HTML email with customizable sections.
1957
+ *
1958
+ * @author Leo Fajardo (@leorw)
1959
+ * @since 1.1.2
1960
+ *
1961
+ * @param string $to_address
1962
+ * @param string $subject
1963
+ * @param array $sections
1964
+ * @param array $headers
1965
+ *
1966
+ * @return bool Whether the email contents were sent successfully.
1967
+ */
1968
+ private function send_email(
1969
+ $to_address,
1970
+ $subject,
1971
+ $sections = array(),
1972
+ $headers = array()
1973
+ ) {
1974
+ $default_sections = $this->get_email_sections();
1975
+
1976
+ // Insert new sections or replace the default email sections.
1977
+ if ( is_array( $sections ) && ! empty( $sections ) ) {
1978
+ foreach ( $sections as $section_id => $custom_section ) {
1979
+ if ( ! isset( $default_sections[ $section_id ] ) ) {
1980
+ // If the section does not exist, add it.
1981
+ $default_sections[ $section_id ] = $custom_section;
1982
+ } else {
1983
+ // If the section already exists, override it.
1984
+ $current_section = $default_sections[ $section_id ];
1985
+
1986
+ // Replace the current section's title if a custom section title exists.
1987
+ if ( isset( $custom_section['title'] ) ) {
1988
+ $current_section['title'] = $custom_section['title'];
1989
+ }
1990
+
1991
+ // Insert new rows under the current section or replace the default rows.
1992
+ if ( isset( $custom_section['rows'] ) && is_array( $custom_section['rows'] ) && ! empty( $custom_section['rows'] ) ) {
1993
+ foreach ( $custom_section['rows'] as $row_id => $row ) {
1994
+ $current_section['rows'][ $row_id ] = $row;
1995
+ }
1996
+ }
1997
+
1998
+ $default_sections[ $section_id ] = $current_section;
1999
+ }
2000
+ }
2001
+ }
2002
+
2003
+ $vars = array( 'sections' => $default_sections );
2004
+ $message = fs_get_template( 'email.php', $vars );
2005
+
2006
+ // Set the type of email to HTML.
2007
+ $headers[] = 'Content-type: text/html';
2008
+
2009
+ $header_string = implode( "\r\n", $headers );
2010
+
2011
+ return wp_mail(
2012
+ $to_address,
2013
+ $subject,
2014
+ $message,
2015
+ $header_string
2016
+ );
2017
+ }
2018
+
2019
+ /**
2020
+ * Generates the data for the sections of the email content.
2021
+ *
2022
+ * @author Leo Fajardo (@leorw)
2023
+ * @since 1.1.2
2024
+ *
2025
+ * @return array
2026
+ */
2027
+ private function get_email_sections() {
2028
+ // Retrieve the current user's information so that we can get the user's email, first name, and last name below.
2029
+ $current_user = self::_get_current_wp_user();
2030
+
2031
+ // Retrieve the cURL version information so that we can get the version number below.
2032
+ $curl_version_information = curl_version();
2033
+
2034
+ $active_plugin = self::get_active_plugins();
2035
+
2036
+ // Generate the list of active plugins separated by new line.
2037
+ $active_plugin_string = '';
2038
+ foreach ( $active_plugin as $plugin ) {
2039
+ $active_plugin_string .= sprintf(
2040
+ '<a href="%s">%s</a> [v%s]<br>',
2041
+ $plugin['PluginURI'],
2042
+ $plugin['Name'],
2043
+ $plugin['Version']
2044
+ );
2045
+ }
2046
+
2047
+ $server_ip = WP_FS__REMOTE_ADDR;
2048
+
2049
+ // Generate the default email sections.
2050
+ $sections = array(
2051
+ 'sdk' => array(
2052
+ 'title' => 'SDK',
2053
+ 'rows' => array(
2054
+ 'fs_version' => array( 'FS Version', $this->version ),
2055
+ 'curl_version' => array( 'cURL Version', $curl_version_information['version'] )
2056
+ )
2057
+ ),
2058
+ 'plugin' => array(
2059
+ 'title' => 'Plugin',
2060
+ 'rows' => array(
2061
+ 'name' => array( 'Name', $this->get_plugin_name() ),
2062
+ 'version' => array( 'Version', $this->get_plugin_version() )
2063
+ )
2064
+ ),
2065
+ 'site' => array(
2066
+ 'title' => 'Site',
2067
+ 'rows' => array(
2068
+ 'unique_id' => array( 'Address', $this->get_anonymous_id() ),
2069
+ 'address' => array( 'Address', site_url() ),
2070
+ 'host' => array(
2071
+ 'HTTP_HOST',
2072
+ ( ! empty( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' )
2073
+ ),
2074
+ 'server_addr' => array(
2075
+ 'SERVER_ADDR',
2076
+ '<a href="http://www.projecthoneypot.org/ip_' . $server_ip . '">' . $server_ip . '</a>'
2077
+ )
2078
+ )
2079
+ ),
2080
+ 'user' => array(
2081
+ 'title' => 'User',
2082
+ 'rows' => array(
2083
+ 'email' => array( 'Email', $current_user->user_email ),
2084
+ 'first' => array( 'First', $current_user->user_firstname ),
2085
+ 'last' => array( 'Last', $current_user->user_lastname )
2086
+ )
2087
+ ),
2088
+ 'plugins' => array(
2089
+ 'title' => 'Plugins',
2090
+ 'rows' => array(
2091
+ 'active_plugins' => array( 'Active Plugins', $active_plugin_string )
2092
+ )
2093
+ ),
2094
+ );
2095
+
2096
+ // Allow the sections to be modified by other code.
2097
+ $sections = $this->apply_filters( 'email_template_sections', $sections );
2098
+
2099
+ return $sections;
2100
+ }
2101
+
2102
+ #endregion
2103
+
2104
+ #----------------------------------------------------------------------------------
2105
+ #region Initialization
2106
+ #----------------------------------------------------------------------------------
2107
+
2108
+ /**
2109
+ * Init plugin's Freemius instance.
2110
+ *
2111
+ * @author Vova Feldman (@svovaf)
2112
+ * @since 1.0.1
2113
+ *
2114
+ * @param number $id
2115
+ * @param string $public_key
2116
+ * @param bool $is_live
2117
+ * @param bool $is_premium
2118
+ */
2119
+ function init( $id, $public_key, $is_live = true, $is_premium = true ) {
2120
+ $this->_logger->entrance();
2121
+
2122
+ $this->dynamic_init( array(
2123
+ 'id' => $id,
2124
+ 'public_key' => $public_key,
2125
+ 'is_live' => $is_live,
2126
+ 'is_premium' => $is_premium,
2127
+ ) );
2128
+ }
2129
+
2130
+ /**
2131
+ * Dynamic initiator, originally created to support initiation
2132
+ * with parent_id for add-ons.
2133
+ *
2134
+ * @author Vova Feldman (@svovaf)
2135
+ * @since 1.0.6
2136
+ *
2137
+ * @param array $plugin_info
2138
+ *
2139
+ * @throws Freemius_Exception
2140
+ */
2141
+ function dynamic_init( array $plugin_info ) {
2142
+ $this->_logger->entrance();
2143
+
2144
+ $this->parse_settings( $plugin_info );
2145
+
2146
+ if ( $this->should_stop_execution() ) {
2147
+ return;
2148
+ }
2149
+
2150
+ if ( ! $this->is_registered() ) {
2151
+ if ( $this->is_anonymous() ) {
2152
+ // If user skipped, no need to test connectivity.
2153
+ $this->_has_api_connection = true;
2154
+ $this->_is_on = true;
2155
+ } else {
2156
+ if ( ! $this->has_api_connectivity() ) {
2157
+ if ( $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) ||
2158
+ $this->_admin_notices->has_sticky( 'failed_connect_api' )
2159
+ ) {
2160
+ if ( ! $this->_enable_anonymous || $this->is_premium() ) {
2161
+ // If anonymous mode is disabled, add firewall admin-notice message.
2162
+ add_action( 'admin_footer', array( 'Freemius', '_add_firewall_issues_javascript' ) );
2163
+
2164
+ $this->add_ajax_action( 'resolve_firewall_issues', array(
2165
+ &$this,
2166
+ '_email_about_firewall_issue'
2167
+ ) );
2168
+
2169
+ $this->add_ajax_action( 'retry_connectivity_test', array(
2170
+ &$this,
2171
+ '_retry_connectivity_test'
2172
+ ) );
2173
+ }
2174
+ }
2175
+
2176
+ return;
2177
+ } else {
2178
+ $this->_admin_notices->remove_sticky( array(
2179
+ 'failed_connect_api_first',
2180
+ 'failed_connect_api',
2181
+ ) );
2182
+
2183
+ if ( $this->_anonymous_mode ) {
2184
+ // Simulate anonymous mode.
2185
+ $this->_is_anonymous = true;
2186
+ }
2187
+ }
2188
+ }
2189
+
2190
+ // Check if Freemius is on for the current plugin.
2191
+ // This MUST be executed after all the plugin variables has been loaded.
2192
+ if ( ! $this->is_on() ) {
2193
+ return;
2194
+ }
2195
+ }
2196
+
2197
+ if ( $this->has_api_connectivity() ) {
2198
+ if ( $this->is_cron() ) {
2199
+ $this->hook_callback_to_sync_cron();
2200
+ } else if ( $this->is_user_in_admin() ) {
2201
+ /**
2202
+ * Schedule daily data sync cron if:
2203
+ *
2204
+ * 1. User opted-in (for tracking).
2205
+ * 2. If skipped, but later upgraded (opted-in via upgrade).
2206
+ *
2207
+ * @author Vova Feldman (@svovaf)
2208
+ * @since 1.1.7.3
2209
+ *
2210
+ */
2211
+ if ( $this->is_registered() ) {
2212
+ if ( ! $this->is_sync_cron_on() && $this->is_tracking_allowed() ) {
2213
+ $this->schedule_sync_cron();
2214
+ }
2215
+ }
2216
+
2217
+ /**
2218
+ * Check if requested for manual blocking background sync.
2219
+ */
2220
+ if ( fs_request_has( 'background_sync' ) ) {
2221
+ $this->run_manual_sync();
2222
+ }
2223
+ }
2224
+ }
2225
+
2226
+ if ( $this->is_registered() ) {
2227
+ $this->hook_callback_to_install_sync();
2228
+ }
2229
+
2230
+ if ( $this->is_addon() ) {
2231
+ if ( $this->is_parent_plugin_installed() ) {
2232
+ // Link to parent FS.
2233
+ $this->_parent = self::get_instance_by_id( $this->_plugin->parent_plugin_id );
2234
+
2235
+ // Get parent plugin reference.
2236
+ $this->_parent_plugin = $this->_parent->get_plugin();
2237
+ }
2238
+ }
2239
+
2240
+ if ( $this->is_user_in_admin() ) {
2241
+ if ( $this->is_plugins_page() ) {
2242
+ $this->hook_plugin_action_links();
2243
+ }
2244
+
2245
+ if ( $this->is_addon() ) {
2246
+ if ( ! $this->is_parent_plugin_installed() ) {
2247
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2248
+
2249
+ if ( isset( $plugin_info['parent'] ) ) {
2250
+ $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2251
+ }
2252
+
2253
+ $this->_admin_notices->add(
2254
+ ( ! empty( $parent_name ) ?
2255
+ sprintf( __fs( 'addon-x-cannot-run-without-y', $this->_slug ), $this->get_plugin_name(), $parent_name ) :
2256
+ sprintf( __fs( 'addon-x-cannot-run-without-parent', $this->_slug ), $this->get_plugin_name() )
2257
+ ),
2258
+ __fs( 'oops', $this->_slug ) . '...',
2259
+ 'error'
2260
+ );
2261
+
2262
+ return;
2263
+ } else {
2264
+ if ( $this->_parent->is_registered() && ! $this->is_registered() ) {
2265
+ // If parent plugin activated, automatically install add-on for the user.
2266
+ $this->_activate_addon_account( $this->_parent );
2267
+ }
2268
+
2269
+ // @todo This should be only executed on activation. It should be migrated to register_activation_hook() together with other activation related logic.
2270
+ if ( $this->is_premium() ) {
2271
+ // Remove add-on download admin-notice.
2272
+ $this->_parent->_admin_notices->remove_sticky( array(
2273
+ 'addon_plan_upgraded_' . $this->_slug,
2274
+ 'no_addon_license_' . $this->_slug,
2275
+ ) );
2276
+ }
2277
+
2278
+ $this->deactivate_premium_only_addon_without_license();
2279
+ }
2280
+ } else {
2281
+ add_action( 'admin_init', array( &$this, '_admin_init_action' ) );
2282
+
2283
+ if ( $this->has_addons() &&
2284
+ 'plugin-information' === fs_request_get( 'tab', false ) &&
2285
+ $this->get_id() == fs_request_get( 'parent_plugin_id', false )
2286
+ ) {
2287
+ require_once WP_FS__DIR_INCLUDES . '/fs-plugin-info-dialog.php';
2288
+
2289
+ new FS_Plugin_Info_Dialog( $this );
2290
+ }
2291
+ }
2292
+
2293
+ if ( $this->is_premium() ) {
2294
+ new FS_Plugin_Updater( $this );
2295
+ }
2296
+
2297
+ // if ( $this->is_registered() ||
2298
+ // $this->is_anonymous() ||
2299
+ // $this->is_pending_activation()
2300
+ // ) {
2301
+ // $this->_init_admin();
2302
+ // }
2303
+ }
2304
+
2305
+ $this->do_action( 'initiated' );
2306
+
2307
+ if ( $this->_storage->prev_is_premium !== $this->_plugin->is_premium ) {
2308
+ if ( isset( $this->_storage->prev_is_premium ) ) {
2309
+ $this->apply_filters(
2310
+ 'after_code_type_change',
2311
+ // New code type.
2312
+ $this->_plugin->is_premium
2313
+ );
2314
+ } else {
2315
+ // Set for code type for the first time.
2316
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2317
+ }
2318
+ }
2319
+
2320
+ if ( ! $this->is_addon() ) {
2321
+ if ( $this->is_registered() ) {
2322
+ // Fix for upgrade from versions < 1.0.9.
2323
+ if ( ! isset( $this->_storage->activation_timestamp ) ) {
2324
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
2325
+ }
2326
+
2327
+ $this->do_action( 'after_init_plugin_registered' );
2328
+ } else if ( $this->is_anonymous() ) {
2329
+ $this->do_action( 'after_init_plugin_anonymous' );
2330
+ } else if ( $this->is_pending_activation() ) {
2331
+ $this->do_action( 'after_init_plugin_pending_activations' );
2332
+ }
2333
+ } else {
2334
+ if ( $this->is_registered() ) {
2335
+ $this->do_action( 'after_init_addon_registered' );
2336
+ } else if ( $this->is_anonymous() ) {
2337
+ $this->do_action( 'after_init_addon_anonymous' );
2338
+ } else if ( $this->is_pending_activation() ) {
2339
+ $this->do_action( 'after_init_addon_pending_activations' );
2340
+ }
2341
+ }
2342
+ }
2343
+
2344
+ /**
2345
+ * @author Leo Fajardo (@leorw)
2346
+ *
2347
+ * @since 1.2.1.5
2348
+ */
2349
+ function _stop_tracking_callback() {
2350
+ $result = $this->stop_tracking();
2351
+
2352
+ if ( true === $result ) {
2353
+ $this->shoot_ajax_success();
2354
+ }
2355
+
2356
+ $this->_logger->api_error( $result );
2357
+
2358
+ $this->shoot_ajax_failure(
2359
+ __fs( 'unexpected-api-error', $this->_slug ) .
2360
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
2361
+ $result->error->message :
2362
+ var_export( $result, true ) )
2363
+ );
2364
+ }
2365
+
2366
+ /**
2367
+ * @author Leo Fajardo (@leorw)
2368
+ * @since 1.2.1.5
2369
+ */
2370
+ function _allow_tracking_callback() {
2371
+ $result = $this->allow_tracking();
2372
+
2373
+ if ( true === $result ) {
2374
+ $this->shoot_ajax_success();
2375
+ }
2376
+
2377
+ $this->_logger->api_error( $result );
2378
+
2379
+ $this->shoot_ajax_failure(
2380
+ __fs( 'unexpected-api-error', $this->_slug ) .
2381
+ ( $this->is_api_error( $result ) && isset( $result->error ) ?
2382
+ $result->error->message :
2383
+ var_export( $result, true ) )
2384
+ );
2385
+ }
2386
+
2387
+ /**
2388
+ * Opt-out from usage tracking.
2389
+ *
2390
+ * Note: This will not delete the account information but will stop all tracking.
2391
+ *
2392
+ * Returns:
2393
+ * 1. FALSE - If the user never opted-in.
2394
+ * 2. TRUE - If successfully opted-out.
2395
+ * 3. object - API result on failure.
2396
+ *
2397
+ * @author Leo Fajardo (@leorw)
2398
+ * @since 1.2.1.5
2399
+ *
2400
+ * @return bool|object
2401
+ */
2402
+ function stop_tracking() {
2403
+ $this->_logger->entrance();
2404
+
2405
+ if ( ! $this->is_registered() ) {
2406
+ // User never opted-in.
2407
+ return false;
2408
+ }
2409
+
2410
+ if ( $this->is_tracking_prohibited() ) {
2411
+ // Already disconnected.
2412
+ return true;
2413
+ }
2414
+
2415
+ // Send update to FS.
2416
+ $result = $this->get_api_site_scope()->call( '/?fields=is_disconnected', 'put', array(
2417
+ 'is_disconnected' => true
2418
+ ) );
2419
+
2420
+ if ( ! $this->is_api_result_entity( $result ) ||
2421
+ ! isset( $result->is_disconnected ) ||
2422
+ ! $result->is_disconnected
2423
+ ) {
2424
+ $this->_logger->api_error( $result );
2425
+
2426
+ return $result;
2427
+ }
2428
+
2429
+ $this->_site->is_disconnected = $result->is_disconnected;
2430
+ $this->_store_site();
2431
+
2432
+ $this->clear_sync_cron();
2433
+
2434
+ // Successfully disconnected.
2435
+ return true;
2436
+ }
2437
+
2438
+ /**
2439
+ * Opt-in back into usage tracking.
2440
+ *
2441
+ * Note: This will only work if the user opted-in previously.
2442
+ *
2443
+ * Returns:
2444
+ * 1. FALSE - If the user never opted-in.
2445
+ * 2. TRUE - If successfully opted-in back to usage tracking.
2446
+ * 3. object - API result on failure.
2447
+ *
2448
+ * @author Leo Fajardo (@leorw)
2449
+ * @since 1.2.1.5
2450
+ *
2451
+ * @return bool|object
2452
+ */
2453
+ function allow_tracking() {
2454
+ $this->_logger->entrance();
2455
+
2456
+ if ( ! $this->is_registered() ) {
2457
+ // User never opted-in.
2458
+ return false;
2459
+ }
2460
+
2461
+ if ( $this->is_tracking_allowed() ) {
2462
+ // Tracking already allowed.
2463
+ return true;
2464
+ }
2465
+
2466
+ $result = $this->get_api_site_scope()->call( '/?is_disconnected', 'put', array(
2467
+ 'is_disconnected' => false
2468
+ ) );
2469
+
2470
+ if ( ! $this->is_api_result_entity( $result ) ||
2471
+ ! isset( $result->is_disconnected ) ||
2472
+ $result->is_disconnected
2473
+ ) {
2474
+ $this->_logger->api_error( $result );
2475
+
2476
+ return $result;
2477
+ }
2478
+
2479
+ $this->_site->is_disconnected = $result->is_disconnected;
2480
+ $this->_store_site();
2481
+
2482
+ $this->schedule_sync_cron();
2483
+
2484
+ // Successfully reconnected.
2485
+ return true;
2486
+ }
2487
+
2488
+ /**
2489
+ * If user opted-in and later disabled usage-tracking,
2490
+ * re-allow tracking for licensing and updates.
2491
+ *
2492
+ * @author Leo Fajardo (@leorw)
2493
+ *
2494
+ * @since 1.2.1.5
2495
+ */
2496
+ private function reconnect_locally() {
2497
+ $this->_logger->entrance();
2498
+
2499
+ if ( $this->is_tracking_prohibited() &&
2500
+ $this->is_registered()
2501
+ ) {
2502
+ $this->_site->is_disconnected = false;
2503
+ $this->_store_site();
2504
+ }
2505
+ }
2506
+
2507
+ /**
2508
+ * Parse plugin's settings (as defined by the plugin dev).
2509
+ *
2510
+ * @author Vova Feldman (@svovaf)
2511
+ * @since 1.1.7.3
2512
+ *
2513
+ * @param array $plugin_info
2514
+ *
2515
+ * @throws \Freemius_Exception
2516
+ */
2517
+ private function parse_settings( &$plugin_info ) {
2518
+ $this->_logger->entrance();
2519
+
2520
+ $id = $this->get_numeric_option( $plugin_info, 'id', false );
2521
+ $public_key = $this->get_option( $plugin_info, 'public_key', false );
2522
+ $secret_key = $this->get_option( $plugin_info, 'secret_key', null );
2523
+ $parent_id = $this->get_numeric_option( $plugin_info, 'parent_id', null );
2524
+ $parent_name = $this->get_option( $plugin_info, 'parent_name', null );
2525
+
2526
+ /**
2527
+ * @author Vova Feldman (@svovaf)
2528
+ * @since 1.1.9 Try to pull secret key from external config.
2529
+ */
2530
+ if ( is_null( $secret_key ) && defined( "WP_FS__{$this->_slug}_SECRET_KEY" ) ) {
2531
+ $secret_key = constant( "WP_FS__{$this->_slug}_SECRET_KEY" );
2532
+ }
2533
+
2534
+ if ( isset( $plugin_info['parent'] ) ) {
2535
+ $parent_id = $this->get_numeric_option( $plugin_info['parent'], 'id', null );
2536
+ // $parent_slug = $this->get_option( $plugin_info['parent'], 'slug', null );
2537
+ // $parent_public_key = $this->get_option( $plugin_info['parent'], 'public_key', null );
2538
+ // $parent_name = $this->get_option( $plugin_info['parent'], 'name', null );
2539
+ }
2540
+
2541
+ if ( false === $id ) {
2542
+ throw new Freemius_Exception( 'Plugin id parameter is not set.' );
2543
+ }
2544
+ if ( false === $public_key ) {
2545
+ throw new Freemius_Exception( 'Plugin public_key parameter is not set.' );
2546
+ }
2547
+
2548
+ $plugin = ( $this->_plugin instanceof FS_Plugin ) ?
2549
+ $this->_plugin :
2550
+ new FS_Plugin();
2551
+
2552
+ $plugin->update( array(
2553
+ 'id' => $id,
2554
+ 'public_key' => $public_key,
2555
+ 'slug' => $this->_slug,
2556
+ 'parent_plugin_id' => $parent_id,
2557
+ 'version' => $this->get_plugin_version(),
2558
+ 'title' => $this->get_plugin_name(),
2559
+ 'file' => $this->_plugin_basename,
2560
+ 'is_premium' => $this->get_bool_option( $plugin_info, 'is_premium', true ),
2561
+ 'is_live' => $this->get_bool_option( $plugin_info, 'is_live', true ),
2562
+ // 'secret_key' => $secret_key,
2563
+ ) );
2564
+
2565
+ if ( $plugin->is_updated() ) {
2566
+ // Update plugin details.
2567
+ $this->_plugin = FS_Plugin_Manager::instance( $this->_slug )->store( $plugin );
2568
+ }
2569
+ // Set the secret key after storing the plugin, we don't want to store the key in the storage.
2570
+ $this->_plugin->secret_key = $secret_key;
2571
+
2572
+ if ( ! isset( $plugin_info['menu'] ) ) {
2573
+ // Back compatibility to 1.1.2
2574
+ $plugin_info['menu'] = array(
2575
+ 'slug' => isset( $plugin_info['menu_slug'] ) ?
2576
+ $plugin_info['menu_slug'] :
2577
+ $this->_slug
2578
+ );
2579
+ }
2580
+
2581
+ $this->_menu = FS_Admin_Menu_Manager::instance( $this->_slug );
2582
+ $this->_menu->init( $plugin_info['menu'], $this->is_addon() );
2583
+
2584
+ $this->_has_addons = $this->get_bool_option( $plugin_info, 'has_addons', false );
2585
+ $this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
2586
+ $this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
2587
+ $this->_is_premium_only = $this->get_bool_option( $plugin_info, 'is_premium_only', false );
2588
+ if ( $this->_is_premium_only ) {
2589
+ // If premium only plugin, disable anonymous mode.
2590
+ $this->_enable_anonymous = false;
2591
+ $this->_anonymous_mode = false;
2592
+ } else {
2593
+ $this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
2594
+ $this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
2595
+ }
2596
+ $this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
2597
+
2598
+ if ( ! empty( $plugin_info['trial'] ) ) {
2599
+ $this->_trial_days = $this->get_numeric_option(
2600
+ $plugin_info['trial'],
2601
+ 'days',
2602
+ // Default to 0 - trial without days specification.
2603
+ 0
2604
+ );
2605
+
2606
+ $this->_is_trial_require_payment = $this->get_bool_option( $plugin_info['trial'], 'is_require_payment', false );
2607
+ }
2608
+ }
2609
+
2610
+ /**
2611
+ * @param string[] $options
2612
+ * @param string $key
2613
+ * @param mixed $default
2614
+ *
2615
+ * @return bool
2616
+ */
2617
+ private function get_option( &$options, $key, $default = false ) {
2618
+ return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
2619
+ }
2620
+
2621
+ private function get_bool_option( &$options, $key, $default = false ) {
2622
+ return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
2623
+ }
2624
+
2625
+ private function get_numeric_option( &$options, $key, $default = false ) {
2626
+ return isset( $options[ $key ] ) && is_numeric( $options[ $key ] ) ? $options[ $key ] : $default;
2627
+ }
2628
+
2629
+ /**
2630
+ * Gate keeper.
2631
+ *
2632
+ * @author Vova Feldman (@svovaf)
2633
+ * @since 1.1.7.3
2634
+ *
2635
+ * @return bool
2636
+ */
2637
+ private function should_stop_execution() {
2638
+ if ( empty( $this->_storage->was_plugin_loaded ) ) {
2639
+ /**
2640
+ * Don't execute Freemius until plugin was fully loaded at least once,
2641
+ * to give the opportunity for the activation hook to run before pinging
2642
+ * the API for connectivity test. This logic is relevant for the
2643
+ * identification of new plugin install vs. plugin update.
2644
+ *
2645
+ * @author Vova Feldman (@svovaf)
2646
+ * @since 1.1.9
2647
+ */
2648
+ return true;
2649
+ }
2650
+
2651
+ if ( $this->is_activation_mode() ) {
2652
+ if ( ! is_admin() ) {
2653
+ /**
2654
+ * If in activation mode, don't execute Freemius outside of the
2655
+ * admin dashboard.
2656
+ *
2657
+ * @author Vova Feldman (@svovaf)
2658
+ * @since 1.1.7.3
2659
+ */
2660
+ return true;
2661
+ }
2662
+
2663
+ if ( ! WP_FS__IS_HTTP_REQUEST ) {
2664
+ /**
2665
+ * If in activation and executed without HTTP context (e.g. CLI, Cronjob),
2666
+ * then don't start Freemius.
2667
+ *
2668
+ * @author Vova Feldman (@svovaf)
2669
+ * @since 1.1.6.3
2670
+ *
2671
+ * @link https://wordpress.org/support/topic/errors-in-the-freemius-class-when-running-in-wordpress-in-cli
2672
+ */
2673
+ return true;
2674
+ }
2675
+
2676
+ if ( $this->is_cron() ) {
2677
+ /**
2678
+ * If in activation mode, don't execute Freemius during wp crons
2679
+ * (wp crons have HTTP context - called as HTTP request).
2680
+ *
2681
+ * @author Vova Feldman (@svovaf)
2682
+ * @since 1.1.7.3
2683
+ */
2684
+ return true;
2685
+ }
2686
+
2687
+ if ( $this->is_ajax() &&
2688
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api_first' ) &&
2689
+ ! $this->_admin_notices->has_sticky( 'failed_connect_api' )
2690
+ ) {
2691
+ /**
2692
+ * During activation, if running in AJAX mode, unless there's a sticky
2693
+ * connectivity issue notice, don't run Freemius.
2694
+ *
2695
+ * @author Vova Feldman (@svovaf)
2696
+ * @since 1.1.7.3
2697
+ */
2698
+ return true;
2699
+ }
2700
+ }
2701
+
2702
+ return false;
2703
+ }
2704
+
2705
+ /**
2706
+ * Triggered after code type has changed.
2707
+ *
2708
+ * @author Vova Feldman (@svovaf)
2709
+ * @since 1.1.9.1
2710
+ */
2711
+ function _after_code_type_change() {
2712
+ $this->_logger->entrance();
2713
+
2714
+ add_action( is_admin() ? 'admin_init' : 'init', array(
2715
+ &$this,
2716
+ '_plugin_code_type_changed'
2717
+ ) );
2718
+ }
2719
+
2720
+ /**
2721
+ * Handles plugin's code type change (free <--> premium).
2722
+ *
2723
+ * @author Vova Feldman (@svovaf)
2724
+ * @since 1.0.9
2725
+ */
2726
+ function _plugin_code_type_changed() {
2727
+ $this->_logger->entrance();
2728
+
2729
+ if ( $this->is_premium() ) {
2730
+ $this->reconnect_locally();
2731
+
2732
+ // Activated premium code.
2733
+ $this->do_action( 'after_premium_version_activation' );
2734
+
2735
+ // Remove all sticky messages related to download of the premium version.
2736
+ $this->_admin_notices->remove_sticky( array(
2737
+ 'trial_started',
2738
+ 'plan_upgraded',
2739
+ 'plan_changed',
2740
+ 'license_activated',
2741
+ ) );
2742
+
2743
+ $this->_admin_notices->add_sticky(
2744
+ __fs( 'premium-activated-message', $this->_slug ),
2745
+ 'premium_activated',
2746
+ __fs( 'woot', $this->_slug ) . '!'
2747
+ );
2748
+ } else {
2749
+ // Remove sticky message related to premium code activation.
2750
+ $this->_admin_notices->remove_sticky( 'premium_activated' );
2751
+
2752
+ // Activated free code (after had the premium before).
2753
+ $this->do_action( 'after_free_version_reactivation' );
2754
+
2755
+ if ( $this->is_paying() && ! $this->is_premium() ) {
2756
+ $this->_admin_notices->add_sticky(
2757
+ sprintf(
2758
+ __fs( 'you-have-x-license', $this->_slug ),
2759
+ $this->_site->plan->title
2760
+ ) . $this->get_complete_upgrade_instructions(),
2761
+ 'plan_upgraded',
2762
+ __fs( 'yee-haw', $this->_slug ) . '!'
2763
+ );
2764
+ }
2765
+ }
2766
+
2767
+ // Schedule code type changes event.
2768
+ $this->schedule_install_sync();
2769
+
2770
+ /**
2771
+ * Unregister the uninstall hook for the other version of the plugin (with different code type) to avoid
2772
+ * triggering a fatal error when uninstalling that plugin. For example, after deactivating the "free" version
2773
+ * of a specific plugin, its uninstall hook should be unregistered after the "premium" version has been
2774
+ * activated. If we don't do that, a fatal error will occur when we try to uninstall the "free" version since
2775
+ * the main file of the "free" version will be loaded first before calling the hooked callback. Since the
2776
+ * free and premium versions are almost identical (same class or have same functions), a fatal error like
2777
+ * "Cannot redeclare class MyClass" or "Cannot redeclare my_function()" will occur.
2778
+ */
2779
+ $this->unregister_uninstall_hook();
2780
+
2781
+ $this->clear_module_main_file_cache();
2782
+
2783
+ // Update is_premium of latest version.
2784
+ $this->_storage->prev_is_premium = $this->_plugin->is_premium;
2785
+ }
2786
+
2787
+ #endregion
2788
+
2789
+ #----------------------------------------------------------------------------------
2790
+ #region Add-ons
2791
+ #----------------------------------------------------------------------------------
2792
+
2793
+ /**
2794
+ * Check if add-on installed and activated on site.
2795
+ *
2796
+ * @author Vova Feldman (@svovaf)
2797
+ * @since 1.0.6
2798
+ *
2799
+ * @param string|number $slug_or_id
2800
+ *
2801
+ * @return bool
2802
+ */
2803
+ function is_addon_activated( $slug_or_id ) {
2804
+ return self::has_instance( $slug_or_id );
2805
+ }
2806
+
2807
+ /**
2808
+ * Check if add-on was connected to install
2809
+ *
2810
+ * @author Vova Feldman (@svovaf)
2811
+ * @since 1.1.7
2812
+ *
2813
+ * @param string $slug
2814
+ *
2815
+ * @return bool
2816
+ */
2817
+ function is_addon_connected( $slug ) {
2818
+ $sites = self::get_all_sites();
2819
+
2820
+ if ( ! isset( $sites[ $slug ] ) ) {
2821
+ return false;
2822
+ }
2823
+
2824
+ $site = $sites[ $slug ];
2825
+
2826
+ $plugin = FS_Plugin_Manager::instance( $slug )->get();
2827
+
2828
+ if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
2829
+ // The given slug do NOT belong to any of the plugin's add-ons.
2830
+ return false;
2831
+ }
2832
+
2833
+ return ( is_object( $site ) &&
2834
+ is_numeric( $site->id ) &&
2835
+ is_numeric( $site->user_id ) &&
2836
+ is_object( $site->plan )
2837
+ );
2838
+ }
2839
+
2840
+ /**
2841
+ * Determines if add-on installed.
2842
+ *
2843
+ * NOTE: This is a heuristic and only works if the folder/file named as the slug.
2844
+ *
2845
+ * @author Vova Feldman (@svovaf)
2846
+ * @since 1.0.6
2847
+ *
2848
+ * @param string $slug
2849
+ *
2850
+ * @return bool
2851
+ */
2852
+ function is_addon_installed( $slug ) {
2853
+ return file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $this->get_addon_basename( $slug ) ) );
2854
+ }
2855
+
2856
+ /**
2857
+ * Get add-on basename.
2858
+ *
2859
+ * @author Vova Feldman (@svovaf)
2860
+ * @since 1.0.6
2861
+ *
2862
+ * @param string $slug
2863
+ *
2864
+ * @return string
2865
+ */
2866
+ function get_addon_basename( $slug ) {
2867
+ if ( $this->is_addon_activated( $slug ) ) {
2868
+ self::instance( $slug )->get_plugin_basename();
2869
+ }
2870
+
2871
+ $premium_basename = $slug . '-premium/' . $slug . '.php';
2872
+
2873
+ if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $premium_basename ) ) ) {
2874
+ return $premium_basename;
2875
+ }
2876
+
2877
+ $free_basename = $slug . '/' . $slug . '.php';
2878
+
2879
+ return $free_basename;
2880
+ }
2881
+
2882
+ /**
2883
+ * Get installed add-ons instances.
2884
+ *
2885
+ * @author Vova Feldman (@svovaf)
2886
+ * @since 1.0.6
2887
+ *
2888
+ * @return Freemius[]
2889
+ */
2890
+ function get_installed_addons() {
2891
+ $installed_addons = array();
2892
+ foreach ( self::$_instances as $slug => $instance ) {
2893
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2894
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2895
+ $installed_addons[] = $instance;
2896
+ }
2897
+ }
2898
+ }
2899
+
2900
+ return $installed_addons;
2901
+ }
2902
+
2903
+ /**
2904
+ * Check if any add-ons of the plugin are installed.
2905
+ *
2906
+ * @author Leo Fajardo (@leorw)
2907
+ * @since 1.1.1
2908
+ *
2909
+ * @return bool
2910
+ */
2911
+ function has_installed_addons() {
2912
+ if ( ! $this->has_addons() ) {
2913
+ return false;
2914
+ }
2915
+
2916
+ foreach ( self::$_instances as $slug => $instance ) {
2917
+ if ( $instance->is_addon() && is_object( $instance->_parent_plugin ) ) {
2918
+ if ( $this->_plugin->id == $instance->_parent_plugin->id ) {
2919
+ return true;
2920
+ }
2921
+ }
2922
+ }
2923
+
2924
+ return false;
2925
+ }
2926
+
2927
+ /**
2928
+ * Tell Freemius that the current plugin is an add-on.
2929
+ *
2930
+ * @author Vova Feldman (@svovaf)
2931
+ * @since 1.0.6
2932
+ *
2933
+ * @param number $parent_plugin_id The parent plugin ID
2934
+ */
2935
+ function init_addon( $parent_plugin_id ) {
2936
+ $this->_plugin->parent_plugin_id = $parent_plugin_id;
2937
+ }
2938
+
2939
+ /**
2940
+ * @author Vova Feldman (@svovaf)
2941
+ * @since 1.0.6
2942
+ *
2943
+ * @return bool
2944
+ */
2945
+ function is_addon() {
2946
+ return isset( $this->_plugin->parent_plugin_id ) && is_numeric( $this->_plugin->parent_plugin_id );
2947
+ }
2948
+
2949
+ /**
2950
+ * Deactivate add-on if it's premium only and the user does't have a valid license.
2951
+ *
2952
+ * @param bool $is_after_trial_cancel
2953
+ *
2954
+ * @return bool If add-on was deactivated.
2955
+ */
2956
+ private function deactivate_premium_only_addon_without_license( $is_after_trial_cancel = false ) {
2957
+ if ( ! $this->has_free_plan() &&
2958
+ ! $this->has_features_enabled_license() &&
2959
+ ! $this->_has_premium_license()
2960
+ ) {
2961
+ // IF wrapper is turned off because activation_timestamp is currently only stored for plugins (not addons).
2962
+ // if (empty($this->_storage->activation_timestamp) ||
2963
+ // (WP_FS__SCRIPT_START_TIME - $this->_storage->activation_timestamp) > 30
2964
+ // ) {
2965
+ /**
2966
+ * @todo When it's first fail, there's no reason to try and re-sync because the licenses were just synced after initial activation.
2967
+ *
2968
+ * Retry syncing the user add-on licenses.
2969
+ */
2970
+ // Sync licenses.
2971
+ $this->_sync_licenses();
2972
+ // }
2973
+
2974
+ // Try to activate premium license.
2975
+ $this->_activate_license( true );
2976
+
2977
+ if ( ! $this->has_free_plan() &&
2978
+ ! $this->has_features_enabled_license() &&
2979
+ ! $this->_has_premium_license()
2980
+ ) {
2981
+ // @todo Check if deactivate plugins also call the deactivation hook.
2982
+
2983
+ deactivate_plugins( array( $this->_plugin_basename ), true );
2984
+
2985
+ $this->_parent->_admin_notices->add_sticky(
2986
+ sprintf(
2987
+ __fs( ( $is_after_trial_cancel ?
2988
+ 'addon-trial-cancelled-message' :
2989
+ 'addon-no-license-message' ),
2990
+ $this->_parent->_slug
2991
+ ),
2992
+ '<b>' . $this->_plugin->title . '</b>'
2993
+ ) . ' ' . sprintf(
2994
+ '<a href="%s" aria-label="%s" class="button button-primary" style="margin-left: 10px; vertical-align: middle;">%s &nbsp;&#10140;</a>',
2995
+ $this->_parent->addon_url( $this->_slug ),
2996
+ esc_attr( sprintf( __fs( 'more-information-about-x', $this->_parent->_slug ), $this->_plugin->title ) ),
2997
+ __fs( 'purchase-license', $this->_parent->_slug )
2998
+ ),
2999
+ 'no_addon_license_' . $this->_slug,
3000
+ ( $is_after_trial_cancel ? '' : __fs( 'oops', $this->_parent->_slug ) . '...' ),
3001
+ ( $is_after_trial_cancel ? 'success' : 'error' )
3002
+ );
3003
+
3004
+ return true;
3005
+ }
3006
+ }
3007
+
3008
+ return false;
3009
+ }
3010
+
3011
+ #endregion
3012
+
3013
+ #----------------------------------------------------------------------------------
3014
+ #region Sandbox
3015
+ #----------------------------------------------------------------------------------
3016
+
3017
+ /**
3018
+ * Set Freemius into sandbox mode for debugging.
3019
+ *
3020
+ * @author Vova Feldman (@svovaf)
3021
+ * @since 1.0.4
3022
+ *
3023
+ * @param string $secret_key
3024
+ */
3025
+ function init_sandbox( $secret_key ) {
3026
+ $this->_plugin->secret_key = $secret_key;
3027
+
3028
+ // Update plugin details.
3029
+ FS_Plugin_Manager::instance( $this->_slug )->update( $this->_plugin, true );
3030
+ }
3031
+
3032
+ /**
3033
+ * Check if running payments in sandbox mode.
3034
+ *
3035
+ * @author Vova Feldman (@svovaf)
3036
+ * @since 1.0.4
3037
+ *
3038
+ * @return bool
3039
+ */
3040
+ function is_payments_sandbox() {
3041
+ return ( ! $this->is_live() ) || isset( $this->_plugin->secret_key );
3042
+ }
3043
+
3044
+ #endregion
3045
+
3046
+ /**
3047
+ * Check if running test vs. live plugin.
3048
+ *
3049
+ * @author Vova Feldman (@svovaf)
3050
+ * @since 1.0.5
3051
+ *
3052
+ * @return bool
3053
+ */
3054
+ function is_live() {
3055
+ return $this->_plugin->is_live;
3056
+ }
3057
+
3058
+ /**
3059
+ * Check if the user skipped connecting the account with Freemius.
3060
+ *
3061
+ * @author Vova Feldman (@svovaf)
3062
+ * @since 1.0.7
3063
+ *
3064
+ * @return bool
3065
+ */
3066
+ function is_anonymous() {
3067
+ if ( ! isset( $this->_is_anonymous ) ) {
3068
+ if ( ! isset( $this->_storage->is_anonymous ) ) {
3069
+ // Not skipped.
3070
+ $this->_is_anonymous = false;
3071
+ } else if ( is_bool( $this->_storage->is_anonymous ) ) {
3072
+ // For back compatibility, since the variable was boolean before.
3073
+ $this->_is_anonymous = $this->_storage->is_anonymous;
3074
+
3075
+ // Upgrade stored data format to 1.1.3 format.
3076
+ $this->set_anonymous_mode( $this->_storage->is_anonymous );
3077
+ } else {
3078
+ // Version 1.1.3 and later.
3079
+ $this->_is_anonymous = $this->_storage->is_anonymous['is'];
3080
+ }
3081
+ }
3082
+
3083
+ return $this->_is_anonymous;
3084
+ }
3085
+
3086
+ /**
3087
+ * Check if user connected his account and install pending email activation.
3088
+ *
3089
+ * @author Vova Feldman (@svovaf)
3090
+ * @since 1.0.7
3091
+ *
3092
+ * @return bool
3093
+ */
3094
+ function is_pending_activation() {
3095
+ return $this->_storage->get( 'is_pending_activation', false );
3096
+ }
3097
+
3098
+ /**
3099
+ * Check if plugin must be WordPress.org compliant.
3100
+ *
3101
+ * @since 1.0.7
3102
+ *
3103
+ * @return bool
3104
+ */
3105
+ function is_org_repo_compliant() {
3106
+ return $this->_is_org_compliant;
3107
+ }
3108
+
3109
+ #----------------------------------------------------------------------------------
3110
+ #region Daily Sync Cron
3111
+ #----------------------------------------------------------------------------------
3112
+
3113
+ /**
3114
+ * @author Vova Feldman (@svovaf)
3115
+ * @since 1.1.7.3
3116
+ */
3117
+ private function run_manual_sync() {
3118
+ $this->require_pluggable_essentials();
3119
+
3120
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3121
+ return;
3122
+ }
3123
+
3124
+ // Run manual sync.
3125
+ $this->_sync_cron();
3126
+
3127
+ // Reschedule next cron to run 24 hours from now (performance optimization).
3128
+ $this->clear_sync_cron();
3129
+
3130
+ $this->schedule_sync_cron( time() + WP_FS__TIME_24_HOURS_IN_SEC, false );
3131
+ }
3132
+
3133
+ /**
3134
+ * Data sync cron job. Replaces the background sync non blocking HTTP request
3135
+ * that doesn't halt page loading.
3136
+ *
3137
+ * @author Vova Feldman (@svovaf)
3138
+ * @since 1.1.7.3
3139
+ */
3140
+ function _sync_cron() {
3141
+ $this->_logger->entrance();
3142
+
3143
+ // Store the last time data sync was executed.
3144
+ $this->_storage->sync_timestamp = time();
3145
+
3146
+ // Check if API is temporary down.
3147
+ if ( FS_Api::is_temporary_down() ) {
3148
+ return;
3149
+ }
3150
+
3151
+ // @todo Add logic that identifies API latency, and reschedule the next background sync randomly between 8-16 hours.
3152
+
3153
+ if ( $this->is_registered() ) {
3154
+ if ( $this->has_paid_plan() ) {
3155
+ // Initiate background plan sync.
3156
+ $this->_sync_license( true );
3157
+
3158
+ if ( $this->is_paying() ) {
3159
+ // Check for premium plugin updates.
3160
+ $this->_check_updates( true );
3161
+ }
3162
+ } else {
3163
+ // Sync install (only if something changed locally).
3164
+ $this->sync_install();
3165
+ }
3166
+ }
3167
+
3168
+ $this->do_action( 'after_sync_cron' );
3169
+ }
3170
+
3171
+ /**
3172
+ * Check if sync was executed in the last $period of seconds.
3173
+ *
3174
+ * @author Vova Feldman (@svovaf)
3175
+ * @since 1.1.7.3
3176
+ *
3177
+ * @param int $period In seconds
3178
+ *
3179
+ * @return bool
3180
+ */
3181
+ private function is_sync_executed( $period = WP_FS__TIME_24_HOURS_IN_SEC ) {
3182
+ if ( ! isset( $this->_storage->sync_timestamp ) ) {
3183
+ return false;
3184
+ }
3185
+
3186
+ return ( $this->_storage->sync_timestamp > ( WP_FS__SCRIPT_START_TIME - $period ) );
3187
+ }
3188
+
3189
+ /**
3190
+ * @author Vova Feldman (@svovaf)
3191
+ * @since 1.1.7.3
3192
+ *
3193
+ * @return bool
3194
+ */
3195
+ private function is_sync_cron_on() {
3196
+ /**
3197
+ * @var object $sync_cron_data
3198
+ */
3199
+ $sync_cron_data = $this->_storage->get( 'sync_cron', null );
3200
+
3201
+ return ( ! is_null( $sync_cron_data ) && true === $sync_cron_data->on );
3202
+ }
3203
+
3204
+ /**
3205
+ * @author Vova Feldman (@svovaf)
3206
+ * @since 1.1.7.3
3207
+ *
3208
+ * @param int $start_at Defaults to now.
3209
+ * @param bool $randomize_start If true, schedule first job randomly during the next 12 hours. Otherwise,
3210
+ * schedule job to start right away.
3211
+ */
3212
+ private function schedule_sync_cron( $start_at = WP_FS__SCRIPT_START_TIME, $randomize_start = true ) {
3213
+ $this->_logger->entrance();
3214
+
3215
+ if ( $randomize_start ) {
3216
+ // Schedule first sync with a random 12 hour time range from now.
3217
+ $start_at += rand( 0, ( WP_FS__TIME_24_HOURS_IN_SEC / 2 ) );
3218
+ }
3219
+
3220
+ // Schedule daily WP cron.
3221
+ wp_schedule_event(
3222
+ $start_at,
3223
+ 'daily',
3224
+ $this->get_action_tag( 'data_sync' )
3225
+ );
3226
+
3227
+ $this->_storage->store( 'sync_cron', (object) array(
3228
+ 'version' => $this->get_plugin_version(),
3229
+ 'sdk_version' => $this->version,
3230
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3231
+ 'on' => true,
3232
+ ) );
3233
+ }
3234
+
3235
+ /**
3236
+ * Add the actual sync function to the cron job hook.
3237
+ *
3238
+ * @author Vova Feldman (@svovaf)
3239
+ * @since 1.1.7.3
3240
+ */
3241
+ private function hook_callback_to_sync_cron() {
3242
+ $this->add_action( 'data_sync', array( &$this, '_sync_cron' ) );
3243
+ }
3244
+
3245
+ /**
3246
+ * @author Vova Feldman (@svovaf)
3247
+ * @since 1.1.7.3
3248
+ */
3249
+ private function clear_sync_cron() {
3250
+ $this->_logger->entrance();
3251
+
3252
+ if ( ! $this->is_sync_cron_on() ) {
3253
+ return;
3254
+ }
3255
+
3256
+ $this->_storage->remove( 'sync_cron' );
3257
+
3258
+ wp_clear_scheduled_hook( $this->get_action_tag( 'data_sync' ) );
3259
+ }
3260
+
3261
+ /**
3262
+ * Unix timestamp for next sync cron execution or false if not scheduled.
3263
+ *
3264
+ * @author Vova Feldman (@svovaf)
3265
+ * @since 1.1.7.3
3266
+ *
3267
+ * @return int|false
3268
+ */
3269
+ function next_sync_cron() {
3270
+ $this->_logger->entrance();
3271
+
3272
+ if ( ! $this->is_sync_cron_on() ) {
3273
+ return false;
3274
+ }
3275
+
3276
+ return wp_next_scheduled( $this->get_action_tag( 'data_sync' ) );
3277
+ }
3278
+
3279
+ /**
3280
+ * Unix timestamp for previous sync cron execution or false if never executed.
3281
+ *
3282
+ * @author Vova Feldman (@svovaf)
3283
+ * @since 1.1.7.3
3284
+ *
3285
+ * @return int|false
3286
+ */
3287
+ function last_sync_cron() {
3288
+ $this->_logger->entrance();
3289
+
3290
+ return $this->_storage->get( 'sync_timestamp' );
3291
+ }
3292
+
3293
+ #endregion Daily Sync Cron ------------------------------------------------------------------
3294
+
3295
+ #----------------------------------------------------------------------------------
3296
+ #region Async Install Sync
3297
+ #----------------------------------------------------------------------------------
3298
+
3299
+ /**
3300
+ * @author Vova Feldman (@svovaf)
3301
+ * @since 1.1.7.3
3302
+ *
3303
+ * @return bool
3304
+ */
3305
+ private function is_install_sync_scheduled() {
3306
+ /**
3307
+ * @var object $cron_data
3308
+ */
3309
+ $cron_data = $this->_storage->get( 'install_sync_cron', null );
3310
+
3311
+ return ( ! is_null( $cron_data ) && true === $cron_data->on );
3312
+ }
3313
+
3314
+ /**
3315
+ * Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
3316
+ *
3317
+ * @author Vova Feldman (@svovaf)
3318
+ * @since 1.1.7.3
3319
+ */
3320
+ private function schedule_install_sync() {
3321
+ $this->_logger->entrance();
3322
+
3323
+ $this->clear_install_sync_cron();
3324
+
3325
+ // Schedule immediate install sync.
3326
+ wp_schedule_single_event(
3327
+ WP_FS__SCRIPT_START_TIME,
3328
+ $this->get_action_tag( 'install_sync' )
3329
+ );
3330
+
3331
+ $this->_storage->store( 'install_sync_cron', (object) array(
3332
+ 'version' => $this->get_plugin_version(),
3333
+ 'sdk_version' => $this->version,
3334
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3335
+ 'on' => true,
3336
+ ) );
3337
+ }
3338
+
3339
+ /**
3340
+ * Unix timestamp for previous install sync cron execution or false if never executed.
3341
+ *
3342
+ * @todo There's some very strange bug that $this->_storage->install_sync_timestamp value is not being
3343
+ * updated. But for sure the sync event is working.
3344
+ *
3345
+ * @author Vova Feldman (@svovaf)
3346
+ * @since 1.1.7.3
3347
+ *
3348
+ * @return int|false
3349
+ */
3350
+ function last_install_sync() {
3351
+ $this->_logger->entrance();
3352
+
3353
+ return $this->_storage->get( 'install_sync_timestamp' );
3354
+ }
3355
+
3356
+ /**
3357
+ * Unix timestamp for next install sync cron execution or false if not scheduled.
3358
+ *
3359
+ * @author Vova Feldman (@svovaf)
3360
+ * @since 1.1.7.3
3361
+ *
3362
+ * @return int|false
3363
+ */
3364
+ function next_install_sync() {
3365
+ $this->_logger->entrance();
3366
+
3367
+ if ( ! $this->is_install_sync_scheduled() ) {
3368
+ return false;
3369
+ }
3370
+
3371
+ return wp_next_scheduled( $this->get_action_tag( 'install_sync' ) );
3372
+ }
3373
+
3374
+ /**
3375
+ * Add the actual install sync function to the cron job hook.
3376
+ *
3377
+ * @author Vova Feldman (@svovaf)
3378
+ * @since 1.1.7.3
3379
+ */
3380
+ private function hook_callback_to_install_sync() {
3381
+ $this->add_action( 'install_sync', array( &$this, '_run_sync_install' ) );
3382
+ }
3383
+
3384
+ /**
3385
+ * @author Vova Feldman (@svovaf)
3386
+ * @since 1.1.7.3
3387
+ */
3388
+ private function clear_install_sync_cron() {
3389
+ $this->_logger->entrance();
3390
+
3391
+ if ( ! $this->is_install_sync_scheduled() ) {
3392
+ return;
3393
+ }
3394
+
3395
+ $this->_storage->remove( 'install_sync_cron' );
3396
+
3397
+ wp_clear_scheduled_hook( $this->get_action_tag( 'install_sync' ) );
3398
+ }
3399
+
3400
+ /**
3401
+ * @author Vova Feldman (@svovaf)
3402
+ * @since 1.1.7.3
3403
+ */
3404
+ public function _run_sync_install() {
3405
+ $this->_logger->entrance();
3406
+
3407
+ // Update last install sync timestamp.
3408
+ $this->_storage->install_sync_timestamp = time();
3409
+
3410
+ $this->sync_install( array(), true );
3411
+ }
3412
+
3413
+ #endregion Async Install Sync ------------------------------------------------------------------
3414
+
3415
+ /**
3416
+ * Show a notice that activation is currently pending.
3417
+ *
3418
+ * @author Vova Feldman (@svovaf)
3419
+ * @since 1.0.7
3420
+ *
3421
+ * @param bool|string $email
3422
+ * @param bool $is_pending_trial Since 1.2.1.5
3423
+ */
3424
+ function _add_pending_activation_notice( $email = false, $is_pending_trial = false ) {
3425
+ if ( ! is_string( $email ) ) {
3426
+ $current_user = self::_get_current_wp_user();
3427
+ $email = $current_user->user_email;
3428
+ }
3429
+
3430
+ $this->_admin_notices->add_sticky(
3431
+ sprintf(
3432
+ __fs( 'pending-activation-message', $this->_slug ),
3433
+ '<b>' . $this->get_plugin_name() . '</b>',
3434
+ '<b>' . $email . '</b>',
3435
+ __fs( $is_pending_trial ? 'start-the-trial' : 'complete-the-install', $this->_slug )
3436
+ ),
3437
+ 'activation_pending',
3438
+ 'Thanks!'
3439
+ );
3440
+ }
3441
+
3442
+ /**
3443
+ * Check if currently in plugin activation.
3444
+ *
3445
+ * @author Vova Feldman (@svovaf)
3446
+ * @since 1.1.4
3447
+ *
3448
+ * @return bool
3449
+ */
3450
+ function is_plugin_activation() {
3451
+ return get_option( "fs_{$this->_slug}_activated", false );
3452
+ }
3453
+
3454
+ /**
3455
+ *
3456
+ * NOTE: admin_menu action executed before admin_init.
3457
+ *
3458
+ * @author Vova Feldman (@svovaf)
3459
+ * @since 1.0.7
3460
+ */
3461
+ function _admin_init_action() {
3462
+ /**
3463
+ * Automatically redirect to connect/activation page after plugin activation.
3464
+ *
3465
+ * @since 1.1.7 Do NOT redirect to opt-in when running in network admin mode.
3466
+ */
3467
+ if ( $this->is_plugin_activation() ) {
3468
+ delete_option( "fs_{$this->_slug}_activated" );
3469
+
3470
+ if ( ! function_exists( 'is_network_admin' ) || ! is_network_admin() ) {
3471
+ $this->_redirect_on_activation_hook();
3472
+
3473
+ return;
3474
+ }
3475
+ }
3476
+
3477
+ if ( fs_request_is_action( $this->_slug . '_skip_activation' ) ) {
3478
+ check_admin_referer( $this->_slug . '_skip_activation' );
3479
+
3480
+ $this->skip_connection();
3481
+
3482
+ fs_redirect( $this->get_after_activation_url( 'after_skip_url' ) );
3483
+ }
3484
+
3485
+ if ( ! $this->is_addon() && ! $this->is_registered() && ! $this->is_anonymous() ) {
3486
+ if ( ! $this->is_pending_activation() ) {
3487
+ if ( ! $this->_menu->is_activation_page() ) {
3488
+ if ( $this->is_plugin_new_install() || $this->is_only_premium() ) {
3489
+ // Show notice for new plugin installations.
3490
+ $this->_admin_notices->add(
3491
+ sprintf(
3492
+ __fs( 'you-are-step-away', $this->_slug ),
3493
+ sprintf( '<b><a href="%s">%s</a></b>',
3494
+ $this->get_activation_url(),
3495
+ sprintf( __fs( 'activate-x-now', $this->_slug ), $this->get_plugin_name() )
3496
+ )
3497
+ ),
3498
+ '',
3499
+ 'update-nag'
3500
+ );
3501
+ } else {
3502
+ if ( ! isset( $this->_storage->sticky_optin_added ) ) {
3503
+ $this->_storage->sticky_optin_added = true;
3504
+
3505
+ // Show notice for new plugin installations.
3506
+ $this->_admin_notices->add_sticky(
3507
+ sprintf(
3508
+ __fs( 'few-plugin-tweaks', $this->_slug ),
3509
+ sprintf( '<b><a href="%s">%s</a></b>',
3510
+ $this->get_activation_url(),
3511
+ sprintf( __fs( 'optin-x-now', $this->_slug ), $this->get_plugin_name() )
3512
+ )
3513
+ ),
3514
+ 'connect_account',
3515
+ '',
3516
+ 'update-nag'
3517
+ );
3518
+ }
3519
+
3520
+ if ( $this->has_filter( 'optin_pointer_element' ) ) {
3521
+ // Don't show admin nag if plugin update.
3522
+ wp_enqueue_script( 'wp-pointer' );
3523
+ wp_enqueue_style( 'wp-pointer' );
3524
+
3525
+ $this->_enqueue_connect_essentials();
3526
+
3527
+ add_action( 'admin_print_footer_scripts', array(
3528
+ $this,
3529
+ '_add_connect_pointer_script'
3530
+ ) );
3531
+ }
3532
+
3533
+ }
3534
+ }
3535
+ }
3536
+ }
3537
+
3538
+ $this->_add_upgrade_action_link();
3539
+ }
3540
+
3541
+ /**
3542
+ * Enqueue connect requires scripts and styles.
3543
+ *
3544
+ * @author Vova Feldman (@svovaf)
3545
+ * @since 1.1.4
3546
+ */
3547
+ function _enqueue_connect_essentials() {
3548
+ wp_enqueue_script( 'jquery' );
3549
+ wp_enqueue_script( 'json2' );
3550
+
3551
+ fs_enqueue_local_script( 'postmessage', 'nojquery.ba-postmessage.min.js' );
3552
+ fs_enqueue_local_script( 'fs-postmessage', 'postmessage.js' );
3553
+
3554
+ fs_enqueue_local_style( 'fs_connect', '/admin/connect.css' );
3555
+ }
3556
+
3557
+ /**
3558
+ * Add connect / opt-in pointer.
3559
+ *
3560
+ * @author Vova Feldman (@svovaf)
3561
+ * @since 1.1.4
3562
+ */
3563
+ function _add_connect_pointer_script() {
3564
+ $vars = array( 'slug' => $this->_slug );
3565
+ $pointer_content = fs_get_template( 'connect.php', $vars );
3566
+ ?>
3567
+ <script type="text/javascript">// <![CDATA[
3568
+ jQuery(document).ready(function ($) {
3569
+ if ('undefined' !== typeof(jQuery().pointer)) {
3570
+
3571
+ var element = <?php echo $this->apply_filters( 'optin_pointer_element', '$("#non_existing_element");' ) ?>;
3572
+
3573
+ if (element.length > 0) {
3574
+ var optin = $(element).pointer($.extend(true, {}, {
3575
+ content : <?php echo json_encode( $pointer_content ) ?>,
3576
+ position : {
3577
+ edge : 'left',
3578
+ align: 'center'
3579
+ },
3580
+ buttons : function () {
3581
+ // Don't show pointer buttons.
3582
+ return '';
3583
+ },
3584
+ pointerWidth: 482
3585
+ }, <?php echo $this->apply_filters( 'optin_pointer_options_json', '{}' ) ?>));
3586
+
3587
+ <?php
3588
+ echo $this->apply_filters( 'optin_pointer_execute', "
3589
+
3590
+ optin.pointer('open');
3591
+
3592
+ // Tag the opt-in pointer with custom class.
3593
+ $('.wp-pointer #fs_connect')
3594
+ .parents('.wp-pointer.wp-pointer-top')
3595
+ .addClass('fs-opt-in-pointer');
3596
+
3597
+ ", 'element', 'optin' ) ?>
3598
+ }
3599
+ }
3600
+ });
3601
+ // ]]></script>
3602
+ <?php
3603
+ }
3604
+
3605
+ /**
3606
+ * Return current page's URL.
3607
+ *
3608
+ * @author Vova Feldman (@svovaf)
3609
+ * @since 1.0.7
3610
+ *
3611
+ * @return string
3612
+ */
3613
+ function current_page_url() {
3614
+ $url = 'http';
3615
+
3616
+ if ( isset( $_SERVER["HTTPS"] ) ) {
3617
+ if ( $_SERVER["HTTPS"] == "on" ) {
3618
+ $url .= "s";
3619
+ }
3620
+ }
3621
+ $url .= "://";
3622
+ if ( $_SERVER["SERVER_PORT"] != "80" ) {
3623
+ $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
3624
+ } else {
3625
+ $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
3626
+ }
3627
+
3628
+ return esc_url( $url );
3629
+ }
3630
+
3631
+ /**
3632
+ * Check if the current page is the plugin's main admin settings page.
3633
+ *
3634
+ * @author Vova Feldman (@svovaf)
3635
+ * @since 1.0.7
3636
+ *
3637
+ * @return bool
3638
+ */
3639
+ function _is_plugin_page() {
3640
+ return fs_is_plugin_page( $this->_menu->get_raw_slug() ) ||
3641
+ fs_is_plugin_page( $this->_slug );
3642
+ }
3643
+
3644
+ /* Events
3645
+ ------------------------------------------------------------------------------------------------------------------*/
3646
+ /**
3647
+ * Delete site install from Database.
3648
+ *
3649
+ * @author Vova Feldman (@svovaf)
3650
+ * @since 1.0.1
3651
+ *
3652
+ * @param bool $store
3653
+ */
3654
+ function _delete_site( $store = true ) {
3655
+ $sites = self::get_all_sites();
3656
+
3657
+ if ( isset( $sites[ $this->_slug ] ) ) {
3658
+ unset( $sites[ $this->_slug ] );
3659
+ }
3660
+
3661
+ self::$_accounts->set_option( 'sites', $sites, $store );
3662
+ }
3663
+
3664
+ /**
3665
+ * Delete plugin's plans information.
3666
+ *
3667
+ * @param bool $store Flush to Database if true.
3668
+ *
3669
+ * @author Vova Feldman (@svovaf)
3670
+ * @since 1.0.9
3671
+ */
3672
+ private function _delete_plans( $store = true ) {
3673
+ $this->_logger->entrance();
3674
+
3675
+ $plans = self::get_all_plans();
3676
+
3677
+ unset( $plans[ $this->_slug ] );
3678
+
3679
+ self::$_accounts->set_option( 'plans', $plans, $store );
3680
+ }
3681
+
3682
+ /**
3683
+ * Delete all plugin licenses.
3684
+ *
3685
+ * @author Vova Feldman (@svovaf)
3686
+ * @since 1.0.9
3687
+ *
3688
+ * @param bool $store
3689
+ * @param string|bool $plugin_slug
3690
+ */
3691
+ private function _delete_licenses( $store = true, $plugin_slug = false ) {
3692
+ $this->_logger->entrance();
3693
+
3694
+ $all_licenses = self::get_all_licenses();
3695
+
3696
+ if ( ! is_string( $plugin_slug ) ) {
3697
+ $plugin_slug = $this->_slug;
3698
+ }
3699
+
3700
+ unset( $all_licenses[ $plugin_slug ] );
3701
+
3702
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
3703
+ }
3704
+
3705
+ /**
3706
+ * Check if Freemius was added on new plugin installation.
3707
+ *
3708
+ * @author Vova Feldman (@svovaf)
3709
+ * @since 1.1.5
3710
+ *
3711
+ * @return bool
3712
+ */
3713
+ function is_plugin_new_install() {
3714
+ return isset( $this->_storage->is_plugin_new_install ) &&
3715
+ $this->_storage->is_plugin_new_install;
3716
+ }
3717
+
3718
+ /**
3719
+ * Check if it's the first plugin release that is running Freemius.
3720
+ *
3721
+ * @author Vova Feldman (@svovaf)
3722
+ * @since 1.2.1.5
3723
+ *
3724
+ * @return bool
3725
+ */
3726
+ function is_first_freemius_powered_version() {
3727
+ return empty( $this->_storage->plugin_last_version );
3728
+ }
3729
+
3730
+ /**
3731
+ * Plugin activated hook.
3732
+ *
3733
+ * @author Vova Feldman (@svovaf)
3734
+ * @since 1.0.1
3735
+ *
3736
+ * @uses FS_Api
3737
+ */
3738
+ function _activate_plugin_event_hook() {
3739
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3740
+
3741
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3742
+ return;
3743
+ }
3744
+
3745
+ $this->unregister_uninstall_hook();
3746
+
3747
+ // Clear API cache on activation.
3748
+ FS_Api::clear_cache();
3749
+
3750
+ if ( $this->is_registered() ) {
3751
+ $this->reconnect_locally();
3752
+
3753
+ // Schedule re-activation event and sync.
3754
+ // $this->sync_install( array(), true );
3755
+ $this->schedule_install_sync();
3756
+
3757
+ $is_premium_version_activation = ( current_filter() !== ( 'activate_' . $this->_free_plugin_basename ) );
3758
+
3759
+ // 1. If running in the activation of the FREE module, get the basename of the PREMIUM.
3760
+ // 2. If running in the activation of the PREMIUM module, get the basename of the FREE.
3761
+ $other_version_basename = $is_premium_version_activation ?
3762
+ $this->_free_plugin_basename :
3763
+ $this->premium_plugin_basename();
3764
+
3765
+ /**
3766
+ * If the other module version is activate, deactivate it.
3767
+ *
3768
+ * @author Leo Fajardo (@leorw)
3769
+ * @since 1.2.2
3770
+ */
3771
+ if ( is_plugin_active( $other_version_basename ) ) {
3772
+ deactivate_plugins( $other_version_basename );
3773
+ }
3774
+
3775
+ // If activating the premium module version, add an admin noitce to congratulate for an upgrade completion.
3776
+ if ( $is_premium_version_activation ) {
3777
+ $this->_admin_notices->add(
3778
+ sprintf( __fs( 'successful-version-upgrade-message', $this->_slug ), sprintf( '<b>%s</b>', $this->_plugin->title ) ),
3779
+ __fs( 'woot', $this->_slug ) . '!'
3780
+ );
3781
+ }
3782
+ } else if ( $this->is_anonymous() ) {
3783
+ /**
3784
+ * Reset "skipped" click cache on the following:
3785
+ * 1. Development mode.
3786
+ * 2. If the user skipped the exact same version before.
3787
+ *
3788
+ * @todo 3. If explicitly asked to retry after every activation.
3789
+ */
3790
+ if ( WP_FS__DEV_MODE ||
3791
+ $this->get_plugin_version() == $this->_storage->is_anonymous['version']
3792
+ ) {
3793
+ $this->reset_anonymous_mode();
3794
+ }
3795
+ }
3796
+
3797
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3798
+ /**
3799
+ * If no previous version of plugin's version exist, it means that it's either
3800
+ * the first time that the plugin installed on the site, or the plugin was installed
3801
+ * before but didn't have Freemius integrated.
3802
+ *
3803
+ * Since register_activation_hook() do NOT fires on updates since 3.1, and only fires
3804
+ * on manual activation via the dashboard, is_plugin_activation() is TRUE
3805
+ * only after immediate activation.
3806
+ *
3807
+ * @since 1.1.4
3808
+ * @link https://make.wordpress.org/core/2010/10/27/plugin-activation-hooks-no-longer-fire-for-updates/
3809
+ */
3810
+ $this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
3811
+ }
3812
+
3813
+ if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
3814
+ // Store hint that the plugin was just activated to enable auto-redirection to settings.
3815
+ add_option( "fs_{$this->_slug}_activated", true );
3816
+ }
3817
+
3818
+ /**
3819
+ * Activation hook is executed after the plugin's main file is loaded, therefore,
3820
+ * after the plugin was loaded. The logic is located at activate_plugin()
3821
+ * ./wp-admin/includes/plugin.php.
3822
+ *
3823
+ * @author Vova Feldman (@svovaf)
3824
+ * @since 1.1.9
3825
+ */
3826
+ $this->_storage->was_plugin_loaded = true;
3827
+ }
3828
+
3829
+ /**
3830
+ * Delete account.
3831
+ *
3832
+ * @author Vova Feldman (@svovaf)
3833
+ * @since 1.0.3
3834
+ *
3835
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
3836
+ */
3837
+ function delete_account_event( $check_user = true ) {
3838
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3839
+
3840
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
3841
+ return;
3842
+ }
3843
+
3844
+ $this->do_action( 'before_account_delete' );
3845
+
3846
+ // Clear all admin notices.
3847
+ $this->_admin_notices->clear_all_sticky();
3848
+
3849
+ $this->_delete_site( false );
3850
+
3851
+ $this->_delete_plans( false );
3852
+
3853
+ $this->_delete_licenses( false );
3854
+
3855
+ // Delete add-ons related to plugin's account.
3856
+ $this->_delete_account_addons( false );
3857
+
3858
+ // @todo Delete plans and licenses of add-ons.
3859
+
3860
+ self::$_accounts->store();
3861
+
3862
+ /**
3863
+ * IMPORTANT:
3864
+ * Clear crons must be executed before clearing all storage.
3865
+ * Otherwise, the cron will not be cleared.
3866
+ */
3867
+ $this->clear_sync_cron();
3868
+ $this->clear_install_sync_cron();
3869
+
3870
+ // Clear all storage data.
3871
+ $this->_storage->clear_all( true, array(
3872
+ 'connectivity_test',
3873
+ 'is_on',
3874
+ ) );
3875
+
3876
+ // Send delete event.
3877
+ $this->get_api_site_scope()->call( '/', 'delete' );
3878
+
3879
+ $this->do_action( 'after_account_delete' );
3880
+ }
3881
+
3882
+ /**
3883
+ * Plugin deactivation hook.
3884
+ *
3885
+ * @author Vova Feldman (@svovaf)
3886
+ * @since 1.0.1
3887
+ */
3888
+ function _deactivate_plugin_hook() {
3889
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
3890
+
3891
+ if ( ! current_user_can( 'activate_plugins' ) ) {
3892
+ return;
3893
+ }
3894
+
3895
+ $this->_admin_notices->clear_all_sticky();
3896
+ if ( isset( $this->_storage->sticky_optin_added ) ) {
3897
+ unset( $this->_storage->sticky_optin_added );
3898
+ }
3899
+
3900
+ if ( ! isset( $this->_storage->is_plugin_new_install ) ) {
3901
+ // Remember that plugin was already installed.
3902
+ $this->_storage->is_plugin_new_install = false;
3903
+ }
3904
+
3905
+ // Hook to plugin uninstall.
3906
+ register_uninstall_hook( $this->_plugin_main_file_path, array( 'Freemius', '_uninstall_plugin_hook' ) );
3907
+
3908
+ $this->clear_module_main_file_cache();
3909
+ $this->clear_sync_cron();
3910
+ $this->clear_install_sync_cron();
3911
+
3912
+ if ( $this->is_registered() ) {
3913
+ // Send deactivation event.
3914
+ $this->sync_install( array(
3915
+ 'is_active' => false,
3916
+ ) );
3917
+ } else {
3918
+ if ( ! $this->has_api_connectivity() ) {
3919
+ // Reset connectivity test cache.
3920
+ unset( $this->_storage->connectivity_test );
3921
+ }
3922
+ }
3923
+
3924
+ // Clear API cache on deactivation.
3925
+ FS_Api::clear_cache();
3926
+
3927
+ $this->remove_sdk_reference();
3928
+ }
3929
+
3930
+ /**
3931
+ * @author Vova Feldman (@svovaf)
3932
+ * @since 1.1.6
3933
+ */
3934
+ private function remove_sdk_reference() {
3935
+ global $fs_active_plugins;
3936
+
3937
+ foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
3938
+ if ( $this->_plugin_basename == $data->plugin_path ) {
3939
+ unset( $fs_active_plugins->plugins[ $sdk_path ] );
3940
+ break;
3941
+ }
3942
+ }
3943
+
3944
+ fs_fallback_to_newest_active_sdk();
3945
+ }
3946
+
3947
+ /**
3948
+ * @author Vova Feldman (@svovaf)
3949
+ * @since 1.1.3
3950
+ *
3951
+ * @param bool $is_anonymous
3952
+ */
3953
+ private function set_anonymous_mode( $is_anonymous = true ) {
3954
+ // Store information regarding skip to try and opt-in the user
3955
+ // again in the future.
3956
+ $this->_storage->is_anonymous = array(
3957
+ 'is' => $is_anonymous,
3958
+ 'timestamp' => WP_FS__SCRIPT_START_TIME,
3959
+ 'version' => $this->get_plugin_version(),
3960
+ );
3961
+
3962
+ // Update anonymous mode cache.
3963
+ $this->_is_anonymous = $is_anonymous;
3964
+ }
3965
+
3966
+ /**
3967
+ * @author Vova Feldman (@svovaf)
3968
+ * @since 1.1.3
3969
+ */
3970
+ private function reset_anonymous_mode() {
3971
+ unset( $this->_storage->is_anonymous );
3972
+ }
3973
+
3974
+ /**
3975
+ * Clears the anonymous mode and redirects to the opt-in screen.
3976
+ *
3977
+ * @author Vova Feldman (@svovaf)
3978
+ * @since 1.1.7
3979
+ */
3980
+ function connect_again() {
3981
+ if ( ! $this->is_anonymous() ) {
3982
+ return;
3983
+ }
3984
+
3985
+ $this->reset_anonymous_mode();
3986
+
3987
+ fs_redirect( $this->get_activation_url() );
3988
+ }
3989
+
3990
+ /**
3991
+ * Skip account connect, and set anonymous mode.
3992
+ *
3993
+ * @author Vova Feldman (@svovaf)
3994
+ * @since 1.1.1
3995
+ */
3996
+ private function skip_connection() {
3997
+ $this->_logger->entrance();
3998
+
3999
+ $this->_admin_notices->remove_sticky( 'connect_account' );
4000
+
4001
+ $this->set_anonymous_mode();
4002
+
4003
+ // Send anonymous skip event.
4004
+ // No user identified info nor any tracking will be sent after the user skips the opt-in.
4005
+ $this->get_api_plugin_scope()->call( 'skip.json', 'put', array(
4006
+ 'uid' => $this->get_anonymous_id(),
4007
+ ) );
4008
+ }
4009
+
4010
+ /**
4011
+ * Plugin version update hook.
4012
+ *
4013
+ * @author Vova Feldman (@svovaf)
4014
+ * @since 1.0.4
4015
+ */
4016
+ private function update_plugin_version_event() {
4017
+ $this->_logger->entrance();
4018
+
4019
+ if ( ! $this->is_registered() ) {
4020
+ return;
4021
+ }
4022
+
4023
+ $this->schedule_install_sync();
4024
+ // $this->sync_install( array(), true );
4025
+ }
4026
+
4027
+ /**
4028
+ * Return a list of modified plugins since the last sync.
4029
+ *
4030
+ * Note:
4031
+ * There's no point to store a plugins counter since even if the number of
4032
+ * plugins didn't change, we still need to check if the versions are all the
4033
+ * same and the activity state is similar.
4034
+ *
4035
+ * @author Vova Feldman (@svovaf)
4036
+ * @since 1.1.8
4037
+ *
4038
+ * @return array|false
4039
+ */
4040
+ private function get_plugins_data_for_api() {
4041
+ // Alias.
4042
+ $option_name = 'all_plugins';
4043
+
4044
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
4045
+
4046
+ if ( ! is_object( $all_cached_plugins ) ) {
4047
+ $all_cached_plugins = (object) array(
4048
+ 'timestamp' => '',
4049
+ 'md5' => '',
4050
+ 'plugins' => array(),
4051
+ );
4052
+ }
4053
+
4054
+ $time = time();
4055
+
4056
+ if ( ! empty( $all_cached_plugins->timestamp ) &&
4057
+ ( $time - $all_cached_plugins->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
4058
+ ) {
4059
+ // Don't send plugin updates if last update was in the past 5 min.
4060
+ return false;
4061
+ }
4062
+
4063
+ // Write timestamp to lock the logic.
4064
+ $all_cached_plugins->timestamp = $time;
4065
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
4066
+
4067
+ // Reload options from DB.
4068
+ self::$_accounts->load( true );
4069
+ $all_cached_plugins = self::$_accounts->get_option( $option_name );
4070
+
4071
+ if ( $time != $all_cached_plugins->timestamp ) {
4072
+ // If timestamp is different, then another thread captured the lock.
4073
+ return false;
4074
+ }
4075
+
4076
+ // Check if there's a change in plugins.
4077
+ $all_plugins = self::get_all_plugins();
4078
+
4079
+ // Check if plugins changed.
4080
+ ksort( $all_plugins );
4081
+
4082
+ $plugins_signature = '';
4083
+ foreach ( $all_plugins as $basename => $data ) {
4084
+ $plugins_signature .= $data['slug'] . ',' .
4085
+ $data['Version'] . ',' .
4086
+ ( $data['is_active'] ? '1' : '0' ) . ';';
4087
+ }
4088
+
4089
+ // Check if plugins status changed (version or active/inactive).
4090
+ $plugins_changed = ( $all_cached_plugins->md5 !== md5( $plugins_signature ) );
4091
+
4092
+ $plugins_update_data = array();
4093
+
4094
+ if ( $plugins_changed ) {
4095
+ // Change in plugins, report changes.
4096
+
4097
+ // Update existing plugins info.
4098
+ foreach ( $all_cached_plugins->plugins as $basename => $data ) {
4099
+ if ( ! isset( $all_plugins[ $basename ] ) ) {
4100
+ // Plugin uninstalled.
4101
+ $uninstalled_plugin_data = $data;
4102
+ $uninstalled_plugin_data['is_active'] = false;
4103
+ $uninstalled_plugin_data['is_uninstalled'] = true;
4104
+ $plugins_update_data[] = $uninstalled_plugin_data;
4105
+
4106
+ unset( $all_plugins[ $basename ] );
4107
+ unset( $all_cached_plugins->plugins[ $basename ] );
4108
+ } else if ( $data['is_active'] !== $all_plugins[ $basename ]['is_active'] ||
4109
+ $data['version'] !== $all_plugins[ $basename ]['Version']
4110
+ ) {
4111
+ // Plugin activated or deactivated, or version changed.
4112
+ $all_cached_plugins->plugins[ $basename ]['is_active'] = $all_plugins[ $basename ]['is_active'];
4113
+ $all_cached_plugins->plugins[ $basename ]['version'] = $all_plugins[ $basename ]['Version'];
4114
+
4115
+ $plugins_update_data[] = $all_cached_plugins->plugins[ $basename ];
4116
+ }
4117
+ }
4118
+
4119
+ // Find new plugins that weren't yet seen before.
4120
+ foreach ( $all_plugins as $basename => $data ) {
4121
+ if ( ! isset( $all_cached_plugins->plugins[ $basename ] ) ) {
4122
+ // New plugin.
4123
+ $new_plugin = array(
4124
+ 'slug' => $data['slug'],
4125
+ 'version' => $data['Version'],
4126
+ 'title' => $data['Name'],
4127
+ 'is_active' => $data['is_active'],
4128
+ 'is_uninstalled' => false,
4129
+ );
4130
+
4131
+ $plugins_update_data[] = $new_plugin;
4132
+ $all_cached_plugins->plugins[ $basename ] = $new_plugin;
4133
+ }
4134
+ }
4135
+
4136
+ $all_cached_plugins->md5 = md5( $plugins_signature );
4137
+ $all_cached_plugins->timestamp = $time;
4138
+ self::$_accounts->set_option( $option_name, $all_cached_plugins, true );
4139
+ }
4140
+
4141
+ return $plugins_update_data;
4142
+ }
4143
+
4144
+ /**
4145
+ * Return a list of modified themes since the last sync.
4146
+ *
4147
+ * Note:
4148
+ * There's no point to store a themes counter since even if the number of
4149
+ * themes didn't change, we still need to check if the versions are all the
4150
+ * same and the activity state is similar.
4151
+ *
4152
+ * @author Vova Feldman (@svovaf)
4153
+ * @since 1.1.8
4154
+ *
4155
+ * @return array|false
4156
+ */
4157
+ private function get_themes_data_for_api() {
4158
+ // Alias.
4159
+ $option_name = 'all_themes';
4160
+
4161
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
4162
+
4163
+ if ( ! is_object( $all_cached_themes ) ) {
4164
+ $all_cached_themes = (object) array(
4165
+ 'timestamp' => '',
4166
+ 'md5' => '',
4167
+ 'themes' => array(),
4168
+ );
4169
+ }
4170
+
4171
+ $time = time();
4172
+
4173
+ if ( ! empty( $all_cached_themes->timestamp ) &&
4174
+ ( $time - $all_cached_themes->timestamp ) < WP_FS__TIME_5_MIN_IN_SEC
4175
+ ) {
4176
+ // Don't send theme updates if last update was in the past 5 min.
4177
+ return false;
4178
+ }
4179
+
4180
+ // Write timestamp to lock the logic.
4181
+ $all_cached_themes->timestamp = $time;
4182
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
4183
+
4184
+ // Reload options from DB.
4185
+ self::$_accounts->load( true );
4186
+ $all_cached_themes = self::$_accounts->get_option( $option_name );
4187
+
4188
+ if ( $time != $all_cached_themes->timestamp ) {
4189
+ // If timestamp is different, then another thread captured the lock.
4190
+ return false;
4191
+ }
4192
+
4193
+ // Get active theme.
4194
+ $active_theme = wp_get_theme();
4195
+ $active_theme_stylesheet = $active_theme->get_stylesheet();
4196
+
4197
+ // Check if there's a change in themes.
4198
+ $all_themes = wp_get_themes();
4199
+
4200
+ // Check if themes changed.
4201
+ ksort( $all_themes );
4202
+
4203
+ $themes_signature = '';
4204
+ foreach ( $all_themes as $slug => $data ) {
4205
+ $is_active = ( $slug === $active_theme_stylesheet );
4206
+ $themes_signature .= $slug . ',' .
4207
+ $data->version . ',' .
4208
+ ( $is_active ? '1' : '0' ) . ';';
4209
+ }
4210
+
4211
+ // Check if themes status changed (version or active/inactive).
4212
+ $themes_changed = ( $all_cached_themes->md5 !== md5( $themes_signature ) );
4213
+
4214
+ $themes_update_data = array();
4215
+
4216
+ if ( $themes_changed ) {
4217
+ // Change in themes, report changes.
4218
+
4219
+ // Update existing themes info.
4220
+ foreach ( $all_cached_themes->themes as $slug => $data ) {
4221
+ $is_active = ( $slug === $active_theme_stylesheet );
4222
+
4223
+ if ( ! isset( $all_themes[ $slug ] ) ) {
4224
+ // Plugin uninstalled.
4225
+ $uninstalled_theme_data = $data;
4226
+ $uninstalled_theme_data['is_active'] = false;
4227
+ $uninstalled_theme_data['is_uninstalled'] = true;
4228
+ $themes_update_data[] = $uninstalled_theme_data;
4229
+
4230
+ unset( $all_themes[ $slug ] );
4231
+ unset( $all_cached_themes->themes[ $slug ] );
4232
+ } else if ( $data['is_active'] !== $is_active ||
4233
+ $data['version'] !== $all_themes[ $slug ]->version
4234
+ ) {
4235
+ // Plugin activated or deactivated, or version changed.
4236
+
4237
+ $all_cached_themes->themes[ $slug ]['is_active'] = $is_active;
4238
+ $all_cached_themes->themes[ $slug ]['version'] = $all_themes[ $slug ]->version;
4239
+
4240
+ $themes_update_data[] = $all_cached_themes->themes[ $slug ];
4241
+ }
4242
+ }
4243
+
4244
+ // Find new themes that weren't yet seen before.
4245
+ foreach ( $all_themes as $slug => $data ) {
4246
+ if ( ! isset( $all_cached_themes->themes[ $slug ] ) ) {
4247
+ $is_active = ( $slug === $active_theme_stylesheet );
4248
+
4249
+ // New plugin.
4250
+ $new_plugin = array(
4251
+ 'slug' => $slug,
4252
+ 'version' => $data->version,
4253
+ 'title' => $data->name,
4254
+ 'is_active' => $is_active,
4255
+ 'is_uninstalled' => false,
4256
+ );
4257
+
4258
+ $themes_update_data[] = $new_plugin;
4259
+ $all_cached_themes->themes[ $slug ] = $new_plugin;
4260
+ }
4261
+ }
4262
+
4263
+ $all_cached_themes->md5 = md5( $themes_signature );
4264
+ $all_cached_themes->timestamp = time();
4265
+ self::$_accounts->set_option( $option_name, $all_cached_themes, true );
4266
+ }
4267
+
4268
+ return $themes_update_data;
4269
+ }
4270
+
4271
+ /**
4272
+ * Update install details.
4273
+ *
4274
+ * @author Vova Feldman (@svovaf)
4275
+ * @since 1.1.2
4276
+ *
4277
+ * @param string[] string $override
4278
+ * @param bool $include_plugins Since 1.1.8 by default include plugin changes.
4279
+ * @param bool $include_themes Since 1.1.8 by default include plugin changes.
4280
+ *
4281
+ * @return array
4282
+ */
4283
+ private function get_install_data_for_api(
4284
+ array $override,
4285
+ $include_plugins = true,
4286
+ $include_themes = true
4287
+ ) {
4288
+ /**
4289
+ * @since 1.1.8 Also send plugin updates.
4290
+ */
4291
+ if ( $include_plugins && ! isset( $override['plugins'] ) ) {
4292
+ $plugins = $this->get_plugins_data_for_api();
4293
+ if ( ! empty( $plugins ) ) {
4294
+ $override['plugins'] = $plugins;
4295
+ }
4296
+ }
4297
+ /**
4298
+ * @since 1.1.8 Also send themes updates.
4299
+ */
4300
+ if ( $include_themes && ! isset( $override['themes'] ) ) {
4301
+ $themes = $this->get_themes_data_for_api();
4302
+ if ( ! empty( $themes ) ) {
4303
+ $override['themes'] = $themes;
4304
+ }
4305
+ }
4306
+
4307
+ return array_merge( array(
4308
+ 'version' => $this->get_plugin_version(),
4309
+ 'is_premium' => $this->is_premium(),
4310
+ 'language' => get_bloginfo( 'language' ),
4311
+ 'charset' => get_bloginfo( 'charset' ),
4312
+ 'platform_version' => get_bloginfo( 'version' ),
4313
+ 'sdk_version' => $this->version,
4314
+ 'programming_language_version' => phpversion(),
4315
+ 'title' => get_bloginfo( 'name' ),
4316
+ 'url' => get_site_url(),
4317
+ // Special params.
4318
+ 'is_active' => true,
4319
+ 'is_disconnected' => $this->is_tracking_prohibited(),
4320
+ 'is_uninstalled' => false,
4321
+ ), $override );
4322
+ }
4323
+
4324
+ /**
4325
+ * Update install only if changed.
4326
+ *
4327
+ * @author Vova Feldman (@svovaf)
4328
+ * @since 1.0.9
4329
+ *
4330
+ * @param string[] string $override
4331
+ * @param bool $flush
4332
+ *
4333
+ * @return false|object|string
4334
+ */
4335
+ private function send_install_update( $override = array(), $flush = false ) {
4336
+ $this->_logger->entrance();
4337
+
4338
+ $check_properties = $this->get_install_data_for_api( $override );
4339
+
4340
+ if ( $flush ) {
4341
+ $params = $check_properties;
4342
+ } else {
4343
+ $params = array();
4344
+ $special = array();
4345
+ $special_override = false;
4346
+
4347
+ foreach ( $check_properties as $p => $v ) {
4348
+ if ( property_exists( $this->_site, $p ) ) {
4349
+ if ( ( is_bool( $this->_site->{$p} ) || ! empty( $this->_site->{$p} ) ) &&
4350
+ $this->_site->{$p} != $v
4351
+ ) {
4352
+ $this->_site->{$p} = $v;
4353
+ $params[ $p ] = $v;
4354
+ }
4355
+ } else {
4356
+ $special[ $p ] = $v;
4357
+
4358
+ if ( isset( $override[ $p ] ) ||
4359
+ 'plugins' === $p ||
4360
+ 'themes' === $p
4361
+ ) {
4362
+ $special_override = true;
4363
+ }
4364
+ }
4365
+ }
4366
+
4367
+ if ( $special_override || 0 < count( $params ) ) {
4368
+ // Add special params only if has at least one
4369
+ // standard param, or if explicitly requested to
4370
+ // override a special param or a param which is not exist
4371
+ // in the install object.
4372
+ $params = array_merge( $params, $special );
4373
+ }
4374
+ }
4375
+
4376
+ if ( 0 < count( $params ) ) {
4377
+ // Update last install sync timestamp.
4378
+ $this->_storage->install_sync_timestamp = time();
4379
+
4380
+ $params['uid'] = $this->get_anonymous_id();
4381
+
4382
+ // Send updated values to FS.
4383
+ $site = $this->get_api_site_scope()->call( '/', 'put', $params );
4384
+
4385
+ if ( $this->is_api_result_entity( $site ) ) {
4386
+ // I successfully sent install update, clear scheduled sync if exist.
4387
+ $this->clear_install_sync_cron();
4388
+ }
4389
+
4390
+ return $site;
4391
+ }
4392
+
4393
+ return false;
4394
+ }
4395
+
4396
+ /**
4397
+ * Update install only if changed.
4398
+ *
4399
+ * @author Vova Feldman (@svovaf)
4400
+ * @since 1.0.9
4401
+ *
4402
+ * @param string[] string $override
4403
+ * @param bool $flush
4404
+ */
4405
+ private function sync_install( $override = array(), $flush = false ) {
4406
+ $this->_logger->entrance();
4407
+
4408
+ $site = $this->send_install_update( $override, $flush );
4409
+
4410
+ if ( false === $site ) {
4411
+ // No sync required.
4412
+ return;
4413
+ }
4414
+
4415
+ if ( ! $this->is_api_result_entity( $site ) ) {
4416
+ // Failed to sync, don't update locally.
4417
+ return;
4418
+ }
4419
+
4420
+ $plan = $this->get_plan();
4421
+ $this->_site = new FS_Site( $site );
4422
+ $this->_site->plan = $plan;
4423
+
4424
+ $this->_store_site( true );
4425
+ }
4426
+
4427
+ /**
4428
+ * Track install's custom event.
4429
+ *
4430
+ * IMPORTANT:
4431
+ * Custom event tracking is currently only supported for specific clients.
4432
+ * If you are not one of them, please don't use this method. If you will,
4433
+ * the API will simply ignore your request based on the plugin ID.
4434
+ *
4435
+ * Need custom tracking for your plugin or theme?
4436
+ * If you are interested in custom event tracking please contact yo@freemius.com
4437
+ * for further details.
4438
+ *
4439
+ * @author Vova Feldman (@svovaf)
4440
+ * @since 1.2.1
4441
+ *
4442
+ * @param string $name Event name.
4443
+ * @param array $properties Associative key/value array with primitive values only
4444
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
4445
+ * @param bool $once If true, event will be tracked only once. IMPORTANT: Still trigger the API call.
4446
+ *
4447
+ * @return object|false Event data or FALSE on failure.
4448
+ *
4449
+ * @throws \Freemius_InvalidArgumentException
4450
+ */
4451
+ public function track_event( $name, $properties = array(), $process_at = false, $once = false ) {
4452
+ $this->_logger->entrance( http_build_query( array( 'name' => $name, 'once' => $once ) ) );
4453
+
4454
+ if ( ! $this->is_registered() ) {
4455
+ return false;
4456
+ }
4457
+
4458
+ $event = array( 'type' => $name );
4459
+
4460
+ if ( is_numeric( $process_at ) && $process_at > time() ) {
4461
+ $event['process_at'] = $process_at;
4462
+ }
4463
+
4464
+ if ( $once ) {
4465
+ $event['once'] = true;
4466
+ }
4467
+
4468
+ if ( ! empty( $properties ) ) {
4469
+ // Verify associative array values are primitive.
4470
+ foreach ( $properties as $k => $v ) {
4471
+ if ( ! is_scalar( $v ) ) {
4472
+ throw new Freemius_InvalidArgumentException( 'The $properties argument must be an associative key/value array with primitive values only.' );
4473
+ }
4474
+ }
4475
+
4476
+ $event['properties'] = $properties;
4477
+ }
4478
+
4479
+ $result = $this->get_api_site_scope()->call( 'events.json', 'post', $event );
4480
+
4481
+ return $this->is_api_error( $result ) ?
4482
+ false :
4483
+ $result;
4484
+ }
4485
+
4486
+ /**
4487
+ * Track install's custom event only once, but it still triggers the API call.
4488
+ *
4489
+ * IMPORTANT:
4490
+ * Custom event tracking is currently only supported for specific clients.
4491
+ * If you are not one of them, please don't use this method. If you will,
4492
+ * the API will simply ignore your request based on the plugin ID.
4493
+ *
4494
+ * Need custom tracking for your plugin or theme?
4495
+ * If you are interested in custom event tracking please contact yo@freemius.com
4496
+ * for further details.
4497
+ *
4498
+ * @author Vova Feldman (@svovaf)
4499
+ * @since 1.2.1
4500
+ *
4501
+ * @param string $name Event name.
4502
+ * @param array $properties Associative key/value array with primitive values only
4503
+ * @param bool $process_at A valid future date-time in the following format Y-m-d H:i:s.
4504
+ *
4505
+ * @return object|false Event data or FALSE on failure.
4506
+ *
4507
+ * @throws \Freemius_InvalidArgumentException
4508
+ *
4509
+ * @user Freemius::track_event()
4510
+ */
4511
+ public function track_event_once( $name, $properties = array(), $process_at = false ) {
4512
+ return $this->track_event( $name, $properties, $process_at, true );
4513
+ }
4514
+
4515
+ /**
4516
+ * Plugin uninstall hook.
4517
+ *
4518
+ * @author Vova Feldman (@svovaf)
4519
+ * @since 1.0.1
4520
+ *
4521
+ * @param bool $check_user Enforce checking if user have plugins activation privileges.
4522
+ */
4523
+ function _uninstall_plugin_event( $check_user = true ) {
4524
+ $this->_logger->entrance( 'slug = ' . $this->_slug );
4525
+
4526
+ if ( $check_user && ! current_user_can( 'activate_plugins' ) ) {
4527
+ return;
4528
+ }
4529
+
4530
+ $params = array();
4531
+ $uninstall_reason = null;
4532
+ if ( isset( $this->_storage->uninstall_reason ) ) {
4533
+ $uninstall_reason = $this->_storage->uninstall_reason;
4534
+ $params['reason_id'] = $uninstall_reason->id;
4535
+ $params['reason_info'] = $uninstall_reason->info;
4536
+ }
4537
+
4538
+ if ( ! $this->is_registered() && isset( $uninstall_reason ) ) {
4539
+ // Send anonymous uninstall event only if user submitted a feedback.
4540
+ if ( isset( $uninstall_reason->is_anonymous ) && ! $uninstall_reason->is_anonymous ) {
4541
+ $this->opt_in( false, false, false, false, true );
4542
+ } else {
4543
+ $params['uid'] = $this->get_anonymous_id();
4544
+ $this->get_api_plugin_scope()->call( 'uninstall.json', 'put', $params );
4545
+ }
4546
+ } else {
4547
+ // Send uninstall event.
4548
+ $this->send_install_update( array_merge( $params, array(
4549
+ 'is_active' => false,
4550
+ 'is_uninstalled' => true,
4551
+ ) ) );
4552
+ }
4553
+
4554
+ // @todo Decide if we want to delete plugin information from db.
4555
+ }
4556
+
4557
+ /**
4558
+ * @author Vova Feldman (@svovaf)
4559
+ * @since 1.1.1
4560
+ *
4561
+ * @return string
4562
+ */
4563
+ private function premium_plugin_basename() {
4564
+ return preg_replace( '/\//', '-premium/', $this->_free_plugin_basename, 1 );
4565
+ }
4566
+
4567
+ /**
4568
+ * Uninstall plugin hook. Called only when connected his account with Freemius for active sites tracking.
4569
+ *
4570
+ * @author Vova Feldman (@svovaf)
4571
+ * @since 1.0.2
4572
+ */
4573
+ public static function _uninstall_plugin_hook() {
4574
+ self::_load_required_static();
4575
+
4576
+ self::$_static_logger->entrance();
4577
+
4578
+ if ( ! current_user_can( 'activate_plugins' ) ) {
4579
+ return;
4580
+ }
4581
+
4582
+ $plugin_file = substr( current_filter(), strlen( 'uninstall_' ) );
4583
+
4584
+ self::$_static_logger->info( 'plugin = ' . $plugin_file );
4585
+
4586
+ define( 'WP_FS__UNINSTALL_MODE', true );
4587
+
4588
+ $fs = self::get_instance_by_file( $plugin_file );
4589
+
4590
+ if ( is_object( $fs ) ) {
4591
+ self::require_plugin_essentials();
4592
+
4593
+ if ( is_plugin_active( $fs->_free_plugin_basename ) ||
4594
+ is_plugin_active( $fs->premium_plugin_basename() )
4595
+ ) {
4596
+ // Deleting Free or Premium plugin version while the other version still installed.
4597
+ return;
4598
+ }
4599
+
4600
+ $fs->_uninstall_plugin_event();
4601
+
4602
+ $fs->do_action( 'after_uninstall' );
4603
+ }
4604
+ }
4605
+
4606
+ #----------------------------------------------------------------------------------
4607
+ #region Plugin Information
4608
+ #----------------------------------------------------------------------------------
4609
+
4610
+ /**
4611
+ * Load WordPress core plugin.php essential module.
4612
+ *
4613
+ * @author Vova Feldman (@svovaf)
4614
+ * @since 1.1.1
4615
+ */
4616
+ private static function require_plugin_essentials() {
4617
+ if ( ! function_exists( 'get_plugins' ) ) {
4618
+ self::$_static_logger->log( 'Including wp-admin/includes/plugin.php...' );
4619
+
4620
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
4621
+ }
4622
+ }
4623
+
4624
+ /**
4625
+ * Load WordPress core pluggable.php module.
4626
+ *
4627
+ * @author Vova Feldman (@svovaf)
4628
+ * @since 1.1.2
4629
+ */
4630
+ private static function require_pluggable_essentials() {
4631
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
4632
+ require_once( ABSPATH . 'wp-includes/pluggable.php' );
4633
+ }
4634
+ }
4635
+
4636
+ /**
4637
+ * Return plugin data.
4638
+ *
4639
+ * @author Vova Feldman (@svovaf)
4640
+ * @since 1.0.1
4641
+ *
4642
+ * @return array
4643
+ */
4644
+ function get_plugin_data() {
4645
+ if ( ! isset( $this->_plugin_data ) ) {
4646
+ self::require_plugin_essentials();
4647
+
4648
+ /**
4649
+ * @author Vova Feldman (@svovaf)
4650
+ * @since 1.2.0 When using get_plugin_data() do NOT translate plugin data.
4651
+ *
4652
+ * @link https://github.com/Freemius/wordpress-sdk/issues/77
4653
+ */
4654
+ $this->_plugin_data = get_plugin_data(
4655
+ $this->_plugin_main_file_path,
4656
+ false,
4657
+ false
4658
+ );
4659
+ }
4660
+
4661
+ return $this->_plugin_data;
4662
+ }
4663
+
4664
+ /**
4665
+ * @author Vova Feldman (@svovaf)
4666
+ * @since 1.0.1
4667
+ *
4668
+ * @return string Plugin slug.
4669
+ */
4670
+ function get_slug() {
4671
+ return $this->_slug;
4672
+ }
4673
+
4674
+ /**
4675
+ * @author Vova Feldman (@svovaf)
4676
+ * @since 1.0.1
4677
+ *
4678
+ * @return number Plugin ID.
4679
+ */
4680
+ function get_id() {
4681
+ return $this->_plugin->id;
4682
+ }
4683
+
4684
+ /**
4685
+ * @author Vova Feldman (@svovaf)
4686
+ * @since 1.2.1.5
4687
+ *
4688
+ * @return string Freemius SDK version
4689
+ */
4690
+ function get_sdk_version() {
4691
+ return $this->version;
4692
+ }
4693
+
4694
+ /**
4695
+ * @author Vova Feldman (@svovaf)
4696
+ * @since 1.2.1.5
4697
+ *
4698
+ * @return number Parent plugin ID (if parent exist).
4699
+ */
4700
+ function get_parent_id() {
4701
+ return $this->is_addon() ?
4702
+ $this->get_parent_instance()->get_id() :
4703
+ $this->_plugin->id;
4704
+ }
4705
+
4706
+ /**
4707
+ * @author Vova Feldman (@svovaf)
4708
+ * @since 1.0.1
4709
+ *
4710
+ * @return string Plugin public key.
4711
+ */
4712
+ function get_public_key() {
4713
+ return $this->_plugin->public_key;
4714
+ }
4715
+
4716
+ /**
4717
+ * Will be available only on sandbox mode.
4718
+ *
4719
+ * @author Vova Feldman (@svovaf)
4720
+ * @since 1.0.4
4721
+ *
4722
+ * @return mixed Plugin secret key.
4723
+ */
4724
+ function get_secret_key() {
4725
+ return $this->_plugin->secret_key;
4726
+ }
4727
+
4728
+ /**
4729
+ * @author Vova Feldman (@svovaf)
4730
+ * @since 1.1.1
4731
+ *
4732
+ * @return bool
4733
+ */
4734
+ function has_secret_key() {
4735
+ return ! empty( $this->_plugin->secret_key );
4736
+ }
4737
+
4738
+ /**
4739
+ * @author Vova Feldman (@svovaf)
4740
+ * @since 1.0.9
4741
+ *
4742
+ * @return string
4743
+ */
4744
+ function get_plugin_name() {
4745
+ $this->_logger->entrance();
4746
+
4747
+ if ( ! isset( $this->_plugin_name ) ) {
4748
+ $plugin_data = $this->get_plugin_data();
4749
+
4750
+ // Get name.
4751
+ $this->_plugin_name = $plugin_data['Name'];
4752
+
4753
+ // Check if plugin name contains [Premium] suffix and remove it.
4754
+ $suffix = '[premium]';
4755
+ $suffix_len = strlen( $suffix );
4756
+
4757
+ if ( strlen( $plugin_data['Name'] ) > $suffix_len &&
4758
+ $suffix === substr( strtolower( $plugin_data['Name'] ), - $suffix_len )
4759
+ ) {
4760
+ $this->_plugin_name = substr( $plugin_data['Name'], 0, - $suffix_len );
4761
+ }
4762
+
4763
+ $this->_logger->departure( 'Name = ' . $this->_plugin_name );
4764
+ }
4765
+
4766
+ return $this->_plugin_name;
4767
+ }
4768
+
4769
+ /**
4770
+ * @author Vova Feldman (@svovaf)
4771
+ * @since 1.0.0
4772
+ *
4773
+ * @return string
4774
+ */
4775
+ function get_plugin_version() {
4776
+ $this->_logger->entrance();
4777
+
4778
+ $plugin_data = $this->get_plugin_data();
4779
+
4780
+ $this->_logger->departure( 'Version = ' . $plugin_data['Version'] );
4781
+
4782
+ return $this->apply_filters( 'plugin_version', $plugin_data['Version'] );
4783
+ }
4784
+
4785
+ /**
4786
+ * @author Vova Feldman (@svovaf)
4787
+ * @since 1.0.4
4788
+ *
4789
+ * @return string
4790
+ */
4791
+ function get_plugin_basename() {
4792
+ return $this->_plugin_basename;
4793
+ }
4794
+
4795
+ function get_plugin_folder_name() {
4796
+ $this->_logger->entrance();
4797
+
4798
+ $plugin_folder = $this->_plugin_basename;
4799
+
4800
+ while ( '.' !== dirname( $plugin_folder ) ) {
4801
+ $plugin_folder = dirname( $plugin_folder );
4802
+ }
4803
+
4804
+ $this->_logger->departure( 'Folder Name = ' . $plugin_folder );
4805
+
4806
+ return $plugin_folder;
4807
+ }
4808
+
4809
+ #endregion ------------------------------------------------------------------
4810
+
4811
+ /* Account
4812
+ ------------------------------------------------------------------------------------------------------------------*/
4813
+
4814
+ /**
4815
+ * Find plugin's slug by plugin's basename.
4816
+ *
4817
+ * @author Vova Feldman (@svovaf)
4818
+ * @since 1.0.9
4819
+ *
4820
+ * @param string $plugin_base_name
4821
+ *
4822
+ * @return false|string
4823
+ */
4824
+ private static function find_slug_by_basename( $plugin_base_name ) {
4825
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4826
+
4827
+ if ( ! array( $file_slug_map ) || ! isset( $file_slug_map[ $plugin_base_name ] ) ) {
4828
+ return false;
4829
+ }
4830
+
4831
+ return $file_slug_map[ $plugin_base_name ];
4832
+ }
4833
+
4834
+ /**
4835
+ * Store the map between the plugin's basename to the slug.
4836
+ *
4837
+ * @author Vova Feldman (@svovaf)
4838
+ * @since 1.0.9
4839
+ */
4840
+ private function store_file_slug_map() {
4841
+ $file_slug_map = self::$_accounts->get_option( 'file_slug_map', array() );
4842
+
4843
+ if ( ! array( $file_slug_map ) ) {
4844
+ $file_slug_map = array();
4845
+ }
4846
+
4847
+ if ( ! isset( $file_slug_map[ $this->_plugin_basename ] ) ||
4848
+ $file_slug_map[ $this->_plugin_basename ] !== $this->_slug
4849
+ ) {
4850
+ $file_slug_map[ $this->_plugin_basename ] = $this->_slug;
4851
+ self::$_accounts->set_option( 'file_slug_map', $file_slug_map, true );
4852
+ }
4853
+ }
4854
+
4855
+ /**
4856
+ * @return FS_User[]
4857
+ */
4858
+ static function get_all_users() {
4859
+ $users = self::$_accounts->get_option( 'users', array() );
4860
+
4861
+ if ( ! is_array( $users ) ) {
4862
+ $users = array();
4863
+ }
4864
+
4865
+ return $users;
4866
+ }
4867
+
4868
+ /**
4869
+ * @return FS_Site[]
4870
+ */
4871
+ private static function get_all_sites() {
4872
+ $sites = self::$_accounts->get_option( 'sites', array() );
4873
+
4874
+ if ( ! is_array( $sites ) ) {
4875
+ $sites = array();
4876
+ }
4877
+
4878
+ return $sites;
4879
+ }
4880
+
4881
+ /**
4882
+ * @author Vova Feldman (@svovaf)
4883
+ * @since 1.0.6
4884
+ *
4885
+ * @return FS_Plugin_License[]
4886
+ */
4887
+ private static function get_all_licenses() {
4888
+ $licenses = self::$_accounts->get_option( 'licenses', array() );
4889
+
4890
+ if ( ! is_array( $licenses ) ) {
4891
+ $licenses = array();
4892
+ }
4893
+
4894
+ return $licenses;
4895
+ }
4896
+
4897
+ /**
4898
+ * @return FS_Plugin_Plan[]
4899
+ */
4900
+ private static function get_all_plans() {
4901
+ $plans = self::$_accounts->get_option( 'plans', array() );
4902
+
4903
+ if ( ! is_array( $plans ) ) {
4904
+ $plans = array();
4905
+ }
4906
+
4907
+ return $plans;
4908
+ }
4909
+
4910
+ /**
4911
+ * @author Vova Feldman (@svovaf)
4912
+ * @since 1.0.4
4913
+ *
4914
+ * @return FS_Plugin_Tag[]
4915
+ */
4916
+ private static function get_all_updates() {
4917
+ $updates = self::$_accounts->get_option( 'updates', array() );
4918
+
4919
+ if ( ! is_array( $updates ) ) {
4920
+ $updates = array();
4921
+ }
4922
+
4923
+ return $updates;
4924
+ }
4925
+
4926
+ /**
4927
+ * @author Vova Feldman (@svovaf)
4928
+ * @since 1.0.6
4929
+ *
4930
+ * @return array<number,FS_Plugin[]>|false
4931
+ */
4932
+ private static function get_all_addons() {
4933
+ $addons = self::$_accounts->get_option( 'addons', array() );
4934
+
4935
+ if ( ! is_array( $addons ) ) {
4936
+ $addons = array();
4937
+ }
4938
+
4939
+ return $addons;
4940
+ }
4941
+
4942
+ /**
4943
+ * @author Vova Feldman (@svovaf)
4944
+ * @since 1.0.6
4945
+ *
4946
+ * @return FS_Plugin[]|false
4947
+ */
4948
+ private static function get_all_account_addons() {
4949
+ $addons = self::$_accounts->get_option( 'account_addons', array() );
4950
+
4951
+ if ( ! is_array( $addons ) ) {
4952
+ $addons = array();
4953
+ }
4954
+
4955
+ return $addons;
4956
+ }
4957
+
4958
+ /**
4959
+ * Check if user is registered.
4960
+ *
4961
+ * @author Vova Feldman (@svovaf)
4962
+ * @since 1.0.1
4963
+ * @return bool
4964
+ */
4965
+ function is_registered() {
4966
+ return is_object( $this->_user );
4967
+ }
4968
+
4969
+ /**
4970
+ * Returns TRUE if the user opted-in and didn't disconnect (opt-out).
4971
+ *
4972
+ * @author Leo Fajardo (@leorw)
4973
+ * @since 1.2.1.5
4974
+ *
4975
+ * @return bool
4976
+ */
4977
+ function is_tracking_allowed() {
4978
+ return ( is_object( $this->_site ) && true !== $this->_site->is_disconnected );
4979
+ }
4980
+
4981
+ /**
4982
+ * @author Vova Feldman (@svovaf)
4983
+ * @since 1.0.4
4984
+ *
4985
+ * @return FS_Plugin
4986
+ */
4987
+ function get_plugin() {
4988
+ return $this->_plugin;
4989
+ }
4990
+
4991
+ /**
4992
+ * @author Vova Feldman (@svovaf)
4993
+ * @since 1.0.3
4994
+ *
4995
+ * @return FS_User
4996
+ */
4997
+ function get_user() {
4998
+ return $this->_user;
4999
+ }
5000
+
5001
+ /**
5002
+ * @author Vova Feldman (@svovaf)
5003
+ * @since 1.0.3
5004
+ *
5005
+ * @return FS_Site
5006
+ */
5007
+ function get_site() {
5008
+ return $this->_site;
5009
+ }
5010
+
5011
+ /**
5012
+ * Get plugin add-ons.
5013
+ *
5014
+ * @author Vova Feldman (@svovaf)
5015
+ * @since 1.0.6
5016
+ *
5017
+ * @since 1.1.7.3 If not yet loaded, fetch data from the API.
5018
+ *
5019
+ * @param bool $flush
5020
+ *
5021
+ * @return FS_Plugin[]|false
5022
+ */
5023
+ function get_addons( $flush = false ) {
5024
+ $this->_logger->entrance();
5025
+
5026
+ if ( ! $this->_has_addons ) {
5027
+ return false;
5028
+ }
5029
+
5030
+ $addons = $this->_sync_addons( $flush );
5031
+
5032
+ return ( ! is_array( $addons ) || empty( $addons ) ) ?
5033
+ false :
5034
+ $addons;
5035
+ }
5036
+
5037
+ /**
5038
+ * @author Vova Feldman (@svovaf)
5039
+ * @since 1.0.6
5040
+ *
5041
+ * @return FS_Plugin[]|false
5042
+ */
5043
+ function get_account_addons() {
5044
+ $this->_logger->entrance();
5045
+
5046
+ $addons = self::get_all_account_addons();
5047
+
5048
+ if ( ! is_array( $addons ) ||
5049
+ ! isset( $addons[ $this->_plugin->id ] ) ||
5050
+ ! is_array( $addons[ $this->_plugin->id ] ) ||
5051
+ 0 === count( $addons[ $this->_plugin->id ] )
5052
+ ) {
5053
+ return false;
5054
+ }
5055
+
5056
+ return $addons[ $this->_plugin->id ];
5057
+ }
5058
+
5059
+ /**
5060
+ * Check if user has any
5061
+ *
5062
+ * @author Vova Feldman (@svovaf)
5063
+ * @since 1.1.6
5064
+ *
5065
+ * @return bool
5066
+ */
5067
+ function has_account_addons() {
5068
+ $addons = $this->get_account_addons();
5069
+
5070
+ return is_array( $addons ) && ( 0 < count( $addons ) );
5071
+ }
5072
+
5073
+
5074
+ /**
5075
+ * Get add-on by ID (from local data).
5076
+ *
5077
+ * @author Vova Feldman (@svovaf)
5078
+ * @since 1.0.6
5079
+ *
5080
+ * @param number $id
5081
+ *
5082
+ * @return FS_Plugin|false
5083
+ */
5084
+ function get_addon( $id ) {
5085
+ $this->_logger->entrance();
5086
+
5087
+ $addons = $this->get_addons();
5088
+
5089
+ if ( is_array( $addons ) ) {
5090
+ foreach ( $addons as $addon ) {
5091
+ if ( $id == $addon->id ) {
5092
+ return $addon;
5093
+ }
5094
+ }
5095
+ }
5096
+
5097
+ return false;
5098
+ }
5099
+
5100
+ /**
5101
+ * Get add-on by slug (from local data).
5102
+ *
5103
+ * @author Vova Feldman (@svovaf)
5104
+ * @since 1.0.6
5105
+ *
5106
+ * @param string $slug
5107
+ *
5108
+ * @param bool $flush
5109
+ *
5110
+ * @return FS_Plugin|false
5111
+ */
5112
+ function get_addon_by_slug( $slug, $flush = false ) {
5113
+ $this->_logger->entrance();
5114
+
5115
+ $addons = $this->get_addons( $flush );
5116
+
5117
+ if ( is_array( $addons ) ) {
5118
+ foreach ( $addons as $addon ) {
5119
+ if ( $slug === $addon->slug ) {
5120
+ return $addon;
5121
+ }
5122
+ }
5123
+ }
5124
+
5125
+ return false;
5126
+ }
5127
+
5128
+ #----------------------------------------------------------------------------------
5129
+ #region Plans & Licensing
5130
+ #----------------------------------------------------------------------------------
5131
+
5132
+ /**
5133
+ * Check if running premium plugin code.
5134
+ *
5135
+ * @author Vova Feldman (@svovaf)
5136
+ * @since 1.0.5
5137
+ *
5138
+ * @return bool
5139
+ */
5140
+ function is_premium() {
5141
+ return $this->_plugin->is_premium;
5142
+ }
5143
+
5144
+ /**
5145
+ * Get site's plan ID.
5146
+ *
5147
+ * @author Vova Feldman (@svovaf)
5148
+ * @since 1.0.2
5149
+ *
5150
+ * @return number
5151
+ */
5152
+ function get_plan_id() {
5153
+ return $this->_site->plan->id;
5154
+ }
5155
+
5156
+ /**
5157
+ * Get site's plan title.
5158
+ *
5159
+ * @author Vova Feldman (@svovaf)
5160
+ * @since 1.0.2
5161
+ *
5162
+ * @return string
5163
+ */
5164
+ function get_plan_title() {
5165
+ return $this->_site->plan->title;
5166
+ }
5167
+
5168
+ /**
5169
+ * @author Vova Feldman (@svovaf)
5170
+ * @since 1.0.9
5171
+ *
5172
+ * @return FS_Plugin_Plan|false
5173
+ */
5174
+ function get_plan() {
5175
+ return is_object( $this->_site->plan ) ?
5176
+ $this->_site->plan :
5177
+ false;
5178
+ }
5179
+
5180
+ /**
5181
+ * @author Vova Feldman (@svovaf)
5182
+ * @since 1.0.3
5183
+ *
5184
+ * @return bool
5185
+ */
5186
+ function is_trial() {
5187
+ $this->_logger->entrance();
5188
+
5189
+ if ( ! $this->is_registered() ) {
5190
+ return false;
5191
+ }
5192
+
5193
+ return $this->_site->is_trial();
5194
+ }
5195
+
5196
+ /**
5197
+ * Check if currently in a trial with payment method (credit card or paypal).
5198
+ *
5199
+ * @author Vova Feldman (@svovaf)
5200
+ * @since 1.1.7
5201
+ *
5202
+ * @return bool
5203
+ */
5204
+ function is_paid_trial() {
5205
+ $this->_logger->entrance();
5206
+
5207
+ if ( ! $this->is_trial() ) {
5208
+ return false;
5209
+ }
5210
+
5211
+ return $this->has_active_valid_license() && ( $this->_site->trial_plan_id == $this->_license->plan_id );
5212
+ }
5213
+
5214
+ /**
5215
+ * Check if trial already utilized.
5216
+ *
5217
+ * @since 1.0.9
5218
+ *
5219
+ * @return bool
5220
+ */
5221
+ function is_trial_utilized() {
5222
+ $this->_logger->entrance();
5223
+
5224
+ if ( ! $this->is_registered() ) {
5225
+ return false;
5226
+ }
5227
+
5228
+ return $this->_site->is_trial_utilized();
5229
+ }
5230
+
5231
+ /**
5232
+ * Get trial plan information (if in trial).
5233
+ *
5234
+ * @author Vova Feldman (@svovaf)
5235
+ * @since 1.0.9
5236
+ *
5237
+ * @return bool|FS_Plugin_Plan
5238
+ */
5239
+ function get_trial_plan() {
5240
+ $this->_logger->entrance();
5241
+
5242
+ if ( ! $this->is_trial() ) {
5243
+ return false;
5244
+ }
5245
+
5246
+ return $this->_storage->trial_plan;
5247
+ }
5248
+
5249
+ /**
5250
+ * Check if the user has an activate, non-expired license on current plugin's install.
5251
+ *
5252
+ * @since 1.0.9
5253
+ *
5254
+ * @return bool
5255
+ */
5256
+ function is_paying() {
5257
+ $this->_logger->entrance();
5258
+
5259
+ if ( ! $this->is_registered() ) {
5260
+ return false;
5261
+ }
5262
+
5263
+ if ( ! $this->has_paid_plan() ) {
5264
+ return false;
5265
+ }
5266
+
5267
+ return (
5268
+ ! $this->is_trial() &&
5269
+ 'free' !== $this->_site->plan->name &&
5270
+ $this->has_active_valid_license()
5271
+ );
5272
+ }
5273
+
5274
+ /**
5275
+ * @author Vova Feldman (@svovaf)
5276
+ * @since 1.0.4
5277
+ *
5278
+ * @return bool
5279
+ */
5280
+ function is_free_plan() {
5281
+ if ( ! $this->is_registered() ) {
5282
+ return true;
5283
+ }
5284
+
5285
+ if ( ! $this->has_paid_plan() ) {
5286
+ return true;
5287
+ }
5288
+
5289
+ return (
5290
+ 'free' === $this->_site->plan->name ||
5291
+ ! $this->has_features_enabled_license()
5292
+ );
5293
+ }
5294
+
5295
+ /**
5296
+ * @author Vova Feldman (@svovaf)
5297
+ * @since 1.0.5
5298
+ *
5299
+ * @return bool
5300
+ */
5301
+ function _has_premium_license() {
5302
+ $this->_logger->entrance();
5303
+
5304
+ $premium_license = $this->_get_available_premium_license();
5305
+
5306
+ return ( false !== $premium_license );
5307
+ }
5308
+
5309
+ /**
5310
+ * Check if user has any licenses associated with the plugin (including expired or blocking).
5311
+ *
5312
+ * @author Vova Feldman (@svovaf)
5313
+ * @since 1.1.7.3
5314
+ *
5315
+ * @return bool
5316
+ */
5317
+ private function has_any_license() {
5318
+ return is_array( $this->_licenses ) && ( 0 < count( $this->_licenses ) );
5319
+ }
5320
+
5321
+ /**
5322
+ * @author Vova Feldman (@svovaf)
5323
+ * @since 1.0.5
5324
+ *
5325
+ * @return FS_Plugin_License|false
5326
+ */
5327
+ function _get_available_premium_license() {
5328
+ $this->_logger->entrance();
5329
+
5330
+ if ( ! $this->has_paid_plan() ) {
5331
+ return false;
5332
+ }
5333
+
5334
+ if ( is_array( $this->_licenses ) ) {
5335
+ foreach ( $this->_licenses as $license ) {
5336
+ if ( ! $license->is_utilized() && $license->is_features_enabled() ) {
5337
+ return $license;
5338
+ }
5339
+ }
5340
+ }
5341
+
5342
+ return false;
5343
+ }
5344
+
5345
+ /**
5346
+ * Sync local plugin plans with remote server.
5347
+ *
5348
+ * @author Vova Feldman (@svovaf)
5349
+ * @since 1.0.5
5350
+ *
5351
+ * @return FS_Plugin_Plan[]|object
5352
+ */
5353
+ function _sync_plans() {
5354
+ $plans = $this->_fetch_plugin_plans();
5355
+
5356
+ if ( $this->is_array_instanceof( $plans, 'FS_Plugin_Plan' ) ) {
5357
+ $this->_plans = $plans;
5358
+ $this->_store_plans();
5359
+ }
5360
+
5361
+ $this->do_action( 'after_plans_sync', $plans );
5362
+
5363
+ return $this->_plans;
5364
+ }
5365
+
5366
+ /**
5367
+ * @author Vova Feldman (@svovaf)
5368
+ * @since 1.0.5
5369
+ *
5370
+ * @param number $id
5371
+ *
5372
+ * @return FS_Plugin_Plan|false
5373
+ */
5374
+ function _get_plan_by_id( $id ) {
5375
+ $this->_logger->entrance();
5376
+
5377
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
5378
+ $this->_sync_plans();
5379
+ }
5380
+
5381
+ foreach ( $this->_plans as $plan ) {
5382
+ if ( $id == $plan->id ) {
5383
+ return $plan;
5384
+ }
5385
+ }
5386
+
5387
+ return false;
5388
+ }
5389
+
5390
+ /**
5391
+ * @author Vova Feldman (@svovaf)
5392
+ * @since 1.1.8.1
5393
+ *
5394
+ * @param string $name
5395
+ *
5396
+ * @return FS_Plugin_Plan|false
5397
+ */
5398
+ private function get_plan_by_name( $name ) {
5399
+ $this->_logger->entrance();
5400
+
5401
+ if ( ! is_array( $this->_plans ) || 0 === count( $this->_plans ) ) {
5402
+ $this->_sync_plans();
5403
+ }
5404
+
5405
+ foreach ( $this->_plans as $plan ) {
5406
+ if ( $name == $plan->name ) {
5407
+ return $plan;
5408
+ }
5409
+ }
5410
+
5411
+ return false;
5412
+ }
5413
+
5414
+ /**
5415
+ * Sync local plugin plans with remote server.
5416
+ *
5417
+ * @author Vova Feldman (@svovaf)
5418
+ * @since 1.0.6
5419
+ *
5420
+ * @param number|bool $site_license_id
5421
+ *
5422
+ * @return FS_Plugin_License[]|object
5423
+ */
5424
+ function _sync_licenses( $site_license_id = false ) {
5425
+ $licenses = $this->_fetch_licenses( false, $site_license_id );
5426
+
5427
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
5428
+ $this->_licenses = $licenses;
5429
+ $this->_store_licenses();
5430
+ }
5431
+
5432
+ // Update current license.
5433
+ if ( is_object( $this->_license ) ) {
5434
+ $this->_license = $this->_get_license_by_id( $this->_license->id );
5435
+ }
5436
+
5437
+ return $this->_licenses;
5438
+ }
5439
+
5440
+ /**
5441
+ * @author Vova Feldman (@svovaf)
5442
+ * @since 1.0.5
5443
+ *
5444
+ * @param number $id
5445
+ *
5446
+ * @return FS_Plugin_License|false
5447
+ */
5448
+ function _get_license_by_id( $id ) {
5449
+ $this->_logger->entrance();
5450
+
5451
+ if ( ! is_numeric( $id ) ) {
5452
+ return false;
5453
+ }
5454
+
5455
+ if ( ! $this->has_any_license() ) {
5456
+ $this->_sync_licenses();
5457
+ }
5458
+
5459
+ foreach ( $this->_licenses as $license ) {
5460
+ if ( $id == $license->id ) {
5461
+ return $license;
5462
+ }
5463
+ }
5464
+
5465
+ return false;
5466
+ }
5467
+
5468
+ /**
5469
+ * Sync site's license with user licenses.
5470
+ *
5471
+ * @author Vova Feldman (@svovaf)
5472
+ * @since 1.0.6
5473
+ *
5474
+ * @param FS_Plugin_License|null $new_license
5475
+ */
5476
+ function _update_site_license( $new_license ) {
5477
+ $this->_logger->entrance();
5478
+
5479
+ $this->_license = $new_license;
5480
+
5481
+ if ( ! is_object( $new_license ) ) {
5482
+ $this->_site->license_id = null;
5483
+ $this->_sync_site_subscription( null );
5484
+
5485
+ return;
5486
+ }
5487
+
5488
+ $this->_site->license_id = $this->_license->id;
5489
+
5490
+ if ( ! is_array( $this->_licenses ) ) {
5491
+ $this->_licenses = array();
5492
+ }
5493
+
5494
+ $is_license_found = false;
5495
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
5496
+ if ( $new_license->id == $this->_licenses[ $i ]->id ) {
5497
+ $this->_licenses[ $i ] = $new_license;
5498
+
5499
+ $is_license_found = true;
5500
+ break;
5501
+ }
5502
+ }
5503
+
5504
+ // If new license just append.
5505
+ if ( ! $is_license_found ) {
5506
+ $this->_licenses[] = $new_license;
5507
+ }
5508
+
5509
+ $this->_sync_site_subscription( $new_license );
5510
+ }
5511
+
5512
+ /**
5513
+ * Sync site's subscription.
5514
+ *
5515
+ * @author Vova Feldman (@svovaf)
5516
+ * @since 1.0.9
5517
+ *
5518
+ * @param FS_Plugin_License|null $license
5519
+ *
5520
+ * @return bool|\FS_Subscription
5521
+ */
5522
+ private function _sync_site_subscription( $license ) {
5523
+ if ( ! is_object( $license ) ) {
5524
+ unset( $this->_storage->subscription );
5525
+
5526
+ return false;
5527
+ }
5528
+
5529
+ // Load subscription details if not lifetime.
5530
+ $subscription = $license->is_lifetime() ?
5531
+ false :
5532
+ $this->_fetch_site_license_subscription();
5533
+
5534
+ if ( is_object( $subscription ) && ! isset( $subscription->error ) ) {
5535
+ $this->_storage->subscription = $subscription;
5536
+ } else {
5537
+ unset( $this->_storage->subscription );
5538
+ }
5539
+
5540
+ return $subscription;
5541
+ }
5542
+
5543
+ /**
5544
+ * @author Vova Feldman (@svovaf)
5545
+ * @since 1.0.6
5546
+ *
5547
+ * @return bool|\FS_Plugin_License
5548
+ */
5549
+ function _get_license() {
5550
+ return $this->_license;
5551
+ }
5552
+
5553
+ /**
5554
+ * @return bool|\FS_Subscription
5555
+ */
5556
+ function _get_subscription() {
5557
+ return isset( $this->_storage->subscription ) ?
5558
+ $this->_storage->subscription :
5559
+ false;
5560
+ }
5561
+
5562
+ /**
5563
+ * @author Vova Feldman (@svovaf)
5564
+ * @since 1.0.2
5565
+ *
5566
+ * @param string $plan Plan name
5567
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
5568
+ *
5569
+ * @return bool
5570
+ */
5571
+ function is_plan( $plan, $exact = false ) {
5572
+ $this->_logger->entrance();
5573
+
5574
+ if ( ! $this->is_registered() ) {
5575
+ return false;
5576
+ }
5577
+
5578
+ $plan = strtolower( $plan );
5579
+
5580
+ if ( $this->_site->plan->name === $plan ) // Exact plan.
5581
+ {
5582
+ return true;
5583
+ } else if ( $exact ) // Required exact, but plans are different.
5584
+ {
5585
+ return false;
5586
+ }
5587
+
5588
+ $current_plan_order = - 1;
5589
+ $required_plan_order = - 1;
5590
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5591
+ if ( $plan === $this->_plans[ $i ]->name ) {
5592
+ $required_plan_order = $i;
5593
+ } else if ( $this->_site->plan->name === $this->_plans[ $i ]->name ) {
5594
+ $current_plan_order = $i;
5595
+ }
5596
+ }
5597
+
5598
+ return ( $current_plan_order > $required_plan_order );
5599
+ }
5600
+
5601
+ /**
5602
+ * Check if plan based on trial. If not in trial mode, should return false.
5603
+ *
5604
+ * @since 1.0.9
5605
+ *
5606
+ * @param string $plan Plan name
5607
+ * @param bool $exact If true, looks for exact plan. If false, also check "higher" plans.
5608
+ *
5609
+ * @return bool
5610
+ */
5611
+ function is_trial_plan( $plan, $exact = false ) {
5612
+ $this->_logger->entrance();
5613
+
5614
+ if ( ! $this->is_registered() ) {
5615
+ return false;
5616
+ }
5617
+
5618
+ if ( ! $this->is_trial() ) {
5619
+ return false;
5620
+ }
5621
+
5622
+ if ( ! isset( $this->_storage->trial_plan ) ) {
5623
+ // Store trial plan information.
5624
+ $this->_enrich_site_trial_plan( true );
5625
+ }
5626
+
5627
+ if ( $this->_storage->trial_plan->name === $plan ) // Exact plan.
5628
+ {
5629
+ return true;
5630
+ } else if ( $exact ) // Required exact, but plans are different.
5631
+ {
5632
+ return false;
5633
+ }
5634
+
5635
+ $current_plan_order = - 1;
5636
+ $required_plan_order = - 1;
5637
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
5638
+ if ( $plan === $this->_plans[ $i ]->name ) {
5639
+ $required_plan_order = $i;
5640
+ } else if ( $this->_storage->trial_plan->name === $this->_plans[ $i ]->name ) {
5641
+ $current_plan_order = $i;
5642
+ }
5643
+ }
5644
+
5645
+ return ( $current_plan_order > $required_plan_order );
5646
+ }
5647
+
5648
+ /**
5649
+ * Check if plugin has any paid plans.
5650
+ *
5651
+ * @author Vova Feldman (@svovaf)
5652
+ * @since 1.0.7
5653
+ *
5654
+ * @return bool
5655
+ */
5656
+ function has_paid_plan() {
5657
+ return $this->_has_paid_plans ||
5658
+ FS_Plan_Manager::instance()->has_paid_plan( $this->_plans );
5659
+ }
5660
+
5661
+ /**
5662
+ * Check if plugin has any plan with a trail.
5663
+ *
5664
+ * @author Vova Feldman (@svovaf)
5665
+ * @since 1.0.9
5666
+ *
5667
+ * @return bool
5668
+ */
5669
+ function has_trial_plan() {
5670
+ if ( ! $this->is_registered() ) {
5671
+ /**
5672
+ * @author Vova Feldman(@svovaf)
5673
+ * @since 1.2.1.5
5674
+ *
5675
+ * Allow setting a trial from the SDK without calling the API.
5676
+ * But, if the user did opt-in, continue using the real data from the API.
5677
+ */
5678
+ if ( $this->_trial_days >= 0 ) {
5679
+ return true;
5680
+ }
5681
+
5682
+ return false;
5683
+ }
5684
+
5685
+ return $this->_storage->get( 'has_trial_plan', false );
5686
+ }
5687
+
5688
+ /**
5689
+ * Check if plugin has any free plan, or is it premium only.
5690
+ *
5691
+ * Note: If no plans configured, assume plugin is free.
5692
+ *
5693
+ * @author Vova Feldman (@svovaf)
5694
+ * @since 1.0.7
5695
+ *
5696
+ * @return bool
5697
+ */
5698
+ function has_free_plan() {
5699
+ return ! $this->is_only_premium();
5700
+ }
5701
+
5702
+ /**
5703
+ * Displays a license activation dialog box when the user clicks on the "Activate License"
5704
+ * or "Change License" link on the plugins
5705
+ * page.
5706
+ *
5707
+ * @author Leo Fajardo (@leorw)
5708
+ * @since 1.1.9
5709
+ */
5710
+ function _add_license_activation_dialog_box() {
5711
+ $vars = array(
5712
+ 'slug' => $this->_slug,
5713
+ );
5714
+
5715
+ fs_require_template( 'forms/license-activation.php', $vars );
5716
+ fs_require_template( 'forms/resend-key.php', $vars );
5717
+ }
5718
+
5719
+ /**
5720
+ * Displays the opt-out dialog box when the user clicks on the "Opt Out" link on the "Plugins"
5721
+ * page.
5722
+ *
5723
+ * @author Leo Fajardo (@leorw)
5724
+ * @since 1.2.1.5
5725
+ */
5726
+ function _add_optout_dialog() {
5727
+ $vars = array(
5728
+ 'slug' => $this->_slug,
5729
+ );
5730
+
5731
+ fs_require_template( 'forms/optout.php', $vars );
5732
+ }
5733
+
5734
+ /**
5735
+ * Prepare page to include all required UI and logic for the license activation dialog.
5736
+ *
5737
+ * @author Vova Feldman (@svovaf)
5738
+ * @since 1.2.0
5739
+ */
5740
+ function _add_license_activation() {
5741
+ if ( ! current_user_can( 'activate_plugins' ) ) {
5742
+ // Only admins can activate a license.
5743
+ return;
5744
+ }
5745
+
5746
+ if ( ! $this->has_paid_plan() ) {
5747
+ // Module doesn't have any paid plans.
5748
+ return;
5749
+ }
5750
+
5751
+ if ( ! $this->is_premium() ) {
5752
+ // Only add license activation logic to the premium version.
5753
+ return;
5754
+ }
5755
+
5756
+ // Add license activation link and AJAX request handler.
5757
+ if ( $this->is_plugins_page() ) {
5758
+ /**
5759
+ * @since 1.2.0 Add license action link only on plugins page.
5760
+ */
5761
+ $this->_add_license_action_link();
5762
+ }
5763
+
5764
+ // Add license activation AJAX callback.
5765
+ $this->add_ajax_action( 'activate_license', array( &$this, '_activate_license_ajax_action' ) );
5766
+
5767
+ // Add resend license AJAX callback.
5768
+ $this->add_ajax_action( 'resend_license_key', array( &$this, '_resend_license_key_ajax_action' ) );
5769
+ }
5770
+
5771
+ /**
5772
+ * @author Leo Fajardo (@leorw)
5773
+ * @since 1.1.9
5774
+ */
5775
+ function _activate_license_ajax_action() {
5776
+ $license_key = trim( fs_request_get( 'license_key' ) );
5777
+
5778
+ if ( empty( $license_key ) ) {
5779
+ exit;
5780
+ }
5781
+
5782
+ $slug = $_POST['slug'];
5783
+ $fs = ( ( $slug === $this->_slug ) ? $this : self::instance( $slug ) );
5784
+ $error = false;
5785
+ $next_page = false;
5786
+
5787
+ if ( $this->is_registered() ) {
5788
+ $api = $fs->get_api_site_scope();
5789
+ $install = $api->call( '/', 'put', array(
5790
+ 'license_key' => $this->apply_filters( 'license_key', $license_key )
5791
+ ) );
5792
+
5793
+ if ( isset( $install->error ) ) {
5794
+ $error = $install->error->message;
5795
+ } else {
5796
+ $fs = $this->is_addon() ?
5797
+ $this->get_parent_instance() :
5798
+ $this;
5799
+
5800
+ $next_page = $fs->_get_sync_license_url( $this->get_id(), true );
5801
+
5802
+ $this->reconnect_locally();
5803
+ }
5804
+ } else {
5805
+ $next_page = $this->opt_in( false, false, false, $license_key );
5806
+
5807
+ if ( isset( $next_page->error ) ) {
5808
+ $error = $next_page->error;
5809
+ }
5810
+ }
5811
+
5812
+ $result = array(
5813
+ 'success' => ( false === $error )
5814
+ );
5815
+
5816
+ if ( false !== $error ) {
5817
+ $result['error'] = $error;
5818
+ } else {
5819
+ $result['next_page'] = $next_page;
5820
+ }
5821
+
5822
+ echo json_encode( $result );
5823
+
5824
+ exit;
5825
+ }
5826
+
5827
+ /**
5828
+ * Billing update AJAX callback.
5829
+ *
5830
+ * @author Vova Feldman (@svovaf)
5831
+ * @since 1.2.1.5
5832
+ */
5833
+ function _update_billing_ajax_action() {
5834
+ check_ajax_referer( $this->get_action_tag( 'update_billing' ), 'security' );
5835
+
5836
+ if ( ! current_user_can( 'activate_plugins' ) ) {
5837
+ // Only for admins.
5838
+ $this->shoot_ajax_failure();
5839
+ }
5840
+
5841
+ $billing = fs_request_get( 'billing' );
5842
+
5843
+ $api = $this->get_api_user_scope();
5844
+ $result = $api->call( '/billing.json', 'put', array_merge( $billing, array(
5845
+ 'plugin_id' => $this->get_parent_id(),
5846
+ ) ) );
5847
+
5848
+ if ( ! $this->is_api_result_entity( $result ) ) {
5849
+ $this->shoot_ajax_failure();
5850
+ }
5851
+
5852
+ // Purge cached billing.
5853
+ $this->get_api_user_scope()->purge_cache( 'billing.json' );
5854
+
5855
+ $this->shoot_ajax_success();
5856
+ }
5857
+
5858
+ /**
5859
+ * Trial start for anonymous users (AJAX callback).
5860
+ *
5861
+ * @author Vova Feldman (@svovaf)
5862
+ * @since 1.2.1.5
5863
+ */
5864
+ function _start_trial_ajax_action() {
5865
+ check_ajax_referer( $this->get_action_tag( 'start_trial' ), 'security' );
5866
+
5867
+ if ( ! current_user_can( 'activate_plugins' ) ) {
5868
+ // Only for admins.
5869
+ $this->shoot_ajax_failure();
5870
+ }
5871
+
5872
+ $trial_data = fs_request_get( 'trial' );
5873
+
5874
+ $next_page = $this->opt_in(
5875
+ false,
5876
+ false,
5877
+ false,
5878
+ false,
5879
+ false,
5880
+ $trial_data['plan_id']
5881
+ );
5882
+
5883
+ if ( is_object( $next_page ) && $this->is_api_error( $next_page ) ) {
5884
+ $this->shoot_ajax_failure(
5885
+ isset( $next_page->error ) ?
5886
+ $next_page->error->message :
5887
+ var_export( $next_page, true )
5888
+ );
5889
+ }
5890
+
5891
+ $this->shoot_ajax_success( array(
5892
+ 'next_page' => $next_page,
5893
+ ) );
5894
+ }
5895
+
5896
+ /**
5897
+ * @author Leo Fajardo (@leorw)
5898
+ * @since 1.2.0
5899
+ */
5900
+ function _resend_license_key_ajax_action() {
5901
+ if ( ! isset( $_POST['email'] ) ) {
5902
+ exit;
5903
+ }
5904
+
5905
+ $email_address = trim( $_POST['email'] );
5906
+ if ( empty( $email_address ) ) {
5907
+ exit;
5908
+ }
5909
+
5910
+ $error = false;
5911
+
5912
+ $api = $this->get_api_plugin_scope();
5913
+ $result = $api->call( '/licenses/resend.json', 'post',
5914
+ array(
5915
+ 'email' => $email_address,
5916
+ 'is_localhost' => WP_FS__IS_LOCALHOST
5917
+ )
5918
+ );
5919
+
5920
+ if ( is_object( $result ) && isset( $result->error ) ) {
5921
+ $error = $result->error;
5922
+
5923
+ if ( in_array( $error->code, array( 'invalid_email', 'no_user' ) ) ) {
5924
+ $error = __fs( 'email-not-found' );
5925
+ } else if ( 'no_license' === $error->code ) {
5926
+ $error = __fs( 'no-active-licenses' );
5927
+ } else {
5928
+ $error = $error->message;
5929
+ }
5930
+ }
5931
+
5932
+ $licenses = array(
5933
+ 'success' => ( false === $error )
5934
+ );
5935
+
5936
+ if ( false !== $error ) {
5937
+ $licenses['error'] = sprintf( '%s... %s', __fs( 'oops', $this->_slug ), strtolower( $error ) );
5938
+ }
5939
+
5940
+ echo json_encode( $licenses );
5941
+
5942
+ exit;
5943
+ }
5944
+
5945
+ /**
5946
+ * Helper method to check if user in the plugins page.
5947
+ *
5948
+ * @author Vova Feldman (@svovaf)
5949
+ * @since 1.2.1.5
5950
+ *
5951
+ * @return bool
5952
+ */
5953
+ private function is_plugins_page() {
5954
+ global $pagenow;
5955
+
5956
+ return ( 'plugins.php' === $pagenow );
5957
+ }
5958
+
5959
+ #----------------------------------------------------------------------------------
5960
+ #region URL Generators
5961
+ #----------------------------------------------------------------------------------
5962
+
5963
+ /**
5964
+ * Alias to pricing_url().
5965
+ *
5966
+ * @author Vova Feldman (@svovaf)
5967
+ * @since 1.0.2
5968
+ *
5969
+ * @uses pricing_url()
5970
+ *
5971
+ * @param string $period Billing cycle
5972
+ * @param bool $is_trial
5973
+ *
5974
+ * @return string
5975
+ */
5976
+ function get_upgrade_url( $period = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
5977
+ return $this->pricing_url( $period, $is_trial );
5978
+ }
5979
+
5980
+ /**
5981
+ * @author Vova Feldman (@svovaf)
5982
+ * @since 1.0.9
5983
+ *
5984
+ * @uses get_upgrade_url()
5985
+ *
5986
+ * @return string
5987
+ */
5988
+ function get_trial_url() {
5989
+ return $this->get_upgrade_url( WP_FS__PERIOD_ANNUALLY, true );
5990
+ }
5991
+
5992
+ /**
5993
+ * Plugin's pricing URL.
5994
+ *
5995
+ * @author Vova Feldman (@svovaf)
5996
+ * @since 1.0.4
5997
+ *
5998
+ * @param string $billing_cycle Billing cycle
5999
+ *
6000
+ * @param bool $is_trial
6001
+ *
6002
+ * @return string
6003
+ */
6004
+ function pricing_url( $billing_cycle = WP_FS__PERIOD_ANNUALLY, $is_trial = false ) {
6005
+ $this->_logger->entrance();
6006
+
6007
+ $params = array(
6008
+ 'billing_cycle' => $billing_cycle
6009
+ );
6010
+
6011
+ if ( $is_trial ) {
6012
+ $params['trial'] = 'true';
6013
+ }
6014
+
6015
+ return $this->_get_admin_page_url( 'pricing', $params );
6016
+ }
6017
+
6018
+ /**
6019
+ * Checkout page URL.
6020
+ *
6021
+ * @author Vova Feldman (@svovaf)
6022
+ * @since 1.0.6
6023
+ *
6024
+ * @param string $billing_cycle Billing cycle
6025
+ * @param bool $is_trial
6026
+ * @param array $extra (optional) Extra parameters, override other query params.
6027
+ *
6028
+ * @return string
6029
+ */
6030
+ function checkout_url(
6031
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
6032
+ $is_trial = false,
6033
+ $extra = array()
6034
+ ) {
6035
+ $this->_logger->entrance();
6036
+
6037
+ $params = array(
6038
+ 'checkout' => 'true',
6039
+ 'billing_cycle' => $billing_cycle,
6040
+ );
6041
+
6042
+ if ( $is_trial ) {
6043
+ $params['trial'] = 'true';
6044
+ }
6045
+
6046
+ /**
6047
+ * Params in extra override other params.
6048
+ */
6049
+ $params = array_merge( $params, $extra );
6050
+
6051
+ return $this->_get_admin_page_url( 'pricing', $params );
6052
+ }
6053
+
6054
+ /**
6055
+ * Add-on checkout URL.
6056
+ *
6057
+ * @author Vova Feldman (@svovaf)
6058
+ * @since 1.1.7
6059
+ *
6060
+ * @param number $addon_id
6061
+ * @param number $pricing_id
6062
+ * @param string $billing_cycle
6063
+ * @param bool $is_trial
6064
+ *
6065
+ * @return string
6066
+ */
6067
+ function addon_checkout_url(
6068
+ $addon_id,
6069
+ $pricing_id,
6070
+ $billing_cycle = WP_FS__PERIOD_ANNUALLY,
6071
+ $is_trial = false
6072
+ ) {
6073
+ return $this->checkout_url( $billing_cycle, $is_trial, array(
6074
+ 'plugin_id' => $addon_id,
6075
+ 'pricing_id' => $pricing_id,
6076
+ ) );
6077
+ }
6078
+
6079
+ #endregion
6080
+
6081
+ #endregion ------------------------------------------------------------------
6082
+
6083
+ /**
6084
+ * Check if plugin has any add-ons.
6085
+ *
6086
+ * @author Vova Feldman (@svovaf)
6087
+ * @since 1.0.5
6088
+ *
6089
+ * @since 1.1.7.3 Base logic only on the parameter provided by the developer in the init function.
6090
+ *
6091
+ * @return bool
6092
+ */
6093
+ function has_addons() {
6094
+ $this->_logger->entrance();
6095
+
6096
+ return $this->_has_addons;
6097
+ }
6098
+
6099
+ /**
6100
+ * Check if plugin can work in anonymous mode.
6101
+ *
6102
+ * @author Vova Feldman (@svovaf)
6103
+ * @since 1.0.9
6104
+ *
6105
+ * @return bool
6106
+ *
6107
+ * @deprecated Please use is_enable_anonymous() instead
6108
+ */
6109
+ function enable_anonymous() {
6110
+ return $this->_enable_anonymous;
6111
+ }
6112
+
6113
+ /**
6114
+ * Check if plugin can work in anonymous mode.
6115
+ *
6116
+ * @author Vova Feldman (@svovaf)
6117
+ * @since 1.1.9
6118
+ *
6119
+ * @return bool
6120
+ */
6121
+ function is_enable_anonymous() {
6122
+ return $this->_enable_anonymous;
6123
+ }
6124
+
6125
+ /**
6126
+ * Check if plugin is premium only (no free plans).
6127
+ *
6128
+ * @author Vova Feldman (@svovaf)
6129
+ * @since 1.1.9
6130
+ *
6131
+ * @return bool
6132
+ */
6133
+ function is_only_premium() {
6134
+ return $this->_is_premium_only;
6135
+ }
6136
+
6137
+ /**
6138
+ * Check if feature supported with current site's plan.
6139
+ *
6140
+ * @author Vova Feldman (@svovaf)
6141
+ * @since 1.0.1
6142
+ *
6143
+ * @todo IMPLEMENT
6144
+ *
6145
+ * @param number $feature_id
6146
+ *
6147
+ * @throws Exception
6148
+ */
6149
+ function is_feature_supported( $feature_id ) {
6150
+ throw new Exception( 'not implemented' );
6151
+ }
6152
+
6153
+ /**
6154
+ * @author Vova Feldman (@svovaf)
6155
+ * @since 1.0.1
6156
+ *
6157
+ * @return bool Is running in SSL/HTTPS
6158
+ */
6159
+ function is_ssl() {
6160
+ return WP_FS__IS_HTTPS;
6161
+ }
6162
+
6163
+ /**
6164
+ * @author Vova Feldman (@svovaf)
6165
+ * @since 1.0.9
6166
+ *
6167
+ * @return bool Is running in AJAX call.
6168
+ *
6169
+ * @link http://wordpress.stackexchange.com/questions/70676/how-to-check-if-i-am-in-admin-ajax
6170
+ */
6171
+ function is_ajax() {
6172
+ return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
6173
+ }
6174
+
6175
+ /**
6176
+ * Check if it's an AJAX call targeted for the current module.
6177
+ *
6178
+ * @author Vova Feldman (@svovaf)
6179
+ * @since 1.2.0
6180
+ *
6181
+ * @param array|string $actions Collection of AJAX actions.
6182
+ *
6183
+ * @return bool
6184
+ */
6185
+ function is_ajax_action( $actions ) {
6186
+ // Verify it's an ajax call.
6187
+ if ( ! $this->is_ajax() ) {
6188
+ return false;
6189
+ }
6190
+
6191
+ // Verify the call is relevant for the plugin.
6192
+ if ( $this->_slug !== fs_request_get( 'slug' ) ) {
6193
+ return false;
6194
+ }
6195
+
6196
+ // Verify it's one of the specified actions.
6197
+ if ( is_string( $actions ) ) {
6198
+ $actions = explode( ',', $actions );
6199
+ }
6200
+
6201
+ if ( is_array( $actions ) && 0 < count( $actions ) ) {
6202
+ $ajax_action = fs_request_get( 'action' );
6203
+
6204
+ foreach ( $actions as $action ) {
6205
+ if ( $ajax_action === $this->get_action_tag( $action ) ) {
6206
+ return true;
6207
+ }
6208
+ }
6209
+ }
6210
+
6211
+ return false;
6212
+ }
6213
+
6214
+ /**
6215
+ * @author Vova Feldman (@svovaf)
6216
+ * @since 1.1.7
6217
+ *
6218
+ * @return bool
6219
+ */
6220
+ function is_cron() {
6221
+ return ( defined( 'DOING_CRON' ) && DOING_CRON );
6222
+ }
6223
+
6224
+ /**
6225
+ * Check if a real user is visiting the admin dashboard.
6226
+ *
6227
+ * @author Vova Feldman (@svovaf)
6228
+ * @since 1.1.7
6229
+ *
6230
+ * @return bool
6231
+ */
6232
+ function is_user_in_admin() {
6233
+ return is_admin() && ! $this->is_ajax() && ! $this->is_cron();
6234
+ }
6235
+
6236
+ /**
6237
+ * Check if running in HTTPS and if site's plan matching the specified plan.
6238
+ *
6239
+ * @param string $plan
6240
+ * @param bool $exact
6241
+ *
6242
+ * @return bool
6243
+ */
6244
+ function is_ssl_and_plan( $plan, $exact = false ) {
6245
+ return ( $this->is_ssl() && $this->is_plan( $plan, $exact ) );
6246
+ }
6247
+
6248
+ /**
6249
+ * Construct plugin's settings page URL.
6250
+ *
6251
+ * @author Vova Feldman (@svovaf)
6252
+ * @since 1.0.4
6253
+ *
6254
+ * @param string $page
6255
+ * @param array $params
6256
+ *
6257
+ * @return string
6258
+ */
6259
+ function _get_admin_page_url( $page = '', $params = array() ) {
6260
+ if ( 0 < count( $params ) ) {
6261
+ foreach ( $params as $k => $v ) {
6262
+ $params[ $k ] = urlencode( $v );
6263
+ }
6264
+ }
6265
+
6266
+ if ( ! $this->_menu->is_top_level() ) {
6267
+ $parent_slug = $this->_menu->get_parent_slug();
6268
+ $menu_file = ( false !== strpos( $parent_slug, '.php' ) ) ?
6269
+ $parent_slug :
6270
+ 'admin.php';
6271
+
6272
+ return add_query_arg( array_merge( $params, array(
6273
+ 'page' => $this->_menu->get_slug( $page ),
6274
+ ) ), admin_url( $menu_file, 'admin' ) );
6275
+ }
6276
+
6277
+ if ( $this->_menu->is_cpt() ) {
6278
+ if ( empty( $page ) && $this->is_activation_mode() ) {
6279
+ return add_query_arg( array_merge( $params, array(
6280
+ 'page' => $this->_menu->get_slug()
6281
+ ) ), admin_url( 'admin.php', 'admin' ) );
6282
+ } else {
6283
+ if ( ! empty( $page ) ) {
6284
+ $params['page'] = $this->_menu->get_slug( $page );
6285
+ }
6286
+
6287
+ return add_query_arg( $params, admin_url( $this->_menu->get_raw_slug(), 'admin' ) );
6288
+ }
6289
+ } else {
6290
+ return add_query_arg( array_merge( $params, array(
6291
+ 'page' => $this->_menu->get_slug( $page ),
6292
+ ) ), admin_url( 'admin.php', 'admin' ) );
6293
+ }
6294
+ }
6295
+
6296
+ /**
6297
+ * Plugin's account page + sync license URL.
6298
+ *
6299
+ * @author Vova Feldman (@svovaf)
6300
+ * @since 1.1.9.1
6301
+ *
6302
+ * @param bool|number $plugin_id
6303
+ * @param bool $add_action_nonce
6304
+ *
6305
+ * @return string
6306
+ */
6307
+ function _get_sync_license_url( $plugin_id = false, $add_action_nonce = true ) {
6308
+ $params = array();
6309
+
6310
+ if ( is_numeric( $plugin_id ) ) {
6311
+ $params['plugin_id'] = $plugin_id;
6312
+ }
6313
+
6314
+ return $this->get_account_url(
6315
+ $this->_slug . '_sync_license',
6316
+ $params,
6317
+ $add_action_nonce
6318
+ );
6319
+ }
6320
+
6321
+ /**
6322
+ * Plugin's account URL.
6323
+ *
6324
+ * @author Vova Feldman (@svovaf)
6325
+ * @since 1.0.4
6326
+ *
6327
+ * @param bool|string $action
6328
+ * @param array $params
6329
+ *
6330
+ * @param bool $add_action_nonce
6331
+ *
6332
+ * @return string
6333
+ */
6334
+ function get_account_url( $action = false, $params = array(), $add_action_nonce = true ) {
6335
+ if ( is_string( $action ) ) {
6336
+ $params['fs_action'] = $action;
6337
+ }
6338
+
6339
+ self::require_pluggable_essentials();
6340
+
6341
+ return ( $add_action_nonce && is_string( $action ) ) ?
6342
+ fs_nonce_url( $this->_get_admin_page_url( 'account', $params ), $action ) :
6343
+ $this->_get_admin_page_url( 'account', $params );
6344
+ }
6345
+
6346
+ /**
6347
+ * @author Vova Feldman (@svovaf)
6348
+ * @since 1.2.0
6349
+ *
6350
+ * @param string $tab
6351
+ * @param bool $action
6352
+ * @param array $params
6353
+ * @param bool $add_action_nonce
6354
+ *
6355
+ * @return string
6356
+ *
6357
+ * @uses get_account_url()
6358
+ */
6359
+ function get_account_tab_url( $tab, $action = false, $params = array(), $add_action_nonce = true ) {
6360
+ $params['tab'] = $tab;
6361
+
6362
+ return $this->get_account_url( $action, $params, $add_action_nonce );
6363
+ }
6364
+
6365
+ /**
6366
+ * Plugin's account URL.
6367
+ *
6368
+ * @author Vova Feldman (@svovaf)
6369
+ * @since 1.0.4
6370
+ *
6371
+ * @param bool|string $topic
6372
+ * @param bool|string $message
6373
+ *
6374
+ * @return string
6375
+ */
6376
+ function contact_url( $topic = false, $message = false ) {
6377
+ $params = array();
6378
+ if ( is_string( $topic ) ) {
6379
+ $params['topic'] = $topic;
6380
+ }
6381
+ if ( is_string( $message ) ) {
6382
+ $params['message'] = $message;
6383
+ }
6384
+
6385
+ if ( $this->is_addon() ) {
6386
+ $params['addon_id'] = $this->get_id();
6387
+
6388
+ return $this->get_parent_instance()->_get_admin_page_url( 'contact', $params );
6389
+ } else {
6390
+ return $this->_get_admin_page_url( 'contact', $params );
6391
+ }
6392
+ }
6393
+
6394
+ /**
6395
+ * Add-on direct info URL.
6396
+ *
6397
+ * @author Vova Feldman (@svovaf)
6398
+ * @since 1.1.0
6399
+ *
6400
+ * @param string $slug
6401
+ *
6402
+ * @return string
6403
+ */
6404
+ function addon_url( $slug ) {
6405
+ return $this->_get_admin_page_url( 'addons', array(
6406
+ 'slug' => $slug
6407
+ ) );
6408
+ }
6409
+
6410
+ /* Logger
6411
+ ------------------------------------------------------------------------------------------------------------------*/
6412
+ /**
6413
+ * @param string $id
6414
+ * @param bool $prefix_slug
6415
+ *
6416
+ * @return FS_Logger
6417
+ */
6418
+ function get_logger( $id = '', $prefix_slug = true ) {
6419
+ return FS_Logger::get_logger( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id );
6420
+ }
6421
+
6422
+ /**
6423
+ * @param $id
6424
+ * @param bool $load_options
6425
+ * @param bool $prefix_slug
6426
+ *
6427
+ * @return FS_Option_Manager
6428
+ */
6429
+ function get_options_manager( $id, $load_options = false, $prefix_slug = true ) {
6430
+ return FS_Option_Manager::get_manager( ( $prefix_slug ? $this->_slug : '' ) . ( ( ! $prefix_slug || empty( $id ) ) ? '' : '_' ) . $id, $load_options );
6431
+ }
6432
+
6433
+ /* Security
6434
+ ------------------------------------------------------------------------------------------------------------------*/
6435
+ private function _encrypt( $str ) {
6436
+ if ( is_null( $str ) ) {
6437
+ return null;
6438
+ }
6439
+
6440
+ return base64_encode( $str );
6441
+ }
6442
+
6443
+ private function _decrypt( $str ) {
6444
+ if ( is_null( $str ) ) {
6445
+ return null;
6446
+ }
6447
+
6448
+ return base64_decode( $str );
6449
+ }
6450
+
6451
+ /**
6452
+ * @author Vova Feldman (@svovaf)
6453
+ * @since 1.0.5
6454
+ *
6455
+ * @param FS_Entity $entity
6456
+ *
6457
+ * @return FS_Entity Return an encrypted clone entity.
6458
+ */
6459
+ private function _encrypt_entity( FS_Entity $entity ) {
6460
+ $clone = clone $entity;
6461
+ $props = get_object_vars( $entity );
6462
+
6463
+ foreach ( $props as $key => $val ) {
6464
+ $clone->{$key} = $this->_encrypt( $val );
6465
+ }
6466
+
6467
+ return $clone;
6468
+ }
6469
+
6470
+ /**
6471
+ * @author Vova Feldman (@svovaf)
6472
+ * @since 1.0.5
6473
+ *
6474
+ * @param FS_Entity $entity
6475
+ *
6476
+ * @return FS_Entity Return an decrypted clone entity.
6477
+ */
6478
+ private function _decrypt_entity( FS_Entity $entity ) {
6479
+ $clone = clone $entity;
6480
+ $props = get_object_vars( $entity );
6481
+
6482
+ foreach ( $props as $key => $val ) {
6483
+ $clone->{$key} = $this->_decrypt( $val );
6484
+ }
6485
+
6486
+ return $clone;
6487
+ }
6488
+
6489
+ /**
6490
+ * Tries to activate account based on POST params.
6491
+ *
6492
+ * @author Vova Feldman (@svovaf)
6493
+ * @since 1.0.2
6494
+ */
6495
+ function _activate_account() {
6496
+ if ( $this->is_registered() ) {
6497
+ // Already activated.
6498
+ return;
6499
+ }
6500
+
6501
+ self::_clean_admin_content_section();
6502
+
6503
+ if ( fs_request_is_action( 'activate' ) && fs_request_is_post() ) {
6504
+ // check_admin_referer( 'activate_' . $this->_plugin->public_key );
6505
+
6506
+ // Verify matching plugin details.
6507
+ if ( $this->_plugin->id != fs_request_get( 'plugin_id' ) || $this->_slug != fs_request_get( 'plugin_slug' ) ) {
6508
+ return;
6509
+ }
6510
+
6511
+ $user = new FS_User();
6512
+ $user->id = fs_request_get( 'user_id' );
6513
+ $user->public_key = fs_request_get( 'user_public_key' );
6514
+ $user->secret_key = fs_request_get( 'user_secret_key' );
6515
+ $user->email = fs_request_get( 'user_email' );
6516
+ $user->first = fs_request_get( 'user_first' );
6517
+ $user->last = fs_request_get( 'user_last' );
6518
+ $user->is_verified = fs_request_get_bool( 'user_is_verified' );
6519
+
6520
+ $site = new FS_Site();
6521
+ $site->id = fs_request_get( 'install_id' );
6522
+ $site->public_key = fs_request_get( 'install_public_key' );
6523
+ $site->secret_key = fs_request_get( 'install_secret_key' );
6524
+ $site->plan->id = fs_request_get( 'plan_id' );
6525
+ $site->plan->title = fs_request_get( 'plan_title' );
6526
+ $site->plan->name = fs_request_get( 'plan_name' );
6527
+
6528
+ $plans = array();
6529
+ $plans_data = json_decode( urldecode( fs_request_get( 'plans' ) ) );
6530
+ foreach ( $plans_data as $p ) {
6531
+ $plans[] = new FS_Plugin_Plan( $p );
6532
+ }
6533
+
6534
+ $this->_set_account( $user, $site, $plans );
6535
+
6536
+ // Reload the page with the keys.
6537
+ fs_redirect( $this->_get_admin_page_url() );
6538
+ }
6539
+ }
6540
+
6541
+ /**
6542
+ * @author Vova Feldman (@svovaf)
6543
+ * @since 1.0.7
6544
+ *
6545
+ * @param string $email
6546
+ *
6547
+ * @return FS_User|bool
6548
+ */
6549
+ static function _get_user_by_email( $email ) {
6550
+ self::$_static_logger->entrance();
6551
+
6552
+ $email = trim( strtolower( $email ) );
6553
+ $users = self::get_all_users();
6554
+ if ( is_array( $users ) ) {
6555
+ foreach ( $users as $u ) {
6556
+ if ( $email === trim( strtolower( $u->email ) ) ) {
6557
+ return $u;
6558
+ }
6559
+ }
6560
+ }
6561
+
6562
+ return false;
6563
+ }
6564
+
6565
+ #----------------------------------------------------------------------------------
6566
+ #region Account (Loading, Updates & Activation)
6567
+ #----------------------------------------------------------------------------------
6568
+
6569
+ /***
6570
+ * Load account information (user + site).
6571
+ *
6572
+ * @author Vova Feldman (@svovaf)
6573
+ * @since 1.0.1
6574
+ */
6575
+ private function _load_account() {
6576
+ $this->_logger->entrance();
6577
+
6578
+ $this->do_action( 'before_account_load' );
6579
+
6580
+ $sites = self::get_all_sites();
6581
+ $users = self::get_all_users();
6582
+ $plans = self::get_all_plans();
6583
+ $licenses = self::get_all_licenses();
6584
+
6585
+ if ( $this->_logger->is_on() && is_admin() ) {
6586
+ $this->_logger->log( 'sites = ' . var_export( $sites, true ) );
6587
+ $this->_logger->log( 'users = ' . var_export( $users, true ) );
6588
+ $this->_logger->log( 'plans = ' . var_export( $plans, true ) );
6589
+ $this->_logger->log( 'licenses = ' . var_export( $licenses, true ) );
6590
+ }
6591
+
6592
+ $site = isset( $sites[ $this->_slug ] ) ? $sites[ $this->_slug ] : false;
6593
+
6594
+ if ( is_object( $site ) &&
6595
+ is_numeric( $site->id ) &&
6596
+ is_numeric( $site->user_id ) &&
6597
+ is_object( $site->plan )
6598
+ ) {
6599
+ // Load site.
6600
+ $this->_site = clone $site;
6601
+ $this->_site->plan = $this->_decrypt_entity( $this->_site->plan );
6602
+
6603
+ // Load relevant user.
6604
+ $this->_user = clone $users[ $this->_site->user_id ];
6605
+
6606
+ // Load plans.
6607
+ $this->_plans = $plans[ $this->_slug ];
6608
+ if ( ! is_array( $this->_plans ) || empty( $this->_plans ) ) {
6609
+ $this->_sync_plans();
6610
+ } else {
6611
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
6612
+ if ( $this->_plans[ $i ] instanceof FS_Plugin_Plan ) {
6613
+ $this->_plans[ $i ] = $this->_decrypt_entity( $this->_plans[ $i ] );
6614
+ } else {
6615
+ unset( $this->_plans[ $i ] );
6616
+ }
6617
+ }
6618
+ }
6619
+
6620
+ // Load licenses.
6621
+ $this->_licenses = array();
6622
+ if ( is_array( $licenses ) &&
6623
+ isset( $licenses[ $this->_slug ] ) &&
6624
+ isset( $licenses[ $this->_slug ][ $this->_user->id ] )
6625
+ ) {
6626
+ $this->_licenses = $licenses[ $this->_slug ][ $this->_user->id ];
6627
+ }
6628
+
6629
+ $this->_license = $this->_get_license_by_id( $this->_site->license_id );
6630
+
6631
+ if ( $this->_site->version != $this->get_plugin_version() ) {
6632
+ // If stored install version is different than current installed plugin version,
6633
+ // then update plugin version event.
6634
+ $this->update_plugin_version_event();
6635
+ }
6636
+ }
6637
+
6638
+ $this->_register_account_hooks();
6639
+ }
6640
+
6641
+ /**
6642
+ * @author Vova Feldman (@svovaf)
6643
+ * @since 1.0.1
6644
+ *
6645
+ * @param FS_User $user
6646
+ * @param FS_Site $site
6647
+ * @param bool|array $plans
6648
+ */
6649
+ private function _set_account( FS_User $user, FS_Site $site, $plans = false ) {
6650
+ $site->slug = $this->_slug;
6651
+ $site->user_id = $user->id;
6652
+
6653
+ $this->_site = $site;
6654
+ $this->_user = $user;
6655
+ if ( false !== $plans ) {
6656
+ $this->_plans = $plans;
6657
+ }
6658
+
6659
+ $this->send_install_update();
6660
+
6661
+ $this->_store_account();
6662
+
6663
+ }
6664
+
6665
+ /**
6666
+ * @author Vova Feldman (@svovaf)
6667
+ * @since 1.1.7.4
6668
+ *
6669
+ * @param array $override_with
6670
+ *
6671
+ * @return array
6672
+ */
6673
+ function get_opt_in_params( $override_with = array() ) {
6674
+ $this->_logger->entrance();
6675
+
6676
+ $current_user = self::_get_current_wp_user();
6677
+
6678
+ $activation_action = $this->_slug . '_activate_new';
6679
+ $return_url = $this->is_anonymous() ?
6680
+ // If skipped already, then return to the account page.
6681
+ $this->get_account_url( $activation_action, array(), false ) :
6682
+ // Return to the module's main page.
6683
+ $this->_get_admin_page_url(
6684
+ '',
6685
+ array( 'fs_action' => $activation_action )
6686
+ );
6687
+
6688
+ $params = array(
6689
+ 'user_firstname' => $current_user->user_firstname,
6690
+ 'user_lastname' => $current_user->user_lastname,
6691
+ 'user_nickname' => $current_user->user_nicename,
6692
+ 'user_email' => $current_user->user_email,
6693
+ 'user_ip' => WP_FS__REMOTE_ADDR,
6694
+ 'plugin_slug' => $this->_slug,
6695
+ 'plugin_id' => $this->get_id(),
6696
+ 'plugin_public_key' => $this->get_public_key(),
6697
+ 'plugin_version' => $this->get_plugin_version(),
6698
+ 'return_url' => fs_nonce_url( $return_url, $activation_action ),
6699
+ 'account_url' => fs_nonce_url( $this->_get_admin_page_url(
6700
+ 'account',
6701
+ array( 'fs_action' => 'sync_user' )
6702
+ ), 'sync_user' ),
6703
+ 'site_uid' => $this->get_anonymous_id(),
6704
+ 'site_url' => get_site_url(),
6705
+ 'site_name' => get_bloginfo( 'name' ),
6706
+ 'platform_version' => get_bloginfo( 'version' ),
6707
+ 'sdk_version' => $this->version,
6708
+ 'programming_language_version' => phpversion(),
6709
+ 'language' => get_bloginfo( 'language' ),
6710
+ 'charset' => get_bloginfo( 'charset' ),
6711
+ 'is_premium' => $this->is_premium(),
6712
+ 'is_active' => true,
6713
+ 'is_uninstalled' => false,
6714
+ );
6715
+
6716
+ if ( $this->is_pending_activation() &&
6717
+ ! empty( $this->_storage->pending_license_key )
6718
+ ) {
6719
+ $params['license_key'] = $this->_storage->pending_license_key;
6720
+ }
6721
+
6722
+ if ( WP_FS__SKIP_EMAIL_ACTIVATION && $this->has_secret_key() ) {
6723
+ // Even though rand() is known for its security issues,
6724
+ // the timestamp adds another layer of protection.
6725
+ // It would be very hard for an attacker to get the secret key form here.
6726
+ // Plus, this should never run in production since the secret should never
6727
+ // be included in the production version.
6728
+ $params['ts'] = WP_FS__SCRIPT_START_TIME;
6729
+ $params['salt'] = md5( uniqid( rand() ) );
6730
+ $params['secure'] = md5(
6731
+ $params['ts'] .
6732
+ $params['salt'] .
6733
+ $this->get_secret_key()
6734
+ );
6735
+ }
6736
+
6737
+ return array_merge( $params, $override_with );
6738
+ }
6739
+
6740
+ /**
6741
+ * 1. If successful opt-in or pending activation returns the next page that the user should be redirected to.
6742
+ * 2. If there was an API error, return the API result.
6743
+ *
6744
+ * @author Vova Feldman (@svovaf)
6745
+ * @since 1.1.7.4
6746
+ *
6747
+ * @param string|bool $email
6748
+ * @param string|bool $first
6749
+ * @param string|bool $last
6750
+ * @param string|bool $license_key
6751
+ * @param bool $is_uninstall If "true", this means that the module is currently being uninstalled.
6752
+ * In this case, the user and site info will be sent to the server but no
6753
+ * data will be saved to the WP installation's database.
6754
+ * @param number|bool $trial_plan_id
6755
+ *
6756
+ * @return string|object
6757
+ * @use WP_Error
6758
+ */
6759
+ function opt_in(
6760
+ $email = false,
6761
+ $first = false,
6762
+ $last = false,
6763
+ $license_key = false,
6764
+ $is_uninstall = false,
6765
+ $trial_plan_id = false
6766
+ ) {
6767
+ $this->_logger->entrance();
6768
+
6769
+ if ( false === $email ) {
6770
+ $current_user = self::_get_current_wp_user();
6771
+ $email = $current_user->user_email;
6772
+ }
6773
+
6774
+ /**
6775
+ * @since 1.2.1 If activating with license key, ignore the context-user
6776
+ * since the user will be automatically loaded from the license.
6777
+ */
6778
+ if ( empty( $license_key ) ) {
6779
+ // Clean up pending license if opt-ing in again.
6780
+ $this->_storage->remove( 'pending_license_key' );
6781
+
6782
+ if ( ! $is_uninstall ) {
6783
+ $fs_user = Freemius::_get_user_by_email( $email );
6784
+ if ( is_object( $fs_user ) && ! $this->is_pending_activation() ) {
6785
+ return $this->install_with_current_user( false, $trial_plan_id );
6786
+ }
6787
+ }
6788
+ }
6789
+
6790
+ $user_info = array();
6791
+ if ( ! empty( $email ) ) {
6792
+ $user_info['user_email'] = $email;
6793
+ }
6794
+ if ( ! empty( $first ) ) {
6795
+ $user_info['user_firstname'] = $first;
6796
+ }
6797
+ if ( ! empty( $last ) ) {
6798
+ $user_info['user_lastname'] = $last;
6799
+ }
6800
+
6801
+ $params = $this->get_opt_in_params( $user_info );
6802
+
6803
+ $filtered_license_key = false;
6804
+ if ( is_string( $license_key ) ) {
6805
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
6806
+ $params['license_key'] = $filtered_license_key;
6807
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
6808
+ $params['trial_plan_id'] = $trial_plan_id;
6809
+ }
6810
+
6811
+ if ( $is_uninstall ) {
6812
+ $params['uninstall_params'] = array(
6813
+ 'reason_id' => $this->_storage->uninstall_reason->id,
6814
+ 'reason_info' => $this->_storage->uninstall_reason->info
6815
+ );
6816
+ }
6817
+
6818
+ $params['format'] = 'json';
6819
+
6820
+ $url = WP_FS__ADDRESS . '/action/service/user/install/';
6821
+ if ( isset( $_COOKIE['XDEBUG_SESSION'] ) ) {
6822
+ $url = add_query_arg( 'XDEBUG_SESSION', 'PHPSTORM', $url );
6823
+ }
6824
+
6825
+ $response = wp_remote_post( $url, array(
6826
+ 'method' => 'POST',
6827
+ 'body' => $params,
6828
+ 'timeout' => 15,
6829
+ ) );
6830
+
6831
+ if ( $response instanceof WP_Error ) {
6832
+ if ( 'https://' === substr( $url, 0, 8 ) &&
6833
+ isset( $response->errors ) &&
6834
+ isset( $response->errors['http_request_failed'] )
6835
+ ) {
6836
+ $http_error = strtolower( $response->errors['http_request_failed'][0] );
6837
+
6838
+ if ( false !== strpos( $http_error, 'ssl' ) ) {
6839
+ // Failed due to old version of cURL or Open SSL (SSLv3 is not supported by CloudFlare).
6840
+ $url = 'http://' . substr( $url, 8 );
6841
+
6842
+ $response = wp_remote_post( $url, array(
6843
+ 'method' => 'POST',
6844
+ 'body' => $params,
6845
+ 'timeout' => 15,
6846
+ ) );
6847
+ }
6848
+ }
6849
+ }
6850
+
6851
+ if ( is_wp_error( $response ) ) {
6852
+ /**
6853
+ * @var WP_Error $response
6854
+ */
6855
+ $result = new stdClass();
6856
+
6857
+ $error_code = $response->get_error_code();
6858
+ $error_type = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $error_code ) ) );
6859
+
6860
+ $result->error = (object) array(
6861
+ 'type' => $error_type,
6862
+ 'message' => $response->get_error_message(),
6863
+ 'code' => $error_code,
6864
+ 'http' => 402
6865
+ );
6866
+
6867
+ return $result;
6868
+ }
6869
+
6870
+ // Module is being uninstalled, don't handle the returned data.
6871
+ if ( $is_uninstall ) {
6872
+ return true;
6873
+ }
6874
+
6875
+ $decoded = @json_decode( $response['body'] );
6876
+
6877
+ if ( empty( $decoded ) ) {
6878
+ return false;
6879
+ }
6880
+
6881
+ if ( ! $this->is_api_result_object( $decoded ) ) {
6882
+ if ( ! empty( $params['license_key'] ) ) {
6883
+ // Pass the fully entered license key to the failure handler.
6884
+ $params['license_key'] = $license_key;
6885
+ }
6886
+
6887
+ return $is_uninstall ?
6888
+ $decoded :
6889
+ $this->apply_filters( 'after_install_failure', $decoded, $params );
6890
+ } else if ( isset( $decoded->pending_activation ) && $decoded->pending_activation ) {
6891
+ // Pending activation, add message.
6892
+ return $this->set_pending_confirmation(
6893
+ true,
6894
+ false,
6895
+ $filtered_license_key,
6896
+ ! empty( $params['trial_plan_id'] )
6897
+ );
6898
+ } else if ( isset( $decoded->install_secret_key ) ) {
6899
+ return $this->install_with_new_user(
6900
+ $decoded->user_id,
6901
+ $decoded->user_public_key,
6902
+ $decoded->user_secret_key,
6903
+ $decoded->install_id,
6904
+ $decoded->install_public_key,
6905
+ $decoded->install_secret_key,
6906
+ false
6907
+ );
6908
+ }
6909
+
6910
+ return $decoded;
6911
+ }
6912
+
6913
+ /**
6914
+ * Set user and site identities.
6915
+ *
6916
+ * @author Vova Feldman (@svovaf)
6917
+ * @since 1.0.9
6918
+ *
6919
+ * @param FS_User $user
6920
+ * @param FS_Site $site
6921
+ * @param bool $redirect
6922
+ *
6923
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
6924
+ */
6925
+ function setup_account( FS_User $user, FS_Site $site, $redirect = true ) {
6926
+ $this->_user = $user;
6927
+ $this->_site = $site;
6928
+
6929
+ $this->_sync_plans();
6930
+
6931
+ $this->_enrich_site_plan( false );
6932
+
6933
+ $this->_set_account( $user, $site );
6934
+
6935
+ if ( $this->is_trial() ) {
6936
+ // Store trial plan information.
6937
+ $this->_enrich_site_trial_plan( true );
6938
+ }
6939
+
6940
+ // If Freemius was OFF before, turn it on.
6941
+ $this->turn_on();
6942
+
6943
+ $this->do_action( 'after_account_connection', $user, $site );
6944
+
6945
+ if ( is_numeric( $site->license_id ) ) {
6946
+ $this->_license = $this->_get_license_by_id( $site->license_id );
6947
+ }
6948
+
6949
+ $this->_admin_notices->remove_sticky( 'connect_account' );
6950
+
6951
+ if ( $this->is_pending_activation() ) {
6952
+ // Remove pending activation sticky notice (if still exist).
6953
+ $this->_admin_notices->remove_sticky( 'activation_pending' );
6954
+
6955
+ // Remove plugin from pending activation mode.
6956
+ unset( $this->_storage->is_pending_activation );
6957
+
6958
+ if ( ! $this->is_paying_or_trial() ) {
6959
+ $this->_admin_notices->add_sticky(
6960
+ sprintf( __fs( 'plugin-x-activation-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
6961
+ 'activation_complete'
6962
+ );
6963
+ }
6964
+ }
6965
+
6966
+ if ( $this->is_paying_or_trial() && ! $this->is_premium() ) {
6967
+ if ( $this->is_paying() ) {
6968
+ $this->_admin_notices->add_sticky(
6969
+ sprintf(
6970
+ __fs( 'activation-with-plan-x-message', $this->_slug ),
6971
+ $this->_site->plan->title
6972
+ ) . $this->get_complete_upgrade_instructions(),
6973
+ 'plan_upgraded',
6974
+ __fs( 'yee-haw', $this->_slug ) . '!'
6975
+ );
6976
+ } else {
6977
+ $this->_admin_notices->add_sticky(
6978
+ sprintf(
6979
+ __fs( 'trial-started-message', $this->_slug ),
6980
+ '<i>' . $this->get_plugin_name() . '</i>'
6981
+ ) . $this->get_complete_upgrade_instructions( $this->_storage->trial_plan->title ),
6982
+ 'trial_started',
6983
+ __fs( 'yee-haw', $this->_slug ) . '!'
6984
+ );
6985
+ }
6986
+
6987
+ $this->_admin_notices->remove_sticky( array(
6988
+ 'trial_promotion',
6989
+ ) );
6990
+ }
6991
+
6992
+ $plugin_id = fs_request_get( 'plugin_id', false );
6993
+
6994
+ // Store activation time ONLY for plugins (not add-ons).
6995
+ if ( ! is_numeric( $plugin_id ) || ( $plugin_id == $this->_plugin->id ) ) {
6996
+ $this->_storage->activation_timestamp = WP_FS__SCRIPT_START_TIME;
6997
+ }
6998
+
6999
+ $next_page = '';
7000
+
7001
+ if ( is_numeric( $plugin_id ) ) {
7002
+ if ( $plugin_id != $this->_plugin->id ) {
7003
+ // Add-on was installed - sync license right after install.
7004
+ $next_page = $this->_get_sync_license_url( $plugin_id );
7005
+ }
7006
+ } else {
7007
+ /**
7008
+ * @author Vova Feldman (@svovaf)
7009
+ * @since 1.1.9 If site installed with a valid license, sync license.
7010
+ */
7011
+ if ( $this->is_paying() ) {
7012
+ $this->_sync_plugin_license( true );
7013
+ }
7014
+
7015
+ // Reload the page with the keys.
7016
+ $next_page = $this->is_anonymous() ?
7017
+ // If user previously skipped, redirect to account page.
7018
+ $this->get_account_url() :
7019
+ $this->get_after_activation_url( 'after_connect_url' );
7020
+ }
7021
+
7022
+ if ( ! empty( $next_page ) && $redirect ) {
7023
+ fs_redirect( $next_page );
7024
+ }
7025
+
7026
+ return $next_page;
7027
+ }
7028
+
7029
+ /**
7030
+ * Install plugin with new user information after approval.
7031
+ *
7032
+ * @author Vova Feldman (@svovaf)
7033
+ * @since 1.0.7
7034
+ */
7035
+ function _install_with_new_user() {
7036
+ $this->_logger->entrance();
7037
+
7038
+ if ( $this->is_registered() ) {
7039
+ return;
7040
+ }
7041
+
7042
+ if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
7043
+ // check_admin_referer( $this->_slug . '_activate_new' );
7044
+
7045
+ if ( fs_request_has( 'user_secret_key' ) ) {
7046
+ $this->install_with_new_user(
7047
+ fs_request_get( 'user_id' ),
7048
+ fs_request_get( 'user_public_key' ),
7049
+ fs_request_get( 'user_secret_key' ),
7050
+ fs_request_get( 'install_id' ),
7051
+ fs_request_get( 'install_public_key' ),
7052
+ fs_request_get( 'install_secret_key' )
7053
+ );
7054
+ } else if ( fs_request_has( 'pending_activation' ) ) {
7055
+ $this->set_pending_confirmation( fs_request_get( 'user_email' ), true );
7056
+ }
7057
+ }
7058
+ }
7059
+
7060
+ /**
7061
+ * Install plugin with new user.
7062
+ *
7063
+ * @author Vova Feldman (@svovaf)
7064
+ * @since 1.1.7.4
7065
+ *
7066
+ * @param number $user_id
7067
+ * @param string $user_public_key
7068
+ * @param string $user_secret_key
7069
+ * @param number $install_id
7070
+ * @param string $install_public_key
7071
+ * @param string $install_secret_key
7072
+ * @param bool $redirect
7073
+ *
7074
+ * @return string If redirect is `false`, returns the next page the user should be redirected to.
7075
+ */
7076
+ private function install_with_new_user(
7077
+ $user_id,
7078
+ $user_public_key,
7079
+ $user_secret_key,
7080
+ $install_id,
7081
+ $install_public_key,
7082
+ $install_secret_key,
7083
+ $redirect = true
7084
+ ) {
7085
+ $user = new FS_User();
7086
+ $user->id = $user_id;
7087
+ $user->public_key = $user_public_key;
7088
+ $user->secret_key = $user_secret_key;
7089
+
7090
+ $this->_user = $user;
7091
+ $user_result = $this->get_api_user_scope()->get();
7092
+ $user = new FS_User( $user_result );
7093
+ $this->_user = $user;
7094
+
7095
+ $site = new FS_Site();
7096
+ $site->id = $install_id;
7097
+ $site->public_key = $install_public_key;
7098
+ $site->secret_key = $install_secret_key;
7099
+
7100
+ $this->_site = $site;
7101
+ $site_result = $this->get_api_site_scope()->get();
7102
+ $site = new FS_Site( $site_result );
7103
+ $this->_site = $site;
7104
+
7105
+ return $this->setup_account( $this->_user, $this->_site, $redirect );
7106
+ }
7107
+
7108
+ /**
7109
+ * @author Vova Feldman (@svovaf)
7110
+ * @since 1.1.7.4
7111
+ *
7112
+ * @param string|bool $email
7113
+ * @param bool $redirect
7114
+ * @param string|bool $license_key Since 1.2.1.5
7115
+ * @param bool $is_pending_trial Since 1.2.1.5
7116
+ *
7117
+ * @return string Since 1.2.1.5 if $redirect is `false`, return the pending activation page.
7118
+ */
7119
+ private function set_pending_confirmation(
7120
+ $email = false,
7121
+ $redirect = true,
7122
+ $license_key = false,
7123
+ $is_pending_trial = false
7124
+ ) {
7125
+ // Install must be activated via email since
7126
+ // user with the same email already exist.
7127
+ $this->_storage->is_pending_activation = true;
7128
+ $this->_add_pending_activation_notice( $email, $is_pending_trial );
7129
+
7130
+ if ( ! empty( $license_key ) ) {
7131
+ $this->_storage->pending_license_key = $license_key;
7132
+ }
7133
+
7134
+ // Remove the opt-in sticky notice.
7135
+ $this->_admin_notices->remove_sticky( array(
7136
+ 'connect_account',
7137
+ 'trial_promotion',
7138
+ ) );
7139
+
7140
+ $next_page = $this->get_after_activation_url( 'after_pending_connect_url' );
7141
+
7142
+ // Reload the page with with pending activation message.
7143
+ if ( $redirect ) {
7144
+ fs_redirect( $next_page );
7145
+ }
7146
+
7147
+ return $next_page;
7148
+ }
7149
+
7150
+ /**
7151
+ * Install plugin with current logged WP user info.
7152
+ *
7153
+ * @author Vova Feldman (@svovaf)
7154
+ * @since 1.0.7
7155
+ */
7156
+ function _install_with_current_user() {
7157
+ $this->_logger->entrance();
7158
+
7159
+ if ( $this->is_registered() ) {
7160
+ return;
7161
+ }
7162
+
7163
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) && fs_request_is_post() ) {
7164
+ // check_admin_referer( 'activate_existing_' . $this->_plugin->public_key );
7165
+
7166
+ /**
7167
+ * @author Vova Feldman (@svovaf)
7168
+ * @since 1.1.9 Add license key if given.
7169
+ */
7170
+ $license_key = fs_request_get( 'license_secret_key' );
7171
+
7172
+ $this->install_with_current_user( $license_key );
7173
+ }
7174
+ }
7175
+
7176
+
7177
+ /**
7178
+ * @author Vova Feldman (@svovaf)
7179
+ * @since 1.1.7.4
7180
+ *
7181
+ * @param string|bool $license_key
7182
+ * @param number|bool $trial_plan_id
7183
+ * @param bool $redirect
7184
+ *
7185
+ * @return string|object If redirect is `false`, returns the next page the user should be redirected to, or the
7186
+ * API error object if failed to install.
7187
+ */
7188
+ private function install_with_current_user(
7189
+ $license_key = false,
7190
+ $trial_plan_id = false,
7191
+ $redirect = true
7192
+ ) {
7193
+ // Get current logged WP user.
7194
+ $current_user = self::_get_current_wp_user();
7195
+
7196
+ // Find the relevant FS user by the email.
7197
+ $user = self::_get_user_by_email( $current_user->user_email );
7198
+
7199
+ // We have to set the user before getting user scope API handler.
7200
+ $this->_user = $user;
7201
+
7202
+ $extra_install_params = array(
7203
+ 'uid' => $this->get_anonymous_id(),
7204
+ );
7205
+
7206
+ if ( ! empty( $license_key ) ) {
7207
+ $filtered_license_key = $this->apply_filters( 'license_key', $license_key );
7208
+ $extra_install_params['license_key'] = $filtered_license_key;
7209
+ } else if ( FS_Plugin_Plan::is_valid_id( $trial_plan_id ) ) {
7210
+ $extra_install_params['trial_plan_id'] = $trial_plan_id;
7211
+ }
7212
+
7213
+ $args = $this->get_install_data_for_api( $extra_install_params, false, false );
7214
+
7215
+ // Install the plugin.
7216
+ $install = $this->get_api_user_scope()->call(
7217
+ "/plugins/{$this->get_id()}/installs.json",
7218
+ 'post',
7219
+ $args
7220
+ );
7221
+
7222
+ if ( ! $this->is_api_result_entity( $install ) ) {
7223
+ if ( ! empty( $args['license_key'] ) ) {
7224
+ // Pass full the fully entered license key to the failure handler.
7225
+ $args['license_key'] = $license_key;
7226
+ }
7227
+
7228
+ $install = $this->apply_filters( 'after_install_failure', $install, $args );
7229
+
7230
+ $this->_admin_notices->add(
7231
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
7232
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $install->error->message . '</b>',
7233
+ __fs( 'oops', $this->_slug ) . '...',
7234
+ 'error'
7235
+ );
7236
+
7237
+ if ( $redirect ) {
7238
+ fs_redirect( $this->get_activation_url( array( 'error' => $install->error->message ) ) );
7239
+ }
7240
+
7241
+ return $install;
7242
+ }
7243
+
7244
+ $site = new FS_Site( $install );
7245
+ $this->_site = $site;
7246
+
7247
+ return $this->setup_account( $this->_user, $this->_site, $redirect );
7248
+ }
7249
+
7250
+ /**
7251
+ * Tries to activate add-on account based on parent plugin info.
7252
+ *
7253
+ * @author Vova Feldman (@svovaf)
7254
+ * @since 1.0.6
7255
+ *
7256
+ * @param Freemius $parent_fs
7257
+ */
7258
+ private function _activate_addon_account( Freemius $parent_fs ) {
7259
+ if ( $this->is_registered() ) {
7260
+ // Already activated.
7261
+ return;
7262
+ }
7263
+
7264
+ // Activate add-on with parent plugin credentials.
7265
+ $addon_install = $parent_fs->get_api_site_scope()->call(
7266
+ "/addons/{$this->_plugin->id}/installs.json",
7267
+ 'post',
7268
+ $this->get_install_data_for_api( array(
7269
+ 'uid' => $this->get_anonymous_id(),
7270
+ ), false, false )
7271
+ );
7272
+
7273
+ if ( isset( $addon_install->error ) ) {
7274
+ $this->_admin_notices->add(
7275
+ sprintf( __fs( 'could-not-activate-x', $this->_slug ), $this->get_plugin_name() ) . ' ' .
7276
+ __fs( 'contact-us-with-error-message', $this->_slug ) . ' ' . '<b>' . $addon_install->error->message . '</b>',
7277
+ __fs( 'oops', $this->_slug ) . '...',
7278
+ 'error'
7279
+ );
7280
+
7281
+ return;
7282
+ }
7283
+
7284
+ // First of all, set site info - otherwise we won't
7285
+ // be able to invoke API calls.
7286
+ $this->_site = new FS_Site( $addon_install );
7287
+
7288
+ // Sync add-on plans.
7289
+ $this->_sync_plans();
7290
+
7291
+ // Get site's current plan.
7292
+ $this->_site->plan = $this->_get_plan_by_id( $this->_site->plan->id );
7293
+
7294
+ // Get user information based on parent's plugin.
7295
+ $user = $parent_fs->get_user();
7296
+
7297
+ $this->_set_account( $user, $this->_site );
7298
+
7299
+ // Sync licenses.
7300
+ $this->_sync_licenses();
7301
+
7302
+ // Try to activate premium license.
7303
+ $this->_activate_license( true );
7304
+ }
7305
+
7306
+ #endregion
7307
+
7308
+ #----------------------------------------------------------------------------------
7309
+ #region Admin Menu Items
7310
+ #----------------------------------------------------------------------------------
7311
+
7312
+ private $_menu_items = array();
7313
+
7314
+ /**
7315
+ * @author Vova Feldman (@svovaf)
7316
+ * @since 1.0.7
7317
+ *
7318
+ * @return string
7319
+ */
7320
+ function get_menu_slug() {
7321
+ return $this->_menu->get_slug();
7322
+ }
7323
+
7324
+ /**
7325
+ * @author Vova Feldman (@svovaf)
7326
+ * @since 1.0.9
7327
+ */
7328
+ function _prepare_admin_menu() {
7329
+ // if ( ! $this->is_on() ) {
7330
+ // return;
7331
+ // }
7332
+
7333
+ if ( ! $this->has_api_connectivity() && ! $this->is_enable_anonymous() ) {
7334
+ $this->_menu->remove_menu_item();
7335
+ } else {
7336
+ $this->do_action( 'before_admin_menu_init' );
7337
+
7338
+ $this->add_menu_action();
7339
+ $this->add_submenu_items();
7340
+ }
7341
+ }
7342
+
7343
+ /**
7344
+ * Admin dashboard menu items modifications.
7345
+ *
7346
+ * NOTE: admin_menu action executed before admin_init.
7347
+ *
7348
+ * @author Vova Feldman (@svovaf)
7349
+ * @since 1.0.7
7350
+ *
7351
+ */
7352
+ private function add_menu_action() {
7353
+ if ( $this->is_activation_mode() ) {
7354
+ $this->override_plugin_menu_with_activation();
7355
+ } else {
7356
+ // If not registered try to install user.
7357
+ if ( ! $this->is_registered() &&
7358
+ fs_request_is_action( $this->_slug . '_activate_new' )
7359
+ ) {
7360
+ $this->_install_with_new_user();
7361
+ }
7362
+ }
7363
+ }
7364
+
7365
+ /**
7366
+ * @author Vova Feldman (@svovaf)
7367
+ * @since 1.0.1
7368
+ */
7369
+ function _redirect_on_clicked_menu_link() {
7370
+ $this->_logger->entrance();
7371
+
7372
+ $page = strtolower( isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '' );
7373
+
7374
+ $this->_logger->log( 'page = ' . $page );
7375
+
7376
+ foreach ( $this->_menu_items as $priority => $items ) {
7377
+ foreach ( $items as $item ) {
7378
+ if ( isset( $item['url'] ) ) {
7379
+ if ( $page === $this->_menu->get_slug( strtolower( $item['menu_slug'] ) ) ) {
7380
+ $this->_logger->log( 'Redirecting to ' . $item['url'] );
7381
+
7382
+ fs_redirect( $item['url'] );
7383
+ }
7384
+ }
7385
+ }
7386
+ }
7387
+ }
7388
+
7389
+ /**
7390
+ * Remove plugin's all admin menu items & pages, and replace with activation page.
7391
+ *
7392
+ * @author Vova Feldman (@svovaf)
7393
+ * @since 1.0.1
7394
+ */
7395
+ private function override_plugin_menu_with_activation() {
7396
+ $this->_logger->entrance();
7397
+
7398
+ $hook = false;
7399
+
7400
+ if ( $this->_menu->is_top_level() ) {
7401
+ $hook = $this->_menu->override_menu_item( array( &$this, '_connect_page_render' ) );
7402
+
7403
+ if ( false === $hook ) {
7404
+ // Create new menu item just for the opt-in.
7405
+ $hook = add_menu_page(
7406
+ $this->get_plugin_name(),
7407
+ $this->get_plugin_name(),
7408
+ 'manage_options',
7409
+ $this->_menu->get_slug(),
7410
+ array( &$this, '_connect_page_render' )
7411
+ );
7412
+ }
7413
+ } else {
7414
+ $menus = array( $this->_menu->get_parent_slug() );
7415
+
7416
+ if ( $this->_menu->is_override_exact() ) {
7417
+ // Make sure the current page is matching the activation page.
7418
+ $activation_url = strtolower( $this->get_activation_url() );
7419
+ $request_url = strtolower( $_SERVER['REQUEST_URI'] );
7420
+
7421
+ if ( parse_url( $activation_url, PHP_URL_PATH ) !== parse_url( $request_url, PHP_URL_PATH ) ) {
7422
+ // Different path - DO NOT OVERRIDE PAGE.
7423
+ return;
7424
+ }
7425
+
7426
+ $activation_url_params = array();
7427
+ parse_str( parse_url( $activation_url, PHP_URL_QUERY ), $activation_url_params );
7428
+
7429
+ $request_url_params = array();
7430
+ parse_str( parse_url( $request_url, PHP_URL_QUERY ), $request_url_params );
7431
+
7432
+
7433
+ foreach ( $activation_url_params as $key => $val ) {
7434
+ if ( ! isset( $request_url_params[ $key ] ) || $val != $request_url_params[ $key ] ) {
7435
+ // Not matching query string - DO NOT OVERRIDE PAGE.
7436
+ return;
7437
+ }
7438
+ }
7439
+ }
7440
+
7441
+ foreach ( $menus as $parent_slug ) {
7442
+ $hook = $this->_menu->override_submenu_action(
7443
+ $parent_slug,
7444
+ $this->_menu->get_raw_slug(),
7445
+ array( &$this, '_connect_page_render' )
7446
+ );
7447
+
7448
+ if ( false !== $hook ) {
7449
+ // Found plugin's submenu item.
7450
+ break;
7451
+ }
7452
+ }
7453
+ }
7454
+
7455
+ if ( $this->_menu->is_activation_page() ) {
7456
+ // Clean admin page from distracting content.
7457
+ self::_clean_admin_content_section();
7458
+ }
7459
+
7460
+ if ( false !== $hook ) {
7461
+ if ( fs_request_is_action( $this->_slug . '_activate_existing' ) ) {
7462
+ add_action( "load-$hook", array( &$this, '_install_with_current_user' ) );
7463
+ } else if ( fs_request_is_action( $this->_slug . '_activate_new' ) ) {
7464
+ add_action( "load-$hook", array( &$this, '_install_with_new_user' ) );
7465
+ }
7466
+ }
7467
+ }
7468
+
7469
+ /**
7470
+ * @author Leo Fajardo (leorw)
7471
+ * @since 1.2.1
7472
+ *
7473
+ * return string
7474
+ */
7475
+ function get_top_level_menu_capability() {
7476
+ global $menu;
7477
+
7478
+ $top_level_menu_slug = $this->get_top_level_menu_slug();
7479
+
7480
+ foreach ( $menu as $menu_info ) {
7481
+ /**
7482
+ * The second element in the menu info array is the capability/role that has access to the menu and the
7483
+ * third element is the menu slug.
7484
+ */
7485
+ if ( $menu_info[2] === $top_level_menu_slug ) {
7486
+ return $menu_info[1];
7487
+ }
7488
+ }
7489
+
7490
+ return 'read';
7491
+ }
7492
+
7493
+ /**
7494
+ * @author Vova Feldman (@svovaf)
7495
+ * @since 1.0.0
7496
+ *
7497
+ * @return string
7498
+ */
7499
+ private function get_top_level_menu_slug() {
7500
+ return ( $this->is_addon() ?
7501
+ $this->get_parent_instance()->_menu->get_top_level_menu_slug() :
7502
+ $this->_menu->get_top_level_menu_slug() );
7503
+ }
7504
+
7505
+ /**
7506
+ * Add default Freemius menu items.
7507
+ *
7508
+ * @author Vova Feldman (@svovaf)
7509
+ * @since 1.0.0
7510
+ */
7511
+ private function add_submenu_items() {
7512
+ $this->_logger->entrance();
7513
+
7514
+ if ( ! $this->is_addon() ) {
7515
+ if ( ! $this->is_activation_mode() ) {
7516
+ if ( $this->is_registered() ) {
7517
+ // Add user account page.
7518
+ $this->add_submenu_item(
7519
+ __fs( 'account', $this->_slug ),
7520
+ array( &$this, '_account_page_render' ),
7521
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'account', $this->_slug ),
7522
+ 'manage_options',
7523
+ 'account',
7524
+ array( &$this, '_account_page_load' ),
7525
+ WP_FS__DEFAULT_PRIORITY,
7526
+ $this->_menu->is_submenu_item_visible( 'account' )
7527
+ );
7528
+ }
7529
+
7530
+ // Add contact page.
7531
+ $this->add_submenu_item(
7532
+ __fs( 'contact-us', $this->_slug ),
7533
+ array( &$this, '_contact_page_render' ),
7534
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'contact-us', $this->_slug ),
7535
+ 'manage_options',
7536
+ 'contact',
7537
+ 'Freemius::_clean_admin_content_section',
7538
+ WP_FS__DEFAULT_PRIORITY,
7539
+ $this->_menu->is_submenu_item_visible( 'contact' )
7540
+ );
7541
+
7542
+ if ( $this->has_addons() ) {
7543
+ $this->add_submenu_item(
7544
+ __fs( 'add-ons', $this->_slug ),
7545
+ array( &$this, '_addons_page_render' ),
7546
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'add-ons', $this->_slug ),
7547
+ 'manage_options',
7548
+ 'addons',
7549
+ array( &$this, '_addons_page_load' ),
7550
+ WP_FS__LOWEST_PRIORITY - 1,
7551
+ $this->_menu->is_submenu_item_visible( 'addons' )
7552
+ );
7553
+ }
7554
+
7555
+ $show_pricing = ( $this->has_paid_plan() && $this->_menu->is_submenu_item_visible( 'pricing' ) );
7556
+ // If user don't have paid plans, add pricing page
7557
+ // to support add-ons checkout but don't add the submenu item.
7558
+ // || (isset( $_GET['page'] ) && $this->_menu->get_slug( 'pricing' ) == $_GET['page']);
7559
+
7560
+ $pricing_cta_slug = 'upgrade';
7561
+ $pricing_class = 'upgrade-mode';
7562
+ if ( $show_pricing ) {
7563
+ if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) &&
7564
+ ! $this->is_paying_or_trial()
7565
+ ) {
7566
+ // If running a trial promotion, modify the pricing to load the trial.
7567
+ $pricing_cta_slug = 'start-trial';
7568
+ $pricing_class = 'trial-mode';
7569
+ } else if ( $this->is_paying() ) {
7570
+ $pricing_cta_slug = 'pricing';
7571
+ $pricing_class = '';
7572
+ }
7573
+ }
7574
+
7575
+ // Add upgrade/pricing page.
7576
+ $this->add_submenu_item(
7577
+ __fs( $pricing_cta_slug, $this->_slug ) . '&nbsp;&nbsp;&#x27a4;',
7578
+ array( &$this, '_pricing_page_render' ),
7579
+ $this->get_plugin_name() . ' &ndash; ' . __fs( 'pricing', $this->_slug ),
7580
+ 'manage_options',
7581
+ 'pricing',
7582
+ 'Freemius::_clean_admin_content_section',
7583
+ WP_FS__LOWEST_PRIORITY,
7584
+ $show_pricing,
7585
+ $pricing_class
7586
+ );
7587
+ }
7588
+ }
7589
+
7590
+
7591
+ if ( 0 < count( $this->_menu_items ) ) {
7592
+ if ( ! $this->_menu->is_top_level() ) {
7593
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
7594
+
7595
+ // Append submenu items right after the plugin's submenu item.
7596
+ $this->order_sub_submenu_items();
7597
+ } else {
7598
+ // Append submenu items.
7599
+ $this->embed_submenu_items();
7600
+ }
7601
+ }
7602
+ }
7603
+
7604
+ /**
7605
+ * Moved the actual submenu item additions to a separated function,
7606
+ * in order to support sub-submenu items when the plugin's settings
7607
+ * only have a submenu and not top-level menu item.
7608
+ *
7609
+ * @author Vova Feldman (@svovaf)
7610
+ * @since 1.1.4
7611
+ */
7612
+ private function embed_submenu_items() {
7613
+ $item_template = $this->_menu->is_top_level() ?
7614
+ '<span class="fs-submenu-item %s %s %s">%s</span>' :
7615
+ '<span class="fs-submenu-item fs-sub %s %s %s">%s</span>';
7616
+
7617
+ $top_level_menu_capability = $this->get_top_level_menu_capability();
7618
+
7619
+ ksort( $this->_menu_items );
7620
+
7621
+ foreach ( $this->_menu_items as $priority => $items ) {
7622
+ foreach ( $items as $item ) {
7623
+ $capability = ( ! empty( $item['capability'] ) ? $item['capability'] : $top_level_menu_capability );
7624
+
7625
+ $menu_item = sprintf(
7626
+ $item_template,
7627
+ $this->_slug,
7628
+ $item['menu_slug'],
7629
+ ! empty( $item['class'] ) ? $item['class'] : '',
7630
+ $item['menu_title']
7631
+ );
7632
+
7633
+ $menu_slug = $this->_menu->get_slug( $item['menu_slug'] );
7634
+
7635
+ if ( ! isset( $item['url'] ) ) {
7636
+ $hook = add_submenu_page(
7637
+ $item['show_submenu'] ?
7638
+ $this->get_top_level_menu_slug() :
7639
+ null,
7640
+ $item['page_title'],
7641
+ $menu_item,
7642
+ $capability,
7643
+ $menu_slug,
7644
+ $item['render_function']
7645
+ );
7646
+
7647
+ if ( false !== $item['before_render_function'] ) {
7648
+ add_action( "load-$hook", $item['before_render_function'] );
7649
+ }
7650
+ } else {
7651
+ add_submenu_page(
7652
+ $this->get_top_level_menu_slug(),
7653
+ $item['page_title'],
7654
+ $menu_item,
7655
+ $capability,
7656
+ $menu_slug,
7657
+ array( $this, '' )
7658
+ );
7659
+ }
7660
+ }
7661
+ }
7662
+ }
7663
+
7664
+ /**
7665
+ * Re-order the submenu items so all Freemius added new submenu items
7666
+ * are added right after the plugin's settings submenu item.
7667
+ *
7668
+ * @author Vova Feldman (@svovaf)
7669
+ * @since 1.1.4
7670
+ */
7671
+ private function order_sub_submenu_items() {
7672
+ global $submenu;
7673
+
7674
+ $menu_slug = $this->_menu->get_top_level_menu_slug();
7675
+
7676
+ /**
7677
+ * Before "admin_menu" fires, WordPress will loop over the default submenus and remove pages for which the user
7678
+ * does not have permissions. So in case a plugin does not have top-level menu but does have submenus under any
7679
+ * of the default menus, only users that have the right role can access its sub-submenus (Account, Contact Us,
7680
+ * Support Forum, etc.) since $submenu[ $menu_slug ] will be empty if the user doesn't have permission.
7681
+ *
7682
+ * In case a plugin does not have submenus under any of the default menus but does have submenus under the menu
7683
+ * of another plugin, only users that have the right role can access its sub-submenus since we will use the
7684
+ * capability needed to access the parent menu as the capability for the submenus that we will add.
7685
+ */
7686
+ if ( empty( $submenu[ $menu_slug ] ) ) {
7687
+ return;
7688
+ }
7689
+
7690
+ $top_level_menu = &$submenu[ $menu_slug ];
7691
+
7692
+ $all_submenu_items_after = array();
7693
+
7694
+ $found_submenu_item = false;
7695
+
7696
+ foreach ( $top_level_menu as $submenu_id => $meta ) {
7697
+ if ( $found_submenu_item ) {
7698
+ // Remove all submenu items after the plugin's submenu item.
7699
+ $all_submenu_items_after[] = $meta;
7700
+ unset( $top_level_menu[ $submenu_id ] );
7701
+ }
7702
+
7703
+ if ( $this->_menu->get_raw_slug() === $meta[2] ) {
7704
+ // Found the submenu item, put all below.
7705
+ $found_submenu_item = true;
7706
+ continue;
7707
+ }
7708
+ }
7709
+
7710
+ // Embed all plugin's new submenu items.
7711
+ $this->embed_submenu_items();
7712
+
7713
+ // Start with specially high number to make sure it's appended.
7714
+ $i = max( 10000, max( array_keys( $top_level_menu ) ) + 1 );
7715
+ foreach ( $all_submenu_items_after as $meta ) {
7716
+ $top_level_menu[ $i ] = $meta;
7717
+ $i ++;
7718
+ }
7719
+
7720
+ // Sort submenu items.
7721
+ ksort( $top_level_menu );
7722
+ }
7723
+
7724
+ /**
7725
+ * Displays the Support Forum link when enabled.
7726
+ *
7727
+ * Can be filtered like so:
7728
+ *
7729
+ * function _fs_show_support_menu( $is_visible, $menu_id ) {
7730
+ * if ( 'support' === $menu_id ) {
7731
+ * return _fs->is_registered();
7732
+ * }
7733
+ * return $is_visible;
7734
+ * }
7735
+ * _fs()->add_filter('is_submenu_visible', '_fs_show_support_menu', 10, 2);
7736
+ *
7737
+ */
7738
+ function _add_default_submenu_items() {
7739
+ if ( ! $this->is_on() ) {
7740
+ return;
7741
+ }
7742
+
7743
+ if ( ! $this->is_activation_mode() ) {
7744
+ if ( $this->_menu->is_submenu_item_visible( 'support' ) ) {
7745
+ $this->add_submenu_link_item(
7746
+ $this->apply_filters( 'support_forum_submenu', __fs( 'support-forum', $this->_slug ) ),
7747
+ $this->apply_filters( 'support_forum_url', 'https://wordpress.org/support/plugin/' . $this->_slug ),
7748
+ 'wp-support-forum',
7749
+ null,
7750
+ 50
7751
+ );
7752
+ }
7753
+ }
7754
+ }
7755
+
7756
+ /**
7757
+ * @author Vova Feldman (@svovaf)
7758
+ * @since 1.0.1
7759
+ *
7760
+ * @param string $menu_title
7761
+ * @param callable $render_function
7762
+ * @param bool|string $page_title
7763
+ * @param string $capability
7764
+ * @param bool|string $menu_slug
7765
+ * @param bool|callable $before_render_function
7766
+ * @param int $priority
7767
+ * @param bool $show_submenu
7768
+ * @param string $class Since 1.2.1.5 can add custom classes to menu items.
7769
+ */
7770
+ function add_submenu_item(
7771
+ $menu_title,
7772
+ $render_function,
7773
+ $page_title = false,
7774
+ $capability = 'manage_options',
7775
+ $menu_slug = false,
7776
+ $before_render_function = false,
7777
+ $priority = WP_FS__DEFAULT_PRIORITY,
7778
+ $show_submenu = true,
7779
+ $class = ''
7780
+ ) {
7781
+ $this->_logger->entrance( 'Title = ' . $menu_title );
7782
+
7783
+ if ( $this->is_addon() ) {
7784
+ $parent_fs = $this->get_parent_instance();
7785
+
7786
+ if ( is_object( $parent_fs ) ) {
7787
+ $parent_fs->add_submenu_item(
7788
+ $menu_title,
7789
+ $render_function,
7790
+ $page_title,
7791
+ $capability,
7792
+ $menu_slug,
7793
+ $before_render_function,
7794
+ $priority,
7795
+ $show_submenu,
7796
+ $class
7797
+ );
7798
+
7799
+ return;
7800
+ }
7801
+ }
7802
+
7803
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
7804
+ $this->_menu_items[ $priority ] = array();
7805
+ }
7806
+
7807
+ $this->_menu_items[ $priority ][] = array(
7808
+ 'page_title' => is_string( $page_title ) ? $page_title : $menu_title,
7809
+ 'menu_title' => $menu_title,
7810
+ 'capability' => $capability,
7811
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
7812
+ 'render_function' => $render_function,
7813
+ 'before_render_function' => $before_render_function,
7814
+ 'show_submenu' => $show_submenu,
7815
+ 'class' => $class,
7816
+ );
7817
+ }
7818
+
7819
+ /**
7820
+ * @author Vova Feldman (@svovaf)
7821
+ * @since 1.0.1
7822
+ *
7823
+ * @param string $menu_title
7824
+ * @param string $url
7825
+ * @param bool $menu_slug
7826
+ * @param string $capability
7827
+ * @param int $priority
7828
+ *
7829
+ */
7830
+ function add_submenu_link_item(
7831
+ $menu_title,
7832
+ $url,
7833
+ $menu_slug = false,
7834
+ $capability = 'read',
7835
+ $priority = WP_FS__DEFAULT_PRIORITY
7836
+ ) {
7837
+ $this->_logger->entrance( 'Title = ' . $menu_title . '; Url = ' . $url );
7838
+
7839
+ if ( $this->is_addon() ) {
7840
+ $parent_fs = $this->get_parent_instance();
7841
+
7842
+ if ( is_object( $parent_fs ) ) {
7843
+ $parent_fs->add_submenu_link_item(
7844
+ $menu_title,
7845
+ $url,
7846
+ $menu_slug,
7847
+ $capability,
7848
+ $priority
7849
+ );
7850
+
7851
+ return;
7852
+ }
7853
+ }
7854
+
7855
+ if ( ! isset( $this->_menu_items[ $priority ] ) ) {
7856
+ $this->_menu_items[ $priority ] = array();
7857
+ }
7858
+
7859
+ $this->_menu_items[ $priority ][] = array(
7860
+ 'menu_title' => $menu_title,
7861
+ 'capability' => $capability,
7862
+ 'menu_slug' => is_string( $menu_slug ) ? $menu_slug : strtolower( $menu_title ),
7863
+ 'url' => $url,
7864
+ 'page_title' => $menu_title,
7865
+ 'render_function' => 'fs_dummy',
7866
+ 'before_render_function' => '',
7867
+ );
7868
+ }
7869
+
7870
+ #endregion ------------------------------------------------------------------
7871
+
7872
+ /* Actions / Hooks / Filters
7873
+ ------------------------------------------------------------------------------------------------------------------*/
7874
+ /**
7875
+ * @author Vova Feldman (@svovaf)
7876
+ * @since 1.1.7
7877
+ *
7878
+ * @param string $tag
7879
+ *
7880
+ * @return string
7881
+ */
7882
+ public function get_action_tag( $tag ) {
7883
+ return "fs_{$tag}_{$this->_slug}";
7884
+ }
7885
+
7886
+ /**
7887
+ * @author Vova Feldman (@svovaf)
7888
+ * @since 1.2.1
7889
+ *
7890
+ * @param string $tag
7891
+ *
7892
+ * @return string
7893
+ */
7894
+ private function get_ajax_action_tag( $tag ) {
7895
+ return 'wp_ajax_' . $this->get_action_tag( $tag );
7896
+ }
7897
+
7898
+ /**
7899
+ * Do action, specific for the current context plugin.
7900
+ *
7901
+ * @author Vova Feldman (@svovaf)
7902
+ * @since 1.0.1
7903
+ *
7904
+ * @param string $tag The name of the action to be executed.
7905
+ * @param mixed $arg,... Optional. Additional arguments which are passed on to the
7906
+ * functions hooked to the action. Default empty.
7907
+ *
7908
+ * @uses do_action()
7909
+ */
7910
+ function do_action( $tag, $arg = '' ) {
7911
+ $this->_logger->entrance( $tag );
7912
+
7913
+ $args = func_get_args();
7914
+
7915
+ call_user_func_array( 'do_action', array_merge(
7916
+ array( $this->get_action_tag( $tag ) ),
7917
+ array_slice( $args, 1 ) )
7918
+ );
7919
+ }
7920
+
7921
+ /**
7922
+ * Add action, specific for the current context plugin.
7923
+ *
7924
+ * @author Vova Feldman (@svovaf)
7925
+ * @since 1.0.1
7926
+ *
7927
+ * @param string $tag
7928
+ * @param callable $function_to_add
7929
+ * @param int $priority
7930
+ * @param int $accepted_args
7931
+ *
7932
+ * @uses add_action()
7933
+ */
7934
+ function add_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
7935
+ $this->_logger->entrance( $tag );
7936
+
7937
+ add_action( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
7938
+ }
7939
+
7940
+ /**
7941
+ * Add AJAX action, specific for the current context plugin.
7942
+ *
7943
+ * @author Vova Feldman (@svovaf)
7944
+ * @since 1.2.1
7945
+ *
7946
+ * @param string $tag
7947
+ * @param callable $function_to_add
7948
+ * @param int $priority
7949
+ * @param int $accepted_args
7950
+ *
7951
+ * @uses add_action()
7952
+ *
7953
+ * @return bool True if action added, false if no need to add the action since the AJAX call isn't matching.
7954
+ */
7955
+ function add_ajax_action( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
7956
+ $this->_logger->entrance( $tag );
7957
+
7958
+ if ( ! $this->is_ajax_action( $tag ) ) {
7959
+ return false;
7960
+ }
7961
+
7962
+ add_action( $this->get_ajax_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
7963
+
7964
+ $this->_logger->info( "$tag AJAX callback action added." );
7965
+
7966
+ return true;
7967
+ }
7968
+
7969
+ /**
7970
+ * Send a JSON response back to an Ajax request.
7971
+ *
7972
+ * @author Vova Feldman (@svovaf)
7973
+ * @since 1.2.1.5
7974
+ *
7975
+ * @param mixed $response
7976
+ */
7977
+ function shoot_ajax_response( $response ) {
7978
+ wp_send_json( $response );
7979
+ }
7980
+
7981
+ /**
7982
+ * Send a JSON response back to an Ajax request, indicating success.
7983
+ *
7984
+ * @author Vova Feldman (@svovaf)
7985
+ * @since 1.2.1.5
7986
+ *
7987
+ * @param mixed $data Data to encode as JSON, then print and exit.
7988
+ */
7989
+ function shoot_ajax_success( $data = null ) {
7990
+ wp_send_json_success( $data );
7991
+ }
7992
+
7993
+ /**
7994
+ * Send a JSON response back to an Ajax request, indicating failure.
7995
+ *
7996
+ * @author Vova Feldman (@svovaf)
7997
+ * @since 1.2.1.5
7998
+ *
7999
+ * @param mixed $error Optional error message.
8000
+ */
8001
+ function shoot_ajax_failure( $error = '' ) {
8002
+ $result = array( 'success' => false );
8003
+ if ( ! empty( $error ) ) {
8004
+ $result['error'] = $error;
8005
+ }
8006
+
8007
+ wp_send_json( $result );
8008
+ }
8009
+
8010
+ /**
8011
+ * Apply filter, specific for the current context plugin.
8012
+ *
8013
+ * @author Vova Feldman (@svovaf)
8014
+ * @since 1.0.9
8015
+ *
8016
+ * @param string $tag The name of the filter hook.
8017
+ * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
8018
+ *
8019
+ * @return mixed The filtered value after all hooked functions are applied to it.
8020
+ *
8021
+ * @uses apply_filters()
8022
+ */
8023
+ function apply_filters( $tag, $value ) {
8024
+ $this->_logger->entrance( $tag );
8025
+
8026
+ $args = func_get_args();
8027
+ array_unshift( $args, $this->_slug );
8028
+
8029
+ return call_user_func_array( 'fs_apply_filter', $args );
8030
+ }
8031
+
8032
+ /**
8033
+ * Add filter, specific for the current context plugin.
8034
+ *
8035
+ * @author Vova Feldman (@svovaf)
8036
+ * @since 1.0.9
8037
+ *
8038
+ * @param string $tag
8039
+ * @param callable $function_to_add
8040
+ * @param int $priority
8041
+ * @param int $accepted_args
8042
+ *
8043
+ * @uses add_filter()
8044
+ */
8045
+ function add_filter( $tag, $function_to_add, $priority = WP_FS__DEFAULT_PRIORITY, $accepted_args = 1 ) {
8046
+ $this->_logger->entrance( $tag );
8047
+
8048
+ add_filter( $this->get_action_tag( $tag ), $function_to_add, $priority, $accepted_args );
8049
+ }
8050
+
8051
+ /**
8052
+ * Check if has filter.
8053
+ *
8054
+ * @author Vova Feldman (@svovaf)
8055
+ * @since 1.1.4
8056
+ *
8057
+ * @param string $tag
8058
+ * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
8059
+ *
8060
+ * @return false|int
8061
+ *
8062
+ * @uses has_filter()
8063
+ */
8064
+ function has_filter( $tag, $function_to_check = false ) {
8065
+ $this->_logger->entrance( $tag );
8066
+
8067
+ return has_filter( $this->get_action_tag( $tag ), $function_to_check );
8068
+ }
8069
+
8070
+ /**
8071
+ * Override default i18n text phrases.
8072
+ *
8073
+ * @author Vova Feldman (@svovaf)
8074
+ * @since 1.1.6
8075
+ *
8076
+ * @param string[] string $key_value
8077
+ *
8078
+ * @uses fs_override_i18n()
8079
+ */
8080
+ function override_i18n( $key_value ) {
8081
+ fs_override_i18n( $key_value, $this->_slug );
8082
+ }
8083
+
8084
+ /* Account Page
8085
+ ------------------------------------------------------------------------------------------------------------------*/
8086
+ /**
8087
+ * Update site information.
8088
+ *
8089
+ * @author Vova Feldman (@svovaf)
8090
+ * @since 1.0.1
8091
+ *
8092
+ * @param bool $store Flush to Database if true.
8093
+ */
8094
+ private function _store_site( $store = true ) {
8095
+ $this->_logger->entrance();
8096
+
8097
+ if ( empty( $this->_site->id ) ) {
8098
+ $this->_logger->error( "Empty install ID, can't store site." );
8099
+
8100
+ return;
8101
+ }
8102
+
8103
+ $encrypted_site = clone $this->_site;
8104
+ $encrypted_site->plan = $this->_encrypt_entity( $this->_site->plan );
8105
+
8106
+ $sites = self::get_all_sites();
8107
+ $sites[ $this->_slug ] = $encrypted_site;
8108
+ self::$_accounts->set_option( 'sites', $sites, $store );
8109
+ }
8110
+
8111
+ /**
8112
+ * Update plugin's plans information.
8113
+ *
8114
+ * @author Vova Feldman (@svovaf)
8115
+ * @since 1.0.2
8116
+ *
8117
+ * @param bool $store Flush to Database if true.
8118
+ */
8119
+ private function _store_plans( $store = true ) {
8120
+ $this->_logger->entrance();
8121
+
8122
+ $plans = self::get_all_plans();
8123
+
8124
+ // Copy plans.
8125
+ $encrypted_plans = array();
8126
+ for ( $i = 0, $len = count( $this->_plans ); $i < $len; $i ++ ) {
8127
+ $encrypted_plans[] = $this->_encrypt_entity( $this->_plans[ $i ] );
8128
+ }
8129
+
8130
+ $plans[ $this->_slug ] = $encrypted_plans;
8131
+ self::$_accounts->set_option( 'plans', $plans, $store );
8132
+ }
8133
+
8134
+ /**
8135
+ * Update user's plugin licenses.
8136
+ *
8137
+ * @author Vova Feldman (@svovaf)
8138
+ * @since 1.0.5
8139
+ *
8140
+ * @param bool $store
8141
+ * @param string|bool $plugin_slug
8142
+ * @param FS_Plugin_License[] $licenses
8143
+ */
8144
+ private function _store_licenses( $store = true, $plugin_slug = false, $licenses = array() ) {
8145
+ $this->_logger->entrance();
8146
+
8147
+ $all_licenses = self::get_all_licenses();
8148
+
8149
+ if ( ! is_string( $plugin_slug ) ) {
8150
+ $plugin_slug = $this->_slug;
8151
+ $licenses = $this->_licenses;
8152
+ }
8153
+
8154
+ if ( ! isset( $all_licenses[ $plugin_slug ] ) ) {
8155
+ $all_licenses[ $plugin_slug ] = array();
8156
+ }
8157
+
8158
+ $all_licenses[ $plugin_slug ][ $this->_user->id ] = $licenses;
8159
+
8160
+ self::$_accounts->set_option( 'licenses', $all_licenses, $store );
8161
+ }
8162
+
8163
+ /**
8164
+ * Update user information.
8165
+ *
8166
+ * @author Vova Feldman (@svovaf)
8167
+ * @since 1.0.1
8168
+ *
8169
+ * @param bool $store Flush to Database if true.
8170
+ */
8171
+ private function _store_user( $store = true ) {
8172
+ $this->_logger->entrance();
8173
+
8174
+ if ( empty( $this->_user->id ) ) {
8175
+ $this->_logger->error( "Empty user ID, can't store user." );
8176
+
8177
+ return;
8178
+ }
8179
+
8180
+ $users = self::get_all_users();
8181
+ $users[ $this->_user->id ] = $this->_user;
8182
+ self::$_accounts->set_option( 'users', $users, $store );
8183
+ }
8184
+
8185
+ /**
8186
+ * Update new updates information.
8187
+ *
8188
+ * @author Vova Feldman (@svovaf)
8189
+ * @since 1.0.4
8190
+ *
8191
+ * @param FS_Plugin_Tag|null $update
8192
+ * @param bool $store Flush to Database if true.
8193
+ * @param bool|number $plugin_id
8194
+ */
8195
+ private function _store_update( $update, $store = true, $plugin_id = false ) {
8196
+ $this->_logger->entrance();
8197
+
8198
+ if ( $update instanceof FS_Plugin_Tag ) {
8199
+ $update->updated = time();
8200
+ }
8201
+
8202
+ if ( ! is_numeric( $plugin_id ) ) {
8203
+ $plugin_id = $this->_plugin->id;
8204
+ }
8205
+
8206
+ $updates = self::get_all_updates();
8207
+ $updates[ $plugin_id ] = $update;
8208
+ self::$_accounts->set_option( 'updates', $updates, $store );
8209
+ }
8210
+
8211
+ /**
8212
+ * Update new updates information.
8213
+ *
8214
+ * @author Vova Feldman (@svovaf)
8215
+ * @since 1.0.6
8216
+ *
8217
+ * @param FS_Plugin[] $plugin_addons
8218
+ * @param bool $store Flush to Database if true.
8219
+ */
8220
+ private function _store_addons( $plugin_addons, $store = true ) {
8221
+ $this->_logger->entrance();
8222
+
8223
+ $addons = self::get_all_addons();
8224
+ $addons[ $this->_plugin->id ] = $plugin_addons;
8225
+ self::$_accounts->set_option( 'addons', $addons, $store );
8226
+ }
8227
+
8228
+ /**
8229
+ * Delete plugin's associated add-ons.
8230
+ *
8231
+ * @author Vova Feldman (@svovaf)
8232
+ * @since 1.0.8
8233
+ *
8234
+ * @param bool $store
8235
+ *
8236
+ * @return bool
8237
+ */
8238
+ private function _delete_account_addons( $store = true ) {
8239
+ $all_addons = self::get_all_account_addons();
8240
+
8241
+ if ( ! isset( $all_addons[ $this->_plugin->id ] ) ) {
8242
+ return false;
8243
+ }
8244
+
8245
+ unset( $all_addons[ $this->_plugin->id ] );
8246
+
8247
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
8248
+
8249
+ return true;
8250
+ }
8251
+
8252
+ /**
8253
+ * Update account add-ons list.
8254
+ *
8255
+ * @author Vova Feldman (@svovaf)
8256
+ * @since 1.0.6
8257
+ *
8258
+ * @param FS_Plugin[] $addons
8259
+ * @param bool $store Flush to Database if true.
8260
+ */
8261
+ private function _store_account_addons( $addons, $store = true ) {
8262
+ $this->_logger->entrance();
8263
+
8264
+ $all_addons = self::get_all_account_addons();
8265
+ $all_addons[ $this->_plugin->id ] = $addons;
8266
+ self::$_accounts->set_option( 'account_addons', $all_addons, $store );
8267
+ }
8268
+
8269
+ /**
8270
+ * Store account params in the Database.
8271
+ *
8272
+ * @author Vova Feldman (@svovaf)
8273
+ * @since 1.0.1
8274
+ */
8275
+ private function _store_account() {
8276
+ $this->_logger->entrance();
8277
+
8278
+ $this->_store_site( false );
8279
+ $this->_store_user( false );
8280
+ $this->_store_plans( false );
8281
+ $this->_store_licenses( false );
8282
+
8283
+ self::$_accounts->store();
8284
+ }
8285
+
8286
+ /**
8287
+ * Sync user's information.
8288
+ *
8289
+ * @author Vova Feldman (@svovaf)
8290
+ * @since 1.0.3
8291
+ * @uses FS_Api
8292
+ */
8293
+ private function _handle_account_user_sync() {
8294
+ $this->_logger->entrance();
8295
+
8296
+ $api = $this->get_api_user_scope();
8297
+
8298
+ // Get user's information.
8299
+ $user = $api->get( '/', true );
8300
+
8301
+ if ( isset( $user->id ) ) {
8302
+ $this->_user->first = $user->first;
8303
+ $this->_user->last = $user->last;
8304
+ $this->_user->email = $user->email;
8305
+
8306
+ $is_menu_item_account_visible = $this->_menu->is_submenu_item_visible( 'account' );
8307
+
8308
+ if ( $user->is_verified &&
8309
+ ( ! isset( $this->_user->is_verified ) || false === $this->_user->is_verified )
8310
+ ) {
8311
+ $this->_user->is_verified = true;
8312
+
8313
+ $this->do_action( 'account_email_verified', $user->email );
8314
+
8315
+ $this->_admin_notices->add(
8316
+ __fs( 'email-verified-message', $this->_slug ),
8317
+ __fs( 'right-on', $this->_slug ) . '!',
8318
+ 'success',
8319
+ // Make admin sticky if account menu item is invisible,
8320
+ // since the page will be auto redirected to the plugin's
8321
+ // main settings page, and the non-sticky message
8322
+ // will disappear.
8323
+ ! $is_menu_item_account_visible,
8324
+ false,
8325
+ 'email_verified'
8326
+ );
8327
+ }
8328
+
8329
+ // Flush user details to DB.
8330
+ $this->_store_user();
8331
+
8332
+ $this->do_action( 'after_account_user_sync', $user );
8333
+
8334
+ /**
8335
+ * If account menu item is hidden, redirect to plugin's main settings page.
8336
+ *
8337
+ * @author Vova Feldman (@svovaf)
8338
+ * @since 1.1.6
8339
+ *
8340
+ * @link https://github.com/Freemius/wordpress-sdk/issues/6
8341
+ */
8342
+ if ( ! $is_menu_item_account_visible ) {
8343
+ fs_redirect( $this->_get_admin_page_url() );
8344
+ }
8345
+ }
8346
+ }
8347
+
8348
+ /**
8349
+ * @param bool $store
8350
+ *
8351
+ * @return FS_Plugin_Plan|object|false
8352
+ */
8353
+ private function _enrich_site_plan( $store = true ) {
8354
+ // Try to load plan from local cache.
8355
+ $plan = $this->_get_plan_by_id( $this->_site->plan->id );
8356
+
8357
+ if ( false === $plan ) {
8358
+ $plan = $this->_fetch_site_plan();
8359
+ }
8360
+
8361
+ if ( $plan instanceof FS_Plugin_Plan ) {
8362
+ $this->_update_plan( $plan, $store );
8363
+ }
8364
+
8365
+ return $plan;
8366
+ }
8367
+
8368
+ /**
8369
+ * @author Vova Feldman (@svovaf)
8370
+ * @since 1.0.9
8371
+ * @uses FS_Api
8372
+ *
8373
+ * @param bool $store
8374
+ *
8375
+ * @return FS_Plugin_Plan|object|false
8376
+ */
8377
+ private function _enrich_site_trial_plan( $store = true ) {
8378
+ // Try to load plan from local cache.
8379
+ $trial_plan = $this->_get_plan_by_id( $this->_site->trial_plan_id );
8380
+
8381
+ if ( false === $trial_plan ) {
8382
+ $trial_plan = $this->_fetch_site_plan( $this->_site->trial_plan_id );
8383
+ }
8384
+
8385
+ if ( $trial_plan instanceof FS_Plugin_Plan ) {
8386
+ $this->_storage->store( 'trial_plan', $trial_plan, $store );
8387
+ }
8388
+
8389
+ return $trial_plan;
8390
+ }
8391
+
8392
+ /**
8393
+ * @author Vova Feldman (@svovaf)
8394
+ * @since 1.0.9
8395
+ * @uses FS_Api
8396
+ *
8397
+ * @param number|bool $license_id
8398
+ *
8399
+ * @return FS_Subscription|object|bool
8400
+ */
8401
+ private function _fetch_site_license_subscription( $license_id = false ) {
8402
+ $this->_logger->entrance();
8403
+ $api = $this->get_api_site_scope();
8404
+
8405
+ if ( ! is_numeric( $license_id ) ) {
8406
+ $license_id = $this->_license->id;
8407
+ }
8408
+
8409
+ $result = $api->get( "/licenses/{$license_id}/subscriptions.json", true );
8410
+
8411
+ return ! isset( $result->error ) ?
8412
+ ( ( is_array( $result->subscriptions ) && 0 < count( $result->subscriptions ) ) ?
8413
+ new FS_Subscription( $result->subscriptions[0] ) :
8414
+ false
8415
+ ) :
8416
+ $result;
8417
+ }
8418
+
8419
+ /**
8420
+ * @author Vova Feldman (@svovaf)
8421
+ * @since 1.0.4
8422
+ * @uses FS_Api
8423
+ *
8424
+ * @param number|bool $plan_id
8425
+ *
8426
+ * @return FS_Plugin_Plan|object
8427
+ */
8428
+ private function _fetch_site_plan( $plan_id = false ) {
8429
+ $this->_logger->entrance();
8430
+ $api = $this->get_api_site_scope();
8431
+
8432
+ if ( ! is_numeric( $plan_id ) ) {
8433
+ $plan_id = $this->_site->plan->id;
8434
+ }
8435
+
8436
+ $plan = $api->get( "/plans/{$plan_id}.json", true );
8437
+
8438
+ return ! isset( $plan->error ) ? new FS_Plugin_Plan( $plan ) : $plan;
8439
+ }
8440
+
8441
+ /**
8442
+ * @author Vova Feldman (@svovaf)
8443
+ * @since 1.0.5
8444
+ * @uses FS_Api
8445
+ *
8446
+ * @return FS_Plugin_Plan[]|object
8447
+ */
8448
+ private function _fetch_plugin_plans() {
8449
+ $this->_logger->entrance();
8450
+ $api = $this->get_api_site_scope();
8451
+
8452
+ $result = $api->get( '/plans.json', true );
8453
+
8454
+ if ( $this->is_api_result_object( $result, 'plans' ) && is_array( $result->plans ) ) {
8455
+ for ( $i = 0, $len = count( $result->plans ); $i < $len; $i ++ ) {
8456
+ $result->plans[ $i ] = new FS_Plugin_Plan( $result->plans[ $i ] );
8457
+ }
8458
+
8459
+ $result = $result->plans;
8460
+ }
8461
+
8462
+ return $result;
8463
+ }
8464
+
8465
+ /**
8466
+ * @author Vova Feldman (@svovaf)
8467
+ * @since 1.0.5
8468
+ * @uses FS_Api
8469
+ *
8470
+ * @param number|bool $plugin_id
8471
+ * @param number|bool $site_license_id
8472
+ *
8473
+ * @return FS_Plugin_License[]|object
8474
+ */
8475
+ private function _fetch_licenses( $plugin_id = false, $site_license_id = false ) {
8476
+ $this->_logger->entrance();
8477
+
8478
+ $api = $this->get_api_user_scope();
8479
+
8480
+ if ( ! is_numeric( $plugin_id ) ) {
8481
+ $plugin_id = $this->_plugin->id;
8482
+ }
8483
+
8484
+ $result = $api->get( "/plugins/{$plugin_id}/licenses.json", true );
8485
+
8486
+ $is_site_license_synced = false;
8487
+
8488
+ $api_errors = array();
8489
+
8490
+ if ( $this->is_api_result_object( $result, 'licenses' ) &&
8491
+ is_array( $result->licenses )
8492
+ ) {
8493
+ for ( $i = 0, $len = count( $result->licenses ); $i < $len; $i ++ ) {
8494
+ $result->licenses[ $i ] = new FS_Plugin_License( $result->licenses[ $i ] );
8495
+
8496
+ if ( ( ! $is_site_license_synced ) && is_numeric( $site_license_id ) ) {
8497
+ $is_site_license_synced = ( $site_license_id == $result->licenses[ $i ]->id );
8498
+ }
8499
+ }
8500
+
8501
+ $result = $result->licenses;
8502
+ } else {
8503
+ $api_errors[] = $result;
8504
+ $result = array();
8505
+ }
8506
+
8507
+ if ( ! $is_site_license_synced ) {
8508
+ $api = $this->get_api_site_scope();
8509
+
8510
+ if ( is_numeric( $site_license_id ) ) {
8511
+ // Try to retrieve a foreign license that is linked to the install.
8512
+ $api_result = $api->call( '/licenses.json' );
8513
+
8514
+ if ( $this->is_api_result_object( $api_result, 'licenses' ) &&
8515
+ is_array( $api_result->licenses )
8516
+ ) {
8517
+ $licenses = $api_result->licenses;
8518
+
8519
+ if ( ! empty( $licenses ) ) {
8520
+ $result[] = new FS_Plugin_License( $licenses[0] );
8521
+ }
8522
+ } else {
8523
+ $api_errors[] = $api_result;
8524
+ }
8525
+ } else if ( is_object( $this->_license ) ) {
8526
+ // Fetch foreign license by ID and license key.
8527
+ $license = $api->get( "/licenses/{$this->_license->id}.json?license_key=" .
8528
+ urlencode( $this->_license->secret_key ) );
8529
+
8530
+ if ( $this->is_api_result_entity( $license ) ) {
8531
+ $result[] = new FS_Plugin_License( $license );
8532
+ } else {
8533
+ $api_errors[] = $license;
8534
+ }
8535
+ }
8536
+ }
8537
+
8538
+ if ( is_array( $result ) && 0 < count( $result ) ) {
8539
+ // If found at least one license, return license collection even if there are errors.
8540
+ return $result;
8541
+ }
8542
+
8543
+ if ( ! empty( $api_errors ) ) {
8544
+ // If found any errors and no licenses, return first error.
8545
+ return $api_errors[0];
8546
+ }
8547
+
8548
+ // Fallback to empty licenses list.
8549
+ return $result;
8550
+ }
8551
+
8552
+ /**
8553
+ * @author Vova Feldman (@svovaf)
8554
+ * @since 1.2.0
8555
+ * @uses FS_Api
8556
+ *
8557
+ * @param number|bool $plugin_id
8558
+ *
8559
+ * @return FS_Payment[]|object
8560
+ */
8561
+ function _fetch_payments( $plugin_id = false ) {
8562
+ $this->_logger->entrance();
8563
+
8564
+ $api = $this->get_api_user_scope();
8565
+
8566
+ if ( ! is_numeric( $plugin_id ) ) {
8567
+ $plugin_id = $this->_plugin->id;
8568
+ }
8569
+
8570
+ $result = $api->get( "/plugins/{$plugin_id}/payments.json", true );
8571
+
8572
+ if ( ! isset( $result->error ) ) {
8573
+ for ( $i = 0, $len = count( $result->payments ); $i < $len; $i ++ ) {
8574
+ $result->payments[ $i ] = new FS_Payment( $result->payments[ $i ] );
8575
+ }
8576
+ $result = $result->payments;
8577
+ }
8578
+
8579
+ return $result;
8580
+ }
8581
+
8582
+ /**
8583
+ * @author Vova Feldman (@svovaf)
8584
+ * @since 1.2.1.5
8585
+ * @uses FS_Api
8586
+ *
8587
+ * @return \FS_Billing|mixed
8588
+ */
8589
+ function _fetch_billing() {
8590
+ require_once WP_FS__DIR_INCLUDES . '/entities/class-fs-billing.php';
8591
+
8592
+ $billing = $this->get_api_user_scope()->call( 'billing.json' );
8593
+
8594
+ if ( $this->is_api_result_entity( $billing ) ) {
8595
+ $billing = new FS_Billing( $billing );
8596
+ }
8597
+
8598
+ return $billing;
8599
+ }
8600
+
8601
+ /**
8602
+ * @author Vova Feldman (@svovaf)
8603
+ * @since 1.0.4
8604
+ *
8605
+ * @param FS_Plugin_Plan $plan
8606
+ * @param bool $store
8607
+ */
8608
+ private function _update_plan( $plan, $store = false ) {
8609
+ $this->_logger->entrance();
8610
+
8611
+ $this->_site->plan = $plan;
8612
+ $this->_store_site( $store );
8613
+ }
8614
+
8615
+ /**
8616
+ * @author Vova Feldman (@svovaf)
8617
+ * @since 1.0.5
8618
+ *
8619
+ * @param FS_Plugin_License[] $licenses
8620
+ * @param string|bool $plugin_slug
8621
+ */
8622
+ private function _update_licenses( $licenses, $plugin_slug = false ) {
8623
+ $this->_logger->entrance();
8624
+
8625
+ if ( is_array( $licenses ) ) {
8626
+ for ( $i = 0, $len = count( $licenses ); $i < $len; $i ++ ) {
8627
+ $licenses[ $i ]->updated = time();
8628
+ }
8629
+ }
8630
+
8631
+ if ( ! is_string( $plugin_slug ) ) {
8632
+ $this->_licenses = $licenses;
8633
+ }
8634
+
8635
+ $this->_store_licenses( true, $plugin_slug, $licenses );
8636
+ }
8637
+
8638
+ /**
8639
+ * @author Vova Feldman (@svovaf)
8640
+ * @since 1.0.4
8641
+ *
8642
+ * @param bool|number $plugin_id
8643
+ * @param bool $flush Since 1.1.7.3
8644
+ *
8645
+ * @return object|false New plugin tag info if exist.
8646
+ */
8647
+ private function _fetch_newer_version( $plugin_id = false, $flush = true ) {
8648
+ $latest_tag = $this->_fetch_latest_version( $plugin_id, $flush );
8649
+
8650
+ if ( ! is_object( $latest_tag ) ) {
8651
+ return false;
8652
+ }
8653
+
8654
+ // Check if version is actually newer.
8655
+ $has_new_version =
8656
+ // If it's an non-installed add-on then always return latest.
8657
+ ( $this->_is_addon_id( $plugin_id ) && ! $this->is_addon_activated( $plugin_id ) ) ||
8658
+ // Compare versions.
8659
+ version_compare( $this->get_plugin_version(), $latest_tag->version, '<' );
8660
+
8661
+ $this->_logger->departure( $has_new_version ? 'Found newer plugin version ' . $latest_tag->version : 'No new version' );
8662
+
8663
+ return $has_new_version ? $latest_tag : false;
8664
+ }
8665
+
8666
+ /**
8667
+ * @author Vova Feldman (@svovaf)
8668
+ * @since 1.0.5
8669
+ *
8670
+ * @param bool|number $plugin_id
8671
+ * @param bool $flush Since 1.1.7.3
8672
+ *
8673
+ * @return bool|FS_Plugin_Tag
8674
+ */
8675
+ function get_update( $plugin_id = false, $flush = true ) {
8676
+ $this->_logger->entrance();
8677
+
8678
+ if ( ! is_numeric( $plugin_id ) ) {
8679
+ $plugin_id = $this->_plugin->id;
8680
+ }
8681
+
8682
+ $this->_check_updates( true, $plugin_id, $flush );
8683
+ $updates = $this->get_all_updates();
8684
+
8685
+ return isset( $updates[ $plugin_id ] ) && is_object( $updates[ $plugin_id ] ) ? $updates[ $plugin_id ] : false;
8686
+ }
8687
+
8688
+ /**
8689
+ * Check if site assigned with active license.
8690
+ *
8691
+ * @author Vova Feldman (@svovaf)
8692
+ * @since 1.0.6
8693
+ *
8694
+ * @deprecated Please use has_active_valid_license() instead because license can be cancelled.
8695
+ */
8696
+ function has_active_license() {
8697
+ return (
8698
+ is_object( $this->_license ) &&
8699
+ is_numeric( $this->_license->id ) &&
8700
+ ! $this->_license->is_expired()
8701
+ );
8702
+ }
8703
+
8704
+ /**
8705
+ * Check if site assigned with active & valid (not expired) license.
8706
+ *
8707
+ * @author Vova Feldman (@svovaf)
8708
+ * @since 1.2.1
8709
+ */
8710
+ function has_active_valid_license() {
8711
+ return (
8712
+ is_object( $this->_license ) &&
8713
+ is_numeric( $this->_license->id ) &&
8714
+ $this->_license->is_active() &&
8715
+ $this->_license->is_valid()
8716
+ );
8717
+ }
8718
+
8719
+ /**
8720
+ * Check if site assigned with license with enabled features.
8721
+ *
8722
+ * @author Vova Feldman (@svovaf)
8723
+ * @since 1.0.6
8724
+ *
8725
+ * @return bool
8726
+ */
8727
+ function has_features_enabled_license() {
8728
+ return (
8729
+ is_object( $this->_license ) &&
8730
+ is_numeric( $this->_license->id ) &&
8731
+ $this->_license->is_features_enabled()
8732
+ );
8733
+ }
8734
+
8735
+ /**
8736
+ * Check if user is a trial or have feature enabled license.
8737
+ *
8738
+ * @author Vova Feldman (@svovaf)
8739
+ * @since 1.1.7
8740
+ *
8741
+ * @return bool
8742
+ */
8743
+ function can_use_premium_code() {
8744
+ return $this->is_trial() || $this->has_features_enabled_license();
8745
+ }
8746
+
8747
+ /**
8748
+ * Sync site's plan.
8749
+ *
8750
+ * @author Vova Feldman (@svovaf)
8751
+ * @since 1.0.3
8752
+ *
8753
+ * @uses FS_Api
8754
+ *
8755
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
8756
+ * the admin.
8757
+ */
8758
+ private function _sync_license( $background = false ) {
8759
+ $this->_logger->entrance();
8760
+
8761
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
8762
+
8763
+ $is_addon_sync = ( ! $this->_plugin->is_addon() && $plugin_id != $this->get_id() );
8764
+
8765
+ if ( $is_addon_sync ) {
8766
+ $this->_sync_addon_license( $plugin_id, $background );
8767
+ } else {
8768
+ $this->_sync_plugin_license( $background );
8769
+ }
8770
+
8771
+ $this->do_action( 'after_account_plan_sync', $this->_site->plan->name );
8772
+ }
8773
+
8774
+ /**
8775
+ * Sync plugin's add-on license.
8776
+ *
8777
+ * @author Vova Feldman (@svovaf)
8778
+ * @since 1.0.6
8779
+ * @uses FS_Api
8780
+ *
8781
+ * @param number $addon_id
8782
+ * @param bool $background
8783
+ */
8784
+ private function _sync_addon_license( $addon_id, $background ) {
8785
+ $this->_logger->entrance();
8786
+
8787
+ if ( $this->is_addon_activated( $addon_id ) ) {
8788
+ // If already installed, use add-on sync.
8789
+ $fs_addon = self::get_instance_by_id( $addon_id );
8790
+ $fs_addon->_sync_license( $background );
8791
+
8792
+ return;
8793
+ }
8794
+
8795
+ // Validate add-on exists.
8796
+ $addon = $this->get_addon( $addon_id );
8797
+
8798
+ if ( ! is_object( $addon ) ) {
8799
+ return;
8800
+ }
8801
+
8802
+ // Add add-on into account add-ons.
8803
+ $account_addons = $this->get_account_addons();
8804
+ if ( ! is_array( $account_addons ) ) {
8805
+ $account_addons = array();
8806
+ }
8807
+ $account_addons[] = $addon->id;
8808
+ $account_addons = array_unique( $account_addons );
8809
+ $this->_store_account_addons( $account_addons );
8810
+
8811
+ // Load add-on licenses.
8812
+ $licenses = $this->_fetch_licenses( $addon->id );
8813
+
8814
+ // Sync add-on licenses.
8815
+ if ( $this->is_array_instanceof( $licenses, 'FS_Plugin_License' ) ) {
8816
+ $this->_update_licenses( $licenses, $addon->slug );
8817
+
8818
+ if ( ! $this->is_addon_installed( $addon->slug ) && FS_License_Manager::has_premium_license( $licenses ) ) {
8819
+ $plans_result = $this->get_api_site_or_plugin_scope()->get( "/addons/{$addon_id}/plans.json" );
8820
+
8821
+ if ( ! isset( $plans_result->error ) ) {
8822
+ $plans = array();
8823
+ foreach ( $plans_result->plans as $plan ) {
8824
+ $plans[] = new FS_Plugin_Plan( $plan );
8825
+ }
8826
+
8827
+ $this->_admin_notices->add_sticky(
8828
+ FS_Plan_Manager::instance()->has_free_plan( $plans ) ?
8829
+ sprintf(
8830
+ __fs( 'addon-successfully-upgraded-message', $this->_slug ),
8831
+ $addon->title
8832
+ ) . ' ' . $this->_get_latest_download_link(
8833
+ __fs( 'download-latest-version', $this->_slug ),
8834
+ $addon_id
8835
+ )
8836
+ :
8837
+ sprintf(
8838
+ __fs( 'addon-successfully-purchased-message', $this->_slug ),
8839
+ $addon->title
8840
+ ) . ' ' . $this->_get_latest_download_link(
8841
+ __fs( 'download-latest-version', $this->_slug ),
8842
+ $addon_id
8843
+ ),
8844
+ 'addon_plan_upgraded_' . $addon->slug,
8845
+ __fs( 'yee-haw', $this->_slug ) . '!'
8846
+ );
8847
+ }
8848
+ }
8849
+ }
8850
+ }
8851
+
8852
+ /**
8853
+ * Sync site's plugin plan.
8854
+ *
8855
+ * @author Vova Feldman (@svovaf)
8856
+ * @since 1.0.6
8857
+ * @uses FS_Api
8858
+ *
8859
+ * @param bool $background Hints the method if it's a background sync. If false, it means that was initiated by
8860
+ * the admin.
8861
+ */
8862
+ private function _sync_plugin_license( $background = false ) {
8863
+ $this->_logger->entrance();
8864
+
8865
+ /**
8866
+ * Sync site info.
8867
+ *
8868
+ * @todo This line will execute install sync on a daily basis, even if running the free version (for opted-in users). The reason we want to keep it that way is for cases when the user was a paying customer, then there was a failure in subscription payment, and then after some time the payment was successful. This could be heavily optimized. For example, we can skip the $flush if the current install was never associated with a paid version.
8869
+ */
8870
+ $site = $this->send_install_update( array(), true );
8871
+
8872
+ $plan_change = 'none';
8873
+
8874
+ if ( ! $this->is_api_result_entity( $site ) ) {
8875
+ // Show API messages only if not background sync or if paying customer.
8876
+ if ( ! $background || $this->is_paying() ) {
8877
+ // Try to ping API to see if not blocked.
8878
+ if ( ! FS_Api::test() ) {
8879
+ /**
8880
+ * Failed to ping API - blocked!
8881
+ *
8882
+ * @author Vova Feldman (@svovaf)
8883
+ * @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.
8884
+ */
8885
+ $api = $this->get_api_site_scope();
8886
+
8887
+ if ( ! self::$_global_admin_notices->has_sticky( 'api_blocked' ) ) {
8888
+ self::$_global_admin_notices->add(
8889
+ sprintf(
8890
+ __fs( 'server-blocking-access', $this->_slug ),
8891
+ $this->get_plugin_name(),
8892
+ '<a href="' . $api->get_url() . '" target="_blank">' . $api->get_url() . '</a>'
8893
+ ) . '<br> ' . __fs( 'server-error-message', $this->_slug ) . var_export( $site->error, true ),
8894
+ __fs( 'oops', $this->_slug ) . '...',
8895
+ 'error',
8896
+ $background,
8897
+ false,
8898
+ 'api_blocked'
8899
+ );
8900
+ }
8901
+ } else {
8902
+ // Authentication params are broken.
8903
+ $this->_admin_notices->add(
8904
+ __fs( 'wrong-authentication-param-message', $this->_slug ),
8905
+ __fs( 'oops', $this->_slug ) . '...',
8906
+ 'error'
8907
+ );
8908
+ }
8909
+ }
8910
+
8911
+ // No reason to continue with license sync while there are API issues.
8912
+ return;
8913
+ }
8914
+
8915
+ // Remove sticky API connectivity message.
8916
+ self::$_global_admin_notices->remove_sticky( 'api_blocked' );
8917
+
8918
+ $site = new FS_Site( $site );
8919
+
8920
+ // Sync plans.
8921
+ $this->_sync_plans();
8922
+
8923
+ if ( ! $this->has_paid_plan() ) {
8924
+ $this->_site = $site;
8925
+ $this->_enrich_site_plan( true );
8926
+ $this->_store_site();
8927
+ } else {
8928
+ /**
8929
+ * Sync licenses. Pass the site's license ID so that the foreign licenses will be fetched if the license
8930
+ * associated with that ID is not included in the user's licenses collection.
8931
+ */
8932
+ $this->_sync_licenses( $site->license_id );
8933
+
8934
+ // Check if plan / license changed.
8935
+ if ( ! FS_Entity::equals( $site->plan, $this->_site->plan ) ||
8936
+ // Check if trial started.
8937
+ $site->trial_plan_id != $this->_site->trial_plan_id ||
8938
+ $site->trial_ends != $this->_site->trial_ends ||
8939
+ // Check if license changed.
8940
+ $site->license_id != $this->_site->license_id
8941
+ ) {
8942
+ if ( $site->is_trial() && ( ! $this->_site->is_trial() || $site->trial_ends != $this->_site->trial_ends ) ) {
8943
+ // New trial started.
8944
+ $this->_site = $site;
8945
+ $plan_change = 'trial_started';
8946
+
8947
+ // Store trial plan information.
8948
+ $this->_enrich_site_trial_plan( true );
8949
+
8950
+ // For trial with subscription use-case.
8951
+ $new_license = is_null( $site->license_id ) ? null : $this->_get_license_by_id( $site->license_id );
8952
+
8953
+ if ( is_object( $new_license ) && $new_license->is_valid() ) {
8954
+ $this->_site = $site;
8955
+ $this->_update_site_license( $new_license );
8956
+ $this->_store_licenses();
8957
+ $this->_enrich_site_plan( true );
8958
+
8959
+ $this->_sync_site_subscription( $this->_license );
8960
+ }
8961
+ } else if ( $this->_site->is_trial() && ! $site->is_trial() && ! is_numeric( $site->license_id ) ) {
8962
+ // Was in trial, but now trial expired and no license ID.
8963
+ // New trial started.
8964
+ $this->_site = $site;
8965
+ $plan_change = 'trial_expired';
8966
+
8967
+ // Clear trial plan information.
8968
+ $this->_storage->trial_plan = null;
8969
+
8970
+ } else {
8971
+ $is_free = $this->is_free_plan();
8972
+
8973
+ // Make sure license exist and not expired.
8974
+ $new_license = is_null( $site->license_id ) ?
8975
+ null :
8976
+ $this->_get_license_by_id( $site->license_id );
8977
+
8978
+ if ( $is_free && is_null( $new_license ) && $this->has_any_license() && $this->_license->is_cancelled ) {
8979
+ // License cancelled.
8980
+ $this->_site = $site;
8981
+ $this->_update_site_license( $new_license );
8982
+ $this->_store_licenses();
8983
+ $this->_enrich_site_plan( true );
8984
+
8985
+ $plan_change = 'cancelled';
8986
+ } else if ( $is_free && ( ( ! is_object( $new_license ) || $new_license->is_expired() ) ) ) {
8987
+ // The license is expired, so ignore upgrade method.
8988
+ } else {
8989
+ // License changed.
8990
+ $this->_site = $site;
8991
+ $this->_update_site_license( $new_license );
8992
+ $this->_store_licenses();
8993
+ $this->_enrich_site_plan( true );
8994
+
8995
+ $plan_change = $is_free ?
8996
+ 'upgraded' :
8997
+ ( is_object( $new_license ) ?
8998
+ 'changed' :
8999
+ 'downgraded' );
9000
+ }
9001
+ }
9002
+
9003
+ // Store updated site info.
9004
+ $this->_store_site();
9005
+ } else {
9006
+ if ( is_object( $this->_license ) && $this->_license->is_expired() ) {
9007
+ if ( ! $this->has_features_enabled_license() ) {
9008
+ $this->_deactivate_license();
9009
+ $plan_change = 'downgraded';
9010
+ } else {
9011
+ $plan_change = 'expired';
9012
+ }
9013
+ }
9014
+
9015
+ if ( is_numeric( $site->license_id ) && is_object( $this->_license ) ) {
9016
+ $this->_sync_site_subscription( $this->_license );
9017
+ }
9018
+ }
9019
+ }
9020
+
9021
+ if ( $this->has_paid_plan() ) {
9022
+ switch ( $plan_change ) {
9023
+ case 'none':
9024
+ if ( ! $background && is_admin() ) {
9025
+ $plan = $this->is_trial() ?
9026
+ $this->_storage->trial_plan :
9027
+ $this->_site->plan;
9028
+
9029
+ $this->_admin_notices->add(
9030
+ sprintf(
9031
+ __fs( 'plan-did-not-change-message', $this->_slug ),
9032
+ '<i><b>' . $plan->title . ( $this->is_trial() ? ' ' . __fs( 'trial', $this->_slug ) : '' ) . '</b></i>'
9033
+ ) . ' ' . sprintf(
9034
+ '<a href="%s">%s</a>',
9035
+ $this->contact_url(
9036
+ 'bug',
9037
+ sprintf( __fs( 'plan-did-not-change-email-message', $this->_slug ),
9038
+ strtoupper( $plan->name )
9039
+ )
9040
+ ),
9041
+ __fs( 'contact-us-here', $this->_slug )
9042
+ ),
9043
+ __fs( 'hmm', $this->_slug ) . '...'
9044
+ );
9045
+ }
9046
+ break;
9047
+ case 'upgraded':
9048
+ $this->_admin_notices->add_sticky(
9049
+ sprintf(
9050
+ __fs( 'plan-upgraded-message', $this->_slug ),
9051
+ '<i>' . $this->get_plugin_name() . '</i>'
9052
+ ) . $this->get_complete_upgrade_instructions(),
9053
+ 'plan_upgraded',
9054
+ __fs( 'yee-haw', $this->_slug ) . '!'
9055
+ );
9056
+
9057
+ $this->_admin_notices->remove_sticky( array(
9058
+ 'trial_started',
9059
+ 'trial_promotion',
9060
+ 'trial_expired',
9061
+ 'activation_complete',
9062
+ ) );
9063
+ break;
9064
+ case 'changed':
9065
+ $this->_admin_notices->add_sticky(
9066
+ sprintf(
9067
+ __fs( 'plan-changed-to-x-message', $this->_slug ),
9068
+ $this->_site->plan->title
9069
+ ),
9070
+ 'plan_changed'
9071
+ );
9072
+
9073
+ $this->_admin_notices->remove_sticky( array(
9074
+ 'trial_started',
9075
+ 'trial_promotion',
9076
+ 'trial_expired',
9077
+ 'activation_complete',
9078
+ ) );
9079
+ break;
9080
+ case 'downgraded':
9081
+ $this->_admin_notices->add_sticky(
9082
+ sprintf( __fs( 'license-expired-blocking-message', $this->_slug ) ),
9083
+ 'license_expired',
9084
+ __fs( 'hmm', $this->_slug ) . '...'
9085
+ );
9086
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
9087
+ break;
9088
+ case 'cancelled':
9089
+ $this->_admin_notices->add(
9090
+ __fs( 'license-cancelled', $this->_slug ) . ' ' .
9091
+ sprintf(
9092
+ '<a href="%s">%s</a>',
9093
+ $this->contact_url( 'bug' ),
9094
+ __fs( 'contact-us-here', $this->_slug )
9095
+ ),
9096
+ __fs( 'hmm', $this->_slug ) . '...',
9097
+ 'error'
9098
+ );
9099
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
9100
+ break;
9101
+ case 'expired':
9102
+ $this->_admin_notices->add_sticky(
9103
+ sprintf( __fs( 'license-expired-non-blocking-message', $this->_slug ), $this->_site->plan->title ),
9104
+ 'license_expired',
9105
+ __fs( 'hmm', $this->_slug ) . '...'
9106
+ );
9107
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
9108
+ break;
9109
+ case 'trial_started':
9110
+ $this->_admin_notices->add_sticky(
9111
+ sprintf(
9112
+ __fs( 'trial-started-message', $this->_slug ),
9113
+ '<i>' . $this->get_plugin_name() . '</i>'
9114
+ ) . $this->get_complete_upgrade_instructions( $this->_storage->trial_plan->title ),
9115
+ 'trial_started',
9116
+ __fs( 'yee-haw', $this->_slug ) . '!'
9117
+ );
9118
+
9119
+ $this->_admin_notices->remove_sticky( array(
9120
+ 'trial_promotion',
9121
+ ) );
9122
+ break;
9123
+ case 'trial_expired':
9124
+ $this->_admin_notices->add_sticky(
9125
+ __fs( 'trial-expired-message', $this->_slug ),
9126
+ 'trial_expired',
9127
+ __fs( 'hmm', $this->_slug ) . '...'
9128
+ );
9129
+ $this->_admin_notices->remove_sticky( array(
9130
+ 'trial_started',
9131
+ 'trial_promotion',
9132
+ 'plan_upgraded',
9133
+ ) );
9134
+ break;
9135
+ }
9136
+ }
9137
+
9138
+ if ( 'none' !== $plan_change ) {
9139
+ $this->do_action( 'after_license_change', $plan_change, $this->_site->plan );
9140
+ }
9141
+ }
9142
+
9143
+ /**
9144
+ * @author Vova Feldman (@svovaf)
9145
+ * @since 1.0.5
9146
+ *
9147
+ * @param bool $background
9148
+ */
9149
+ protected function _activate_license( $background = false ) {
9150
+ $this->_logger->entrance();
9151
+
9152
+ $license_id = fs_request_get( 'license_id' );
9153
+
9154
+ if ( FS_Plugin_License::is_valid_id( $license_id ) && $license_id == $this->_site->license_id ) {
9155
+ // License is already activated.
9156
+ return;
9157
+ }
9158
+
9159
+ $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
9160
+ $this->_get_license_by_id( $license_id ) :
9161
+ $this->_get_available_premium_license();
9162
+
9163
+ if ( ! is_object( $premium_license ) ) {
9164
+ return;
9165
+ }
9166
+
9167
+ /**
9168
+ * If the premium license is already associated with the install, just
9169
+ * update the license reference (activation is not required).
9170
+ *
9171
+ * @since 1.1.9
9172
+ */
9173
+ if ( $premium_license->id == $this->_site->license_id ) {
9174
+ // License is already activated.
9175
+ $this->_update_site_license( $premium_license );
9176
+ $this->_enrich_site_plan( false );
9177
+ $this->_store_account();
9178
+
9179
+ return;
9180
+ }
9181
+
9182
+ if ( $this->_site->user_id != $premium_license->user_id ) {
9183
+ $api_request_params = array( 'license_key' => $premium_license->secret_key );
9184
+ } else {
9185
+ $api_request_params = array();
9186
+ }
9187
+
9188
+ $api = $this->get_api_site_scope();
9189
+ $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );
9190
+
9191
+ if ( ! $this->is_api_result_entity( $license ) ) {
9192
+ if ( ! $background ) {
9193
+ $this->_admin_notices->add( sprintf(
9194
+ '%s %s',
9195
+ __fs( 'license-activation-failed-message', $this->_slug ),
9196
+ ( is_object( $license ) && isset( $license->error ) ?
9197
+ $license->error->message :
9198
+ sprintf( '%s<br><code>%s</code>',
9199
+ __fs( 'server-error-message', $this->_slug ),
9200
+ var_export( $license, true )
9201
+ )
9202
+ )
9203
+ ),
9204
+ __fs( 'hmm', $this->_slug ) . '...',
9205
+ 'error'
9206
+ );
9207
+ }
9208
+
9209
+ return;
9210
+ }
9211
+
9212
+ $premium_license = new FS_Plugin_License( $license );
9213
+
9214
+ // Updated site plan.
9215
+ $site = $this->get_api_site_scope()->get( '/', true );
9216
+ if ( $this->is_api_result_entity( $site ) ) {
9217
+ $this->_site = new FS_Site( $site );
9218
+ }
9219
+ $this->_update_site_license( $premium_license );
9220
+ $this->_enrich_site_plan( false );
9221
+
9222
+ $this->_store_account();
9223
+
9224
+ if ( ! $background ) {
9225
+ $this->_admin_notices->add_sticky(
9226
+ __fs( 'license-activated-message', $this->_slug ) .
9227
+ $this->get_complete_upgrade_instructions(),
9228
+ 'license_activated',
9229
+ __fs( 'yee-haw', $this->_slug ) . '!'
9230
+ );
9231
+ }
9232
+
9233
+ $this->_admin_notices->remove_sticky( array(
9234
+ 'trial_promotion',
9235
+ 'license_expired',
9236
+ ) );
9237
+ }
9238
+
9239
+ /**
9240
+ * @author Vova Feldman (@svovaf)
9241
+ * @since 1.0.5
9242
+ *
9243
+ * @param bool $show_notice
9244
+ */
9245
+ protected function _deactivate_license( $show_notice = true ) {
9246
+ $this->_logger->entrance();
9247
+
9248
+ if ( ! is_object( $this->_license ) ) {
9249
+ $this->_admin_notices->add(
9250
+ sprintf( __fs( 'no-active-license-message', $this->_slug ), $this->_site->plan->title ),
9251
+ __fs( 'hmm', $this->_slug ) . '...'
9252
+ );
9253
+
9254
+ return;
9255
+ }
9256
+
9257
+ $api = $this->get_api_site_scope();
9258
+ $license = $api->call( "/licenses/{$this->_site->license_id}.json", 'delete' );
9259
+
9260
+ if ( isset( $license->error ) ) {
9261
+ $this->_admin_notices->add(
9262
+ __fs( 'license-deactivation-failed-message', $this->_slug ) . '<br> ' .
9263
+ __fs( 'server-error-message', $this->_slug ) . ' ' . var_export( $license->error, true ),
9264
+ __fs( 'hmm', $this->_slug ) . '...',
9265
+ 'error'
9266
+ );
9267
+
9268
+ return;
9269
+ }
9270
+
9271
+ // Update license cache.
9272
+ for ( $i = 0, $len = count( $this->_licenses ); $i < $len; $i ++ ) {
9273
+ if ( $license->id == $this->_licenses[ $i ]->id ) {
9274
+ $this->_licenses[ $i ] = new FS_Plugin_License( $license );
9275
+ }
9276
+ }
9277
+
9278
+ // Updated site plan to default.
9279
+ $this->_sync_plans();
9280
+ $this->_site->plan->id = $this->_plans[0]->id;
9281
+ // Unlink license from site.
9282
+ $this->_update_site_license( null );
9283
+ $this->_enrich_site_plan( false );
9284
+
9285
+ $this->_store_account();
9286
+
9287
+ if ( $show_notice ) {
9288
+ $this->_admin_notices->add(
9289
+ sprintf( __fs( 'license-deactivation-message', $this->_slug ), $this->_site->plan->title ),
9290
+ __fs( 'ok', $this->_slug )
9291
+ );
9292
+ }
9293
+
9294
+ $this->_admin_notices->remove_sticky( array(
9295
+ 'plan_upgraded',
9296
+ 'license_activated',
9297
+ ) );
9298
+ }
9299
+
9300
+ /**
9301
+ * Site plan downgrade.
9302
+ *
9303
+ * @author Vova Feldman (@svovaf)
9304
+ * @since 1.0.4
9305
+ *
9306
+ * @uses FS_Api
9307
+ */
9308
+ private function _downgrade_site() {
9309
+ $this->_logger->entrance();
9310
+
9311
+ $api = $this->get_api_site_scope();
9312
+ $site = $api->call( 'downgrade.json', 'put' );
9313
+
9314
+ $plan_downgraded = false;
9315
+ $plan = false;
9316
+ if ( $this->is_api_result_entity( $site ) ) {
9317
+ $prev_plan_id = $this->_site->plan->id;
9318
+
9319
+ // Update new site plan id.
9320
+ $this->_site->plan->id = $site->plan_id;
9321
+
9322
+ $plan = $this->_enrich_site_plan();
9323
+ $subscription = $this->_sync_site_subscription( $this->_license );
9324
+
9325
+ // Plan downgraded if plan was changed or subscription was cancelled.
9326
+ $plan_downgraded = ( $plan instanceof FS_Plugin_Plan && $prev_plan_id != $plan->id ) ||
9327
+ ( is_object( $subscription ) && ! isset( $subscription->error ) && ! $subscription->is_active() );
9328
+ } else {
9329
+ // handle different error cases.
9330
+
9331
+ }
9332
+
9333
+ if ( $plan_downgraded ) {
9334
+ // Remove previous sticky message about upgrade (if exist).
9335
+ $this->_admin_notices->remove_sticky( 'plan_upgraded' );
9336
+
9337
+ $this->_admin_notices->add(
9338
+ sprintf( __fs( 'plan-x-downgraded-message', $this->_slug ),
9339
+ $plan->title,
9340
+ human_time_diff( time(), strtotime( $this->_license->expiration ) )
9341
+ )
9342
+ );
9343
+
9344
+ // Store site updates.
9345
+ $this->_store_site();
9346
+ } else {
9347
+ $this->_admin_notices->add(
9348
+ __fs( 'plan-downgraded-failure-message', $this->_slug ),
9349
+ __fs( 'oops', $this->_slug ) . '...',
9350
+ 'error'
9351
+ );
9352
+ }
9353
+ }
9354
+
9355
+ /**
9356
+ * @author Vova Feldman (@svovaf)
9357
+ * @since 1.1.8.1
9358
+ *
9359
+ * @param bool|string $plan_name
9360
+ *
9361
+ * @return bool If trial was successfully started.
9362
+ */
9363
+ function start_trial( $plan_name = false ) {
9364
+ $this->_logger->entrance();
9365
+
9366
+ if ( $this->is_trial() ) {
9367
+ // Already in trial mode.
9368
+ $this->_admin_notices->add(
9369
+ __fs( 'in-trial-mode', $this->_slug ),
9370
+ __fs( 'oops', $this->_slug ) . '...',
9371
+ 'error'
9372
+ );
9373
+
9374
+ return false;
9375
+ }
9376
+
9377
+ if ( $this->_site->is_trial_utilized() ) {
9378
+ // Trial was already utilized.
9379
+ $this->_admin_notices->add(
9380
+ __fs( 'trial-utilized', $this->_slug ),
9381
+ __fs( 'oops', $this->_slug ) . '...',
9382
+ 'error'
9383
+ );
9384
+
9385
+ return false;
9386
+ }
9387
+
9388
+ if ( false !== $plan_name ) {
9389
+ $plan = $this->get_plan_by_name( $plan_name );
9390
+
9391
+ if ( false === $plan ) {
9392
+ // Plan doesn't exist.
9393
+ $this->_admin_notices->add(
9394
+ sprintf( __fs( 'trial-plan-x-not-exist', $this->_slug ), $plan_name ),
9395
+ __fs( 'oops', $this->_slug ) . '...',
9396
+ 'error'
9397
+ );
9398
+
9399
+ return false;
9400
+ }
9401
+
9402
+ if ( ! $plan->has_trial() ) {
9403
+ // Plan doesn't exist.
9404
+ $this->_admin_notices->add(
9405
+ sprintf( __fs( 'plan-x-no-trial', $this->_slug ), $plan_name ),
9406
+ __fs( 'oops', $this->_slug ) . '...',
9407
+ 'error'
9408
+ );
9409
+
9410
+ return false;
9411
+ }
9412
+ } else {
9413
+ if ( ! $this->has_trial_plan() ) {
9414
+ // None of the plans have a trial.
9415
+ $this->_admin_notices->add(
9416
+ __fs( 'no-trials', $this->_slug ),
9417
+ __fs( 'oops', $this->_slug ) . '...',
9418
+ 'error'
9419
+ );
9420
+
9421
+ return false;
9422
+ }
9423
+
9424
+ $plans_with_trial = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
9425
+
9426
+ $plan = $plans_with_trial[0];
9427
+ }
9428
+
9429
+ $api = $this->get_api_site_scope();
9430
+ $plan = $api->call( "plans/{$plan->id}/trials.json", 'post' );
9431
+
9432
+ if ( ! $this->is_api_result_entity( $plan ) ) {
9433
+ // Some API error while trying to start the trial.
9434
+ $this->_admin_notices->add(
9435
+ __fs( 'unexpected-api-error', $this->_slug ) . ' ' . var_export( $plan, true ),
9436
+ __fs( 'oops', $this->_slug ) . '...',
9437
+ 'error'
9438
+ );
9439
+
9440
+ return false;
9441
+ }
9442
+
9443
+ // Sync license.
9444
+ $this->_sync_license();
9445
+
9446
+ return $this->is_trial();
9447
+ }
9448
+
9449
+ /**
9450
+ * Cancel site trial.
9451
+ *
9452
+ * @author Vova Feldman (@svovaf)
9453
+ * @since 1.0.9
9454
+ *
9455
+ * @uses FS_Api
9456
+ */
9457
+ private function _cancel_trial() {
9458
+ $this->_logger->entrance();
9459
+
9460
+ if ( ! $this->is_trial() ) {
9461
+ $this->_admin_notices->add(
9462
+ __fs( 'trial-cancel-no-trial-message', $this->_slug ),
9463
+ __fs( 'oops', $this->_slug ) . '...',
9464
+ 'error'
9465
+ );
9466
+
9467
+ return;
9468
+ }
9469
+
9470
+ $api = $this->get_api_site_scope();
9471
+ $site = $api->call( 'trials.json', 'delete' );
9472
+
9473
+ $trial_cancelled = false;
9474
+
9475
+ if ( $this->is_api_result_entity( $site ) ) {
9476
+ $prev_trial_ends = $this->_site->trial_ends;
9477
+
9478
+ if ( $this->is_paid_trial() ) {
9479
+ $this->_license->expiration = $site->trial_ends;
9480
+ $this->_license->is_cancelled = true;
9481
+ $this->_update_site_license( $this->_license );
9482
+ $this->_store_licenses();
9483
+
9484
+ // Clear subscription reference.
9485
+ $this->_sync_site_subscription( null );
9486
+ }
9487
+
9488
+ // Update site info.
9489
+ $this->_site = new FS_Site( $site );
9490
+ $this->_enrich_site_plan();
9491
+
9492
+ $trial_cancelled = ( $prev_trial_ends != $site->trial_ends );
9493
+ } else {
9494
+ // handle different error cases.
9495
+
9496
+ }
9497
+
9498
+ if ( $trial_cancelled ) {
9499
+ // Remove previous sticky messages about upgrade or trial (if exist).
9500
+ $this->_admin_notices->remove_sticky( array(
9501
+ 'trial_started',
9502
+ 'trial_promotion',
9503
+ 'plan_upgraded',
9504
+ ) );
9505
+
9506
+ // Store site updates.
9507
+ $this->_store_site();
9508
+
9509
+ if ( ! $this->is_addon() ||
9510
+ ! $this->deactivate_premium_only_addon_without_license( true )
9511
+ ) {
9512
+ $this->_admin_notices->add(
9513
+ sprintf( __fs( 'trial-cancel-message', $this->_slug ), $this->_storage->trial_plan->title )
9514
+ );
9515
+ }
9516
+
9517
+ // Clear trial plan information.
9518
+ unset( $this->_storage->trial_plan );
9519
+ } else {
9520
+ $this->_admin_notices->add(
9521
+ __fs( 'trial-cancel-failure-message', $this->_slug ),
9522
+ __fs( 'oops', $this->_slug ) . '...',
9523
+ 'error'
9524
+ );
9525
+ }
9526
+ }
9527
+
9528
+ /**
9529
+ * @author Vova Feldman (@svovaf)
9530
+ * @since 1.0.6
9531
+ *
9532
+ * @param bool|number $plugin_id
9533
+ *
9534
+ * @return bool
9535
+ */
9536
+ private function _is_addon_id( $plugin_id ) {
9537
+ return is_numeric( $plugin_id ) && ( $this->get_id() != $plugin_id );
9538
+ }
9539
+
9540
+ /**
9541
+ * Check if user eligible to download premium version updates.
9542
+ *
9543
+ * @author Vova Feldman (@svovaf)
9544
+ * @since 1.0.6
9545
+ *
9546
+ * @return bool
9547
+ */
9548
+ private function _can_download_premium() {
9549
+ return $this->has_active_valid_license() ||
9550
+ ( $this->is_trial() && ! $this->get_trial_plan()->is_free() );
9551
+ }
9552
+
9553
+ /**
9554
+ *
9555
+ * @author Vova Feldman (@svovaf)
9556
+ * @since 1.0.6
9557
+ *
9558
+ * @param bool|number $addon_id
9559
+ * @param string $type "json" or "zip"
9560
+ *
9561
+ * @return string
9562
+ */
9563
+ private function _get_latest_version_endpoint( $addon_id = false, $type = 'json' ) {
9564
+
9565
+ $is_addon = $this->_is_addon_id( $addon_id );
9566
+
9567
+ $is_premium = null;
9568
+ if ( ! $is_addon ) {
9569
+ $is_premium = $this->_can_download_premium();
9570
+ } else if ( $this->is_addon_activated( $addon_id ) ) {
9571
+ $is_premium = self::get_instance_by_id( $addon_id )->_can_download_premium();
9572
+ }
9573
+
9574
+ return // If add-on, then append add-on ID.
9575
+ ( $is_addon ? "/addons/$addon_id" : '' ) .
9576
+ '/updates/latest.' . $type .
9577
+ // If add-on and not yet activated, try to fetch based on server licensing.
9578
+ ( is_bool( $is_premium ) ? '?is_premium=' . json_encode( $is_premium ) : '' );
9579
+ }
9580
+
9581
+ /**
9582
+ * @author Vova Feldman (@svovaf)
9583
+ * @since 1.0.4
9584
+ *
9585
+ * @param bool|number $addon_id
9586
+ * @param bool $flush Since 1.1.7.3
9587
+ *
9588
+ * @return object|false Plugin latest tag info.
9589
+ */
9590
+ function _fetch_latest_version( $addon_id = false, $flush = true ) {
9591
+ $this->_logger->entrance();
9592
+
9593
+ /**
9594
+ * @since 1.1.7.3 Check for plugin updates from Freemius only if opted-in.
9595
+ * @since 1.1.7.4 Also check updates for add-ons.
9596
+ */
9597
+ if ( ! $this->is_registered() &&
9598
+ ! $this->_is_addon_id( $addon_id )
9599
+ ) {
9600
+ return false;
9601
+ }
9602
+
9603
+ $tag = $this->get_api_site_or_plugin_scope()->get(
9604
+ $this->_get_latest_version_endpoint( $addon_id, 'json' ),
9605
+ $flush
9606
+ );
9607
+
9608
+ $latest_version = ( is_object( $tag ) && isset( $tag->version ) ) ? $tag->version : 'couldn\'t get';
9609
+
9610
+ $this->_logger->departure( 'Latest version ' . $latest_version );
9611
+
9612
+ return ( is_object( $tag ) && isset( $tag->version ) ) ? $tag : false;
9613
+ }
9614
+
9615
+ #----------------------------------------------------------------------------------
9616
+ #region Download Plugin
9617
+ #----------------------------------------------------------------------------------
9618
+
9619
+ /**
9620
+ * Download latest plugin version, based on plan.
9621
+ *
9622
+ * Not like _download_latest(), this will redirect the page
9623
+ * to secure download url to prevent dual download (from FS to WP server,
9624
+ * and then from WP server to the client / browser).
9625
+ *
9626
+ * @author Vova Feldman (@svovaf)
9627
+ * @since 1.0.9
9628
+ *
9629
+ * @param bool|number $plugin_id
9630
+ *
9631
+ * @uses FS_Api
9632
+ * @uses wp_redirect()
9633
+ */
9634
+ private function _download_latest_directly( $plugin_id = false ) {
9635
+ $this->_logger->entrance();
9636
+
9637
+ wp_redirect( $this->_get_latest_download_api_url( $plugin_id ) );
9638
+ }
9639
+
9640
+ /**
9641
+ * Get latest plugin FS API download URL.
9642
+ *
9643
+ * @author Vova Feldman (@svovaf)
9644
+ * @since 1.0.9
9645
+ *
9646
+ * @param bool|number $plugin_id
9647
+ *
9648
+ * @return string
9649
+ */
9650
+ private function _get_latest_download_api_url( $plugin_id = false ) {
9651
+ $this->_logger->entrance();
9652
+
9653
+ return $this->get_api_site_scope()->get_signed_url(
9654
+ $this->_get_latest_version_endpoint( $plugin_id, 'zip' )
9655
+ );
9656
+ }
9657
+
9658
+ /**
9659
+ * Get payment invoice URL.
9660
+ *
9661
+ * @author Vova Feldman (@svovaf)
9662
+ * @since 1.2.0
9663
+ *
9664
+ * @param bool|number $payment_id
9665
+ *
9666
+ * @return string
9667
+ */
9668
+ function _get_invoice_api_url( $payment_id = false ) {
9669
+ $this->_logger->entrance();
9670
+
9671
+ return $this->get_api_user_scope()->get_signed_url(
9672
+ "/payments/{$payment_id}/invoice.pdf"
9673
+ );
9674
+ }
9675
+
9676
+ /**
9677
+ * Get latest plugin download link.
9678
+ *
9679
+ * @author Vova Feldman (@svovaf)
9680
+ * @since 1.0.9
9681
+ *
9682
+ * @param string $label
9683
+ * @param bool|number $plugin_id
9684
+ *
9685
+ * @return string
9686
+ */
9687
+ private function _get_latest_download_link( $label, $plugin_id = false ) {
9688
+ return sprintf(
9689
+ '<a target="_blank" href="%s">%s</a>',
9690
+ $this->_get_latest_download_local_url( $plugin_id ),
9691
+ $label
9692
+ );
9693
+ }
9694
+
9695
+ /**
9696
+ * Get latest plugin download local URL.
9697
+ *
9698
+ * @author Vova Feldman (@svovaf)
9699
+ * @since 1.0.9
9700
+ *
9701
+ * @param bool|number $plugin_id
9702
+ *
9703
+ * @return string
9704
+ */
9705
+ function _get_latest_download_local_url( $plugin_id = false ) {
9706
+ // Add timestamp to protect from caching.
9707
+ $params = array( 'ts' => WP_FS__SCRIPT_START_TIME );
9708
+
9709
+ if ( ! empty( $plugin_id ) ) {
9710
+ $params['plugin_id'] = $plugin_id;
9711
+ }
9712
+
9713
+ return $this->get_account_url( 'download_latest', $params );
9714
+ }
9715
+
9716
+ #endregion Download Plugin ------------------------------------------------------------------
9717
+
9718
+ /**
9719
+ * @author Vova Feldman (@svovaf)
9720
+ * @since 1.0.4
9721
+ *
9722
+ * @uses FS_Api
9723
+ *
9724
+ * @param bool $background Hints the method if it's a background updates check. If false, it means that
9725
+ * was initiated by the admin.
9726
+ * @param bool|number $plugin_id
9727
+ * @param bool $flush Since 1.1.7.3
9728
+ */
9729
+ private function _check_updates( $background = false, $plugin_id = false, $flush = true ) {
9730
+ $this->_logger->entrance();
9731
+
9732
+ // Check if there's a newer version for download.
9733
+ $new_version = $this->_fetch_newer_version( $plugin_id, $flush );
9734
+
9735
+ $update = null;
9736
+ if ( is_object( $new_version ) ) {
9737
+ $update = new FS_Plugin_Tag( $new_version );
9738
+
9739
+ if ( ! $background ) {
9740
+ $this->_admin_notices->add(
9741
+ sprintf(
9742
+ __fs( 'version-x-released', $this->_slug ) . ' ' . __fs( 'please-download-x', $this->_slug ),
9743
+ $update->version,
9744
+ sprintf(
9745
+ '<a href="%s" target="_blank">%s</a>',
9746
+ $this->get_account_url( 'download_latest' ),
9747
+ sprintf( __fs( 'latest-x-version', $this->_slug ), $this->_site->plan->title )
9748
+ )
9749
+ ),
9750
+ __fs( 'new', $this->_slug ) . '!'
9751
+ );
9752
+ }
9753
+ } else if ( false === $new_version && ! $background ) {
9754
+ $this->_admin_notices->add(
9755
+ __fs( 'you-have-latest', $this->_slug ),
9756
+ __fs( 'you-are-good', $this->_slug )
9757
+ );
9758
+ }
9759
+
9760
+ $this->_store_update( $update, true, $plugin_id );
9761
+ }
9762
+
9763
+ /**
9764
+ * @author Vova Feldman (@svovaf)
9765
+ * @since 1.0.4
9766
+ *
9767
+ * @param bool $flush Since 1.1.7.3 add 24 hour cache by default.
9768
+ *
9769
+ * @return FS_Plugin[]
9770
+ *
9771
+ * @uses FS_Api
9772
+ */
9773
+ private function _sync_addons( $flush = false ) {
9774
+ $this->_logger->entrance();
9775
+
9776
+ $api = $this->get_api_site_or_plugin_scope();
9777
+
9778
+ /**
9779
+ * @since 1.2.1
9780
+ *
9781
+ * If there's a cached version of the add-ons and not asking
9782
+ * for a flush, just use the currently stored add-ons.
9783
+ */
9784
+ if ( ! $flush && $api->is_cached( '/addons.json?enriched=true' ) ) {
9785
+ $addons = self::get_all_addons();
9786
+
9787
+ return $addons[ $this->_plugin->id ];
9788
+ }
9789
+
9790
+ $result = $api->get( '/addons.json?enriched=true', $flush );
9791
+
9792
+ $addons = array();
9793
+ if ( $this->is_api_result_object( $result, 'plugins' ) &&
9794
+ is_array( $result->plugins )
9795
+ ) {
9796
+ for ( $i = 0, $len = count( $result->plugins ); $i < $len; $i ++ ) {
9797
+ $addons[ $i ] = new FS_Plugin( $result->plugins[ $i ] );
9798
+ }
9799
+
9800
+ $this->_store_addons( $addons, true );
9801
+ }
9802
+
9803
+ return $addons;
9804
+ }
9805
+
9806
+ /**
9807
+ * Handle user email update.
9808
+ *
9809
+ * @author Vova Feldman (@svovaf)
9810
+ * @since 1.0.3
9811
+ * @uses FS_Api
9812
+ *
9813
+ * @param string $new_email
9814
+ *
9815
+ * @return object
9816
+ */
9817
+ private function _update_email( $new_email ) {
9818
+ $this->_logger->entrance();
9819
+
9820
+
9821
+ $api = $this->get_api_user_scope();
9822
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,email,is_verified", 'put', array(
9823
+ 'email' => $new_email,
9824
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
9825
+ 'account',
9826
+ array( 'fs_action' => 'sync_user' )
9827
+ ),
9828
+ ) );
9829
+
9830
+ if ( ! isset( $user->error ) ) {
9831
+ $this->_user->email = $user->email;
9832
+ $this->_user->is_verified = $user->is_verified;
9833
+ $this->_store_user();
9834
+ } else {
9835
+ // handle different error cases.
9836
+
9837
+ }
9838
+
9839
+ return $user;
9840
+ }
9841
+
9842
+ #----------------------------------------------------------------------------------
9843
+ #region API Error Handling
9844
+ #----------------------------------------------------------------------------------
9845
+
9846
+ /**
9847
+ * @author Vova Feldman (@svovaf)
9848
+ * @since 1.1.1
9849
+ *
9850
+ * @param mixed $result
9851
+ *
9852
+ * @return bool Is API result contains an error.
9853
+ */
9854
+ private function is_api_error( $result ) {
9855
+ return FS_Api::is_api_error( $result );
9856
+ }
9857
+
9858
+ /**
9859
+ * Checks if given API result is a non-empty and not an error object.
9860
+ *
9861
+ * @author Vova Feldman (@svovaf)
9862
+ * @since 1.2.1.5
9863
+ *
9864
+ * @param mixed $result
9865
+ * @param string|null $required_property Optional property we want to verify that is set.
9866
+ *
9867
+ * @return bool
9868
+ */
9869
+ function is_api_result_object( $result, $required_property = null ) {
9870
+ return FS_Api::is_api_result_object( $result, $required_property );
9871
+ }
9872
+
9873
+ /**
9874
+ * Checks if given API result is a non-empty entity object with non-empty ID.
9875
+ *
9876
+ * @author Vova Feldman (@svovaf)
9877
+ * @since 1.2.1.5
9878
+ *
9879
+ * @param mixed $result
9880
+ *
9881
+ * @return bool
9882
+ */
9883
+ private function is_api_result_entity( $result ) {
9884
+ return FS_Api::is_api_result_entity( $result );
9885
+ }
9886
+
9887
+ #endregion
9888
+
9889
+ /**
9890
+ * Make sure a given argument is an array of a specific type.
9891
+ *
9892
+ * @author Vova Feldman (@svovaf)
9893
+ * @since 1.2.1.5
9894
+ *
9895
+ * @param mixed $array
9896
+ * @param string $class
9897
+ *
9898
+ * @return bool
9899
+ */
9900
+ private function is_array_instanceof( $array, $class ) {
9901
+ return ( is_array( $array ) && ( empty( $array ) || $array[0] instanceof $class ) );
9902
+ }
9903
+
9904
+ /**
9905
+ * Start install ownership change.
9906
+ *
9907
+ * @author Vova Feldman (@svovaf)
9908
+ * @since 1.1.1
9909
+ * @uses FS_Api
9910
+ *
9911
+ * @param string $candidate_email
9912
+ *
9913
+ * @return bool Is ownership change successfully initiated.
9914
+ */
9915
+ private function init_change_owner( $candidate_email ) {
9916
+ $this->_logger->entrance();
9917
+
9918
+ $api = $this->get_api_site_scope();
9919
+ $result = $api->call( "/users/{$this->_user->id}.json", 'put', array(
9920
+ 'email' => $candidate_email,
9921
+ 'after_confirm_url' => $this->_get_admin_page_url(
9922
+ 'account',
9923
+ array( 'fs_action' => 'change_owner' )
9924
+ ),
9925
+ ) );
9926
+
9927
+ return ! $this->is_api_error( $result );
9928
+ }
9929
+
9930
+ /**
9931
+ * Handle install ownership change.
9932
+ *
9933
+ * @author Vova Feldman (@svovaf)
9934
+ * @since 1.1.1
9935
+ * @uses FS_Api
9936
+ *
9937
+ * @return bool Was ownership change successfully complete.
9938
+ */
9939
+ private function complete_change_owner() {
9940
+ $this->_logger->entrance();
9941
+
9942
+ $site_result = $this->get_api_site_scope( true )->get();
9943
+ $site = new FS_Site( $site_result );
9944
+ $this->_site = $site;
9945
+
9946
+ $user = new FS_User();
9947
+ $user->id = fs_request_get( 'user_id' );
9948
+
9949
+ // Validate install's user and given user.
9950
+ if ( $user->id != $this->_site->user_id ) {
9951
+ return false;
9952
+ }
9953
+
9954
+ $user->public_key = fs_request_get( 'user_public_key' );
9955
+ $user->secret_key = fs_request_get( 'user_secret_key' );
9956
+
9957
+ // Fetch new user information.
9958
+ $this->_user = $user;
9959
+ $user_result = $this->get_api_user_scope( true )->get();
9960
+ $user = new FS_User( $user_result );
9961
+ $this->_user = $user;
9962
+
9963
+ $this->_set_account( $user, $site );
9964
+
9965
+ return true;
9966
+ }
9967
+
9968
+ /**
9969
+ * Handle user name update.
9970
+ *
9971
+ * @author Vova Feldman (@svovaf)
9972
+ * @since 1.0.9
9973
+ * @uses FS_Api
9974
+ *
9975
+ * @return object
9976
+ */
9977
+ private function update_user_name() {
9978
+ $this->_logger->entrance();
9979
+ $name = fs_request_get( 'fs_user_name_' . $this->_slug, '' );
9980
+
9981
+ $api = $this->get_api_user_scope();
9982
+ $user = $api->call( "?plugin_id={$this->_plugin->id}&fields=id,first,last", 'put', array(
9983
+ 'name' => $name,
9984
+ ) );
9985
+
9986
+ if ( ! isset( $user->error ) ) {
9987
+ $this->_user->first = $user->first;
9988
+ $this->_user->last = $user->last;
9989
+ $this->_store_user();
9990
+ } else {
9991
+ // handle different error cases.
9992
+
9993
+ }
9994
+
9995
+ return $user;
9996
+ }
9997
+
9998
+ /**
9999
+ * Verify user email.
10000
+ *
10001
+ * @author Vova Feldman (@svovaf)
10002
+ * @since 1.0.3
10003
+ * @uses FS_Api
10004
+ */
10005
+ private function verify_email() {
10006
+ $this->_handle_account_user_sync();
10007
+
10008
+ if ( $this->_user->is_verified() ) {
10009
+ return;
10010
+ }
10011
+
10012
+ $api = $this->get_api_site_scope();
10013
+ $result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
10014
+ 'after_email_confirm_url' => $this->_get_admin_page_url(
10015
+ 'account',
10016
+ array( 'fs_action' => 'sync_user' )
10017
+ )
10018
+ ) );
10019
+
10020
+ if ( ! isset( $result->error ) ) {
10021
+ $this->_admin_notices->add( sprintf(
10022
+ __fs( 'verification-email-sent-message', $this->_slug ),
10023
+ sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
10024
+ ) );
10025
+ } else {
10026
+ // handle different error cases.
10027
+
10028
+ }
10029
+ }
10030
+
10031
+ /**
10032
+ * @author Vova Feldman (@svovaf)
10033
+ * @since 1.1.2
10034
+ *
10035
+ * @param array $params
10036
+ *
10037
+ * @return string
10038
+ */
10039
+ private function get_activation_url( $params = array() ) {
10040
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params ) );
10041
+ }
10042
+
10043
+ /**
10044
+ * @author Vova Feldman (@svovaf)
10045
+ * @since 1.2.1.5
10046
+ *
10047
+ * @param array $params
10048
+ *
10049
+ * @return string
10050
+ */
10051
+ function get_reconnect_url( $params = array() ) {
10052
+ $params['fs_action'] = 'reset_anonymous_mode';
10053
+ $params['fs_slug'] = $this->_slug;
10054
+
10055
+ return $this->apply_filters( 'connect_url', $this->_get_admin_page_url( '', $params ) );
10056
+ }
10057
+
10058
+ /**
10059
+ * Get the URL of the page that should be loaded after the user connect or skip in the opt-in screen.
10060
+ *
10061
+ * @author Vova Feldman (@svovaf)
10062
+ * @since 1.1.3
10063
+ *
10064
+ * @param string $filter Filter name.
10065
+ *
10066
+ * @return string
10067
+ */
10068
+ function get_after_activation_url( $filter ) {
10069
+ $first_time_path = $this->_menu->get_first_time_path();
10070
+
10071
+ return $this->apply_filters(
10072
+ $filter,
10073
+ empty( $first_time_path ) ?
10074
+ $this->_get_admin_page_url() :
10075
+ $first_time_path
10076
+ );
10077
+ }
10078
+
10079
+ /**
10080
+ * Handle account page updates / edits / actions.
10081
+ *
10082
+ * @author Vova Feldman (@svovaf)
10083
+ * @since 1.0.2
10084
+ *
10085
+ */
10086
+ private function _handle_account_edits() {
10087
+ if ( ! current_user_can( 'activate_plugins' ) ) {
10088
+ return;
10089
+ }
10090
+
10091
+ $plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
10092
+ $action = fs_get_action();
10093
+
10094
+ switch ( $action ) {
10095
+ case 'delete_account':
10096
+ check_admin_referer( $action );
10097
+
10098
+ if ( $plugin_id == $this->get_id() ) {
10099
+ $this->delete_account_event();
10100
+
10101
+ // Clear user and site.
10102
+ $this->_site = null;
10103
+ $this->_user = null;
10104
+
10105
+ fs_redirect( $this->get_activation_url() );
10106
+ } else {
10107
+ if ( $this->is_addon_activated( $plugin_id ) ) {
10108
+ $fs_addon = self::get_instance_by_id( $plugin_id );
10109
+ $fs_addon->delete_account_event();
10110
+
10111
+ fs_redirect( $this->_get_admin_page_url( 'account' ) );
10112
+ }
10113
+ }
10114
+
10115
+ return;
10116
+
10117
+ case 'downgrade_account':
10118
+ check_admin_referer( $action );
10119
+
10120
+ if ( $plugin_id == $this->get_id() ) {
10121
+ $this->_downgrade_site();
10122
+ } else if ( $this->is_addon_activated( $plugin_id ) ) {
10123
+ $fs_addon = self::get_instance_by_id( $plugin_id );
10124
+ $fs_addon->_downgrade_site();
10125
+ }
10126
+
10127
+ return;
10128
+
10129
+ case 'activate_license':
10130
+ check_admin_referer( $action );
10131
+
10132
+ if ( $plugin_id == $this->get_id() ) {
10133
+ $this->_activate_license();
10134
+ } else {
10135
+ if ( $this->is_addon_activated( $plugin_id ) ) {
10136
+ $fs_addon = self::get_instance_by_id( $plugin_id );
10137
+ $fs_addon->_activate_license();
10138
+ }
10139
+ }
10140
+
10141
+ return;
10142
+
10143
+ case 'deactivate_license':
10144
+ check_admin_referer( $action );
10145
+
10146
+ if ( $plugin_id == $this->get_id() ) {
10147
+ $this->_deactivate_license();
10148
+ } else {
10149
+ if ( $this->is_addon_activated( $plugin_id ) ) {
10150
+ $fs_addon = self::get_instance_by_id( $plugin_id );
10151
+ $fs_addon->_deactivate_license();
10152
+ }
10153
+ }
10154
+
10155
+ return;
10156
+
10157
+ case 'check_updates':
10158
+ check_admin_referer( $action );
10159
+ $this->_check_updates();
10160
+
10161
+ return;
10162
+
10163
+ case 'change_owner':
10164
+ $state = fs_request_get( 'state', 'init' );
10165
+ switch ( $state ) {
10166
+ case 'init':
10167
+ $candidate_email = fs_request_get( 'candidate_email', '' );
10168
+
10169
+ if ( $this->init_change_owner( $candidate_email ) ) {
10170
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request-sent-x', $this->_slug ), '<b>' . $this->_user->email . '</b>' ) );
10171
+ }
10172
+ break;
10173
+ case 'owner_confirmed':
10174
+ $candidate_email = fs_request_get( 'candidate_email', '' );
10175
+
10176
+ $this->_admin_notices->add( sprintf( __fs( 'change-owner-request_owner-confirmed', $this->_slug ), '<b>' . $candidate_email . '</b>' ) );
10177
+ break;
10178
+ case 'candidate_confirmed':
10179
+ if ( $this->complete_change_owner() ) {
10180
+ $this->_admin_notices->add_sticky(
10181
+ sprintf( __fs( 'change-owner-request_candidate-confirmed', $this->_slug ), '<b>' . $this->_user->email . '</b>' ),
10182
+ 'ownership_changed',
10183
+ __fs( 'congrats', $this->_slug ) . '!'
10184
+ );
10185
+ } else {
10186
+ // @todo Handle failed ownership change message.
10187
+ }
10188
+ break;
10189
+ }
10190
+
10191
+ return;
10192
+
10193
+ case 'update_email':
10194
+ check_admin_referer( 'update_email' );
10195
+
10196
+ $new_email = fs_request_get( 'fs_email_' . $this->_slug, '' );
10197
+ $result = $this->_update_email( $new_email );
10198
+
10199
+ if ( isset( $result->error ) ) {
10200
+ switch ( $result->error->code ) {
10201
+ case 'user_exist':
10202
+ $this->_admin_notices->add(
10203
+ __fs( 'user-exist-message', $this->_slug ) . ' ' .
10204
+ sprintf( __fs( 'user-exist-message_ownership', $this->_slug ), '<b>' . $new_email . '</b>' ) .
10205
+ sprintf(
10206
+ '<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
10207
+ $this->get_account_url( 'change_owner', array(
10208
+ 'state' => 'init',
10209
+ 'candidate_email' => $new_email
10210
+ ) ),
10211
+ __fs( 'change-ownership', $this->_slug )
10212
+ ),
10213
+ __fs( 'oops', $this->_slug ) . '...',
10214
+ 'error'
10215
+ );
10216
+ break;
10217
+ }
10218
+ } else {
10219
+ $this->_admin_notices->add( __fs( 'email-updated-message', $this->_slug ) );
10220
+ }
10221
+
10222
+ return;
10223
+
10224
+ case 'update_user_name':
10225
+ check_admin_referer( 'update_user_name' );
10226
+
10227
+ $result = $this->update_user_name();
10228
+
10229
+ if ( isset( $result->error ) ) {
10230
+ $this->_admin_notices->add(
10231
+ __fs( 'name-update-failed-message', $this->_slug ),
10232
+ __fs( 'oops', $this->_slug ) . '...',
10233
+ 'error'
10234
+ );
10235
+ } else {
10236
+ $this->_admin_notices->add( __fs( 'name-updated-message', $this->_slug ) );
10237
+ }
10238
+
10239
+ return;
10240
+
10241
+ #region Actions that might be called from external links (e.g. email)
10242
+
10243
+ case 'cancel_trial':
10244
+ if ( $plugin_id == $this->get_id() ) {
10245
+ $this->_cancel_trial();
10246
+ } else {
10247
+ if ( $this->is_addon_activated( $plugin_id ) ) {
10248
+ $fs_addon = self::get_instance_by_id( $plugin_id );
10249
+ $fs_addon->_cancel_trial();
10250
+ }
10251
+ }
10252
+
10253
+ return;
10254
+
10255
+ case 'verify_email':
10256
+ $this->verify_email();
10257
+
10258
+ return;
10259
+
10260
+ case 'sync_user':
10261
+ $this->_handle_account_user_sync();
10262
+
10263
+ return;
10264
+
10265
+ case $this->_slug . '_sync_license':
10266
+ $this->_sync_license();
10267
+
10268
+ return;
10269
+
10270
+ case 'download_latest':
10271
+ $this->_download_latest_directly( $plugin_id );
10272
+
10273
+ return;
10274
+
10275
+ #endregion
10276
+ }
10277
+
10278
+ if ( WP_FS__IS_POST_REQUEST ) {
10279
+ $properties = array( 'site_secret_key', 'site_id', 'site_public_key' );
10280
+ foreach ( $properties as $p ) {
10281
+ if ( 'update_' . $p === $action ) {
10282
+ check_admin_referer( $action );
10283
+
10284
+ $this->_logger->log( $action );
10285
+
10286
+ $site_property = substr( $p, strlen( 'site_' ) );
10287
+ $site_property_value = fs_request_get( 'fs_' . $p . '_' . $this->_slug, '' );
10288
+ $this->get_site()->{$site_property} = $site_property_value;
10289
+
10290
+ // Store account after modification.
10291
+ $this->_store_site();
10292
+
10293
+ $this->do_action( 'account_property_edit', 'site', $site_property, $site_property_value );
10294
+
10295
+ $this->_admin_notices->add( sprintf(
10296
+ __fs( 'x-updated', $this->_slug ),
10297
+ '<b>' . str_replace( '_', ' ', $p ) . '</b>' ) );
10298
+
10299
+ return;
10300
+ }
10301
+ }
10302
+ }
10303
+ }
10304
+
10305
+ /**
10306
+ * Account page resources load.
10307
+ *
10308
+ * @author Vova Feldman (@svovaf)
10309
+ * @since 1.0.6
10310
+ */
10311
+ function _account_page_load() {
10312
+ $this->_logger->entrance();
10313
+
10314
+ $this->_logger->info( var_export( $_REQUEST, true ) );
10315
+
10316
+ fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
10317
+
10318
+ if ( $this->has_addons() ) {
10319
+ wp_enqueue_script( 'plugin-install' );
10320
+ add_thickbox();
10321
+
10322
+ function fs_addons_body_class( $classes ) {
10323
+ $classes .= ' plugins-php';
10324
+
10325
+ return $classes;
10326
+ }
10327
+
10328
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
10329
+ }
10330
+
10331
+ if ( $this->has_paid_plan() &&
10332
+ ! $this->has_any_license() &&
10333
+ ! $this->is_sync_executed() &&
10334
+ $this->is_tracking_allowed()
10335
+ ) {
10336
+ /**
10337
+ * If no licenses found and no sync job was executed during the last 24 hours,
10338
+ * just execute the sync job right away (blocking execution).
10339
+ *
10340
+ * @since 1.1.7.3
10341
+ */
10342
+ $this->run_manual_sync();
10343
+ }
10344
+
10345
+ $this->_handle_account_edits();
10346
+
10347
+ $this->do_action( 'account_page_load_before_departure' );
10348
+ }
10349
+
10350
+ /**
10351
+ * Render account page.
10352
+ *
10353
+ * @author Vova Feldman (@svovaf)
10354
+ * @since 1.0.0
10355
+ */
10356
+ function _account_page_render() {
10357
+ $this->_logger->entrance();
10358
+
10359
+ $vars = array( 'slug' => $this->_slug );
10360
+ if ( 'billing' === fs_request_get( 'tab' ) ) {
10361
+ fs_require_once_template( 'billing.php', $vars );
10362
+ } else {
10363
+ fs_require_once_template( 'account.php', $vars );
10364
+ }
10365
+ }
10366
+
10367
+ /**
10368
+ * Render account connect page.
10369
+ *
10370
+ * @author Vova Feldman (@svovaf)
10371
+ * @since 1.0.7
10372
+ */
10373
+ function _connect_page_render() {
10374
+ $this->_logger->entrance();
10375
+
10376
+ $vars = array( 'slug' => $this->_slug );
10377
+ fs_require_once_template( 'connect.php', $vars );
10378
+ }
10379
+
10380
+ /**
10381
+ * Load required resources before add-ons page render.
10382
+ *
10383
+ * @author Vova Feldman (@svovaf)
10384
+ * @since 1.0.6
10385
+ */
10386
+ function _addons_page_load() {
10387
+ $this->_logger->entrance();
10388
+
10389
+ fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
10390
+
10391
+ wp_enqueue_script( 'plugin-install' );
10392
+ add_thickbox();
10393
+
10394
+ function fs_addons_body_class( $classes ) {
10395
+ $classes .= ' plugins-php';
10396
+
10397
+ return $classes;
10398
+ }
10399
+
10400
+ add_filter( 'admin_body_class', 'fs_addons_body_class' );
10401
+
10402
+ if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
10403
+ $this->_admin_notices->add(
10404
+ sprintf( __fs( 'addons-info-external-message', $this->_slug ), '<b>' . $this->get_plugin_name() . '</b>' ),
10405
+ __fs( 'heads-up', $this->_slug ),
10406
+ 'update-nag'
10407
+ );
10408
+ }
10409
+ }
10410
+
10411
+ /**
10412
+ * Render add-ons page.
10413
+ *
10414
+ * @author Vova Feldman (@svovaf)
10415
+ * @since 1.0.6
10416
+ */
10417
+ function _addons_page_render() {
10418
+ $this->_logger->entrance();
10419
+
10420
+ $vars = array( 'slug' => $this->_slug );
10421
+ fs_require_once_template( 'add-ons.php', $vars );
10422
+ }
10423
+
10424
+ /* Pricing & Upgrade
10425
+ ------------------------------------------------------------------------------------------------------------------*/
10426
+ /**
10427
+ * Render pricing page.
10428
+ *
10429
+ * @author Vova Feldman (@svovaf)
10430
+ * @since 1.0.0
10431
+ */
10432
+ function _pricing_page_render() {
10433
+ $this->_logger->entrance();
10434
+
10435
+ $vars = array( 'slug' => $this->_slug );
10436
+
10437
+ if ( 'true' === fs_request_get( 'checkout', false ) ) {
10438
+ fs_require_once_template( 'checkout.php', $vars );
10439
+ } else {
10440
+ fs_require_once_template( 'pricing.php', $vars );
10441
+ }
10442
+ }
10443
+
10444
+ #----------------------------------------------------------------------------------
10445
+ #region Contact Us
10446
+ #----------------------------------------------------------------------------------
10447
+
10448
+ /**
10449
+ * Render contact-us page.
10450
+ *
10451
+ * @author Vova Feldman (@svovaf)
10452
+ * @since 1.0.3
10453
+ */
10454
+ function _contact_page_render() {
10455
+ $this->_logger->entrance();
10456
+
10457
+ $vars = array( 'slug' => $this->_slug );
10458
+ fs_require_once_template( 'contact.php', $vars );
10459
+ }
10460
+
10461
+ #endregion ------------------------------------------------------------------------
10462
+
10463
+ /**
10464
+ * Hide all admin notices to prevent distractions.
10465
+ *
10466
+ * @author Vova Feldman (@svovaf)
10467
+ * @since 1.0.3
10468
+ *
10469
+ * @uses remove_all_actions()
10470
+ */
10471
+ private static function _hide_admin_notices() {
10472
+ remove_all_actions( 'admin_notices' );
10473
+ remove_all_actions( 'network_admin_notices' );
10474
+ remove_all_actions( 'all_admin_notices' );
10475
+ remove_all_actions( 'user_admin_notices' );
10476
+ }
10477
+
10478
+ static function _clean_admin_content_section_hook() {
10479
+ self::_hide_admin_notices();
10480
+
10481
+ // Hide footer.
10482
+ echo '<style>#wpfooter { display: none !important; }</style>';
10483
+ }
10484
+
10485
+ /**
10486
+ * Attach to admin_head hook to hide all admin notices.
10487
+ *
10488
+ * @author Vova Feldman (@svovaf)
10489
+ * @since 1.0.3
10490
+ */
10491
+ static function _clean_admin_content_section() {
10492
+ add_action( 'admin_head', 'Freemius::_clean_admin_content_section_hook' );
10493
+ }
10494
+
10495
+ /* CSS & JavaScript
10496
+ ------------------------------------------------------------------------------------------------------------------*/
10497
+ /* function _enqueue_script($handle, $src) {
10498
+ $url = plugins_url( substr( WP_FS__DIR_JS, strlen( $this->_plugin_dir_path ) ) . '/assets/js/' . $src );
10499
+
10500
+ $this->_logger->entrance( 'script = ' . $url );
10501
+
10502
+ wp_enqueue_script( $handle, $url );
10503
+ }*/
10504
+
10505
+ /* SDK
10506
+ ------------------------------------------------------------------------------------------------------------------*/
10507
+ private $_user_api;
10508
+
10509
+ /**
10510
+ *
10511
+ * @author Vova Feldman (@svovaf)
10512
+ * @since 1.0.2
10513
+ *
10514
+ * @param bool $flush
10515
+ *
10516
+ * @return FS_Api
10517
+ */
10518
+ function get_api_user_scope( $flush = false ) {
10519
+ if ( ! isset( $this->_user_api ) || $flush ) {
10520
+ $this->_user_api = FS_Api::instance(
10521
+ $this->_slug,
10522
+ 'user',
10523
+ $this->_user->id,
10524
+ $this->_user->public_key,
10525
+ ! $this->is_live(),
10526
+ $this->_user->secret_key
10527
+ );
10528
+ }
10529
+
10530
+ return $this->_user_api;
10531
+ }
10532
+
10533
+ private $_site_api;
10534
+
10535
+ /**
10536
+ *
10537
+ * @author Vova Feldman (@svovaf)
10538
+ * @since 1.0.2
10539
+ *
10540
+ * @param bool $flush
10541
+ *
10542
+ * @return FS_Api
10543
+ */
10544
+ function get_api_site_scope( $flush = false ) {
10545
+ if ( ! isset( $this->_site_api ) || $flush ) {
10546
+ $this->_site_api = FS_Api::instance(
10547
+ $this->_slug,
10548
+ 'install',
10549
+ $this->_site->id,
10550
+ $this->_site->public_key,
10551
+ ! $this->is_live(),
10552
+ $this->_site->secret_key
10553
+ );
10554
+ }
10555
+
10556
+ return $this->_site_api;
10557
+ }
10558
+
10559
+ private $_plugin_api;
10560
+
10561
+ /**
10562
+ * Get plugin public API scope.
10563
+ *
10564
+ * @author Vova Feldman (@svovaf)
10565
+ * @since 1.0.7
10566
+ *
10567
+ * @return FS_Api
10568
+ */
10569
+ function get_api_plugin_scope() {
10570
+ if ( ! isset( $this->_plugin_api ) ) {
10571
+ $this->_plugin_api = FS_Api::instance(
10572
+ $this->_slug,
10573
+ 'plugin',
10574
+ $this->_plugin->id,
10575
+ $this->_plugin->public_key,
10576
+ ! $this->is_live()
10577
+ );
10578
+ }
10579
+
10580
+ return $this->_plugin_api;
10581
+ }
10582
+
10583
+ /**
10584
+ * Get site API scope object (fallback to public plugin scope when not registered).
10585
+ *
10586
+ * @author Vova Feldman (@svovaf)
10587
+ * @since 1.0.7
10588
+ *
10589
+ * @return FS_Api
10590
+ */
10591
+ function get_api_site_or_plugin_scope() {
10592
+ return $this->is_registered() ?
10593
+ $this->get_api_site_scope() :
10594
+ $this->get_api_plugin_scope();
10595
+ }
10596
+
10597
+ /**
10598
+ * Show trial promotional notice (if any trial exist).
10599
+ *
10600
+ * @author Vova Feldman (@svovaf)
10601
+ * @since 1.0.9
10602
+ *
10603
+ * @param $plans
10604
+ */
10605
+ function _check_for_trial_plans( $plans ) {
10606
+ $this->_storage->has_trial_plan = FS_Plan_Manager::instance()->has_trial_plan( $plans );
10607
+ }
10608
+
10609
+ /**
10610
+ * During trial promotion the "upgrade" submenu item turns to
10611
+ * "start trial" to encourage the trial. Since we want to keep
10612
+ * the same menu item handler and there's no robust way to
10613
+ * add new arguments to the menu item link's querystring,
10614
+ * use JavaScript to find the menu item and update the href of
10615
+ * the link.
10616
+ *
10617
+ * @author Vova Feldman (@svovaf)
10618
+ * @since 1.2.1.5
10619
+ */
10620
+ function _fix_start_trial_menu_item_url() {
10621
+ $template_args = array( 'slug' => $this->_slug );
10622
+ fs_require_template( 'add-trial-to-pricing.php', $template_args );
10623
+ }
10624
+
10625
+ /**
10626
+ * Show trial promotional notice (if any trial exist).
10627
+ *
10628
+ * @author Vova Feldman (@svovaf)
10629
+ * @since 1.0.9
10630
+ *
10631
+ * @return bool If trial notice added.
10632
+ */
10633
+ function _add_trial_notice() {
10634
+ if ( ! current_user_can( 'activate_plugins' ) ) {
10635
+ return false;
10636
+ }
10637
+
10638
+ if ( ! $this->is_user_in_admin() ) {
10639
+ return false;
10640
+ }
10641
+
10642
+ // Check if trial message is already shown.
10643
+ if ( $this->_admin_notices->has_sticky( 'trial_promotion' ) ) {
10644
+ add_action( 'admin_footer', array( &$this, '_fix_start_trial_menu_item_url' ) );
10645
+
10646
+ $this->_menu->add_counter_to_menu_item( 1, 'fs-trial' );
10647
+
10648
+ return false;
10649
+ }
10650
+
10651
+ if ( $this->is_premium() && ! WP_FS__DEV_MODE ) {
10652
+ // Don't show trial if running the premium code, unless running in DEV mode.
10653
+ return false;
10654
+ }
10655
+
10656
+ if ( ! $this->has_trial_plan() ) {
10657
+ // No plans with trial.
10658
+ return false;
10659
+ }
10660
+
10661
+ if ( ! $this->apply_filters( 'show_trial', true ) ) {
10662
+ // Developer explicitly asked not to show the trial promo.
10663
+ return false;
10664
+ }
10665
+
10666
+ if ( $this->is_registered() ) {
10667
+ // Check if trial already utilized.
10668
+ if ( $this->_site->is_trial_utilized() ) {
10669
+ return false;
10670
+ }
10671
+
10672
+ if ( $this->is_paying_or_trial() ) {
10673
+ // Don't show trial if paying or already in trial.
10674
+ return false;
10675
+ }
10676
+ }
10677
+
10678
+ if ( $this->is_activation_mode() || $this->is_pending_activation() ) {
10679
+ // If not yet opted-in/skipped, or pending activation, don't show trial.
10680
+ return false;
10681
+ }
10682
+
10683
+ $last_time_trial_promotion_shown = $this->_storage->get( 'trial_promotion_shown', false );
10684
+ $was_promotion_shown_before = ( false !== $last_time_trial_promotion_shown );
10685
+
10686
+ // Show promotion if never shown before and 24 hours after initial activation with FS.
10687
+ if ( ! $was_promotion_shown_before &&
10688
+ $this->_storage->install_timestamp > ( time() - WP_FS__TIME_24_HOURS_IN_SEC )
10689
+ ) {
10690
+ return false;
10691
+ }
10692
+
10693
+ // OR if promotion was shown before, try showing it every 30 days.
10694
+ if ( $was_promotion_shown_before &&
10695
+ 30 * WP_FS__TIME_24_HOURS_IN_SEC > time() - $last_time_trial_promotion_shown
10696
+ ) {
10697
+ return false;
10698
+ }
10699
+
10700
+ $trial_period = $this->_trial_days;
10701
+ $require_payment = $this->_is_trial_require_payment;
10702
+ $trial_url = $this->get_trial_url();
10703
+ $plans_string = strtolower( __fs( 'awesome', $this->_slug ) );
10704
+
10705
+ if ( $this->is_registered() ) {
10706
+ // If opted-in, override trial with up to date data from API.
10707
+ $trial_plans = FS_Plan_Manager::instance()->get_trial_plans( $this->_plans );
10708
+ $trial_plans_count = count( $trial_plans );
10709
+
10710
+ if ( 0 === $trial_plans_count ) {
10711
+ // If there's no plans with a trial just exit.
10712
+ return false;
10713
+ }
10714
+
10715
+ /**
10716
+ * @var FS_Plugin_Plan $paid_plan
10717
+ */
10718
+ $paid_plan = $trial_plans[0];
10719
+ $require_payment = $paid_plan->is_require_subscription;
10720
+ $trial_period = $paid_plan->trial_period;
10721
+
10722
+ $total_paid_plans = count( $this->_plans ) - ( FS_Plan_Manager::instance()->has_free_plan( $this->_plans ) ? 1 : 0 );
10723
+
10724
+ if ( $total_paid_plans !== $trial_plans_count ) {
10725
+ // Not all paid plans have a trial - generate a string of those that have it.
10726
+ for ( $i = 0; $i < $trial_plans_count; $i ++ ) {
10727
+ $plans_string .= sprintf(
10728
+ '<a href="%s">%s</a>',
10729
+ $trial_url,
10730
+ $trial_plans[ $i ]->title
10731
+ );
10732
+
10733
+ if ( $i < $trial_plans_count - 2 ) {
10734
+ $plans_string .= ', ';
10735
+ } else if ( $i == $trial_plans_count - 2 ) {
10736
+ $plans_string .= ' and ';
10737
+ }
10738
+ }
10739
+ }
10740
+ }
10741
+
10742
+ $message = sprintf(
10743
+ __fs( 'hey', $this->_slug ) . '! ' . __fs( 'trial-x-promotion-message', $this->_slug ),
10744
+ sprintf( '<b>%s</b>', $this->get_plugin_name() ),
10745
+ $plans_string,
10746
+ $trial_period
10747
+ );
10748
+
10749
+ // "No Credit-Card Required" or "No Commitment for N Days".
10750
+ $cc_string = $require_payment ?
10751
+ sprintf( __fs( 'no-commitment-for-x-days', $this->_slug ), $trial_period ) :
10752
+ __fs( 'no-cc-required', $this->_slug ) . '!';
10753
+
10754
+
10755
+ // Start trial button.
10756
+ $button = ' ' . sprintf(
10757
+ '<a style="margin-left: 10px; vertical-align: super;" href="%s"><button class="button button-primary">%s &nbsp;&#10140;</button></a>',
10758
+ $trial_url,
10759
+ __fs( 'start-free-trial', $this->_slug )
10760
+ );
10761
+
10762
+ $this->_admin_notices->add_sticky(
10763
+ $this->apply_filters( 'trial_promotion_message', "{$message} {$cc_string} {$button}" ),
10764
+ 'trial_promotion',
10765
+ '',
10766
+ 'promotion'
10767
+ );
10768
+
10769
+ $this->_storage->trial_promotion_shown = WP_FS__SCRIPT_START_TIME;
10770
+
10771
+ return true;
10772
+ }
10773
+
10774
+ /**
10775
+ * @author Vova Feldman (@svovaf)
10776
+ * @since 1.2.1.5
10777
+ */
10778
+ function _enqueue_common_css() {
10779
+ if ( $this->has_paid_plan() && ! $this->is_paying() ) {
10780
+ // Add basic CSS for admin-notices and menu-item colors.
10781
+ fs_enqueue_local_style( 'fs_common', '/admin/common.css' );
10782
+ }
10783
+ }
10784
+
10785
+ /* Action Links
10786
+ ------------------------------------------------------------------------------------------------------------------*/
10787
+ private $_action_links_hooked = false;
10788
+ private $_action_links = array();
10789
+
10790
+ /**
10791
+ * Hook to plugin action links filter.
10792
+ *
10793
+ * @author Vova Feldman (@svovaf)
10794
+ * @since 1.0.0
10795
+ */
10796
+ private function hook_plugin_action_links() {
10797
+ $this->_logger->entrance();
10798
+
10799
+ $this->_action_links_hooked = true;
10800
+
10801
+ $this->_logger->log( 'Adding action links hooks.' );
10802
+
10803
+ // Add action link to settings page.
10804
+ add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
10805
+ &$this,
10806
+ '_modify_plugin_action_links_hook'
10807
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
10808
+ add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
10809
+ &$this,
10810
+ '_modify_plugin_action_links_hook'
10811
+ ), WP_FS__DEFAULT_PRIORITY, 2 );
10812
+ }
10813
+
10814
+ /**
10815
+ * Add plugin action link.
10816
+ *
10817
+ * @author Vova Feldman (@svovaf)
10818
+ * @since 1.0.0
10819
+ *
10820
+ * @param $label
10821
+ * @param $url
10822
+ * @param bool $external
10823
+ * @param int $priority
10824
+ * @param bool $key
10825
+ */
10826
+ function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
10827
+ $this->_logger->entrance();
10828
+
10829
+ if ( ! isset( $this->_action_links[ $priority ] ) ) {
10830
+ $this->_action_links[ $priority ] = array();
10831
+ }
10832
+
10833
+ if ( false === $key ) {
10834
+ $key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
10835
+ }
10836
+
10837
+ $this->_action_links[ $priority ][] = array(
10838
+ 'label' => $label,
10839
+ 'href' => $url,
10840
+ 'key' => $key,
10841
+ 'external' => $external
10842
+ );
10843
+ }
10844
+
10845
+ /**
10846
+ * Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
10847
+ *
10848
+ * @author Vova Feldman (@svovaf)
10849
+ * @since 1.0.0
10850
+ */
10851
+ function _add_upgrade_action_link() {
10852
+ $this->_logger->entrance();
10853
+
10854
+ if ( $this->is_registered() ) {
10855
+ if ( ! $this->is_paying() && $this->has_paid_plan() ) {
10856
+ $this->add_plugin_action_link(
10857
+ __fs( 'upgrade', $this->_slug ),
10858
+ $this->get_upgrade_url(),
10859
+ false,
10860
+ 7,
10861
+ 'upgrade'
10862
+ );
10863
+ }
10864
+
10865
+ if ( $this->has_addons() ) {
10866
+ $this->add_plugin_action_link(
10867
+ __fs( 'add-ons', $this->_slug ),
10868
+ $this->_get_admin_page_url( 'addons' ),
10869
+ false,
10870
+ 9,
10871
+ 'addons'
10872
+ );
10873
+ }
10874
+ }
10875
+ }
10876
+
10877
+ /**
10878
+ * Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
10879
+ *
10880
+ * @author Leo Fajardo (@leorw)
10881
+ * @since 1.1.9
10882
+ */
10883
+ function _add_license_action_link() {
10884
+ $this->_logger->entrance();
10885
+
10886
+ if ( $this->is_free_plan() && $this->is_addon() ) {
10887
+ return;
10888
+ }
10889
+
10890
+ if ( ! $this->is_ajax() ) {
10891
+ // Inject license activation dialog UI and client side code.
10892
+ add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
10893
+ }
10894
+
10895
+ $link_text = __fs(
10896
+ $this->is_free_plan() ? 'activate-license' : 'change-license',
10897
+ $this->_slug
10898
+ );
10899
+
10900
+ $this->add_plugin_action_link(
10901
+ $link_text,
10902
+ '#',
10903
+ false,
10904
+ 11,
10905
+ ( 'activate-license ' . $this->_slug )
10906
+ );
10907
+ }
10908
+
10909
+ /**
10910
+ * Adds "Opt in" or "Opt out" link to the main "Plugins" page link actions collection.
10911
+ *
10912
+ * @author Leo Fajardo (@leorw)
10913
+ * @since 1.2.1.5
10914
+ */
10915
+ function _add_tracking_links() {
10916
+ if ( ! current_user_can( 'activate_plugins' ) ) {
10917
+ return;
10918
+ }
10919
+
10920
+ $this->_logger->entrance();
10921
+
10922
+ if ( ! $this->is_enable_anonymous() ) {
10923
+ // Don't allow to opt-out if anonymous mode is disabled.
10924
+ return;
10925
+ }
10926
+
10927
+ if ( ! $this->is_free_plan() ) {
10928
+ // Don't allow to opt-out if running in paid plan.
10929
+ return;
10930
+ }
10931
+
10932
+ if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
10933
+ return;
10934
+ }
10935
+
10936
+ if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
10937
+ return;
10938
+ }
10939
+
10940
+ if ( fs_request_is_action_secure( $this->_slug . '_reconnect' ) ) {
10941
+ if ( ! $this->is_registered() && $this->is_anonymous() ) {
10942
+ $this->connect_again();
10943
+
10944
+ return;
10945
+ }
10946
+ }
10947
+
10948
+ $url = '#';
10949
+
10950
+ if ( $this->is_registered() ) {
10951
+ if ( $this->is_tracking_allowed() ) {
10952
+ $link_text_id = 'opt-out';
10953
+ } else {
10954
+ $link_text_id = 'opt-in';
10955
+ }
10956
+
10957
+ add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
10958
+ } else {
10959
+ $link_text_id = 'opt-in';
10960
+
10961
+ $params = ! $this->is_anonymous() ?
10962
+ array() :
10963
+ array(
10964
+ 'nonce' => wp_create_nonce( $this->_slug . '_reconnect' ),
10965
+ 'fs_action' => ( $this->_slug . '_reconnect' ),
10966
+ );
10967
+
10968
+ $url = $this->get_activation_url( $params );
10969
+ }
10970
+
10971
+ $this->add_plugin_action_link(
10972
+ __fs( $link_text_id, $this->_slug ),
10973
+ $url,
10974
+ false,
10975
+ 13,
10976
+ "opt-in-or-opt-out {$this->_slug}"
10977
+ );
10978
+ }
10979
+
10980
+ /**
10981
+ * Get the URL of the page that should be loaded right after the plugin activation.
10982
+ *
10983
+ * @author Vova Feldman (@svovaf)
10984
+ * @since 1.1.7.4
10985
+ *
10986
+ * @return string
10987
+ */
10988
+ function get_after_plugin_activation_redirect_url() {
10989
+ $url = false;
10990
+ $plugin_fs = false;
10991
+
10992
+ if ( ! $this->is_addon() ) {
10993
+ $first_time_path = $this->_menu->get_first_time_path();
10994
+ $plugin_fs = $this;
10995
+ $url = $plugin_fs->is_activation_mode() ?
10996
+ $plugin_fs->get_activation_url() :
10997
+ ( empty( $first_time_path ) ?
10998
+ $this->_get_admin_page_url() :
10999
+ $first_time_path );
11000
+ } else {
11001
+ if ( $this->is_parent_plugin_installed() ) {
11002
+ $plugin_fs = self::get_parent_instance();
11003
+ }
11004
+
11005
+ if ( is_object( $plugin_fs ) ) {
11006
+ if ( ! $plugin_fs->is_registered() ) {
11007
+ // Forward to parent plugin connect when parent not registered.
11008
+ $url = $plugin_fs->get_activation_url();
11009
+ } else {
11010
+ // Forward to account page.
11011
+ $url = $plugin_fs->_get_admin_page_url( 'account' );
11012
+ }
11013
+ }
11014
+ }
11015
+
11016
+ return $url;
11017
+ }
11018
+
11019
+ /**
11020
+ * Forward page to activation page.
11021
+ *
11022
+ * @author Vova Feldman (@svovaf)
11023
+ * @since 1.0.3
11024
+ */
11025
+ function _redirect_on_activation_hook() {
11026
+ $url = $this->get_after_plugin_activation_redirect_url();
11027
+
11028
+ if ( is_string( $url ) ) {
11029
+ fs_redirect( $url );
11030
+ }
11031
+ }
11032
+
11033
+ /**
11034
+ * Modify plugin's page action links collection.
11035
+ *
11036
+ * @author Vova Feldman (@svovaf)
11037
+ * @since 1.0.0
11038
+ *
11039
+ * @param array $links
11040
+ * @param $file
11041
+ *
11042
+ * @return array
11043
+ */
11044
+ function _modify_plugin_action_links_hook( $links, $file ) {
11045
+ $this->_logger->entrance();
11046
+
11047
+ $passed_deactivate = false;
11048
+ $deactivate_link = '';
11049
+ $before_deactivate = array();
11050
+ $after_deactivate = array();
11051
+ foreach ( $links as $key => $link ) {
11052
+ if ( 'deactivate' === $key ) {
11053
+ $deactivate_link = $link;
11054
+ $passed_deactivate = true;
11055
+ continue;
11056
+ }
11057
+
11058
+ if ( ! $passed_deactivate ) {
11059
+ $before_deactivate[ $key ] = $link;
11060
+ } else {
11061
+ $after_deactivate[ $key ] = $link;
11062
+ }
11063
+ }
11064
+
11065
+ ksort( $this->_action_links );
11066
+
11067
+ foreach ( $this->_action_links as $new_links ) {
11068
+ foreach ( $new_links as $link ) {
11069
+ $before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
11070
+ }
11071
+ }
11072
+
11073
+ if ( ! empty( $deactivate_link ) ) {
11074
+ if ( ! $this->is_paying_or_trial() || $this->is_premium() ) {
11075
+ /*
11076
+ * This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
11077
+ *
11078
+ * If user is paying or in trial and have the free version installed,
11079
+ * assume that the deactivation is for the upgrade process, so this is not needed.
11080
+ */
11081
+ $deactivate_link .= '<i class="fs-slug" data-slug="' . $this->_slug . '"></i>';
11082
+ }
11083
+
11084
+ // Append deactivation link.
11085
+ $before_deactivate['deactivate'] = $deactivate_link;
11086
+ }
11087
+
11088
+ return array_merge( $before_deactivate, $after_deactivate );
11089
+ }
11090
+
11091
+ /**
11092
+ * Adds admin message.
11093
+ *
11094
+ * @author Vova Feldman (@svovaf)
11095
+ * @since 1.0.4
11096
+ *
11097
+ * @param string $message
11098
+ * @param string $title
11099
+ * @param string $type
11100
+ */
11101
+ function add_admin_message( $message, $title = '', $type = 'success' ) {
11102
+ $this->_admin_notices->add( $message, $title, $type );
11103
+ }
11104
+
11105
+ /**
11106
+ * Adds sticky admin message.
11107
+ *
11108
+ * @author Vova Feldman (@svovaf)
11109
+ * @since 1.1.0
11110
+ *
11111
+ * @param string $message
11112
+ * @param string $id
11113
+ * @param string $title
11114
+ * @param string $type
11115
+ */
11116
+ function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
11117
+ $this->_admin_notices->add_sticky( $message, $id, $title, $type );
11118
+ }
11119
+
11120
+ /**
11121
+ * Helper function that returns the final steps for the upgrade completion.
11122
+ *
11123
+ * If the module is already running the premium code, returns an empty string.
11124
+ *
11125
+ * @author Vova Feldman (@svovaf)
11126
+ * @since 1.2.1
11127
+ *
11128
+ * @param string $plan_title
11129
+ *
11130
+ * @return string
11131
+ */
11132
+ private function get_complete_upgrade_instructions( $plan_title = '' ) {
11133
+ if ( $this->is_premium() ) {
11134
+ return '';
11135
+ }
11136
+
11137
+ if ( empty( $plan_title ) ) {
11138
+ $plan_title = $this->_site->plan->title;
11139
+ }
11140
+
11141
+ // @since 1.2.1.5 The free version is auto deactivated.
11142
+ $deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
11143
+ ( '<li>' . __fs( 'deactivate-free-version', $this->_slug ) . '.</li>' ) :
11144
+ '';
11145
+
11146
+ return sprintf(
11147
+ ' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
11148
+ __fs( 'follow-steps-to-complete-upgrade', $this->_slug ),
11149
+ $this->_get_latest_download_link( sprintf(
11150
+ __fs( 'download-latest-x-version', $this->_slug ),
11151
+ $plan_title
11152
+ ) ),
11153
+ $deactivation_step,
11154
+ __fs( 'upload-and-activate', $this->_slug ),
11155
+ '//bit.ly/upload-wp-plugin',
11156
+ __fs( 'howto-upload-activate', $this->_slug )
11157
+ );
11158
+ }
11159
+
11160
+ /* Plugin Auto-Updates (@since 1.0.4)
11161
+ ------------------------------------------------------------------------------------------------------------------*/
11162
+ /**
11163
+ * @var string[]
11164
+ */
11165
+ private static $_auto_updated_plugins;
11166
+
11167
+ /**
11168
+ * @todo TEST IF IT WORKS!!!
11169
+ *
11170
+ * Include plugins for automatic updates based on stored settings.
11171
+ *
11172
+ * @see http://wordpress.stackexchange.com/questions/131394/how-do-i-exclude-plugins-from-getting-automatically-updated/131404#131404
11173
+ *
11174
+ * @author Vova Feldman (@svovaf)
11175
+ * @since 1.0.4
11176
+ *
11177
+ * @param bool $update Whether to update (not used for plugins)
11178
+ * @param object $item The plugin's info
11179
+ *
11180
+ * @return bool
11181
+ */
11182
+ static function _include_plugins_in_auto_update( $update, $item ) {
11183
+ // Before version 3.8.2 the $item was the file name of the plugin,
11184
+ // while in 3.8.2 statistics were added (https://core.trac.wordpress.org/changeset/27905).
11185
+ $by_slug = ( (int) str_replace( '.', '', get_bloginfo( 'version' ) ) >= 382 );
11186
+
11187
+ if ( ! isset( self::$_auto_updated_plugins ) ) {
11188
+ $plugins = self::$_accounts->get_option( 'plugins', array() );
11189
+
11190
+ $identifiers = array();
11191
+ foreach ( $plugins as $p ) {
11192
+ /**
11193
+ * @var FS_Plugin $p
11194
+ */
11195
+ if ( isset( $p->auto_update ) && $p->auto_update ) {
11196
+ $identifiers[] = ( $by_slug ? $p->slug : plugin_basename( $p->file ) );
11197
+ }
11198
+ }
11199
+
11200
+ self::$_auto_updated_plugins = $identifiers;
11201
+ }
11202
+
11203
+ if ( in_array( $by_slug ? $item->slug : $item, self::$_auto_updated_plugins ) ) {
11204
+ return true;
11205
+ }
11206
+
11207
+ // Pass update decision to next filters
11208
+ return $update;
11209
+ }
11210
+
11211
+ #----------------------------------------------------------------------------------
11212
+ #region Versioning
11213
+ #----------------------------------------------------------------------------------
11214
+
11215
+ /**
11216
+ * Check if Freemius in SDK upgrade mode.
11217
+ *
11218
+ * @author Vova Feldman (@svovaf)
11219
+ * @since 1.0.9
11220
+ *
11221
+ * @return bool
11222
+ */
11223
+ function is_sdk_upgrade_mode() {
11224
+ return isset( $this->_storage->sdk_upgrade_mode ) ?
11225
+ $this->_storage->sdk_upgrade_mode :
11226
+ false;
11227
+ }
11228
+
11229
+ /**
11230
+ * Turn SDK upgrade mode off.
11231
+ *
11232
+ * @author Vova Feldman (@svovaf)
11233
+ * @since 1.0.9
11234
+ */
11235
+ function set_sdk_upgrade_complete() {
11236
+ $this->_storage->sdk_upgrade_mode = false;
11237
+ }
11238
+
11239
+ /**
11240
+ * Check if plugin upgrade mode.
11241
+ *
11242
+ * @author Vova Feldman (@svovaf)
11243
+ * @since 1.0.9
11244
+ *
11245
+ * @return bool
11246
+ */
11247
+ function is_plugin_upgrade_mode() {
11248
+ return isset( $this->_storage->plugin_upgrade_mode ) ?
11249
+ $this->_storage->plugin_upgrade_mode :
11250
+ false;
11251
+ }
11252
+
11253
+ /**
11254
+ * Turn plugin upgrade mode off.
11255
+ *
11256
+ * @author Vova Feldman (@svovaf)
11257
+ * @since 1.0.9
11258
+ *
11259
+ * @return bool
11260
+ */
11261
+ function set_plugin_upgrade_complete() {
11262
+ $this->_storage->plugin_upgrade_mode = false;
11263
+ }
11264
+
11265
+ #endregion
11266
+
11267
+ #----------------------------------------------------------------------------------
11268
+ #region Permissions
11269
+ #----------------------------------------------------------------------------------
11270
+
11271
+ /**
11272
+ * Check if specific permission requested.
11273
+ *
11274
+ * @author Vova Feldman (@svovaf)
11275
+ * @since 1.1.6
11276
+ *
11277
+ * @param string $permission
11278
+ *
11279
+ * @return bool
11280
+ */
11281
+ function is_permission_requested( $permission ) {
11282
+ return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
11283
+ }
11284
+
11285
+ #endregion
11286
+
11287
+ #----------------------------------------------------------------------------------
11288
+ #region Marketing
11289
+ #----------------------------------------------------------------------------------
11290
+
11291
+ /**
11292
+ * Check if current user purchased any other plugins before.
11293
+ *
11294
+ * @author Vova Feldman (@svovaf)
11295
+ * @since 1.0.9
11296
+ *
11297
+ * @return bool
11298
+ */
11299
+ function has_purchased_before() {
11300
+ // TODO: Implement has_purchased_before() method.
11301
+ throw new Exception( 'not implemented' );
11302
+ }
11303
+
11304
+ /**
11305
+ * Check if current user classified as an agency.
11306
+ *
11307
+ * @author Vova Feldman (@svovaf)
11308
+ * @since 1.0.9
11309
+ *
11310
+ * @return bool
11311
+ */
11312
+ function is_agency() {
11313
+ // TODO: Implement is_agency() method.
11314
+ throw new Exception( 'not implemented' );
11315
+ }
11316
+
11317
+ /**
11318
+ * Check if current user classified as a developer.
11319
+ *
11320
+ * @author Vova Feldman (@svovaf)
11321
+ * @since 1.0.9
11322
+ *
11323
+ * @return bool
11324
+ */
11325
+ function is_developer() {
11326
+ // TODO: Implement is_developer() method.
11327
+ throw new Exception( 'not implemented' );
11328
+ }
11329
+
11330
+ /**
11331
+ * Check if current user classified as a business.
11332
+ *
11333
+ * @author Vova Feldman (@svovaf)
11334
+ * @since 1.0.9
11335
+ *
11336
+ * @return bool
11337
+ */
11338
+ function is_b